Skip to main content

TreeCheckedModel

Struct TreeCheckedModel 

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

Source

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

Create a new model wrapping tree with the default AggregateMode::DescendantsDriveAncestors cascade behaviour.

Source

pub fn with_mode(tree: TreeModel<T>, mode: AggregateMode) -> Self

Create a new model wrapping tree with an explicit AggregateMode.

Source

pub fn aggregate_mode(&self) -> AggregateMode

Returns the current AggregateMode controlling cascade behaviour.

Source

pub fn set_aggregate_mode(&self, mode: AggregateMode)

Change the cascade behaviour; takes effect on the next write to any node’s signal.

Source

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.

Source

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.

Source

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

Source

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.

Source

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.

Source

pub fn toggle(&self, node: NodeId)

Toggle node’s check state: under DescendantsDriveAncestors a leaf cycles two-state (UncheckedChecked); a branch or AggregateMode::None cycles the full tristate sequence via CheckState::next_tristate.

Source

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.

Source

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.

Trait Implementations§

Source§

impl<T: 'static> Clone for TreeCheckedModel<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<T: 'static> Debug for TreeCheckedModel<T>

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.