Skip to main content

thedes_tui/slidebar/
style.rs

1use std::sync::Arc;
2
3use thedes_tui_core::{
4    color::{BasicColor, Color, ColorPair},
5    geometry::Coord,
6    grapheme,
7};
8
9#[derive(Debug, Clone, PartialEq)]
10pub struct Style {
11    background: Color,
12    title_colors: ColorPair,
13    message_colors: ColorPair,
14    bar_colors: ColorPair,
15    back_colors: ColorPair,
16    left_margin: Coord,
17    right_margin: Coord,
18    top_margin: Coord,
19    title_slidebar_padding: Coord,
20    slidebar_message_padding: Coord,
21    message_back_padding: Coord,
22    bottom_margin: Coord,
23    left_arrow: Arc<str>,
24    right_arrow: Arc<str>,
25    left_bar_ch: grapheme::Id,
26    right_bar_ch: grapheme::Id,
27    slide_handle: Arc<str>,
28    back_label: Arc<str>,
29}
30
31impl Default for Style {
32    fn default() -> Self {
33        let default_colors = ColorPair::default();
34        Self {
35            background: Color::default(),
36            title_colors: default_colors,
37            message_colors: default_colors,
38            bar_colors: default_colors,
39            back_colors: ColorPair {
40                background: BasicColor::White.into(),
41                foreground: BasicColor::Black.into(),
42            },
43            left_margin: 1,
44            right_margin: 1,
45            top_margin: 1,
46            title_slidebar_padding: 1,
47            slidebar_message_padding: 1,
48            message_back_padding: 1,
49            bottom_margin: 1,
50            left_arrow: Arc::from(""),
51            right_arrow: Arc::from(""),
52            left_bar_ch: '═'.into(),
53            right_bar_ch: '─'.into(),
54            slide_handle: Arc::from("❚"),
55            back_label: Arc::from("BACK"),
56        }
57    }
58}
59
60impl Style {
61    pub fn new() -> Self {
62        Self::default()
63    }
64
65    pub fn background(&self) -> Color {
66        self.background
67    }
68
69    pub fn with_background(mut self, value: Color) -> Self {
70        self.background = value;
71        self
72    }
73
74    pub fn title_colors(&self) -> ColorPair {
75        self.title_colors
76    }
77
78    pub fn with_title_colors(mut self, value: ColorPair) -> Self {
79        self.title_colors = value;
80        self
81    }
82
83    pub fn message_colors(&self) -> ColorPair {
84        self.message_colors
85    }
86
87    pub fn with_message_colors(mut self, value: ColorPair) -> Self {
88        self.message_colors = value;
89        self
90    }
91
92    pub fn bar_colors(&self) -> ColorPair {
93        self.bar_colors
94    }
95
96    pub fn with_bar_colors(mut self, value: ColorPair) -> Self {
97        self.bar_colors = value;
98        self
99    }
100
101    pub fn back_colors(&self) -> ColorPair {
102        self.back_colors
103    }
104
105    pub fn with_back_colors(mut self, value: ColorPair) -> Self {
106        self.back_colors = value;
107        self
108    }
109
110    pub fn left_margin(&self) -> Coord {
111        self.left_margin
112    }
113
114    pub fn with_left_margin(mut self, value: Coord) -> Self {
115        self.left_margin = value;
116        self
117    }
118
119    pub fn right_margin(&self) -> Coord {
120        self.right_margin
121    }
122
123    pub fn with_right_margin(mut self, value: Coord) -> Self {
124        self.right_margin = value;
125        self
126    }
127
128    pub fn top_margin(&self) -> Coord {
129        self.top_margin
130    }
131
132    pub fn with_top_margin(mut self, value: Coord) -> Self {
133        self.top_margin = value;
134        self
135    }
136
137    pub fn title_slidebar_padding(&self) -> Coord {
138        self.title_slidebar_padding
139    }
140
141    pub fn with_title_slidebar_padding(mut self, value: Coord) -> Self {
142        self.title_slidebar_padding = value;
143        self
144    }
145
146    pub fn slidebar_message_padding(&self) -> Coord {
147        self.slidebar_message_padding
148    }
149
150    pub fn with_slidebar_message_padding(mut self, value: Coord) -> Self {
151        self.slidebar_message_padding = value;
152        self
153    }
154
155    pub fn message_back_padding(&self) -> Coord {
156        self.message_back_padding
157    }
158
159    pub fn with_message_back_padding(mut self, value: Coord) -> Self {
160        self.message_back_padding = value;
161        self
162    }
163
164    pub fn bottom_margin(&self) -> Coord {
165        self.bottom_margin
166    }
167
168    pub fn with_bottom_margin(mut self, value: Coord) -> Self {
169        self.bottom_margin = value;
170        self
171    }
172
173    pub fn left_arrow(&self) -> &str {
174        &self.left_arrow[..]
175    }
176
177    pub fn with_left_arrow(mut self, value: impl AsRef<str>) -> Self {
178        self.left_arrow = value.as_ref().into();
179        self
180    }
181
182    pub fn right_arrow(&self) -> &str {
183        &self.right_arrow[..]
184    }
185
186    pub fn with_right_arrow(mut self, value: impl AsRef<str>) -> Self {
187        self.right_arrow = value.as_ref().into();
188        self
189    }
190
191    pub fn left_bar_ch(&self) -> grapheme::Id {
192        self.left_bar_ch
193    }
194
195    pub fn with_left_bar_ch(mut self, value: grapheme::Id) -> Self {
196        self.left_bar_ch = value;
197        self
198    }
199
200    pub fn right_bar_ch(&self) -> grapheme::Id {
201        self.right_bar_ch
202    }
203
204    pub fn with_right_bar_ch(mut self, value: grapheme::Id) -> Self {
205        self.right_bar_ch = value;
206        self
207    }
208
209    pub fn slide_handle(&self) -> &str {
210        &self.slide_handle[..]
211    }
212
213    pub fn with_slide_handle(mut self, value: impl AsRef<str>) -> Self {
214        self.slide_handle = value.as_ref().into();
215        self
216    }
217
218    pub fn back_label(&self) -> &str {
219        &self.back_label[..]
220    }
221
222    pub fn with_back_label(mut self, value: impl AsRef<str>) -> Self {
223        self.back_label = value.as_ref().into();
224        self
225    }
226}