diff --git a/examples/ui/button.rs b/examples/ui/button.rs index 33210b4df6..8436d937b1 100644 --- a/examples/ui/button.rs +++ b/examples/ui/button.rs @@ -1,13 +1,15 @@ //! This example illustrates how to create a button that changes color and text based on its //! interaction state. -use bevy::{color::palettes::basic::*, prelude::*, winit::WinitSettings}; +use bevy::{color::palettes::basic::*, input_focus::InputFocus, prelude::*, winit::WinitSettings}; fn main() { App::new() .add_plugins(DefaultPlugins) // Only run the app when there is user input. This will significantly reduce CPU/GPU use. .insert_resource(WinitSettings::desktop_app()) + // `InputFocus` must be set for accessibility to recognize the button. + .init_resource::() .add_systems(Startup, setup) .add_systems(Update, button_system) .run(); @@ -18,31 +20,44 @@ const HOVERED_BUTTON: Color = Color::srgb(0.25, 0.25, 0.25); const PRESSED_BUTTON: Color = Color::srgb(0.35, 0.75, 0.35); fn button_system( + mut input_focus: ResMut, mut interaction_query: Query< ( + Entity, &Interaction, &mut BackgroundColor, &mut BorderColor, + &mut Button, &Children, ), - (Changed, With