pub struct Scrollbar<'a> { /* private fields */ }Expand description
A widget to display a scrollbar
The following components of the scrollbar are customizable in symbol and style. Note the scrollbar is represented horizontally but it can also be set vertically (which is actually the default).
<--▮------->
^ ^ ^ ^
│ │ │ └ end
│ │ └──── track
│ └──────── thumb
└─────────── begin§Important
You must specify the ScrollbarState::content_length before rendering the Scrollbar, or
else the Scrollbar will render blank.
§Examples
use ratatui::Frame;
use ratatui::layout::{Margin, Rect};
use ratatui::text::Line;
use ratatui::widgets::{
Block, Borders, Paragraph, Scrollbar, ScrollbarOrientation, ScrollbarState, StatefulWidget,
};
let vertical_scroll = 0; // from app state
let items = vec![
Line::from("Item 1"),
Line::from("Item 2"),
Line::from("Item 3"),
];
let paragraph = Paragraph::new(items.clone())
.scroll((vertical_scroll as u16, 0))
.block(Block::new().borders(Borders::RIGHT)); // to show a background for the scrollbar
let scrollbar = Scrollbar::new(ScrollbarOrientation::VerticalRight)
.begin_symbol(Some("↑"))
.end_symbol(Some("↓"));
let mut scrollbar_state = ScrollbarState::new(items.len()).position(vertical_scroll);
let area = frame.area();
// Note we render the paragraph
frame.render_widget(paragraph, area);
// and the scrollbar, those are separate widgets
frame.render_stateful_widget(
scrollbar,
area.inner(Margin {
// using an inner vertical margin of 1 unit makes the scrollbar inside the block
vertical: 1,
horizontal: 0,
}),
&mut scrollbar_state,
);Implementations§
Source§impl<'a> Scrollbar<'a>
impl<'a> Scrollbar<'a>
Sourcepub const fn new(orientation: ScrollbarOrientation) -> Scrollbar<'a>
pub const fn new(orientation: ScrollbarOrientation) -> Scrollbar<'a>
Creates a new scrollbar with the given orientation.
Most of the time you’ll want ScrollbarOrientation::VerticalRight or
ScrollbarOrientation::HorizontalBottom. See ScrollbarOrientation for more options.
Sourcepub const fn orientation(
self,
orientation: ScrollbarOrientation,
) -> Scrollbar<'a>
pub const fn orientation( self, orientation: ScrollbarOrientation, ) -> Scrollbar<'a>
Sets the position of the scrollbar.
The orientation of the scrollbar is the position it will take around a Rect. See
ScrollbarOrientation for more details.
Resets the symbols to DOUBLE_VERTICAL or DOUBLE_HORIZONTAL based on orientation.
This is a fluent setter method which must be chained or used as it consumes self
Sourcepub const fn orientation_and_symbol(
self,
orientation: ScrollbarOrientation,
symbols: Set<'a>,
) -> Scrollbar<'a>
pub const fn orientation_and_symbol( self, orientation: ScrollbarOrientation, symbols: Set<'a>, ) -> Scrollbar<'a>
Sets the orientation and symbols for the scrollbar from a Set.
This has the same effect as calling Scrollbar::orientation and then
Scrollbar::symbols. See those for more details.
This is a fluent setter method which must be chained or used as it consumes self
Sourcepub const fn thumb_symbol(self, thumb_symbol: &'a str) -> Scrollbar<'a>
pub const fn thumb_symbol(self, thumb_symbol: &'a str) -> Scrollbar<'a>
Sets the symbol that represents the thumb of the scrollbar.
The thumb is the handle representing the progression on the scrollbar. See Scrollbar
for a visual example of what this represents.
This is a fluent setter method which must be chained or used as it consumes self
Sourcepub fn thumb_style<S>(self, thumb_style: S) -> Scrollbar<'a>
pub fn thumb_style<S>(self, thumb_style: S) -> Scrollbar<'a>
Sets the style on the scrollbar thumb.
The thumb is the handle representing the progression on the scrollbar. See Scrollbar
for a visual example of what this represents.
style accepts any type that is convertible to Style (e.g. Style, Color, or
your own type that implements Into<Style>).
This is a fluent setter method which must be chained or used as it consumes self
Sourcepub const fn track_symbol(self, track_symbol: Option<&'a str>) -> Scrollbar<'a>
pub const fn track_symbol(self, track_symbol: Option<&'a str>) -> Scrollbar<'a>
Sets the symbol that represents the track of the scrollbar.
See Scrollbar for a visual example of what this represents.
This is a fluent setter method which must be chained or used as it consumes self
Sourcepub fn track_style<S>(self, track_style: S) -> Scrollbar<'a>
pub fn track_style<S>(self, track_style: S) -> Scrollbar<'a>
Sets the style that is used for the track of the scrollbar.
See Scrollbar for a visual example of what this represents.
style accepts any type that is convertible to Style (e.g. Style, Color, or
your own type that implements Into<Style>).
This is a fluent setter method which must be chained or used as it consumes self
Sourcepub const fn begin_symbol(self, begin_symbol: Option<&'a str>) -> Scrollbar<'a>
pub const fn begin_symbol(self, begin_symbol: Option<&'a str>) -> Scrollbar<'a>
Sets the symbol that represents the beginning of the scrollbar.
See Scrollbar for a visual example of what this represents.
This is a fluent setter method which must be chained or used as it consumes self
Sourcepub fn begin_style<S>(self, begin_style: S) -> Scrollbar<'a>
pub fn begin_style<S>(self, begin_style: S) -> Scrollbar<'a>
Sets the style that is used for the beginning of the scrollbar.
See Scrollbar for a visual example of what this represents.
style accepts any type that is convertible to Style (e.g. Style, Color, or
your own type that implements Into<Style>).
This is a fluent setter method which must be chained or used as it consumes self
Sourcepub const fn end_symbol(self, end_symbol: Option<&'a str>) -> Scrollbar<'a>
pub const fn end_symbol(self, end_symbol: Option<&'a str>) -> Scrollbar<'a>
Sets the symbol that represents the end of the scrollbar.
See Scrollbar for a visual example of what this represents.
This is a fluent setter method which must be chained or used as it consumes self
Sourcepub fn end_style<S>(self, end_style: S) -> Scrollbar<'a>
pub fn end_style<S>(self, end_style: S) -> Scrollbar<'a>
Sets the style that is used for the end of the scrollbar.
See Scrollbar for a visual example of what this represents.
style accepts any type that is convertible to Style (e.g. Style, Color, or
your own type that implements Into<Style>).
This is a fluent setter method which must be chained or used as it consumes self
Sourcepub const fn symbols(self, symbols: Set<'a>) -> Scrollbar<'a>
pub const fn symbols(self, symbols: Set<'a>) -> Scrollbar<'a>
Sets the symbols used for the various parts of the scrollbar from a Set.
<--▮------->
^ ^ ^ ^
│ │ │ └ end
│ │ └──── track
│ └──────── thumb
└─────────── beginOnly sets begin_symbol, end_symbol and track_symbol if they already contain a value.
If they were set to None explicitly, this function will respect that choice. Use their
respective setters to change their value.
This is a fluent setter method which must be chained or used as it consumes self
Sourcepub fn style<S>(self, style: S) -> Scrollbar<'a>
pub fn style<S>(self, style: S) -> Scrollbar<'a>
Sets the style used for the various parts of the scrollbar from a Style.
style accepts any type that is convertible to Style (e.g. Style, Color, or
your own type that implements Into<Style>).
<--▮------->
^ ^ ^ ^
│ │ │ └ end
│ │ └──── track
│ └──────── thumb
└─────────── beginThis is a fluent setter method which must be chained or used as it consumes self
Trait Implementations§
Source§impl StatefulWidget for Scrollbar<'_>
impl StatefulWidget for Scrollbar<'_>
Source§type State = ScrollbarState
type State = ScrollbarState
impl<'a> Eq for Scrollbar<'a>
impl<'a> StructuralPartialEq for Scrollbar<'a>
Auto Trait Implementations§
impl<'a> Freeze for Scrollbar<'a>
impl<'a> RefUnwindSafe for Scrollbar<'a>
impl<'a> Send for Scrollbar<'a>
impl<'a> Sync for Scrollbar<'a>
impl<'a> Unpin for Scrollbar<'a>
impl<'a> UnwindSafe for Scrollbar<'a>
Blanket Implementations§
Source§impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
Source§fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
Source§fn adapt_into(self) -> D
fn adapt_into(self) -> D
Source§impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
Source§fn arrays_from(colors: C) -> T
fn arrays_from(colors: C) -> T
Source§impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
Source§fn arrays_into(self) -> C
fn arrays_into(self) -> C
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<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
Source§type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
parameters when converting.Source§fn cam16_into_unclamped(
self,
parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>,
) -> T
fn cam16_into_unclamped( self, parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>, ) -> T
self into C, using the provided parameters.Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
Source§fn components_from(colors: C) -> T
fn components_from(colors: C) -> T
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> FromAngle<T> for T
impl<T> FromAngle<T> for T
Source§fn from_angle(angle: T) -> T
fn from_angle(angle: T) -> T
angle.Source§impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
Source§fn from_stimulus(other: U) -> T
fn from_stimulus(other: U) -> T
other into Self, while performing the appropriate scaling,
rounding and clamping.Source§impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
Source§fn into_angle(self) -> U
fn into_angle(self) -> U
T.Source§impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
Source§type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
parameters when converting.Source§fn into_cam16_unclamped(
self,
parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>,
) -> T
fn into_cam16_unclamped( self, parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>, ) -> T
self into C, using the provided parameters.Source§impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
Source§fn into_color(self) -> U
fn into_color(self) -> U
Source§impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
Source§fn into_color_unclamped(self) -> U
fn into_color_unclamped(self) -> U
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 moreSource§impl<T> IntoStimulus<T> for T
impl<T> IntoStimulus<T> for T
Source§fn into_stimulus(self) -> T
fn into_stimulus(self) -> T
self into T, while performing the appropriate scaling,
rounding and clamping.Source§impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
Source§type Error = <C as TryFromComponents<T>>::Error
type Error = <C as TryFromComponents<T>>::Error
try_into_colors fails to cast.Source§fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
Source§impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
Source§fn try_into_color(self) -> Result<U, OutOfBounds<U>>
fn try_into_color(self) -> Result<U, OutOfBounds<U>>
OutOfBounds error is returned which contains
the unclamped color. Read more