pub struct ModeState { /* private fields */ }Expand description
Named mode system with independent screen stacks.
Each mode contains its own ScreenState. Switching modes preserves
the previous mode’s screen stack, focus, and hook state.
§Example
let mut modes = slt::ModeState::new("app", "home");
modes.add_mode("settings", "general");
slt::run(|ui| {
if ui.key('1') { modes.switch_mode("app"); }
if ui.key('2') { modes.switch_mode("settings"); }
let mode = modes.active_mode().to_string();
ui.text(format!("Mode: {}", mode));
});Implementations§
Source§impl ModeState
impl ModeState
Sourcepub fn new(mode: impl Into<String>, screen: impl Into<String>) -> Self
pub fn new(mode: impl Into<String>, screen: impl Into<String>) -> Self
Create a mode system with an initial mode and screen.
Sourcepub fn add_mode(&mut self, mode: impl Into<String>, screen: impl Into<String>)
pub fn add_mode(&mut self, mode: impl Into<String>, screen: impl Into<String>)
Add a new mode with an initial screen.
Sourcepub fn switch_mode(&mut self, mode: impl Into<String>)
pub fn switch_mode(&mut self, mode: impl Into<String>)
Switch to a different mode. The mode must have been added with Self::add_mode.
Panics if the mode does not exist. For a non-panicking variant that
reports success, use Self::try_switch_mode.
Sourcepub fn try_switch_mode(&mut self, mode: impl Into<String>) -> bool
pub fn try_switch_mode(&mut self, mode: impl Into<String>) -> bool
Switch modes, returning true when the mode exists and the switch
happened, or false when the mode has not been registered via
Self::add_mode.
Prefer this over Self::switch_mode when the mode name comes from
user input, key bindings, or anywhere the value could be unexpected
at runtime — an unknown mode should not crash the host application.
Sourcepub fn active_mode(&self) -> &str
pub fn active_mode(&self) -> &str
Return the active mode name.
Sourcepub fn screens(&self) -> &ScreenState
pub fn screens(&self) -> &ScreenState
Get a reference to the active mode’s screen state.
Sourcepub fn screens_mut(&mut self) -> &mut ScreenState
pub fn screens_mut(&mut self) -> &mut ScreenState
Get a mutable reference to the active mode’s screen state.