From f6c5808378a73f1aa4f6a698ab3570c25242147b Mon Sep 17 00:00:00 2001 From: Andrew Wason Date: Tue, 11 Feb 2025 11:38:39 -0500 Subject: [PATCH] highlight active drawing viewport --- src/ui.rs | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/src/ui.rs b/src/ui.rs index 43af2e9..7afd200 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -7,9 +7,28 @@ mod brush_size; pub(super) fn plugin(app: &mut App) { app.add_systems(Startup, (setup_ui_camera, setup_ui)) + .add_systems( + OnEnter(AppState::Draw(Interpolated::Source)), + active_color_handler, + ) + .add_systems( + OnEnter(AppState::Draw(Interpolated::Target)), + active_color_handler, + ) + .add_systems( + OnExit(AppState::Draw(Interpolated::Source)), + active_color_handler, + ) + .add_systems( + OnExit(AppState::Draw(Interpolated::Source)), + active_color_handler, + ) .add_plugins((brush_size::plugin, brush_color::plugin)); } +const INACTIVE_COLOR: Color = Color::Srgba(Srgba::rgb(0.4, 0.4, 0.4)); +const ACTIVE_COLOR: Color = Color::Srgba(Srgba::rgb(0.7, 0.7, 0.0)); + #[derive(Component)] pub(super) struct CameraLayout; @@ -49,6 +68,28 @@ where } } +fn active_color_handler( + state: Res>, + mut borders: Query<(&mut BorderColor, &Interpolated), With>, +) { + match state.get() { + AppState::Draw(interpolated) => { + for (mut border_color, border_interpolated) in borders.iter_mut() { + if border_interpolated == interpolated { + border_color.0 = ACTIVE_COLOR; + } else { + border_color.0 = INACTIVE_COLOR; + } + } + } + _ => { + for (mut border_color, _) in borders.iter_mut() { + border_color.0 = INACTIVE_COLOR; + } + } + } +} + fn setup_ui(mut commands: Commands) { commands .spawn(Node { @@ -72,7 +113,7 @@ fn setup_ui(mut commands: Commands) { height: Val::Percent(100.0), ..default() }, - BorderColor(Srgba::rgb(0.4, 0.4, 0.4).into()), + BorderColor(INACTIVE_COLOR), )) .observe(button_state_handler::>(AppState::Draw( Interpolated::Source, @@ -108,7 +149,7 @@ fn setup_ui(mut commands: Commands) { height: Val::Percent(100.0), ..default() }, - BorderColor(Srgba::rgb(0.3, 0.3, 0.3).into()), + BorderColor(INACTIVE_COLOR), )) .observe(button_state_handler::>(AppState::Draw( Interpolated::Target,