pub trait TreeDataSource: 'static {
type Item: 'static;
type Key: ItemKey;
Show 20 methods
// Required methods
fn visible_count(&self) -> usize;
fn with_entry<R>(
&self,
flat_index: usize,
f: impl FnOnce(&Self::Item, &FlatEntry<Self::Key>) -> R,
) -> Option<R>;
fn key_at(&self, flat_index: usize) -> Option<Self::Key>;
fn flat_index_of(&self, key: &Self::Key) -> Option<usize>;
fn parent(&self, key: &Self::Key) -> Option<Self::Key>;
fn child_keys(&self, key: &Self::Key) -> Vec<Self::Key>;
fn version_signal(&self) -> Signal<u64>;
fn is_expanded(&self, key: &Self::Key) -> bool;
fn set_expanded(&self, key: &Self::Key, expanded: bool);
// Provided methods
fn first_changed_index(&self) -> Option<usize> { ... }
fn contains_key(&self, key: &Self::Key) -> bool { ... }
fn drag(&self, _key: &Self::Key) -> DragEligibility { ... }
fn can_accept(&self, _query: &DropQuery<'_, Self::Key>) -> DropResponse { ... }
fn accept_drop(&self, _commit: DropCommit<'_, Self::Key>) -> bool { ... }
fn reorder_within(
&self,
sources: &[Self::Key],
target: &Self::Key,
position: DropPosition,
) -> bool { ... }
fn on_drag_out(&self, _key: &Self::Key) { ... }
fn row_state(&self, _flat_index: usize) -> RowState { ... }
fn request_window(&self, _range: Range<usize>) { ... }
fn can_fetch_more(&self) -> bool { ... }
fn fetch_more(&self) { ... }
}Expand description
A per-view flattened, projectable view over hierarchical data.
Not object-safe (associated types + impl FnOnce); views consume it
generically and erase it into a closure bundle, exactly as ListView does
with ListDataSource. The DnD (drag/can_accept/accept_drop/
on_drag_out) and lazy (row_state/request_window/can_fetch_more/
fetch_more) methods default to inert/fully-resident, so a read-only source
implements only the core read + nav surface.
Required Associated Types§
Required Methods§
Sourcefn visible_count(&self) -> usize
fn visible_count(&self) -> usize
Number of currently-visible (flattened) rows.
Sourcefn 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>
Access the item + flat metadata at a visible index via callback.
Sourcefn key_at(&self, flat_index: usize) -> Option<Self::Key>
fn key_at(&self, flat_index: usize) -> Option<Self::Key>
The key of the row at a visible index.
Sourcefn flat_index_of(&self, key: &Self::Key) -> Option<usize>
fn flat_index_of(&self, key: &Self::Key) -> Option<usize>
The visible index of a key, if currently visible.
Sourcefn parent(&self, key: &Self::Key) -> Option<Self::Key>
fn parent(&self, key: &Self::Key) -> Option<Self::Key>
The parent of a node (None for a root) — drives sibling nav + the
drop cycle-guard.
Sourcefn child_keys(&self, key: &Self::Key) -> Vec<Self::Key>
fn child_keys(&self, key: &Self::Key) -> Vec<Self::Key>
The children of a node, in order.
Sourcefn version_signal(&self) -> Signal<u64>
fn version_signal(&self) -> Signal<u64>
A version signal that bumps on every structural/projection change — the
view binds it at BindingLevel::Rebuild.
Sourcefn is_expanded(&self, key: &Self::Key) -> bool
fn is_expanded(&self, key: &Self::Key) -> bool
Whether the node is expanded.
Sourcefn set_expanded(&self, key: &Self::Key, expanded: bool)
fn set_expanded(&self, key: &Self::Key, expanded: bool)
Expand (true) or collapse (false) the node.
Provided Methods§
Sourcefn first_changed_index(&self) -> Option<usize>
fn first_changed_index(&self) -> Option<usize>
First visible index whose content may differ after the latest change —
rows 0..index are unchanged, so per-row derived state (e.g. a measured
height) remains valid. None means unknown (treat as a full change).
Sourcefn contains_key(&self, key: &Self::Key) -> bool
fn contains_key(&self, key: &Self::Key) -> bool
Whether 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.
Sourcefn drag(&self, _key: &Self::Key) -> DragEligibility
fn drag(&self, _key: &Self::Key) -> DragEligibility
Whether the node may begin a drag (the transferable gate).
Sourcefn can_accept(&self, _query: &DropQuery<'_, Self::Key>) -> DropResponse
fn can_accept(&self, _query: &DropQuery<'_, Self::Key>) -> DropResponse
Whether a hovered drop is permitted (and where) — the pre-commit verdict.
Sourcefn accept_drop(&self, _commit: DropCommit<'_, Self::Key>) -> bool
fn accept_drop(&self, _commit: DropCommit<'_, Self::Key>) -> bool
Apply a committed drop. Returns whether it was applied.
Sourcefn 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
Reorder a whole set of this source’s OWN nodes so they land contiguously
at a drop gap — the multi-row same-view reorder commit. sources are the
dragged nodes’ keys in visible order; target / position name the drop
gap. Returns whether anything moved.
The default first drops any sources node that is a descendant of
another sources node (moving an ancestor already carries its
subtree), then moves the remaining top-level nodes one at a time,
re-anchoring each after the previous. Tree keys are stable, so the
re-anchoring is correct without index bookkeeping.
Sourcefn on_drag_out(&self, _key: &Self::Key)
fn on_drag_out(&self, _key: &Self::Key)
Called on the origin source after one of its rows was accepted by a different view (source-side completion). Sources backed by a shared / command model no-op this; independent models use it to drop the moved row.
Sourcefn row_state(&self, _flat_index: usize) -> RowState
fn row_state(&self, _flat_index: usize) -> RowState
Whether the row at a visible index is loaded.
Sourcefn request_window(&self, _range: Range<usize>)
fn request_window(&self, _range: Range<usize>)
Nudge the source to load the given visible range (the view calls this each build with its visible + buffer window).
Sourcefn can_fetch_more(&self) -> bool
fn can_fetch_more(&self) -> bool
Whether more rows can be appended (infinite scroll).
Sourcefn fetch_more(&self)
fn fetch_more(&self)
Fetch the next page (append-only growth).
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
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§impl<T: 'static> TreeDataSource for SortFilterTreeModel<T>
SortFilterTreeModel is a TreeDataSource so it drops directly into a
TreeView / TreeTableView. DnD is left inert (reordering a sort/filter
projection is ill-defined); apps that need a reorderable tree feed a
TreeSlice or a bespoke source.
impl<T: 'static> TreeDataSource for SortFilterTreeModel<T>
SortFilterTreeModel is a TreeDataSource so it drops directly into a
TreeView / TreeTableView. DnD is left inert (reordering a sort/filter
projection is ill-defined); apps that need a reorderable tree feed a
TreeSlice or a bespoke source.
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.