Struct rat_widget::scrolled::ScrollState
source · 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: RectArea of the Scrollbar.
orientation: ScrollbarOrientationVertical/Horizontal scroll?
offset: usizeCurrent offset.
page_len: usizePage-size at the current offset.
max_offset: usizeMaximum 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.
scroll_by: Option<usize>Scrolling step-size for mouse-scrolling
overscroll_by: Option<usize>Allow overscroll by n items.
mouse: MouseFlagsMouse support.
non_exhaustive: NonExhaustiveImplementations§
source§impl ScrollState
impl ScrollState
pub fn new() -> ScrollState
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. Limits the offset to max_v_offset + v_overscroll.
Due to overscroll it’s 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_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 limit_offset(&self, offset: usize) -> usize
pub fn limit_offset(&self, offset: usize) -> usize
Calculate the offset limited to max_offset+overscroll_by.
sourcepub fn clamp_offset(&self, offset: isize) -> usize
pub fn clamp_offset(&self, offset: isize) -> 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§fn default() -> ScrollState
fn default() -> 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
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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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