OutlinerState

Struct OutlinerState 

Source
pub struct OutlinerState<Id>
where Id: Hash + Eq + Clone + Send + Sync,
{ /* 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 implement Hash, Eq, and Clone.

§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>
where Id: Hash + Eq + Clone + Send + Sync,

Source

pub fn load(ctx: &Context, id: Id) -> Self
where 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 from
  • id - The unique identifier for this outliner instance
§Examples
let state = OutlinerState::<String>::load(ctx, egui::Id::new("my_outliner"));
Source

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 in
  • id - 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"));
Source

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()));
Source

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()));
Source

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 modify
  • expanded - true to expand the node, false to 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()));
Source

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()));
Source

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 editing
  • initial_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()));
Source

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()));
Source

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.

Source

pub fn editing_text(&self) -> &str

Returns a reference to the editing text.

Source

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());
Source

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());
Source

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
Source

pub fn last_selected(&self) -> Option<&Id>

Returns the ID of the last selected node, if any.

Source

pub fn start_box_selection(&mut self, start_pos: Pos2)

Starts a box selection operation.

§Parameters
  • start_pos - The starting position in screen coordinates
Source

pub fn box_selection(&self) -> Option<&BoxSelectionState>

Returns the current box selection state, if any.

Source

pub fn end_box_selection(&mut self)

Ends the current box selection operation.

Source

pub fn set_dragging_nodes(&mut self, nodes: Vec<Id>)

Sets the nodes being dragged in a multi-drag operation.

Source

pub fn dragging_nodes(&self) -> &[Id]

Returns the nodes being dragged in a multi-drag operation.

Source

pub fn clear_dragging_nodes(&mut self)

Clears the dragging nodes list.

Trait Implementations§

Source§

impl<Id> Clone for OutlinerState<Id>
where Id: Hash + Eq + Clone + Send + Sync + Clone,

Source§

fn clone(&self) -> OutlinerState<Id>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Id> Debug for OutlinerState<Id>
where Id: Hash + Eq + Clone + Send + Sync + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Id> Default for OutlinerState<Id>
where Id: Hash + Eq + Clone + Send + Sync,

Source§

fn default() -> Self

Creates a new outliner state with no expanded nodes and no editing node.

Auto Trait Implementations§

§

impl<Id> Freeze for OutlinerState<Id>
where Id: Freeze,

§

impl<Id> RefUnwindSafe for OutlinerState<Id>
where Id: RefUnwindSafe,

§

impl<Id> Send for OutlinerState<Id>

§

impl<Id> Sync for OutlinerState<Id>

§

impl<Id> Unpin for OutlinerState<Id>
where Id: Unpin,

§

impl<Id> UnwindSafe for OutlinerState<Id>
where Id: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> SerializableAny for T
where T: 'static + Any + Clone + for<'a> Send + Sync,