pub struct TreeDataSlice<K: ItemKey, T> { /* private fields */ }Expand description
Per-view flattened projection of an external, indent-ordered tree source. See the module documentation.
Implementations§
Source§impl<K: ItemKey, T> TreeDataSlice<K, T>
impl<K: ItemKey, T> TreeDataSlice<K, T>
Sourcepub fn set_source(&self, f: impl Fn() -> Vec<TreeRow<K, T>> + 'static)
pub fn set_source(&self, f: impl Fn() -> Vec<TreeRow<K, T>> + 'static)
Install the row source (rows::load). reload and a
committed drop call it to re-materialise the tree.
Sourcepub fn set_reorder(&self, f: impl Fn(K, K, DropPosition) -> bool + 'static)
pub fn set_reorder(&self, f: impl Fn(K, K, DropPosition) -> bool + 'static)
Install the reorder command (dragged, target, position -> applied).
Without one, drops are refused.
Sourcepub fn set_drag_policy(&self, f: impl Fn(&K) -> DragEligibility + 'static)
pub fn set_drag_policy(&self, f: impl Fn(&K) -> DragEligibility + 'static)
Install the per-row drag gate. Without one, no row is draggable.
Sourcepub fn set_drop_resolver(
&self,
f: impl Fn(&K, &K, &T, DropPosition) -> Option<DropPosition> + 'static,
)
pub fn set_drop_resolver( &self, f: impl Fn(&K, &K, &T, DropPosition) -> Option<DropPosition> + 'static, )
Install the domain drop resolver. The engine’s cycle guard (no drop into
your own subtree, no self-drop) runs first, then hands the resolver
(dragged, target, target_item, position); return Some(pos) to accept
at pos (a different pos snaps the indicator, i.e.
DropResponse::Redirect) or None to forbid. Without one, any
non-cyclic drop is accepted at the requested position.
Sourcepub fn set_expand_new_nodes(&self, expand: bool)
pub fn set_expand_new_nodes(&self, expand: bool)
Whether nodes appearing for the first time start expanded (true) or
collapsed (false, the default, matching TreeSlice). Set this before
the first populate to affect the initial rows.
Sourcepub fn from_rows(rows: Vec<TreeRow<K, T>>) -> Self
pub fn from_rows(rows: Vec<TreeRow<K, T>>) -> Self
Build a slice directly from an initial row stream (no version bump / no divergence — construction is not a change).
Sourcepub fn reload(&self)where
T: PartialEq,
pub fn reload(&self)where
T: PartialEq,
Re-source the rows via the set_source closure and
reproject. No-op if no source is installed.
Sourcepub fn set_rows(&self, rows: Vec<TreeRow<K, T>>)where
T: PartialEq,
pub fn set_rows(&self, rows: Vec<TreeRow<K, T>>)where
T: PartialEq,
Replace the rows with a freshly-sourced stream, preserving per-view
expand state by key, computing first_changed_index,
and bumping the version signal.
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<K>) -> R,
) -> Option<R>
pub fn with_entry<R>( &self, flat_index: usize, f: impl FnOnce(&T, &FlatEntry<K>) -> R, ) -> Option<R>
Access the item + flat metadata at a visible index via callback.
Sourcepub fn with_key<R>(&self, key: &K, f: impl FnOnce(&T) -> R) -> Option<R>
pub fn with_key<R>(&self, key: &K, f: impl FnOnce(&T) -> R) -> Option<R>
Access a node’s item by key via callback, regardless of visibility (a
node hidden under a collapsed ancestor is still reachable). Returns None
if the key is absent from the source. The by-key counterpart of
with_entry (which is by visible index) — use it to
resolve a key to its domain payload.
Sourcepub fn entry_at(&self, flat_index: usize) -> Option<FlatEntry<K>>
pub fn entry_at(&self, flat_index: usize) -> Option<FlatEntry<K>>
The FlatEntry at a visible index (cloned).
Sourcepub fn depth_at(&self, flat_index: usize) -> usize
pub fn depth_at(&self, flat_index: usize) -> usize
Structural depth at a visible index (0 for a root).
Sourcepub fn flat_index_of(&self, key: &K) -> Option<usize>
pub fn flat_index_of(&self, key: &K) -> Option<usize>
The visible index of a key, if currently visible.
Sourcepub fn contains_key(&self, key: &K) -> bool
pub fn contains_key(&self, key: &K) -> bool
Whether key still exists in the source, independent of visibility (a
node hidden under a collapsed ancestor still exists).
Sourcepub fn parent_of(&self, key: &K) -> Option<K>
pub fn parent_of(&self, key: &K) -> Option<K>
The parent of a node (None for a root or an absent key).
Sourcepub fn child_keys_of(&self, key: &K) -> Vec<K>
pub fn child_keys_of(&self, key: &K) -> Vec<K>
The children of a node, in order (empty for a leaf / absent key). O(children).
Sourcepub fn is_expanded(&self, key: &K) -> bool
pub fn is_expanded(&self, key: &K) -> bool
Whether the node is effectively expanded (its children shown) — true
for every branch while the set_all_expanded
reveal override is on, otherwise its per-view expand state. Use
expanded_keys for the persistent set.
Sourcepub fn expand_all(&self)where
T: PartialEq,
pub fn expand_all(&self)where
T: PartialEq,
Expand every node that has children.
Sourcepub fn collapse_all(&self)where
T: PartialEq,
pub fn collapse_all(&self)where
T: PartialEq,
Collapse every node (only roots remain visible).
Sourcepub fn expanded_keys(&self) -> Vec<K>
pub fn expanded_keys(&self) -> Vec<K>
The currently-expanded keys (for persistence).
Sourcepub fn set_expanded_keys(&self, keys: &[K])where
T: PartialEq,
pub fn set_expanded_keys(&self, keys: &[K])where
T: PartialEq,
Restore expanded state (for persistence). Keys absent from the source are ignored on the next reflatten.
Sourcepub fn version_signal(&self) -> Signal<u64>
pub fn version_signal(&self) -> Signal<u64>
Version signal — bind at BindingLevel::Rebuild. Bumps on every
set_rows / expand / collapse.
Sourcepub fn first_changed_index(&self) -> Option<usize>
pub fn first_changed_index(&self) -> Option<usize>
First visible index whose content may differ after the latest change —
rows 0..index are unchanged (same key, depth, has-children, expand, and
item content), so per-row derived state remains valid for them. Equal to
visible_count() when nothing visible changed; None before the first
change (construction is not a change).
Sourcepub fn set_all_expanded(&self, on: bool)where
T: PartialEq,
pub fn set_all_expanded(&self, on: bool)where
T: PartialEq,
Reveal override for a filtered view: when on, the flatten treats every
node as expanded, so all rows in the (already sort/filter-narrowed) stream
are visible — the ancestors TreeRowFilter::KeepAncestors keeps no longer
hide their matching descendants. The per-view expand set is preserved
underneath, so turning it off restores the user’s real collapse state.
Flip it on with the filter and off when it clears. No-op if unchanged.
Sourcepub fn all_expanded(&self) -> bool
pub fn all_expanded(&self) -> bool
Whether the reveal-all override is on (see set_all_expanded).
Trait Implementations§
Source§impl<K: ItemKey, T> Clone for TreeDataSlice<K, T>
impl<K: ItemKey, T> Clone for TreeDataSlice<K, T>
Source§impl<K: ItemKey, T> Debug for TreeDataSlice<K, T>
impl<K: ItemKey, T> Debug for TreeDataSlice<K, T>
Source§impl<K: ItemKey, T> Default for TreeDataSlice<K, T>
impl<K: ItemKey, T> Default for TreeDataSlice<K, T>
Source§impl<K: ItemKey, T: PartialEq + 'static> TreeDataSource for TreeDataSlice<K, T>
TreeDataSlice is a reusable per-view TreeDataSource over an external,
indent-ordered source. Identity is the domain key K; a SameView drop is
resolved by the cycle guard + injected drop resolver and applied via the
injected reorder command (then the slice re-sources). Foreign drops are
rejected.
impl<K: ItemKey, T: PartialEq + 'static> TreeDataSource for TreeDataSlice<K, T>
TreeDataSlice is a reusable per-view TreeDataSource over an external,
indent-ordered source. Identity is the domain key K; a SameView drop is
resolved by the cycle guard + injected drop resolver and applied via the
injected reorder command (then the slice re-sources). Foreign drops are
rejected.
Source§type Key = K
type Key = K
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: &K) -> Option<usize>
fn flat_index_of(&self, key: &K) -> Option<usize>
Source§fn parent(&self, key: &K) -> Option<K>
fn parent(&self, key: &K) -> Option<K>
None for a root) — drives sibling nav + the
drop cycle-guard.Source§fn child_keys(&self, key: &K) -> Vec<K>
fn child_keys(&self, key: &K) -> Vec<K>
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: &K) -> bool
fn contains_key(&self, key: &K) -> 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: &K) -> bool
fn is_expanded(&self, key: &K) -> bool
Source§fn set_expanded(&self, key: &K, expanded: bool)
fn set_expanded(&self, key: &K, expanded: bool)
true) or collapse (false) the node.Source§fn drag(&self, key: &K) -> DragEligibility
fn drag(&self, key: &K) -> DragEligibility
Source§fn can_accept(&self, query: &DropQuery<'_, K>) -> DropResponse
fn can_accept(&self, query: &DropQuery<'_, K>) -> DropResponse
Source§fn accept_drop(&self, commit: DropCommit<'_, K>) -> bool
fn accept_drop(&self, commit: DropCommit<'_, K>) -> bool
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