1use crate::Rgba;
4use crate::model::border::{ResolvedWidgetBorder, WidgetBorderSpec};
5use crate::model::{
6 ArrowSide, DialogButtonOrder, DialogEntranceStyle, FontSpec, ResolvedFontSpec, TabIndicatorSide,
7};
8use native_theme_derive::{ThemeFields, ThemeWidget};
9
10#[serde_with::skip_serializing_none]
14#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
15#[serde(default)]
16#[theme_inherit(border_kind = "full_lg", font = "title_bar_font")]
17pub struct WindowTheme {
18 #[theme(inherit_from = "defaults.background_color")]
20 pub background_color: Option<Rgba>,
21 #[theme(inherit_from = "defaults.surface_color")]
23 pub title_bar_background: Option<Rgba>,
24 pub inactive_title_bar_background: Option<Rgba>,
26 pub inactive_title_bar_text_color: Option<Rgba>,
28 #[theme(nested, resolved_type = "ResolvedFontSpec")]
30 pub title_bar_font: Option<FontSpec>,
31 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
33 pub border: Option<WidgetBorderSpec>,
34}
35
36#[serde_with::skip_serializing_none]
40#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
41#[serde(default)]
42#[theme_inherit(border_kind = "full", font = "font")]
43pub struct ButtonTheme {
44 #[theme(inherit_from = "defaults.background_color")]
46 pub background_color: Option<Rgba>,
47 #[theme(inherit_from = "defaults.accent_color")]
49 pub primary_background: Option<Rgba>,
50 #[theme(inherit_from = "defaults.accent_text_color")]
52 pub primary_text_color: Option<Rgba>,
53 #[serde(rename = "min_width_px")]
55 #[theme(check = "non_negative")]
56 pub min_width: Option<f32>,
57 #[serde(rename = "min_height_px")]
59 #[theme(check = "non_negative")]
60 pub min_height: Option<f32>,
61 #[serde(rename = "icon_text_gap_px")]
63 #[theme(check = "non_negative")]
64 pub icon_text_gap: Option<f32>,
65 #[theme(range = "0.0..=1.0", inherit_from = "defaults.disabled_opacity")]
69 pub disabled_opacity: Option<f32>,
70 #[theme(inherit_from = "defaults.background_color")]
72 pub hover_background: Option<Rgba>,
73 pub hover_text_color: Option<Rgba>,
75 pub active_text_color: Option<Rgba>,
77 #[theme(inherit_from = "defaults.disabled_text_color")]
79 pub disabled_text_color: Option<Rgba>,
80 #[theme(category = "soft_option")]
82 pub active_background: Option<Rgba>,
83 #[theme(category = "soft_option")]
85 pub disabled_background: Option<Rgba>,
86 #[theme(category = "soft_option")]
93 pub checked_background: Option<Rgba>,
94 #[theme(category = "soft_option")]
97 pub checked_text_color: Option<Rgba>,
98 #[theme(category = "soft_option")]
102 pub hover_border_color: Option<Rgba>,
103 #[theme(category = "soft_option")]
107 pub focus_border_color: Option<Rgba>,
108 #[theme(category = "soft_option")]
119 pub default_button_background: Option<Rgba>,
120 #[theme(category = "soft_option")]
124 pub default_button_text_color: Option<Rgba>,
125 #[theme(category = "soft_option")]
129 pub default_button_border_color: Option<Rgba>,
130 #[theme(nested, resolved_type = "ResolvedFontSpec")]
132 pub font: Option<FontSpec>,
133 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
135 pub border: Option<WidgetBorderSpec>,
136}
137
138#[serde_with::skip_serializing_none]
143#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
144#[serde(default)]
145#[theme_inherit(border_kind = "full", font = "font")]
146pub struct InputTheme {
147 #[theme(inherit_from = "defaults.background_color")]
149 pub background_color: Option<Rgba>,
150 #[theme(inherit_from = "defaults.muted_color")]
152 pub placeholder_color: Option<Rgba>,
153 pub caret_color: Option<Rgba>,
155 #[serde(rename = "caret_blink_on_ms")]
161 #[theme(category = "soft_option", min_u32 = "1")]
162 pub caret_blink_on: Option<u32>,
163 #[serde(rename = "caret_blink_off_ms")]
168 #[theme(category = "soft_option")]
169 pub caret_blink_off: Option<u32>,
170 #[serde(rename = "caret_blink_timeout_ms")]
175 #[theme(category = "soft_option", min_u32 = "1")]
176 pub caret_blink_timeout: Option<u32>,
177 #[theme(inherit_from = "defaults.text_selection_background")]
179 pub selection_background: Option<Rgba>,
180 #[theme(inherit_from = "defaults.text_selection_color")]
182 pub selection_text_color: Option<Rgba>,
183 #[serde(rename = "min_height_px")]
185 #[theme(check = "non_negative")]
186 pub min_height: Option<f32>,
187 #[theme(range = "0.0..=1.0", inherit_from = "defaults.disabled_opacity")]
191 pub disabled_opacity: Option<f32>,
192 #[theme(inherit_from = "defaults.disabled_text_color")]
194 pub disabled_text_color: Option<Rgba>,
195 #[theme(category = "soft_option")]
197 pub hover_border_color: Option<Rgba>,
198 #[theme(category = "soft_option")]
200 pub focus_border_color: Option<Rgba>,
201 #[theme(category = "soft_option")]
203 pub disabled_background: Option<Rgba>,
204 #[theme(nested, resolved_type = "ResolvedFontSpec")]
206 pub font: Option<FontSpec>,
207 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
209 pub border: Option<WidgetBorderSpec>,
210}
211
212#[serde_with::skip_serializing_none]
218#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
219#[serde(default)]
220pub struct TextAreaTheme {
221 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
227 pub border: Option<WidgetBorderSpec>,
228}
229
230#[serde_with::skip_serializing_none]
234#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
235#[serde(default)]
236#[theme_inherit(border_kind = "full", font = "font")]
237pub struct CheckboxTheme {
238 #[theme(inherit_from = "defaults.background_color")]
240 pub background_color: Option<Rgba>,
241 #[theme(inherit_from = "defaults.accent_color")]
243 pub checked_background: Option<Rgba>,
244 #[theme(inherit_from = "defaults.accent_text_color")]
246 pub indicator_color: Option<Rgba>,
247 #[serde(rename = "indicator_width_px")]
251 #[theme(check = "non_negative")]
252 pub indicator_width: Option<f32>,
253 #[serde(rename = "radio_indicator_width_px")]
258 #[theme(category = "soft_option", check = "non_negative")]
259 pub radio_indicator_width: Option<f32>,
260 #[serde(rename = "radio_dot_diameter_px")]
265 #[theme(category = "soft_option", check = "non_negative")]
266 pub radio_dot_diameter: Option<f32>,
267 #[serde(rename = "check_mark_stroke_width_px")]
271 #[theme(category = "soft_option", check = "non_negative")]
272 pub check_mark_stroke_width: Option<f32>,
273 #[serde(rename = "label_gap_px")]
275 #[theme(check = "non_negative")]
276 pub label_gap: Option<f32>,
277 #[theme(range = "0.0..=1.0", inherit_from = "defaults.disabled_opacity")]
281 pub disabled_opacity: Option<f32>,
282 #[theme(inherit_from = "defaults.disabled_text_color")]
284 pub disabled_text_color: Option<Rgba>,
285 #[theme(category = "soft_option")]
287 pub hover_background: Option<Rgba>,
288 #[theme(category = "soft_option")]
292 pub hover_border_color: Option<Rgba>,
293 #[theme(category = "soft_option")]
296 pub disabled_background: Option<Rgba>,
297 #[theme(category = "soft_option")]
299 pub unchecked_background: Option<Rgba>,
300 #[theme(category = "soft_option")]
302 pub unchecked_border_color: Option<Rgba>,
303 #[theme(nested, resolved_type = "ResolvedFontSpec")]
305 pub font: Option<FontSpec>,
306 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
308 pub border: Option<WidgetBorderSpec>,
309}
310
311#[serde_with::skip_serializing_none]
318#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
319#[serde(default)]
320#[theme_layer(border_kind = "none")]
321#[theme_inherit(font = "font")]
322pub struct MenuTheme {
323 #[theme(inherit_from = "defaults.background_color")]
325 pub background_color: Option<Rgba>,
326 #[theme(inherit_from = "defaults.border.color")]
328 pub separator_color: Option<Rgba>,
329 #[serde(rename = "row_height_px")]
335 #[theme(category = "soft_option", check = "non_negative")]
336 pub row_height: Option<f32>,
337 #[serde(rename = "min_row_height_px")]
344 #[theme(category = "soft_option", check = "non_negative")]
345 pub min_row_height: Option<f32>,
346 #[serde(rename = "icon_text_gap_px")]
348 #[theme(check = "non_negative")]
349 pub icon_text_gap: Option<f32>,
350 #[serde(rename = "icon_size_px")]
352 #[theme(check = "non_negative", inherit_from = "defaults.icon_sizes.toolbar")]
353 pub icon_size: Option<f32>,
354 #[theme(inherit_from = "defaults.selection_background")]
360 pub hover_background: Option<Rgba>,
361 #[theme(inherit_from = "defaults.selection_text_color")]
363 pub hover_text_color: Option<Rgba>,
364 #[theme(inherit_from = "defaults.disabled_text_color")]
366 pub disabled_text_color: Option<Rgba>,
367 #[theme(category = "soft_option")]
374 pub hover_border_color: Option<Rgba>,
375 #[theme(category = "soft_option")]
379 pub bar_hover_background: Option<Rgba>,
380 #[theme(category = "soft_option")]
384 pub bar_open_background: Option<Rgba>,
385 #[theme(category = "soft_option")]
389 pub bar_hover_text_color: Option<Rgba>,
390 #[serde(rename = "bar_padding_horizontal_px")]
395 #[theme(category = "soft_option", check = "non_negative")]
396 pub bar_padding_horizontal: Option<f32>,
397 #[serde(rename = "bar_padding_vertical_px")]
401 #[theme(category = "soft_option", check = "non_negative")]
402 pub bar_padding_vertical: Option<f32>,
403 #[theme(category = "soft_option")]
409 pub active_background: Option<Rgba>,
410 #[theme(category = "soft_option")]
413 pub active_text_color: Option<Rgba>,
414 #[serde(rename = "panel_padding_horizontal_px")]
421 #[theme(category = "soft_option", check = "non_negative")]
422 pub panel_padding_horizontal: Option<f32>,
423 #[serde(rename = "panel_padding_vertical_px")]
430 #[theme(category = "soft_option", check = "non_negative")]
431 pub panel_padding_vertical: Option<f32>,
432 #[theme(nested, resolved_type = "ResolvedFontSpec")]
434 pub font: Option<FontSpec>,
435 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
444 pub border: Option<WidgetBorderSpec>,
445}
446
447#[serde_with::skip_serializing_none]
451#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
452#[serde(default)]
453#[theme_inherit(border_kind = "full", font = "font")]
454pub struct TooltipTheme {
455 #[theme(inherit_from = "defaults.background_color")]
457 pub background_color: Option<Rgba>,
458 #[serde(rename = "max_width_px")]
460 #[theme(check = "non_negative")]
461 pub max_width: Option<f32>,
462 #[serde(rename = "show_delay_ms")]
466 #[theme(category = "soft_option")]
467 pub show_delay: Option<u16>,
468 #[theme(nested, resolved_type = "ResolvedFontSpec")]
470 pub font: Option<FontSpec>,
471 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
473 pub border: Option<WidgetBorderSpec>,
474}
475
476#[serde_with::skip_serializing_none]
480#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
481#[serde(default)]
482pub struct ScrollbarTheme {
483 pub track_color: Option<Rgba>,
487 #[theme(inherit_from = "defaults.muted_color")]
489 pub thumb_color: Option<Rgba>,
490 #[theme(inherit_from = "defaults.muted_color")]
492 pub thumb_hover_color: Option<Rgba>,
493 #[serde(rename = "groove_width_px")]
495 #[theme(check = "non_negative")]
496 pub groove_width: Option<f32>,
497 #[serde(rename = "min_thumb_length_px")]
499 #[theme(check = "non_negative")]
500 pub min_thumb_length: Option<f32>,
501 #[serde(rename = "thumb_width_px")]
503 #[theme(check = "non_negative")]
504 pub thumb_width: Option<f32>,
505 pub overlay_mode: Option<bool>,
507 #[theme(category = "soft_option")]
509 pub thumb_active_color: Option<Rgba>,
510}
511
512#[serde_with::skip_serializing_none]
516#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
517#[serde(default)]
518pub struct SliderTheme {
519 #[theme(inherit_from = "defaults.accent_color")]
521 pub fill_color: Option<Rgba>,
522 #[theme(inherit_from = "defaults.muted_color")]
524 pub track_color: Option<Rgba>,
525 #[theme(inherit_from = "defaults.surface_color")]
527 pub thumb_color: Option<Rgba>,
528 #[serde(rename = "track_height_px")]
530 #[theme(check = "non_negative")]
531 pub track_height: Option<f32>,
532 #[serde(rename = "thumb_diameter_px")]
534 #[theme(check = "non_negative")]
535 pub thumb_diameter: Option<f32>,
536 #[serde(rename = "tick_mark_length_px")]
538 #[theme(check = "non_negative")]
539 pub tick_mark_length: Option<f32>,
540 #[theme(range = "0.0..=1.0", inherit_from = "defaults.disabled_opacity")]
544 pub disabled_opacity: Option<f32>,
545 #[theme(category = "soft_option")]
547 pub thumb_hover_color: Option<Rgba>,
548 #[theme(category = "soft_option")]
551 pub disabled_fill_color: Option<Rgba>,
552 #[theme(category = "soft_option")]
554 pub disabled_track_color: Option<Rgba>,
555 #[theme(category = "soft_option")]
557 pub disabled_thumb_color: Option<Rgba>,
558 #[theme(category = "soft_option")]
563 pub thumb_border_color: Option<Rgba>,
564 #[serde(rename = "thumb_border_line_width_px")]
569 #[theme(category = "soft_option", check = "non_negative")]
570 pub thumb_border_line_width: Option<f32>,
571 #[theme(category = "soft_option")]
575 pub thumb_hover_border_color: Option<Rgba>,
576 #[theme(category = "soft_option")]
580 pub thumb_focus_border_color: Option<Rgba>,
581}
582
583#[serde_with::skip_serializing_none]
587#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
588#[serde(default)]
589#[theme_inherit(border_kind = "full")]
590pub struct ProgressBarTheme {
591 #[theme(inherit_from = "defaults.accent_color")]
593 pub fill_color: Option<Rgba>,
594 #[theme(inherit_from = "defaults.muted_color")]
596 pub track_color: Option<Rgba>,
597 #[serde(rename = "track_height_px")]
599 #[theme(check = "non_negative")]
600 pub track_height: Option<f32>,
601 #[serde(rename = "min_width_px")]
603 #[theme(check = "non_negative")]
604 pub min_width: Option<f32>,
605 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
607 pub border: Option<WidgetBorderSpec>,
608}
609
610#[serde_with::skip_serializing_none]
614#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
615#[serde(default)]
616#[theme_layer(border_kind = "none")]
617#[theme_inherit(font = "font")]
618pub struct TabTheme {
619 #[theme(inherit_from = "defaults.background_color")]
621 pub background_color: Option<Rgba>,
622 #[theme(inherit_from = "defaults.background_color")]
624 pub active_background: Option<Rgba>,
625 #[theme(inherit_from = "defaults.text_color")]
627 pub active_text_color: Option<Rgba>,
628 #[theme(inherit_from = "defaults.background_color")]
630 pub bar_background: Option<Rgba>,
631 #[serde(rename = "min_width_px")]
633 #[theme(check = "non_negative")]
634 pub min_width: Option<f32>,
635 #[serde(rename = "min_height_px")]
637 #[theme(check = "non_negative")]
638 pub min_height: Option<f32>,
639 #[serde(rename = "item_gap_px")]
643 #[theme(category = "soft_option", check = "non_negative")]
644 pub item_gap: Option<f32>,
645 #[theme(category = "soft_option")]
651 pub active_indicator_color: Option<Rgba>,
652 #[serde(rename = "active_indicator_width_px")]
655 #[theme(category = "soft_option", check = "non_negative")]
656 pub active_indicator_width: Option<f32>,
657 #[theme(category = "soft_option")]
661 pub active_indicator_side: Option<TabIndicatorSide>,
662 #[serde(rename = "active_outward_corner_radius_px")]
670 #[theme(category = "soft_option", check = "non_negative")]
671 pub active_outward_corner_radius: Option<f32>,
672 pub hover_text_color: Option<Rgba>,
674 #[theme(category = "soft_option")]
676 pub hover_background: Option<Rgba>,
677 #[theme(nested, resolved_type = "ResolvedFontSpec")]
679 pub font: Option<FontSpec>,
680 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
682 pub border: Option<WidgetBorderSpec>,
683}
684
685#[serde_with::skip_serializing_none]
689#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
690#[serde(default)]
691#[theme_layer(border_kind = "partial")]
692#[theme_inherit(border_kind = "partial", font = "font")]
693pub struct SidebarTheme {
694 #[theme(inherit_from = "defaults.background_color")]
696 pub background_color: Option<Rgba>,
697 #[theme(inherit_from = "defaults.selection_background")]
699 pub selection_background: Option<Rgba>,
700 #[theme(inherit_from = "defaults.selection_text_color")]
702 pub selection_text_color: Option<Rgba>,
703 pub hover_background: Option<Rgba>,
707 #[theme(nested, resolved_type = "ResolvedFontSpec")]
709 pub font: Option<FontSpec>,
710 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
712 pub border: Option<WidgetBorderSpec>,
713}
714
715#[serde_with::skip_serializing_none]
726#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
727#[serde(default)]
728#[theme_inherit(border_kind = "full", font = "font")]
729pub struct ToolbarTheme {
730 #[theme(inherit_from = "defaults.background_color")]
734 pub background_color: Option<Rgba>,
735 #[serde(rename = "bar_height_px")]
739 #[theme(category = "soft_option", check = "non_negative")]
740 pub bar_height: Option<f32>,
741 #[serde(rename = "item_gap_px")]
745 #[theme(category = "soft_option", check = "non_negative")]
746 pub item_gap: Option<f32>,
747 #[serde(rename = "icon_size_px")]
749 #[theme(check = "non_negative", inherit_from = "defaults.icon_sizes.toolbar")]
750 pub icon_size: Option<f32>,
751 #[theme(category = "soft_option")]
756 pub button_hover_background: Option<Rgba>,
757 #[theme(category = "soft_option")]
761 pub button_hover_border_color: Option<Rgba>,
762 #[theme(category = "soft_option")]
766 pub button_active_background: Option<Rgba>,
767 #[theme(category = "soft_option")]
771 pub button_checked_background: Option<Rgba>,
772 #[theme(category = "soft_option")]
779 pub button_checked_border_color: Option<Rgba>,
780 #[theme(nested, resolved_type = "ResolvedFontSpec")]
782 pub font: Option<FontSpec>,
783 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
785 pub border: Option<WidgetBorderSpec>,
786}
787
788#[serde_with::skip_serializing_none]
792#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
793#[serde(default)]
794#[theme_layer(border_kind = "partial")]
795#[theme_inherit(border_kind = "partial", font = "font")]
796pub struct StatusBarTheme {
797 #[theme(inherit_from = "defaults.background_color")]
799 pub background_color: Option<Rgba>,
800 #[theme(nested, resolved_type = "ResolvedFontSpec")]
802 pub font: Option<FontSpec>,
803 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
805 pub border: Option<WidgetBorderSpec>,
806}
807
808#[serde_with::skip_serializing_none]
812#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
813#[serde(default)]
814#[theme_inherit(border_kind = "full", font = "item_font")]
815#[theme_inherit(font = "header_font")]
816pub struct ListTheme {
817 pub background_color: Option<Rgba>,
819 pub alternate_row_background: Option<Rgba>,
821 #[theme(inherit_from = "defaults.selection_background")]
823 pub selection_background: Option<Rgba>,
824 #[theme(inherit_from = "defaults.selection_text_color")]
826 pub selection_text_color: Option<Rgba>,
827 #[theme(inherit_from = "defaults.surface_color")]
829 pub header_background: Option<Rgba>,
830 #[theme(inherit_from = "defaults.border.color")]
833 pub grid_color: Option<Rgba>,
834 #[serde(rename = "row_height_px")]
838 #[theme(category = "soft_option", check = "non_negative")]
839 pub row_height: Option<f32>,
840 #[serde(rename = "header_height_px")]
844 #[theme(category = "soft_option", check = "positive")]
845 pub header_height: Option<f32>,
846 #[theme(category = "soft_option")]
851 pub header_hover_background: Option<Rgba>,
852 #[theme(category = "soft_option")]
858 pub header_active_background: Option<Rgba>,
859 #[theme(category = "soft_option")]
865 pub header_separator_color: Option<Rgba>,
866 pub hover_background: Option<Rgba>,
874 pub hover_text_color: Option<Rgba>,
876 #[theme(category = "soft_option")]
881 pub hover_border_color: Option<Rgba>,
882 #[theme(inherit_from = "defaults.disabled_text_color")]
884 pub disabled_text_color: Option<Rgba>,
885 #[theme(nested, resolved_type = "ResolvedFontSpec")]
887 pub item_font: Option<FontSpec>,
888 #[theme(nested, resolved_type = "ResolvedFontSpec")]
890 pub header_font: Option<FontSpec>,
891 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
893 pub border: Option<WidgetBorderSpec>,
894}
895
896#[serde_with::skip_serializing_none]
900#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
901#[serde(default)]
902#[theme_inherit(border_kind = "full_lg", font = "font")]
903pub struct PopoverTheme {
904 pub background_color: Option<Rgba>,
906 #[theme(nested, resolved_type = "ResolvedFontSpec")]
908 pub font: Option<FontSpec>,
909 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
911 pub border: Option<WidgetBorderSpec>,
912}
913
914#[serde_with::skip_serializing_none]
918#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
919#[serde(default)]
920pub struct SplitterTheme {
921 #[serde(rename = "divider_width_px")]
923 #[theme(check = "non_negative")]
924 pub divider_width: Option<f32>,
925 #[theme(inherit_from = "defaults.border.color")]
927 pub divider_color: Option<Rgba>,
928 pub hover_color: Option<Rgba>,
930}
931
932#[serde_with::skip_serializing_none]
936#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
937#[serde(default)]
938pub struct SeparatorTheme {
939 #[theme(inherit_from = "defaults.border.color")]
941 pub line_color: Option<Rgba>,
942 #[serde(rename = "line_width_px")]
944 #[theme(check = "non_negative", inherit_from = "defaults.border.line_width")]
945 pub line_width: Option<f32>,
946}
947
948#[serde_with::skip_serializing_none]
952#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
953#[serde(default)]
954pub struct SwitchTheme {
955 #[theme(inherit_from = "defaults.accent_color")]
957 pub checked_background: Option<Rgba>,
958 pub unchecked_background: Option<Rgba>,
960 #[theme(inherit_from = "defaults.surface_color")]
963 pub thumb_background: Option<Rgba>,
964 #[theme(category = "soft_option")]
969 pub unchecked_thumb_background: Option<Rgba>,
970 #[serde(rename = "track_width_px")]
972 #[theme(check = "non_negative")]
973 pub track_width: Option<f32>,
974 #[serde(rename = "track_height_px")]
976 #[theme(check = "non_negative")]
977 pub track_height: Option<f32>,
978 #[serde(rename = "thumb_diameter_px")]
984 #[theme(check = "non_negative")]
985 pub thumb_diameter: Option<f32>,
986 #[serde(rename = "unchecked_thumb_diameter_px")]
991 #[theme(category = "soft_option", check = "non_negative")]
992 pub unchecked_thumb_diameter: Option<f32>,
993 #[serde(rename = "track_radius_px")]
995 #[theme(check = "non_negative")]
996 pub track_radius: Option<f32>,
997 #[theme(range = "0.0..=1.0", inherit_from = "defaults.disabled_opacity")]
1001 pub disabled_opacity: Option<f32>,
1002 #[theme(category = "soft_option")]
1004 pub hover_checked_background: Option<Rgba>,
1005 #[theme(category = "soft_option")]
1007 pub hover_unchecked_background: Option<Rgba>,
1008 #[theme(category = "soft_option")]
1011 pub disabled_checked_background: Option<Rgba>,
1012 #[theme(category = "soft_option")]
1014 pub disabled_unchecked_background: Option<Rgba>,
1015 #[theme(category = "soft_option")]
1017 pub disabled_thumb_color: Option<Rgba>,
1018 #[theme(category = "soft_option")]
1024 pub unchecked_track_border_color: Option<Rgba>,
1025 #[theme(category = "soft_option")]
1029 pub checked_track_border_color: Option<Rgba>,
1030 #[theme(category = "soft_option")]
1033 pub disabled_unchecked_track_border_color: Option<Rgba>,
1034 #[theme(category = "soft_option")]
1036 pub disabled_checked_track_border_color: Option<Rgba>,
1037 #[serde(rename = "track_border_line_width_px")]
1040 #[theme(category = "soft_option", check = "non_negative")]
1041 pub track_border_line_width: Option<f32>,
1042 #[theme(category = "soft_option")]
1046 pub thumb_border_color: Option<Rgba>,
1047 #[serde(rename = "thumb_border_line_width_px")]
1049 #[theme(category = "soft_option", check = "non_negative")]
1050 pub thumb_border_line_width: Option<f32>,
1051}
1052
1053#[serde_with::skip_serializing_none]
1057#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
1058#[serde(default)]
1059#[theme_inherit(border_kind = "full_lg", font = "title_font")]
1060#[theme_inherit(font = "body_font")]
1061pub struct DialogTheme {
1062 pub background_color: Option<Rgba>,
1064 #[serde(rename = "min_width_px")]
1066 #[theme(check = "non_negative", min_max_pair = "max_width")]
1067 pub min_width: Option<f32>,
1068 #[serde(rename = "max_width_px")]
1070 #[theme(check = "non_negative")]
1071 pub max_width: Option<f32>,
1072 #[serde(rename = "min_height_px")]
1074 #[theme(check = "non_negative", min_max_pair = "max_height")]
1075 pub min_height: Option<f32>,
1076 #[serde(rename = "max_height_px")]
1078 #[theme(check = "non_negative")]
1079 pub max_height: Option<f32>,
1080 #[serde(rename = "button_gap_px")]
1082 #[theme(check = "non_negative")]
1083 pub button_gap: Option<f32>,
1084 #[serde(rename = "icon_size_px")]
1086 #[theme(check = "non_negative")]
1087 pub icon_size: Option<f32>,
1088 pub button_order: Option<DialogButtonOrder>,
1090 #[theme(category = "soft_option")]
1095 pub entrance: Option<DialogEntranceStyle>,
1096 #[theme(nested, resolved_type = "ResolvedFontSpec")]
1098 pub title_font: Option<FontSpec>,
1099 #[theme(nested, resolved_type = "ResolvedFontSpec")]
1101 pub body_font: Option<FontSpec>,
1102 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
1104 pub border: Option<WidgetBorderSpec>,
1105}
1106
1107#[serde_with::skip_serializing_none]
1111#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
1112#[serde(default)]
1113pub struct SpinnerTheme {
1114 pub fill_color: Option<Rgba>,
1116 #[serde(rename = "diameter_px")]
1118 #[theme(check = "non_negative")]
1119 pub diameter: Option<f32>,
1120 #[serde(rename = "min_diameter_px")]
1122 #[theme(check = "non_negative")]
1123 pub min_diameter: Option<f32>,
1124 #[serde(rename = "stroke_width_px")]
1126 #[theme(check = "non_negative")]
1127 pub stroke_width: Option<f32>,
1128}
1129
1130#[serde_with::skip_serializing_none]
1135#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
1136#[serde(default)]
1137#[theme_inherit(border_kind = "full", font = "font")]
1138pub struct ComboBoxTheme {
1139 #[theme(inherit_from = "defaults.background_color")]
1141 pub background_color: Option<Rgba>,
1142 #[serde(rename = "min_height_px")]
1144 #[theme(check = "non_negative")]
1145 pub min_height: Option<f32>,
1146 #[serde(rename = "min_width_px")]
1148 #[theme(check = "non_negative")]
1149 pub min_width: Option<f32>,
1150 #[serde(rename = "arrow_icon_size_px")]
1152 #[theme(check = "non_negative")]
1153 pub arrow_icon_size: Option<f32>,
1154 #[serde(rename = "arrow_area_width_px")]
1160 #[theme(category = "soft_option", check = "non_negative")]
1161 pub arrow_area_width: Option<f32>,
1162 #[theme(range = "0.0..=1.0", inherit_from = "defaults.disabled_opacity")]
1166 pub disabled_opacity: Option<f32>,
1167 #[theme(inherit_from = "defaults.disabled_text_color")]
1169 pub disabled_text_color: Option<Rgba>,
1170 #[theme(category = "soft_option")]
1172 pub hover_background: Option<Rgba>,
1173 #[theme(category = "soft_option")]
1177 pub hover_border_color: Option<Rgba>,
1178 #[theme(category = "soft_option")]
1180 pub disabled_background: Option<Rgba>,
1181 #[theme(category = "soft_option")]
1186 pub open_background: Option<Rgba>,
1187 #[theme(category = "soft_option")]
1191 pub open_border_color: Option<Rgba>,
1192 #[theme(nested, resolved_type = "ResolvedFontSpec")]
1194 pub font: Option<FontSpec>,
1195 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
1197 pub border: Option<WidgetBorderSpec>,
1198}
1199
1200#[serde_with::skip_serializing_none]
1204#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
1205#[serde(default)]
1206#[theme_inherit(border_kind = "full", font = "font")]
1207pub struct SegmentedControlTheme {
1208 #[theme(inherit_from = "defaults.background_color")]
1210 pub background_color: Option<Rgba>,
1211 #[theme(inherit_from = "defaults.accent_color")]
1213 pub active_background: Option<Rgba>,
1214 #[theme(inherit_from = "defaults.accent_text_color")]
1216 pub active_text_color: Option<Rgba>,
1217 #[serde(rename = "segment_height_px")]
1219 #[theme(check = "non_negative")]
1220 pub segment_height: Option<f32>,
1221 #[serde(rename = "separator_width_px")]
1223 #[theme(check = "non_negative")]
1224 pub separator_width: Option<f32>,
1225 #[theme(range = "0.0..=1.0", inherit_from = "defaults.disabled_opacity")]
1229 pub disabled_opacity: Option<f32>,
1230 #[theme(category = "soft_option")]
1232 pub hover_background: Option<Rgba>,
1233 #[theme(nested, resolved_type = "ResolvedFontSpec")]
1235 pub font: Option<FontSpec>,
1236 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
1238 pub border: Option<WidgetBorderSpec>,
1239}
1240
1241#[serde_with::skip_serializing_none]
1245#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
1246#[serde(default)]
1247#[theme_layer(border_kind = "none")]
1248pub struct CardTheme {
1249 #[theme(inherit_from = "defaults.surface_color")]
1251 pub background_color: Option<Rgba>,
1252 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
1254 pub border: Option<WidgetBorderSpec>,
1255}
1256
1257#[serde_with::skip_serializing_none]
1261#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
1262#[serde(default)]
1263#[theme_inherit(border_kind = "full", font = "font")]
1264pub struct ExpanderTheme {
1265 #[serde(rename = "header_height_px")]
1267 #[theme(check = "non_negative")]
1268 pub header_height: Option<f32>,
1269 #[serde(rename = "arrow_icon_size_px")]
1271 #[theme(check = "non_negative")]
1272 pub arrow_icon_size: Option<f32>,
1273 #[theme(category = "soft_option")]
1275 pub hover_background: Option<Rgba>,
1276 #[theme(category = "soft_option")]
1278 pub arrow_color: Option<Rgba>,
1279 #[theme(category = "soft_option")]
1283 pub arrow_side: Option<ArrowSide>,
1284 #[serde(rename = "arrow_gap_px")]
1289 #[theme(category = "soft_option", check = "non_negative")]
1290 pub arrow_gap: Option<f32>,
1291 #[serde(rename = "content_indent_px")]
1296 #[theme(category = "soft_option", check = "non_negative")]
1297 pub content_indent: Option<f32>,
1298 #[theme(category = "soft_option")]
1303 pub frame_enabled: Option<bool>,
1304 #[theme(nested, resolved_type = "ResolvedFontSpec")]
1306 pub font: Option<FontSpec>,
1307 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
1309 pub border: Option<WidgetBorderSpec>,
1310}
1311
1312#[serde_with::skip_serializing_none]
1316#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
1317#[serde(default)]
1318#[theme_inherit(font = "font")]
1319pub struct LinkTheme {
1320 #[theme(inherit_from = "defaults.link_color")]
1322 pub visited_text_color: Option<Rgba>,
1323 pub underline_enabled: Option<bool>,
1325 pub background_color: Option<Rgba>,
1327 pub hover_background: Option<Rgba>,
1329 pub hover_text_color: Option<Rgba>,
1331 pub active_text_color: Option<Rgba>,
1333 #[theme(inherit_from = "defaults.disabled_text_color")]
1335 pub disabled_text_color: Option<Rgba>,
1336 #[theme(nested, resolved_type = "ResolvedFontSpec")]
1338 pub font: Option<FontSpec>,
1339}
1340
1341#[serde_with::skip_serializing_none]
1352#[derive(
1353 Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget, ThemeFields,
1354)]
1355#[serde(default)]
1356#[theme_layer(skip_inventory)]
1357pub struct LayoutTheme {
1358 #[serde(rename = "widget_gap_px")]
1360 #[theme(check = "non_negative")]
1361 pub widget_gap: Option<f32>,
1362 #[serde(rename = "container_margin_px")]
1364 #[theme(check = "non_negative")]
1365 pub container_margin: Option<f32>,
1366 #[serde(rename = "window_margin_px")]
1368 #[theme(check = "non_negative")]
1369 pub window_margin: Option<f32>,
1370 #[serde(rename = "section_gap_px")]
1372 #[theme(check = "non_negative")]
1373 pub section_gap: Option<f32>,
1374}
1375
1376#[cfg(test)]
1377#[allow(clippy::unwrap_used, clippy::expect_used, dead_code)]
1378mod tests {
1379 use super::*;
1380 use crate::Rgba;
1381 use crate::model::border::{ResolvedWidgetBorder, WidgetBorderSpec};
1382 use crate::model::font::FontSize;
1383 use crate::model::{DialogButtonOrder, FontSpec};
1384
1385 #[serde_with::skip_serializing_none]
1388 #[derive(
1389 Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget,
1390 )]
1391 #[serde(default)]
1392 #[theme_layer(skip_inventory)]
1393 pub struct TestWidget {
1394 pub size: Option<f32>,
1395 pub label: Option<String>,
1396 #[theme(nested, resolved_type = "ResolvedFontSpec")]
1397 pub font: Option<FontSpec>,
1398 }
1399
1400 #[test]
1403 fn resolved_font_spec_fields_are_concrete() {
1404 let rfs = ResolvedFontSpec {
1405 family: "Inter".into(),
1406 size: 14.0,
1407 defined_size: Some(crate::model::font::FontSize::Px(14.0)),
1408 weight: 400,
1409 style: crate::model::font::FontStyle::Normal,
1410 color: crate::Rgba::rgb(0, 0, 0),
1411 };
1412 assert_eq!(rfs.family.as_ref(), "Inter");
1413 assert_eq!(rfs.size, 14.0);
1414 assert_eq!(rfs.weight, 400);
1415 }
1416
1417 #[test]
1420 fn generated_option_struct_has_option_fields() {
1421 let w = TestWidget::default();
1422 assert!(w.size.is_none());
1423 assert!(w.label.is_none());
1424 assert!(w.font.is_none());
1425 }
1426
1427 #[test]
1428 fn generated_option_struct_is_empty_by_default() {
1429 assert!(TestWidget::default().is_empty());
1430 }
1431
1432 #[test]
1433 fn generated_option_struct_not_empty_when_size_set() {
1434 let w = TestWidget {
1435 size: Some(24.0),
1436 ..Default::default()
1437 };
1438 assert!(!w.is_empty());
1439 }
1440
1441 #[test]
1442 fn generated_option_struct_not_empty_when_font_set() {
1443 let w = TestWidget {
1444 font: Some(FontSpec {
1445 size: Some(FontSize::Px(14.0)),
1446 ..Default::default()
1447 }),
1448 ..Default::default()
1449 };
1450 assert!(!w.is_empty());
1451 }
1452
1453 #[test]
1454 fn generated_resolved_struct_has_concrete_fields() {
1455 let resolved = ResolvedTestWidget {
1456 size: 24.0,
1457 label: "Click me".into(),
1458 font: ResolvedFontSpec {
1459 family: "Inter".into(),
1460 size: 14.0,
1461 defined_size: Some(crate::model::font::FontSize::Px(14.0)),
1462 weight: 400,
1463 style: crate::model::font::FontStyle::Normal,
1464 color: crate::Rgba::rgb(0, 0, 0),
1465 },
1466 };
1467 assert_eq!(resolved.size, 24.0);
1468 assert_eq!(resolved.label, "Click me");
1469 assert_eq!(resolved.font.family.as_ref(), "Inter");
1470 }
1471
1472 #[test]
1475 fn generated_merge_option_field_overlay_wins() {
1476 let mut base = TestWidget {
1477 size: Some(20.0),
1478 ..Default::default()
1479 };
1480 let overlay = TestWidget {
1481 size: Some(24.0),
1482 ..Default::default()
1483 };
1484 base.merge(&overlay);
1485 assert_eq!(base.size, Some(24.0));
1486 }
1487
1488 #[test]
1489 fn generated_merge_option_field_none_preserves_base() {
1490 let mut base = TestWidget {
1491 size: Some(20.0),
1492 ..Default::default()
1493 };
1494 let overlay = TestWidget::default();
1495 base.merge(&overlay);
1496 assert_eq!(base.size, Some(20.0));
1497 }
1498
1499 #[test]
1500 fn generated_merge_optional_nested_both_some_merges_inner() {
1501 let mut base = TestWidget {
1502 font: Some(FontSpec {
1503 family: Some("Noto Sans".into()),
1504 size: Some(FontSize::Px(12.0)),
1505 weight: None,
1506 ..Default::default()
1507 }),
1508 ..Default::default()
1509 };
1510 let overlay = TestWidget {
1511 font: Some(FontSpec {
1512 family: None,
1513 size: None,
1514 weight: Some(700),
1515 ..Default::default()
1516 }),
1517 ..Default::default()
1518 };
1519 base.merge(&overlay);
1520 let font = base.font.as_ref().unwrap();
1521 assert_eq!(font.family.as_deref(), Some("Noto Sans")); assert_eq!(font.size, Some(FontSize::Px(12.0))); assert_eq!(font.weight, Some(700)); }
1525
1526 #[test]
1527 fn generated_merge_optional_nested_none_plus_some_clones() {
1528 let mut base = TestWidget::default();
1529 let overlay = TestWidget {
1530 font: Some(FontSpec {
1531 family: Some("Inter".into()),
1532 size: Some(FontSize::Px(14.0)),
1533 weight: Some(400),
1534 ..Default::default()
1535 }),
1536 ..Default::default()
1537 };
1538 base.merge(&overlay);
1539 let font = base.font.as_ref().unwrap();
1540 assert_eq!(font.family.as_deref(), Some("Inter"));
1541 assert_eq!(font.size, Some(FontSize::Px(14.0)));
1542 assert_eq!(font.weight, Some(400));
1543 }
1544
1545 #[test]
1546 fn generated_merge_optional_nested_some_plus_none_preserves_base() {
1547 let mut base = TestWidget {
1548 font: Some(FontSpec {
1549 family: Some("Inter".into()),
1550 size: Some(FontSize::Px(14.0)),
1551 weight: Some(400),
1552 ..Default::default()
1553 }),
1554 ..Default::default()
1555 };
1556 let overlay = TestWidget::default();
1557 base.merge(&overlay);
1558 let font = base.font.as_ref().unwrap();
1559 assert_eq!(font.family.as_deref(), Some("Inter"));
1560 }
1561
1562 #[test]
1563 fn generated_merge_optional_nested_none_plus_none_stays_none() {
1564 let mut base = TestWidget::default();
1565 let overlay = TestWidget::default();
1566 base.merge(&overlay);
1567 assert!(base.font.is_none());
1568 }
1569
1570 #[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize)]
1574 struct WithFont {
1575 name: Option<String>,
1576 font: Option<FontSpec>,
1577 }
1578
1579 impl_merge!(WithFont {
1580 option { name }
1581 optional_nested { font }
1582 });
1583
1584 #[test]
1585 fn impl_merge_optional_nested_none_none_stays_none() {
1586 let mut base = WithFont::default();
1587 let overlay = WithFont::default();
1588 base.merge(&overlay);
1589 assert!(base.font.is_none());
1590 }
1591
1592 #[test]
1593 fn impl_merge_optional_nested_some_none_preserves_base() {
1594 let mut base = WithFont {
1595 font: Some(FontSpec {
1596 size: Some(FontSize::Px(12.0)),
1597 ..Default::default()
1598 }),
1599 ..Default::default()
1600 };
1601 let overlay = WithFont::default();
1602 base.merge(&overlay);
1603 assert_eq!(base.font.as_ref().unwrap().size, Some(FontSize::Px(12.0)));
1604 }
1605
1606 #[test]
1607 fn impl_merge_optional_nested_none_some_clones_overlay() {
1608 let mut base = WithFont::default();
1609 let overlay = WithFont {
1610 font: Some(FontSpec {
1611 family: Some("Inter".into()),
1612 ..Default::default()
1613 }),
1614 ..Default::default()
1615 };
1616 base.merge(&overlay);
1617 assert_eq!(base.font.as_ref().unwrap().family.as_deref(), Some("Inter"));
1618 }
1619
1620 #[test]
1621 fn impl_merge_optional_nested_some_some_merges_inner() {
1622 let mut base = WithFont {
1623 font: Some(FontSpec {
1624 family: Some("Noto".into()),
1625 size: Some(FontSize::Px(11.0)),
1626 weight: None,
1627 ..Default::default()
1628 }),
1629 ..Default::default()
1630 };
1631 let overlay = WithFont {
1632 font: Some(FontSpec {
1633 family: None,
1634 size: Some(FontSize::Px(14.0)),
1635 weight: Some(400),
1636 ..Default::default()
1637 }),
1638 ..Default::default()
1639 };
1640 base.merge(&overlay);
1641 let f = base.font.as_ref().unwrap();
1642 assert_eq!(f.family.as_deref(), Some("Noto")); assert_eq!(f.size, Some(FontSize::Px(14.0))); assert_eq!(f.weight, Some(400)); }
1646
1647 #[test]
1648 fn impl_merge_optional_nested_is_empty_none() {
1649 let w = WithFont::default();
1650 assert!(w.is_empty());
1651 }
1652
1653 #[test]
1654 fn impl_merge_optional_nested_is_empty_some_default() {
1655 let w = WithFont {
1657 font: Some(FontSpec::default()),
1658 ..Default::default()
1659 };
1660 assert!(w.is_empty());
1661 }
1662
1663 #[test]
1664 fn impl_merge_optional_nested_is_not_empty_when_populated() {
1665 let w = WithFont {
1666 font: Some(FontSpec {
1667 size: Some(FontSize::Px(14.0)),
1668 ..Default::default()
1669 }),
1670 ..Default::default()
1671 };
1672 assert!(!w.is_empty());
1673 }
1674
1675 #[test]
1678 fn button_theme_default_is_empty() {
1679 assert!(ButtonTheme::default().is_empty());
1680 }
1681
1682 #[test]
1683 fn button_theme_not_empty_when_set() {
1684 let b = ButtonTheme {
1685 background_color: Some(Rgba::rgb(200, 200, 200)),
1686 min_width: Some(64.0),
1687 ..Default::default()
1688 };
1689 assert!(!b.is_empty());
1690 }
1691
1692 #[test]
1693 fn button_theme_merge_font_optional_nested() {
1694 let mut base = ButtonTheme {
1695 font: Some(FontSpec {
1696 family: Some("Noto Sans".into()),
1697 size: Some(FontSize::Px(11.0)),
1698 weight: None,
1699 ..Default::default()
1700 }),
1701 ..Default::default()
1702 };
1703 let overlay = ButtonTheme {
1704 font: Some(FontSpec {
1705 family: None,
1706 weight: Some(700),
1707 ..Default::default()
1708 }),
1709 ..Default::default()
1710 };
1711 base.merge(&overlay);
1712 let f = base.font.as_ref().unwrap();
1713 assert_eq!(f.family.as_deref(), Some("Noto Sans")); assert_eq!(f.weight, Some(700)); }
1716
1717 #[test]
1718 fn button_theme_toml_round_trip_with_font_and_border() {
1719 let b = ButtonTheme {
1720 background_color: Some(Rgba::rgb(200, 200, 200)),
1721 font: Some(FontSpec {
1722 family: Some("Inter".into()),
1723 size: Some(FontSize::Px(14.0)),
1724 weight: Some(400),
1725 ..Default::default()
1726 }),
1727 border: Some(WidgetBorderSpec {
1728 corner_radius: Some(4.0),
1729 ..Default::default()
1730 }),
1731 ..Default::default()
1732 };
1733 let toml_str = toml::to_string(&b).unwrap();
1734 let b2: ButtonTheme = toml::from_str(&toml_str).unwrap();
1735 assert_eq!(b, b2);
1736 }
1737
1738 #[test]
1741 fn window_theme_has_new_fields() {
1742 let w = WindowTheme {
1743 inactive_title_bar_background: Some(Rgba::rgb(180, 180, 180)),
1744 inactive_title_bar_text_color: Some(Rgba::rgb(120, 120, 120)),
1745 title_bar_font: Some(FontSpec {
1746 weight: Some(700),
1747 ..Default::default()
1748 }),
1749 border: Some(WidgetBorderSpec {
1750 corner_radius: Some(4.0),
1751 shadow_enabled: Some(true),
1752 ..Default::default()
1753 }),
1754 ..Default::default()
1755 };
1756 assert!(!w.is_empty());
1757 assert!(w.inactive_title_bar_background.is_some());
1758 assert!(w.inactive_title_bar_text_color.is_some());
1759 assert!(w.title_bar_font.is_some());
1760 assert!(w.border.is_some());
1761 }
1762
1763 #[test]
1764 fn window_theme_default_is_empty() {
1765 assert!(WindowTheme::default().is_empty());
1766 }
1767
1768 #[test]
1771 fn dialog_theme_button_order_works() {
1772 let d = DialogTheme {
1773 button_order: Some(DialogButtonOrder::PrimaryRight),
1774 min_width: Some(300.0),
1775 ..Default::default()
1776 };
1777 assert_eq!(d.button_order, Some(DialogButtonOrder::PrimaryRight));
1778 assert_eq!(d.min_width, Some(300.0));
1779 assert!(!d.is_empty());
1780 }
1781
1782 #[test]
1783 fn dialog_theme_button_order_toml_round_trip() {
1784 let d = DialogTheme {
1785 button_order: Some(DialogButtonOrder::PrimaryLeft),
1786 ..Default::default()
1787 };
1788 let toml_str = toml::to_string(&d).unwrap();
1789 let d2: DialogTheme = toml::from_str(&toml_str).unwrap();
1790 assert_eq!(d, d2);
1791 }
1792
1793 #[test]
1794 fn dialog_theme_default_is_empty() {
1795 assert!(DialogTheme::default().is_empty());
1796 }
1797
1798 #[test]
1801 fn splitter_theme_single_field_merge() {
1802 let mut base = SplitterTheme {
1803 divider_width: Some(4.0),
1804 ..Default::default()
1805 };
1806 let overlay = SplitterTheme {
1807 divider_width: Some(6.0),
1808 ..Default::default()
1809 };
1810 base.merge(&overlay);
1811 assert_eq!(base.divider_width, Some(6.0));
1812 }
1813
1814 #[test]
1815 fn splitter_theme_merge_none_preserves_base() {
1816 let mut base = SplitterTheme {
1817 divider_width: Some(4.0),
1818 ..Default::default()
1819 };
1820 let overlay = SplitterTheme::default();
1821 base.merge(&overlay);
1822 assert_eq!(base.divider_width, Some(4.0));
1823 }
1824
1825 #[test]
1826 fn splitter_theme_default_is_empty() {
1827 assert!(SplitterTheme::default().is_empty());
1828 }
1829
1830 #[test]
1831 fn splitter_theme_not_empty_when_set() {
1832 assert!(
1833 !SplitterTheme {
1834 divider_width: Some(4.0),
1835 ..Default::default()
1836 }
1837 .is_empty()
1838 );
1839 }
1840
1841 #[test]
1844 fn separator_theme_single_field() {
1845 let s = SeparatorTheme {
1846 line_color: Some(Rgba::rgb(200, 200, 200)),
1847 ..Default::default()
1848 };
1849 assert!(!s.is_empty());
1850 }
1851
1852 #[test]
1855 fn all_widget_theme_defaults_are_empty() {
1856 assert!(WindowTheme::default().is_empty());
1857 assert!(ButtonTheme::default().is_empty());
1858 assert!(InputTheme::default().is_empty());
1859 assert!(CheckboxTheme::default().is_empty());
1860 assert!(MenuTheme::default().is_empty());
1861 assert!(TooltipTheme::default().is_empty());
1862 assert!(ScrollbarTheme::default().is_empty());
1863 assert!(SliderTheme::default().is_empty());
1864 assert!(ProgressBarTheme::default().is_empty());
1865 assert!(TabTheme::default().is_empty());
1866 assert!(SidebarTheme::default().is_empty());
1867 assert!(ToolbarTheme::default().is_empty());
1868 assert!(StatusBarTheme::default().is_empty());
1869 assert!(ListTheme::default().is_empty());
1870 assert!(PopoverTheme::default().is_empty());
1871 assert!(SplitterTheme::default().is_empty());
1872 assert!(SeparatorTheme::default().is_empty());
1873 assert!(SwitchTheme::default().is_empty());
1874 assert!(DialogTheme::default().is_empty());
1875 assert!(SpinnerTheme::default().is_empty());
1876 assert!(ComboBoxTheme::default().is_empty());
1877 assert!(SegmentedControlTheme::default().is_empty());
1878 assert!(CardTheme::default().is_empty());
1879 assert!(ExpanderTheme::default().is_empty());
1880 assert!(LinkTheme::default().is_empty());
1881 }
1882
1883 #[test]
1886 fn input_theme_toml_round_trip() {
1887 let t = InputTheme {
1888 background_color: Some(Rgba::rgb(255, 255, 255)),
1889 font: Some(FontSpec {
1890 family: Some("Noto Sans".into()),
1891 ..Default::default()
1892 }),
1893 border: Some(WidgetBorderSpec {
1894 color: Some(Rgba::rgb(180, 180, 180)),
1895 corner_radius: Some(4.0),
1896 ..Default::default()
1897 }),
1898 ..Default::default()
1899 };
1900 let toml_str = toml::to_string(&t).unwrap();
1901 let t2: InputTheme = toml::from_str(&toml_str).unwrap();
1902 assert_eq!(t, t2);
1903 }
1904
1905 #[test]
1906 fn switch_theme_toml_round_trip() {
1907 let s = SwitchTheme {
1908 checked_background: Some(Rgba::rgb(0, 120, 215)),
1909 track_width: Some(40.0),
1910 track_height: Some(20.0),
1911 thumb_diameter: Some(14.0),
1912 track_radius: Some(10.0),
1913 ..Default::default()
1914 };
1915 let toml_str = toml::to_string(&s).unwrap();
1916 let s2: SwitchTheme = toml::from_str(&toml_str).unwrap();
1917 assert_eq!(s, s2);
1918 }
1919
1920 #[test]
1921 fn new_sizes_use_px_keys() {
1922 let m = MenuTheme {
1923 bar_padding_horizontal: Some(10.0),
1924 bar_padding_vertical: Some(6.0),
1925 ..Default::default()
1926 };
1927 let toml_str = toml::to_string(&m).unwrap();
1928 assert!(
1929 toml_str.contains("bar_padding_horizontal_px = 10.0"),
1930 "{toml_str}"
1931 );
1932 assert!(
1933 toml_str.contains("bar_padding_vertical_px = 6.0"),
1934 "{toml_str}"
1935 );
1936 let m2: MenuTheme = toml::from_str(&toml_str).unwrap();
1937 assert_eq!(m, m2);
1938
1939 let m = MenuTheme {
1940 min_row_height: Some(29.0),
1941 panel_padding_horizontal: Some(3.0),
1942 panel_padding_vertical: Some(3.0),
1943 ..Default::default()
1944 };
1945 let toml_str = toml::to_string(&m).unwrap();
1946 for key in [
1947 "min_row_height_px = 29.0",
1948 "panel_padding_horizontal_px = 3.0",
1949 "panel_padding_vertical_px = 3.0",
1950 ] {
1951 assert!(toml_str.contains(key), "{toml_str}");
1952 }
1953 let m2: MenuTheme = toml::from_str(&toml_str).unwrap();
1954 assert_eq!(m, m2);
1955
1956 let s = SliderTheme {
1957 thumb_border_line_width: Some(1.0),
1958 ..Default::default()
1959 };
1960 let toml_str = toml::to_string(&s).unwrap();
1961 assert!(
1962 toml_str.contains("thumb_border_line_width_px = 1.0"),
1963 "{toml_str}"
1964 );
1965 let s2: SliderTheme = toml::from_str(&toml_str).unwrap();
1966 assert_eq!(s, s2);
1967 }
1968
1969 #[test]
1970 fn card_theme_with_border() {
1971 let c = CardTheme {
1972 background_color: Some(Rgba::rgb(255, 255, 255)),
1973 border: Some(WidgetBorderSpec {
1974 corner_radius: Some(8.0),
1975 shadow_enabled: Some(true),
1976 ..Default::default()
1977 }),
1978 };
1979 assert!(!c.is_empty());
1980 }
1981
1982 #[test]
1983 fn link_theme_has_underline_enabled_bool_field() {
1984 let l = LinkTheme {
1985 visited_text_color: Some(Rgba::rgb(100, 0, 200)),
1986 underline_enabled: Some(true),
1987 ..Default::default()
1988 };
1989 assert!(!l.is_empty());
1990 assert_eq!(l.underline_enabled, Some(true));
1991 }
1992
1993 #[test]
1994 fn status_bar_theme_has_font_and_background() {
1995 let s = StatusBarTheme {
1996 background_color: Some(Rgba::rgb(240, 240, 240)),
1997 font: Some(FontSpec {
1998 size: Some(FontSize::Px(11.0)),
1999 ..Default::default()
2000 }),
2001 ..Default::default()
2002 };
2003 assert!(!s.is_empty());
2004 }
2005
2006 #[serde_with::skip_serializing_none]
2011 #[derive(
2012 Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget,
2013 )]
2014 #[serde(default)]
2015 #[theme_layer(skip_inventory)]
2016 pub struct DualNestedTestWidget {
2017 pub background: Option<Rgba>,
2018 pub min_height: Option<f32>,
2019 #[theme(nested, resolved_type = "ResolvedFontSpec")]
2020 pub font: Option<FontSpec>,
2021 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
2022 pub border: Option<WidgetBorderSpec>,
2023 }
2024
2025 #[test]
2026 fn dual_nested_default_is_empty() {
2027 assert!(DualNestedTestWidget::default().is_empty());
2028 }
2029
2030 #[test]
2031 fn dual_nested_field_names() {
2032 assert_eq!(DualNestedTestWidget::FIELD_NAMES.len(), 4);
2033 assert!(DualNestedTestWidget::FIELD_NAMES.contains(&"background"));
2034 assert!(DualNestedTestWidget::FIELD_NAMES.contains(&"min_height"));
2035 assert!(DualNestedTestWidget::FIELD_NAMES.contains(&"font"));
2036 assert!(DualNestedTestWidget::FIELD_NAMES.contains(&"border"));
2037 }
2038
2039 #[test]
2040 fn dual_nested_not_empty_when_font_set() {
2041 let w = DualNestedTestWidget {
2042 font: Some(FontSpec {
2043 family: Some("Inter".into()),
2044 ..Default::default()
2045 }),
2046 ..Default::default()
2047 };
2048 assert!(!w.is_empty());
2049 }
2050
2051 #[test]
2052 fn dual_nested_not_empty_when_border_set() {
2053 let w = DualNestedTestWidget {
2054 border: Some(WidgetBorderSpec {
2055 color: Some(Rgba::rgb(100, 100, 100)),
2056 ..Default::default()
2057 }),
2058 ..Default::default()
2059 };
2060 assert!(!w.is_empty());
2061 }
2062
2063 #[test]
2064 fn dual_nested_merge_both_nested() {
2065 let mut base = DualNestedTestWidget {
2066 font: Some(FontSpec {
2067 family: Some("Noto Sans".into()),
2068 ..Default::default()
2069 }),
2070 ..Default::default()
2071 };
2072 let overlay = DualNestedTestWidget {
2073 border: Some(WidgetBorderSpec {
2074 corner_radius: Some(4.0),
2075 ..Default::default()
2076 }),
2077 ..Default::default()
2078 };
2079 base.merge(&overlay);
2080 assert!(base.font.is_some());
2081 assert!(base.border.is_some());
2082 assert_eq!(
2083 base.font.as_ref().and_then(|f| f.family.as_deref()),
2084 Some("Noto Sans")
2085 );
2086 assert_eq!(
2087 base.border.as_ref().and_then(|b| b.corner_radius),
2088 Some(4.0)
2089 );
2090 }
2091
2092 #[test]
2093 fn dual_nested_merge_inner_font_fields() {
2094 let mut base = DualNestedTestWidget {
2095 font: Some(FontSpec {
2096 family: Some("Noto Sans".into()),
2097 ..Default::default()
2098 }),
2099 ..Default::default()
2100 };
2101 let overlay = DualNestedTestWidget {
2102 font: Some(FontSpec {
2103 size: Some(FontSize::Px(14.0)),
2104 ..Default::default()
2105 }),
2106 ..Default::default()
2107 };
2108 base.merge(&overlay);
2109 let font = base.font.as_ref().unwrap();
2110 assert_eq!(font.family.as_deref(), Some("Noto Sans")); assert_eq!(font.size, Some(FontSize::Px(14.0))); }
2113
2114 #[test]
2115 fn dual_nested_toml_round_trip() {
2116 let w = DualNestedTestWidget {
2117 background: Some(Rgba::rgb(240, 240, 240)),
2118 min_height: Some(32.0),
2119 font: Some(FontSpec {
2120 family: Some("Inter".into()),
2121 size: Some(FontSize::Px(14.0)),
2122 weight: Some(400),
2123 ..Default::default()
2124 }),
2125 border: Some(WidgetBorderSpec {
2126 color: Some(Rgba::rgb(180, 180, 180)),
2127 corner_radius: Some(4.0),
2128 line_width: Some(1.0),
2129 ..Default::default()
2130 }),
2131 };
2132 let toml_str = toml::to_string(&w).unwrap();
2133 let w2: DualNestedTestWidget = toml::from_str(&toml_str).unwrap();
2134 assert_eq!(w, w2);
2135 }
2136
2137 #[test]
2142 fn button_validate_widget_extracts_all_fields() {
2143 let button = ButtonTheme {
2144 background_color: Some(Rgba::rgb(200, 200, 200)),
2145 primary_background: Some(Rgba::rgb(0, 120, 215)),
2146 primary_text_color: Some(Rgba::rgb(255, 255, 255)),
2147 min_width: Some(80.0),
2148 min_height: Some(32.0),
2149 icon_text_gap: Some(8.0),
2150 disabled_opacity: Some(0.4),
2151 hover_background: Some(Rgba::rgb(210, 210, 210)),
2152 hover_text_color: Some(Rgba::rgb(0, 0, 0)),
2153 active_text_color: Some(Rgba::rgb(0, 0, 0)),
2154 disabled_text_color: Some(Rgba::rgb(128, 128, 128)),
2155 active_background: Some(Rgba::rgb(180, 180, 180)),
2156 disabled_background: Some(Rgba::rgb(220, 220, 220)),
2157 checked_background: Some(Rgba::rgb(190, 190, 190)),
2158 checked_text_color: None,
2159 hover_border_color: Some(Rgba::rgb(0, 120, 215)),
2160 focus_border_color: None,
2161 default_button_background: Some(Rgba::rgb(210, 230, 245)),
2162 default_button_text_color: None,
2163 default_button_border_color: None,
2164 font: Some(FontSpec {
2165 family: Some("Inter".into()),
2166 size: Some(FontSize::Px(14.0)),
2167 weight: Some(400),
2168 style: Some(crate::model::font::FontStyle::Normal),
2169 color: Some(Rgba::rgb(0, 0, 0)),
2170 }),
2171 border: Some(WidgetBorderSpec {
2172 color: Some(Rgba::rgb(100, 100, 100)),
2173 corner_radius: Some(4.0),
2174 line_width: Some(1.0),
2175 shadow_enabled: Some(false),
2176 padding_top: Some(6.0),
2177 padding_right: Some(12.0),
2178 padding_bottom: Some(6.0),
2179 padding_left: Some(12.0),
2180 }),
2181 };
2182 let mut missing = Vec::new();
2183 let resolved = ResolvedButtonTheme::validate_widget(&button, "button", 96.0, &mut missing);
2184 assert!(missing.is_empty(), "unexpected missing: {missing:?}");
2185 assert_eq!(resolved.background_color, Rgba::rgb(200, 200, 200));
2186 assert_eq!(resolved.min_width, 80.0);
2187 assert_eq!(resolved.font.family.as_ref(), "Inter");
2188 assert_eq!(resolved.font.size, 14.0);
2189 assert_eq!(resolved.border.corner_radius, 4.0);
2190 assert_eq!(resolved.active_background, Some(Rgba::rgb(180, 180, 180)));
2192 assert_eq!(resolved.disabled_background, Some(Rgba::rgb(220, 220, 220)));
2193 assert_eq!(resolved.checked_background, Some(Rgba::rgb(190, 190, 190)));
2194 assert_eq!(resolved.checked_text_color, None);
2195 assert_eq!(resolved.hover_border_color, Some(Rgba::rgb(0, 120, 215)));
2196 assert_eq!(resolved.focus_border_color, None);
2197 assert_eq!(
2198 resolved.default_button_background,
2199 Some(Rgba::rgb(210, 230, 245))
2200 );
2201 assert_eq!(resolved.default_button_text_color, None);
2202 assert_eq!(resolved.default_button_border_color, None);
2203 }
2204
2205 #[test]
2206 fn button_validate_widget_records_missing_fields() {
2207 let button = ButtonTheme::default(); let mut missing = Vec::new();
2209 let _ = ResolvedButtonTheme::validate_widget(&button, "button", 96.0, &mut missing);
2210 assert!(missing.contains(&"button.background_color".to_string()));
2212 assert!(missing.contains(&"button.min_width_px".to_string()));
2213 assert!(missing.contains(&"button.font".to_string()));
2215 assert!(missing.contains(&"button.border".to_string()));
2217 assert!(!missing.iter().any(|m| m.contains("active_background")));
2219 assert!(!missing.iter().any(|m| m.contains("disabled_background")));
2220 }
2221
2222 #[test]
2225 fn layout_theme_default_is_empty() {
2226 assert!(LayoutTheme::default().is_empty());
2227 }
2228
2229 #[test]
2230 fn layout_theme_not_empty_when_widget_gap_set() {
2231 let l = LayoutTheme {
2232 widget_gap: Some(8.0),
2233 ..Default::default()
2234 };
2235 assert!(!l.is_empty());
2236 }
2237
2238 #[test]
2239 fn layout_theme_field_names() {
2240 assert_eq!(LayoutTheme::FIELD_NAMES.len(), 4);
2241 assert!(LayoutTheme::FIELD_NAMES.contains(&"widget_gap_px"));
2242 assert!(LayoutTheme::FIELD_NAMES.contains(&"container_margin_px"));
2243 assert!(LayoutTheme::FIELD_NAMES.contains(&"window_margin_px"));
2244 assert!(LayoutTheme::FIELD_NAMES.contains(&"section_gap_px"));
2245 }
2246
2247 #[test]
2248 fn layout_theme_toml_round_trip() {
2249 let l = LayoutTheme {
2250 widget_gap: Some(8.0),
2251 container_margin: Some(12.0),
2252 window_margin: Some(16.0),
2253 section_gap: Some(24.0),
2254 };
2255 let toml_str = toml::to_string(&l).unwrap();
2256 let l2: LayoutTheme = toml::from_str(&toml_str).unwrap();
2257 assert_eq!(l, l2);
2258 }
2259
2260 #[test]
2261 fn layout_theme_merge() {
2262 let mut base = LayoutTheme {
2263 widget_gap: Some(6.0),
2264 container_margin: Some(10.0),
2265 ..Default::default()
2266 };
2267 let overlay = LayoutTheme {
2268 widget_gap: Some(8.0),
2269 section_gap: Some(24.0),
2270 ..Default::default()
2271 };
2272 base.merge(&overlay);
2273 assert_eq!(base.widget_gap, Some(8.0));
2275 assert_eq!(base.container_margin, Some(10.0));
2277 assert_eq!(base.section_gap, Some(24.0));
2279 assert!(base.window_margin.is_none());
2281 }
2282}