Skip to content

Commit

Permalink
Added setting edit fields for shortcut action
Browse files Browse the repository at this point in the history
  • Loading branch information
samclane committed Oct 28, 2024
1 parent 2ec5b16 commit a1f002f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
42 changes: 40 additions & 2 deletions src/action.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 4 additions & 3 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a1f002f

Please sign in to comment.