feat: highlight toggle buttons when on

This commit is contained in:
galister
2024-03-29 12:48:31 +01:00
parent 4843aeef5d
commit 7f6e8909e6
2 changed files with 38 additions and 1 deletions

View File

@@ -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<Vec<ButtonAction>>,
pub(super) scroll_down: Option<Vec<ButtonAction>>,
pub(super) scroll_up: Option<Vec<ButtonAction>>,
pub(super) highlight: Option<HighlightTest>,
}
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<Vec4> {
// 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),