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