feat: highlight toggle buttons when on
This commit is contained in:
@@ -6,7 +6,7 @@ use std::{
|
|||||||
time::{Duration, Instant},
|
time::{Duration, Instant},
|
||||||
};
|
};
|
||||||
|
|
||||||
use glam::{Quat, Vec3A};
|
use glam::{Quat, Vec3A, Vec4};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -40,6 +40,12 @@ pub enum Axis {
|
|||||||
Z,
|
Z,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Clone)]
|
||||||
|
pub enum HighlightTest {
|
||||||
|
NotificationSounds,
|
||||||
|
Notifications,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Clone)]
|
#[derive(Deserialize, Clone)]
|
||||||
pub enum SystemAction {
|
pub enum SystemAction {
|
||||||
ToggleNotificationSounds,
|
ToggleNotificationSounds,
|
||||||
@@ -167,6 +173,7 @@ pub struct ButtonData {
|
|||||||
pub(super) long_middle_up: Option<Vec<ButtonAction>>,
|
pub(super) long_middle_up: Option<Vec<ButtonAction>>,
|
||||||
pub(super) scroll_down: Option<Vec<ButtonAction>>,
|
pub(super) scroll_down: Option<Vec<ButtonAction>>,
|
||||||
pub(super) scroll_up: 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) {
|
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_press = Some(modular_button_dn);
|
||||||
button.on_release = Some(modular_button_up);
|
button.on_release = Some(modular_button_up);
|
||||||
button.on_scroll = Some(modular_button_scroll);
|
button.on_scroll = Some(modular_button_scroll);
|
||||||
|
button.test_highlight = Some(modular_button_highlight);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn modular_button_dn(
|
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) {
|
fn handle_action(action: &ButtonAction, press: &mut PressData, app: &mut AppState) {
|
||||||
match action {
|
match action {
|
||||||
ButtonAction::Exec { command, toast } => run_exec(command, toast, press, app),
|
ButtonAction::Exec { command, toast } => run_exec(command, toast, press, app),
|
||||||
|
|||||||
@@ -533,6 +533,7 @@ elements:
|
|||||||
click_down:
|
click_down:
|
||||||
- type: System
|
- type: System
|
||||||
action: ToggleNotifications
|
action: ToggleNotifications
|
||||||
|
highlight: Notifications
|
||||||
|
|
||||||
- type: Button
|
- type: Button
|
||||||
rect: [330, 555, 220, 30]
|
rect: [330, 555, 220, 30]
|
||||||
@@ -543,6 +544,7 @@ elements:
|
|||||||
click_down:
|
click_down:
|
||||||
- type: System
|
- type: System
|
||||||
action: ToggleNotificationSounds
|
action: ToggleNotificationSounds
|
||||||
|
highlight: NotificationSounds
|
||||||
|
|
||||||
- type: Panel
|
- type: Panel
|
||||||
rect: [50, 605, 500, 1]
|
rect: [50, 605, 500, 1]
|
||||||
|
|||||||
Reference in New Issue
Block a user