Add NodeEditor command history + undo/redo buttons
This commit is contained in:
parent
51546fc2a2
commit
68fd63eaff
|
@ -44,6 +44,14 @@ impl eframe::App for Application {
|
|||
egui::TopBottomPanel::top("menu_panel").show(ctx, |ui| {
|
||||
egui::menu::bar(ui, |ui| {
|
||||
egui::widgets::global_dark_light_mode_switch(ui);
|
||||
|
||||
if ui.button("Undo").clicked() {
|
||||
self.editor.undo();
|
||||
}
|
||||
|
||||
if ui.button("Redo").clicked() {
|
||||
self.editor.redo();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
use egui::{Color32, Frame, Stroke};
|
||||
use glam::Vec2;
|
||||
use ramen::command::CommandHistory;
|
||||
use ramen::node::{Edge, SlotIndex};
|
||||
use ramen::Graph;
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub struct NodeEditor {
|
||||
graph: Graph,
|
||||
cmd_history: CommandHistory,
|
||||
pointer_state: PointerState,
|
||||
}
|
||||
|
||||
|
@ -13,9 +15,18 @@ impl NodeEditor {
|
|||
pub fn from_graph(graph: Graph) -> Self {
|
||||
Self {
|
||||
graph,
|
||||
cmd_history: CommandHistory::new(),
|
||||
pointer_state: PointerState::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn undo(&mut self) {
|
||||
self.cmd_history.undo(&mut self.graph).unwrap();
|
||||
}
|
||||
|
||||
pub fn redo(&mut self) {
|
||||
self.cmd_history.redo(&mut self.graph).unwrap();
|
||||
}
|
||||
|
||||
pub fn show(&mut self, ui: &mut egui::Ui) {
|
||||
let style = ui.style();
|
||||
|
@ -90,7 +101,7 @@ impl NodeEditor {
|
|||
};
|
||||
|
||||
if let Some(cmd) = cmd {
|
||||
cmd.apply(&mut self.graph).unwrap();
|
||||
self.cmd_history.push(&mut self.graph, cmd).unwrap();
|
||||
}
|
||||
|
||||
self.pointer_state.action = PointerAction::Idle(None); // TODO idle pointer targeting
|
||||
|
|
Loading…
Reference in New Issue