Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Control the effect options UI inside Effects
Browse files Browse the repository at this point in the history
4JX committed Nov 18, 2024
1 parent ce13415 commit ac33f07
Showing 21 changed files with 151 additions and 112 deletions.
8 changes: 4 additions & 4 deletions app/src/cli.rs
Original file line number Diff line number Diff line change
@@ -6,8 +6,8 @@ use strum::IntoEnumIterator;
use thiserror::Error;

use crate::{
effects::{self, custom_effect::CustomEffect, ManagerCreationError},
enums::{Brightness, Direction, Effects},
manager::{self, custom_effect::CustomEffect, ManagerCreationError},
profile::{self, Profile},
};

@@ -152,7 +152,7 @@ pub fn try_cli() -> Result<GuiCommand, CliError> {
}

fn handle_cli_output(output_type: OutputType) -> Result<GuiCommand, CliError> {
let manager_result = effects::EffectManager::new(effects::OperationMode::Cli);
let manager_result = manager::EffectManager::new(manager::OperationMode::Cli);
let instance_not_unique = manager_result
.as_ref()
.err()
@@ -205,8 +205,8 @@ fn parse_cli() -> Result<CliOutput, CliError> {
[0; 12]
};

let profile = Profile {
name: "Profile".to_string(),
let mut profile = Profile {
name: None,
rgb_zones: profile::arr_to_zones(rgb_array),
effect,
direction,
2 changes: 1 addition & 1 deletion app/src/enums.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{effects::custom_effect::CustomEffect, profile::Profile};
use crate::{manager::custom_effect::CustomEffect, profile::Profile};
use serde::{Deserialize, Serialize};
use strum_macros::{Display, EnumIter, EnumString, IntoStaticStr};

69 changes: 0 additions & 69 deletions app/src/gui/effect_options.rs

This file was deleted.

2 changes: 1 addition & 1 deletion app/src/gui/menu_bar.rs
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ use egui_file::FileDialog;
use egui_notify::Toasts;
use std::{path::PathBuf, time::Duration};

use crate::{effects::custom_effect::CustomEffect, gui::modals, profile::Profile};
use crate::{gui::modals, manager::custom_effect::CustomEffect, profile::Profile};

use super::{CustomEffectState, GuiMessage};

14 changes: 6 additions & 8 deletions app/src/gui/mod.rs
Original file line number Diff line number Diff line change
@@ -21,19 +21,18 @@ use tray_icon::menu::MenuEvent;

use crate::{
cli::OutputType,
effects::{self, custom_effect::CustomEffect, EffectManager, ManagerCreationError},
enums::Effects,
manager::{self, custom_effect::CustomEffect, EffectManager, ManagerCreationError},
persist::Settings,
tray::{QUIT_ID, SHOW_ID},
};

use self::{effect_options::EffectOptions, menu_bar::MenuBarState, profile_list::ProfileList, style::Theme};
use self::{menu_bar::MenuBarState, profile_list::ProfileList, style::Theme};

mod effect_options;
mod menu_bar;
mod modals;
mod profile_list;
mod style;
pub mod style;

pub struct App {
settings: Settings,
@@ -51,7 +50,6 @@ pub struct App {

menu_bar: MenuBarState,
profile_list: ProfileList,
effect_options: EffectOptions,
global_rgb: [u8; 3],
theme: Theme,
toasts: Toasts,
@@ -74,7 +72,7 @@ impl App {
pub fn new(output: OutputType, has_tray: Arc<AtomicBool>, visible: Arc<AtomicBool>) -> Self {
let (gui_tx, gui_rx) = crossbeam_channel::unbounded::<GuiMessage>();

let manager_result = EffectManager::new(effects::OperationMode::Gui);
let manager_result = EffectManager::new(manager::OperationMode::Gui);

let instance_not_unique = if let Err(err) = &manager_result {
&ManagerCreationError::InstanceAlreadyRunning == err.current_context()
@@ -106,7 +104,6 @@ impl App {

menu_bar: MenuBarState::new(gui_tx_c),
profile_list: ProfileList::new(profiles),
effect_options: EffectOptions::default(),
global_rgb: [0; 3],
theme: Theme::default(),
toasts: Toasts::default(),
@@ -247,7 +244,8 @@ impl eframe::App for App {
ui.set_width(res.inner.rect.width());

ui.add_enabled_ui(matches!(self.custom_effect, CustomEffectState::None), |ui| {
self.effect_options.show(ui, &mut self.settings.current_profile, &mut self.profile_changed, &self.theme.spacing);
let mut effect = self.settings.current_profile.effect;
effect.show_ui(ui, &mut self.settings.current_profile, &mut self.profile_changed, &self.theme);
});

self.profile_list
7 changes: 4 additions & 3 deletions app/src/gui/profile_list.rs
Original file line number Diff line number Diff line change
@@ -35,13 +35,13 @@ impl ProfileList {

modal.buttons(ui, |ui| {
let is_empty = self.new_profile_name.is_empty();
let name_not_unique = self.profiles.iter().any(|prof| prof.name == self.new_profile_name);
let name_not_unique = self.profiles.iter().any(|prof| prof.name.as_ref() == Some(&self.new_profile_name));

modal.button(ui, "Cancel");

ui.add_enabled_ui(!is_empty && !name_not_unique, |ui| {
if modal.button(ui, "Save").clicked() {
current_profile.name = self.new_profile_name.clone();
current_profile.name = Some(self.new_profile_name.clone());
self.profiles.push(current_profile.clone());
};
});
@@ -99,7 +99,8 @@ impl ProfileList {
ScrollArea::vertical().auto_shrink([false; 2]).show(ui, |ui| {
ui.horizontal_wrapped(|ui| {
for prof in &self.profiles {
if ui.selectable_value(current_profile, prof.clone(), &prof.name).clicked() {
let name = prof.name.as_ref().map(|s| s.as_str()).unwrap_or("Unnamed");
if ui.selectable_value(current_profile, prof.clone(), name).clicked() {
*changed = true;
*custom_effect_state = CustomEffectState::None;
};
2 changes: 1 addition & 1 deletion app/src/main.rs
Original file line number Diff line number Diff line change
@@ -4,9 +4,9 @@
mod cli;
#[cfg(target_os = "windows")]
mod console;
mod effects;
mod enums;
mod gui;
mod manager;
mod persist;
mod profile;
mod tray;
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -9,13 +9,15 @@ use fast_image_resize as fr;
use fr::Resizer;
use scrap::{Capturer, Display, Frame, TraitCapturer, TraitPixelBuffer};

use crate::manager::Inner;

#[derive(Clone, Copy)]
struct ScreenDimensions {
src: (u32, u32),
dest: (u32, u32),
}

pub fn play(manager: &mut super::Inner, fps: u8, saturation_boost: f32) {
pub fn play(manager: &mut Inner, fps: u8, saturation_boost: f32) {
while !manager.stop_signals.manager_stop_signal.load(Ordering::SeqCst) {
//Display setup
let display = Display::all().unwrap().remove(0);
Original file line number Diff line number Diff line change
@@ -2,7 +2,9 @@ use std::{sync::atomic::Ordering, thread, time::Duration};

use rand::Rng;

pub fn play(manager: &mut super::Inner, thread_rng: &mut rand::rngs::ThreadRng) {
use crate::manager::Inner;

pub fn play(manager: &mut Inner, thread_rng: &mut rand::rngs::ThreadRng) {
let xmas_color_array = [[255, 10, 10], [255, 255, 20], [30, 255, 30], [70, 70, 255]];
let subeffect_count = 4;
let mut last_subeffect = -1;
62 changes: 62 additions & 0 deletions app/src/manager/effects/default_ui.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
use eframe::egui::{ComboBox, Slider, Ui};
use legion_rgb_driver::SPEED_RANGE;
use strum::IntoEnumIterator;

use crate::{
enums::{Brightness, Direction},
gui::style::SpacingStyle,
profile::Profile,
};

const COMBOBOX_WIDTH: f32 = 20.0;

pub fn show(ui: &mut Ui, profile: &mut Profile, update_lights: &mut bool, spacing: &SpacingStyle) {
ui.scope(|ui| {
ui.style_mut().spacing.item_spacing = spacing.default;

show_brightness(ui, profile, update_lights);
show_direction(ui, profile, update_lights);
show_effect_settings(ui, profile, update_lights);
});
}

pub fn show_brightness(ui: &mut Ui, profile: &mut Profile, update_lights: &mut bool) {
ComboBox::from_label("Brightness")
.width(COMBOBOX_WIDTH)
.selected_text({
let text: &'static str = profile.brightness.into();
text
})
.show_ui(ui, |ui| {
for val in Brightness::iter() {
let text: &'static str = val.into();
*update_lights |= ui.selectable_value(&mut profile.brightness, val, text).changed();
}
});
}

pub fn show_direction(ui: &mut Ui, profile: &mut Profile, update_lights: &mut bool) {
ui.add_enabled_ui(profile.effect.takes_direction(), |ui| {
ComboBox::from_label("Direction")
.width(COMBOBOX_WIDTH)
.selected_text({
let text: &'static str = profile.direction.into();
text
})
.show_ui(ui, |ui| {
for val in Direction::iter() {
let text: &'static str = val.into();
*update_lights |= ui.selectable_value(&mut profile.direction, val, text).changed();
}
});
});
}

pub fn show_effect_settings(ui: &mut Ui, profile: &mut Profile, update_lights: &mut bool) {
let range = if profile.effect.is_built_in() { SPEED_RANGE } else { 1..=10 };

ui.horizontal(|ui| {
*update_lights |= ui.add_enabled(profile.effect.takes_speed(), Slider::new(&mut profile.speed, range)).changed();
ui.label("Speed");
});
}
4 changes: 2 additions & 2 deletions app/src/effects/disco.rs → app/src/manager/effects/disco.rs
Original file line number Diff line number Diff line change
@@ -2,9 +2,9 @@ use std::{sync::atomic::Ordering, thread, time::Duration};

use rand::Rng;

use crate::profile::Profile;
use crate::{manager::Inner, profile::Profile};

pub fn play(manager: &mut super::Inner, p: &Profile, thread_rng: &mut rand::rngs::ThreadRng) {
pub fn play(manager: &mut Inner, p: &Profile, thread_rng: &mut rand::rngs::ThreadRng) {
while !manager.stop_signals.manager_stop_signal.load(Ordering::SeqCst) {
let colors = [[255, 0, 0], [255, 255, 0], [0, 255, 0], [0, 255, 255], [0, 0, 255], [255, 0, 255]];
let colors_index = thread_rng.gen_range(0..6);
4 changes: 2 additions & 2 deletions app/src/effects/fade.rs → app/src/manager/effects/fade.rs
Original file line number Diff line number Diff line change
@@ -9,9 +9,9 @@ use std::{

use device_query::DeviceQuery;

use crate::profile::Profile;
use crate::{manager::Inner, profile::Profile};

pub fn play(manager: &mut super::Inner, p: &Profile) {
pub fn play(manager: &mut Inner, p: &Profile) {
let stop_signals = manager.stop_signals.clone();

let kill_thread = Arc::new(AtomicBool::new(false));
Original file line number Diff line number Diff line change
@@ -2,9 +2,9 @@ use std::{sync::atomic::Ordering, thread, time::Duration};

use rand::{rngs::ThreadRng, Rng};

use crate::profile::Profile;
use crate::{manager::Inner, profile::Profile};

pub fn play(manager: &mut super::Inner, p: &Profile, thread_rng: &mut ThreadRng) {
pub fn play(manager: &mut Inner, p: &Profile, thread_rng: &mut ThreadRng) {
while !manager.stop_signals.manager_stop_signal.load(Ordering::SeqCst) {
let profile_array = p.rgb_array();

42 changes: 42 additions & 0 deletions app/src/manager/effects/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use default_ui::{show_brightness, show_direction};
use eframe::egui::{self, Slider};

use crate::{enums::Effects, profile::Profile};

pub mod ambient;
pub mod christmas;
pub mod default_ui;
pub mod disco;
pub mod fade;
pub mod lightning;
pub mod ripple;
pub mod swipe;
pub mod temperature;
pub mod zones;

impl Effects {
pub fn show_ui(&mut self, ui: &mut egui::Ui, profile: &mut Profile, update_lights: &mut bool, theme: &crate::gui::style::Theme) {
match self {
Effects::AmbientLight { fps, saturation_boost } => {
ui.scope(|ui| {
ui.style_mut().spacing.item_spacing = theme.spacing.default;

show_brightness(ui, profile, update_lights);
show_direction(ui, profile, update_lights);

ui.horizontal(|ui| {
*update_lights |= ui.add(Slider::new(fps, 1..=60)).changed();
ui.label("FPS");
});
ui.horizontal(|ui| {
*update_lights |= ui.add(Slider::new(saturation_boost, 0.0..=1.0)).changed();
ui.label("Saturation Boost");
});
});
}
_ => {
default_ui::show(ui, profile, update_lights, &theme.spacing);
}
}
}
}
Loading

0 comments on commit ac33f07

Please sign in to comment.