pub struct ListState {
pub selected: Option<usize>,
pub hovered: Option<usize>,
pub offset: usize,
/* 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).
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 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.
Sourcepub fn persistence_id(&self) -> Option<&str>
pub fn persistence_id(&self) -> Option<&str>
Get the persistence ID, if set.
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.