Skip to content

Commit

Permalink
Simpler system for "last active scene"
Browse files Browse the repository at this point in the history
  • Loading branch information
anselanza committed Mar 7, 2024
1 parent 563ff01 commit 5ab76cf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/model.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{
sync::{Arc, Mutex},
thread::JoinHandle,
time::{Duration, SystemTime},
time::Duration,
};

use egui::Color32;
Expand Down Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion src/project/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub struct Scene {
#[serde(skip)]
pub is_editing: bool,
#[serde(skip)]
pub last_active: Option<SystemTime>,
pub last_active: bool,
}

impl Project {
Expand Down
28 changes: 17 additions & 11 deletions src/ui/scenes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
}

Expand All @@ -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() {
Expand Down Expand Up @@ -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() {
Expand All @@ -155,7 +161,6 @@ pub fn render_scenes(model: &mut Model, ui: &mut Ui) {
}
});
}
ui.separator();
});
}
});
Expand Down Expand Up @@ -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;
}
}
Expand Down

0 comments on commit 5ab76cf

Please sign in to comment.