pub struct ListState {
pub selected: Option<usize>,
pub hovered: Option<usize>,
pub offset: usize,
pub focused: bool,
/* private fields */
}Expand description
Mutable state for a List widget tracking selection and scroll offset.
Fields§
§selected: Option<usize>Index of the currently selected item, if any.
hovered: Option<usize>Index of the currently hovered item, if any.
offset: usizeScroll offset (first visible item index).
focused: boolWhether this list currently owns keyboard focus.
Implementations§
Source§impl ListState
impl ListState
Sourcepub fn select(&mut self, index: Option<usize>)
pub fn select(&mut self, index: Option<usize>)
Set the selected item index, or None to deselect.
Sourcepub fn set_focused(&mut self, focused: bool)
pub fn set_focused(&mut self, focused: bool)
Mark whether this list currently owns keyboard focus.
Sourcepub fn with_focused(self, focused: bool) -> Self
pub fn with_focused(self, focused: bool) -> Self
Builder for keyboard focus ownership.
Sourcepub const fn is_focused(&self) -> bool
pub const fn is_focused(&self) -> bool
Whether this list currently owns keyboard focus.
Sourcepub fn with_persistence_id(self, id: impl Into<String>) -> Self
pub fn with_persistence_id(self, id: impl Into<String>) -> Self
Create a new ListState with a persistence ID for state saving. Without
one the list has no StateKey and its state is not persisted.
Sourcepub fn persistence_id(&self) -> Option<&str>
pub fn persistence_id(&self) -> Option<&str>
Get the persistence ID, if set.
Sourcepub fn set_multi_select(&mut self, enabled: bool)
pub fn set_multi_select(&mut self, enabled: bool)
Enable or disable multi-select mode.
Sourcepub const fn multi_select_enabled(&self) -> bool
pub const fn multi_select_enabled(&self) -> bool
Whether multi-select mode is enabled.
Sourcepub fn filter_query(&self) -> &str
pub fn filter_query(&self) -> &str
Current incremental filter query.
Sourcepub fn set_filter_query(&mut self, query: impl Into<String>)
pub fn set_filter_query(&mut self, query: impl Into<String>)
Replace the incremental filter query.
Sourcepub fn clear_filter_query(&mut self)
pub fn clear_filter_query(&mut self)
Clear the current filter query.
Sourcepub fn selected_count(&self) -> usize
pub fn selected_count(&self) -> usize
Number of selected rows (single or multi mode).
Sourcepub fn selected_indices(&self) -> &BTreeSet<usize>
pub fn selected_indices(&self) -> &BTreeSet<usize>
Selected indices in multi-select mode.
Sourcepub fn with_hover_stabilizer(self, config: HoverStabilizerConfig) -> Self
pub fn with_hover_stabilizer(self, config: HoverStabilizerConfig) -> Self
Route hover through a CUSUM hover stabilizer
(ftui_core::hover_stabilizer) so one-cell pointer jitter across a
row boundary keeps the hovered row while a decisive move still
switches within a frame. Without it, hovered follows the raw hit
test on every mouse move.
Sourcepub fn hover_stabilizer(&self) -> Option<&HoverStabilizer>
pub fn hover_stabilizer(&self) -> Option<&HoverStabilizer>
The hover stabilizer, if one is attached (diagnostics such as
HoverStabilizer::switch_count).
Sourcepub fn handle_mouse(
&mut self,
event: &MouseEvent,
hit: Option<(HitId, HitRegion, u64)>,
expected_id: HitId,
item_count: usize,
) -> MouseResult
pub fn handle_mouse( &mut self, event: &MouseEvent, hit: Option<(HitId, HitRegion, u64)>, expected_id: HitId, item_count: usize, ) -> MouseResult
Handle a mouse event for this list.
§Hit data convention
The hit data (u64) encodes the item index. When the list renders with
a hit_id, each visible row registers HitRegion::Content with
data = item_index as u64.
§Arguments
event— the mouse event from the terminalhit— result offrame.hit_test(event.x, event.y), if availableexpected_id— theHitIdthis list was rendered withitem_count— total number of items in the list
Sourcepub fn scroll_down(&mut self, lines: usize, item_count: usize)
pub fn scroll_down(&mut self, lines: usize, item_count: usize)
Scroll the list down by the given number of lines.
Clamps so that the last item can still appear at the top of the viewport.
Sourcepub fn select_next(&mut self, item_count: usize)
pub fn select_next(&mut self, item_count: usize)
Move selection to the next item.
If nothing is selected, selects the first item. Clamps to the last item.
Sourcepub fn select_previous(&mut self)
pub fn select_previous(&mut self)
Move selection to the previous item.
If nothing is selected, selects the first item. Clamps to 0.
Trait Implementations§
Source§impl ListUndoExt for ListState
impl ListUndoExt for ListState
Source§fn selected_index(&self) -> Option<usize>
fn selected_index(&self) -> Option<usize>
Source§fn set_selected_index(&mut self, index: Option<usize>)
fn set_selected_index(&mut self, index: Option<usize>)
Source§impl Stateful for ListState
impl Stateful for ListState
Source§type State = ListPersistState
type State = ListPersistState
Source§fn state_key(&self) -> Option<StateKey>
fn state_key(&self) -> Option<StateKey>
None if it has no
stable identity and must not be persisted. Read more