Skip to main content

ItemTree

Struct ItemTree 

Source
pub struct ItemTree<T>
where T: Clone + Debug + Send + Sync + 'static,
{ /* 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>
where T: Clone + Debug + Send + Sync + 'static,

Source

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.

Source

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).

Source

pub fn on_selected(&mut self, id: NodeId, mode: SelectionMode)

Apply a selection gesture (S11.7 → S6.x analogue).

Source

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.

Source

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.

Clear the active search.

Source§

impl<T> ItemTree<T>
where T: Clone + Debug + Send + Sync + 'static,

Source

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>
where T: Clone + Debug + Send + Sync + 'static,

Source

pub fn new() -> ItemTree<T>

Create an empty tree with no display function.

Source

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.

Source

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>
where T: Clone + Debug + Send + Sync + 'static,

Source

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).

Source

pub fn is_selected(&self, id: NodeId) -> bool

true iff id is in the current selection set.

Source

pub fn selected_ids(&self) -> &[NodeId]

Ordered selected IDs.

Source

pub fn active_id(&self) -> Option<NodeId>

The keyboard-focus / active node.

Source

pub fn search_state(&self) -> Option<&ItemSearchState>

Active search session, or None.

Source

pub fn search_query(&self) -> Option<&str>

Current search query, or None.

Source

pub fn search_match_count(&self) -> usize

Direct match count (S11.6 → S9.8 analogue).

Source

pub fn node_count(&self) -> usize

Number of nodes currently in the tree.

Source

pub fn is_drag_and_drop_enabled(&self) -> bool

Whether drag-and-drop is enabled (S11.9).

Source

pub fn is_dragging(&self) -> bool

Whether a drag is currently in progress.

Source

pub fn drag_sources(&self) -> &[NodeId]

The nodes being dragged (pre-order), or an empty slice when idle.

Source

pub fn drop_target(&self) -> Option<(NodeId, DropPosition)>

The current valid drop target and position, or None.

Source

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§

Source§

impl<T> Clone for ItemTree<T>
where T: Clone + Debug + Send + Sync + 'static,

Source§

fn clone(&self) -> ItemTree<T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for ItemTree<T>
where T: Clone + Debug + Send + Sync + 'static,

Source§

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

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

impl<T> Default for ItemTree<T>
where T: Clone + Debug + Send + Sync + 'static,

Source§

fn default() -> ItemTree<T>

Returns the “default value” for a type. Read more

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> 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> InitializeFromFunction<T> for T

Source§

fn initialize_from_function(f: fn() -> T) -> T

Create an instance of this type from an initialization function
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<Ret> SpawnIfAsync<(), Ret> for Ret

Source§

fn spawn(self) -> Ret

Spawn the value into the dioxus runtime if it is an async block
Source§

impl<T, O> SuperFrom<T> for O
where O: From<T>,

Source§

fn super_from(input: T) -> O

Convert from a type to another type.
Source§

impl<T, O, M> SuperInto<O, M> for T
where O: SuperFrom<T, M>,

Source§

fn super_into(self) -> O

Convert from a type to another type.
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> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more