pub struct ScrollbarState { /* private fields */ }
Expand description
A struct representing the state of a Scrollbar widget.
§Important
It’s essential to set the content_length
field when using this struct. This field
represents the total length of the scrollable content. The default value is zero
which will result in the Scrollbar not rendering.
For example, in the following list, assume there are 4 bullet points:
- the
content_length
is 4 - the
position
is 0 - the
viewport_content_length
is 2
┌───────────────┐
│1. this is a █
│ single item █
│2. this is a ║
│ second item ║
└───────────────┘
If you don’t have multi-line content, you can leave the viewport_content_length
set to the
default and it’ll use the track size as a viewport_content_length
.
Implementations§
Source§impl ScrollbarState
impl ScrollbarState
Sourcepub const fn new(content_length: usize) -> Self
pub const fn new(content_length: usize) -> Self
Constructs a new ScrollbarState
with the specified content length.
content_length
is the total number of element, that can be scrolled. See
ScrollbarState
for more details.
Sourcepub const fn position(self, position: usize) -> Self
pub const fn position(self, position: usize) -> Self
Sets the scroll position of the scrollbar.
This represents the number of scrolled items.
This is a fluent setter method which must be chained or used as it consumes self
Sourcepub const fn content_length(self, content_length: usize) -> Self
pub const fn content_length(self, content_length: usize) -> Self
Sets the length of the scrollable content.
This is the number of scrollable items. If items have a length of one, then this is the same as the number of scrollable cells.
This is a fluent setter method which must be chained or used as it consumes self
Sourcepub const fn viewport_content_length(
self,
viewport_content_length: usize,
) -> Self
pub const fn viewport_content_length( self, viewport_content_length: usize, ) -> Self
Sets the items’ size.
This is a fluent setter method which must be chained or used as it consumes self
Sourcepub fn prev(&mut self)
pub fn prev(&mut self)
Decrements the scroll position by one, ensuring it doesn’t go below zero.
Sourcepub fn next(&mut self)
pub fn next(&mut self)
Increments the scroll position by one, ensuring it doesn’t exceed the length of the content.
Sourcepub fn scroll(&mut self, direction: ScrollDirection)
pub fn scroll(&mut self, direction: ScrollDirection)
Changes the scroll position based on the provided ScrollDirection
.
Trait Implementations§
Source§impl Clone for ScrollbarState
impl Clone for ScrollbarState
Source§fn clone(&self) -> ScrollbarState
fn clone(&self) -> ScrollbarState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for ScrollbarState
impl Debug for ScrollbarState
Source§impl Default for ScrollbarState
impl Default for ScrollbarState
Source§fn default() -> ScrollbarState
fn default() -> ScrollbarState
Source§impl Hash for ScrollbarState
impl Hash for ScrollbarState
Source§impl PartialEq for ScrollbarState
impl PartialEq for ScrollbarState
impl Copy for ScrollbarState
impl Eq for ScrollbarState
impl StructuralPartialEq for ScrollbarState
Auto Trait Implementations§
impl Freeze for ScrollbarState
impl RefUnwindSafe for ScrollbarState
impl Send for ScrollbarState
impl Sync for ScrollbarState
impl Unpin for ScrollbarState
impl UnwindSafe for ScrollbarState
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