yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
tree_undo_stack.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_LAYOUT_LAYOUT_DESIGNER_TREE_UNDO_STACK_H_
2#define YAZE_APP_EDITOR_LAYOUT_LAYOUT_DESIGNER_TREE_UNDO_STACK_H_
3
4#include <cstddef>
5#include <vector>
6
8
9namespace yaze {
10namespace editor {
11namespace layout_designer {
12
13// Snapshot-based undo/redo for the Layout Designer. Stores full DockTree
14// clones so any mutation is reversible without per-operation delta math.
15// The stack is bounded (kDefaultMaxSteps = 64 entries) to keep memory
16// predictable even for deeply-edited trees. Designer-local — no
17// integration with the editor-wide undo system.
19 public:
20 static constexpr std::size_t kDefaultMaxSteps = 64;
21
22 explicit TreeUndoStack(std::size_t max_steps = kDefaultMaxSteps);
23
24 // Snapshot the current state before a mutation. Clears redo history
25 // (a new timeline invalidates the branch the user was previously
26 // stepping back through).
27 void Push(const DockTree& current);
28
29 bool CanUndo() const { return !undo_.empty(); }
30 bool CanRedo() const { return !redo_.empty(); }
31
32 // Pop the most recent snapshot into `*current`, moving the replaced
33 // `*current` onto the redo stack. No-op when `current` is null or the
34 // undo stack is empty; returns true on successful mutation.
35 bool Undo(DockTree* current);
36 bool Redo(DockTree* current);
37
38 // Discard the most recent Push() without touching `*current` or the
39 // redo stack. Used by callers that speculatively snapshot before a
40 // mutation that then refuses (validation failure, etc.) so the stack
41 // stays clean without polluting redo history.
42 void PopLastPush();
43
44 void Clear();
45
46 std::size_t UndoDepth() const { return undo_.size(); }
47 std::size_t RedoDepth() const { return redo_.size(); }
48
49 private:
50 std::size_t max_steps_;
51 std::vector<DockTree> undo_;
52 std::vector<DockTree> redo_;
53};
54
55} // namespace layout_designer
56} // namespace editor
57} // namespace yaze
58
59#endif // YAZE_APP_EDITOR_LAYOUT_LAYOUT_DESIGNER_TREE_UNDO_STACK_H_
static constexpr std::size_t kDefaultMaxSteps
TreeUndoStack(std::size_t max_steps=kDefaultMaxSteps)