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(nested, resolved_type = "ResolvedFontSpec")]
100 pub font: Option<FontSpec>,
101 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
103 pub border: Option<WidgetBorderSpec>,
104}
105
106#[serde_with::skip_serializing_none]
111#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
112#[serde(default)]
113#[theme_inherit(border_kind = "full", font = "font")]
114pub struct InputTheme {
115 #[theme(inherit_from = "defaults.background_color")]
117 pub background_color: Option<Rgba>,
118 #[theme(inherit_from = "defaults.muted_color")]
120 pub placeholder_color: Option<Rgba>,
121 pub caret_color: Option<Rgba>,
123 #[theme(inherit_from = "defaults.text_selection_background")]
125 pub selection_background: Option<Rgba>,
126 #[theme(inherit_from = "defaults.text_selection_color")]
128 pub selection_text_color: Option<Rgba>,
129 #[serde(rename = "min_height_px")]
131 #[theme(check = "non_negative")]
132 pub min_height: Option<f32>,
133 #[theme(range = "0.0..=1.0", inherit_from = "defaults.disabled_opacity")]
137 pub disabled_opacity: Option<f32>,
138 #[theme(inherit_from = "defaults.disabled_text_color")]
140 pub disabled_text_color: Option<Rgba>,
141 #[theme(category = "soft_option")]
143 pub hover_border_color: Option<Rgba>,
144 #[theme(category = "soft_option")]
146 pub focus_border_color: Option<Rgba>,
147 #[theme(category = "soft_option")]
149 pub disabled_background: Option<Rgba>,
150 #[theme(nested, resolved_type = "ResolvedFontSpec")]
152 pub font: Option<FontSpec>,
153 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
155 pub border: Option<WidgetBorderSpec>,
156}
157
158#[serde_with::skip_serializing_none]
164#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
165#[serde(default)]
166pub struct TextAreaTheme {
167 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
173 pub border: Option<WidgetBorderSpec>,
174}
175
176#[serde_with::skip_serializing_none]
180#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
181#[serde(default)]
182#[theme_inherit(border_kind = "full", font = "font")]
183pub struct CheckboxTheme {
184 #[theme(inherit_from = "defaults.background_color")]
186 pub background_color: Option<Rgba>,
187 #[theme(inherit_from = "defaults.accent_color")]
189 pub checked_background: Option<Rgba>,
190 #[theme(inherit_from = "defaults.accent_text_color")]
192 pub indicator_color: Option<Rgba>,
193 #[serde(rename = "indicator_width_px")]
197 #[theme(check = "non_negative")]
198 pub indicator_width: Option<f32>,
199 #[serde(rename = "radio_indicator_width_px")]
204 #[theme(category = "soft_option", check = "non_negative")]
205 pub radio_indicator_width: Option<f32>,
206 #[serde(rename = "radio_dot_diameter_px")]
210 #[theme(category = "soft_option", check = "non_negative")]
211 pub radio_dot_diameter: Option<f32>,
212 #[serde(rename = "check_mark_stroke_width_px")]
216 #[theme(category = "soft_option", check = "non_negative")]
217 pub check_mark_stroke_width: Option<f32>,
218 #[serde(rename = "label_gap_px")]
220 #[theme(check = "non_negative")]
221 pub label_gap: Option<f32>,
222 #[theme(range = "0.0..=1.0", inherit_from = "defaults.disabled_opacity")]
226 pub disabled_opacity: Option<f32>,
227 #[theme(inherit_from = "defaults.disabled_text_color")]
229 pub disabled_text_color: Option<Rgba>,
230 #[theme(category = "soft_option")]
232 pub hover_background: Option<Rgba>,
233 #[theme(category = "soft_option")]
236 pub disabled_background: Option<Rgba>,
237 #[theme(category = "soft_option")]
239 pub unchecked_background: Option<Rgba>,
240 #[theme(category = "soft_option")]
242 pub unchecked_border_color: Option<Rgba>,
243 #[theme(nested, resolved_type = "ResolvedFontSpec")]
245 pub font: Option<FontSpec>,
246 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
248 pub border: Option<WidgetBorderSpec>,
249}
250
251#[serde_with::skip_serializing_none]
255#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
256#[serde(default)]
257#[theme_layer(border_kind = "none")]
258#[theme_inherit(font = "font")]
259pub struct MenuTheme {
260 #[theme(inherit_from = "defaults.background_color")]
262 pub background_color: Option<Rgba>,
263 #[theme(inherit_from = "defaults.border.color")]
265 pub separator_color: Option<Rgba>,
266 #[serde(rename = "row_height_px")]
270 #[theme(category = "soft_option", check = "non_negative")]
271 pub row_height: Option<f32>,
272 #[serde(rename = "icon_text_gap_px")]
274 #[theme(check = "non_negative")]
275 pub icon_text_gap: Option<f32>,
276 #[serde(rename = "icon_size_px")]
278 #[theme(check = "non_negative", inherit_from = "defaults.icon_sizes.toolbar")]
279 pub icon_size: Option<f32>,
280 #[theme(inherit_from = "defaults.selection_background")]
286 pub hover_background: Option<Rgba>,
287 #[theme(inherit_from = "defaults.selection_text_color")]
289 pub hover_text_color: Option<Rgba>,
290 #[theme(inherit_from = "defaults.disabled_text_color")]
292 pub disabled_text_color: Option<Rgba>,
293 #[theme(nested, resolved_type = "ResolvedFontSpec")]
295 pub font: Option<FontSpec>,
296 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
305 pub border: Option<WidgetBorderSpec>,
306}
307
308#[serde_with::skip_serializing_none]
312#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
313#[serde(default)]
314#[theme_inherit(border_kind = "full", font = "font")]
315pub struct TooltipTheme {
316 #[theme(inherit_from = "defaults.background_color")]
318 pub background_color: Option<Rgba>,
319 #[serde(rename = "max_width_px")]
321 #[theme(check = "non_negative")]
322 pub max_width: Option<f32>,
323 #[serde(rename = "show_delay_ms")]
327 #[theme(category = "soft_option")]
328 pub show_delay: Option<u16>,
329 #[theme(nested, resolved_type = "ResolvedFontSpec")]
331 pub font: Option<FontSpec>,
332 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
334 pub border: Option<WidgetBorderSpec>,
335}
336
337#[serde_with::skip_serializing_none]
341#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
342#[serde(default)]
343pub struct ScrollbarTheme {
344 pub track_color: Option<Rgba>,
348 #[theme(inherit_from = "defaults.muted_color")]
350 pub thumb_color: Option<Rgba>,
351 #[theme(inherit_from = "defaults.muted_color")]
353 pub thumb_hover_color: Option<Rgba>,
354 #[serde(rename = "groove_width_px")]
356 #[theme(check = "non_negative")]
357 pub groove_width: Option<f32>,
358 #[serde(rename = "min_thumb_length_px")]
360 #[theme(check = "non_negative")]
361 pub min_thumb_length: Option<f32>,
362 #[serde(rename = "thumb_width_px")]
364 #[theme(check = "non_negative")]
365 pub thumb_width: Option<f32>,
366 pub overlay_mode: Option<bool>,
368 #[theme(category = "soft_option")]
370 pub thumb_active_color: Option<Rgba>,
371}
372
373#[serde_with::skip_serializing_none]
377#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
378#[serde(default)]
379pub struct SliderTheme {
380 #[theme(inherit_from = "defaults.accent_color")]
382 pub fill_color: Option<Rgba>,
383 #[theme(inherit_from = "defaults.muted_color")]
385 pub track_color: Option<Rgba>,
386 #[theme(inherit_from = "defaults.surface_color")]
388 pub thumb_color: Option<Rgba>,
389 #[serde(rename = "track_height_px")]
391 #[theme(check = "non_negative")]
392 pub track_height: Option<f32>,
393 #[serde(rename = "thumb_diameter_px")]
395 #[theme(check = "non_negative")]
396 pub thumb_diameter: Option<f32>,
397 #[serde(rename = "tick_mark_length_px")]
399 #[theme(check = "non_negative")]
400 pub tick_mark_length: Option<f32>,
401 #[theme(range = "0.0..=1.0", inherit_from = "defaults.disabled_opacity")]
405 pub disabled_opacity: Option<f32>,
406 #[theme(category = "soft_option")]
408 pub thumb_hover_color: Option<Rgba>,
409 #[theme(category = "soft_option")]
412 pub disabled_fill_color: Option<Rgba>,
413 #[theme(category = "soft_option")]
415 pub disabled_track_color: Option<Rgba>,
416 #[theme(category = "soft_option")]
418 pub disabled_thumb_color: Option<Rgba>,
419}
420
421#[serde_with::skip_serializing_none]
425#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
426#[serde(default)]
427#[theme_inherit(border_kind = "full")]
428pub struct ProgressBarTheme {
429 #[theme(inherit_from = "defaults.accent_color")]
431 pub fill_color: Option<Rgba>,
432 #[theme(inherit_from = "defaults.muted_color")]
434 pub track_color: Option<Rgba>,
435 #[serde(rename = "track_height_px")]
437 #[theme(check = "non_negative")]
438 pub track_height: Option<f32>,
439 #[serde(rename = "min_width_px")]
441 #[theme(check = "non_negative")]
442 pub min_width: Option<f32>,
443 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
445 pub border: Option<WidgetBorderSpec>,
446}
447
448#[serde_with::skip_serializing_none]
452#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
453#[serde(default)]
454#[theme_layer(border_kind = "none")]
455#[theme_inherit(font = "font")]
456pub struct TabTheme {
457 #[theme(inherit_from = "defaults.background_color")]
459 pub background_color: Option<Rgba>,
460 #[theme(inherit_from = "defaults.background_color")]
462 pub active_background: Option<Rgba>,
463 #[theme(inherit_from = "defaults.text_color")]
465 pub active_text_color: Option<Rgba>,
466 #[theme(inherit_from = "defaults.background_color")]
468 pub bar_background: Option<Rgba>,
469 #[serde(rename = "min_width_px")]
471 #[theme(check = "non_negative")]
472 pub min_width: Option<f32>,
473 #[serde(rename = "min_height_px")]
475 #[theme(check = "non_negative")]
476 pub min_height: Option<f32>,
477 #[serde(rename = "item_gap_px")]
481 #[theme(category = "soft_option", check = "non_negative")]
482 pub item_gap: Option<f32>,
483 #[theme(category = "soft_option")]
489 pub active_indicator_color: Option<Rgba>,
490 #[serde(rename = "active_indicator_width_px")]
493 #[theme(category = "soft_option", check = "non_negative")]
494 pub active_indicator_width: Option<f32>,
495 #[theme(category = "soft_option")]
499 pub active_indicator_side: Option<TabIndicatorSide>,
500 #[serde(rename = "active_outward_corner_radius_px")]
508 #[theme(category = "soft_option", check = "non_negative")]
509 pub active_outward_corner_radius: Option<f32>,
510 pub hover_text_color: Option<Rgba>,
512 #[theme(category = "soft_option")]
514 pub hover_background: Option<Rgba>,
515 #[theme(nested, resolved_type = "ResolvedFontSpec")]
517 pub font: Option<FontSpec>,
518 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
520 pub border: Option<WidgetBorderSpec>,
521}
522
523#[serde_with::skip_serializing_none]
527#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
528#[serde(default)]
529#[theme_layer(border_kind = "partial")]
530#[theme_inherit(border_kind = "partial", font = "font")]
531pub struct SidebarTheme {
532 #[theme(inherit_from = "defaults.background_color")]
534 pub background_color: Option<Rgba>,
535 #[theme(inherit_from = "defaults.selection_background")]
537 pub selection_background: Option<Rgba>,
538 #[theme(inherit_from = "defaults.selection_text_color")]
540 pub selection_text_color: Option<Rgba>,
541 pub hover_background: Option<Rgba>,
545 #[theme(nested, resolved_type = "ResolvedFontSpec")]
547 pub font: Option<FontSpec>,
548 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
550 pub border: Option<WidgetBorderSpec>,
551}
552
553#[serde_with::skip_serializing_none]
557#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
558#[serde(default)]
559#[theme_inherit(border_kind = "full", font = "font")]
560pub struct ToolbarTheme {
561 #[theme(inherit_from = "defaults.background_color")]
563 pub background_color: Option<Rgba>,
564 #[serde(rename = "bar_height_px")]
568 #[theme(category = "soft_option", check = "non_negative")]
569 pub bar_height: Option<f32>,
570 #[serde(rename = "item_gap_px")]
574 #[theme(category = "soft_option", check = "non_negative")]
575 pub item_gap: Option<f32>,
576 #[serde(rename = "icon_size_px")]
578 #[theme(check = "non_negative", inherit_from = "defaults.icon_sizes.toolbar")]
579 pub icon_size: Option<f32>,
580 #[theme(nested, resolved_type = "ResolvedFontSpec")]
582 pub font: Option<FontSpec>,
583 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
585 pub border: Option<WidgetBorderSpec>,
586}
587
588#[serde_with::skip_serializing_none]
592#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
593#[serde(default)]
594#[theme_layer(border_kind = "partial")]
595#[theme_inherit(border_kind = "partial", font = "font")]
596pub struct StatusBarTheme {
597 #[theme(inherit_from = "defaults.background_color")]
599 pub background_color: Option<Rgba>,
600 #[theme(nested, resolved_type = "ResolvedFontSpec")]
602 pub font: Option<FontSpec>,
603 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
605 pub border: Option<WidgetBorderSpec>,
606}
607
608#[serde_with::skip_serializing_none]
612#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
613#[serde(default)]
614#[theme_inherit(border_kind = "full", font = "item_font")]
615#[theme_inherit(font = "header_font")]
616pub struct ListTheme {
617 pub background_color: Option<Rgba>,
619 pub alternate_row_background: Option<Rgba>,
621 #[theme(inherit_from = "defaults.selection_background")]
623 pub selection_background: Option<Rgba>,
624 #[theme(inherit_from = "defaults.selection_text_color")]
626 pub selection_text_color: Option<Rgba>,
627 #[theme(inherit_from = "defaults.surface_color")]
629 pub header_background: Option<Rgba>,
630 #[theme(inherit_from = "defaults.border.color")]
633 pub grid_color: Option<Rgba>,
634 #[serde(rename = "row_height_px")]
638 #[theme(category = "soft_option", check = "non_negative")]
639 pub row_height: Option<f32>,
640 #[serde(rename = "header_height_px")]
644 #[theme(category = "soft_option", check = "positive")]
645 pub header_height: Option<f32>,
646 pub hover_background: Option<Rgba>,
654 pub hover_text_color: Option<Rgba>,
656 #[theme(inherit_from = "defaults.disabled_text_color")]
658 pub disabled_text_color: Option<Rgba>,
659 #[theme(nested, resolved_type = "ResolvedFontSpec")]
661 pub item_font: Option<FontSpec>,
662 #[theme(nested, resolved_type = "ResolvedFontSpec")]
664 pub header_font: Option<FontSpec>,
665 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
667 pub border: Option<WidgetBorderSpec>,
668}
669
670#[serde_with::skip_serializing_none]
674#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
675#[serde(default)]
676#[theme_inherit(border_kind = "full_lg", font = "font")]
677pub struct PopoverTheme {
678 pub background_color: Option<Rgba>,
680 #[theme(nested, resolved_type = "ResolvedFontSpec")]
682 pub font: Option<FontSpec>,
683 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
685 pub border: Option<WidgetBorderSpec>,
686}
687
688#[serde_with::skip_serializing_none]
692#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
693#[serde(default)]
694pub struct SplitterTheme {
695 #[serde(rename = "divider_width_px")]
697 #[theme(check = "non_negative")]
698 pub divider_width: Option<f32>,
699 #[theme(inherit_from = "defaults.border.color")]
701 pub divider_color: Option<Rgba>,
702 pub hover_color: Option<Rgba>,
704}
705
706#[serde_with::skip_serializing_none]
710#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
711#[serde(default)]
712pub struct SeparatorTheme {
713 #[theme(inherit_from = "defaults.border.color")]
715 pub line_color: Option<Rgba>,
716 #[serde(rename = "line_width_px")]
718 #[theme(check = "non_negative", inherit_from = "defaults.border.line_width")]
719 pub line_width: Option<f32>,
720}
721
722#[serde_with::skip_serializing_none]
726#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
727#[serde(default)]
728pub struct SwitchTheme {
729 #[theme(inherit_from = "defaults.accent_color")]
731 pub checked_background: Option<Rgba>,
732 pub unchecked_background: Option<Rgba>,
734 #[theme(inherit_from = "defaults.surface_color")]
737 pub thumb_background: Option<Rgba>,
738 #[theme(category = "soft_option")]
743 pub unchecked_thumb_background: Option<Rgba>,
744 #[serde(rename = "track_width_px")]
746 #[theme(check = "non_negative")]
747 pub track_width: Option<f32>,
748 #[serde(rename = "track_height_px")]
750 #[theme(check = "non_negative")]
751 pub track_height: Option<f32>,
752 #[serde(rename = "thumb_diameter_px")]
758 #[theme(check = "non_negative")]
759 pub thumb_diameter: Option<f32>,
760 #[serde(rename = "unchecked_thumb_diameter_px")]
765 #[theme(category = "soft_option", check = "non_negative")]
766 pub unchecked_thumb_diameter: Option<f32>,
767 #[serde(rename = "track_radius_px")]
769 #[theme(check = "non_negative")]
770 pub track_radius: Option<f32>,
771 #[theme(range = "0.0..=1.0", inherit_from = "defaults.disabled_opacity")]
775 pub disabled_opacity: Option<f32>,
776 #[theme(category = "soft_option")]
778 pub hover_checked_background: Option<Rgba>,
779 #[theme(category = "soft_option")]
781 pub hover_unchecked_background: Option<Rgba>,
782 #[theme(category = "soft_option")]
785 pub disabled_checked_background: Option<Rgba>,
786 #[theme(category = "soft_option")]
788 pub disabled_unchecked_background: Option<Rgba>,
789 #[theme(category = "soft_option")]
791 pub disabled_thumb_color: Option<Rgba>,
792 #[theme(category = "soft_option")]
798 pub unchecked_track_border_color: Option<Rgba>,
799 #[theme(category = "soft_option")]
803 pub checked_track_border_color: Option<Rgba>,
804 #[theme(category = "soft_option")]
807 pub disabled_unchecked_track_border_color: Option<Rgba>,
808 #[theme(category = "soft_option")]
810 pub disabled_checked_track_border_color: Option<Rgba>,
811 #[serde(rename = "track_border_line_width_px")]
814 #[theme(category = "soft_option", check = "non_negative")]
815 pub track_border_line_width: Option<f32>,
816 #[theme(category = "soft_option")]
820 pub thumb_border_color: Option<Rgba>,
821 #[serde(rename = "thumb_border_line_width_px")]
823 #[theme(category = "soft_option", check = "non_negative")]
824 pub thumb_border_line_width: Option<f32>,
825}
826
827#[serde_with::skip_serializing_none]
831#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
832#[serde(default)]
833#[theme_inherit(border_kind = "full_lg", font = "title_font")]
834#[theme_inherit(font = "body_font")]
835pub struct DialogTheme {
836 pub background_color: Option<Rgba>,
838 #[serde(rename = "min_width_px")]
840 #[theme(check = "non_negative", min_max_pair = "max_width")]
841 pub min_width: Option<f32>,
842 #[serde(rename = "max_width_px")]
844 #[theme(check = "non_negative")]
845 pub max_width: Option<f32>,
846 #[serde(rename = "min_height_px")]
848 #[theme(check = "non_negative", min_max_pair = "max_height")]
849 pub min_height: Option<f32>,
850 #[serde(rename = "max_height_px")]
852 #[theme(check = "non_negative")]
853 pub max_height: Option<f32>,
854 #[serde(rename = "button_gap_px")]
856 #[theme(check = "non_negative")]
857 pub button_gap: Option<f32>,
858 #[serde(rename = "icon_size_px")]
860 #[theme(check = "non_negative")]
861 pub icon_size: Option<f32>,
862 pub button_order: Option<DialogButtonOrder>,
864 #[theme(category = "soft_option")]
869 pub entrance: Option<DialogEntranceStyle>,
870 #[theme(nested, resolved_type = "ResolvedFontSpec")]
872 pub title_font: Option<FontSpec>,
873 #[theme(nested, resolved_type = "ResolvedFontSpec")]
875 pub body_font: Option<FontSpec>,
876 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
878 pub border: Option<WidgetBorderSpec>,
879}
880
881#[serde_with::skip_serializing_none]
885#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
886#[serde(default)]
887pub struct SpinnerTheme {
888 pub fill_color: Option<Rgba>,
890 #[serde(rename = "diameter_px")]
892 #[theme(check = "non_negative")]
893 pub diameter: Option<f32>,
894 #[serde(rename = "min_diameter_px")]
896 #[theme(check = "non_negative")]
897 pub min_diameter: Option<f32>,
898 #[serde(rename = "stroke_width_px")]
900 #[theme(check = "non_negative")]
901 pub stroke_width: Option<f32>,
902}
903
904#[serde_with::skip_serializing_none]
908#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
909#[serde(default)]
910#[theme_inherit(border_kind = "full", font = "font")]
911pub struct ComboBoxTheme {
912 #[theme(inherit_from = "defaults.background_color")]
914 pub background_color: Option<Rgba>,
915 #[serde(rename = "min_height_px")]
917 #[theme(check = "non_negative")]
918 pub min_height: Option<f32>,
919 #[serde(rename = "min_width_px")]
921 #[theme(check = "non_negative")]
922 pub min_width: Option<f32>,
923 #[serde(rename = "arrow_icon_size_px")]
925 #[theme(check = "non_negative")]
926 pub arrow_icon_size: Option<f32>,
927 #[serde(rename = "arrow_area_width_px")]
933 #[theme(category = "soft_option", check = "non_negative")]
934 pub arrow_area_width: Option<f32>,
935 #[theme(range = "0.0..=1.0", inherit_from = "defaults.disabled_opacity")]
939 pub disabled_opacity: Option<f32>,
940 #[theme(inherit_from = "defaults.disabled_text_color")]
942 pub disabled_text_color: Option<Rgba>,
943 #[theme(category = "soft_option")]
945 pub hover_background: Option<Rgba>,
946 #[theme(category = "soft_option")]
948 pub disabled_background: Option<Rgba>,
949 #[theme(nested, resolved_type = "ResolvedFontSpec")]
951 pub font: Option<FontSpec>,
952 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
954 pub border: Option<WidgetBorderSpec>,
955}
956
957#[serde_with::skip_serializing_none]
961#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
962#[serde(default)]
963#[theme_inherit(border_kind = "full", font = "font")]
964pub struct SegmentedControlTheme {
965 #[theme(inherit_from = "defaults.background_color")]
967 pub background_color: Option<Rgba>,
968 #[theme(inherit_from = "defaults.accent_color")]
970 pub active_background: Option<Rgba>,
971 #[theme(inherit_from = "defaults.accent_text_color")]
973 pub active_text_color: Option<Rgba>,
974 #[serde(rename = "segment_height_px")]
976 #[theme(check = "non_negative")]
977 pub segment_height: Option<f32>,
978 #[serde(rename = "separator_width_px")]
980 #[theme(check = "non_negative")]
981 pub separator_width: Option<f32>,
982 #[theme(range = "0.0..=1.0", inherit_from = "defaults.disabled_opacity")]
986 pub disabled_opacity: Option<f32>,
987 #[theme(category = "soft_option")]
989 pub hover_background: Option<Rgba>,
990 #[theme(nested, resolved_type = "ResolvedFontSpec")]
992 pub font: Option<FontSpec>,
993 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
995 pub border: Option<WidgetBorderSpec>,
996}
997
998#[serde_with::skip_serializing_none]
1002#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
1003#[serde(default)]
1004#[theme_layer(border_kind = "none")]
1005pub struct CardTheme {
1006 #[theme(inherit_from = "defaults.surface_color")]
1008 pub background_color: Option<Rgba>,
1009 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
1011 pub border: Option<WidgetBorderSpec>,
1012}
1013
1014#[serde_with::skip_serializing_none]
1018#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
1019#[serde(default)]
1020#[theme_inherit(border_kind = "full", font = "font")]
1021pub struct ExpanderTheme {
1022 #[serde(rename = "header_height_px")]
1024 #[theme(check = "non_negative")]
1025 pub header_height: Option<f32>,
1026 #[serde(rename = "arrow_icon_size_px")]
1028 #[theme(check = "non_negative")]
1029 pub arrow_icon_size: Option<f32>,
1030 #[theme(category = "soft_option")]
1032 pub hover_background: Option<Rgba>,
1033 #[theme(category = "soft_option")]
1035 pub arrow_color: Option<Rgba>,
1036 #[theme(category = "soft_option")]
1040 pub arrow_side: Option<ArrowSide>,
1041 #[serde(rename = "arrow_gap_px")]
1046 #[theme(category = "soft_option", check = "non_negative")]
1047 pub arrow_gap: Option<f32>,
1048 #[serde(rename = "content_indent_px")]
1053 #[theme(category = "soft_option", check = "non_negative")]
1054 pub content_indent: Option<f32>,
1055 #[theme(category = "soft_option")]
1060 pub frame_enabled: Option<bool>,
1061 #[theme(nested, resolved_type = "ResolvedFontSpec")]
1063 pub font: Option<FontSpec>,
1064 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
1066 pub border: Option<WidgetBorderSpec>,
1067}
1068
1069#[serde_with::skip_serializing_none]
1073#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
1074#[serde(default)]
1075#[theme_inherit(font = "font")]
1076pub struct LinkTheme {
1077 #[theme(inherit_from = "defaults.link_color")]
1079 pub visited_text_color: Option<Rgba>,
1080 pub underline_enabled: Option<bool>,
1082 pub background_color: Option<Rgba>,
1084 pub hover_background: Option<Rgba>,
1086 pub hover_text_color: Option<Rgba>,
1088 pub active_text_color: Option<Rgba>,
1090 #[theme(inherit_from = "defaults.disabled_text_color")]
1092 pub disabled_text_color: Option<Rgba>,
1093 #[theme(nested, resolved_type = "ResolvedFontSpec")]
1095 pub font: Option<FontSpec>,
1096}
1097
1098#[serde_with::skip_serializing_none]
1109#[derive(
1110 Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget, ThemeFields,
1111)]
1112#[serde(default)]
1113#[theme_layer(skip_inventory)]
1114pub struct LayoutTheme {
1115 #[serde(rename = "widget_gap_px")]
1117 #[theme(check = "non_negative")]
1118 pub widget_gap: Option<f32>,
1119 #[serde(rename = "container_margin_px")]
1121 #[theme(check = "non_negative")]
1122 pub container_margin: Option<f32>,
1123 #[serde(rename = "window_margin_px")]
1125 #[theme(check = "non_negative")]
1126 pub window_margin: Option<f32>,
1127 #[serde(rename = "section_gap_px")]
1129 #[theme(check = "non_negative")]
1130 pub section_gap: Option<f32>,
1131}
1132
1133#[cfg(test)]
1134#[allow(clippy::unwrap_used, clippy::expect_used, dead_code)]
1135mod tests {
1136 use super::*;
1137 use crate::Rgba;
1138 use crate::model::border::{ResolvedWidgetBorder, WidgetBorderSpec};
1139 use crate::model::font::FontSize;
1140 use crate::model::{DialogButtonOrder, FontSpec};
1141
1142 #[serde_with::skip_serializing_none]
1145 #[derive(
1146 Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget,
1147 )]
1148 #[serde(default)]
1149 #[theme_layer(skip_inventory)]
1150 pub struct TestWidget {
1151 pub size: Option<f32>,
1152 pub label: Option<String>,
1153 #[theme(nested, resolved_type = "ResolvedFontSpec")]
1154 pub font: Option<FontSpec>,
1155 }
1156
1157 #[test]
1160 fn resolved_font_spec_fields_are_concrete() {
1161 let rfs = ResolvedFontSpec {
1162 family: "Inter".into(),
1163 size: 14.0,
1164 defined_size: Some(crate::model::font::FontSize::Px(14.0)),
1165 weight: 400,
1166 style: crate::model::font::FontStyle::Normal,
1167 color: crate::Rgba::rgb(0, 0, 0),
1168 };
1169 assert_eq!(rfs.family.as_ref(), "Inter");
1170 assert_eq!(rfs.size, 14.0);
1171 assert_eq!(rfs.weight, 400);
1172 }
1173
1174 #[test]
1177 fn generated_option_struct_has_option_fields() {
1178 let w = TestWidget::default();
1179 assert!(w.size.is_none());
1180 assert!(w.label.is_none());
1181 assert!(w.font.is_none());
1182 }
1183
1184 #[test]
1185 fn generated_option_struct_is_empty_by_default() {
1186 assert!(TestWidget::default().is_empty());
1187 }
1188
1189 #[test]
1190 fn generated_option_struct_not_empty_when_size_set() {
1191 let w = TestWidget {
1192 size: Some(24.0),
1193 ..Default::default()
1194 };
1195 assert!(!w.is_empty());
1196 }
1197
1198 #[test]
1199 fn generated_option_struct_not_empty_when_font_set() {
1200 let w = TestWidget {
1201 font: Some(FontSpec {
1202 size: Some(FontSize::Px(14.0)),
1203 ..Default::default()
1204 }),
1205 ..Default::default()
1206 };
1207 assert!(!w.is_empty());
1208 }
1209
1210 #[test]
1211 fn generated_resolved_struct_has_concrete_fields() {
1212 let resolved = ResolvedTestWidget {
1213 size: 24.0,
1214 label: "Click me".into(),
1215 font: ResolvedFontSpec {
1216 family: "Inter".into(),
1217 size: 14.0,
1218 defined_size: Some(crate::model::font::FontSize::Px(14.0)),
1219 weight: 400,
1220 style: crate::model::font::FontStyle::Normal,
1221 color: crate::Rgba::rgb(0, 0, 0),
1222 },
1223 };
1224 assert_eq!(resolved.size, 24.0);
1225 assert_eq!(resolved.label, "Click me");
1226 assert_eq!(resolved.font.family.as_ref(), "Inter");
1227 }
1228
1229 #[test]
1232 fn generated_merge_option_field_overlay_wins() {
1233 let mut base = TestWidget {
1234 size: Some(20.0),
1235 ..Default::default()
1236 };
1237 let overlay = TestWidget {
1238 size: Some(24.0),
1239 ..Default::default()
1240 };
1241 base.merge(&overlay);
1242 assert_eq!(base.size, Some(24.0));
1243 }
1244
1245 #[test]
1246 fn generated_merge_option_field_none_preserves_base() {
1247 let mut base = TestWidget {
1248 size: Some(20.0),
1249 ..Default::default()
1250 };
1251 let overlay = TestWidget::default();
1252 base.merge(&overlay);
1253 assert_eq!(base.size, Some(20.0));
1254 }
1255
1256 #[test]
1257 fn generated_merge_optional_nested_both_some_merges_inner() {
1258 let mut base = TestWidget {
1259 font: Some(FontSpec {
1260 family: Some("Noto Sans".into()),
1261 size: Some(FontSize::Px(12.0)),
1262 weight: None,
1263 ..Default::default()
1264 }),
1265 ..Default::default()
1266 };
1267 let overlay = TestWidget {
1268 font: Some(FontSpec {
1269 family: None,
1270 size: None,
1271 weight: Some(700),
1272 ..Default::default()
1273 }),
1274 ..Default::default()
1275 };
1276 base.merge(&overlay);
1277 let font = base.font.as_ref().unwrap();
1278 assert_eq!(font.family.as_deref(), Some("Noto Sans")); assert_eq!(font.size, Some(FontSize::Px(12.0))); assert_eq!(font.weight, Some(700)); }
1282
1283 #[test]
1284 fn generated_merge_optional_nested_none_plus_some_clones() {
1285 let mut base = TestWidget::default();
1286 let overlay = TestWidget {
1287 font: Some(FontSpec {
1288 family: Some("Inter".into()),
1289 size: Some(FontSize::Px(14.0)),
1290 weight: Some(400),
1291 ..Default::default()
1292 }),
1293 ..Default::default()
1294 };
1295 base.merge(&overlay);
1296 let font = base.font.as_ref().unwrap();
1297 assert_eq!(font.family.as_deref(), Some("Inter"));
1298 assert_eq!(font.size, Some(FontSize::Px(14.0)));
1299 assert_eq!(font.weight, Some(400));
1300 }
1301
1302 #[test]
1303 fn generated_merge_optional_nested_some_plus_none_preserves_base() {
1304 let mut base = TestWidget {
1305 font: Some(FontSpec {
1306 family: Some("Inter".into()),
1307 size: Some(FontSize::Px(14.0)),
1308 weight: Some(400),
1309 ..Default::default()
1310 }),
1311 ..Default::default()
1312 };
1313 let overlay = TestWidget::default();
1314 base.merge(&overlay);
1315 let font = base.font.as_ref().unwrap();
1316 assert_eq!(font.family.as_deref(), Some("Inter"));
1317 }
1318
1319 #[test]
1320 fn generated_merge_optional_nested_none_plus_none_stays_none() {
1321 let mut base = TestWidget::default();
1322 let overlay = TestWidget::default();
1323 base.merge(&overlay);
1324 assert!(base.font.is_none());
1325 }
1326
1327 #[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize)]
1331 struct WithFont {
1332 name: Option<String>,
1333 font: Option<FontSpec>,
1334 }
1335
1336 impl_merge!(WithFont {
1337 option { name }
1338 optional_nested { font }
1339 });
1340
1341 #[test]
1342 fn impl_merge_optional_nested_none_none_stays_none() {
1343 let mut base = WithFont::default();
1344 let overlay = WithFont::default();
1345 base.merge(&overlay);
1346 assert!(base.font.is_none());
1347 }
1348
1349 #[test]
1350 fn impl_merge_optional_nested_some_none_preserves_base() {
1351 let mut base = WithFont {
1352 font: Some(FontSpec {
1353 size: Some(FontSize::Px(12.0)),
1354 ..Default::default()
1355 }),
1356 ..Default::default()
1357 };
1358 let overlay = WithFont::default();
1359 base.merge(&overlay);
1360 assert_eq!(base.font.as_ref().unwrap().size, Some(FontSize::Px(12.0)));
1361 }
1362
1363 #[test]
1364 fn impl_merge_optional_nested_none_some_clones_overlay() {
1365 let mut base = WithFont::default();
1366 let overlay = WithFont {
1367 font: Some(FontSpec {
1368 family: Some("Inter".into()),
1369 ..Default::default()
1370 }),
1371 ..Default::default()
1372 };
1373 base.merge(&overlay);
1374 assert_eq!(base.font.as_ref().unwrap().family.as_deref(), Some("Inter"));
1375 }
1376
1377 #[test]
1378 fn impl_merge_optional_nested_some_some_merges_inner() {
1379 let mut base = WithFont {
1380 font: Some(FontSpec {
1381 family: Some("Noto".into()),
1382 size: Some(FontSize::Px(11.0)),
1383 weight: None,
1384 ..Default::default()
1385 }),
1386 ..Default::default()
1387 };
1388 let overlay = WithFont {
1389 font: Some(FontSpec {
1390 family: None,
1391 size: Some(FontSize::Px(14.0)),
1392 weight: Some(400),
1393 ..Default::default()
1394 }),
1395 ..Default::default()
1396 };
1397 base.merge(&overlay);
1398 let f = base.font.as_ref().unwrap();
1399 assert_eq!(f.family.as_deref(), Some("Noto")); assert_eq!(f.size, Some(FontSize::Px(14.0))); assert_eq!(f.weight, Some(400)); }
1403
1404 #[test]
1405 fn impl_merge_optional_nested_is_empty_none() {
1406 let w = WithFont::default();
1407 assert!(w.is_empty());
1408 }
1409
1410 #[test]
1411 fn impl_merge_optional_nested_is_empty_some_default() {
1412 let w = WithFont {
1414 font: Some(FontSpec::default()),
1415 ..Default::default()
1416 };
1417 assert!(w.is_empty());
1418 }
1419
1420 #[test]
1421 fn impl_merge_optional_nested_is_not_empty_when_populated() {
1422 let w = WithFont {
1423 font: Some(FontSpec {
1424 size: Some(FontSize::Px(14.0)),
1425 ..Default::default()
1426 }),
1427 ..Default::default()
1428 };
1429 assert!(!w.is_empty());
1430 }
1431
1432 #[test]
1435 fn button_theme_default_is_empty() {
1436 assert!(ButtonTheme::default().is_empty());
1437 }
1438
1439 #[test]
1440 fn button_theme_not_empty_when_set() {
1441 let b = ButtonTheme {
1442 background_color: Some(Rgba::rgb(200, 200, 200)),
1443 min_width: Some(64.0),
1444 ..Default::default()
1445 };
1446 assert!(!b.is_empty());
1447 }
1448
1449 #[test]
1450 fn button_theme_merge_font_optional_nested() {
1451 let mut base = ButtonTheme {
1452 font: Some(FontSpec {
1453 family: Some("Noto Sans".into()),
1454 size: Some(FontSize::Px(11.0)),
1455 weight: None,
1456 ..Default::default()
1457 }),
1458 ..Default::default()
1459 };
1460 let overlay = ButtonTheme {
1461 font: Some(FontSpec {
1462 family: None,
1463 weight: Some(700),
1464 ..Default::default()
1465 }),
1466 ..Default::default()
1467 };
1468 base.merge(&overlay);
1469 let f = base.font.as_ref().unwrap();
1470 assert_eq!(f.family.as_deref(), Some("Noto Sans")); assert_eq!(f.weight, Some(700)); }
1473
1474 #[test]
1475 fn button_theme_toml_round_trip_with_font_and_border() {
1476 let b = ButtonTheme {
1477 background_color: Some(Rgba::rgb(200, 200, 200)),
1478 font: Some(FontSpec {
1479 family: Some("Inter".into()),
1480 size: Some(FontSize::Px(14.0)),
1481 weight: Some(400),
1482 ..Default::default()
1483 }),
1484 border: Some(WidgetBorderSpec {
1485 corner_radius: Some(4.0),
1486 ..Default::default()
1487 }),
1488 ..Default::default()
1489 };
1490 let toml_str = toml::to_string(&b).unwrap();
1491 let b2: ButtonTheme = toml::from_str(&toml_str).unwrap();
1492 assert_eq!(b, b2);
1493 }
1494
1495 #[test]
1498 fn window_theme_has_new_fields() {
1499 let w = WindowTheme {
1500 inactive_title_bar_background: Some(Rgba::rgb(180, 180, 180)),
1501 inactive_title_bar_text_color: Some(Rgba::rgb(120, 120, 120)),
1502 title_bar_font: Some(FontSpec {
1503 weight: Some(700),
1504 ..Default::default()
1505 }),
1506 border: Some(WidgetBorderSpec {
1507 corner_radius: Some(4.0),
1508 shadow_enabled: Some(true),
1509 ..Default::default()
1510 }),
1511 ..Default::default()
1512 };
1513 assert!(!w.is_empty());
1514 assert!(w.inactive_title_bar_background.is_some());
1515 assert!(w.inactive_title_bar_text_color.is_some());
1516 assert!(w.title_bar_font.is_some());
1517 assert!(w.border.is_some());
1518 }
1519
1520 #[test]
1521 fn window_theme_default_is_empty() {
1522 assert!(WindowTheme::default().is_empty());
1523 }
1524
1525 #[test]
1528 fn dialog_theme_button_order_works() {
1529 let d = DialogTheme {
1530 button_order: Some(DialogButtonOrder::PrimaryRight),
1531 min_width: Some(300.0),
1532 ..Default::default()
1533 };
1534 assert_eq!(d.button_order, Some(DialogButtonOrder::PrimaryRight));
1535 assert_eq!(d.min_width, Some(300.0));
1536 assert!(!d.is_empty());
1537 }
1538
1539 #[test]
1540 fn dialog_theme_button_order_toml_round_trip() {
1541 let d = DialogTheme {
1542 button_order: Some(DialogButtonOrder::PrimaryLeft),
1543 ..Default::default()
1544 };
1545 let toml_str = toml::to_string(&d).unwrap();
1546 let d2: DialogTheme = toml::from_str(&toml_str).unwrap();
1547 assert_eq!(d, d2);
1548 }
1549
1550 #[test]
1551 fn dialog_theme_default_is_empty() {
1552 assert!(DialogTheme::default().is_empty());
1553 }
1554
1555 #[test]
1558 fn splitter_theme_single_field_merge() {
1559 let mut base = SplitterTheme {
1560 divider_width: Some(4.0),
1561 ..Default::default()
1562 };
1563 let overlay = SplitterTheme {
1564 divider_width: Some(6.0),
1565 ..Default::default()
1566 };
1567 base.merge(&overlay);
1568 assert_eq!(base.divider_width, Some(6.0));
1569 }
1570
1571 #[test]
1572 fn splitter_theme_merge_none_preserves_base() {
1573 let mut base = SplitterTheme {
1574 divider_width: Some(4.0),
1575 ..Default::default()
1576 };
1577 let overlay = SplitterTheme::default();
1578 base.merge(&overlay);
1579 assert_eq!(base.divider_width, Some(4.0));
1580 }
1581
1582 #[test]
1583 fn splitter_theme_default_is_empty() {
1584 assert!(SplitterTheme::default().is_empty());
1585 }
1586
1587 #[test]
1588 fn splitter_theme_not_empty_when_set() {
1589 assert!(
1590 !SplitterTheme {
1591 divider_width: Some(4.0),
1592 ..Default::default()
1593 }
1594 .is_empty()
1595 );
1596 }
1597
1598 #[test]
1601 fn separator_theme_single_field() {
1602 let s = SeparatorTheme {
1603 line_color: Some(Rgba::rgb(200, 200, 200)),
1604 ..Default::default()
1605 };
1606 assert!(!s.is_empty());
1607 }
1608
1609 #[test]
1612 fn all_widget_theme_defaults_are_empty() {
1613 assert!(WindowTheme::default().is_empty());
1614 assert!(ButtonTheme::default().is_empty());
1615 assert!(InputTheme::default().is_empty());
1616 assert!(CheckboxTheme::default().is_empty());
1617 assert!(MenuTheme::default().is_empty());
1618 assert!(TooltipTheme::default().is_empty());
1619 assert!(ScrollbarTheme::default().is_empty());
1620 assert!(SliderTheme::default().is_empty());
1621 assert!(ProgressBarTheme::default().is_empty());
1622 assert!(TabTheme::default().is_empty());
1623 assert!(SidebarTheme::default().is_empty());
1624 assert!(ToolbarTheme::default().is_empty());
1625 assert!(StatusBarTheme::default().is_empty());
1626 assert!(ListTheme::default().is_empty());
1627 assert!(PopoverTheme::default().is_empty());
1628 assert!(SplitterTheme::default().is_empty());
1629 assert!(SeparatorTheme::default().is_empty());
1630 assert!(SwitchTheme::default().is_empty());
1631 assert!(DialogTheme::default().is_empty());
1632 assert!(SpinnerTheme::default().is_empty());
1633 assert!(ComboBoxTheme::default().is_empty());
1634 assert!(SegmentedControlTheme::default().is_empty());
1635 assert!(CardTheme::default().is_empty());
1636 assert!(ExpanderTheme::default().is_empty());
1637 assert!(LinkTheme::default().is_empty());
1638 }
1639
1640 #[test]
1643 fn input_theme_toml_round_trip() {
1644 let t = InputTheme {
1645 background_color: Some(Rgba::rgb(255, 255, 255)),
1646 font: Some(FontSpec {
1647 family: Some("Noto Sans".into()),
1648 ..Default::default()
1649 }),
1650 border: Some(WidgetBorderSpec {
1651 color: Some(Rgba::rgb(180, 180, 180)),
1652 corner_radius: Some(4.0),
1653 ..Default::default()
1654 }),
1655 ..Default::default()
1656 };
1657 let toml_str = toml::to_string(&t).unwrap();
1658 let t2: InputTheme = toml::from_str(&toml_str).unwrap();
1659 assert_eq!(t, t2);
1660 }
1661
1662 #[test]
1663 fn switch_theme_toml_round_trip() {
1664 let s = SwitchTheme {
1665 checked_background: Some(Rgba::rgb(0, 120, 215)),
1666 track_width: Some(40.0),
1667 track_height: Some(20.0),
1668 thumb_diameter: Some(14.0),
1669 track_radius: Some(10.0),
1670 ..Default::default()
1671 };
1672 let toml_str = toml::to_string(&s).unwrap();
1673 let s2: SwitchTheme = toml::from_str(&toml_str).unwrap();
1674 assert_eq!(s, s2);
1675 }
1676
1677 #[test]
1678 fn card_theme_with_border() {
1679 let c = CardTheme {
1680 background_color: Some(Rgba::rgb(255, 255, 255)),
1681 border: Some(WidgetBorderSpec {
1682 corner_radius: Some(8.0),
1683 shadow_enabled: Some(true),
1684 ..Default::default()
1685 }),
1686 };
1687 assert!(!c.is_empty());
1688 }
1689
1690 #[test]
1691 fn link_theme_has_underline_enabled_bool_field() {
1692 let l = LinkTheme {
1693 visited_text_color: Some(Rgba::rgb(100, 0, 200)),
1694 underline_enabled: Some(true),
1695 ..Default::default()
1696 };
1697 assert!(!l.is_empty());
1698 assert_eq!(l.underline_enabled, Some(true));
1699 }
1700
1701 #[test]
1702 fn status_bar_theme_has_font_and_background() {
1703 let s = StatusBarTheme {
1704 background_color: Some(Rgba::rgb(240, 240, 240)),
1705 font: Some(FontSpec {
1706 size: Some(FontSize::Px(11.0)),
1707 ..Default::default()
1708 }),
1709 ..Default::default()
1710 };
1711 assert!(!s.is_empty());
1712 }
1713
1714 #[serde_with::skip_serializing_none]
1719 #[derive(
1720 Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget,
1721 )]
1722 #[serde(default)]
1723 #[theme_layer(skip_inventory)]
1724 pub struct DualNestedTestWidget {
1725 pub background: Option<Rgba>,
1726 pub min_height: Option<f32>,
1727 #[theme(nested, resolved_type = "ResolvedFontSpec")]
1728 pub font: Option<FontSpec>,
1729 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
1730 pub border: Option<WidgetBorderSpec>,
1731 }
1732
1733 #[test]
1734 fn dual_nested_default_is_empty() {
1735 assert!(DualNestedTestWidget::default().is_empty());
1736 }
1737
1738 #[test]
1739 fn dual_nested_field_names() {
1740 assert_eq!(DualNestedTestWidget::FIELD_NAMES.len(), 4);
1741 assert!(DualNestedTestWidget::FIELD_NAMES.contains(&"background"));
1742 assert!(DualNestedTestWidget::FIELD_NAMES.contains(&"min_height"));
1743 assert!(DualNestedTestWidget::FIELD_NAMES.contains(&"font"));
1744 assert!(DualNestedTestWidget::FIELD_NAMES.contains(&"border"));
1745 }
1746
1747 #[test]
1748 fn dual_nested_not_empty_when_font_set() {
1749 let w = DualNestedTestWidget {
1750 font: Some(FontSpec {
1751 family: Some("Inter".into()),
1752 ..Default::default()
1753 }),
1754 ..Default::default()
1755 };
1756 assert!(!w.is_empty());
1757 }
1758
1759 #[test]
1760 fn dual_nested_not_empty_when_border_set() {
1761 let w = DualNestedTestWidget {
1762 border: Some(WidgetBorderSpec {
1763 color: Some(Rgba::rgb(100, 100, 100)),
1764 ..Default::default()
1765 }),
1766 ..Default::default()
1767 };
1768 assert!(!w.is_empty());
1769 }
1770
1771 #[test]
1772 fn dual_nested_merge_both_nested() {
1773 let mut base = DualNestedTestWidget {
1774 font: Some(FontSpec {
1775 family: Some("Noto Sans".into()),
1776 ..Default::default()
1777 }),
1778 ..Default::default()
1779 };
1780 let overlay = DualNestedTestWidget {
1781 border: Some(WidgetBorderSpec {
1782 corner_radius: Some(4.0),
1783 ..Default::default()
1784 }),
1785 ..Default::default()
1786 };
1787 base.merge(&overlay);
1788 assert!(base.font.is_some());
1789 assert!(base.border.is_some());
1790 assert_eq!(
1791 base.font.as_ref().and_then(|f| f.family.as_deref()),
1792 Some("Noto Sans")
1793 );
1794 assert_eq!(
1795 base.border.as_ref().and_then(|b| b.corner_radius),
1796 Some(4.0)
1797 );
1798 }
1799
1800 #[test]
1801 fn dual_nested_merge_inner_font_fields() {
1802 let mut base = DualNestedTestWidget {
1803 font: Some(FontSpec {
1804 family: Some("Noto Sans".into()),
1805 ..Default::default()
1806 }),
1807 ..Default::default()
1808 };
1809 let overlay = DualNestedTestWidget {
1810 font: Some(FontSpec {
1811 size: Some(FontSize::Px(14.0)),
1812 ..Default::default()
1813 }),
1814 ..Default::default()
1815 };
1816 base.merge(&overlay);
1817 let font = base.font.as_ref().unwrap();
1818 assert_eq!(font.family.as_deref(), Some("Noto Sans")); assert_eq!(font.size, Some(FontSize::Px(14.0))); }
1821
1822 #[test]
1823 fn dual_nested_toml_round_trip() {
1824 let w = DualNestedTestWidget {
1825 background: Some(Rgba::rgb(240, 240, 240)),
1826 min_height: Some(32.0),
1827 font: Some(FontSpec {
1828 family: Some("Inter".into()),
1829 size: Some(FontSize::Px(14.0)),
1830 weight: Some(400),
1831 ..Default::default()
1832 }),
1833 border: Some(WidgetBorderSpec {
1834 color: Some(Rgba::rgb(180, 180, 180)),
1835 corner_radius: Some(4.0),
1836 line_width: Some(1.0),
1837 ..Default::default()
1838 }),
1839 };
1840 let toml_str = toml::to_string(&w).unwrap();
1841 let w2: DualNestedTestWidget = toml::from_str(&toml_str).unwrap();
1842 assert_eq!(w, w2);
1843 }
1844
1845 #[test]
1850 fn button_validate_widget_extracts_all_fields() {
1851 let button = ButtonTheme {
1852 background_color: Some(Rgba::rgb(200, 200, 200)),
1853 primary_background: Some(Rgba::rgb(0, 120, 215)),
1854 primary_text_color: Some(Rgba::rgb(255, 255, 255)),
1855 min_width: Some(80.0),
1856 min_height: Some(32.0),
1857 icon_text_gap: Some(8.0),
1858 disabled_opacity: Some(0.4),
1859 hover_background: Some(Rgba::rgb(210, 210, 210)),
1860 hover_text_color: Some(Rgba::rgb(0, 0, 0)),
1861 active_text_color: Some(Rgba::rgb(0, 0, 0)),
1862 disabled_text_color: Some(Rgba::rgb(128, 128, 128)),
1863 active_background: Some(Rgba::rgb(180, 180, 180)),
1864 disabled_background: Some(Rgba::rgb(220, 220, 220)),
1865 checked_background: Some(Rgba::rgb(190, 190, 190)),
1866 checked_text_color: None,
1867 font: Some(FontSpec {
1868 family: Some("Inter".into()),
1869 size: Some(FontSize::Px(14.0)),
1870 weight: Some(400),
1871 style: Some(crate::model::font::FontStyle::Normal),
1872 color: Some(Rgba::rgb(0, 0, 0)),
1873 }),
1874 border: Some(WidgetBorderSpec {
1875 color: Some(Rgba::rgb(100, 100, 100)),
1876 corner_radius: Some(4.0),
1877 line_width: Some(1.0),
1878 shadow_enabled: Some(false),
1879 padding_top: Some(6.0),
1880 padding_right: Some(12.0),
1881 padding_bottom: Some(6.0),
1882 padding_left: Some(12.0),
1883 }),
1884 };
1885 let mut missing = Vec::new();
1886 let resolved = ResolvedButtonTheme::validate_widget(&button, "button", 96.0, &mut missing);
1887 assert!(missing.is_empty(), "unexpected missing: {missing:?}");
1888 assert_eq!(resolved.background_color, Rgba::rgb(200, 200, 200));
1889 assert_eq!(resolved.min_width, 80.0);
1890 assert_eq!(resolved.font.family.as_ref(), "Inter");
1891 assert_eq!(resolved.font.size, 14.0);
1892 assert_eq!(resolved.border.corner_radius, 4.0);
1893 assert_eq!(resolved.active_background, Some(Rgba::rgb(180, 180, 180)));
1895 assert_eq!(resolved.disabled_background, Some(Rgba::rgb(220, 220, 220)));
1896 assert_eq!(resolved.checked_background, Some(Rgba::rgb(190, 190, 190)));
1897 assert_eq!(resolved.checked_text_color, None);
1898 }
1899
1900 #[test]
1901 fn button_validate_widget_records_missing_fields() {
1902 let button = ButtonTheme::default(); let mut missing = Vec::new();
1904 let _ = ResolvedButtonTheme::validate_widget(&button, "button", 96.0, &mut missing);
1905 assert!(missing.contains(&"button.background_color".to_string()));
1907 assert!(missing.contains(&"button.min_width_px".to_string()));
1908 assert!(missing.contains(&"button.font".to_string()));
1910 assert!(missing.contains(&"button.border".to_string()));
1912 assert!(!missing.iter().any(|m| m.contains("active_background")));
1914 assert!(!missing.iter().any(|m| m.contains("disabled_background")));
1915 }
1916
1917 #[test]
1920 fn layout_theme_default_is_empty() {
1921 assert!(LayoutTheme::default().is_empty());
1922 }
1923
1924 #[test]
1925 fn layout_theme_not_empty_when_widget_gap_set() {
1926 let l = LayoutTheme {
1927 widget_gap: Some(8.0),
1928 ..Default::default()
1929 };
1930 assert!(!l.is_empty());
1931 }
1932
1933 #[test]
1934 fn layout_theme_field_names() {
1935 assert_eq!(LayoutTheme::FIELD_NAMES.len(), 4);
1936 assert!(LayoutTheme::FIELD_NAMES.contains(&"widget_gap_px"));
1937 assert!(LayoutTheme::FIELD_NAMES.contains(&"container_margin_px"));
1938 assert!(LayoutTheme::FIELD_NAMES.contains(&"window_margin_px"));
1939 assert!(LayoutTheme::FIELD_NAMES.contains(&"section_gap_px"));
1940 }
1941
1942 #[test]
1943 fn layout_theme_toml_round_trip() {
1944 let l = LayoutTheme {
1945 widget_gap: Some(8.0),
1946 container_margin: Some(12.0),
1947 window_margin: Some(16.0),
1948 section_gap: Some(24.0),
1949 };
1950 let toml_str = toml::to_string(&l).unwrap();
1951 let l2: LayoutTheme = toml::from_str(&toml_str).unwrap();
1952 assert_eq!(l, l2);
1953 }
1954
1955 #[test]
1956 fn layout_theme_merge() {
1957 let mut base = LayoutTheme {
1958 widget_gap: Some(6.0),
1959 container_margin: Some(10.0),
1960 ..Default::default()
1961 };
1962 let overlay = LayoutTheme {
1963 widget_gap: Some(8.0),
1964 section_gap: Some(24.0),
1965 ..Default::default()
1966 };
1967 base.merge(&overlay);
1968 assert_eq!(base.widget_gap, Some(8.0));
1970 assert_eq!(base.container_margin, Some(10.0));
1972 assert_eq!(base.section_gap, Some(24.0));
1974 assert!(base.window_margin.is_none());
1976 }
1977}