Skip to content

Commit

Permalink
Edit commands animation
Browse files Browse the repository at this point in the history
Still to be done: undo/redo animation.
  • Loading branch information
PetrGlad committed Dec 12, 2023
1 parent d06063d commit 0b5710b
Show file tree
Hide file tree
Showing 7 changed files with 233 additions and 119 deletions.
19 changes: 9 additions & 10 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,10 @@ impl eframe::App for EmApp {
if ui.input(|i| i.key_pressed(egui::Key::Space)) {
self.toggle_pause();
}
ui.heading(format!(
"🌲 {} [{} / {}]",
self.stave.history.directory.display(),
self.stave.history.version(),
self.stave.track_version.to_string()
));

{
let h = self.stave.history.borrow();
ui.heading(format!("🌲 {} [{}]", h.directory.display(), h.version()));
}
StripBuilder::new(ui)
.size(Size::remainder())
.size(Size::exact(20.0))
Expand Down Expand Up @@ -182,17 +179,19 @@ impl eframe::App for EmApp {
self.export();
}
if ui.button("⤵ Undo").clicked() {
self.stave.history.undo(&mut vec![]); // TODO (implement) changes highlighting
self.stave.history.borrow_mut().undo(&mut vec![]);
// TODO (implement) changes highlighting
}
if ui.button("⤴ Redo").clicked() {
self.stave.history.redo(&mut vec![]); // TODO (implement) changes highlighting
self.stave.history.borrow_mut().redo(&mut vec![]);
// TODO (implement) changes highlighting
}
});
ui.horizontal(|ui| {
// Status line
ui.label(format!(
"track_len={} n_sel={} t_sel={} at={}s ",
self.stave.history.with_track(|t| t.events.len()),
self.stave.history.borrow().with_track(|t| t.events.len()),
self.stave.note_selection.count(),
self.stave.time_selection.as_ref().map_or(
"()".to_string(),
Expand Down
8 changes: 8 additions & 0 deletions src/changeset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ impl EventAction {
}
}

pub fn before(&self) -> Option<&TrackEvent> {
match self {
EventAction::Delete(ev) => Some(ev),
EventAction::Update(ev, _) => Some(ev),
EventAction::Insert(_) => None,
}
}

pub fn after(&self) -> Option<&TrackEvent> {
match self {
EventAction::Delete(_) => None,
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub fn main() {
}

{
let track_midi_source = TrackSource::new(project.history.track.clone());
let track_midi_source = TrackSource::new(project.history.borrow().track.clone());
engine_command_sender
.send(Box::new(|engine| engine.add(Box::new(track_midi_source))))
.unwrap();
Expand Down
5 changes: 3 additions & 2 deletions src/project.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use std::cell::RefCell;
use std::fs;
use std::path::PathBuf;

use crate::track_history::TrackHistory;

pub struct Project {
pub history: TrackHistory,
pub history: RefCell<TrackHistory>,
pub home_path: PathBuf,
}

Expand Down Expand Up @@ -37,7 +38,7 @@ impl Project {
history.open();
Project {
home_path: directory,
history,
history: RefCell::new(history),
}
}
}
Loading

0 comments on commit 0b5710b

Please sign in to comment.