Skip to main content

SelectionModel

Struct SelectionModel 

Source
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

Source

pub fn new(mode: SelectionMode) -> Self

Create a new selection model with the given mode.

Source

pub fn mode(&self) -> SelectionMode

The selection mode.

Source

pub fn selection_signal(&self) -> Signal<BTreeSet<usize>>

Get a clone of the selection signal for reactive binding.

Source

pub fn is_selected(&self, index: usize) -> bool

Whether the given index is currently selected.

Source

pub fn selected_indices(&self) -> Vec<usize>

The currently selected indices, sorted.

Source

pub fn count(&self) -> usize

Number of selected items.

Source

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.

Source

pub fn toggle(&self, index: usize)

Toggle selection of a single index (for Ctrl+click in Multi mode). In Single mode, behaves like select().

Source

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

Source

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.

Source

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.

Source

pub fn clear(&self)

Clear the selection.

Source

pub fn adjust_for_insert(&self, start: usize, count: usize)

Adjust selection indices after items are inserted. Indices >= start are shifted up by count.

Source

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.

Source

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

Source

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

Trait Implementations§

Source§

impl Clone for SelectionModel

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 Debug for SelectionModel

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.