Skip to main content

KeyedTreeCheckedModel

Struct KeyedTreeCheckedModel 

Source
pub struct KeyedTreeCheckedModel<K: ItemKey> { /* private fields */ }
Expand description

Per-node checkbox state for a domain-keyed tree, with optional descendant→ancestor tristate aggregation. See the module docs.

Implementations§

Source§

impl<K: ItemKey> KeyedTreeCheckedModel<K>

Source

pub fn new( children: impl Fn(&K) -> Vec<K> + 'static, parent: impl Fn(&K) -> Option<K> + 'static, ) -> Self

Create a model over a tree whose shape is given by two closures: children(key) -> Vec<K> and parent(key) -> Option<K>. Uses the default AggregateMode::DescendantsDriveAncestors.

Source

pub fn from_source<S>(source: S) -> Self
where S: TreeDataSource<Key = K> + Clone + 'static,

Create a model whose tree shape is read from a cloneable TreeDataSource (e.g. a TreeDataSlice). The source is cloned into the shape closures, so the model reflects the live tree — call prune_missing after the source reloads to drop state for removed nodes.

Source

pub fn with_mode(self, mode: AggregateMode) -> Self

Set the AggregateMode at construction.

Source

pub fn aggregate_mode(&self) -> AggregateMode

The current AggregateMode.

Source

pub fn set_aggregate_mode(&self, mode: AggregateMode)

Change the cascade behaviour; takes effect on the next write.

Source

pub fn signal_for(&self, key: K) -> Signal<CheckState>

Writable Signal<CheckState> for key (cached). External writes trigger the configured aggregation pass. The cascade observer is wired idempotently — including for a signal first materialised by a cascade (write_state) before its own signal_for was ever called — so binding a lazily-realised (e.g. virtualized) row still cascades on write.

Source

pub fn bool_signal_for(&self, key: K) -> Signal<bool>

Two-state Signal<bool> projection of signal_for (cached, writable). Checked → true; anything else → false. See crate::TreeCheckedModel::bool_signal_for.

Source

pub fn check_state(&self, key: &K) -> CheckState

The current CheckState for key (Unchecked if never touched).

Source

pub fn check(&self, key: K)

Set key to CheckState::Checked (triggers cascade + ancestor recompute).

Source

pub fn uncheck(&self, key: K)

Set key to CheckState::Unchecked (triggers cascade + ancestor recompute).

Source

pub fn toggle(&self, key: K)

Toggle key: a leaf under DescendantsDriveAncestors cycles two-state; a branch or AggregateMode::None cycles the full tristate sequence.

Source

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

All keys whose current state is exactly CheckState::Checked. May include stale keys after a tree mutation — call prune_missing or filter against the current tree yourself.

Source

pub fn clear(&self)

Reset all known nodes to CheckState::Unchecked.

Writes every tracked key directly via the internal write_state helper (per-key cascade-suppressed) instead of signal_for(..).set(..)’s normal path, which would, for every currently-checked key, cascade the write down its whole descendant subtree and recompute every ancestor up to the root — redundant here, since every tracked key ends up Unchecked and “all children unchecked” is already the correct parent aggregate. See TreeCheckedModel::clear for the non-keyed twin of this same optimization.

Source

pub fn prune_missing(&self, exists: impl Fn(&K) -> bool)

Drop cached check state (and its signals/observers) for every key for which exists(&key) returns false, then reaggregate surviving parents against the current tree. Call after a reload so a deleted node’s state doesn’t linger in checked_keys() and the ancestors it used to affect show the correct tristate. Mirrors crate::KeyedSelectionModel::prune_missing.

Source

pub fn reaggregate(&self)

Recompute every surviving parent’s aggregate from the current tree shape + leaf states, deepest first. Call after the backing tree’s structure changed (a reload that added/removed/moved nodes) so parent tristates reflect the new children; prune_missing does this for you. A no-op under AggregateMode::None.

Trait Implementations§

Source§

impl<K: ItemKey> Clone for KeyedTreeCheckedModel<K>

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> Debug for KeyedTreeCheckedModel<K>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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.