ScrollState

Struct 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: 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

Source

pub fn new() -> Self

Source

pub fn set_orientation(&mut self, orientation: ScrollbarOrientation)

Source

pub fn is_vertical(&self) -> bool

Vertical scroll?

Source

pub fn is_horizontal(&self) -> bool

Horizontal scroll?

Source

pub fn clear(&mut self)

Resets the offset to 0.

Source

pub fn offset(&self) -> usize

Current vertical offset.

Source

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.

Source

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.

Source

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.

Source

pub fn scroll_up(&mut self, n: usize) -> bool

Scroll up by n.

Source

pub fn scroll_down(&mut self, n: usize) -> bool

Scroll down by n.

Source

pub fn scroll_left(&mut self, n: usize) -> bool

Scroll left by n.

Source

pub fn scroll_right(&mut self, n: usize) -> bool

Scroll right by n.

Source

pub fn limited_offset(&self, offset: usize) -> usize

Calculate the offset limited to max_offset+overscroll_by.

Source

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.

Source

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.

Source

pub fn page_len(&self) -> usize

Page-size at the current offset.

Source

pub fn set_page_len(&mut self, page: usize)

Page-size at the current offset.

Source

pub fn scroll_by(&self) -> usize

Suggested scroll per scroll-event. Defaults to 1/10 of the page

Source

pub fn set_scroll_by(&mut self, scroll: Option<usize>)

Suggested scroll per scroll-event. Defaults to 1/10 of the page

Source

pub fn overscroll_by(&self) -> usize

Allowed overscroll

Source

pub fn set_overscroll_by(&mut self, overscroll_by: Option<usize>)

Allowed overscroll

Source

pub fn items_added(&mut self, pos: usize, n: usize)

Update the state to match adding items.

Source

pub fn items_removed(&mut self, pos: usize, n: usize)

Update the state to match removing items.

Source§

impl ScrollState

Source

pub fn map_position_index(&self, pos: u16, base: u16, length: u16) -> usize

Maps a screen-position to an offset. pos - row/column clicked base - x/y of the range length - width/height of the range.

Trait Implementations§

Source§

impl Clone for ScrollState

Source§

fn clone(&self) -> ScrollState

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ScrollState

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ScrollState

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl HandleEvent<Event, MouseOnly, ScrollOutcome> for ScrollState

Source§

fn handle(&mut self, event: &Event, _qualifier: MouseOnly) -> ScrollOutcome

Handle an event. Read more
Source§

impl PartialEq for ScrollState

Source§

fn eq(&self, other: &ScrollState) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl RelocatableState for ScrollState

Source§

fn relocate(&mut self, shift: (i16, i16), clip: Rect)

Relocate the areas in this widgets state.
Source§

impl Eq for ScrollState

Source§

impl StructuralPartialEq for ScrollState

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.