Skip to main content

Module undo

Module undo 

Source
Expand description

Shared undo / redo infrastructure.

Mirrors the C# agg-sharp IUndoRedoCommand / UndoBuffer pattern so that any subsystem — text editing, layout, graph editing — can participate in a common, extensible undo stack.

Two complementary models live here:

  • UndoBuffer — a command-history stack (do/undo/redo per named command), the general-purpose mechanism used by most subsystems.
  • undoer::Undoer — a time-coalescing state snapshot undoer (a faithful port of egui’s Undoer<State>). It suits editors that would rather diff whole-state snapshots than author explicit commands — the RichTextEdit widget snapshots {RichDoc, caret} through it, and the dialogs demo snapshots its {toggle, text}.

§Usage

use agg_gui::undo::{DoUndoActions, UndoBuffer};

let mut buf = UndoBuffer::new();

// Execute an action and make it undoable:
let v = std::rc::Rc::new(std::cell::Cell::new(0i32));
let v2 = v.clone();
buf.add_and_do(Box::new(DoUndoActions::new(
    "set value",
    move || v.set(42),
    move || v2.set(0),
)));

Re-exports§

pub use undoer::Settings;
pub use undoer::Undoer;

Modules§

undoer
Time-coalescing undo/redo history — a faithful port of egui’s egui::util::undoer::Undoer<State> (see egui-reference/crates/egui/src/util/undoer.rs).

Structs§

DoUndoActions
A command backed by two closures: one for do_it and one for undo_it.
UndoBuffer
Two-stack undo/redo history buffer.

Traits§

UndoRedoCommand
A named, reversible operation.