pub struct ItemTree<T>{ /* private fields */ }Expand description
Generic in-memory item tree (S11).
T: Clone + Debug + Send + Sync + 'static mirrors the iced reference
implementation’s bounds. No additional bounds are imposed by ItemTree
itself; the optional display_fn (needed for search and label rendering)
is set at construction time via Self::with_display.
Implementations§
Source§impl<T> ItemTree<T>
impl<T> ItemTree<T>
Sourcepub fn set_tree(&mut self, root: ItemNode<T>)
pub fn set_tree(&mut self, root: ItemNode<T>)
Replace the entire tree content with a new root (S11.4).
State is preserved for any NodeId that survives across the
replacement, regardless of whether the node moved to a new position
(S11.5). Disappeared keys are silently dropped; their selection and
expansion state is discarded.
After set_tree, if a display_fn is set and a search is active,
search visibility is recomputed automatically.
Sourcepub fn on_toggled(&mut self, id: NodeId)
pub fn on_toggled(&mut self, id: NodeId)
Expand or collapse the node identified by id.
Leaves (nodes with no children) are silently ignored (S11.2).
Sourcepub fn on_selected(&mut self, id: NodeId, mode: SelectionMode)
pub fn on_selected(&mut self, id: NodeId, mode: SelectionMode)
Apply a selection gesture (S11.7 → S6.x analogue).
Sourcepub fn handle_key(&self, key: TreeKey, mods: Modifiers) -> Option<ItemTreeEvent>
pub fn handle_key(&self, key: TreeKey, mods: Modifiers) -> Option<ItemTreeEvent>
Translate a key press into an ItemTreeEvent, or None when the
key is unbound.
Read-only — does not mutate self. The caller dispatches the returned
event back through Self::on_toggled / Self::on_selected.
Sourcepub fn set_search_query(&mut self, query: &str)
pub fn set_search_query(&mut self, query: &str)
Activate or update the incremental search filter (S11.6).
Requires a display_fn to have been set at construction time.
Empty string clears the search.
Sourcepub fn clear_search(&mut self)
pub fn clear_search(&mut self)
Clear the active search.
Source§impl<T> ItemTree<T>
impl<T> ItemTree<T>
Sourcepub fn on_drag_msg(&mut self, msg: ItemDragMsg) -> ItemDragOutcome
pub fn on_drag_msg(&mut self, msg: ItemDragMsg) -> ItemDragOutcome
Drive the drag state machine (S11.9–S11.16).
Returns an ItemDragOutcome describing the side effect the host must
handle: a deferred click selection, or a completed drop intent. The
widget mutates no node structure — the host rebuilds its model from
Completed { sources, target, position } and calls
Self::set_tree.
All variants are no-ops when drag-and-drop is disabled or no drag is in progress, so stray or out-of-order messages are harmless.
Source§impl<T> ItemTree<T>
impl<T> ItemTree<T>
Sourcepub fn with_display(
self,
f: impl Fn(&T) -> String + Send + Sync + 'static,
) -> ItemTree<T>
pub fn with_display( self, f: impl Fn(&T) -> String + Send + Sync + 'static, ) -> ItemTree<T>
Builder: attach a display function used for search and label rendering.
The function maps &T → String. Without it, Self::set_search_query
is a no-op and all VisibleItem::labels are empty.
Sourcepub fn with_drag_and_drop(self, enabled: bool) -> ItemTree<T>
pub fn with_drag_and_drop(self, enabled: bool) -> ItemTree<T>
Builder: enable drag-and-drop reorder/nest (opt-in, S11.9). Off by default; when disabled, mouse press selects directly.
Source§impl<T> ItemTree<T>
impl<T> ItemTree<T>
Sourcepub fn visible_rows(&self) -> Vec<VisibleItem>
pub fn visible_rows(&self) -> Vec<VisibleItem>
Ordered list of currently visible rows.
In normal mode: the root and all descendants in expanded branches. In search mode: matches and all their ancestors, regardless of expansion state (S11.6 → S9.3 analogue).
Sourcepub fn is_selected(&self, id: NodeId) -> bool
pub fn is_selected(&self, id: NodeId) -> bool
true iff id is in the current selection set.
Sourcepub fn selected_ids(&self) -> &[NodeId]
pub fn selected_ids(&self) -> &[NodeId]
Ordered selected IDs.
Sourcepub fn search_state(&self) -> Option<&ItemSearchState>
pub fn search_state(&self) -> Option<&ItemSearchState>
Active search session, or None.
Sourcepub fn search_query(&self) -> Option<&str>
pub fn search_query(&self) -> Option<&str>
Current search query, or None.
Sourcepub fn search_match_count(&self) -> usize
pub fn search_match_count(&self) -> usize
Direct match count (S11.6 → S9.8 analogue).
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Number of nodes currently in the tree.
Sourcepub fn is_drag_and_drop_enabled(&self) -> bool
pub fn is_drag_and_drop_enabled(&self) -> bool
Whether drag-and-drop is enabled (S11.9).
Sourcepub fn is_dragging(&self) -> bool
pub fn is_dragging(&self) -> bool
Whether a drag is currently in progress.
Sourcepub fn drag_sources(&self) -> &[NodeId]
pub fn drag_sources(&self) -> &[NodeId]
The nodes being dragged (pre-order), or an empty slice when idle.
Sourcepub fn drop_target(&self) -> Option<(NodeId, DropPosition)>
pub fn drop_target(&self) -> Option<(NodeId, DropPosition)>
The current valid drop target and position, or None.
Sourcepub fn is_expanded(&self, id: NodeId) -> Option<bool>
pub fn is_expanded(&self, id: NodeId) -> Option<bool>
Return whether the node identified by id is currently expanded.
Returns None if the id is not in the tree.
Trait Implementations§
Auto Trait Implementations§
impl<T> !RefUnwindSafe for ItemTree<T>
impl<T> !UnwindSafe for ItemTree<T>
impl<T> Freeze for ItemTree<T>
impl<T> Send for ItemTree<T>
impl<T> Sync for ItemTree<T>
impl<T> Unpin for ItemTree<T>where
T: Unpin,
impl<T> UnsafeUnpin for ItemTree<T>
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§impl<T> InitializeFromFunction<T> for T
impl<T> InitializeFromFunction<T> for T
Source§fn initialize_from_function(f: fn() -> T) -> T
fn initialize_from_function(f: fn() -> T) -> T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more