From a1f002f509ef11f04cd8cd5e0480b2389158e053 Mon Sep 17 00:00:00 2001 From: Sawyer McLane Date: Mon, 28 Oct 2024 10:17:15 -0600 Subject: [PATCH] Added setting edit fields for shortcut action --- src/action.rs | 42 ++++++++++++++++++++++++++++++++++++++++-- src/settings.rs | 7 ++++--- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/src/action.rs b/src/action.rs index faf4b14..a399ab8 100644 --- a/src/action.rs +++ b/src/action.rs @@ -1,10 +1,16 @@ +use eframe::egui; use lifx_core::HSBK; use serde::{Deserialize, Serialize}; use std::fmt::Display; -use crate::{color::HSBKField, device_info::DeviceInfo, LifxManager}; +use crate::{ + app::{KELVIN_RANGE, LIFX_RANGE}, + color::HSBKField, + device_info::DeviceInfo, + LifxManager, +}; -#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)] +#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, Copy)] pub enum UserAction { Refresh, TogglePower, @@ -213,6 +219,38 @@ impl UserAction { }, ] } + + pub fn ui(&mut self, ui: &mut egui::Ui) -> egui::Response { + match self { + UserAction::Refresh => ui.label("Refreshing..."), + UserAction::TogglePower => ui.label("Toggle Power"), + UserAction::SetColor { + hue, + saturation, + brightness, + kelvin, + } => { + ui.vertical(|ui| { + ui.add(egui::Slider::new(hue, LIFX_RANGE).text("Hue")); + ui.add(egui::Slider::new(saturation, LIFX_RANGE).text("Saturation")); + ui.add(egui::Slider::new(brightness, LIFX_RANGE).text("Brightness")); + ui.add(egui::Slider::new(kelvin, KELVIN_RANGE.to_range_u16()).text("Kelvin")); + }) + .response + } + UserAction::SetPower { power } => ui.checkbox(power, "Power"), + UserAction::SetBrightness { brightness } => { + ui.add(egui::Slider::new(brightness, LIFX_RANGE).text("Brightness")) + } + UserAction::SetSaturation { saturation } => { + ui.add(egui::Slider::new(saturation, LIFX_RANGE).text("Saturation")) + } + UserAction::SetKelvin { kelvin } => { + ui.add(egui::Slider::new(kelvin, KELVIN_RANGE.to_range_u16()).text("Kelvin")) + } + UserAction::SetHue { hue } => ui.add(egui::Slider::new(hue, LIFX_RANGE).text("Hue")), + } + } } impl Display for UserAction { diff --git a/src/settings.rs b/src/settings.rs index 6b99514..0a16266 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -116,11 +116,12 @@ impl MantleApp { ) .clicked() { - self.shortcut_manager.new_shortcut.action = - action.clone(); + self.shortcut_manager.new_shortcut.action = *action; } } }); + // based on selected action, show relevant fields + self.shortcut_manager.new_shortcut.action.ui(ui); ui.end_row(); egui::ComboBox::from_label("Device") @@ -193,7 +194,7 @@ impl MantleApp { self.shortcut_manager.add_shortcut( self.shortcut_manager.new_shortcut.name.clone(), self.shortcut_manager.new_shortcut.shortcut.clone(), - self.shortcut_manager.new_shortcut.action.clone(), + self.shortcut_manager.new_shortcut.action, self.shortcut_manager.new_shortcut.device.clone().unwrap(), ); // Clear the fields after adding