Skip to content

Commit

Permalink
Rename Interaction::Clicked -> Interaction::Pressed (#8989) (#9027)
Browse files Browse the repository at this point in the history
# Objective

- Fixes #8989

## Solution

- Renamed Interaction::Clicked -> Interaction::Pressed
- Minor changes to comments to keep clarity of terms

## Migration Guide

- Rename all instances of Interaction::Clicked -> Interaction::Pressed
  • Loading branch information
Anby authored Jul 5, 2023
1 parent a3ab507 commit 7f1d084
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 18 deletions.
22 changes: 12 additions & 10 deletions crates/bevy_ui/src/focus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ 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.
///
/// Note: This does not capture click/press-release action.
Pressed,
/// The node has been hovered over
Hovered,
/// Nothing has happened
Expand Down Expand Up @@ -154,7 +156,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;
}
}
Expand Down Expand Up @@ -255,15 +257,15 @@ pub fn ui_focus_system(
.collect::<Vec<Entity>>()
.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 {
Expand All @@ -279,16 +281,16 @@ 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
// `moused_over_nodes` after the previous loop is exited.
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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/ecs/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions examples/games/game_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -379,7 +379,7 @@ mod menu {
mut setting: ResMut<T>,
) {
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::<SelectedOption>();
Expand Down Expand Up @@ -789,7 +789,7 @@ mod menu {
mut game_state: ResMut<NextState<GameState>>,
) {
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 => {
Expand Down
2 changes: 1 addition & 1 deletion examples/mobile/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
2 changes: 1 addition & 1 deletion examples/ui/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion examples/ui/display_and_visibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ fn buttons_handler<T>(
Target<T>: 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) {
Expand Down
2 changes: 1 addition & 1 deletion examples/ui/size_constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down

0 comments on commit 7f1d084

Please sign in to comment.