From aa0c8b421b452a8ab57e2b93e285b2f4bfc37ead Mon Sep 17 00:00:00 2001 From: Robert Garrett Date: Mon, 25 Aug 2025 11:36:26 -0500 Subject: [PATCH] Handle machine button UI events with observers Observers are "just" systems with a Trigger as their first parameter. I've made 4 systems to handle the start and stop of the press and hover actions. Having the button *actually* do something (not just change colors) will be achieved by attaching another button to the on-press trigger. I'm expecting that the machine-ui-spawning system will do that, but in principle it could be done by anything with access to the UI's button entity ID. --- src/widgets.rs | 65 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/src/widgets.rs b/src/widgets.rs index c7d81c9..598d80b 100644 --- a/src/widgets.rs +++ b/src/widgets.rs @@ -20,7 +20,7 @@ pub fn spawn_cutter_machine_ui(mut commands: Commands) { Pickable::default(), children![(Text::new("Uses: "), TextColor(BLACK.into()),)], )); - + // Center panel (placeholder for the Card view) commands.spawn(( Node::default(), @@ -119,4 +119,67 @@ fn spawn_machine_button(commands: &mut ChildSpawnerCommands) { TextShadow::default(), ], )); + builder.observe(button_hover_start); + builder.observe(button_hover_stop); + builder.observe(button_press_start); + builder.observe(button_press_stop); + builder.observe(second_on_press_event); +} + +/// Re-color the button when a pointer passes over it +fn button_hover_start( + event: Trigger>, + // Get button background and border colors so we can change them. + // Filter for *changed* interactions, and only entities with a [`Button`] + mut button_colors: Query<(&mut BackgroundColor, &mut BorderColor), With