Skip to main content

GlyphSet

Struct GlyphSet 

Source
pub struct GlyphSet {
    pub track_vertical: char,
    pub track_horizontal: char,
    pub arrow_vertical_start: char,
    pub arrow_vertical_end: char,
    pub arrow_horizontal_start: char,
    pub arrow_horizontal_end: char,
    pub thumb_vertical_lower: [char; 8],
    pub thumb_vertical_upper: [char; 8],
    pub thumb_horizontal_left: [char; 8],
    pub thumb_horizontal_right: [char; 8],
}
Expand description

Glyphs used to render the track, arrows, and thumb.

Arrays use indices 0..=7 to represent 1/8th through full coverage.

Fields§

§track_vertical: char

Track glyph for vertical scrollbars.

§track_horizontal: char

Track glyph for horizontal scrollbars.

§arrow_vertical_start: char

Arrow glyph for the start of a vertical scrollbar (top).

§arrow_vertical_end: char

Arrow glyph for the end of a vertical scrollbar (bottom).

§arrow_horizontal_start: char

Arrow glyph for the start of a horizontal scrollbar (left).

§arrow_horizontal_end: char

Arrow glyph for the end of a horizontal scrollbar (right).

§thumb_vertical_lower: [char; 8]

Thumb glyphs for vertical lower fills (1/8th through full).

§thumb_vertical_upper: [char; 8]

Thumb glyphs for vertical upper fills (1/8th through full).

§thumb_horizontal_left: [char; 8]

Thumb glyphs for horizontal left fills (1/8th through full).

§thumb_horizontal_right: [char; 8]

Thumb glyphs for horizontal right fills (1/8th through full).

Implementations§

Source§

impl GlyphSet

Source

pub const fn minimal() -> Self

Minimal glyphs: no visible track by default.

Choose this when the thumb should stand out by color against a filled background instead of a visible line.

This uses a space character for the track so the scrollbar is “all thumb”, with the background color coming from track_style.

[██      ]
[🮋█▏     ]
[🮊█▎     ]
[🮉█▍     ]
[▐█▌     ]
[🮈█▋     ]
[🮇█▊     ]
[▕█▉     ]
[ ██     ]
Source

pub const fn box_drawing() -> Self

Glyphs that include box-drawing line symbols for the track.

Choose this when callers should see a visible track line behind the thumb.

[██──────]
[🮋█▏─────]
[🮊█▎─────]
[🮉█▍─────]
[▐█▌─────]
[🮈█▋─────]
[🮇█▊─────]
[▕█▉─────]
[─██─────]
Examples found in repository?
examples/scrollbar_styled.rs (line 61)
24fn render(area: Rect, frame: &mut ratatui::Frame) {
25    if area.width < 2 || area.height < 2 {
26        return;
27    }
28
29    let horizontal_bar = area
30        .rows()
31        .next_back()
32        .unwrap_or(area)
33        .inner(Margin::new(1, 0));
34    let vertical_bar = area
35        .columns()
36        .next_back()
37        .unwrap_or(area)
38        .inner(Margin::new(0, 1));
39
40    let block = Block::new()
41        .borders(Borders::ALL)
42        .title("styled scrollbars")
43        .border_style((Color::LightBlue, Color::Black))
44        .style((Color::Gray, Color::Black));
45    let content = block.inner(area).inner(Margin::new(2, 1));
46    frame.render_widget(block, area);
47
48    frame.render_widget(
49        Paragraph::new("track_style, thumb_style, and arrow_style can each use distinct colors")
50            .style((Color::Gray, Color::Black)),
51        content,
52    );
53
54    let lengths = ScrollLengths {
55        content_len: 160,
56        viewport_len: 40,
57    };
58    let horizontal = ScrollBar::horizontal(lengths)
59        .offset(48)
60        .arrows(ScrollBarArrows::Both)
61        .glyph_set(GlyphSet::box_drawing())
62        .track_style((Color::Blue, Color::Black).into())
63        .thumb_style((Color::Yellow, Modifier::BOLD).into())
64        .arrow_style((Color::LightGreen, Color::Black, Modifier::BOLD).into());
65    let vertical = ScrollBar::vertical(lengths)
66        .offset(80)
67        .arrows(ScrollBarArrows::Both)
68        .glyph_set(GlyphSet::box_drawing())
69        .track_style((Color::Magenta, Color::Black).into())
70        .thumb_style((Color::Cyan, Modifier::BOLD).into())
71        .arrow_style((Color::LightRed, Color::Black, Modifier::BOLD).into());
72
73    frame.render_widget(&horizontal, horizontal_bar);
74    frame.render_widget(&vertical, vertical_bar);
75}
Source

pub const fn symbols_for_legacy_computing() -> Self

Glyphs that mix standard block elements with legacy supplement glyphs.

Choose this when the terminal font supports Symbols for Legacy Computing and you want precise 1/8th-cell rendering on every thumb edge.

Use this to get full 1/8th coverage for upper and right edges that the standard block set lacks; these glyphs come from Symbols for Legacy Computing.

[██──────]
[🮋█▏─────]
[🮊█▎─────]
[🮉█▍─────]
[▐█▌─────]
[🮈█▋─────]
[🮇█▊─────]
[▕█▉─────]
[─██─────]
Source

pub const fn unicode() -> Self

Glyphs using only standard Unicode block elements.

Choose this if your font lacks the legacy glyphs.

The standard block set does not include 1/8th upper or right fills (those come from Symbols for Legacy Computing), so this set approximates upper and right partials by rounding to coarse blocks:

  • ~1/4: /
  • ~1/2 and ~3/4: /
  • ~7/8 and full:
[██──────]
[██▏─────]
[▐█▎─────]
[▐█▍─────]
[▐█▌─────]
[▐█▋─────]
[▕█▊─────]
[▕█▉─────]
[─██─────]

Trait Implementations§

Source§

impl Clone for GlyphSet

Source§

fn clone(&self) -> GlyphSet

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for GlyphSet

Source§

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

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

impl Default for GlyphSet

Source§

fn default() -> Self

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

impl Eq for GlyphSet

Source§

impl PartialEq for GlyphSet

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 StructuralPartialEq for GlyphSet

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.