pub struct TreeCheckedModel<T: 'static> { /* private fields */ }Expand description
Per-node checkbox state for a TreeModel<T>, with optional
descendant→ancestor tristate aggregation.
See the module documentation for the full semantics and limitations. Clone to share the same checkbox state between multiple call sites.
Implementations§
Source§impl<T: 'static> TreeCheckedModel<T>
impl<T: 'static> TreeCheckedModel<T>
Sourcepub fn new(tree: TreeModel<T>) -> Self
pub fn new(tree: TreeModel<T>) -> Self
Create a new model wrapping tree with the default
AggregateMode::DescendantsDriveAncestors cascade behaviour.
Sourcepub fn with_mode(tree: TreeModel<T>, mode: AggregateMode) -> Self
pub fn with_mode(tree: TreeModel<T>, mode: AggregateMode) -> Self
Create a new model wrapping tree with an explicit AggregateMode.
Sourcepub fn aggregate_mode(&self) -> AggregateMode
pub fn aggregate_mode(&self) -> AggregateMode
Returns the current AggregateMode controlling cascade behaviour.
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 to any node’s signal.
Sourcepub fn signal_for(&self, node: NodeId) -> Signal<CheckState>
pub fn signal_for(&self, node: NodeId) -> Signal<CheckState>
Writable Signal<CheckState> for node. Cached: repeat calls
return the same root. External writes (e.g. from a Checkbox)
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
(a lazily/virtualized-realised row) — so a later external write to it
still cascades.
Sourcepub fn bool_signal_for(&self, node: NodeId) -> Signal<bool>
pub fn bool_signal_for(&self, node: NodeId) -> Signal<bool>
Two-state projection of signal_for for callers that want
to bind a leaf’s check state to a Signal<bool>-shaped widget
(e.g. a non-tristate Checkbox). The returned signal is
writable: setting it to true calls check(node) (which
runs the configured cascade), false calls uncheck(node).
Writes from the model side propagate back into the bool signal
(Checked → true, anything else → false). Cached: repeat
calls return the same handle.
For leaves under AggregateMode::DescendantsDriveAncestors
this is the right pairing — a leaf’s state is two-state by
nature, and the model’s ancestor recompute still runs. For
branches you typically want the tristate signal_for so
Indeterminate is visible.
Sourcepub fn check_state(&self, node: NodeId) -> CheckState
pub fn check_state(&self, node: NodeId) -> CheckState
Returns the current CheckState for node (defaults to Unchecked
if the node’s signal has never been written or read).
Sourcepub fn check(&self, node: NodeId)
pub fn check(&self, node: NodeId)
Set node to CheckState::Checked, triggering the configured cascade and
ancestor recompute; notifies observers of every affected node’s signal.
Sourcepub fn uncheck(&self, node: NodeId)
pub fn uncheck(&self, node: NodeId)
Set node to CheckState::Unchecked, triggering the configured cascade and
ancestor recompute; notifies observers of every affected node’s signal.
Sourcepub fn toggle(&self, node: NodeId)
pub fn toggle(&self, node: NodeId)
Toggle node’s check state: under DescendantsDriveAncestors a leaf
cycles two-state (Unchecked ↔ Checked); a branch or AggregateMode::None
cycles the full tristate sequence via CheckState::next_tristate.
Sourcepub fn checked_nodes(&self) -> Vec<NodeId>
pub fn checked_nodes(&self) -> Vec<NodeId>
Returns all NodeIds whose current state is exactly CheckState::Checked.
Note: may include stale ids if the underlying tree has been mutated since the signals were first registered — see the module-level limitation note.
Sourcepub fn clear(&self)
pub fn clear(&self)
Reset all known nodes to CheckState::Unchecked and notify observers.
Writes every tracked node directly via the internal write_state
helper (per-node cascade-suppressed, like the recompute pass) instead of going
through check/uncheck’s normal signal_for(..).set(..) path —
the latter would, for every currently-checked node, cascade the
write down its entire descendant subtree and recompute every
ancestor up to the root, all before the outer loop even reaches
those same nodes. Since every tracked node ends up Unchecked here,
there is nothing left to aggregate: “all children unchecked” is
already the correct parent state, so skipping the cascade and
ancestor recompute entirely still leaves every node’s state
consistent — one direct write per tracked node instead of a
cascade+recompute pass per checked one.