Struct SelectionModel
pub struct SelectionModel { /* private fields */ }Expand description
Index-based multi-selection state. Indices are opaque usizes the
owning widget assigns to its items (typically the row/cell order).
Implementations§
§impl SelectionModel
impl SelectionModel
pub fn new() -> SelectionModel
pub fn new() -> SelectionModel
An empty selection.
pub fn is_selected(&self, index: usize) -> bool
pub fn is_selected(&self, index: usize) -> bool
Whether index is currently selected.
pub fn selected_set(&self) -> &BTreeSet<usize>
pub fn selected_set(&self) -> &BTreeSet<usize>
Borrow the selected set directly (ascending iteration order).
pub fn remap_indices(&mut self, map: impl Fn(usize) -> Option<usize>)
pub fn remap_indices(&mut self, map: impl Fn(usize) -> Option<usize>)
Follow items when their owning collection changes row order. Map each
old position to its new position, or None if the item disappeared.
The cursor and range anchor remain independent of the selected set,
including a cursor left on an item deselected by Ctrl-click.
pub fn clear(&mut self)
pub fn clear(&mut self)
Drop everything — no selection, no anchor, no cursor.
pub fn replace_indices(
&mut self,
selected: impl IntoIterator<Item = usize>,
primary: Option<usize>,
)
pub fn replace_indices( &mut self, selected: impl IntoIterator<Item = usize>, primary: Option<usize>, )
Replace the selection after a model refresh while preserving the
logical primary item. Callers map stable item identities to their new
indices first; indices absent from selected cannot become primary.
pub fn select_only(&mut self, i: usize)
pub fn select_only(&mut self, i: usize)
Replace the selection with the single index i. Resets the
anchor and cursor to i. This is the plain-click / plain-arrow
behaviour and the public primitive other code can call directly.
pub fn toggle(&mut self, i: usize)
pub fn toggle(&mut self, i: usize)
Toggle i in/out of the selection (Ctrl-click). The anchor and
cursor both move to i so a subsequent Shift gesture extends
from here.
pub fn select_range_to(&mut self, i: usize, additive: bool)
pub fn select_range_to(&mut self, i: usize, additive: bool)
Select the inclusive range from the anchor to i: unioned with the
existing selection when additive (Ctrl+Shift), else replacing it
(Shift). The anchor is preserved so repeated Shift gestures pivot
around the same origin. Falls back to select_only when there is
no anchor to extend from.
pub fn apply_click(&mut self, index: usize, ctrl: bool, shift: bool)
pub fn apply_click(&mut self, index: usize, ctrl: bool, shift: bool)
Apply a pointer click at index with the given modifier state.
This is the one call most widgets need from a mouse handler.
pub fn move_to(&mut self, index: usize, extend: bool)
pub fn move_to(&mut self, index: usize, extend: bool)
Move the keyboard cursor to index. With extend (Shift held)
it grows the contiguous range from the anchor; otherwise it
becomes a single selection. This is the one call most widgets
need from a key handler after computing the target index.
pub fn select_all(&mut self, count: usize)
pub fn select_all(&mut self, count: usize)
Select every index in 0..count. Anchor at 0, cursor at the
last index. No-op for an empty range.
Trait Implementations§
§impl Clone for SelectionModel
impl Clone for SelectionModel
§fn clone(&self) -> SelectionModel
fn clone(&self) -> SelectionModel
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more§impl Debug for SelectionModel
impl Debug for SelectionModel
§impl Default for SelectionModel
impl Default for SelectionModel
§fn default() -> SelectionModel
fn default() -> SelectionModel
§impl PartialEq for SelectionModel
impl PartialEq for SelectionModel
impl Eq for SelectionModel
impl StructuralPartialEq for SelectionModel
Auto Trait Implementations§
impl Freeze for SelectionModel
impl RefUnwindSafe for SelectionModel
impl Send for SelectionModel
impl Sync for SelectionModel
impl Unpin for SelectionModel
impl UnsafeUnpin for SelectionModel
impl UnwindSafe for SelectionModel
Blanket Implementations§
§impl<T> AnyEq for T
impl<T> AnyEq for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more