pub struct ListState {
pub items: Vec<String>,
pub selected: usize,
pub filter: String,
/* private fields */
}Expand description
State for a selectable list widget.
Pass a mutable reference to Context::list each frame. Up/Down arrow
keys (and k/j) move the selection when the widget is focused.
Fields§
§items: Vec<String>The list items as display strings.
selected: usizeIndex of the currently selected item.
filter: StringCase-insensitive substring filter applied to list items.
Implementations§
Source§impl ListState
impl ListState
Sourcepub fn new(items: Vec<impl Into<String>>) -> Self
pub fn new(items: Vec<impl Into<String>>) -> Self
Create a list with the given items. The first item is selected initially.
Sourcepub fn set_items(&mut self, items: Vec<impl Into<String>>)
pub fn set_items(&mut self, items: Vec<impl Into<String>>)
Replace the list items and rebuild the view index.
Use this instead of assigning items directly to ensure the internal
filter/view state stays consistent.
Sourcepub fn set_filter(&mut self, filter: impl Into<String>)
pub fn set_filter(&mut self, filter: impl Into<String>)
Set the filter string. Multiple space-separated tokens are AND’d together — all tokens must match across any cell in the same row. Empty string disables filtering.
Sourcepub fn visible_indices(&self) -> &[usize]
pub fn visible_indices(&self) -> &[usize]
Returns indices of items visible after filtering.
Sourcepub fn selected_item(&self) -> Option<&str>
pub fn selected_item(&self) -> Option<&str>
Get the currently selected item text, or None if the list is empty.