pub struct ScrollState {
pub area: Rect,
pub orientation: ScrollbarOrientation,
pub offset: usize,
pub page_len: usize,
pub max_offset: usize,
pub scroll_by: Option<usize>,
pub overscroll_by: Option<usize>,
pub mouse: MouseFlags,
pub non_exhaustive: NonExhaustive,
}
Expand description
Scroll state.
The current visible page is represented as the pair (offset, page_len).
The limit for scrolling is given as max_offset, which is the maximum offset where a full page can still be displayed.
Note
that the total length of the widgets data is NOT max_offset + page_len. The page_len can be different for every offset selected. Only if the offset is set to max_offset and after the next round of rendering len == max_offset + page_len will hold true.
Note
In terms of ScrollbarState,
- offset is position,
- page_len is viewport_content_length and
- max_offset is content_length.
Fields§
§area: Rect
Area of the Scrollbar. readonly. renewed for each render.
orientation: ScrollbarOrientation
Vertical/Horizontal scroll? readonly. renewed for each render.
offset: usize
Current offset. read+write
page_len: usize
Length of the current displayed page. This value can be used for page-up/page-down handling. read+write
max_offset: usize
Maximum offset that is accessible with scrolling.
This offset is calculated as item_count - last_page_items
. Both
are abstract values and can denote items or columns/rows as
the widget sees fit.
read+write
scroll_by: Option<usize>
How many items are scrolled per scroll event. When not set it defaults to 1/10 of the page_len, which gives a decent median between scroll speed and disorientation. read+write
overscroll_by: Option<usize>
By how much can the max_offset be exceeded. This allows displaying some empty space at the end of the content, which can be more intuitive for some widgets. read+write
mouse: MouseFlags
Mouse support. read+write
non_exhaustive: NonExhaustive
Implementations§
Source§impl ScrollState
impl ScrollState
pub fn new() -> Self
pub fn set_orientation(&mut self, orientation: ScrollbarOrientation)
Sourcepub fn is_vertical(&self) -> bool
pub fn is_vertical(&self) -> bool
Vertical scroll?
Sourcepub fn is_horizontal(&self) -> bool
pub fn is_horizontal(&self) -> bool
Horizontal scroll?
Sourcepub fn set_offset(&mut self, offset: usize) -> bool
pub fn set_offset(&mut self, offset: usize) -> bool
Change the offset. There is no limitation to the value set here. It’s therefore possible that this is an invalid offset for the widget. The widget must deal with this situation.
Sourcepub fn scroll_to_pos(&mut self, pos: usize) -> bool
pub fn scroll_to_pos(&mut self, pos: usize) -> bool
Scroll to make the given pos visible. Adjusts the offset just enough to make this happen. Does nothing if the position is already visible.
Sourcepub fn scroll_to_range(&mut self, range: Range<usize>) -> bool
pub fn scroll_to_range(&mut self, range: Range<usize>) -> bool
Scroll to make the given range visible.Adjusts the offset just enough to make this happen. Does nothing if the range is already visible.
Sourcepub fn scroll_down(&mut self, n: usize) -> bool
pub fn scroll_down(&mut self, n: usize) -> bool
Scroll down by n.
Sourcepub fn scroll_left(&mut self, n: usize) -> bool
pub fn scroll_left(&mut self, n: usize) -> bool
Scroll left by n.
Sourcepub fn scroll_right(&mut self, n: usize) -> bool
pub fn scroll_right(&mut self, n: usize) -> bool
Scroll right by n.
Sourcepub fn limited_offset(&self, offset: usize) -> usize
pub fn limited_offset(&self, offset: usize) -> usize
Calculate the offset limited to max_offset+overscroll_by.
Sourcepub fn max_offset(&self) -> usize
pub fn max_offset(&self) -> usize
Maximum offset that is accessible with scrolling.
This is shorter than the length of the content by whatever fills the last page. This is the base for the scrollbar content_length.
Sourcepub fn set_max_offset(&mut self, max: usize)
pub fn set_max_offset(&mut self, max: usize)
Maximum offset that is accessible with scrolling.
This is shorter than the length of the content by whatever fills the last page. This is the base for the scrollbar content_length.
Sourcepub fn set_page_len(&mut self, page: usize)
pub fn set_page_len(&mut self, page: usize)
Page-size at the current offset.
Sourcepub fn scroll_by(&self) -> usize
pub fn scroll_by(&self) -> usize
Suggested scroll per scroll-event. Defaults to 1/10 of the page
Sourcepub fn set_scroll_by(&mut self, scroll: Option<usize>)
pub fn set_scroll_by(&mut self, scroll: Option<usize>)
Suggested scroll per scroll-event. Defaults to 1/10 of the page
Sourcepub fn overscroll_by(&self) -> usize
pub fn overscroll_by(&self) -> usize
Allowed overscroll
Sourcepub fn set_overscroll_by(&mut self, overscroll_by: Option<usize>)
pub fn set_overscroll_by(&mut self, overscroll_by: Option<usize>)
Allowed overscroll
Sourcepub fn items_added(&mut self, pos: usize, n: usize)
pub fn items_added(&mut self, pos: usize, n: usize)
Update the state to match adding items.
Sourcepub fn items_removed(&mut self, pos: usize, n: usize)
pub fn items_removed(&mut self, pos: usize, n: usize)
Update the state to match removing items.
Source§impl ScrollState
impl ScrollState
Trait Implementations§
Source§impl Clone for ScrollState
impl Clone for ScrollState
Source§fn clone(&self) -> ScrollState
fn clone(&self) -> ScrollState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for ScrollState
impl Debug for ScrollState
Source§impl Default for ScrollState
impl Default for ScrollState
Source§impl HandleEvent<Event, MouseOnly, ScrollOutcome> for ScrollState
impl HandleEvent<Event, MouseOnly, ScrollOutcome> for ScrollState
Source§impl PartialEq for ScrollState
impl PartialEq for ScrollState
Source§impl RelocatableState for ScrollState
impl RelocatableState for ScrollState
impl Eq for ScrollState
impl StructuralPartialEq for 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 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.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