tui_scrollbar/glyphs.rs
1//! Glyph configuration for scrollbar rendering.
2
3/// Glyphs used to render the track, arrows, and thumb.
4///
5/// Arrays use indices 0..=7 to represent 1/8th through full coverage.
6#[derive(Debug, Clone, PartialEq, Eq)]
7pub struct GlyphSet {
8 /// Track glyph for vertical scrollbars.
9 pub track_vertical: char,
10 /// Track glyph for horizontal scrollbars.
11 pub track_horizontal: char,
12 /// Arrow glyph for the start of a vertical scrollbar (top).
13 pub arrow_vertical_start: char,
14 /// Arrow glyph for the end of a vertical scrollbar (bottom).
15 pub arrow_vertical_end: char,
16 /// Arrow glyph for the start of a horizontal scrollbar (left).
17 pub arrow_horizontal_start: char,
18 /// Arrow glyph for the end of a horizontal scrollbar (right).
19 pub arrow_horizontal_end: char,
20 /// Thumb glyphs for vertical lower fills (1/8th through full).
21 pub thumb_vertical_lower: [char; 8],
22 /// Thumb glyphs for vertical upper fills (1/8th through full).
23 pub thumb_vertical_upper: [char; 8],
24 /// Thumb glyphs for horizontal left fills (1/8th through full).
25 pub thumb_horizontal_left: [char; 8],
26 /// Thumb glyphs for horizontal right fills (1/8th through full).
27 pub thumb_horizontal_right: [char; 8],
28}
29
30impl GlyphSet {
31 /// Glyphs that mix standard block elements with legacy supplement glyphs.
32 ///
33 /// Use this to get full 1/8th coverage for upper and right edges that the standard block set
34 /// lacks; these glyphs come from [Symbols for Legacy Computing].
35 ///
36 /// [Symbols for Legacy Computing]: https://en.wikipedia.org/wiki/Symbols_for_Legacy_Computing
37 pub const fn symbols_for_legacy_computing() -> Self {
38 let vertical_lower = ['▁', '▂', '▃', '▄', '▅', '▆', '▇', '█'];
39 let vertical_upper = ['▔', '🮂', '🮃', '▀', '🮄', '🮅', '🮆', '█'];
40 let horizontal_left = ['▏', '▎', '▍', '▌', '▋', '▊', '▉', '█'];
41 let horizontal_right = ['▕', '🮇', '🮈', '▐', '🮉', '🮊', '🮋', '█'];
42 Self {
43 track_vertical: '│',
44 track_horizontal: '─',
45 arrow_vertical_start: '▲',
46 arrow_vertical_end: '▼',
47 arrow_horizontal_start: '◀',
48 arrow_horizontal_end: '▶',
49 thumb_vertical_lower: vertical_lower,
50 thumb_vertical_upper: vertical_upper,
51 thumb_horizontal_left: horizontal_left,
52 thumb_horizontal_right: horizontal_right,
53 }
54 }
55
56 /// Glyphs using only standard Unicode block elements.
57 ///
58 /// Use this if your font lacks the legacy glyphs; upper/right partials will use the same
59 /// glyphs as lower/left partials.
60 pub const fn unicode() -> Self {
61 let vertical = ['▁', '▂', '▃', '▄', '▅', '▆', '▇', '█'];
62 let horizontal = ['▏', '▎', '▍', '▌', '▋', '▊', '▉', '█'];
63 Self {
64 track_vertical: '│',
65 track_horizontal: '─',
66 arrow_vertical_start: '▲',
67 arrow_vertical_end: '▼',
68 arrow_horizontal_start: '◀',
69 arrow_horizontal_end: '▶',
70 thumb_vertical_lower: vertical,
71 thumb_vertical_upper: vertical,
72 thumb_horizontal_left: horizontal,
73 thumb_horizontal_right: horizontal,
74 }
75 }
76}
77
78impl Default for GlyphSet {
79 fn default() -> Self {
80 Self::symbols_for_legacy_computing()
81 }
82}