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")]
282 pub hover_background: Option<Rgba>,
283 #[theme(inherit_from = "defaults.selection_text_color")]
285 pub hover_text_color: Option<Rgba>,
286 #[theme(inherit_from = "defaults.disabled_text_color")]
288 pub disabled_text_color: Option<Rgba>,
289 #[theme(nested, resolved_type = "ResolvedFontSpec")]
291 pub font: Option<FontSpec>,
292 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
294 pub border: Option<WidgetBorderSpec>,
295}
296
297#[serde_with::skip_serializing_none]
301#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
302#[serde(default)]
303#[theme_inherit(border_kind = "full", font = "font")]
304pub struct TooltipTheme {
305 #[theme(inherit_from = "defaults.background_color")]
307 pub background_color: Option<Rgba>,
308 #[serde(rename = "max_width_px")]
310 #[theme(check = "non_negative")]
311 pub max_width: Option<f32>,
312 #[serde(rename = "show_delay_ms")]
316 #[theme(category = "soft_option")]
317 pub show_delay: Option<u16>,
318 #[theme(nested, resolved_type = "ResolvedFontSpec")]
320 pub font: Option<FontSpec>,
321 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
323 pub border: Option<WidgetBorderSpec>,
324}
325
326#[serde_with::skip_serializing_none]
330#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
331#[serde(default)]
332pub struct ScrollbarTheme {
333 pub track_color: Option<Rgba>,
335 #[theme(inherit_from = "defaults.muted_color")]
337 pub thumb_color: Option<Rgba>,
338 #[theme(inherit_from = "defaults.muted_color")]
340 pub thumb_hover_color: Option<Rgba>,
341 #[serde(rename = "groove_width_px")]
343 #[theme(check = "non_negative")]
344 pub groove_width: Option<f32>,
345 #[serde(rename = "min_thumb_length_px")]
347 #[theme(check = "non_negative")]
348 pub min_thumb_length: Option<f32>,
349 #[serde(rename = "thumb_width_px")]
351 #[theme(check = "non_negative")]
352 pub thumb_width: Option<f32>,
353 pub overlay_mode: Option<bool>,
355 #[theme(category = "soft_option")]
357 pub thumb_active_color: Option<Rgba>,
358}
359
360#[serde_with::skip_serializing_none]
364#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
365#[serde(default)]
366pub struct SliderTheme {
367 #[theme(inherit_from = "defaults.accent_color")]
369 pub fill_color: Option<Rgba>,
370 #[theme(inherit_from = "defaults.muted_color")]
372 pub track_color: Option<Rgba>,
373 #[theme(inherit_from = "defaults.surface_color")]
375 pub thumb_color: Option<Rgba>,
376 #[serde(rename = "track_height_px")]
378 #[theme(check = "non_negative")]
379 pub track_height: Option<f32>,
380 #[serde(rename = "thumb_diameter_px")]
382 #[theme(check = "non_negative")]
383 pub thumb_diameter: Option<f32>,
384 #[serde(rename = "tick_mark_length_px")]
386 #[theme(check = "non_negative")]
387 pub tick_mark_length: Option<f32>,
388 #[theme(range = "0.0..=1.0", inherit_from = "defaults.disabled_opacity")]
392 pub disabled_opacity: Option<f32>,
393 #[theme(category = "soft_option")]
395 pub thumb_hover_color: Option<Rgba>,
396 #[theme(category = "soft_option")]
399 pub disabled_fill_color: Option<Rgba>,
400 #[theme(category = "soft_option")]
402 pub disabled_track_color: Option<Rgba>,
403 #[theme(category = "soft_option")]
405 pub disabled_thumb_color: Option<Rgba>,
406}
407
408#[serde_with::skip_serializing_none]
412#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
413#[serde(default)]
414#[theme_inherit(border_kind = "full")]
415pub struct ProgressBarTheme {
416 #[theme(inherit_from = "defaults.accent_color")]
418 pub fill_color: Option<Rgba>,
419 #[theme(inherit_from = "defaults.muted_color")]
421 pub track_color: Option<Rgba>,
422 #[serde(rename = "track_height_px")]
424 #[theme(check = "non_negative")]
425 pub track_height: Option<f32>,
426 #[serde(rename = "min_width_px")]
428 #[theme(check = "non_negative")]
429 pub min_width: Option<f32>,
430 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
432 pub border: Option<WidgetBorderSpec>,
433}
434
435#[serde_with::skip_serializing_none]
439#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
440#[serde(default)]
441#[theme_layer(border_kind = "none")]
442#[theme_inherit(font = "font")]
443pub struct TabTheme {
444 #[theme(inherit_from = "defaults.background_color")]
446 pub background_color: Option<Rgba>,
447 #[theme(inherit_from = "defaults.background_color")]
449 pub active_background: Option<Rgba>,
450 #[theme(inherit_from = "defaults.text_color")]
452 pub active_text_color: Option<Rgba>,
453 #[theme(inherit_from = "defaults.background_color")]
455 pub bar_background: Option<Rgba>,
456 #[serde(rename = "min_width_px")]
458 #[theme(check = "non_negative")]
459 pub min_width: Option<f32>,
460 #[serde(rename = "min_height_px")]
462 #[theme(check = "non_negative")]
463 pub min_height: Option<f32>,
464 #[serde(rename = "item_gap_px")]
468 #[theme(category = "soft_option", check = "non_negative")]
469 pub item_gap: Option<f32>,
470 #[theme(category = "soft_option")]
476 pub active_indicator_color: Option<Rgba>,
477 #[serde(rename = "active_indicator_width_px")]
480 #[theme(category = "soft_option", check = "non_negative")]
481 pub active_indicator_width: Option<f32>,
482 #[theme(category = "soft_option")]
486 pub active_indicator_side: Option<TabIndicatorSide>,
487 #[serde(rename = "active_outward_corner_radius_px")]
495 #[theme(category = "soft_option", check = "non_negative")]
496 pub active_outward_corner_radius: Option<f32>,
497 pub hover_text_color: Option<Rgba>,
499 #[theme(category = "soft_option")]
501 pub hover_background: Option<Rgba>,
502 #[theme(nested, resolved_type = "ResolvedFontSpec")]
504 pub font: Option<FontSpec>,
505 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
507 pub border: Option<WidgetBorderSpec>,
508}
509
510#[serde_with::skip_serializing_none]
514#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
515#[serde(default)]
516#[theme_layer(border_kind = "partial")]
517#[theme_inherit(border_kind = "partial", font = "font")]
518pub struct SidebarTheme {
519 #[theme(inherit_from = "defaults.background_color")]
521 pub background_color: Option<Rgba>,
522 #[theme(inherit_from = "defaults.selection_background")]
524 pub selection_background: Option<Rgba>,
525 #[theme(inherit_from = "defaults.selection_text_color")]
527 pub selection_text_color: Option<Rgba>,
528 pub hover_background: Option<Rgba>,
532 #[theme(nested, resolved_type = "ResolvedFontSpec")]
534 pub font: Option<FontSpec>,
535 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
537 pub border: Option<WidgetBorderSpec>,
538}
539
540#[serde_with::skip_serializing_none]
544#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
545#[serde(default)]
546#[theme_inherit(border_kind = "full", font = "font")]
547pub struct ToolbarTheme {
548 #[theme(inherit_from = "defaults.background_color")]
550 pub background_color: Option<Rgba>,
551 #[serde(rename = "bar_height_px")]
555 #[theme(category = "soft_option", check = "non_negative")]
556 pub bar_height: Option<f32>,
557 #[serde(rename = "item_gap_px")]
561 #[theme(category = "soft_option", check = "non_negative")]
562 pub item_gap: Option<f32>,
563 #[serde(rename = "icon_size_px")]
565 #[theme(check = "non_negative", inherit_from = "defaults.icon_sizes.toolbar")]
566 pub icon_size: Option<f32>,
567 #[theme(nested, resolved_type = "ResolvedFontSpec")]
569 pub font: Option<FontSpec>,
570 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
572 pub border: Option<WidgetBorderSpec>,
573}
574
575#[serde_with::skip_serializing_none]
579#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
580#[serde(default)]
581#[theme_layer(border_kind = "partial")]
582#[theme_inherit(border_kind = "partial", font = "font")]
583pub struct StatusBarTheme {
584 #[theme(inherit_from = "defaults.background_color")]
586 pub background_color: Option<Rgba>,
587 #[theme(nested, resolved_type = "ResolvedFontSpec")]
589 pub font: Option<FontSpec>,
590 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
592 pub border: Option<WidgetBorderSpec>,
593}
594
595#[serde_with::skip_serializing_none]
599#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
600#[serde(default)]
601#[theme_inherit(border_kind = "full", font = "item_font")]
602#[theme_inherit(font = "header_font")]
603pub struct ListTheme {
604 pub background_color: Option<Rgba>,
606 pub alternate_row_background: Option<Rgba>,
608 #[theme(inherit_from = "defaults.selection_background")]
610 pub selection_background: Option<Rgba>,
611 #[theme(inherit_from = "defaults.selection_text_color")]
613 pub selection_text_color: Option<Rgba>,
614 #[theme(inherit_from = "defaults.surface_color")]
616 pub header_background: Option<Rgba>,
617 #[theme(inherit_from = "defaults.border.color")]
619 pub grid_color: Option<Rgba>,
620 #[serde(rename = "row_height_px")]
624 #[theme(category = "soft_option", check = "non_negative")]
625 pub row_height: Option<f32>,
626 #[serde(rename = "header_height_px")]
630 #[theme(category = "soft_option", check = "positive")]
631 pub header_height: Option<f32>,
632 pub hover_background: Option<Rgba>,
636 pub hover_text_color: Option<Rgba>,
638 #[theme(inherit_from = "defaults.disabled_text_color")]
640 pub disabled_text_color: Option<Rgba>,
641 #[theme(nested, resolved_type = "ResolvedFontSpec")]
643 pub item_font: Option<FontSpec>,
644 #[theme(nested, resolved_type = "ResolvedFontSpec")]
646 pub header_font: Option<FontSpec>,
647 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
649 pub border: Option<WidgetBorderSpec>,
650}
651
652#[serde_with::skip_serializing_none]
656#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
657#[serde(default)]
658#[theme_inherit(border_kind = "full_lg", font = "font")]
659pub struct PopoverTheme {
660 pub background_color: Option<Rgba>,
662 #[theme(nested, resolved_type = "ResolvedFontSpec")]
664 pub 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)]
676pub struct SplitterTheme {
677 #[serde(rename = "divider_width_px")]
679 #[theme(check = "non_negative")]
680 pub divider_width: Option<f32>,
681 #[theme(inherit_from = "defaults.border.color")]
683 pub divider_color: Option<Rgba>,
684 pub hover_color: Option<Rgba>,
686}
687
688#[serde_with::skip_serializing_none]
692#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
693#[serde(default)]
694pub struct SeparatorTheme {
695 #[theme(inherit_from = "defaults.border.color")]
697 pub line_color: Option<Rgba>,
698 #[serde(rename = "line_width_px")]
700 #[theme(check = "non_negative", inherit_from = "defaults.border.line_width")]
701 pub line_width: Option<f32>,
702}
703
704#[serde_with::skip_serializing_none]
708#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
709#[serde(default)]
710pub struct SwitchTheme {
711 #[theme(inherit_from = "defaults.accent_color")]
713 pub checked_background: Option<Rgba>,
714 pub unchecked_background: Option<Rgba>,
716 #[theme(inherit_from = "defaults.surface_color")]
719 pub thumb_background: Option<Rgba>,
720 #[theme(category = "soft_option")]
725 pub unchecked_thumb_background: Option<Rgba>,
726 #[serde(rename = "track_width_px")]
728 #[theme(check = "non_negative")]
729 pub track_width: Option<f32>,
730 #[serde(rename = "track_height_px")]
732 #[theme(check = "non_negative")]
733 pub track_height: Option<f32>,
734 #[serde(rename = "thumb_diameter_px")]
740 #[theme(check = "non_negative")]
741 pub thumb_diameter: Option<f32>,
742 #[serde(rename = "unchecked_thumb_diameter_px")]
747 #[theme(category = "soft_option", check = "non_negative")]
748 pub unchecked_thumb_diameter: Option<f32>,
749 #[serde(rename = "track_radius_px")]
751 #[theme(check = "non_negative")]
752 pub track_radius: Option<f32>,
753 #[theme(range = "0.0..=1.0", inherit_from = "defaults.disabled_opacity")]
757 pub disabled_opacity: Option<f32>,
758 #[theme(category = "soft_option")]
760 pub hover_checked_background: Option<Rgba>,
761 #[theme(category = "soft_option")]
763 pub hover_unchecked_background: Option<Rgba>,
764 #[theme(category = "soft_option")]
767 pub disabled_checked_background: Option<Rgba>,
768 #[theme(category = "soft_option")]
770 pub disabled_unchecked_background: Option<Rgba>,
771 #[theme(category = "soft_option")]
773 pub disabled_thumb_color: Option<Rgba>,
774 #[theme(category = "soft_option")]
780 pub unchecked_track_border_color: Option<Rgba>,
781 #[theme(category = "soft_option")]
785 pub checked_track_border_color: Option<Rgba>,
786 #[theme(category = "soft_option")]
789 pub disabled_unchecked_track_border_color: Option<Rgba>,
790 #[theme(category = "soft_option")]
792 pub disabled_checked_track_border_color: Option<Rgba>,
793 #[serde(rename = "track_border_line_width_px")]
796 #[theme(category = "soft_option", check = "non_negative")]
797 pub track_border_line_width: Option<f32>,
798 #[theme(category = "soft_option")]
802 pub thumb_border_color: Option<Rgba>,
803 #[serde(rename = "thumb_border_line_width_px")]
805 #[theme(category = "soft_option", check = "non_negative")]
806 pub thumb_border_line_width: Option<f32>,
807}
808
809#[serde_with::skip_serializing_none]
813#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
814#[serde(default)]
815#[theme_inherit(border_kind = "full_lg", font = "title_font")]
816#[theme_inherit(font = "body_font")]
817pub struct DialogTheme {
818 pub background_color: Option<Rgba>,
820 #[serde(rename = "min_width_px")]
822 #[theme(check = "non_negative", min_max_pair = "max_width")]
823 pub min_width: Option<f32>,
824 #[serde(rename = "max_width_px")]
826 #[theme(check = "non_negative")]
827 pub max_width: Option<f32>,
828 #[serde(rename = "min_height_px")]
830 #[theme(check = "non_negative", min_max_pair = "max_height")]
831 pub min_height: Option<f32>,
832 #[serde(rename = "max_height_px")]
834 #[theme(check = "non_negative")]
835 pub max_height: Option<f32>,
836 #[serde(rename = "button_gap_px")]
838 #[theme(check = "non_negative")]
839 pub button_gap: Option<f32>,
840 #[serde(rename = "icon_size_px")]
842 #[theme(check = "non_negative")]
843 pub icon_size: Option<f32>,
844 pub button_order: Option<DialogButtonOrder>,
846 #[theme(category = "soft_option")]
851 pub entrance: Option<DialogEntranceStyle>,
852 #[theme(nested, resolved_type = "ResolvedFontSpec")]
854 pub title_font: Option<FontSpec>,
855 #[theme(nested, resolved_type = "ResolvedFontSpec")]
857 pub body_font: Option<FontSpec>,
858 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
860 pub border: Option<WidgetBorderSpec>,
861}
862
863#[serde_with::skip_serializing_none]
867#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
868#[serde(default)]
869pub struct SpinnerTheme {
870 pub fill_color: Option<Rgba>,
872 #[serde(rename = "diameter_px")]
874 #[theme(check = "non_negative")]
875 pub diameter: Option<f32>,
876 #[serde(rename = "min_diameter_px")]
878 #[theme(check = "non_negative")]
879 pub min_diameter: Option<f32>,
880 #[serde(rename = "stroke_width_px")]
882 #[theme(check = "non_negative")]
883 pub stroke_width: Option<f32>,
884}
885
886#[serde_with::skip_serializing_none]
890#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
891#[serde(default)]
892#[theme_inherit(border_kind = "full", font = "font")]
893pub struct ComboBoxTheme {
894 #[theme(inherit_from = "defaults.background_color")]
896 pub background_color: Option<Rgba>,
897 #[serde(rename = "min_height_px")]
899 #[theme(check = "non_negative")]
900 pub min_height: Option<f32>,
901 #[serde(rename = "min_width_px")]
903 #[theme(check = "non_negative")]
904 pub min_width: Option<f32>,
905 #[serde(rename = "arrow_icon_size_px")]
907 #[theme(check = "non_negative")]
908 pub arrow_icon_size: Option<f32>,
909 #[serde(rename = "arrow_area_width_px")]
915 #[theme(category = "soft_option", check = "non_negative")]
916 pub arrow_area_width: Option<f32>,
917 #[theme(range = "0.0..=1.0", inherit_from = "defaults.disabled_opacity")]
921 pub disabled_opacity: Option<f32>,
922 #[theme(inherit_from = "defaults.disabled_text_color")]
924 pub disabled_text_color: Option<Rgba>,
925 #[theme(category = "soft_option")]
927 pub hover_background: Option<Rgba>,
928 #[theme(category = "soft_option")]
930 pub disabled_background: Option<Rgba>,
931 #[theme(nested, resolved_type = "ResolvedFontSpec")]
933 pub font: Option<FontSpec>,
934 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
936 pub border: Option<WidgetBorderSpec>,
937}
938
939#[serde_with::skip_serializing_none]
943#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
944#[serde(default)]
945#[theme_inherit(border_kind = "full", font = "font")]
946pub struct SegmentedControlTheme {
947 #[theme(inherit_from = "defaults.background_color")]
949 pub background_color: Option<Rgba>,
950 #[theme(inherit_from = "defaults.accent_color")]
952 pub active_background: Option<Rgba>,
953 #[theme(inherit_from = "defaults.accent_text_color")]
955 pub active_text_color: Option<Rgba>,
956 #[serde(rename = "segment_height_px")]
958 #[theme(check = "non_negative")]
959 pub segment_height: Option<f32>,
960 #[serde(rename = "separator_width_px")]
962 #[theme(check = "non_negative")]
963 pub separator_width: Option<f32>,
964 #[theme(range = "0.0..=1.0", inherit_from = "defaults.disabled_opacity")]
968 pub disabled_opacity: Option<f32>,
969 #[theme(category = "soft_option")]
971 pub hover_background: Option<Rgba>,
972 #[theme(nested, resolved_type = "ResolvedFontSpec")]
974 pub font: Option<FontSpec>,
975 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
977 pub border: Option<WidgetBorderSpec>,
978}
979
980#[serde_with::skip_serializing_none]
984#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
985#[serde(default)]
986#[theme_layer(border_kind = "none")]
987pub struct CardTheme {
988 #[theme(inherit_from = "defaults.surface_color")]
990 pub background_color: Option<Rgba>,
991 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
993 pub border: Option<WidgetBorderSpec>,
994}
995
996#[serde_with::skip_serializing_none]
1000#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
1001#[serde(default)]
1002#[theme_inherit(border_kind = "full", font = "font")]
1003pub struct ExpanderTheme {
1004 #[serde(rename = "header_height_px")]
1006 #[theme(check = "non_negative")]
1007 pub header_height: Option<f32>,
1008 #[serde(rename = "arrow_icon_size_px")]
1010 #[theme(check = "non_negative")]
1011 pub arrow_icon_size: Option<f32>,
1012 #[theme(category = "soft_option")]
1014 pub hover_background: Option<Rgba>,
1015 #[theme(category = "soft_option")]
1017 pub arrow_color: Option<Rgba>,
1018 #[theme(category = "soft_option")]
1022 pub arrow_side: Option<ArrowSide>,
1023 #[serde(rename = "arrow_gap_px")]
1028 #[theme(category = "soft_option", check = "non_negative")]
1029 pub arrow_gap: Option<f32>,
1030 #[serde(rename = "content_indent_px")]
1035 #[theme(category = "soft_option", check = "non_negative")]
1036 pub content_indent: Option<f32>,
1037 #[theme(category = "soft_option")]
1042 pub frame_enabled: Option<bool>,
1043 #[theme(nested, resolved_type = "ResolvedFontSpec")]
1045 pub font: Option<FontSpec>,
1046 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
1048 pub border: Option<WidgetBorderSpec>,
1049}
1050
1051#[serde_with::skip_serializing_none]
1055#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
1056#[serde(default)]
1057#[theme_inherit(font = "font")]
1058pub struct LinkTheme {
1059 #[theme(inherit_from = "defaults.link_color")]
1061 pub visited_text_color: Option<Rgba>,
1062 pub underline_enabled: Option<bool>,
1064 pub background_color: Option<Rgba>,
1066 pub hover_background: Option<Rgba>,
1068 pub hover_text_color: Option<Rgba>,
1070 pub active_text_color: Option<Rgba>,
1072 #[theme(inherit_from = "defaults.disabled_text_color")]
1074 pub disabled_text_color: Option<Rgba>,
1075 #[theme(nested, resolved_type = "ResolvedFontSpec")]
1077 pub font: Option<FontSpec>,
1078}
1079
1080#[serde_with::skip_serializing_none]
1091#[derive(
1092 Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget, ThemeFields,
1093)]
1094#[serde(default)]
1095#[theme_layer(skip_inventory)]
1096pub struct LayoutTheme {
1097 #[serde(rename = "widget_gap_px")]
1099 #[theme(check = "non_negative")]
1100 pub widget_gap: Option<f32>,
1101 #[serde(rename = "container_margin_px")]
1103 #[theme(check = "non_negative")]
1104 pub container_margin: Option<f32>,
1105 #[serde(rename = "window_margin_px")]
1107 #[theme(check = "non_negative")]
1108 pub window_margin: Option<f32>,
1109 #[serde(rename = "section_gap_px")]
1111 #[theme(check = "non_negative")]
1112 pub section_gap: Option<f32>,
1113}
1114
1115#[cfg(test)]
1116#[allow(clippy::unwrap_used, clippy::expect_used, dead_code)]
1117mod tests {
1118 use super::*;
1119 use crate::Rgba;
1120 use crate::model::border::{ResolvedWidgetBorder, WidgetBorderSpec};
1121 use crate::model::font::FontSize;
1122 use crate::model::{DialogButtonOrder, FontSpec};
1123
1124 #[serde_with::skip_serializing_none]
1127 #[derive(
1128 Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget,
1129 )]
1130 #[serde(default)]
1131 #[theme_layer(skip_inventory)]
1132 pub struct TestWidget {
1133 pub size: Option<f32>,
1134 pub label: Option<String>,
1135 #[theme(nested, resolved_type = "ResolvedFontSpec")]
1136 pub font: Option<FontSpec>,
1137 }
1138
1139 #[test]
1142 fn resolved_font_spec_fields_are_concrete() {
1143 let rfs = ResolvedFontSpec {
1144 family: "Inter".into(),
1145 size: 14.0,
1146 defined_size: Some(crate::model::font::FontSize::Px(14.0)),
1147 weight: 400,
1148 style: crate::model::font::FontStyle::Normal,
1149 color: crate::Rgba::rgb(0, 0, 0),
1150 };
1151 assert_eq!(rfs.family.as_ref(), "Inter");
1152 assert_eq!(rfs.size, 14.0);
1153 assert_eq!(rfs.weight, 400);
1154 }
1155
1156 #[test]
1159 fn generated_option_struct_has_option_fields() {
1160 let w = TestWidget::default();
1161 assert!(w.size.is_none());
1162 assert!(w.label.is_none());
1163 assert!(w.font.is_none());
1164 }
1165
1166 #[test]
1167 fn generated_option_struct_is_empty_by_default() {
1168 assert!(TestWidget::default().is_empty());
1169 }
1170
1171 #[test]
1172 fn generated_option_struct_not_empty_when_size_set() {
1173 let w = TestWidget {
1174 size: Some(24.0),
1175 ..Default::default()
1176 };
1177 assert!(!w.is_empty());
1178 }
1179
1180 #[test]
1181 fn generated_option_struct_not_empty_when_font_set() {
1182 let w = TestWidget {
1183 font: Some(FontSpec {
1184 size: Some(FontSize::Px(14.0)),
1185 ..Default::default()
1186 }),
1187 ..Default::default()
1188 };
1189 assert!(!w.is_empty());
1190 }
1191
1192 #[test]
1193 fn generated_resolved_struct_has_concrete_fields() {
1194 let resolved = ResolvedTestWidget {
1195 size: 24.0,
1196 label: "Click me".into(),
1197 font: ResolvedFontSpec {
1198 family: "Inter".into(),
1199 size: 14.0,
1200 defined_size: Some(crate::model::font::FontSize::Px(14.0)),
1201 weight: 400,
1202 style: crate::model::font::FontStyle::Normal,
1203 color: crate::Rgba::rgb(0, 0, 0),
1204 },
1205 };
1206 assert_eq!(resolved.size, 24.0);
1207 assert_eq!(resolved.label, "Click me");
1208 assert_eq!(resolved.font.family.as_ref(), "Inter");
1209 }
1210
1211 #[test]
1214 fn generated_merge_option_field_overlay_wins() {
1215 let mut base = TestWidget {
1216 size: Some(20.0),
1217 ..Default::default()
1218 };
1219 let overlay = TestWidget {
1220 size: Some(24.0),
1221 ..Default::default()
1222 };
1223 base.merge(&overlay);
1224 assert_eq!(base.size, Some(24.0));
1225 }
1226
1227 #[test]
1228 fn generated_merge_option_field_none_preserves_base() {
1229 let mut base = TestWidget {
1230 size: Some(20.0),
1231 ..Default::default()
1232 };
1233 let overlay = TestWidget::default();
1234 base.merge(&overlay);
1235 assert_eq!(base.size, Some(20.0));
1236 }
1237
1238 #[test]
1239 fn generated_merge_optional_nested_both_some_merges_inner() {
1240 let mut base = TestWidget {
1241 font: Some(FontSpec {
1242 family: Some("Noto Sans".into()),
1243 size: Some(FontSize::Px(12.0)),
1244 weight: None,
1245 ..Default::default()
1246 }),
1247 ..Default::default()
1248 };
1249 let overlay = TestWidget {
1250 font: Some(FontSpec {
1251 family: None,
1252 size: None,
1253 weight: Some(700),
1254 ..Default::default()
1255 }),
1256 ..Default::default()
1257 };
1258 base.merge(&overlay);
1259 let font = base.font.as_ref().unwrap();
1260 assert_eq!(font.family.as_deref(), Some("Noto Sans")); assert_eq!(font.size, Some(FontSize::Px(12.0))); assert_eq!(font.weight, Some(700)); }
1264
1265 #[test]
1266 fn generated_merge_optional_nested_none_plus_some_clones() {
1267 let mut base = TestWidget::default();
1268 let overlay = TestWidget {
1269 font: Some(FontSpec {
1270 family: Some("Inter".into()),
1271 size: Some(FontSize::Px(14.0)),
1272 weight: Some(400),
1273 ..Default::default()
1274 }),
1275 ..Default::default()
1276 };
1277 base.merge(&overlay);
1278 let font = base.font.as_ref().unwrap();
1279 assert_eq!(font.family.as_deref(), Some("Inter"));
1280 assert_eq!(font.size, Some(FontSize::Px(14.0)));
1281 assert_eq!(font.weight, Some(400));
1282 }
1283
1284 #[test]
1285 fn generated_merge_optional_nested_some_plus_none_preserves_base() {
1286 let mut base = 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 let overlay = TestWidget::default();
1296 base.merge(&overlay);
1297 let font = base.font.as_ref().unwrap();
1298 assert_eq!(font.family.as_deref(), Some("Inter"));
1299 }
1300
1301 #[test]
1302 fn generated_merge_optional_nested_none_plus_none_stays_none() {
1303 let mut base = TestWidget::default();
1304 let overlay = TestWidget::default();
1305 base.merge(&overlay);
1306 assert!(base.font.is_none());
1307 }
1308
1309 #[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize)]
1313 struct WithFont {
1314 name: Option<String>,
1315 font: Option<FontSpec>,
1316 }
1317
1318 impl_merge!(WithFont {
1319 option { name }
1320 optional_nested { font }
1321 });
1322
1323 #[test]
1324 fn impl_merge_optional_nested_none_none_stays_none() {
1325 let mut base = WithFont::default();
1326 let overlay = WithFont::default();
1327 base.merge(&overlay);
1328 assert!(base.font.is_none());
1329 }
1330
1331 #[test]
1332 fn impl_merge_optional_nested_some_none_preserves_base() {
1333 let mut base = WithFont {
1334 font: Some(FontSpec {
1335 size: Some(FontSize::Px(12.0)),
1336 ..Default::default()
1337 }),
1338 ..Default::default()
1339 };
1340 let overlay = WithFont::default();
1341 base.merge(&overlay);
1342 assert_eq!(base.font.as_ref().unwrap().size, Some(FontSize::Px(12.0)));
1343 }
1344
1345 #[test]
1346 fn impl_merge_optional_nested_none_some_clones_overlay() {
1347 let mut base = WithFont::default();
1348 let overlay = WithFont {
1349 font: Some(FontSpec {
1350 family: Some("Inter".into()),
1351 ..Default::default()
1352 }),
1353 ..Default::default()
1354 };
1355 base.merge(&overlay);
1356 assert_eq!(base.font.as_ref().unwrap().family.as_deref(), Some("Inter"));
1357 }
1358
1359 #[test]
1360 fn impl_merge_optional_nested_some_some_merges_inner() {
1361 let mut base = WithFont {
1362 font: Some(FontSpec {
1363 family: Some("Noto".into()),
1364 size: Some(FontSize::Px(11.0)),
1365 weight: None,
1366 ..Default::default()
1367 }),
1368 ..Default::default()
1369 };
1370 let overlay = WithFont {
1371 font: Some(FontSpec {
1372 family: None,
1373 size: Some(FontSize::Px(14.0)),
1374 weight: Some(400),
1375 ..Default::default()
1376 }),
1377 ..Default::default()
1378 };
1379 base.merge(&overlay);
1380 let f = base.font.as_ref().unwrap();
1381 assert_eq!(f.family.as_deref(), Some("Noto")); assert_eq!(f.size, Some(FontSize::Px(14.0))); assert_eq!(f.weight, Some(400)); }
1385
1386 #[test]
1387 fn impl_merge_optional_nested_is_empty_none() {
1388 let w = WithFont::default();
1389 assert!(w.is_empty());
1390 }
1391
1392 #[test]
1393 fn impl_merge_optional_nested_is_empty_some_default() {
1394 let w = WithFont {
1396 font: Some(FontSpec::default()),
1397 ..Default::default()
1398 };
1399 assert!(w.is_empty());
1400 }
1401
1402 #[test]
1403 fn impl_merge_optional_nested_is_not_empty_when_populated() {
1404 let w = WithFont {
1405 font: Some(FontSpec {
1406 size: Some(FontSize::Px(14.0)),
1407 ..Default::default()
1408 }),
1409 ..Default::default()
1410 };
1411 assert!(!w.is_empty());
1412 }
1413
1414 #[test]
1417 fn button_theme_default_is_empty() {
1418 assert!(ButtonTheme::default().is_empty());
1419 }
1420
1421 #[test]
1422 fn button_theme_not_empty_when_set() {
1423 let b = ButtonTheme {
1424 background_color: Some(Rgba::rgb(200, 200, 200)),
1425 min_width: Some(64.0),
1426 ..Default::default()
1427 };
1428 assert!(!b.is_empty());
1429 }
1430
1431 #[test]
1432 fn button_theme_merge_font_optional_nested() {
1433 let mut base = ButtonTheme {
1434 font: Some(FontSpec {
1435 family: Some("Noto Sans".into()),
1436 size: Some(FontSize::Px(11.0)),
1437 weight: None,
1438 ..Default::default()
1439 }),
1440 ..Default::default()
1441 };
1442 let overlay = ButtonTheme {
1443 font: Some(FontSpec {
1444 family: None,
1445 weight: Some(700),
1446 ..Default::default()
1447 }),
1448 ..Default::default()
1449 };
1450 base.merge(&overlay);
1451 let f = base.font.as_ref().unwrap();
1452 assert_eq!(f.family.as_deref(), Some("Noto Sans")); assert_eq!(f.weight, Some(700)); }
1455
1456 #[test]
1457 fn button_theme_toml_round_trip_with_font_and_border() {
1458 let b = ButtonTheme {
1459 background_color: Some(Rgba::rgb(200, 200, 200)),
1460 font: Some(FontSpec {
1461 family: Some("Inter".into()),
1462 size: Some(FontSize::Px(14.0)),
1463 weight: Some(400),
1464 ..Default::default()
1465 }),
1466 border: Some(WidgetBorderSpec {
1467 corner_radius: Some(4.0),
1468 ..Default::default()
1469 }),
1470 ..Default::default()
1471 };
1472 let toml_str = toml::to_string(&b).unwrap();
1473 let b2: ButtonTheme = toml::from_str(&toml_str).unwrap();
1474 assert_eq!(b, b2);
1475 }
1476
1477 #[test]
1480 fn window_theme_has_new_fields() {
1481 let w = WindowTheme {
1482 inactive_title_bar_background: Some(Rgba::rgb(180, 180, 180)),
1483 inactive_title_bar_text_color: Some(Rgba::rgb(120, 120, 120)),
1484 title_bar_font: Some(FontSpec {
1485 weight: Some(700),
1486 ..Default::default()
1487 }),
1488 border: Some(WidgetBorderSpec {
1489 corner_radius: Some(4.0),
1490 shadow_enabled: Some(true),
1491 ..Default::default()
1492 }),
1493 ..Default::default()
1494 };
1495 assert!(!w.is_empty());
1496 assert!(w.inactive_title_bar_background.is_some());
1497 assert!(w.inactive_title_bar_text_color.is_some());
1498 assert!(w.title_bar_font.is_some());
1499 assert!(w.border.is_some());
1500 }
1501
1502 #[test]
1503 fn window_theme_default_is_empty() {
1504 assert!(WindowTheme::default().is_empty());
1505 }
1506
1507 #[test]
1510 fn dialog_theme_button_order_works() {
1511 let d = DialogTheme {
1512 button_order: Some(DialogButtonOrder::PrimaryRight),
1513 min_width: Some(300.0),
1514 ..Default::default()
1515 };
1516 assert_eq!(d.button_order, Some(DialogButtonOrder::PrimaryRight));
1517 assert_eq!(d.min_width, Some(300.0));
1518 assert!(!d.is_empty());
1519 }
1520
1521 #[test]
1522 fn dialog_theme_button_order_toml_round_trip() {
1523 let d = DialogTheme {
1524 button_order: Some(DialogButtonOrder::PrimaryLeft),
1525 ..Default::default()
1526 };
1527 let toml_str = toml::to_string(&d).unwrap();
1528 let d2: DialogTheme = toml::from_str(&toml_str).unwrap();
1529 assert_eq!(d, d2);
1530 }
1531
1532 #[test]
1533 fn dialog_theme_default_is_empty() {
1534 assert!(DialogTheme::default().is_empty());
1535 }
1536
1537 #[test]
1540 fn splitter_theme_single_field_merge() {
1541 let mut base = SplitterTheme {
1542 divider_width: Some(4.0),
1543 ..Default::default()
1544 };
1545 let overlay = SplitterTheme {
1546 divider_width: Some(6.0),
1547 ..Default::default()
1548 };
1549 base.merge(&overlay);
1550 assert_eq!(base.divider_width, Some(6.0));
1551 }
1552
1553 #[test]
1554 fn splitter_theme_merge_none_preserves_base() {
1555 let mut base = SplitterTheme {
1556 divider_width: Some(4.0),
1557 ..Default::default()
1558 };
1559 let overlay = SplitterTheme::default();
1560 base.merge(&overlay);
1561 assert_eq!(base.divider_width, Some(4.0));
1562 }
1563
1564 #[test]
1565 fn splitter_theme_default_is_empty() {
1566 assert!(SplitterTheme::default().is_empty());
1567 }
1568
1569 #[test]
1570 fn splitter_theme_not_empty_when_set() {
1571 assert!(
1572 !SplitterTheme {
1573 divider_width: Some(4.0),
1574 ..Default::default()
1575 }
1576 .is_empty()
1577 );
1578 }
1579
1580 #[test]
1583 fn separator_theme_single_field() {
1584 let s = SeparatorTheme {
1585 line_color: Some(Rgba::rgb(200, 200, 200)),
1586 ..Default::default()
1587 };
1588 assert!(!s.is_empty());
1589 }
1590
1591 #[test]
1594 fn all_widget_theme_defaults_are_empty() {
1595 assert!(WindowTheme::default().is_empty());
1596 assert!(ButtonTheme::default().is_empty());
1597 assert!(InputTheme::default().is_empty());
1598 assert!(CheckboxTheme::default().is_empty());
1599 assert!(MenuTheme::default().is_empty());
1600 assert!(TooltipTheme::default().is_empty());
1601 assert!(ScrollbarTheme::default().is_empty());
1602 assert!(SliderTheme::default().is_empty());
1603 assert!(ProgressBarTheme::default().is_empty());
1604 assert!(TabTheme::default().is_empty());
1605 assert!(SidebarTheme::default().is_empty());
1606 assert!(ToolbarTheme::default().is_empty());
1607 assert!(StatusBarTheme::default().is_empty());
1608 assert!(ListTheme::default().is_empty());
1609 assert!(PopoverTheme::default().is_empty());
1610 assert!(SplitterTheme::default().is_empty());
1611 assert!(SeparatorTheme::default().is_empty());
1612 assert!(SwitchTheme::default().is_empty());
1613 assert!(DialogTheme::default().is_empty());
1614 assert!(SpinnerTheme::default().is_empty());
1615 assert!(ComboBoxTheme::default().is_empty());
1616 assert!(SegmentedControlTheme::default().is_empty());
1617 assert!(CardTheme::default().is_empty());
1618 assert!(ExpanderTheme::default().is_empty());
1619 assert!(LinkTheme::default().is_empty());
1620 }
1621
1622 #[test]
1625 fn input_theme_toml_round_trip() {
1626 let t = InputTheme {
1627 background_color: Some(Rgba::rgb(255, 255, 255)),
1628 font: Some(FontSpec {
1629 family: Some("Noto Sans".into()),
1630 ..Default::default()
1631 }),
1632 border: Some(WidgetBorderSpec {
1633 color: Some(Rgba::rgb(180, 180, 180)),
1634 corner_radius: Some(4.0),
1635 ..Default::default()
1636 }),
1637 ..Default::default()
1638 };
1639 let toml_str = toml::to_string(&t).unwrap();
1640 let t2: InputTheme = toml::from_str(&toml_str).unwrap();
1641 assert_eq!(t, t2);
1642 }
1643
1644 #[test]
1645 fn switch_theme_toml_round_trip() {
1646 let s = SwitchTheme {
1647 checked_background: Some(Rgba::rgb(0, 120, 215)),
1648 track_width: Some(40.0),
1649 track_height: Some(20.0),
1650 thumb_diameter: Some(14.0),
1651 track_radius: Some(10.0),
1652 ..Default::default()
1653 };
1654 let toml_str = toml::to_string(&s).unwrap();
1655 let s2: SwitchTheme = toml::from_str(&toml_str).unwrap();
1656 assert_eq!(s, s2);
1657 }
1658
1659 #[test]
1660 fn card_theme_with_border() {
1661 let c = CardTheme {
1662 background_color: Some(Rgba::rgb(255, 255, 255)),
1663 border: Some(WidgetBorderSpec {
1664 corner_radius: Some(8.0),
1665 shadow_enabled: Some(true),
1666 ..Default::default()
1667 }),
1668 };
1669 assert!(!c.is_empty());
1670 }
1671
1672 #[test]
1673 fn link_theme_has_underline_enabled_bool_field() {
1674 let l = LinkTheme {
1675 visited_text_color: Some(Rgba::rgb(100, 0, 200)),
1676 underline_enabled: Some(true),
1677 ..Default::default()
1678 };
1679 assert!(!l.is_empty());
1680 assert_eq!(l.underline_enabled, Some(true));
1681 }
1682
1683 #[test]
1684 fn status_bar_theme_has_font_and_background() {
1685 let s = StatusBarTheme {
1686 background_color: Some(Rgba::rgb(240, 240, 240)),
1687 font: Some(FontSpec {
1688 size: Some(FontSize::Px(11.0)),
1689 ..Default::default()
1690 }),
1691 ..Default::default()
1692 };
1693 assert!(!s.is_empty());
1694 }
1695
1696 #[serde_with::skip_serializing_none]
1701 #[derive(
1702 Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget,
1703 )]
1704 #[serde(default)]
1705 #[theme_layer(skip_inventory)]
1706 pub struct DualNestedTestWidget {
1707 pub background: Option<Rgba>,
1708 pub min_height: Option<f32>,
1709 #[theme(nested, resolved_type = "ResolvedFontSpec")]
1710 pub font: Option<FontSpec>,
1711 #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
1712 pub border: Option<WidgetBorderSpec>,
1713 }
1714
1715 #[test]
1716 fn dual_nested_default_is_empty() {
1717 assert!(DualNestedTestWidget::default().is_empty());
1718 }
1719
1720 #[test]
1721 fn dual_nested_field_names() {
1722 assert_eq!(DualNestedTestWidget::FIELD_NAMES.len(), 4);
1723 assert!(DualNestedTestWidget::FIELD_NAMES.contains(&"background"));
1724 assert!(DualNestedTestWidget::FIELD_NAMES.contains(&"min_height"));
1725 assert!(DualNestedTestWidget::FIELD_NAMES.contains(&"font"));
1726 assert!(DualNestedTestWidget::FIELD_NAMES.contains(&"border"));
1727 }
1728
1729 #[test]
1730 fn dual_nested_not_empty_when_font_set() {
1731 let w = DualNestedTestWidget {
1732 font: Some(FontSpec {
1733 family: Some("Inter".into()),
1734 ..Default::default()
1735 }),
1736 ..Default::default()
1737 };
1738 assert!(!w.is_empty());
1739 }
1740
1741 #[test]
1742 fn dual_nested_not_empty_when_border_set() {
1743 let w = DualNestedTestWidget {
1744 border: Some(WidgetBorderSpec {
1745 color: Some(Rgba::rgb(100, 100, 100)),
1746 ..Default::default()
1747 }),
1748 ..Default::default()
1749 };
1750 assert!(!w.is_empty());
1751 }
1752
1753 #[test]
1754 fn dual_nested_merge_both_nested() {
1755 let mut base = DualNestedTestWidget {
1756 font: Some(FontSpec {
1757 family: Some("Noto Sans".into()),
1758 ..Default::default()
1759 }),
1760 ..Default::default()
1761 };
1762 let overlay = DualNestedTestWidget {
1763 border: Some(WidgetBorderSpec {
1764 corner_radius: Some(4.0),
1765 ..Default::default()
1766 }),
1767 ..Default::default()
1768 };
1769 base.merge(&overlay);
1770 assert!(base.font.is_some());
1771 assert!(base.border.is_some());
1772 assert_eq!(
1773 base.font.as_ref().and_then(|f| f.family.as_deref()),
1774 Some("Noto Sans")
1775 );
1776 assert_eq!(
1777 base.border.as_ref().and_then(|b| b.corner_radius),
1778 Some(4.0)
1779 );
1780 }
1781
1782 #[test]
1783 fn dual_nested_merge_inner_font_fields() {
1784 let mut base = DualNestedTestWidget {
1785 font: Some(FontSpec {
1786 family: Some("Noto Sans".into()),
1787 ..Default::default()
1788 }),
1789 ..Default::default()
1790 };
1791 let overlay = DualNestedTestWidget {
1792 font: Some(FontSpec {
1793 size: Some(FontSize::Px(14.0)),
1794 ..Default::default()
1795 }),
1796 ..Default::default()
1797 };
1798 base.merge(&overlay);
1799 let font = base.font.as_ref().unwrap();
1800 assert_eq!(font.family.as_deref(), Some("Noto Sans")); assert_eq!(font.size, Some(FontSize::Px(14.0))); }
1803
1804 #[test]
1805 fn dual_nested_toml_round_trip() {
1806 let w = DualNestedTestWidget {
1807 background: Some(Rgba::rgb(240, 240, 240)),
1808 min_height: Some(32.0),
1809 font: Some(FontSpec {
1810 family: Some("Inter".into()),
1811 size: Some(FontSize::Px(14.0)),
1812 weight: Some(400),
1813 ..Default::default()
1814 }),
1815 border: Some(WidgetBorderSpec {
1816 color: Some(Rgba::rgb(180, 180, 180)),
1817 corner_radius: Some(4.0),
1818 line_width: Some(1.0),
1819 ..Default::default()
1820 }),
1821 };
1822 let toml_str = toml::to_string(&w).unwrap();
1823 let w2: DualNestedTestWidget = toml::from_str(&toml_str).unwrap();
1824 assert_eq!(w, w2);
1825 }
1826
1827 #[test]
1832 fn button_validate_widget_extracts_all_fields() {
1833 let button = ButtonTheme {
1834 background_color: Some(Rgba::rgb(200, 200, 200)),
1835 primary_background: Some(Rgba::rgb(0, 120, 215)),
1836 primary_text_color: Some(Rgba::rgb(255, 255, 255)),
1837 min_width: Some(80.0),
1838 min_height: Some(32.0),
1839 icon_text_gap: Some(8.0),
1840 disabled_opacity: Some(0.4),
1841 hover_background: Some(Rgba::rgb(210, 210, 210)),
1842 hover_text_color: Some(Rgba::rgb(0, 0, 0)),
1843 active_text_color: Some(Rgba::rgb(0, 0, 0)),
1844 disabled_text_color: Some(Rgba::rgb(128, 128, 128)),
1845 active_background: Some(Rgba::rgb(180, 180, 180)),
1846 disabled_background: Some(Rgba::rgb(220, 220, 220)),
1847 checked_background: Some(Rgba::rgb(190, 190, 190)),
1848 checked_text_color: None,
1849 font: Some(FontSpec {
1850 family: Some("Inter".into()),
1851 size: Some(FontSize::Px(14.0)),
1852 weight: Some(400),
1853 style: Some(crate::model::font::FontStyle::Normal),
1854 color: Some(Rgba::rgb(0, 0, 0)),
1855 }),
1856 border: Some(WidgetBorderSpec {
1857 color: Some(Rgba::rgb(100, 100, 100)),
1858 corner_radius: Some(4.0),
1859 line_width: Some(1.0),
1860 shadow_enabled: Some(false),
1861 padding_top: Some(6.0),
1862 padding_right: Some(12.0),
1863 padding_bottom: Some(6.0),
1864 padding_left: Some(12.0),
1865 }),
1866 };
1867 let mut missing = Vec::new();
1868 let resolved = ResolvedButtonTheme::validate_widget(&button, "button", 96.0, &mut missing);
1869 assert!(missing.is_empty(), "unexpected missing: {missing:?}");
1870 assert_eq!(resolved.background_color, Rgba::rgb(200, 200, 200));
1871 assert_eq!(resolved.min_width, 80.0);
1872 assert_eq!(resolved.font.family.as_ref(), "Inter");
1873 assert_eq!(resolved.font.size, 14.0);
1874 assert_eq!(resolved.border.corner_radius, 4.0);
1875 assert_eq!(resolved.active_background, Some(Rgba::rgb(180, 180, 180)));
1877 assert_eq!(resolved.disabled_background, Some(Rgba::rgb(220, 220, 220)));
1878 assert_eq!(resolved.checked_background, Some(Rgba::rgb(190, 190, 190)));
1879 assert_eq!(resolved.checked_text_color, None);
1880 }
1881
1882 #[test]
1883 fn button_validate_widget_records_missing_fields() {
1884 let button = ButtonTheme::default(); let mut missing = Vec::new();
1886 let _ = ResolvedButtonTheme::validate_widget(&button, "button", 96.0, &mut missing);
1887 assert!(missing.contains(&"button.background_color".to_string()));
1889 assert!(missing.contains(&"button.min_width_px".to_string()));
1890 assert!(missing.contains(&"button.font".to_string()));
1892 assert!(missing.contains(&"button.border".to_string()));
1894 assert!(!missing.iter().any(|m| m.contains("active_background")));
1896 assert!(!missing.iter().any(|m| m.contains("disabled_background")));
1897 }
1898
1899 #[test]
1902 fn layout_theme_default_is_empty() {
1903 assert!(LayoutTheme::default().is_empty());
1904 }
1905
1906 #[test]
1907 fn layout_theme_not_empty_when_widget_gap_set() {
1908 let l = LayoutTheme {
1909 widget_gap: Some(8.0),
1910 ..Default::default()
1911 };
1912 assert!(!l.is_empty());
1913 }
1914
1915 #[test]
1916 fn layout_theme_field_names() {
1917 assert_eq!(LayoutTheme::FIELD_NAMES.len(), 4);
1918 assert!(LayoutTheme::FIELD_NAMES.contains(&"widget_gap_px"));
1919 assert!(LayoutTheme::FIELD_NAMES.contains(&"container_margin_px"));
1920 assert!(LayoutTheme::FIELD_NAMES.contains(&"window_margin_px"));
1921 assert!(LayoutTheme::FIELD_NAMES.contains(&"section_gap_px"));
1922 }
1923
1924 #[test]
1925 fn layout_theme_toml_round_trip() {
1926 let l = LayoutTheme {
1927 widget_gap: Some(8.0),
1928 container_margin: Some(12.0),
1929 window_margin: Some(16.0),
1930 section_gap: Some(24.0),
1931 };
1932 let toml_str = toml::to_string(&l).unwrap();
1933 let l2: LayoutTheme = toml::from_str(&toml_str).unwrap();
1934 assert_eq!(l, l2);
1935 }
1936
1937 #[test]
1938 fn layout_theme_merge() {
1939 let mut base = LayoutTheme {
1940 widget_gap: Some(6.0),
1941 container_margin: Some(10.0),
1942 ..Default::default()
1943 };
1944 let overlay = LayoutTheme {
1945 widget_gap: Some(8.0),
1946 section_gap: Some(24.0),
1947 ..Default::default()
1948 };
1949 base.merge(&overlay);
1950 assert_eq!(base.widget_gap, Some(8.0));
1952 assert_eq!(base.container_margin, Some(10.0));
1954 assert_eq!(base.section_gap, Some(24.0));
1956 assert!(base.window_margin.is_none());
1958 }
1959}