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>
impl<K: ItemKey> KeyedTreeCheckedModel<K>
Sourcepub fn new(
children: impl Fn(&K) -> Vec<K> + 'static,
parent: impl Fn(&K) -> Option<K> + 'static,
) -> Self
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.
Sourcepub fn from_source<S>(source: S) -> Selfwhere
S: TreeDataSource<Key = K> + Clone + 'static,
pub fn from_source<S>(source: S) -> Selfwhere
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.
Sourcepub fn with_mode(self, mode: AggregateMode) -> Self
pub fn with_mode(self, mode: AggregateMode) -> Self
Set the AggregateMode at construction.
Sourcepub fn aggregate_mode(&self) -> AggregateMode
pub fn aggregate_mode(&self) -> AggregateMode
The current AggregateMode.
Sourcepub fn set_aggregate_mode(&self, mode: AggregateMode)
pub fn set_aggregate_mode(&self, mode: AggregateMode)
Change the cascade behaviour; takes effect on the next write.
Sourcepub fn signal_for(&self, key: K) -> Signal<CheckState>
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.
Sourcepub fn bool_signal_for(&self, key: K) -> Signal<bool>
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.
Sourcepub fn check_state(&self, key: &K) -> CheckState
pub fn check_state(&self, key: &K) -> CheckState
The current CheckState for key (Unchecked if never touched).
Sourcepub fn check(&self, key: K)
pub fn check(&self, key: K)
Set key to CheckState::Checked (triggers cascade + ancestor recompute).
Sourcepub fn uncheck(&self, key: K)
pub fn uncheck(&self, key: K)
Set key to CheckState::Unchecked (triggers cascade + ancestor recompute).
Sourcepub fn toggle(&self, key: K)
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.
Sourcepub fn checked_keys(&self) -> Vec<K>
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.
Sourcepub fn clear(&self)
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.
Sourcepub fn prune_missing(&self, exists: impl Fn(&K) -> bool)
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.
Sourcepub fn reaggregate(&self)
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.