1use crate::Rgba;
4use crate::model::border::{ResolvedBorderSpec, WidgetBorderSpec};
5use crate::model::{DialogButtonOrder, FontSpec, ResolvedFontSpec};
6use native_theme_derive::{ThemeFields, ThemeWidget};
7
8#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
12#[serde_with::skip_serializing_none]
13#[serde(default)]
14#[theme_inherit(border_kind = "full_lg", font = "title_bar_font")]
15pub struct WindowTheme {
16 #[theme(inherit_from = "defaults.background_color")]
18 pub background_color: Option<Rgba>,
19 #[theme(inherit_from = "defaults.surface_color")]
21 pub title_bar_background: Option<Rgba>,
22 pub inactive_title_bar_background: Option<Rgba>,
24 pub inactive_title_bar_text_color: Option<Rgba>,
26 #[theme(nested, resolved_type = "ResolvedFontSpec")]
28 pub title_bar_font: Option<FontSpec>,
29 #[theme(nested, resolved_type = "ResolvedBorderSpec")]
31 pub border: Option<WidgetBorderSpec>,
32}
33
34#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
38#[serde_with::skip_serializing_none]
39#[serde(default)]
40#[theme_inherit(border_kind = "full", font = "font")]
41pub struct ButtonTheme {
42 #[theme(inherit_from = "defaults.background_color")]
44 pub background_color: Option<Rgba>,
45 #[theme(inherit_from = "defaults.accent_color")]
47 pub primary_background: Option<Rgba>,
48 #[theme(inherit_from = "defaults.accent_text_color")]
50 pub primary_text_color: Option<Rgba>,
51 #[serde(rename = "min_width_px")]
53 #[theme(check = "non_negative")]
54 pub min_width: Option<f32>,
55 #[serde(rename = "min_height_px")]
57 #[theme(check = "non_negative")]
58 pub min_height: Option<f32>,
59 #[serde(rename = "icon_text_gap_px")]
61 #[theme(check = "non_negative")]
62 pub icon_text_gap: Option<f32>,
63 #[theme(range = "0.0..=1.0", inherit_from = "defaults.disabled_opacity")]
65 pub disabled_opacity: Option<f32>,
66 #[theme(inherit_from = "defaults.background_color")]
68 pub hover_background: Option<Rgba>,
69 pub hover_text_color: Option<Rgba>,
71 pub active_text_color: Option<Rgba>,
73 #[theme(inherit_from = "defaults.disabled_text_color")]
75 pub disabled_text_color: Option<Rgba>,
76 #[theme(category = "soft_option")]
78 pub active_background: Option<Rgba>,
79 #[theme(category = "soft_option")]
81 pub disabled_background: Option<Rgba>,
82 #[theme(nested, resolved_type = "ResolvedFontSpec")]
84 pub font: Option<FontSpec>,
85 #[theme(nested, resolved_type = "ResolvedBorderSpec")]
87 pub border: Option<WidgetBorderSpec>,
88}
89
90#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
94#[serde_with::skip_serializing_none]
95#[serde(default)]
96#[theme_inherit(border_kind = "full", font = "font")]
97pub struct InputTheme {
98 #[theme(inherit_from = "defaults.background_color")]
100 pub background_color: Option<Rgba>,
101 #[theme(inherit_from = "defaults.muted_color")]
103 pub placeholder_color: Option<Rgba>,
104 pub caret_color: Option<Rgba>,
106 #[theme(inherit_from = "defaults.text_selection_background")]
108 pub selection_background: Option<Rgba>,
109 #[theme(inherit_from = "defaults.text_selection_color")]
111 pub selection_text_color: Option<Rgba>,
112 #[serde(rename = "min_height_px")]
114 #[theme(check = "non_negative")]
115 pub min_height: Option<f32>,
116 #[theme(range = "0.0..=1.0", inherit_from = "defaults.disabled_opacity")]
118 pub disabled_opacity: Option<f32>,
119 #[theme(inherit_from = "defaults.disabled_text_color")]
121 pub disabled_text_color: Option<Rgba>,
122 #[theme(category = "soft_option")]
124 pub hover_border_color: Option<Rgba>,
125 #[theme(category = "soft_option")]
127 pub focus_border_color: Option<Rgba>,
128 #[theme(category = "soft_option")]
130 pub disabled_background: Option<Rgba>,
131 #[theme(nested, resolved_type = "ResolvedFontSpec")]
133 pub font: Option<FontSpec>,
134 #[theme(nested, resolved_type = "ResolvedBorderSpec")]
136 pub border: Option<WidgetBorderSpec>,
137}
138
139#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
143#[serde_with::skip_serializing_none]
144#[serde(default)]
145#[theme_inherit(border_kind = "full", font = "font")]
146pub struct CheckboxTheme {
147 #[theme(inherit_from = "defaults.background_color")]
149 pub background_color: Option<Rgba>,
150 #[theme(inherit_from = "defaults.accent_color")]
152 pub checked_background: Option<Rgba>,
153 #[theme(inherit_from = "defaults.text_color")]
155 pub indicator_color: Option<Rgba>,
156 #[serde(rename = "indicator_width_px")]
158 #[theme(check = "non_negative")]
159 pub indicator_width: Option<f32>,
160 #[serde(rename = "label_gap_px")]
162 #[theme(check = "non_negative")]
163 pub label_gap: Option<f32>,
164 #[theme(range = "0.0..=1.0", inherit_from = "defaults.disabled_opacity")]
166 pub disabled_opacity: Option<f32>,
167 #[theme(inherit_from = "defaults.disabled_text_color")]
169 pub disabled_text_color: Option<Rgba>,
170 #[theme(category = "soft_option")]
172 pub hover_background: Option<Rgba>,
173 #[theme(category = "soft_option")]
175 pub disabled_background: Option<Rgba>,
176 #[theme(category = "soft_option")]
178 pub unchecked_background: Option<Rgba>,
179 #[theme(category = "soft_option")]
181 pub unchecked_border_color: Option<Rgba>,
182 #[theme(nested, resolved_type = "ResolvedFontSpec")]
184 pub font: Option<FontSpec>,
185 #[theme(nested, resolved_type = "ResolvedBorderSpec")]
187 pub border: Option<WidgetBorderSpec>,
188}
189
190#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
194#[serde_with::skip_serializing_none]
195#[serde(default)]
196#[theme_layer(border_kind = "none")]
197#[theme_inherit(font = "font")]
198pub struct MenuTheme {
199 #[theme(inherit_from = "defaults.background_color")]
201 pub background_color: Option<Rgba>,
202 #[theme(inherit_from = "defaults.border.color")]
204 pub separator_color: Option<Rgba>,
205 #[serde(rename = "row_height_px")]
207 #[theme(check = "non_negative")]
208 pub row_height: Option<f32>,
209 #[serde(rename = "icon_text_gap_px")]
211 #[theme(check = "non_negative")]
212 pub icon_text_gap: Option<f32>,
213 #[serde(rename = "icon_size_px")]
215 #[theme(check = "non_negative", inherit_from = "defaults.icon_sizes.toolbar")]
216 pub icon_size: Option<f32>,
217 #[theme(inherit_from = "defaults.selection_background")]
219 pub hover_background: Option<Rgba>,
220 #[theme(inherit_from = "defaults.selection_text_color")]
222 pub hover_text_color: Option<Rgba>,
223 #[theme(inherit_from = "defaults.disabled_text_color")]
225 pub disabled_text_color: Option<Rgba>,
226 #[theme(nested, resolved_type = "ResolvedFontSpec")]
228 pub font: Option<FontSpec>,
229 #[theme(nested, resolved_type = "ResolvedBorderSpec")]
231 pub border: Option<WidgetBorderSpec>,
232}
233
234#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
238#[serde_with::skip_serializing_none]
239#[serde(default)]
240#[theme_inherit(border_kind = "full", font = "font")]
241pub struct TooltipTheme {
242 #[theme(inherit_from = "defaults.background_color")]
244 pub background_color: Option<Rgba>,
245 #[serde(rename = "max_width_px")]
247 #[theme(check = "non_negative")]
248 pub max_width: Option<f32>,
249 #[theme(nested, resolved_type = "ResolvedFontSpec")]
251 pub font: Option<FontSpec>,
252 #[theme(nested, resolved_type = "ResolvedBorderSpec")]
254 pub border: Option<WidgetBorderSpec>,
255}
256
257#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
261#[serde_with::skip_serializing_none]
262#[serde(default)]
263pub struct ScrollbarTheme {
264 pub track_color: Option<Rgba>,
266 #[theme(inherit_from = "defaults.muted_color")]
268 pub thumb_color: Option<Rgba>,
269 #[theme(inherit_from = "defaults.muted_color")]
271 pub thumb_hover_color: Option<Rgba>,
272 #[serde(rename = "groove_width_px")]
274 #[theme(check = "non_negative")]
275 pub groove_width: Option<f32>,
276 #[serde(rename = "min_thumb_length_px")]
278 #[theme(check = "non_negative")]
279 pub min_thumb_length: Option<f32>,
280 #[serde(rename = "thumb_width_px")]
282 #[theme(check = "non_negative")]
283 pub thumb_width: Option<f32>,
284 pub overlay_mode: Option<bool>,
286 #[theme(category = "soft_option")]
288 pub thumb_active_color: Option<Rgba>,
289}
290
291#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
295#[serde_with::skip_serializing_none]
296#[serde(default)]
297pub struct SliderTheme {
298 #[theme(inherit_from = "defaults.accent_color")]
300 pub fill_color: Option<Rgba>,
301 #[theme(inherit_from = "defaults.muted_color")]
303 pub track_color: Option<Rgba>,
304 #[theme(inherit_from = "defaults.surface_color")]
306 pub thumb_color: Option<Rgba>,
307 #[serde(rename = "track_height_px")]
309 #[theme(check = "non_negative")]
310 pub track_height: Option<f32>,
311 #[serde(rename = "thumb_diameter_px")]
313 #[theme(check = "non_negative")]
314 pub thumb_diameter: Option<f32>,
315 #[serde(rename = "tick_mark_length_px")]
317 #[theme(check = "non_negative")]
318 pub tick_mark_length: Option<f32>,
319 #[theme(range = "0.0..=1.0", inherit_from = "defaults.disabled_opacity")]
321 pub disabled_opacity: Option<f32>,
322 #[theme(category = "soft_option")]
324 pub thumb_hover_color: Option<Rgba>,
325 #[theme(category = "soft_option")]
327 pub disabled_fill_color: Option<Rgba>,
328 #[theme(category = "soft_option")]
330 pub disabled_track_color: Option<Rgba>,
331 #[theme(category = "soft_option")]
333 pub disabled_thumb_color: Option<Rgba>,
334}
335
336#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
340#[serde_with::skip_serializing_none]
341#[serde(default)]
342#[theme_inherit(border_kind = "full")]
343pub struct ProgressBarTheme {
344 #[theme(inherit_from = "defaults.accent_color")]
346 pub fill_color: Option<Rgba>,
347 #[theme(inherit_from = "defaults.muted_color")]
349 pub track_color: Option<Rgba>,
350 #[serde(rename = "track_height_px")]
352 #[theme(check = "non_negative")]
353 pub track_height: Option<f32>,
354 #[serde(rename = "min_width_px")]
356 #[theme(check = "non_negative")]
357 pub min_width: Option<f32>,
358 #[theme(nested, resolved_type = "ResolvedBorderSpec")]
360 pub border: Option<WidgetBorderSpec>,
361}
362
363#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
367#[serde_with::skip_serializing_none]
368#[serde(default)]
369#[theme_layer(border_kind = "none")]
370#[theme_inherit(font = "font")]
371pub struct TabTheme {
372 #[theme(inherit_from = "defaults.background_color")]
374 pub background_color: Option<Rgba>,
375 #[theme(inherit_from = "defaults.background_color")]
377 pub active_background: Option<Rgba>,
378 #[theme(inherit_from = "defaults.text_color")]
380 pub active_text_color: Option<Rgba>,
381 #[theme(inherit_from = "defaults.background_color")]
383 pub bar_background: Option<Rgba>,
384 #[serde(rename = "min_width_px")]
386 #[theme(check = "non_negative")]
387 pub min_width: Option<f32>,
388 #[serde(rename = "min_height_px")]
390 #[theme(check = "non_negative")]
391 pub min_height: Option<f32>,
392 pub hover_text_color: Option<Rgba>,
394 #[theme(category = "soft_option")]
396 pub hover_background: Option<Rgba>,
397 #[theme(nested, resolved_type = "ResolvedFontSpec")]
399 pub font: Option<FontSpec>,
400 #[theme(nested, resolved_type = "ResolvedBorderSpec")]
402 pub border: Option<WidgetBorderSpec>,
403}
404
405#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
409#[serde_with::skip_serializing_none]
410#[serde(default)]
411#[theme_layer(border_kind = "partial")]
412#[theme_inherit(border_kind = "partial", font = "font")]
413pub struct SidebarTheme {
414 #[theme(inherit_from = "defaults.background_color")]
416 pub background_color: Option<Rgba>,
417 #[theme(inherit_from = "defaults.selection_background")]
419 pub selection_background: Option<Rgba>,
420 #[theme(inherit_from = "defaults.selection_text_color")]
422 pub selection_text_color: Option<Rgba>,
423 #[theme(inherit_from = "defaults.background_color")]
425 pub hover_background: Option<Rgba>,
426 #[theme(nested, resolved_type = "ResolvedFontSpec")]
428 pub font: Option<FontSpec>,
429 #[theme(nested, resolved_type = "ResolvedBorderSpec")]
431 pub border: Option<WidgetBorderSpec>,
432}
433
434#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
438#[serde_with::skip_serializing_none]
439#[serde(default)]
440#[theme_inherit(border_kind = "full", font = "font")]
441pub struct ToolbarTheme {
442 #[theme(inherit_from = "defaults.background_color")]
444 pub background_color: Option<Rgba>,
445 #[serde(rename = "bar_height_px")]
447 #[theme(check = "non_negative")]
448 pub bar_height: Option<f32>,
449 #[serde(rename = "item_gap_px")]
451 #[theme(check = "non_negative")]
452 pub item_gap: Option<f32>,
453 #[serde(rename = "icon_size_px")]
455 #[theme(check = "non_negative", inherit_from = "defaults.icon_sizes.toolbar")]
456 pub icon_size: Option<f32>,
457 #[theme(nested, resolved_type = "ResolvedFontSpec")]
459 pub font: Option<FontSpec>,
460 #[theme(nested, resolved_type = "ResolvedBorderSpec")]
462 pub border: Option<WidgetBorderSpec>,
463}
464
465#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
469#[serde_with::skip_serializing_none]
470#[serde(default)]
471#[theme_layer(border_kind = "partial")]
472#[theme_inherit(border_kind = "partial", font = "font")]
473pub struct StatusBarTheme {
474 #[theme(inherit_from = "defaults.background_color")]
476 pub background_color: Option<Rgba>,
477 #[theme(nested, resolved_type = "ResolvedFontSpec")]
479 pub font: Option<FontSpec>,
480 #[theme(nested, resolved_type = "ResolvedBorderSpec")]
482 pub border: Option<WidgetBorderSpec>,
483}
484
485#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
489#[serde_with::skip_serializing_none]
490#[serde(default)]
491#[theme_inherit(border_kind = "full", font = "item_font")]
492#[theme_inherit(font = "header_font")]
493pub struct ListTheme {
494 pub background_color: Option<Rgba>,
496 pub alternate_row_background: Option<Rgba>,
498 #[theme(inherit_from = "defaults.selection_background")]
500 pub selection_background: Option<Rgba>,
501 #[theme(inherit_from = "defaults.selection_text_color")]
503 pub selection_text_color: Option<Rgba>,
504 #[theme(inherit_from = "defaults.surface_color")]
506 pub header_background: Option<Rgba>,
507 #[theme(inherit_from = "defaults.border.color")]
509 pub grid_color: Option<Rgba>,
510 #[serde(rename = "row_height_px")]
512 #[theme(check = "non_negative")]
513 pub row_height: Option<f32>,
514 #[theme(inherit_from = "defaults.background_color")]
516 pub hover_background: Option<Rgba>,
517 pub hover_text_color: Option<Rgba>,
519 #[theme(inherit_from = "defaults.disabled_text_color")]
521 pub disabled_text_color: Option<Rgba>,
522 #[theme(nested, resolved_type = "ResolvedFontSpec")]
524 pub item_font: Option<FontSpec>,
525 #[theme(nested, resolved_type = "ResolvedFontSpec")]
527 pub header_font: Option<FontSpec>,
528 #[theme(nested, resolved_type = "ResolvedBorderSpec")]
530 pub border: Option<WidgetBorderSpec>,
531}
532
533#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
537#[serde_with::skip_serializing_none]
538#[serde(default)]
539#[theme_inherit(border_kind = "full_lg", font = "font")]
540pub struct PopoverTheme {
541 pub background_color: Option<Rgba>,
543 #[theme(nested, resolved_type = "ResolvedFontSpec")]
545 pub font: Option<FontSpec>,
546 #[theme(nested, resolved_type = "ResolvedBorderSpec")]
548 pub border: Option<WidgetBorderSpec>,
549}
550
551#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
555#[serde_with::skip_serializing_none]
556#[serde(default)]
557pub struct SplitterTheme {
558 #[serde(rename = "divider_width_px")]
560 #[theme(check = "non_negative")]
561 pub divider_width: Option<f32>,
562 #[theme(inherit_from = "defaults.border.color")]
564 pub divider_color: Option<Rgba>,
565 pub hover_color: Option<Rgba>,
567}
568
569#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
573#[serde_with::skip_serializing_none]
574#[serde(default)]
575pub struct SeparatorTheme {
576 #[theme(inherit_from = "defaults.border.color")]
578 pub line_color: Option<Rgba>,
579 #[serde(rename = "line_width_px")]
581 #[theme(check = "non_negative", inherit_from = "defaults.border.line_width")]
582 pub line_width: Option<f32>,
583}
584
585#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
589#[serde_with::skip_serializing_none]
590#[serde(default)]
591pub struct SwitchTheme {
592 #[theme(inherit_from = "defaults.accent_color")]
594 pub checked_background: Option<Rgba>,
595 pub unchecked_background: Option<Rgba>,
597 #[theme(inherit_from = "defaults.surface_color")]
599 pub thumb_background: Option<Rgba>,
600 #[serde(rename = "track_width_px")]
602 #[theme(check = "non_negative")]
603 pub track_width: Option<f32>,
604 #[serde(rename = "track_height_px")]
606 #[theme(check = "non_negative")]
607 pub track_height: Option<f32>,
608 #[serde(rename = "thumb_diameter_px")]
610 #[theme(check = "non_negative")]
611 pub thumb_diameter: Option<f32>,
612 #[serde(rename = "track_radius_px")]
614 #[theme(check = "non_negative")]
615 pub track_radius: Option<f32>,
616 #[theme(range = "0.0..=1.0", inherit_from = "defaults.disabled_opacity")]
618 pub disabled_opacity: Option<f32>,
619 #[theme(category = "soft_option")]
621 pub hover_checked_background: Option<Rgba>,
622 #[theme(category = "soft_option")]
624 pub hover_unchecked_background: Option<Rgba>,
625 #[theme(category = "soft_option")]
627 pub disabled_checked_background: Option<Rgba>,
628 #[theme(category = "soft_option")]
630 pub disabled_unchecked_background: Option<Rgba>,
631 #[theme(category = "soft_option")]
633 pub disabled_thumb_color: Option<Rgba>,
634}
635
636#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
640#[serde_with::skip_serializing_none]
641#[serde(default)]
642#[theme_inherit(border_kind = "full_lg", font = "title_font")]
643#[theme_inherit(font = "body_font")]
644pub struct DialogTheme {
645 pub background_color: Option<Rgba>,
647 #[serde(rename = "min_width_px")]
649 #[theme(check = "non_negative", min_max_pair = "max_width")]
650 pub min_width: Option<f32>,
651 #[serde(rename = "max_width_px")]
653 #[theme(check = "non_negative")]
654 pub max_width: Option<f32>,
655 #[serde(rename = "min_height_px")]
657 #[theme(check = "non_negative", min_max_pair = "max_height")]
658 pub min_height: Option<f32>,
659 #[serde(rename = "max_height_px")]
661 #[theme(check = "non_negative")]
662 pub max_height: Option<f32>,
663 #[serde(rename = "button_gap_px")]
665 #[theme(check = "non_negative")]
666 pub button_gap: Option<f32>,
667 #[serde(rename = "icon_size_px")]
669 #[theme(check = "non_negative")]
670 pub icon_size: Option<f32>,
671 pub button_order: Option<DialogButtonOrder>,
673 #[theme(nested, resolved_type = "ResolvedFontSpec")]
675 pub title_font: Option<FontSpec>,
676 #[theme(nested, resolved_type = "ResolvedFontSpec")]
678 pub body_font: Option<FontSpec>,
679 #[theme(nested, resolved_type = "ResolvedBorderSpec")]
681 pub border: Option<WidgetBorderSpec>,
682}
683
684#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
688#[serde_with::skip_serializing_none]
689#[serde(default)]
690pub struct SpinnerTheme {
691 pub fill_color: Option<Rgba>,
693 #[serde(rename = "diameter_px")]
695 #[theme(check = "non_negative")]
696 pub diameter: Option<f32>,
697 #[serde(rename = "min_diameter_px")]
699 #[theme(check = "non_negative")]
700 pub min_diameter: Option<f32>,
701 #[serde(rename = "stroke_width_px")]
703 #[theme(check = "non_negative")]
704 pub stroke_width: Option<f32>,
705}
706
707#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
711#[serde_with::skip_serializing_none]
712#[serde(default)]
713#[theme_inherit(border_kind = "full", font = "font")]
714pub struct ComboBoxTheme {
715 #[theme(inherit_from = "defaults.background_color")]
717 pub background_color: Option<Rgba>,
718 #[serde(rename = "min_height_px")]
720 #[theme(check = "non_negative")]
721 pub min_height: Option<f32>,
722 #[serde(rename = "min_width_px")]
724 #[theme(check = "non_negative")]
725 pub min_width: Option<f32>,
726 #[serde(rename = "arrow_icon_size_px")]
728 #[theme(check = "non_negative")]
729 pub arrow_icon_size: Option<f32>,
730 #[serde(rename = "arrow_area_width_px")]
732 #[theme(check = "non_negative")]
733 pub arrow_area_width: Option<f32>,
734 #[theme(range = "0.0..=1.0", inherit_from = "defaults.disabled_opacity")]
736 pub disabled_opacity: Option<f32>,
737 #[theme(inherit_from = "defaults.disabled_text_color")]
739 pub disabled_text_color: Option<Rgba>,
740 #[theme(category = "soft_option")]
742 pub hover_background: Option<Rgba>,
743 #[theme(category = "soft_option")]
745 pub disabled_background: Option<Rgba>,
746 #[theme(nested, resolved_type = "ResolvedFontSpec")]
748 pub font: Option<FontSpec>,
749 #[theme(nested, resolved_type = "ResolvedBorderSpec")]
751 pub border: Option<WidgetBorderSpec>,
752}
753
754#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
758#[serde_with::skip_serializing_none]
759#[serde(default)]
760#[theme_inherit(border_kind = "full", font = "font")]
761pub struct SegmentedControlTheme {
762 #[theme(inherit_from = "defaults.background_color")]
764 pub background_color: Option<Rgba>,
765 #[theme(inherit_from = "defaults.accent_color")]
767 pub active_background: Option<Rgba>,
768 #[theme(inherit_from = "defaults.accent_text_color")]
770 pub active_text_color: Option<Rgba>,
771 #[serde(rename = "segment_height_px")]
773 #[theme(check = "non_negative")]
774 pub segment_height: Option<f32>,
775 #[serde(rename = "separator_width_px")]
777 #[theme(check = "non_negative")]
778 pub separator_width: Option<f32>,
779 #[theme(range = "0.0..=1.0", inherit_from = "defaults.disabled_opacity")]
781 pub disabled_opacity: Option<f32>,
782 #[theme(category = "soft_option")]
784 pub hover_background: Option<Rgba>,
785 #[theme(nested, resolved_type = "ResolvedFontSpec")]
787 pub font: Option<FontSpec>,
788 #[theme(nested, resolved_type = "ResolvedBorderSpec")]
790 pub border: Option<WidgetBorderSpec>,
791}
792
793#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
797#[serde_with::skip_serializing_none]
798#[serde(default)]
799#[theme_layer(border_kind = "none")]
800pub struct CardTheme {
801 #[theme(inherit_from = "defaults.surface_color")]
803 pub background_color: Option<Rgba>,
804 #[theme(nested, resolved_type = "ResolvedBorderSpec")]
806 pub border: Option<WidgetBorderSpec>,
807}
808
809#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
813#[serde_with::skip_serializing_none]
814#[serde(default)]
815#[theme_inherit(border_kind = "full", font = "font")]
816pub struct ExpanderTheme {
817 #[serde(rename = "header_height_px")]
819 #[theme(check = "non_negative")]
820 pub header_height: Option<f32>,
821 #[serde(rename = "arrow_icon_size_px")]
823 #[theme(check = "non_negative")]
824 pub arrow_icon_size: Option<f32>,
825 #[theme(category = "soft_option")]
827 pub hover_background: Option<Rgba>,
828 #[theme(category = "soft_option")]
830 pub arrow_color: Option<Rgba>,
831 #[theme(nested, resolved_type = "ResolvedFontSpec")]
833 pub font: Option<FontSpec>,
834 #[theme(nested, resolved_type = "ResolvedBorderSpec")]
836 pub border: Option<WidgetBorderSpec>,
837}
838
839#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
843#[serde_with::skip_serializing_none]
844#[serde(default)]
845#[theme_inherit(font = "font")]
846pub struct LinkTheme {
847 #[theme(inherit_from = "defaults.link_color")]
849 pub visited_text_color: Option<Rgba>,
850 pub underline_enabled: Option<bool>,
852 pub background_color: Option<Rgba>,
854 pub hover_background: Option<Rgba>,
856 pub hover_text_color: Option<Rgba>,
858 pub active_text_color: Option<Rgba>,
860 #[theme(inherit_from = "defaults.disabled_text_color")]
862 pub disabled_text_color: Option<Rgba>,
863 #[theme(nested, resolved_type = "ResolvedFontSpec")]
865 pub font: Option<FontSpec>,
866}
867
868#[derive(
879 Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget, ThemeFields,
880)]
881#[serde_with::skip_serializing_none]
882#[serde(default)]
883#[theme_layer(skip_inventory)]
884pub struct LayoutTheme {
885 #[serde(rename = "widget_gap_px")]
887 #[theme(check = "non_negative")]
888 pub widget_gap: Option<f32>,
889 #[serde(rename = "container_margin_px")]
891 #[theme(check = "non_negative")]
892 pub container_margin: Option<f32>,
893 #[serde(rename = "window_margin_px")]
895 #[theme(check = "non_negative")]
896 pub window_margin: Option<f32>,
897 #[serde(rename = "section_gap_px")]
899 #[theme(check = "non_negative")]
900 pub section_gap: Option<f32>,
901}
902
903#[cfg(test)]
904#[allow(clippy::unwrap_used, clippy::expect_used, dead_code)]
905mod tests {
906 use super::*;
907 use crate::Rgba;
908 use crate::model::border::{ResolvedBorderSpec, WidgetBorderSpec};
909 use crate::model::font::FontSize;
910 use crate::model::{DialogButtonOrder, FontSpec};
911
912 #[derive(
915 Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget,
916 )]
917 #[serde_with::skip_serializing_none]
918 #[serde(default)]
919 #[theme_layer(skip_inventory)]
920 pub struct TestWidget {
921 pub size: Option<f32>,
922 pub label: Option<String>,
923 #[theme(nested, resolved_type = "ResolvedFontSpec")]
924 pub font: Option<FontSpec>,
925 }
926
927 #[test]
930 fn resolved_font_spec_fields_are_concrete() {
931 let rfs = ResolvedFontSpec {
932 family: "Inter".into(),
933 size: 14.0,
934 weight: 400,
935 style: crate::model::font::FontStyle::Normal,
936 color: crate::Rgba::rgb(0, 0, 0),
937 };
938 assert_eq!(rfs.family.as_ref(), "Inter");
939 assert_eq!(rfs.size, 14.0);
940 assert_eq!(rfs.weight, 400);
941 }
942
943 #[test]
946 fn generated_option_struct_has_option_fields() {
947 let w = TestWidget::default();
948 assert!(w.size.is_none());
949 assert!(w.label.is_none());
950 assert!(w.font.is_none());
951 }
952
953 #[test]
954 fn generated_option_struct_is_empty_by_default() {
955 assert!(TestWidget::default().is_empty());
956 }
957
958 #[test]
959 fn generated_option_struct_not_empty_when_size_set() {
960 let w = TestWidget {
961 size: Some(24.0),
962 ..Default::default()
963 };
964 assert!(!w.is_empty());
965 }
966
967 #[test]
968 fn generated_option_struct_not_empty_when_font_set() {
969 let w = TestWidget {
970 font: Some(FontSpec {
971 size: Some(FontSize::Px(14.0)),
972 ..Default::default()
973 }),
974 ..Default::default()
975 };
976 assert!(!w.is_empty());
977 }
978
979 #[test]
980 fn generated_resolved_struct_has_concrete_fields() {
981 let resolved = ResolvedTestWidget {
982 size: 24.0,
983 label: "Click me".into(),
984 font: ResolvedFontSpec {
985 family: "Inter".into(),
986 size: 14.0,
987 weight: 400,
988 style: crate::model::font::FontStyle::Normal,
989 color: crate::Rgba::rgb(0, 0, 0),
990 },
991 };
992 assert_eq!(resolved.size, 24.0);
993 assert_eq!(resolved.label, "Click me");
994 assert_eq!(resolved.font.family.as_ref(), "Inter");
995 }
996
997 #[test]
1000 fn generated_merge_option_field_overlay_wins() {
1001 let mut base = TestWidget {
1002 size: Some(20.0),
1003 ..Default::default()
1004 };
1005 let overlay = TestWidget {
1006 size: Some(24.0),
1007 ..Default::default()
1008 };
1009 base.merge(&overlay);
1010 assert_eq!(base.size, Some(24.0));
1011 }
1012
1013 #[test]
1014 fn generated_merge_option_field_none_preserves_base() {
1015 let mut base = TestWidget {
1016 size: Some(20.0),
1017 ..Default::default()
1018 };
1019 let overlay = TestWidget::default();
1020 base.merge(&overlay);
1021 assert_eq!(base.size, Some(20.0));
1022 }
1023
1024 #[test]
1025 fn generated_merge_optional_nested_both_some_merges_inner() {
1026 let mut base = TestWidget {
1027 font: Some(FontSpec {
1028 family: Some("Noto Sans".into()),
1029 size: Some(FontSize::Px(12.0)),
1030 weight: None,
1031 ..Default::default()
1032 }),
1033 ..Default::default()
1034 };
1035 let overlay = TestWidget {
1036 font: Some(FontSpec {
1037 family: None,
1038 size: None,
1039 weight: Some(700),
1040 ..Default::default()
1041 }),
1042 ..Default::default()
1043 };
1044 base.merge(&overlay);
1045 let font = base.font.as_ref().unwrap();
1046 assert_eq!(font.family.as_deref(), Some("Noto Sans")); assert_eq!(font.size, Some(FontSize::Px(12.0))); assert_eq!(font.weight, Some(700)); }
1050
1051 #[test]
1052 fn generated_merge_optional_nested_none_plus_some_clones() {
1053 let mut base = TestWidget::default();
1054 let overlay = TestWidget {
1055 font: Some(FontSpec {
1056 family: Some("Inter".into()),
1057 size: Some(FontSize::Px(14.0)),
1058 weight: Some(400),
1059 ..Default::default()
1060 }),
1061 ..Default::default()
1062 };
1063 base.merge(&overlay);
1064 let font = base.font.as_ref().unwrap();
1065 assert_eq!(font.family.as_deref(), Some("Inter"));
1066 assert_eq!(font.size, Some(FontSize::Px(14.0)));
1067 assert_eq!(font.weight, Some(400));
1068 }
1069
1070 #[test]
1071 fn generated_merge_optional_nested_some_plus_none_preserves_base() {
1072 let mut base = TestWidget {
1073 font: Some(FontSpec {
1074 family: Some("Inter".into()),
1075 size: Some(FontSize::Px(14.0)),
1076 weight: Some(400),
1077 ..Default::default()
1078 }),
1079 ..Default::default()
1080 };
1081 let overlay = TestWidget::default();
1082 base.merge(&overlay);
1083 let font = base.font.as_ref().unwrap();
1084 assert_eq!(font.family.as_deref(), Some("Inter"));
1085 }
1086
1087 #[test]
1088 fn generated_merge_optional_nested_none_plus_none_stays_none() {
1089 let mut base = TestWidget::default();
1090 let overlay = TestWidget::default();
1091 base.merge(&overlay);
1092 assert!(base.font.is_none());
1093 }
1094
1095 #[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize)]
1099 struct WithFont {
1100 name: Option<String>,
1101 font: Option<FontSpec>,
1102 }
1103
1104 impl_merge!(WithFont {
1105 option { name }
1106 optional_nested { font }
1107 });
1108
1109 #[test]
1110 fn impl_merge_optional_nested_none_none_stays_none() {
1111 let mut base = WithFont::default();
1112 let overlay = WithFont::default();
1113 base.merge(&overlay);
1114 assert!(base.font.is_none());
1115 }
1116
1117 #[test]
1118 fn impl_merge_optional_nested_some_none_preserves_base() {
1119 let mut base = WithFont {
1120 font: Some(FontSpec {
1121 size: Some(FontSize::Px(12.0)),
1122 ..Default::default()
1123 }),
1124 ..Default::default()
1125 };
1126 let overlay = WithFont::default();
1127 base.merge(&overlay);
1128 assert_eq!(base.font.as_ref().unwrap().size, Some(FontSize::Px(12.0)));
1129 }
1130
1131 #[test]
1132 fn impl_merge_optional_nested_none_some_clones_overlay() {
1133 let mut base = WithFont::default();
1134 let overlay = WithFont {
1135 font: Some(FontSpec {
1136 family: Some("Inter".into()),
1137 ..Default::default()
1138 }),
1139 ..Default::default()
1140 };
1141 base.merge(&overlay);
1142 assert_eq!(base.font.as_ref().unwrap().family.as_deref(), Some("Inter"));
1143 }
1144
1145 #[test]
1146 fn impl_merge_optional_nested_some_some_merges_inner() {
1147 let mut base = WithFont {
1148 font: Some(FontSpec {
1149 family: Some("Noto".into()),
1150 size: Some(FontSize::Px(11.0)),
1151 weight: None,
1152 ..Default::default()
1153 }),
1154 ..Default::default()
1155 };
1156 let overlay = WithFont {
1157 font: Some(FontSpec {
1158 family: None,
1159 size: Some(FontSize::Px(14.0)),
1160 weight: Some(400),
1161 ..Default::default()
1162 }),
1163 ..Default::default()
1164 };
1165 base.merge(&overlay);
1166 let f = base.font.as_ref().unwrap();
1167 assert_eq!(f.family.as_deref(), Some("Noto")); assert_eq!(f.size, Some(FontSize::Px(14.0))); assert_eq!(f.weight, Some(400)); }
1171
1172 #[test]
1173 fn impl_merge_optional_nested_is_empty_none() {
1174 let w = WithFont::default();
1175 assert!(w.is_empty());
1176 }
1177
1178 #[test]
1179 fn impl_merge_optional_nested_is_empty_some_default() {
1180 let w = WithFont {
1182 font: Some(FontSpec::default()),
1183 ..Default::default()
1184 };
1185 assert!(w.is_empty());
1186 }
1187
1188 #[test]
1189 fn impl_merge_optional_nested_is_not_empty_when_populated() {
1190 let w = WithFont {
1191 font: Some(FontSpec {
1192 size: Some(FontSize::Px(14.0)),
1193 ..Default::default()
1194 }),
1195 ..Default::default()
1196 };
1197 assert!(!w.is_empty());
1198 }
1199
1200 #[test]
1203 fn button_theme_default_is_empty() {
1204 assert!(ButtonTheme::default().is_empty());
1205 }
1206
1207 #[test]
1208 fn button_theme_not_empty_when_set() {
1209 let b = ButtonTheme {
1210 background_color: Some(Rgba::rgb(200, 200, 200)),
1211 min_width: Some(64.0),
1212 ..Default::default()
1213 };
1214 assert!(!b.is_empty());
1215 }
1216
1217 #[test]
1218 fn button_theme_merge_font_optional_nested() {
1219 let mut base = ButtonTheme {
1220 font: Some(FontSpec {
1221 family: Some("Noto Sans".into()),
1222 size: Some(FontSize::Px(11.0)),
1223 weight: None,
1224 ..Default::default()
1225 }),
1226 ..Default::default()
1227 };
1228 let overlay = ButtonTheme {
1229 font: Some(FontSpec {
1230 family: None,
1231 weight: Some(700),
1232 ..Default::default()
1233 }),
1234 ..Default::default()
1235 };
1236 base.merge(&overlay);
1237 let f = base.font.as_ref().unwrap();
1238 assert_eq!(f.family.as_deref(), Some("Noto Sans")); assert_eq!(f.weight, Some(700)); }
1241
1242 #[test]
1243 fn button_theme_toml_round_trip_with_font_and_border() {
1244 let b = ButtonTheme {
1245 background_color: Some(Rgba::rgb(200, 200, 200)),
1246 font: Some(FontSpec {
1247 family: Some("Inter".into()),
1248 size: Some(FontSize::Px(14.0)),
1249 weight: Some(400),
1250 ..Default::default()
1251 }),
1252 border: Some(WidgetBorderSpec {
1253 corner_radius: Some(4.0),
1254 ..Default::default()
1255 }),
1256 ..Default::default()
1257 };
1258 let toml_str = toml::to_string(&b).unwrap();
1259 let b2: ButtonTheme = toml::from_str(&toml_str).unwrap();
1260 assert_eq!(b, b2);
1261 }
1262
1263 #[test]
1266 fn window_theme_has_new_fields() {
1267 let w = WindowTheme {
1268 inactive_title_bar_background: Some(Rgba::rgb(180, 180, 180)),
1269 inactive_title_bar_text_color: Some(Rgba::rgb(120, 120, 120)),
1270 title_bar_font: Some(FontSpec {
1271 weight: Some(700),
1272 ..Default::default()
1273 }),
1274 border: Some(WidgetBorderSpec {
1275 corner_radius: Some(4.0),
1276 shadow_enabled: Some(true),
1277 ..Default::default()
1278 }),
1279 ..Default::default()
1280 };
1281 assert!(!w.is_empty());
1282 assert!(w.inactive_title_bar_background.is_some());
1283 assert!(w.inactive_title_bar_text_color.is_some());
1284 assert!(w.title_bar_font.is_some());
1285 assert!(w.border.is_some());
1286 }
1287
1288 #[test]
1289 fn window_theme_default_is_empty() {
1290 assert!(WindowTheme::default().is_empty());
1291 }
1292
1293 #[test]
1296 fn dialog_theme_button_order_works() {
1297 let d = DialogTheme {
1298 button_order: Some(DialogButtonOrder::PrimaryRight),
1299 min_width: Some(300.0),
1300 ..Default::default()
1301 };
1302 assert_eq!(d.button_order, Some(DialogButtonOrder::PrimaryRight));
1303 assert_eq!(d.min_width, Some(300.0));
1304 assert!(!d.is_empty());
1305 }
1306
1307 #[test]
1308 fn dialog_theme_button_order_toml_round_trip() {
1309 let d = DialogTheme {
1310 button_order: Some(DialogButtonOrder::PrimaryLeft),
1311 ..Default::default()
1312 };
1313 let toml_str = toml::to_string(&d).unwrap();
1314 let d2: DialogTheme = toml::from_str(&toml_str).unwrap();
1315 assert_eq!(d, d2);
1316 }
1317
1318 #[test]
1319 fn dialog_theme_default_is_empty() {
1320 assert!(DialogTheme::default().is_empty());
1321 }
1322
1323 #[test]
1326 fn splitter_theme_single_field_merge() {
1327 let mut base = SplitterTheme {
1328 divider_width: Some(4.0),
1329 ..Default::default()
1330 };
1331 let overlay = SplitterTheme {
1332 divider_width: Some(6.0),
1333 ..Default::default()
1334 };
1335 base.merge(&overlay);
1336 assert_eq!(base.divider_width, Some(6.0));
1337 }
1338
1339 #[test]
1340 fn splitter_theme_merge_none_preserves_base() {
1341 let mut base = SplitterTheme {
1342 divider_width: Some(4.0),
1343 ..Default::default()
1344 };
1345 let overlay = SplitterTheme::default();
1346 base.merge(&overlay);
1347 assert_eq!(base.divider_width, Some(4.0));
1348 }
1349
1350 #[test]
1351 fn splitter_theme_default_is_empty() {
1352 assert!(SplitterTheme::default().is_empty());
1353 }
1354
1355 #[test]
1356 fn splitter_theme_not_empty_when_set() {
1357 assert!(
1358 !SplitterTheme {
1359 divider_width: Some(4.0),
1360 ..Default::default()
1361 }
1362 .is_empty()
1363 );
1364 }
1365
1366 #[test]
1369 fn separator_theme_single_field() {
1370 let s = SeparatorTheme {
1371 line_color: Some(Rgba::rgb(200, 200, 200)),
1372 ..Default::default()
1373 };
1374 assert!(!s.is_empty());
1375 }
1376
1377 #[test]
1380 fn all_widget_theme_defaults_are_empty() {
1381 assert!(WindowTheme::default().is_empty());
1382 assert!(ButtonTheme::default().is_empty());
1383 assert!(InputTheme::default().is_empty());
1384 assert!(CheckboxTheme::default().is_empty());
1385 assert!(MenuTheme::default().is_empty());
1386 assert!(TooltipTheme::default().is_empty());
1387 assert!(ScrollbarTheme::default().is_empty());
1388 assert!(SliderTheme::default().is_empty());
1389 assert!(ProgressBarTheme::default().is_empty());
1390 assert!(TabTheme::default().is_empty());
1391 assert!(SidebarTheme::default().is_empty());
1392 assert!(ToolbarTheme::default().is_empty());
1393 assert!(StatusBarTheme::default().is_empty());
1394 assert!(ListTheme::default().is_empty());
1395 assert!(PopoverTheme::default().is_empty());
1396 assert!(SplitterTheme::default().is_empty());
1397 assert!(SeparatorTheme::default().is_empty());
1398 assert!(SwitchTheme::default().is_empty());
1399 assert!(DialogTheme::default().is_empty());
1400 assert!(SpinnerTheme::default().is_empty());
1401 assert!(ComboBoxTheme::default().is_empty());
1402 assert!(SegmentedControlTheme::default().is_empty());
1403 assert!(CardTheme::default().is_empty());
1404 assert!(ExpanderTheme::default().is_empty());
1405 assert!(LinkTheme::default().is_empty());
1406 }
1407
1408 #[test]
1411 fn input_theme_toml_round_trip() {
1412 let t = InputTheme {
1413 background_color: Some(Rgba::rgb(255, 255, 255)),
1414 font: Some(FontSpec {
1415 family: Some("Noto Sans".into()),
1416 ..Default::default()
1417 }),
1418 border: Some(WidgetBorderSpec {
1419 color: Some(Rgba::rgb(180, 180, 180)),
1420 corner_radius: Some(4.0),
1421 ..Default::default()
1422 }),
1423 ..Default::default()
1424 };
1425 let toml_str = toml::to_string(&t).unwrap();
1426 let t2: InputTheme = toml::from_str(&toml_str).unwrap();
1427 assert_eq!(t, t2);
1428 }
1429
1430 #[test]
1431 fn switch_theme_toml_round_trip() {
1432 let s = SwitchTheme {
1433 checked_background: Some(Rgba::rgb(0, 120, 215)),
1434 track_width: Some(40.0),
1435 track_height: Some(20.0),
1436 thumb_diameter: Some(14.0),
1437 track_radius: Some(10.0),
1438 ..Default::default()
1439 };
1440 let toml_str = toml::to_string(&s).unwrap();
1441 let s2: SwitchTheme = toml::from_str(&toml_str).unwrap();
1442 assert_eq!(s, s2);
1443 }
1444
1445 #[test]
1446 fn card_theme_with_border() {
1447 let c = CardTheme {
1448 background_color: Some(Rgba::rgb(255, 255, 255)),
1449 border: Some(WidgetBorderSpec {
1450 corner_radius: Some(8.0),
1451 shadow_enabled: Some(true),
1452 ..Default::default()
1453 }),
1454 };
1455 assert!(!c.is_empty());
1456 }
1457
1458 #[test]
1459 fn link_theme_has_underline_enabled_bool_field() {
1460 let l = LinkTheme {
1461 visited_text_color: Some(Rgba::rgb(100, 0, 200)),
1462 underline_enabled: Some(true),
1463 ..Default::default()
1464 };
1465 assert!(!l.is_empty());
1466 assert_eq!(l.underline_enabled, Some(true));
1467 }
1468
1469 #[test]
1470 fn status_bar_theme_has_font_and_background() {
1471 let s = StatusBarTheme {
1472 background_color: Some(Rgba::rgb(240, 240, 240)),
1473 font: Some(FontSpec {
1474 size: Some(FontSize::Px(11.0)),
1475 ..Default::default()
1476 }),
1477 ..Default::default()
1478 };
1479 assert!(!s.is_empty());
1480 }
1481
1482 #[derive(
1487 Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget,
1488 )]
1489 #[serde_with::skip_serializing_none]
1490 #[serde(default)]
1491 #[theme_layer(skip_inventory)]
1492 pub struct DualNestedTestWidget {
1493 pub background: Option<Rgba>,
1494 pub min_height: Option<f32>,
1495 #[theme(nested, resolved_type = "ResolvedFontSpec")]
1496 pub font: Option<FontSpec>,
1497 #[theme(nested, resolved_type = "ResolvedBorderSpec")]
1498 pub border: Option<WidgetBorderSpec>,
1499 }
1500
1501 #[test]
1502 fn dual_nested_default_is_empty() {
1503 assert!(DualNestedTestWidget::default().is_empty());
1504 }
1505
1506 #[test]
1507 fn dual_nested_field_names() {
1508 assert_eq!(DualNestedTestWidget::FIELD_NAMES.len(), 4);
1509 assert!(DualNestedTestWidget::FIELD_NAMES.contains(&"background"));
1510 assert!(DualNestedTestWidget::FIELD_NAMES.contains(&"min_height"));
1511 assert!(DualNestedTestWidget::FIELD_NAMES.contains(&"font"));
1512 assert!(DualNestedTestWidget::FIELD_NAMES.contains(&"border"));
1513 }
1514
1515 #[test]
1516 fn dual_nested_not_empty_when_font_set() {
1517 let w = DualNestedTestWidget {
1518 font: Some(FontSpec {
1519 family: Some("Inter".into()),
1520 ..Default::default()
1521 }),
1522 ..Default::default()
1523 };
1524 assert!(!w.is_empty());
1525 }
1526
1527 #[test]
1528 fn dual_nested_not_empty_when_border_set() {
1529 let w = DualNestedTestWidget {
1530 border: Some(WidgetBorderSpec {
1531 color: Some(Rgba::rgb(100, 100, 100)),
1532 ..Default::default()
1533 }),
1534 ..Default::default()
1535 };
1536 assert!(!w.is_empty());
1537 }
1538
1539 #[test]
1540 fn dual_nested_merge_both_nested() {
1541 let mut base = DualNestedTestWidget {
1542 font: Some(FontSpec {
1543 family: Some("Noto Sans".into()),
1544 ..Default::default()
1545 }),
1546 ..Default::default()
1547 };
1548 let overlay = DualNestedTestWidget {
1549 border: Some(WidgetBorderSpec {
1550 corner_radius: Some(4.0),
1551 ..Default::default()
1552 }),
1553 ..Default::default()
1554 };
1555 base.merge(&overlay);
1556 assert!(base.font.is_some());
1557 assert!(base.border.is_some());
1558 assert_eq!(
1559 base.font.as_ref().and_then(|f| f.family.as_deref()),
1560 Some("Noto Sans")
1561 );
1562 assert_eq!(
1563 base.border.as_ref().and_then(|b| b.corner_radius),
1564 Some(4.0)
1565 );
1566 }
1567
1568 #[test]
1569 fn dual_nested_merge_inner_font_fields() {
1570 let mut base = DualNestedTestWidget {
1571 font: Some(FontSpec {
1572 family: Some("Noto Sans".into()),
1573 ..Default::default()
1574 }),
1575 ..Default::default()
1576 };
1577 let overlay = DualNestedTestWidget {
1578 font: Some(FontSpec {
1579 size: Some(FontSize::Px(14.0)),
1580 ..Default::default()
1581 }),
1582 ..Default::default()
1583 };
1584 base.merge(&overlay);
1585 let font = base.font.as_ref().unwrap();
1586 assert_eq!(font.family.as_deref(), Some("Noto Sans")); assert_eq!(font.size, Some(FontSize::Px(14.0))); }
1589
1590 #[test]
1591 fn dual_nested_toml_round_trip() {
1592 let w = DualNestedTestWidget {
1593 background: Some(Rgba::rgb(240, 240, 240)),
1594 min_height: Some(32.0),
1595 font: Some(FontSpec {
1596 family: Some("Inter".into()),
1597 size: Some(FontSize::Px(14.0)),
1598 weight: Some(400),
1599 ..Default::default()
1600 }),
1601 border: Some(WidgetBorderSpec {
1602 color: Some(Rgba::rgb(180, 180, 180)),
1603 corner_radius: Some(4.0),
1604 line_width: Some(1.0),
1605 ..Default::default()
1606 }),
1607 };
1608 let toml_str = toml::to_string(&w).unwrap();
1609 let w2: DualNestedTestWidget = toml::from_str(&toml_str).unwrap();
1610 assert_eq!(w, w2);
1611 }
1612
1613 #[test]
1618 fn button_validate_widget_extracts_all_fields() {
1619 let button = ButtonTheme {
1620 background_color: Some(Rgba::rgb(200, 200, 200)),
1621 primary_background: Some(Rgba::rgb(0, 120, 215)),
1622 primary_text_color: Some(Rgba::rgb(255, 255, 255)),
1623 min_width: Some(80.0),
1624 min_height: Some(32.0),
1625 icon_text_gap: Some(8.0),
1626 disabled_opacity: Some(0.4),
1627 hover_background: Some(Rgba::rgb(210, 210, 210)),
1628 hover_text_color: Some(Rgba::rgb(0, 0, 0)),
1629 active_text_color: Some(Rgba::rgb(0, 0, 0)),
1630 disabled_text_color: Some(Rgba::rgb(128, 128, 128)),
1631 active_background: Some(Rgba::rgb(180, 180, 180)),
1632 disabled_background: Some(Rgba::rgb(220, 220, 220)),
1633 font: Some(FontSpec {
1634 family: Some("Inter".into()),
1635 size: Some(FontSize::Px(14.0)),
1636 weight: Some(400),
1637 style: Some(crate::model::font::FontStyle::Normal),
1638 color: Some(Rgba::rgb(0, 0, 0)),
1639 }),
1640 border: Some(WidgetBorderSpec {
1641 color: Some(Rgba::rgb(100, 100, 100)),
1642 corner_radius: Some(4.0),
1643 line_width: Some(1.0),
1644 shadow_enabled: Some(false),
1645 padding_horizontal: Some(12.0),
1646 padding_vertical: Some(6.0),
1647 }),
1648 };
1649 let mut missing = Vec::new();
1650 let resolved = ResolvedButtonTheme::validate_widget(&button, "button", 96.0, &mut missing);
1651 assert!(missing.is_empty(), "unexpected missing: {missing:?}");
1652 assert_eq!(resolved.background_color, Rgba::rgb(200, 200, 200));
1653 assert_eq!(resolved.min_width, 80.0);
1654 assert_eq!(resolved.font.family.as_ref(), "Inter");
1655 assert_eq!(resolved.font.size, 14.0);
1656 assert_eq!(resolved.border.corner_radius, 4.0);
1657 assert_eq!(resolved.active_background, Some(Rgba::rgb(180, 180, 180)));
1659 assert_eq!(resolved.disabled_background, Some(Rgba::rgb(220, 220, 220)));
1660 }
1661
1662 #[test]
1663 fn button_validate_widget_records_missing_fields() {
1664 let button = ButtonTheme::default(); let mut missing = Vec::new();
1666 let _ = ResolvedButtonTheme::validate_widget(&button, "button", 96.0, &mut missing);
1667 assert!(missing.contains(&"button.background_color".to_string()));
1669 assert!(missing.contains(&"button.min_width".to_string()));
1670 assert!(missing.contains(&"button.font".to_string()));
1672 assert!(missing.contains(&"button.border".to_string()));
1674 assert!(!missing.iter().any(|m| m.contains("active_background")));
1676 assert!(!missing.iter().any(|m| m.contains("disabled_background")));
1677 }
1678
1679 #[test]
1682 fn layout_theme_default_is_empty() {
1683 assert!(LayoutTheme::default().is_empty());
1684 }
1685
1686 #[test]
1687 fn layout_theme_not_empty_when_widget_gap_set() {
1688 let l = LayoutTheme {
1689 widget_gap: Some(8.0),
1690 ..Default::default()
1691 };
1692 assert!(!l.is_empty());
1693 }
1694
1695 #[test]
1696 fn layout_theme_field_names() {
1697 assert_eq!(LayoutTheme::FIELD_NAMES.len(), 4);
1698 assert!(LayoutTheme::FIELD_NAMES.contains(&"widget_gap_px"));
1699 assert!(LayoutTheme::FIELD_NAMES.contains(&"container_margin_px"));
1700 assert!(LayoutTheme::FIELD_NAMES.contains(&"window_margin_px"));
1701 assert!(LayoutTheme::FIELD_NAMES.contains(&"section_gap_px"));
1702 }
1703
1704 #[test]
1705 fn layout_theme_toml_round_trip() {
1706 let l = LayoutTheme {
1707 widget_gap: Some(8.0),
1708 container_margin: Some(12.0),
1709 window_margin: Some(16.0),
1710 section_gap: Some(24.0),
1711 };
1712 let toml_str = toml::to_string(&l).unwrap();
1713 let l2: LayoutTheme = toml::from_str(&toml_str).unwrap();
1714 assert_eq!(l, l2);
1715 }
1716
1717 #[test]
1718 fn layout_theme_merge() {
1719 let mut base = LayoutTheme {
1720 widget_gap: Some(6.0),
1721 container_margin: Some(10.0),
1722 ..Default::default()
1723 };
1724 let overlay = LayoutTheme {
1725 widget_gap: Some(8.0),
1726 section_gap: Some(24.0),
1727 ..Default::default()
1728 };
1729 base.merge(&overlay);
1730 assert_eq!(base.widget_gap, Some(8.0));
1732 assert_eq!(base.container_margin, Some(10.0));
1734 assert_eq!(base.section_gap, Some(24.0));
1736 assert!(base.window_margin.is_none());
1738 }
1739}