Skip to main content

TreeSlice

Struct TreeSlice 

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

Source

pub fn new(tree: TreeModel<T>) -> Self

Create a new TreeSlice for the given TreeModel. All nodes start collapsed (only roots are visible).

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) -> R, ) -> Option<R>

Access a flat entry by index via callback. The callback receives (&T, &FlatEntry).

Source

pub fn visible_node_id(&self, flat_index: usize) -> Option<NodeId>

Get the NodeId at the given flat index.

Source

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

Get the FlatEntry at the given flat index (cloned).

Source

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

Get the depth at the given flat index.

Source

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.

Source

pub fn is_expanded(&self, node: NodeId) -> bool

Whether the given node is expanded.

Source

pub fn expand(&self, node: NodeId)

Expand a node (make its children visible).

Source

pub fn collapse(&self, node: NodeId)

Collapse a node (hide its children).

Source

pub fn toggle(&self, node: NodeId)

Toggle expand/collapse state of a node.

Source

pub fn expand_all(&self)

Expand all nodes in the tree.

Source

pub fn collapse_all(&self)

Collapse all nodes in the tree.

Source

pub fn expanded_nodes(&self) -> Vec<NodeId>

Get all expanded node IDs (for persistence).

Source

pub fn set_expanded_nodes(&self, nodes: &[NodeId])

Restore expanded state (for persistence).

Source

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

Get the version signal for binding to BindingLevel::Rebuild.

Source

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

Source

pub fn tree(&self) -> &TreeModel<T>

Access the underlying TreeModel.

Source

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> Debug for TreeSlice<T>

Source§

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

Formats the value using the given formatter. Read more
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.

Source§

type Item = T

The item type stored at each node.
Source§

type Key = NodeId

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

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

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

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

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

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

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

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: &NodeId) -> 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: &NodeId) -> bool

Whether the node is expanded.
Source§

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

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

fn drag(&self, _key: &NodeId) -> DragEligibility

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

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

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

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

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

fn on_drag_out(&self, key: &NodeId)

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 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 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<T> !RefUnwindSafe for TreeSlice<T>

§

impl<T> !Send for TreeSlice<T>

§

impl<T> !Sync for TreeSlice<T>

§

impl<T> !UnwindSafe for TreeSlice<T>

§

impl<T> Freeze for TreeSlice<T>

§

impl<T> Unpin for TreeSlice<T>

§

impl<T> UnsafeUnpin for TreeSlice<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> 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, 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.