From 5ab76cf933828b34c2ffddc7cd6475ac9d9a94d6 Mon Sep 17 00:00:00 2001 From: stephen Date: Thu, 7 Mar 2024 11:54:52 +0100 Subject: [PATCH] Simpler system for "last active scene" --- src/model.rs | 4 ++-- src/project/mod.rs | 2 +- src/ui/scenes.rs | 28 +++++++++++++++++----------- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/model.rs b/src/model.rs index 6bc912c..7fc237d 100644 --- a/src/model.rs +++ b/src/model.rs @@ -1,7 +1,7 @@ use std::{ sync::{Arc, Mutex}, thread::JoinHandle, - time::{Duration, SystemTime}, + time::Duration, }; use egui::Color32; @@ -425,7 +425,7 @@ impl Model { { Some((index, scene)) => { debug!("Found scene \"{}\" at index {}", &scene.label, index); - scene.last_active = Some(SystemTime::now()); + scene.last_active = true; self.apply_scene(index, msg.ms, msg.fixture_labels); } None => error!("Failed to find matching scene for \"{}\"", &msg.scene_label), diff --git a/src/project/mod.rs b/src/project/mod.rs index d819c5b..8243dea 100644 --- a/src/project/mod.rs +++ b/src/project/mod.rs @@ -42,7 +42,7 @@ pub struct Scene { #[serde(skip)] pub is_editing: bool, #[serde(skip)] - pub last_active: Option, + pub last_active: bool, } impl Project { diff --git a/src/ui/scenes.rs b/src/ui/scenes.rs index 86bf0c6..8074be3 100644 --- a/src/ui/scenes.rs +++ b/src/ui/scenes.rs @@ -45,7 +45,7 @@ pub fn render_scenes(model: &mut Model, ui: &mut Ui) { label, state, is_editing: true, - last_active: None + last_active: false }); } @@ -63,12 +63,12 @@ pub fn render_scenes(model: &mut Model, ui: &mut Ui) { { go_scene = Some((scene_index, None)); // go to scene "immediately" }; - if let Some(t) = scene.last_active { - let progress = t.elapsed().unwrap().as_secs_f32() / 1.0; - if progress >= 1.0 { scene.last_active = None; } - ui.add(Spinner::new()); + if scene.last_active { + ui.label("★"); } }); + ui.separator(); + ui.horizontal(|ui| { ui.label("Transition:"); if ui.button("1s").clicked() { @@ -138,10 +138,16 @@ pub fn render_scenes(model: &mut Model, ui: &mut Ui) { }); }); } - if ui.button("Save ✅").clicked() { - update_scene = Some(scene_index); - edit_scene = None; - } + ui.horizontal(|ui| { + if ui.button("Save ✅").clicked() { + update_scene = Some(scene_index); + edit_scene = None; + } + if ui.button("Cancel ❌").clicked() { + edit_scene = None; + scene.is_editing = false; + } + }); } else { ui.horizontal(|ui| { if ui.button("✏").clicked() { @@ -155,7 +161,6 @@ pub fn render_scenes(model: &mut Model, ui: &mut Ui) { } }); } - ui.separator(); }); } }); @@ -207,9 +212,10 @@ pub fn render_scenes(model: &mut Model, ui: &mut Ui) { for (index, scene) in model.project.scenes.iter_mut().enumerate() { if index == scene_index { // This one - scene.last_active = Some(SystemTime::now()); + scene.last_active = true; } else { // Others + scene.last_active = false; scene.is_editing = false; } }