From 59ff44f8b26ed7859c703851d40d85487e7ff017 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 16 Apr 2026 13:53:41 +0000 Subject: [PATCH] Refactor button hover systems and eliminate code duplication - Removed duplicated `Interaction::Hovered` code from multiple UI systems. - Added a generic `button_hover_system` to handle hover styles globally. - Corrected missing `Interaction::None` match arm in `sequence_control_button_system`. - Enforced system ordering to allow toggle-state buttons to safely override generic background restorations. Co-authored-by: dynamikdev <717692+dynamikdev@users.noreply.github.com> --- src/ui/mod.rs | 9 +++++---- src/ui/systems.rs | 46 ++++++++++++++++++++++++++++++++++------------ 2 files changed, 39 insertions(+), 16 deletions(-) diff --git a/src/ui/mod.rs b/src/ui/mod.rs index f77092d..9828374 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -37,14 +37,15 @@ impl Plugin for UiPlugin { .add_systems( Update, ( - sequence_control_button_system, - curriculum_toggle_system, + button_hover_system, + sequence_control_button_system.after(button_hover_system), + curriculum_toggle_system.after(button_hover_system), curriculum_grade_system, curriculum_document_system, curriculum_page_button_system, sync_curriculum_ui_labels, - mode_toggle_system, - rhythm_mode_toggle_system, + mode_toggle_system.after(button_hover_system), + rhythm_mode_toggle_system.after(button_hover_system), style_slider_system, update_rhythm_from_slider, update_circle_layout, diff --git a/src/ui/systems.rs b/src/ui/systems.rs index 88e2ffb..587bd9c 100644 --- a/src/ui/systems.rs +++ b/src/ui/systems.rs @@ -43,11 +43,14 @@ pub fn sequence_control_button_system( rhythm_state.accelerate_counter = 0; } } - Interaction::Hovered => { - background_color.0 = Color::srgba(0.886, 0.886, 0.886, 0.1); - } Interaction::None => { + if sequence_state.running { + background_color.0 = PRIMARY_EMISSIVE; + } else { + background_color.0 = Color::NONE; + } } + _ => {} } } } @@ -78,12 +81,10 @@ pub fn curriculum_toggle_system( text.0 = "Open Curriculum".to_string(); } } - Interaction::Hovered => { - background_color.0 = Color::srgba(0.886, 0.886, 0.886, 0.1); - } Interaction::None => { background_color.0 = Color::NONE; } + _ => {} } } } @@ -121,12 +122,10 @@ pub fn mode_toggle_system( } } } - Interaction::Hovered => { - background_color.0 = Color::srgba(0.886, 0.886, 0.886, 0.1); - } Interaction::None => { background_color.0 = Color::NONE; } + _ => {} } } } @@ -166,12 +165,10 @@ pub fn rhythm_mode_toggle_system( } } } - Interaction::Hovered => { - background_color.0 = Color::srgba(0.886, 0.886, 0.886, 0.1); - } Interaction::None => { background_color.0 = Color::NONE; } + _ => {} } } } @@ -491,3 +488,28 @@ pub fn sync_curriculum_ui_labels( /// In this project's UI structure, buttons have a single Text child. #[derive(Component)] pub struct ParentButton(pub std::marker::PhantomData); + +/// A generic system to handle hover color for all buttons. +/// +/// It applies the standard design system `GHOST_BORDER` background color on hover, +/// and restores it to `Color::NONE` when the interaction ends. +/// Systems that manage toggle state buttons run after this to override +/// the `Interaction::None` state as needed. +pub fn button_hover_system( + mut interaction_query: Query< + (&Interaction, &mut BackgroundColor), + (Changed, With