Skip to content

Commit

Permalink
Fmt and clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
urholaukkarinen committed May 19, 2024
1 parent ee0f6d3 commit 6a2b8a9
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 42 deletions.
6 changes: 3 additions & 3 deletions crates/transform-gizmo-bevy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ fn handle_hotkeys(
GizmoMode::all_from_axes(*axes)
.iter()
.find(|mode| mode.kind() == kind)
.or_else(|| {
.or({
// If nothing matches, choose the default mode.
Some(match kind {
GizmoModeKind::Rotate => GizmoMode::RotateView,
Expand All @@ -347,8 +347,8 @@ fn handle_hotkeys(
if (hotkeys.mouse_click_deactivates
&& mouse_input.any_just_pressed([MouseButton::Left, MouseButton::Right]))
|| hotkeys
.deactivate_gizmo
.is_some_and(|key| keyboard_input.just_pressed(key))
.deactivate_gizmo
.is_some_and(|key| keyboard_input.just_pressed(key))
{
*mode_override = None;
}
Expand Down
70 changes: 35 additions & 35 deletions crates/transform-gizmo/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl GizmoConfig {
}

/// Whether the modes have changed, compared to given other config
pub(crate) fn modes_changed(&self, other: &GizmoConfig) -> bool {
pub(crate) fn modes_changed(&self, other: &Self) -> bool {
(self.modes != other.modes && self.mode_override.is_none())
|| (self.mode_override != other.mode_override)
}
Expand Down Expand Up @@ -288,17 +288,17 @@ pub enum GizmoMode {

impl GizmoMode {
/// All modes
pub fn all() -> EnumSet<GizmoMode> {
pub fn all() -> EnumSet<Self> {
EnumSet::all()
}

/// All rotation modes
pub const fn all_rotate() -> EnumSet<GizmoMode> {
pub const fn all_rotate() -> EnumSet<Self> {
enum_set!(Self::RotateX | Self::RotateY | Self::RotateZ | Self::RotateView)
}

/// All translation modes
pub const fn all_translate() -> EnumSet<GizmoMode> {
pub const fn all_translate() -> EnumSet<Self> {
enum_set!(
Self::TranslateX
| Self::TranslateY
Expand All @@ -311,7 +311,7 @@ impl GizmoMode {
}

/// All scaling modes
pub const fn all_scale() -> EnumSet<GizmoMode> {
pub const fn all_scale() -> EnumSet<Self> {
enum_set!(
Self::ScaleX
| Self::ScaleY
Expand Down Expand Up @@ -341,67 +341,67 @@ impl GizmoMode {
/// Axes this mode acts on
pub fn axes(&self) -> EnumSet<GizmoDirection> {
match self {
GizmoMode::RotateX | GizmoMode::TranslateX | GizmoMode::ScaleX => {
Self::RotateX | Self::TranslateX | Self::ScaleX => {
enum_set!(GizmoDirection::X)
}
GizmoMode::RotateY | GizmoMode::TranslateY | GizmoMode::ScaleY => {
Self::RotateY | Self::TranslateY | Self::ScaleY => {
enum_set!(GizmoDirection::Y)
}
GizmoMode::RotateZ | GizmoMode::TranslateZ | GizmoMode::ScaleZ => {
Self::RotateZ | Self::TranslateZ | Self::ScaleZ => {
enum_set!(GizmoDirection::Z)
}
GizmoMode::RotateView | GizmoMode::TranslateView => {
Self::RotateView | Self::TranslateView => {
enum_set!(GizmoDirection::View)
}
GizmoMode::ScaleUniform | GizmoMode::Arcball => {
Self::ScaleUniform | Self::Arcball => {
enum_set!(GizmoDirection::X | GizmoDirection::Y | GizmoDirection::Z)
}
GizmoMode::TranslateXY | GizmoMode::ScaleXY => {
Self::TranslateXY | Self::ScaleXY => {
enum_set!(GizmoDirection::X | GizmoDirection::Y)
}
GizmoMode::TranslateXZ | GizmoMode::ScaleXZ => {
Self::TranslateXZ | Self::ScaleXZ => {
enum_set!(GizmoDirection::X | GizmoDirection::Z)
}
GizmoMode::TranslateYZ | GizmoMode::ScaleYZ => {
Self::TranslateYZ | Self::ScaleYZ => {
enum_set!(GizmoDirection::Y | GizmoDirection::Z)
}
}
}

/// Returns the modes that match to given axes exactly
pub fn all_from_axes(axes: EnumSet<GizmoDirection>) -> EnumSet<GizmoMode> {
EnumSet::<GizmoMode>::all()
pub fn all_from_axes(axes: EnumSet<GizmoDirection>) -> EnumSet<Self> {
EnumSet::<Self>::all()
.iter()
.filter(|mode| mode.axes() == axes)
.collect()
}

pub fn kind(&self) -> GizmoModeKind {
match self {
GizmoMode::RotateX
| GizmoMode::RotateY
| GizmoMode::RotateZ
| GizmoMode::RotateView => GizmoModeKind::Rotate,
GizmoMode::TranslateX
| GizmoMode::TranslateY
| GizmoMode::TranslateZ
| GizmoMode::TranslateXY
| GizmoMode::TranslateXZ
| GizmoMode::TranslateYZ
| GizmoMode::TranslateView => GizmoModeKind::Translate,
GizmoMode::ScaleX
| GizmoMode::ScaleY
| GizmoMode::ScaleZ
| GizmoMode::ScaleXY
| GizmoMode::ScaleXZ
| GizmoMode::ScaleYZ
| GizmoMode::ScaleUniform => GizmoModeKind::Scale,
GizmoMode::Arcball => GizmoModeKind::Arcball,
Self::RotateX
| Self::RotateY
| Self::RotateZ
| Self::RotateView => GizmoModeKind::Rotate,
Self::TranslateX
| Self::TranslateY
| Self::TranslateZ
| Self::TranslateXY
| Self::TranslateXZ
| Self::TranslateYZ
| Self::TranslateView => GizmoModeKind::Translate,
Self::ScaleX
| Self::ScaleY
| Self::ScaleZ
| Self::ScaleXY
| Self::ScaleXZ
| Self::ScaleYZ
| Self::ScaleUniform => GizmoModeKind::Scale,
Self::Arcball => GizmoModeKind::Arcball,
}
}
}

#[derive(Debug, Copy, Clone, PartialEq, PartialOrd)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd)]
pub enum GizmoModeKind {
Rotate,
Translate,
Expand Down
7 changes: 3 additions & 4 deletions crates/transform-gizmo/src/gizmo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,10 @@ impl Gizmo {
fn pick_subgizmo(&mut self, ray: Ray) -> Option<&mut SubGizmo> {
// If mode is overridden, assume we only have that mode, and choose it.
if self.config.mode_override.is_some() {
return self.subgizmos.first_mut().and_then(|subgizmo| {
return self.subgizmos.first_mut().map(|subgizmo| {
subgizmo.pick(ray);

Some(subgizmo)
subgizmo
});
}

Expand All @@ -332,8 +332,7 @@ impl Gizmo {
fn enabled_modes(&self) -> EnumSet<GizmoMode> {
self.config
.mode_override
.map(EnumSet::only)
.unwrap_or(self.config.modes)
.map_or(self.config.modes, EnumSet::only)
}

/// Adds rotation subgizmos
Expand Down

0 comments on commit 6a2b8a9

Please sign in to comment.