Skip to main content

Module keyed_tree_checked_model

Module keyed_tree_checked_model 

Source
Expand description

KeyedTreeCheckedModel<K> — per-node checkbox state for a tree keyed by a stable domain id, with optional descendant→ancestor tristate aggregation.

The keyed counterpart of TreeCheckedModel — the checkbox twin of KeyedSelectionModel. Where TreeCheckedModel is bound to a TreeModel<T> and keyed by NodeId, this model is keyed by your domain key K (an entity id, a tagged enum) and takes the tree shape as two injected closures (children + parent), so it composes over a TreeDataSlice or any TreeDataSource — the “select scenes to export” tristate over an external outline, without mirroring into a TreeModel.

Because identity is the domain key (stable across a full re-source), a node’s check state survives the tree reloading — a checked scene stays checked after the backend refreshes. Use prune_missing after a reload to drop the state of nodes that no longer exist.

Semantics, cascade behaviour, the Signal<CheckState> / Signal<bool> bridge, and the re-entry guard are identical to TreeCheckedModel — see its module docs for the detail. This model is a share-by-clone handle (Rc<RefCell<…>> internally).

§Example

use teksilo_data::{KeyedTreeCheckedModel, CheckState, TreeDataSlice, TreeRow};

// An outline: Binder(1) → { Chapter(2) → Scene(3), Scene(4) }
let slice: TreeDataSlice<u64, &str> = TreeDataSlice::from_rows(vec![
    TreeRow::new(1, "Binder", 0),
    TreeRow::new(2, "Chapter", 1),
    TreeRow::new(3, "Scene A", 2),
    TreeRow::new(4, "Scene B", 1),
]);

let checked = KeyedTreeCheckedModel::from_source(slice.clone());
let _ = (checked.signal_for(1), checked.signal_for(2), checked.signal_for(3), checked.signal_for(4));

checked.check(3);                                         // one scene under the chapter
assert_eq!(checked.check_state(&2), CheckState::Checked); // chapter has only Scene A → Checked
assert_eq!(checked.check_state(&1), CheckState::Indeterminate); // Binder: 2 of {chapter, Scene B}

Structs§

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