Trait TreeModel
pub trait TreeModel {
Show 18 methods
// Required methods
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 parent_id(&self, id: u64) -> Option<u64>;
fn child_index(&self, parent: u64, child: u64) -> Option<usize>;
fn child_count(&self, parent: u64) -> usize;
fn child_id(&self, parent: u64, index: usize) -> Option<u64>;
// Provided methods
fn accepts_children(&self, id: u64) -> bool { ... }
fn semantic_key(&self, _id: u64) -> Option<String> { ... }
fn is_selectable(&self, _id: u64) -> bool { ... }
fn is_renamable(&self, _id: u64) -> bool { ... }
fn shows_row_actions(&self, _id: u64) -> bool { ... }
fn can_collapse(&self, _id: u64) -> bool { ... }
fn child_state(&self, parent: u64, index: usize) -> TreeChildState<'_> { ... }
fn request_load(&mut self, _request: TreeLoadRequest) -> bool { ... }
fn poll_changes(&mut self) -> Vec<TreeModelChange> { ... }
fn needs_poll(&self) -> bool { ... }
}Expand description
Source-agnostic hierarchy queried by stable id. Implementations may be
backed by a database, an async cache, a CRDT, or the owned TreeNode
adapter. The view asks only for expanded children and visible labels.
IDs must be unique, parent/child queries must be inverse, and the reachable
hierarchy must be acyclic.
Required Methods§
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>
Provided Methods§
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.