pub struct TreeSlice<T: 'static> { /* private fields */ }Expand description
Per-view flattened projection of a TreeModel<T>.
Owns an independent expand/collapse set and re-flattens automatically on
every TreeChange from the underlying model. Two slices
over the same model have completely independent expand state. See the
module documentation for the full picture.
Implementations§
Source§impl<T: 'static> TreeSlice<T>
impl<T: 'static> TreeSlice<T>
Sourcepub fn new(tree: TreeModel<T>) -> Self
pub fn new(tree: TreeModel<T>) -> Self
Create a new TreeSlice for the given TreeModel.
All nodes start collapsed (only roots are visible).
Sourcepub fn visible_count(&self) -> usize
pub fn visible_count(&self) -> usize
Number of currently visible (flattened) rows.
Sourcepub fn with_entry<R>(
&self,
flat_index: usize,
f: impl FnOnce(&T, &FlatEntry) -> R,
) -> Option<R>
pub fn with_entry<R>( &self, flat_index: usize, f: impl FnOnce(&T, &FlatEntry) -> R, ) -> Option<R>
Access a flat entry by index via callback.
The callback receives (&T, &FlatEntry).
Sourcepub fn visible_node_id(&self, flat_index: usize) -> Option<NodeId>
pub fn visible_node_id(&self, flat_index: usize) -> Option<NodeId>
Get the NodeId at the given flat index.
Sourcepub fn entry_at(&self, flat_index: usize) -> Option<FlatEntry>
pub fn entry_at(&self, flat_index: usize) -> Option<FlatEntry>
Get the FlatEntry at the given flat index (cloned).
Sourcepub fn flat_index_of(&self, node: NodeId) -> Option<usize>
pub fn flat_index_of(&self, node: NodeId) -> Option<usize>
Find the flat index for a given NodeId, or None if not visible.
O(1) — backed by a position map rebuilt on every reflatten.
Sourcepub fn is_expanded(&self, node: NodeId) -> bool
pub fn is_expanded(&self, node: NodeId) -> bool
Whether the given node is expanded.
Sourcepub fn expand_all(&self)
pub fn expand_all(&self)
Expand all nodes in the tree.
Sourcepub fn collapse_all(&self)
pub fn collapse_all(&self)
Collapse all nodes in the tree.
Sourcepub fn expanded_nodes(&self) -> Vec<NodeId>
pub fn expanded_nodes(&self) -> Vec<NodeId>
Get all expanded node IDs (for persistence).
Sourcepub fn set_expanded_nodes(&self, nodes: &[NodeId])
pub fn set_expanded_nodes(&self, nodes: &[NodeId])
Restore expanded state (for persistence).
Sourcepub fn version_signal(&self) -> Signal<u64>
pub fn version_signal(&self) -> Signal<u64>
Get the version signal for binding to BindingLevel::Rebuild.
Sourcepub fn first_changed_index(&self) -> Option<usize>
pub fn first_changed_index(&self) -> Option<usize>
First flat index whose content may differ from before the latest
reflatten — the rows 0..index are the same nodes, at the same
depths, with the same expand state as before, so any per-row
derived state (e.g. a measured row height) remains valid for them.
Equal to visible_count() when the visible list is unchanged.
None means unknown (no reflatten observed yet) — treat as a full
change. The value describes the latest reflatten only; read it
synchronously from a version_signal() observer (observers fire
inline on every bump, so per-change reads cannot miss a value).
Sourcepub fn handle(&self) -> TreeSliceHandle<T>
pub fn handle(&self) -> TreeSliceHandle<T>
Create a lightweight handle for use in closures. Shares all Rc-based internals but does not keep the observer alive.
Trait Implementations§
Source§impl<T: 'static> TreeDataSource for TreeSlice<T>
TreeSlice is the built-in per-view TreeDataSource over an in-memory
TreeModel. Identity is NodeId; a SameView drop reorders via
move_node/move_to_root (with the cycle guard). Foreign drops are
rejected — a bare slice knows no foreign payloads.
impl<T: 'static> TreeDataSource for TreeSlice<T>
TreeSlice is the built-in per-view TreeDataSource over an in-memory
TreeModel. Identity is NodeId; a SameView drop reorders via
move_node/move_to_root (with the cycle guard). Foreign drops are
rejected — a bare slice knows no foreign payloads.
Source§type Key = NodeId
type Key = NodeId
NodeId for in-memory trees, an entity id
for an external store).Source§fn visible_count(&self) -> usize
fn visible_count(&self) -> usize
Source§fn with_entry<R>(
&self,
flat_index: usize,
f: impl FnOnce(&Self::Item, &FlatEntry<Self::Key>) -> R,
) -> Option<R>
fn with_entry<R>( &self, flat_index: usize, f: impl FnOnce(&Self::Item, &FlatEntry<Self::Key>) -> R, ) -> Option<R>
Source§fn flat_index_of(&self, key: &NodeId) -> Option<usize>
fn flat_index_of(&self, key: &NodeId) -> Option<usize>
Source§fn parent(&self, key: &NodeId) -> Option<NodeId>
fn parent(&self, key: &NodeId) -> Option<NodeId>
None for a root) — drives sibling nav + the
drop cycle-guard.Source§fn version_signal(&self) -> Signal<u64>
fn version_signal(&self) -> Signal<u64>
BindingLevel::Rebuild.Source§fn first_changed_index(&self) -> Option<usize>
fn first_changed_index(&self) -> Option<usize>
0..index are unchanged, so per-row derived state (e.g. a measured
height) remains valid. None means unknown (treat as a full change).Source§fn contains_key(&self, key: &NodeId) -> bool
fn contains_key(&self, key: &NodeId) -> bool
key still exists in the source, independent of visibility —
a node hidden under a collapsed ancestor (or scrolled out of a lazy
window) still exists. Drives keyed-selection pruning, so that a
collapsed-but-present node keeps its selection and only a deleted node
is dropped. Default: visible-only (flat_index_of(key).is_some());
sources whose nodes persist while collapsed/scrolled out should override
this to consult their full store.Source§fn is_expanded(&self, key: &NodeId) -> bool
fn is_expanded(&self, key: &NodeId) -> bool
Source§fn set_expanded(&self, key: &NodeId, expanded: bool)
fn set_expanded(&self, key: &NodeId, expanded: bool)
true) or collapse (false) the node.Source§fn drag(&self, _key: &NodeId) -> DragEligibility
fn drag(&self, _key: &NodeId) -> DragEligibility
Source§fn can_accept(&self, query: &DropQuery<'_, NodeId>) -> DropResponse
fn can_accept(&self, query: &DropQuery<'_, NodeId>) -> DropResponse
Source§fn accept_drop(&self, commit: DropCommit<'_, NodeId>) -> bool
fn accept_drop(&self, commit: DropCommit<'_, NodeId>) -> bool
Source§fn on_drag_out(&self, key: &NodeId)
fn on_drag_out(&self, key: &NodeId)
Source§fn reorder_within(
&self,
sources: &[Self::Key],
target: &Self::Key,
position: DropPosition,
) -> bool
fn reorder_within( &self, sources: &[Self::Key], target: &Self::Key, position: DropPosition, ) -> bool
sources are the
dragged nodes’ keys in visible order; target / position name the drop
gap. Returns whether anything moved. Read more