Skip to main content

TreeDataSlice

Struct TreeDataSlice 

Source
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>

Source

pub fn new() -> Self

Create an empty slice. Configure it (set_source / set_reorder / policies / set_expand_new_nodes) then populate with reload or set_rows.

Source

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.

Source

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.

Source

pub fn set_drag_policy(&self, f: impl Fn(&K) -> DragEligibility + 'static)

Install the per-row drag gate. Without one, no row is draggable.

Source

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.

Source

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.

Source

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).

Source

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.

Source

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.

Source

pub fn visible_count(&self) -> usize

Number of currently-visible (flattened) rows.

Source

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.

Source

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.

Source

pub fn key_at(&self, flat_index: usize) -> Option<K>

The key of the row at a visible index.

Source

pub fn entry_at(&self, flat_index: usize) -> Option<FlatEntry<K>>

The FlatEntry at a visible index (cloned).

Source

pub fn depth_at(&self, flat_index: usize) -> usize

Structural depth at a visible index (0 for a root).

Source

pub fn flat_index_of(&self, key: &K) -> Option<usize>

The visible index of a key, if currently visible.

Source

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).

Source

pub fn parent_of(&self, key: &K) -> Option<K>

The parent of a node (None for a root or an absent key).

Source

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).

Source

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.

Source

pub fn expand(&self, key: &K)
where T: PartialEq,

Expand a node (make its children visible).

Source

pub fn collapse(&self, key: &K)
where T: PartialEq,

Collapse a node (hide its children).

Source

pub fn toggle(&self, key: &K)
where T: PartialEq,

Toggle a node’s expand state.

Source

pub fn expand_all(&self)
where T: PartialEq,

Expand every node that has children.

Source

pub fn collapse_all(&self)
where T: PartialEq,

Collapse every node (only roots remain visible).

Source

pub fn expanded_keys(&self) -> Vec<K>

The currently-expanded keys (for persistence).

Source

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.

Source

pub fn version_signal(&self) -> Signal<u64>

Version signal — bind at BindingLevel::Rebuild. Bumps on every set_rows / expand / collapse.

Source

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).

Source

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.

Source

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>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<K: ItemKey, T> Debug for TreeDataSlice<K, T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<K: ItemKey, T> Default for TreeDataSlice<K, T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
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.

Source§

type Item = T

The item type stored at each node.
Source§

type Key = K

The stable per-node identity (NodeId for in-memory trees, an entity id for an external store).
Source§

fn visible_count(&self) -> usize

Number of currently-visible (flattened) rows.
Source§

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.
Source§

fn key_at(&self, flat_index: usize) -> Option<K>

The key of the row at a visible index.
Source§

fn flat_index_of(&self, key: &K) -> Option<usize>

The visible index of a key, if currently visible.
Source§

fn parent(&self, key: &K) -> Option<K>

The parent of a node (None for a root) — drives sibling nav + the drop cycle-guard.
Source§

fn child_keys(&self, key: &K) -> Vec<K>

The children of a node, in order.
Source§

fn version_signal(&self) -> Signal<u64>

A version signal that bumps on every structural/projection change — the view binds it at BindingLevel::Rebuild.
Source§

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).
Source§

fn contains_key(&self, key: &K) -> 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.
Source§

fn is_expanded(&self, key: &K) -> bool

Whether the node is expanded.
Source§

fn set_expanded(&self, key: &K, expanded: bool)

Expand (true) or collapse (false) the node.
Source§

fn drag(&self, key: &K) -> DragEligibility

Whether the node may begin a drag (the transferable gate).
Source§

fn can_accept(&self, query: &DropQuery<'_, K>) -> DropResponse

Whether a hovered drop is permitted (and where) — the pre-commit verdict.
Source§

fn accept_drop(&self, commit: DropCommit<'_, K>) -> bool

Apply a committed drop. Returns whether it was applied.
Source§

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. Read more
Source§

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.
Source§

fn row_state(&self, _flat_index: usize) -> RowState

Whether the row at a visible index is loaded.
Source§

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).
Source§

fn can_fetch_more(&self) -> bool

Whether more rows can be appended (infinite scroll).
Source§

fn fetch_more(&self)

Fetch the next page (append-only growth).

Auto Trait Implementations§

§

impl<K, T> !RefUnwindSafe for TreeDataSlice<K, T>

§

impl<K, T> !Send for TreeDataSlice<K, T>

§

impl<K, T> !Sync for TreeDataSlice<K, T>

§

impl<K, T> !UnwindSafe for TreeDataSlice<K, T>

§

impl<K, T> Freeze for TreeDataSlice<K, T>

§

impl<K, T> Unpin for TreeDataSlice<K, T>

§

impl<K, T> UnsafeUnpin for TreeDataSlice<K, T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.