pub struct Scrollbar { /* private fields */ }Expand description
A vertical scrollbar (typically one cell wide) covering total_len
items in a visible_len-row viewport.
offset defaults to 0; track_style/thumb_style default to
Style::new(). Set whichever a caller needs via
Scrollbar::offset/Scrollbar::track_style/Scrollbar::thumb_style.
track_style fills the whole strip, then crate::draw::thumb_geometry’s
span (if any) is redrawn with thumb_style on top. Draws just the plain
track, with no thumb, if there’s nothing to scroll: see
crate::draw::thumb_geometry.
Deliberately independent of crate::interact: see
crate::draw::thumb_geometry and
crate::draw::offset_for_pos’s own doc comments for how to make this
draggable using Interaction instead.
§Examples
use retroglyph_core::{Grid, Rect};
use retroglyph_widgets::{Scrollbar, Surface, Widget};
let area = Rect::new(0, 0, 1, 10);
let mut grid = Grid::new(1, 10);
Scrollbar::new(100, 10)
.offset(20)
.render(area, &mut Surface::new(&mut grid, area, 0));Implementations§
Source§impl Scrollbar
impl Scrollbar
Sourcepub fn new(total_len: usize, visible_len: usize) -> Self
pub fn new(total_len: usize, visible_len: usize) -> Self
A scrollbar covering total_len items in a visible_len-row
viewport, starting at offset 0 in the default style.
Sourcepub const fn track_style(self, style: Style) -> Self
pub const fn track_style(self, style: Style) -> Self
Set the track’s style.
Sourcepub const fn thumb_style(self, style: Style) -> Self
pub const fn thumb_style(self, style: Style) -> Self
Set the thumb’s style.
Sourcepub fn theme(self, theme: Theme) -> Self
pub fn theme(self, theme: Theme) -> Self
Applies theme’s named roles to this scrollbar: track_style becomes theme.panel_bg
(the same surface the scrolled content sits on), and thumb_style becomes theme.border:
a subtle divider-like color rather than theme.accent, so a themed scrollbar doesn’t
compete with an actually-selected/focused control for attention.
Call before any manual Scrollbar::track_style/Scrollbar::thumb_style override you
want to keep.
Sourcepub fn theme_on(self, theme: Theme, bg: Color) -> Self
pub fn theme_on(self, theme: Theme, bg: Color) -> Self
Same as Scrollbar::theme, but track_style is drawn on bg instead of
theme.panel_bg: for a scrollbar drawn directly on a backdrop other than a themed
super::Panel/super::Modal’s fill. Scrollbar::theme is exactly
theme_on(theme, theme.panel_bg).