pub struct SelectionModel { /* private fields */ }Expand description
Manages selection state for a collection widget.
The selection is exposed as a Signal<BTreeSet<usize>> so widgets can
observe changes reactively.
Implementations§
Source§impl SelectionModel
impl SelectionModel
Sourcepub fn new(mode: SelectionMode) -> Self
pub fn new(mode: SelectionMode) -> Self
Create a new 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<BTreeSet<usize>>
pub fn selection_signal(&self) -> Signal<BTreeSet<usize>>
Get a clone of the selection signal for reactive binding.
Sourcepub fn is_selected(&self, index: usize) -> bool
pub fn is_selected(&self, index: usize) -> bool
Whether the given index is currently selected.
Sourcepub fn selected_indices(&self) -> Vec<usize>
pub fn selected_indices(&self) -> Vec<usize>
The currently selected indices, sorted.
Sourcepub fn select(&self, index: usize)
pub fn select(&self, index: usize)
Select a single index. In Single mode, clears previous selection.
In Multi mode, clears previous and selects just this one (use toggle
for Ctrl+click behavior). Sets the anchor for subsequent Shift+click.
Sourcepub fn toggle(&self, index: usize)
pub fn toggle(&self, index: usize)
Toggle selection of a single index (for Ctrl+click in Multi mode).
In Single mode, behaves like select().
Sourcepub fn extend_to(&self, index: usize)
pub fn extend_to(&self, index: usize)
Extend the selection from the anchor to the given index (for Shift+click).
In Single mode, behaves like select().
Sourcepub fn select_indices(
&self,
indices: impl IntoIterator<Item = usize>,
additive: bool,
)
pub fn select_indices( &self, indices: impl IntoIterator<Item = usize>, additive: bool, )
Replace the selection with indices (or, when additive, union them
into the current selection). Used by rubber-band / marquee selection,
where the selected set is an arbitrary subset rather than a range. In
Single mode the highest index wins; None mode is a no-op.
Sourcepub fn select_all(&self, count: usize)
pub fn select_all(&self, count: usize)
Select all indices from 0 to count-1.
A no-op in None mode, and also in Single mode — “select all” has
no coherent meaning for a control that holds at most one item, and
silently selecting one arbitrary row would be worse than doing
nothing. This mirrors what the gated call sites already do
(ListView’s Ctrl+A handler, which documents it as “Multi selection
only — a no-op for Single / None, matching every list control”, and
TableView’s select_all helper, which matches only the Multi
modes). Enforcing it here too keeps an ungated caller — GridView’s
Ctrl+A handler is one — from breaking the Single invariant that
every other mutator on this type upholds.
Sourcepub fn adjust_for_insert(&self, start: usize, count: usize)
pub fn adjust_for_insert(&self, start: usize, count: usize)
Adjust selection indices after items are inserted.
Indices >= start are shifted up by count.
Sourcepub fn adjust_for_remove(&self, start: usize, count: usize)
pub fn adjust_for_remove(&self, start: usize, count: usize)
Adjust selection indices after items are removed.
Indices in start..start+count are deselected; indices above are shifted down.
Sourcepub fn adjust_for_move(&self, from: usize, to: usize, count: usize)
pub fn adjust_for_move(&self, from: usize, to: usize, count: usize)
Adjust selection indices after a block of count items moved from
from to to (a post-removal index, matching ListModel::move_item).
Selected indices follow their items, so a dragged row stays selected.
Source§impl SelectionModel
impl SelectionModel
Sourcepub fn debug_named(self, _name: impl Into<String>) -> Self
pub fn debug_named(self, _name: impl Into<String>) -> Self
Register this selection model with the debug inspector under
name. In release builds (!cfg(debug_assertions)) this is a
no-op pass-through so call sites stay free of #[cfg] lines.
Idempotent on repeated calls — the latest registration wins.
The registration drops automatically when the last
SelectionModel handle is freed (the strong adapter Rc lives
inside a shared holder; the registry holds only a Weak).