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 /// Minimal glyphs: no visible track by default.
32 ///
33 /// This uses a space character for the track so the scrollbar is "all thumb", with the
34 /// background color coming from `track_style`.
35 ///
36 /// ```plain
37 /// [██ ]
38 /// [🮋█▏ ]
39 /// [🮊█▎ ]
40 /// [🮉█▍ ]
41 /// [▐█▌ ]
42 /// [🮈█▋ ]
43 /// [🮇█▊ ]
44 /// [▕█▉ ]
45 /// [ ██ ]
46 /// ```
47 pub const fn minimal() -> Self {
48 let mut glyphs = Self::symbols_for_legacy_computing();
49 glyphs.track_vertical = ' ';
50 glyphs.track_horizontal = ' ';
51 glyphs
52 }
53
54 /// Glyphs that include box-drawing line symbols for the track.
55 ///
56 /// ```plain
57 /// [██──────]
58 /// [🮋█▏─────]
59 /// [🮊█▎─────]
60 /// [🮉█▍─────]
61 /// [▐█▌─────]
62 /// [🮈█▋─────]
63 /// [🮇█▊─────]
64 /// [▕█▉─────]
65 /// [─██─────]
66 /// ```
67 pub const fn box_drawing() -> Self {
68 Self::symbols_for_legacy_computing()
69 }
70
71 /// Glyphs that mix standard block elements with legacy supplement glyphs.
72 ///
73 /// Use this to get full 1/8th coverage for upper and right edges that the standard block set
74 /// lacks; these glyphs come from [Symbols for Legacy Computing].
75 ///
76 /// ```plain
77 /// [██──────]
78 /// [🮋█▏─────]
79 /// [🮊█▎─────]
80 /// [🮉█▍─────]
81 /// [▐█▌─────]
82 /// [🮈█▋─────]
83 /// [🮇█▊─────]
84 /// [▕█▉─────]
85 /// [─██─────]
86 /// ```
87 ///
88 /// [Symbols for Legacy Computing]: https://en.wikipedia.org/wiki/Symbols_for_Legacy_Computing
89 pub const fn symbols_for_legacy_computing() -> Self {
90 let vertical_lower = ['▁', '▂', '▃', '▄', '▅', '▆', '▇', '█'];
91 let vertical_upper = ['▔', '🮂', '🮃', '▀', '🮄', '🮅', '🮆', '█'];
92 let horizontal_left = ['▏', '▎', '▍', '▌', '▋', '▊', '▉', '█'];
93 let horizontal_right = ['▕', '🮇', '🮈', '▐', '🮉', '🮊', '🮋', '█'];
94 Self {
95 track_vertical: '│',
96 track_horizontal: '─',
97 arrow_vertical_start: '▲',
98 arrow_vertical_end: '▼',
99 arrow_horizontal_start: '◀',
100 arrow_horizontal_end: '▶',
101 thumb_vertical_lower: vertical_lower,
102 thumb_vertical_upper: vertical_upper,
103 thumb_horizontal_left: horizontal_left,
104 thumb_horizontal_right: horizontal_right,
105 }
106 }
107
108 /// Glyphs using only standard Unicode block elements.
109 ///
110 /// Use this if your font lacks the legacy glyphs.
111 ///
112 /// The standard block set does not include 1/8th upper or right fills (those come from
113 /// [Symbols for Legacy Computing]), so this set approximates upper and right partials by
114 /// rounding to coarse blocks:
115 ///
116 /// - ~1/4: `▔` / `▕`
117 /// - ~1/2 and ~3/4: `▀` / `▐`
118 /// - ~7/8 and full: `█`
119 ///
120 /// ```plain
121 /// [██──────]
122 /// [██▏─────]
123 /// [▐█▎─────]
124 /// [▐█▍─────]
125 /// [▐█▌─────]
126 /// [▐█▋─────]
127 /// [▕█▊─────]
128 /// [▕█▉─────]
129 /// [─██─────]
130 /// ```
131 pub const fn unicode() -> Self {
132 let vertical_lower = ['▁', '▂', '▃', '▄', '▅', '▆', '▇', '█'];
133 let vertical_upper = ['▔', '▔', '▀', '▀', '▀', '▀', '█', '█'];
134 let horizontal_left = ['▏', '▎', '▍', '▌', '▋', '▊', '▉', '█'];
135 let horizontal_right = ['▕', '▕', '▐', '▐', '▐', '▐', '█', '█'];
136 Self {
137 track_vertical: '│',
138 track_horizontal: '─',
139 arrow_vertical_start: '▲',
140 arrow_vertical_end: '▼',
141 arrow_horizontal_start: '◀',
142 arrow_horizontal_end: '▶',
143 thumb_vertical_lower: vertical_lower,
144 thumb_vertical_upper: vertical_upper,
145 thumb_horizontal_left: horizontal_left,
146 thumb_horizontal_right: horizontal_right,
147 }
148 }
149}
150
151impl Default for GlyphSet {
152 fn default() -> Self {
153 Self::minimal()
154 }
155}