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