1use crate::RatWidgetColor;
2use crate::palette::{Colors, Palette};
3use crate::theme::SalsaTheme;
4use crate::{StyleName, WidgetStyle};
5use rat_widget::button::ButtonStyle;
6use rat_widget::calendar::CalendarStyle;
7use rat_widget::checkbox::CheckboxStyle;
8use rat_widget::choice::ChoiceStyle;
9use rat_widget::clipper::ClipperStyle;
10#[cfg(feature = "color_input")]
11use rat_widget::color_input::ColorInputStyle;
12use rat_widget::combobox::ComboboxStyle;
13use rat_widget::dialog_frame::DialogFrameStyle;
14use rat_widget::file_dialog::FileDialogStyle;
15use rat_widget::form::FormStyle;
16use rat_widget::line_number::LineNumberStyle;
17use rat_widget::list::ListStyle;
18use rat_widget::menu::MenuStyle;
19use rat_widget::msgdialog::MsgDialogStyle;
20use rat_widget::paragraph::ParagraphStyle;
21use rat_widget::radio::{RadioLayout, RadioStyle};
22use rat_widget::scrolled::{ScrollStyle, ScrollSymbols};
23use rat_widget::shadow::{ShadowDirection, ShadowStyle};
24use rat_widget::slider::SliderStyle;
25use rat_widget::splitter::SplitStyle;
26use rat_widget::statusline::StatusLineStyle;
27use rat_widget::tabbed::TabbedStyle;
28use rat_widget::table::TableStyle;
29use rat_widget::text::TextStyle;
30use rat_widget::view::ViewStyle;
31use ratatui::layout::Alignment;
32use ratatui::style::{Color, Style, Stylize};
33use ratatui::symbols;
34use ratatui::symbols::border;
35use ratatui::widgets::{Block, Borders};
36use std::time::Duration;
37
38pub fn create_shell(p: Palette) -> SalsaTheme {
43 let mut th = SalsaTheme::new(p);
44
45 th.define_style(Style::LABEL_FG, th.p.fg_style_alias(Color::LABEL_FG));
46 th.define_style(Style::INPUT, th.p.style_alias(Color::INPUT_BG));
47 th.define_style(Style::FOCUS, th.p.high_style_alias(Color::FOCUS_BG));
48 th.define_style(Style::SELECT, th.p.style_alias(Color::SELECT_BG));
49 th.define_style(Style::DISABLED, th.p.style_alias(Color::DISABLED_BG));
50 th.define_style(Style::INVALID, th.p.style_alias(Color::INVALID_BG));
51 th.define_style(Style::HOVER, th.p.style_alias(Color::HOVER_BG));
52 th.define_style(
53 Style::TITLE,
54 th.p.fg_bg_style_alias(Color::TITLE_FG, Color::TITLE_BG),
55 );
56 th.define_style(
57 Style::HEADER,
58 th.p.fg_bg_style_alias(Color::HEADER_FG, Color::HEADER_BG),
59 );
60 th.define_style(
61 Style::FOOTER,
62 th.p.fg_bg_style_alias(Color::FOOTER_FG, Color::HEADER_BG),
63 );
64 th.define_style(
65 Style::WEEK_HEADER_FG,
66 th.p.fg_style_alias(Color::WEEK_HEADER_FG),
67 );
68 th.define_style(
69 Style::MONTH_HEADER_FG,
70 th.p.fg_style_alias(Color::MONTH_HEADER_FG),
71 );
72 th.define_style(Style::SHADOWS, th.p.style_alias(Color::SHADOW_BG));
73 th.define_style(
74 Style::INPUT_FOCUS,
75 th.p.high_style_alias(Color::INPUT_FOCUS_BG),
76 );
77 th.define_style(Style::INPUT_SELECT, th.p.style_alias(Color::SELECT_BG));
78 th.define_style(Style::KEY_BINDING, th.p.style_alias(Color::KEY_BINDING_BG));
79
80 th.define_style(Style::BUTTON_BASE, th.p.style_alias(Color::BUTTON_BASE_BG));
81 th.define_style(Style::MENU_BASE, th.p.style_alias(Color::MENU_BASE_BG));
82 th.define_style(Style::STATUS_BASE, th.p.style_alias(Color::STATUS_BASE_BG));
83
84 th.define_style(
85 Style::CONTAINER_BASE,
86 th.p.style_alias(Color::CONTAINER_BASE_BG),
87 );
88 th.define_style(
89 Style::CONTAINER_BORDER_FG,
90 th.p.fg_style_alias(Color::CONTAINER_BORDER_FG),
91 );
92 th.define_style(
93 Style::CONTAINER_ARROW_FG,
94 th.p.fg_style_alias(Color::CONTAINER_ARROW_FG),
95 );
96
97 th.define_style(
98 Style::DOCUMENT_BASE,
99 th.p.style_alias(Color::DOCUMENT_BASE_BG),
100 );
101 th.define_style(
102 Style::DOCUMENT_BORDER_FG,
103 th.p.fg_style_alias(Color::DOCUMENT_BORDER_FG),
104 );
105 th.define_style(
106 Style::DOCUMENT_ARROW_FG,
107 th.p.fg_style_alias(Color::DOCUMENT_ARROW_FG),
108 );
109
110 th.define_style(Style::POPUP_BASE, th.p.style_alias(Color::POPUP_BASE_BG));
111 th.define_style(
112 Style::POPUP_BORDER_FG,
113 th.p.fg_style_alias(Color::POPUP_BORDER_FG),
114 );
115 th.define_style(
116 Style::POPUP_ARROW_FG,
117 th.p.fg_style_alias(Color::POPUP_ARROW_FG),
118 );
119
120 th.define_style(Style::DIALOG_BASE, th.p.style_alias(Color::DIALOG_BASE_BG));
121 th.define_style(
122 Style::DIALOG_BORDER_FG,
123 th.p.fg_style_alias(Color::DIALOG_BORDER_FG),
124 );
125 th.define_style(
126 Style::DIALOG_ARROW_FG,
127 th.p.fg_style_alias(Color::DIALOG_ARROW_FG),
128 );
129
130 th.define_fn(WidgetStyle::BUTTON, button);
131 th.define_fn(WidgetStyle::CALENDAR, month);
132 th.define_fn(WidgetStyle::CHECKBOX, checkbox);
133 th.define_fn(WidgetStyle::CHOICE, choice);
134 th.define_fn(WidgetStyle::CLIPPER, clipper);
135 th.define_fn(WidgetStyle::COMBOBOX, combobox);
136 #[cfg(feature = "color_input")]
137 th.define_fn(WidgetStyle::COLOR_INPUT, color_input);
138 th.define_fn(WidgetStyle::DIALOG_FRAME, dialog_frame);
139 th.define_fn(WidgetStyle::FILE_DIALOG, file_dialog);
140 th.define_fn(WidgetStyle::FORM, form);
141 th.define_fn(WidgetStyle::LINE_NR, line_nr);
142 th.define_fn(WidgetStyle::LIST, list);
143 th.define_fn(WidgetStyle::MENU, menu);
144 th.define_fn(WidgetStyle::MONTH, month);
145 th.define_fn(WidgetStyle::MSG_DIALOG, msg_dialog);
146 th.define_fn(WidgetStyle::PARAGRAPH, paragraph);
147 th.define_fn(WidgetStyle::RADIO, radio);
148 th.define_fn(WidgetStyle::SCROLL, scroll);
149 th.define_fn(WidgetStyle::SCROLL_DIALOG, dialog_scroll);
150 th.define_fn(WidgetStyle::SCROLL_POPUP, popup_scroll);
151 th.define_fn(WidgetStyle::SHADOW, shadow);
152 th.define_fn(WidgetStyle::SLIDER, slider);
153 th.define_fn(WidgetStyle::SPLIT, split);
154 th.define_fn(WidgetStyle::STATUSLINE, statusline);
155 th.define_fn(WidgetStyle::TABBED, tabbed);
156 th.define_fn(WidgetStyle::TABLE, table);
157 th.define_fn(WidgetStyle::TEXT, text);
158 th.define_fn(WidgetStyle::TEXTAREA, textarea);
159 th.define_fn(WidgetStyle::TEXTVIEW, textview);
160 th.define_fn(WidgetStyle::VIEW, view);
161
162 th
163}
164
165fn button(th: &SalsaTheme) -> ButtonStyle {
166 ButtonStyle {
167 style: th.style(Style::BUTTON_BASE),
168 focus: Some(th.style(Style::FOCUS)),
169 armed: Some(th.style(Style::SELECT)),
170 hover: Some(th.p.style_alias(Color::HOVER_BG)),
171 armed_delay: Some(Duration::from_millis(50)),
172 ..Default::default()
173 }
174}
175
176fn checkbox(th: &SalsaTheme) -> CheckboxStyle {
177 CheckboxStyle {
178 style: th.style(Style::INPUT),
179 focus: Some(th.style(Style::INPUT_FOCUS)),
180 ..Default::default()
181 }
182}
183
184fn combobox(th: &SalsaTheme) -> ComboboxStyle {
185 ComboboxStyle {
186 choice: th.style(WidgetStyle::CHOICE),
187 text: th.style(WidgetStyle::TEXT),
188 ..Default::default()
189 }
190}
191
192fn choice(th: &SalsaTheme) -> ChoiceStyle {
193 ChoiceStyle {
194 style: th.style(Style::INPUT),
195 select: Some(th.style(Style::INPUT_SELECT)),
196 focus: Some(th.style(Style::INPUT_FOCUS)),
197 popup_style: Some(th.style(Style::POPUP_BASE)),
198 popup_border: Some(th.style(Style::POPUP_BORDER_FG)),
199 popup_scroll: Some(th.style(WidgetStyle::SCROLL_POPUP)),
200 popup_block: Some(
201 Block::bordered()
202 .borders(Borders::LEFT | Borders::BOTTOM | Borders::RIGHT)
203 .border_set(border::Set {
204 top_left: "X",
205 top_right: "X",
206 bottom_left: "▀",
207 bottom_right: "▀",
208 vertical_left: "▌",
209 vertical_right: "▐",
210 horizontal_top: "X",
211 horizontal_bottom: "▀",
212 })
213 .border_style(th.style::<Style>(Style::POPUP_BORDER_FG)),
214 ),
215 ..Default::default()
216 }
217}
218
219fn clipper(th: &SalsaTheme) -> ClipperStyle {
220 ClipperStyle {
221 style: th.style(Style::CONTAINER_BASE),
222 label_style: Some(th.style(Style::LABEL_FG)),
223 scroll: Some(th.style(WidgetStyle::SCROLL)),
224 ..Default::default()
225 }
226}
227
228fn dialog_frame(th: &SalsaTheme) -> DialogFrameStyle {
229 DialogFrameStyle {
230 style: th.style(Style::DIALOG_BASE),
231 border_style: Some(th.style::<Style>(Style::DIALOG_BORDER_FG)),
232 button_style: Some(th.style(WidgetStyle::BUTTON)),
233 ..DialogFrameStyle::default()
234 }
235}
236
237fn file_dialog(th: &SalsaTheme) -> FileDialogStyle {
238 FileDialogStyle {
239 style: th.style(Style::DIALOG_BASE),
240 list: Some(th.style(WidgetStyle::LIST)),
241 roots: Some(ListStyle {
242 style: th.style(Style::DIALOG_BASE),
243 ..th.style(WidgetStyle::LIST)
244 }),
245 text: Some(th.style(WidgetStyle::TEXT)),
246 button: Some(th.style(WidgetStyle::BUTTON)),
247 block: Some(Block::bordered()),
248 ..Default::default()
249 }
250}
251
252fn form(th: &SalsaTheme) -> FormStyle {
253 FormStyle {
254 style: th.style(Style::CONTAINER_BASE),
255 label_style: Some(th.style(Style::LABEL_FG)),
256 navigation: Some(th.style(Style::CONTAINER_ARROW_FG)),
257 navigation_hover: Some(th.style(Style::HOVER)),
258 block: Some(
259 Block::bordered()
260 .borders(Borders::TOP | Borders::BOTTOM)
261 .border_set(border::EMPTY)
262 .border_style(th.style::<Style>(Style::CONTAINER_BORDER_FG)),
263 ),
264 border_style: Some(th.style::<Style>(Style::CONTAINER_BORDER_FG)),
265 ..Default::default()
266 }
267}
268
269fn line_nr(th: &SalsaTheme) -> LineNumberStyle {
270 LineNumberStyle {
271 style: th.style(Style::CONTAINER_BASE),
272 cursor: Some(th.style(Style::INPUT_SELECT)),
273 ..LineNumberStyle::default()
274 }
275}
276
277fn list(th: &SalsaTheme) -> ListStyle {
278 ListStyle {
279 style: th.style(Style::CONTAINER_BASE),
280 select: Some(th.style(Style::SELECT)),
281 focus: Some(th.style(Style::FOCUS)),
282 scroll: Some(th.style(WidgetStyle::SCROLL)),
283 ..Default::default()
284 }
285}
286
287fn menu(th: &SalsaTheme) -> MenuStyle {
288 MenuStyle {
289 style: th.style(Style::MENU_BASE),
290 title: Some(th.style(Style::TITLE)),
291 focus: Some(th.style(Style::FOCUS)),
292 right: Some(th.style(Style::KEY_BINDING)),
293 disabled: Some(th.style(Style::DISABLED)),
294 highlight: Some(Style::default().underlined()),
295 popup_block: Some(Block::bordered()),
296 popup: Default::default(),
297 popup_border: Some(th.style(Style::MENU_BASE)),
298 popup_style: Some(th.style(Style::MENU_BASE)),
299 popup_focus: Some(th.style(Style::FOCUS)),
300 popup_right: Some(th.style(Style::KEY_BINDING)),
301 popup_disabled: Some(th.style(Style::DISABLED)),
302 popup_highlight: Some(Style::default().underlined()),
303 ..Default::default()
304 }
305}
306
307fn month(th: &SalsaTheme) -> CalendarStyle {
308 CalendarStyle {
309 style: th.style(Style::CONTAINER_BASE),
310 title: Some(th.style(Style::MONTH_HEADER_FG)),
311 weeknum: Some(th.style(Style::WEEK_HEADER_FG)),
312 weekday: Some(th.style(Style::WEEK_HEADER_FG)),
313 day: None,
314 select: Some(th.style(Style::SELECT)),
315 focus: Some(th.style(Style::FOCUS)),
316 ..CalendarStyle::default()
317 }
318}
319
320fn msg_dialog(th: &SalsaTheme) -> MsgDialogStyle {
321 MsgDialogStyle {
322 style: th.style(Style::DIALOG_BASE),
323 button: Some(th.style(WidgetStyle::BUTTON)),
324 ..Default::default()
325 }
326}
327
328fn paragraph(th: &SalsaTheme) -> ParagraphStyle {
329 ParagraphStyle {
330 style: th.style(Style::CONTAINER_BASE),
331 focus: Some(th.style(Style::FOCUS)),
332 scroll: Some(th.style(WidgetStyle::SCROLL)),
333 ..Default::default()
334 }
335}
336
337fn radio(th: &SalsaTheme) -> RadioStyle {
338 RadioStyle {
339 layout: Some(RadioLayout::Stacked),
340 style: th.style(Style::INPUT),
341 focus: Some(th.style(Style::INPUT_FOCUS)),
342 ..Default::default()
343 }
344}
345
346fn scroll(th: &SalsaTheme) -> ScrollStyle {
348 ScrollStyle {
349 thumb_style: Some(th.style(Style::CONTAINER_BORDER_FG)),
350 track_style: Some(th.style(Style::CONTAINER_BORDER_FG)),
351 min_style: Some(th.style(Style::CONTAINER_BORDER_FG)),
352 begin_style: Some(th.style(Style::CONTAINER_ARROW_FG)),
353 end_style: Some(th.style(Style::CONTAINER_ARROW_FG)),
354 horizontal: Some(ScrollSymbols {
355 track: "▒",
356 thumb: symbols::block::FULL,
357 begin: "←",
358 end: "→",
359 min: "░",
360 }),
361 vertical: Some(ScrollSymbols {
362 track: "▒",
363 thumb: symbols::block::FULL,
364 begin: "↑",
365 end: "↓",
366 min: "░",
367 }),
368 ..Default::default()
369 }
370}
371
372fn popup_scroll(th: &SalsaTheme) -> ScrollStyle {
373 ScrollStyle {
374 thumb_style: Some(th.style(Style::POPUP_BORDER_FG)),
375 track_style: Some(th.style(Style::POPUP_BORDER_FG)),
376 min_style: Some(th.style(Style::POPUP_BORDER_FG)),
377 begin_style: Some(th.style(Style::POPUP_ARROW_FG)),
378 end_style: Some(th.style(Style::POPUP_ARROW_FG)),
379 horizontal: Some(ScrollSymbols {
380 track: "▒",
381 thumb: symbols::block::FULL,
382 begin: "←",
383 end: "→",
384 min: "░",
385 }),
386 vertical: Some(ScrollSymbols {
387 track: "▒",
388 thumb: symbols::block::FULL,
389 begin: "↑",
390 end: "↓",
391 min: "░",
392 }),
393 ..Default::default()
394 }
395}
396
397fn dialog_scroll(th: &SalsaTheme) -> ScrollStyle {
398 ScrollStyle {
399 thumb_style: Some(th.style(Style::DIALOG_BORDER_FG)),
400 track_style: Some(th.style(Style::DIALOG_BORDER_FG)),
401 min_style: Some(th.style(Style::DIALOG_BORDER_FG)),
402 begin_style: Some(th.style(Style::POPUP_ARROW_FG)),
403 end_style: Some(th.style(Style::POPUP_ARROW_FG)),
404 horizontal: Some(ScrollSymbols {
405 track: "▒",
406 thumb: symbols::block::FULL,
407 begin: "←",
408 end: "→",
409 min: "░",
410 }),
411 vertical: Some(ScrollSymbols {
412 track: "▒",
413 thumb: symbols::block::FULL,
414 begin: "↑",
415 end: "↓",
416 min: "░",
417 }),
418 ..Default::default()
419 }
420}
421
422fn shadow(th: &SalsaTheme) -> ShadowStyle {
423 ShadowStyle {
424 style: th.style(Style::SHADOWS),
425 dir: ShadowDirection::BottomRight,
426 ..ShadowStyle::default()
427 }
428}
429
430fn slider(th: &SalsaTheme) -> SliderStyle {
431 SliderStyle {
432 style: th.style(Style::INPUT),
433 bounds: Some(th.style(Style::INPUT)),
434 knob: Some(th.style(Style::INPUT_SELECT)),
435 focus: Some(th.style(Style::INPUT_FOCUS)),
436 text_align: Some(Alignment::Center),
437 ..Default::default()
438 }
439}
440
441fn split(th: &SalsaTheme) -> SplitStyle {
442 SplitStyle {
443 style: th.style(Style::CONTAINER_BORDER_FG),
444 arrow_style: Some(th.style(Style::CONTAINER_ARROW_FG)),
445 drag_style: Some(th.style(Style::HOVER)),
446 ..Default::default()
447 }
448}
449
450fn statusline(th: &SalsaTheme) -> StatusLineStyle {
451 StatusLineStyle {
452 styles: vec![
453 th.style(Style::STATUS_BASE),
454 th.p.style(Colors::Blue, 3),
455 th.p.style(Colors::Blue, 2),
456 th.p.style(Colors::Blue, 1),
457 ],
458 ..Default::default()
459 }
460}
461
462fn tabbed(th: &SalsaTheme) -> TabbedStyle {
463 TabbedStyle {
464 style: th.style(Style::CONTAINER_BASE),
465 border_style: Some(th.style(Style::CONTAINER_BORDER_FG)),
466 tab: Some(th.style(Style::CONTAINER_BASE)),
467 hover: Some(th.style(Style::HOVER)),
468 select: Some(th.style(Style::SELECT)),
469 focus: Some(th.style(Style::FOCUS)),
470 ..Default::default()
471 }
472}
473
474fn table(th: &SalsaTheme) -> TableStyle {
475 TableStyle {
476 style: th.style(Style::CONTAINER_BASE),
477 select_row: Some(th.style(Style::SELECT)),
478 show_row_focus: true,
479 focus_style: Some(th.style(Style::FOCUS)),
480 border_style: Some(th.style(Style::CONTAINER_BORDER_FG)),
481 scroll: Some(th.style(WidgetStyle::SCROLL)),
482 header: Some(th.style(Style::HEADER)),
483 footer: Some(th.style(Style::FOOTER)),
484 ..Default::default()
485 }
486}
487
488#[cfg(feature = "color_input")]
489fn color_input(th: &SalsaTheme) -> ColorInputStyle {
490 ColorInputStyle {
491 text: TextStyle {
492 style: th.style(Style::INPUT),
493 focus: Some(th.style(Style::INPUT_FOCUS)),
494 select: Some(th.style(Style::INPUT_SELECT)),
495 invalid: Some(th.style(Style::INVALID)),
496 ..TextStyle::default()
497 },
498 ..Default::default()
499 }
500}
501
502fn text(th: &SalsaTheme) -> TextStyle {
503 TextStyle {
504 style: th.style(Style::INPUT),
505 focus: Some(th.style(Style::INPUT_FOCUS)),
506 select: Some(th.style(Style::INPUT_SELECT)),
507 invalid: Some(th.style(Style::INVALID)),
508 ..TextStyle::default()
509 }
510}
511
512fn textarea(th: &SalsaTheme) -> TextStyle {
513 TextStyle {
514 style: th.style(Style::INPUT),
515 focus: Some(th.style(Style::INPUT)),
516 select: Some(th.style(Style::INPUT_SELECT)),
517 scroll: Some(th.style(WidgetStyle::SCROLL)),
518 border_style: Some(th.style(Style::CONTAINER_BORDER_FG)),
519 ..TextStyle::default()
520 }
521}
522
523fn textview(th: &SalsaTheme) -> TextStyle {
524 TextStyle {
525 style: th.style(Style::CONTAINER_BASE),
526 focus: Some(th.style(Style::CONTAINER_BASE)),
527 select: Some(th.style(Style::INPUT_SELECT)),
528 scroll: Some(th.style(WidgetStyle::SCROLL)),
529 border_style: Some(th.style(Style::CONTAINER_BORDER_FG)),
530 ..TextStyle::default()
531 }
532}
533
534fn view(th: &SalsaTheme) -> ViewStyle {
535 ViewStyle {
536 scroll: Some(th.style(WidgetStyle::SCROLL)),
537 ..Default::default()
538 }
539}