pub struct ScrollState {
pub selected_idx: Option<usize>,
pub scroll_top: usize,
}Expand description
Generic scroll/selection state for a vertical list menu.
Encapsulates the common behavior of a selectable list that supports:
- Optional selection (None when list is empty)
- Wrap-around navigation on Up/Down
- Maintaining a scroll window (
scroll_top) so the selected row stays visible
Callers own the filtered row count and the visible window size. Every mutation method takes those values instead of caching them here, so list views can apply filters, pagination, or density changes without this helper knowing about their data model. Passing a stale length after filtering would leave selection pointing at the wrong row, so callers should clamp or move through this type immediately after changing their visible row set.
Fields§
§selected_idx: Option<usize>§scroll_top: usizeImplementations§
Source§impl ScrollState
impl ScrollState
pub fn new() -> Self
Sourcepub fn clamp_selection(&mut self, len: usize)
pub fn clamp_selection(&mut self, len: usize)
Clamp selection to be within the [0, len-1] range, or None when empty.
Sourcepub fn move_up_wrap(&mut self, len: usize)
pub fn move_up_wrap(&mut self, len: usize)
Move selection up by one, wrapping to the bottom when necessary.
Sourcepub fn move_down_wrap(&mut self, len: usize)
pub fn move_down_wrap(&mut self, len: usize)
Move selection down by one, wrapping to the top when necessary.
Sourcepub fn page_up_clamped(&mut self, len: usize, visible_rows: usize)
pub fn page_up_clamped(&mut self, len: usize, visible_rows: usize)
Move selection up by one visible page, clamping at the first row.
Page movement intentionally does not wrap. It mirrors terminal list behavior where repeated page-up/page-down converges at the nearest edge while still keeping the selected row visible.
Sourcepub fn page_down_clamped(&mut self, len: usize, visible_rows: usize)
pub fn page_down_clamped(&mut self, len: usize, visible_rows: usize)
Move selection down by one visible page, clamping at the last row.
Page movement intentionally does not wrap. It mirrors terminal list behavior where repeated page-up/page-down converges at the nearest edge while still keeping the selected row visible.
Sourcepub fn jump_bottom(&mut self, len: usize, visible_rows: usize)
pub fn jump_bottom(&mut self, len: usize, visible_rows: usize)
Jump selection to the last row.
Sourcepub fn ensure_visible(&mut self, len: usize, visible_rows: usize)
pub fn ensure_visible(&mut self, len: usize, visible_rows: usize)
Adjust scroll_top so that the current selected_idx is visible within
the window of visible_rows.
Trait Implementations§
Source§impl Clone for ScrollState
impl Clone for ScrollState
Source§fn clone(&self) -> ScrollState
fn clone(&self) -> ScrollState
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for ScrollState
Source§impl Debug for ScrollState
impl Debug for ScrollState
Source§impl Default for ScrollState
impl Default for ScrollState
Source§fn default() -> ScrollState
fn default() -> ScrollState
Auto Trait Implementations§
impl Freeze for ScrollState
impl RefUnwindSafe for ScrollState
impl Send for ScrollState
impl Sync for ScrollState
impl Unpin for ScrollState
impl UnsafeUnpin for ScrollState
impl UnwindSafe for ScrollState
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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> ⓘ
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