pub struct KeyedSelectionModel<K: ItemKey> { /* private fields */ }Expand description
Selection state keyed by source-defined identity rather than visible index.
The selection set is exposed as a Signal<HashSet<K>> (via
selection_signal) so widgets
observe it reactively without polling. Cloning the model shares the same
selection and anchor across all handles. The Shift+click anchor is stored as
a K so it survives lazy-window evictions and visible-order changes.
Implementations§
Source§impl<K: ItemKey> KeyedSelectionModel<K>
impl<K: ItemKey> KeyedSelectionModel<K>
Sourcepub fn new(mode: SelectionMode) -> Self
pub fn new(mode: SelectionMode) -> Self
Create a new keyed selection model with the given mode.
Sourcepub fn mode(&self) -> SelectionMode
pub fn mode(&self) -> SelectionMode
The selection mode.
Sourcepub fn selection_signal(&self) -> Signal<HashSet<K>>
pub fn selection_signal(&self) -> Signal<HashSet<K>>
A clone of the selection signal for reactive binding.
Sourcepub fn is_selected(&self, key: &K) -> bool
pub fn is_selected(&self, key: &K) -> bool
Whether key is currently selected (O(1)).
Sourcepub fn selected_keys(&self) -> Vec<K>
pub fn selected_keys(&self) -> Vec<K>
The currently selected keys (unordered snapshot).
Sourcepub fn select(&self, key: K)
pub fn select(&self, key: K)
Select a single key, clearing previous selection and setting the anchor.
Sourcepub fn toggle(&self, key: K)
pub fn toggle(&self, key: K)
Toggle a key (Ctrl+click in Multi mode; acts as select in Single).
Sourcepub fn extend_to(&self, target: K, ordered_keys: &[K])
pub fn extend_to(&self, target: K, ordered_keys: &[K])
Extend the selection from the anchor to target over the current visible
key order (Shift+click). ordered_keys is the projection’s visible order
at click time. If the anchor isn’t currently visible (scrolled out /
evicted), falls back to a single-key select.
Sourcepub fn select_keys(&self, keys: impl IntoIterator<Item = K>, additive: bool)
pub fn select_keys(&self, keys: impl IntoIterator<Item = K>, additive: bool)
Replace the selection with keys (or, when additive, union them in).
Used by rubber-band selection. In Single mode an arbitrary one wins.
Sourcepub fn prune_missing(&self, exists: impl Fn(&K) -> bool)
pub fn prune_missing(&self, exists: impl Fn(&K) -> bool)
Drop any selected key (and the anchor) for which exists returns false.
Call after a removal/reset to prune deleted rows — the index-based
adjust_for_insert/adjust_for_remove are unnecessary here because keys
are stable across inserts, moves, sorts and filters.
Source§impl<K: ItemKey> KeyedSelectionModel<K>
impl<K: ItemKey> KeyedSelectionModel<K>
Sourcepub fn debug_named(self, _name: impl Into<String>) -> Self
pub fn debug_named(self, _name: impl Into<String>) -> Self
Register this model with the debug inspector under name; no-op in
release builds (!cfg(debug_assertions)). Returns self for chaining.