Struct biodivine_sketchbook::app::state::_undo_stack::UndoStack
source · pub struct UndoStack {
event_limit: usize,
payload_limit: usize,
current_payload_size: usize,
undo_stack: VecDeque<UndoStackEntry>,
redo_stack: VecDeque<UndoStackEntry>,
}
Expand description
The stack that keeps track of all the events that can be reversed.
It has a “normal” Rust API, but it also implements SessionState so that parts of it can be accessed as an app state object through events.
Fields§
§event_limit: usize
The number of events this UndoStack
is allowed to track.
Beyond this limit, the stack will start dropping the oldest events.
payload_limit: usize
The number of bytes of payload that this UndoStack
is allowed to store.
Beyond this limit, the stack will start dropping the oldest events.
current_payload_size: usize
The approximate size of all payloads stored on the undo_stack
.
Note that the redo_stack
does not count towards this value, because
entries only move there from the undo_stack
(i.e. after the payload size check)
and when we push to the undo_stack
, the redo_stack
is erased. Hence,
assuming all invariants hold, undo_stack + redo_stack < limit
, even if we
just track the undo_stack
.
undo_stack: VecDeque<UndoStackEntry>
§redo_stack: VecDeque<UndoStackEntry>
Implementations§
source§impl UndoStack
impl UndoStack
pub fn new(event_limit: usize, payload_limit: usize) -> UndoStack
pub fn can_undo(&self) -> bool
pub fn can_redo(&self) -> bool
sourcepub fn do_action(&mut self, perform: UserAction, reverse: UserAction) -> bool
pub fn do_action(&mut self, perform: UserAction, reverse: UserAction) -> bool
Notify the undo stack that a new action has been performed. This creates a new stack entry for this action. Furthermore, it erases any available “redo” actions.
Returns true
if the events were successfully saved, or false
if an error occurred,
e.g. due to excessive payload size.
sourcepub fn undo_action(&mut self) -> Option<UserAction>
pub fn undo_action(&mut self) -> Option<UserAction>
Try to undo the current top of the undo stack. This action can be later re-done using Self::redo_action. Returns None if there is no action to undo, or the “reverse” UserAction originally supplied to Self::do_action.
sourcepub fn redo_action(&mut self) -> Option<UserAction>
pub fn redo_action(&mut self) -> Option<UserAction>
Try to redo the current top of the redo stack. This action can be later un-done using Self::undo_action. Returns None if there is no action to redo, or the “perform” UserAction originally supplied to Self::do_action.
sourcefn drop_undo_event(&mut self) -> Option<UndoStackEntry>
fn drop_undo_event(&mut self) -> Option<UndoStackEntry>
Internal function to drop an UndoStackEntry from the undo_stack
.
Trait Implementations§
source§impl SessionState for UndoStack
impl SessionState for UndoStack
impl Eq for UndoStack
impl StructuralPartialEq for UndoStack
Auto Trait Implementations§
impl Freeze for UndoStack
impl RefUnwindSafe for UndoStack
impl Send for UndoStack
impl Sync for UndoStack
impl Unpin for UndoStack
impl UnwindSafe for UndoStack
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.