pub struct ListState { /* private fields */ }Expand description
Unified list state machine for single and multi-select
Owns the item texts so filtering stays internal to the state
machine. visible maps display positions to absolute indices into
items, and cursor addresses a position within visible. The
selected set holds absolute indices, which is what lets
selections survive filtering.
Implementations§
Source§impl ListState
impl ListState
pub fn new(items: Vec<String>, multi_select: bool, initial_diff: bool) -> Self
pub fn items(&self) -> &[String]
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn search_active(&self) -> bool
Sourcepub fn search_query(&self) -> Option<&str>
pub fn search_query(&self) -> Option<&str>
The current search query, Some (possibly empty) while search
mode is active
Sourcepub fn visible_items(&self) -> impl Iterator<Item = (usize, &str)>
pub fn visible_items(&self) -> impl Iterator<Item = (usize, &str)>
The currently visible items as (absolute index, text) pairs
Sourcepub fn highlighted(&self) -> Option<usize>
pub fn highlighted(&self) -> Option<usize>
Absolute index of the item under the cursor, None when the
filtered list is empty
pub fn show_diff(&self) -> bool
pub fn set_show_diff(&mut self, show_diff: bool)
pub fn is_selected(&self, index: usize) -> bool
pub fn selected_count(&self) -> usize
Sourcepub fn selected_indices(&self) -> Vec<usize>
pub fn selected_indices(&self) -> Vec<usize>
Get sorted list of selected indices for deterministic iteration
pub fn multi_select(&self) -> bool
Sourcepub fn handle(&mut self, action: ListAction) -> Option<ListResult>
pub fn handle(&mut self, action: ListAction) -> Option<ListResult>
Handle a list action, returns Some if the interaction is complete
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ListState
impl RefUnwindSafe for ListState
impl Send for ListState
impl Sync for ListState
impl Unpin for ListState
impl UnsafeUnpin for ListState
impl UnwindSafe for ListState
Blanket Implementations§
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§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> ⓘ
Converts
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> ⓘ
Converts
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