pub struct OutlinerState<Id>{ /* private fields */ }Expand description
State for an outliner widget instance.
This struct tracks which collection nodes are expanded and which node (if any) is currently being edited. The state is generic over the node ID type and integrates with egui’s memory system for automatic persistence.
§Type Parameters
Id- The type used to identify nodes. Must implementHash,Eq, andClone.
§Examples
use egui_arbor::OutlinerState;
use std::collections::HashSet;
let mut state = OutlinerState::<String>::default();
// Toggle expansion state
state.toggle_expanded(&"node1".to_string());
assert!(state.is_expanded(&"node1".to_string()));
// Start editing a node
state.start_editing("node2".to_string(), "Node 2".to_string());
assert!(state.is_editing(&"node2".to_string()));Implementations§
Source§impl<Id> OutlinerState<Id>
impl<Id> OutlinerState<Id>
Sourcepub fn load(ctx: &Context, id: Id) -> Selfwhere
Id: 'static,
pub fn load(ctx: &Context, id: Id) -> Selfwhere
Id: 'static,
Loads the outliner state from egui’s memory system.
If no state exists for the given ID, returns a default empty state.
§Parameters
ctx- The egui context to load state fromid- The unique identifier for this outliner instance
§Examples
let state = OutlinerState::<String>::load(ctx, egui::Id::new("my_outliner"));Sourcepub fn store(&self, ctx: &Context, id: Id)where
Id: 'static,
pub fn store(&self, ctx: &Context, id: Id)where
Id: 'static,
Stores the outliner state to egui’s memory system.
The state will be persisted across frames and can be retrieved using
load with the same ID.
§Parameters
ctx- The egui context to store state inid- The unique identifier for this outliner instance
§Examples
let mut state = OutlinerState::<String>::default();
state.toggle_expanded(&"node1".to_string());
state.store(ctx, egui::Id::new("my_outliner"));Sourcepub fn is_expanded(&self, id: &Id) -> bool
pub fn is_expanded(&self, id: &Id) -> bool
Checks if a node is currently expanded.
§Parameters
id- The ID of the node to check
§Returns
true if the node is expanded, false otherwise.
§Examples
let mut state = OutlinerState::<String>::default();
state.set_expanded(&"node1".to_string(), true);
assert!(state.is_expanded(&"node1".to_string()));Sourcepub fn toggle_expanded(&mut self, id: &Id)
pub fn toggle_expanded(&mut self, id: &Id)
Toggles the expansion state of a node.
If the node is currently expanded, it will be collapsed. If the node is currently collapsed, it will be expanded.
§Parameters
id- The ID of the node to toggle
§Examples
let mut state = OutlinerState::<String>::default();
state.toggle_expanded(&"node1".to_string());
assert!(state.is_expanded(&"node1".to_string()));
state.toggle_expanded(&"node1".to_string());
assert!(!state.is_expanded(&"node1".to_string()));Sourcepub fn set_expanded(&mut self, id: &Id, expanded: bool)
pub fn set_expanded(&mut self, id: &Id, expanded: bool)
Sets the expansion state of a node.
§Parameters
id- The ID of the node to modifyexpanded-trueto expand the node,falseto collapse it
§Examples
let mut state = OutlinerState::<String>::default();
state.set_expanded(&"node1".to_string(), true);
assert!(state.is_expanded(&"node1".to_string()));
state.set_expanded(&"node1".to_string(), false);
assert!(!state.is_expanded(&"node1".to_string()));Sourcepub fn is_editing(&self, id: &Id) -> bool
pub fn is_editing(&self, id: &Id) -> bool
Checks if a node is currently being edited.
§Parameters
id- The ID of the node to check
§Returns
true if the node is being edited, false otherwise.
§Examples
let mut state = OutlinerState::<String>::default();
state.start_editing("node1".to_string(), "Node 1".to_string());
assert!(state.is_editing(&"node1".to_string()));Sourcepub fn start_editing(&mut self, id: Id, initial_text: String)
pub fn start_editing(&mut self, id: Id, initial_text: String)
Starts editing a node.
This will stop editing any previously edited node, as only one node can be edited at a time.
§Parameters
id- The ID of the node to start editinginitial_text- The initial text to display in the edit field
§Examples
let mut state = OutlinerState::<String>::default();
state.start_editing("node1".to_string(), "Initial Name".to_string());
assert!(state.is_editing(&"node1".to_string()));Sourcepub fn stop_editing(&mut self)
pub fn stop_editing(&mut self)
Stops editing the currently edited node, if any.
§Examples
let mut state = OutlinerState::<String>::default();
state.start_editing("node1".to_string(), "Name".to_string());
state.stop_editing();
assert!(!state.is_editing(&"node1".to_string()));Sourcepub fn editing_text_mut(&mut self) -> &mut String
pub fn editing_text_mut(&mut self) -> &mut String
Returns a mutable reference to the editing text.
This allows the text edit widget to modify the text directly.
Sourcepub fn editing_text(&self) -> &str
pub fn editing_text(&self) -> &str
Returns a reference to the editing text.
Sourcepub fn drag_drop(&self) -> &DragDropState<Id>
pub fn drag_drop(&self) -> &DragDropState<Id>
Returns a reference to the drag-drop state.
§Examples
let state = OutlinerState::<String>::default();
assert!(!state.drag_drop().is_dragging());Sourcepub fn drag_drop_mut(&mut self) -> &mut DragDropState<Id>
pub fn drag_drop_mut(&mut self) -> &mut DragDropState<Id>
Returns a mutable reference to the drag-drop state.
§Examples
let mut state = OutlinerState::<String>::default();
state.drag_drop_mut().start_drag("node1".to_string());
assert!(state.drag_drop().is_dragging());Sourcepub fn set_last_selected(&mut self, id: Option<Id>)
pub fn set_last_selected(&mut self, id: Option<Id>)
Sets the last selected node for shift-click range selection.
§Parameters
id- The ID of the last selected node
Sourcepub fn last_selected(&self) -> Option<&Id>
pub fn last_selected(&self) -> Option<&Id>
Returns the ID of the last selected node, if any.
Sourcepub fn start_box_selection(&mut self, start_pos: Pos2)
pub fn start_box_selection(&mut self, start_pos: Pos2)
Starts a box selection operation.
§Parameters
start_pos- The starting position in screen coordinates
Sourcepub fn box_selection(&self) -> Option<&BoxSelectionState>
pub fn box_selection(&self) -> Option<&BoxSelectionState>
Returns the current box selection state, if any.
Sourcepub fn end_box_selection(&mut self)
pub fn end_box_selection(&mut self)
Ends the current box selection operation.
Sourcepub fn set_dragging_nodes(&mut self, nodes: Vec<Id>)
pub fn set_dragging_nodes(&mut self, nodes: Vec<Id>)
Sets the nodes being dragged in a multi-drag operation.
Sourcepub fn dragging_nodes(&self) -> &[Id]
pub fn dragging_nodes(&self) -> &[Id]
Returns the nodes being dragged in a multi-drag operation.
Sourcepub fn clear_dragging_nodes(&mut self)
pub fn clear_dragging_nodes(&mut self)
Clears the dragging nodes list.
Trait Implementations§
Source§impl<Id> Clone for OutlinerState<Id>
impl<Id> Clone for OutlinerState<Id>
Source§fn clone(&self) -> OutlinerState<Id>
fn clone(&self) -> OutlinerState<Id>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more