From b6ad4e31e49a142795c34f01b7904490deb50708 Mon Sep 17 00:00:00 2001 From: Anthony Kalaitzis Date: Sun, 2 Jul 2023 19:57:29 +0930 Subject: [PATCH 1/4] Rename Interaction::Clicked -> Interaction::Pressed (#8989) --- crates/bevy_ui/src/focus.rs | 20 ++++++++++---------- examples/ecs/state.rs | 2 +- examples/games/game_menu.rs | 6 +++--- examples/mobile/src/lib.rs | 2 +- examples/ui/button.rs | 2 +- examples/ui/display_and_visibility.rs | 2 +- examples/ui/size_constraints.rs | 2 +- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/crates/bevy_ui/src/focus.rs b/crates/bevy_ui/src/focus.rs index e3ce2ce927c7d..77bfe0b9e7350 100644 --- a/crates/bevy_ui/src/focus.rs +++ b/crates/bevy_ui/src/focus.rs @@ -35,8 +35,8 @@ use smallvec::SmallVec; #[derive(Component, Copy, Clone, Eq, PartialEq, Debug, Reflect, Serialize, Deserialize)] #[reflect(Component, Serialize, Deserialize, PartialEq)] pub enum Interaction { - /// The node has been clicked - Clicked, + /// The node has been pressed + Pressed, /// The node has been hovered over Hovered, /// Nothing has happened @@ -154,7 +154,7 @@ pub fn ui_focus_system( if mouse_released { for node in node_query.iter_mut() { if let Some(mut interaction) = node.interaction { - if *interaction == Interaction::Clicked { + if *interaction == Interaction::Pressed { *interaction = Interaction::None; } } @@ -255,15 +255,15 @@ pub fn ui_focus_system( .collect::>() .into_iter(); - // set Clicked or Hovered on top nodes. as soon as a node with a `Block` focus policy is detected, + // set Pressed or Hovered on top nodes. as soon as a node with a `Block` focus policy is detected, // the iteration will stop on it because it "captures" the interaction. let mut iter = node_query.iter_many_mut(hovered_nodes.by_ref()); while let Some(node) = iter.fetch_next() { if let Some(mut interaction) = node.interaction { if mouse_clicked { - // only consider nodes with Interaction "clickable" - if *interaction != Interaction::Clicked { - *interaction = Interaction::Clicked; + // only consider nodes with Interaction "pressed" + if *interaction != Interaction::Pressed { + *interaction = Interaction::Pressed; // if the mouse was simultaneously released, reset this Interaction in the next // frame if mouse_released { @@ -279,7 +279,7 @@ pub fn ui_focus_system( FocusPolicy::Block => { break; } - FocusPolicy::Pass => { /* allow the next node to be hovered/clicked */ } + FocusPolicy::Pass => { /* allow the next node to be hovered/pressed */ } } } // reset `Interaction` for the remaining lower nodes to `None`. those are the nodes that remain in @@ -287,8 +287,8 @@ pub fn ui_focus_system( let mut iter = node_query.iter_many_mut(hovered_nodes); while let Some(node) = iter.fetch_next() { if let Some(mut interaction) = node.interaction { - // don't reset clicked nodes because they're handled separately - if *interaction != Interaction::Clicked { + // don't reset pressed nodes because they're handled separately + if *interaction != Interaction::Pressed { interaction.set_if_neq(Interaction::None); } } diff --git a/examples/ecs/state.rs b/examples/ecs/state.rs index aa4810bd80b73..31c0346206bdb 100644 --- a/examples/ecs/state.rs +++ b/examples/ecs/state.rs @@ -99,7 +99,7 @@ fn menu( ) { for (interaction, mut color) in &mut interaction_query { match *interaction { - Interaction::Clicked => { + Interaction::Pressed => { *color = PRESSED_BUTTON.into(); next_state.set(AppState::InGame); } diff --git a/examples/games/game_menu.rs b/examples/games/game_menu.rs index 08055514bd825..aa3c7c1a9e9fa 100644 --- a/examples/games/game_menu.rs +++ b/examples/games/game_menu.rs @@ -362,7 +362,7 @@ mod menu { ) { for (interaction, mut color, selected) in &mut interaction_query { *color = match (*interaction, selected) { - (Interaction::Clicked, _) | (Interaction::None, Some(_)) => PRESSED_BUTTON.into(), + (Interaction::Pressed, _) | (Interaction::None, Some(_)) => PRESSED_BUTTON.into(), (Interaction::Hovered, Some(_)) => HOVERED_PRESSED_BUTTON.into(), (Interaction::Hovered, None) => HOVERED_BUTTON.into(), (Interaction::None, None) => NORMAL_BUTTON.into(), @@ -379,7 +379,7 @@ mod menu { mut setting: ResMut, ) { for (interaction, button_setting, entity) in &interaction_query { - if *interaction == Interaction::Clicked && *setting != *button_setting { + if *interaction == Interaction::Pressed && *setting != *button_setting { let (previous_button, mut previous_color) = selected_query.single_mut(); *previous_color = NORMAL_BUTTON.into(); commands.entity(previous_button).remove::(); @@ -789,7 +789,7 @@ mod menu { mut game_state: ResMut>, ) { for (interaction, menu_button_action) in &interaction_query { - if *interaction == Interaction::Clicked { + if *interaction == Interaction::Pressed { match menu_button_action { MenuButtonAction::Quit => app_exit_events.send(AppExit), MenuButtonAction::Play => { diff --git a/examples/mobile/src/lib.rs b/examples/mobile/src/lib.rs index 843b5cb539975..e6bca949e1754 100644 --- a/examples/mobile/src/lib.rs +++ b/examples/mobile/src/lib.rs @@ -139,7 +139,7 @@ fn button_handler( ) { for (interaction, mut color) in &mut interaction_query { match *interaction { - Interaction::Clicked => { + Interaction::Pressed => { *color = Color::BLUE.into(); } Interaction::Hovered => { diff --git a/examples/ui/button.rs b/examples/ui/button.rs index 288ad8d2c32f9..fef128f6f8c57 100644 --- a/examples/ui/button.rs +++ b/examples/ui/button.rs @@ -32,7 +32,7 @@ fn button_system( for (interaction, mut color, mut border_color, children) in &mut interaction_query { let mut text = text_query.get_mut(children[0]).unwrap(); match *interaction { - Interaction::Clicked => { + Interaction::Pressed => { text.sections[0].value = "Press".to_string(); *color = PRESSED_BUTTON.into(); border_color.0 = Color::RED; diff --git a/examples/ui/display_and_visibility.rs b/examples/ui/display_and_visibility.rs index e6e1bd5b07d4a..d5a7f35dce440 100644 --- a/examples/ui/display_and_visibility.rs +++ b/examples/ui/display_and_visibility.rs @@ -442,7 +442,7 @@ fn buttons_handler( Target: TargetUpdate + Component, { for (target, interaction, children) in visibility_button_query.iter_mut() { - if matches!(interaction, Interaction::Clicked) { + if matches!(interaction, Interaction::Pressed) { let mut target_value = left_panel_query.get_mut(target.id).unwrap(); for &child in children { if let Ok(mut text) = text_query.get_mut(child) { diff --git a/examples/ui/size_constraints.rs b/examples/ui/size_constraints.rs index 562a892bd93c1..b46430990df65 100644 --- a/examples/ui/size_constraints.rs +++ b/examples/ui/size_constraints.rs @@ -306,7 +306,7 @@ fn update_buttons( let mut style = bar_query.single_mut(); for (button_id, interaction, constraint, value) in button_query.iter_mut() { match interaction { - Interaction::Clicked => { + Interaction::Pressed => { button_activated_event.send(ButtonActivatedEvent(button_id)); match constraint { Constraint::FlexBasis => { From cc29f170f4611479e26c7e4a986f9ad36a86a387 Mon Sep 17 00:00:00 2001 From: Anthony Kalaitzis Date: Mon, 3 Jul 2023 17:07:51 +0930 Subject: [PATCH 2/4] Make Interaction::PRessed comment clearer --- crates/bevy_ui/src/focus.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_ui/src/focus.rs b/crates/bevy_ui/src/focus.rs index 77bfe0b9e7350..0f759916ac3fb 100644 --- a/crates/bevy_ui/src/focus.rs +++ b/crates/bevy_ui/src/focus.rs @@ -35,7 +35,7 @@ use smallvec::SmallVec; #[derive(Component, Copy, Clone, Eq, PartialEq, Debug, Reflect, Serialize, Deserialize)] #[reflect(Component, Serialize, Deserialize, PartialEq)] pub enum Interaction { - /// The node has been pressed + /// The node has been pressed (Note: This does not capture click/press-release action) Pressed, /// The node has been hovered over Hovered, From ca2bf4d56b40c2ba729a3c92637f84c6e8bff6db Mon Sep 17 00:00:00 2001 From: Anthony Kalaitzis Date: Tue, 4 Jul 2023 16:58:56 +0930 Subject: [PATCH 3/4] Beautify comment --- crates/bevy_ui/src/focus.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/bevy_ui/src/focus.rs b/crates/bevy_ui/src/focus.rs index 0f759916ac3fb..3c5eee38387dc 100644 --- a/crates/bevy_ui/src/focus.rs +++ b/crates/bevy_ui/src/focus.rs @@ -35,7 +35,9 @@ use smallvec::SmallVec; #[derive(Component, Copy, Clone, Eq, PartialEq, Debug, Reflect, Serialize, Deserialize)] #[reflect(Component, Serialize, Deserialize, PartialEq)] pub enum Interaction { - /// The node has been pressed (Note: This does not capture click/press-release action) + /// The node has been pressed. + /// + /// Note: This does not capture click/press-release action. Pressed, /// The node has been hovered over Hovered, From 12debfd1ecd63953639b35715ab73890525c8b3f Mon Sep 17 00:00:00 2001 From: Anthony Kalaitzis Date: Tue, 4 Jul 2023 17:18:01 +0930 Subject: [PATCH 4/4] Remove whitespace --- crates/bevy_ui/src/focus.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_ui/src/focus.rs b/crates/bevy_ui/src/focus.rs index 3c5eee38387dc..2b180fa7c2dd2 100644 --- a/crates/bevy_ui/src/focus.rs +++ b/crates/bevy_ui/src/focus.rs @@ -36,7 +36,7 @@ use smallvec::SmallVec; #[reflect(Component, Serialize, Deserialize, PartialEq)] pub enum Interaction { /// The node has been pressed. - /// + /// /// Note: This does not capture click/press-release action. Pressed, /// The node has been hovered over