From 7f6e8909e6299b7b2b8c92a2c1aa6f256a5fd203 Mon Sep 17 00:00:00 2001 From: galister <22305755+galister@users.noreply.github.com> Date: Fri, 29 Mar 2024 12:48:31 +0100 Subject: [PATCH] feat: highlight toggle buttons when on --- src/gui/modular/button.rs | 37 ++++++++++++++++++++++++++++++++++++- src/res/settings.yaml | 2 ++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/gui/modular/button.rs b/src/gui/modular/button.rs index edf5a29..4bc0b98 100644 --- a/src/gui/modular/button.rs +++ b/src/gui/modular/button.rs @@ -6,7 +6,7 @@ use std::{ time::{Duration, Instant}, }; -use glam::{Quat, Vec3A}; +use glam::{Quat, Vec3A, Vec4}; use serde::Deserialize; use crate::{ @@ -40,6 +40,12 @@ pub enum Axis { Z, } +#[derive(Deserialize, Clone)] +pub enum HighlightTest { + NotificationSounds, + Notifications, +} + #[derive(Deserialize, Clone)] pub enum SystemAction { ToggleNotificationSounds, @@ -167,6 +173,7 @@ pub struct ButtonData { pub(super) long_middle_up: Option>, pub(super) scroll_down: Option>, pub(super) scroll_up: Option>, + pub(super) highlight: Option, } pub fn modular_button_init(button: &mut ModularControl, data: &ButtonData) { @@ -174,6 +181,7 @@ pub fn modular_button_init(button: &mut ModularControl, data: &ButtonData) { button.on_press = Some(modular_button_dn); button.on_release = Some(modular_button_up); button.on_scroll = Some(modular_button_scroll); + button.test_highlight = Some(modular_button_highlight); } fn modular_button_dn( @@ -265,6 +273,33 @@ fn modular_button_scroll(button: &mut ModularControl, _: &mut (), app: &mut AppS } } +fn modular_button_highlight( + button: &ModularControl, + _: &mut (), + app: &mut AppState, +) -> Option { + // want panic + let ModularData::Button(data) = button.state.as_ref().unwrap() else { + panic!("modular_button_highlight: button state is not Button"); + }; + + if let Some(test) = &data.highlight { + match test { + HighlightTest::NotificationSounds => { + if app.session.config.notifications_sound_enabled { + return Some(Vec4::new(1.0, 1.0, 1.0, 0.5)); + } + } + HighlightTest::Notifications => { + if app.session.config.notifications_enabled { + return Some(Vec4::new(1.0, 1.0, 1.0, 0.5)); + } + } + } + } + None +} + fn handle_action(action: &ButtonAction, press: &mut PressData, app: &mut AppState) { match action { ButtonAction::Exec { command, toast } => run_exec(command, toast, press, app), diff --git a/src/res/settings.yaml b/src/res/settings.yaml index 9521aa1..6504da5 100644 --- a/src/res/settings.yaml +++ b/src/res/settings.yaml @@ -533,6 +533,7 @@ elements: click_down: - type: System action: ToggleNotifications + highlight: Notifications - type: Button rect: [330, 555, 220, 30] @@ -543,6 +544,7 @@ elements: click_down: - type: System action: ToggleNotificationSounds + highlight: NotificationSounds - type: Panel rect: [50, 605, 500, 1]