diff --git a/examples/ui/images/ui_texture_atlas_slice.rs b/examples/ui/images/ui_texture_atlas_slice.rs index 0254157ad12b9..e8c1741471df1 100644 --- a/examples/ui/images/ui_texture_atlas_slice.rs +++ b/examples/ui/images/ui_texture_atlas_slice.rs @@ -3,8 +3,11 @@ use bevy::{ color::palettes::css::{GOLD, ORANGE}, + picking::hover::Hovered, + platform::collections::HashSet, prelude::*, - ui::widget::NodeImageMode, + ui::{widget::NodeImageMode, Pressed}, + ui_widgets::Button, }; fn main() { @@ -15,31 +18,68 @@ fn main() { .run(); } +/// Updates each button label whenever its `Pressed` or `Hovered` state changes. +/// The image node, defined from a spritesheet, will also update upon pressing the button. +/// +/// `Hovered` always exists on the button, so `Ref::is_changed` catches hover transitions and +/// the insertion of `Pressed`. Removal of `Pressed` is not reported by change detection, so we +/// also restyle any button that just had `Pressed` removed this frame. fn button_system( - mut interaction_query: Query< - (&Interaction, &Children, &mut ImageNode), - (Changed, With