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 message_colors: ColorPair,
13 selected_colors: ColorPair,
14 unselected_colors: ColorPair,
15 left_margin: Coord,
16 right_margin: Coord,
17 top_margin: Coord,
18 title_message_padding: Coord,
19 message_ok_padding: Coord,
20 ok_cancel_padding: Coord,
21 bottom_margin: Coord,
22 selected_left: Arc<str>,
23 selected_right: Arc<str>,
24 ok_label: Arc<str>,
25 cancel_label: Arc<str>,
26}
27
28impl Default for Style {
29 fn default() -> Self {
30 let default_colors = ColorPair::default();
31 let inverted_colors = ColorPair {
32 background: default_colors.foreground,
33 foreground: default_colors.background,
34 };
35 Self {
36 background: Color::default(),
37 title_colors: default_colors,
38 message_colors: default_colors,
39 unselected_colors: default_colors,
40 selected_colors: inverted_colors,
41 left_margin: 1,
42 right_margin: 1,
43 top_margin: 1,
44 bottom_margin: 1,
45 title_message_padding: 1,
46 message_ok_padding: 1,
47 ok_cancel_padding: 1,
48 selected_left: Arc::from("> "),
49 selected_right: Arc::from(" <"),
50 ok_label: Arc::from("OK"),
51 cancel_label: Arc::from("CANCEL"),
52 }
53 }
54}
55
56impl Style {
57 pub fn new() -> Self {
58 Self::default()
59 }
60
61 pub fn with_background(self, color: Color) -> Self {
62 Self { background: color, ..self }
63 }
64
65 pub fn background(&self) -> Color {
66 self.background
67 }
68
69 pub fn with_title_colors(self, colors: ColorPair) -> Self {
70 Self { title_colors: colors, ..self }
71 }
72
73 pub fn title_colors(&self) -> ColorPair {
74 self.title_colors
75 }
76
77 pub fn with_selected_colors(self, colors: ColorPair) -> Self {
78 Self { selected_colors: colors, ..self }
79 }
80
81 pub fn selected_colors(&self) -> ColorPair {
82 self.selected_colors
83 }
84
85 pub fn with_unselected_colors(self, colors: ColorPair) -> Self {
86 Self { unselected_colors: colors, ..self }
87 }
88
89 pub fn unselected_colors(&self) -> ColorPair {
90 self.unselected_colors
91 }
92
93 pub fn with_message_colors(self, colors: ColorPair) -> Self {
94 Self { message_colors: colors, ..self }
95 }
96
97 pub fn message_colors(&self) -> ColorPair {
98 self.message_colors
99 }
100
101 pub fn with_left_margin(self, amount: Coord) -> Self {
102 Self { left_margin: amount, ..self }
103 }
104
105 pub fn left_margin(&self) -> Coord {
106 self.left_margin
107 }
108
109 pub fn with_right_margin(self, amount: Coord) -> Self {
110 Self { right_margin: amount, ..self }
111 }
112
113 pub fn right_margin(&self) -> Coord {
114 self.right_margin
115 }
116
117 pub fn with_top_margin(self, amount: Coord) -> Self {
118 Self { top_margin: amount, ..self }
119 }
120
121 pub fn top_margin(&self) -> Coord {
122 self.top_margin
123 }
124
125 pub fn with_title_message_padding(self, amount: Coord) -> Self {
126 Self { title_message_padding: amount, ..self }
127 }
128
129 pub fn title_message_padding(&self) -> Coord {
130 self.title_message_padding
131 }
132
133 pub fn with_message_ok_padding(self, amount: Coord) -> Self {
134 Self { message_ok_padding: amount, ..self }
135 }
136
137 pub fn message_ok_padding(&self) -> Coord {
138 self.message_ok_padding
139 }
140
141 pub fn with_ok_cancel_padding(self, amount: Coord) -> Self {
142 Self { ok_cancel_padding: amount, ..self }
143 }
144
145 pub fn ok_cancel_padding(&self) -> Coord {
146 self.ok_cancel_padding
147 }
148
149 pub fn with_bottom_margin(self, amount: Coord) -> Self {
150 Self { bottom_margin: amount, ..self }
151 }
152
153 pub fn bottom_margin(&self) -> Coord {
154 self.bottom_margin
155 }
156
157 pub fn with_selected_left(self, text: impl AsRef<str>) -> Self {
158 Self { selected_left: text.as_ref().into(), ..self }
159 }
160
161 pub fn selected_left(&self) -> &str {
162 &self.selected_left[..]
163 }
164
165 pub fn with_selected_right(self, text: impl AsRef<str>) -> Self {
166 Self { selected_right: text.as_ref().into(), ..self }
167 }
168
169 pub fn selected_right(&self) -> &str {
170 &self.selected_right[..]
171 }
172
173 pub fn with_ok_label(self, text: impl AsRef<str>) -> Self {
174 Self { ok_label: text.as_ref().into(), ..self }
175 }
176
177 pub fn ok_label(&self) -> &str {
178 &self.ok_label[..]
179 }
180
181 pub fn with_cancel_label(self, text: impl AsRef<str>) -> Self {
182 Self { cancel_label: text.as_ref().into(), ..self }
183 }
184
185 pub fn cancel_label(&self) -> &str {
186 &self.cancel_label[..]
187 }
188}