Struct TreeNode
pub struct TreeNode<T> {
pub id: u64,
pub label: String,
pub data: T,
pub children: Vec<TreeNode<T>>,
/* private fields */
}Fields§
§id: u64§label: String§data: T§children: Vec<TreeNode<T>>Implementations§
§impl<T> TreeNode<T>
impl<T> TreeNode<T>
pub fn leaf(id: u64, label: impl Into<String>, data: T) -> TreeNode<T>
pub fn branch(
id: u64,
label: impl Into<String>,
data: T,
children: Vec<TreeNode<T>>,
) -> TreeNode<T>
pub fn branch( id: u64, label: impl Into<String>, data: T, children: Vec<TreeNode<T>>, ) -> TreeNode<T>
A branch with zero children still renders the disclosure glyph, so callers can populate it (e.g. an empty folder) later.
pub fn is_branch(&self) -> bool
pub fn find(&self, id: u64) -> Option<&TreeNode<T>>
pub fn find_mut(&mut self, id: u64) -> Option<&mut TreeNode<T>>
pub fn can_reorder(&self, source: u64, target: &DropTarget<u64>) -> bool
pub fn can_reorder(&self, source: u64, target: &DropTarget<u64>) -> bool
Whether an owned node can be moved to this stable drop target.
Root moves, self-drops, drops inside leaves, and moves that would put a
node below one of its own descendants are rejected. Apps with further
domain constraints can combine this with TreeView::with_reorder.
pub fn reorder(&mut self, dropped: &ReorderDrop<u64>) -> bool
pub fn reorder(&mut self, dropped: &ReorderDrop<u64>) -> bool
Apply a validated before/inside/after move to this owned hierarchy.
The complete source subtree is preserved. Indices are resolved again
after detaching the source, so sibling moves cannot suffer the usual
off-by-one error. Moving a node to its current position returns
false without mutating the hierarchy.
Trait Implementations§
§impl<T> TreeModel for TreeNode<T>
impl<T> TreeModel for TreeNode<T>
fn root_id(&self) -> u64
fn contains(&self, id: u64) -> bool
fn label(&self, id: u64) -> Option<&str>
fn is_branch(&self, id: u64) -> bool
§fn child_index(&self, parent: u64, child: u64) -> Option<usize>
fn child_index(&self, parent: u64, child: u64) -> Option<usize>
Position of a direct child. Large/paged models should answer this from
an index rather than scanning siblings.
fn child_count(&self, parent: u64) -> usize
fn child_id(&self, parent: u64, index: usize) -> Option<u64>
§fn accepts_children(&self, id: u64) -> bool
fn accepts_children(&self, id: u64) -> bool
Whether a drop or an indent may make
id a parent. Defaults to
Self::is_branch; a hierarchy where any node can hold children (an
outline, a notebook) answers true for leaves too, while
Self::is_branch keeps deciding which rows show a disclosure.§fn semantic_key(&self, _id: u64) -> Option<String>
fn semantic_key(&self, _id: u64) -> Option<String>
A durable identity for
id in the semantic tree ("notes:page:<uuid>"),
for models whose node ids are only stable within a session. Assistive
technology and automation then address the row by it across launches.§fn is_selectable(&self, _id: u64) -> bool
fn is_selectable(&self, _id: u64) -> bool
Whether
id can be chosen. A row that cannot (a section header in a
navigation list) still takes focus and expands, but is never
selected or activated.§fn is_renamable(&self, _id: u64) -> bool
fn is_renamable(&self, _id: u64) -> bool
Whether
id’s label can be edited in place (see
TreeView::on_rename).§fn shows_row_actions(&self, _id: u64) -> bool
fn shows_row_actions(&self, _id: u64) -> bool
Whether
id’s row shows the tree’s row actions on hover and focus.§fn can_collapse(&self, _id: u64) -> bool
fn can_collapse(&self, _id: u64) -> bool
Whether an expanded branch may be collapsed. A heading whose rows
are always shown answers
false.§fn child_state(&self, parent: u64, index: usize) -> TreeChildState<'_>
fn child_state(&self, parent: u64, index: usize) -> TreeChildState<'_>
Resolve a logical child slot. Paged models override this to return
TreeChildState::Loading or TreeChildState::Error for
non-resident rows; existing fully-resident models need only implement
Self::child_id.§fn request_load(&mut self, _request: TreeLoadRequest) -> bool
fn request_load(&mut self, _request: TreeLoadRequest) -> bool
Start or deduplicate work for one visible/retried child slot. Return
whether the model accepted the request. Model-owned asynchronous
sources can complete through
Self::poll_changes; external owners
may instead use TreeView::on_load_request.§fn poll_changes(&mut self) -> Vec<TreeModelChange>
fn poll_changes(&mut self) -> Vec<TreeModelChange>
Drain model-owned structural, row-data, or slot-state changes.
§fn needs_poll(&self) -> bool
fn needs_poll(&self) -> bool
Keep scheduling frames only for sources that cannot wake the app when
a batch completes. Prefer
crate::LatestRequest for idle workers.Auto Trait Implementations§
impl<T> Freeze for TreeNode<T>where
T: Freeze,
impl<T> RefUnwindSafe for TreeNode<T>where
T: RefUnwindSafe,
impl<T> Send for TreeNode<T>where
T: Send,
impl<T> Sync for TreeNode<T>where
T: Sync,
impl<T> Unpin for TreeNode<T>where
T: Unpin,
impl<T> UnsafeUnpin for TreeNode<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for TreeNode<T>where
T: UnwindSafe,
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
Mutably borrows from an owned value. Read more
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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>
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 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>
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