Skip to main content

native_theme/model/widgets/
mod.rs

1// Per-widget struct pairs: all 25 per-variant widgets + LayoutTheme use #[derive(ThemeWidget)].
2
3use crate::Rgba;
4use crate::model::border::{ResolvedBorderSpec, WidgetBorderSpec};
5use crate::model::{DialogButtonOrder, FontSpec, ResolvedFontSpec};
6use native_theme_derive::{ThemeFields, ThemeWidget};
7
8// ── 2.2 Window / Application Chrome ────────────────────────────────────────
9
10/// Window chrome: background, title bar colors, inactive states, geometry.
11#[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    /// Main window background fill.
17    #[theme(inherit_from = "defaults.background_color")]
18    pub background_color: Option<Rgba>,
19    /// Active title bar background fill.
20    #[theme(inherit_from = "defaults.surface_color")]
21    pub title_bar_background: Option<Rgba>,
22    /// Title bar background when the window is unfocused.
23    pub inactive_title_bar_background: Option<Rgba>,
24    /// Title bar text color when the window is unfocused.
25    pub inactive_title_bar_text_color: Option<Rgba>,
26    /// Title bar font specification.
27    #[theme(nested, resolved_type = "ResolvedFontSpec")]
28    pub title_bar_font: Option<FontSpec>,
29    /// Window border specification.
30    #[theme(nested, resolved_type = "ResolvedBorderSpec")]
31    pub border: Option<WidgetBorderSpec>,
32}
33
34// ── 2.3 Button ──────────────────────────────────────────────────────────────
35
36/// Push button: colors, sizing, spacing, geometry.
37#[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    /// Default button background fill.
43    #[theme(inherit_from = "defaults.background_color")]
44    pub background_color: Option<Rgba>,
45    /// Primary / accent button background fill.
46    #[theme(inherit_from = "defaults.accent_color")]
47    pub primary_background: Option<Rgba>,
48    /// Primary / accent button text/icon color.
49    #[theme(inherit_from = "defaults.accent_text_color")]
50    pub primary_text_color: Option<Rgba>,
51    /// Minimum button width in logical pixels.
52    #[serde(rename = "min_width_px")]
53    #[theme(check = "non_negative")]
54    pub min_width: Option<f32>,
55    /// Minimum button height in logical pixels.
56    #[serde(rename = "min_height_px")]
57    #[theme(check = "non_negative")]
58    pub min_height: Option<f32>,
59    /// Space between icon and label.
60    #[serde(rename = "icon_text_gap_px")]
61    #[theme(check = "non_negative")]
62    pub icon_text_gap: Option<f32>,
63    /// Opacity multiplier when the button is disabled (0.0-1.0).
64    #[theme(range = "0.0..=1.0", inherit_from = "defaults.disabled_opacity")]
65    pub disabled_opacity: Option<f32>,
66    /// Button background on hover.
67    #[theme(inherit_from = "defaults.background_color")]
68    pub hover_background: Option<Rgba>,
69    /// Button text color on hover.
70    pub hover_text_color: Option<Rgba>,
71    /// Button text color when pressed/active.
72    pub active_text_color: Option<Rgba>,
73    /// Button text color when disabled.
74    #[theme(inherit_from = "defaults.disabled_text_color")]
75    pub disabled_text_color: Option<Rgba>,
76    /// Button background when pressed/active.
77    #[theme(category = "soft_option")]
78    pub active_background: Option<Rgba>,
79    /// Button background when disabled.
80    #[theme(category = "soft_option")]
81    pub disabled_background: Option<Rgba>,
82    /// Button label font specification.
83    #[theme(nested, resolved_type = "ResolvedFontSpec")]
84    pub font: Option<FontSpec>,
85    /// Button border specification.
86    #[theme(nested, resolved_type = "ResolvedBorderSpec")]
87    pub border: Option<WidgetBorderSpec>,
88}
89
90// ── 2.4 Text Input ──────────────────────────────────────────────────────────
91
92/// Single-line and multi-line text input fields.
93#[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    /// Input field background fill.
99    #[theme(inherit_from = "defaults.background_color")]
100    pub background_color: Option<Rgba>,
101    /// Placeholder text color.
102    #[theme(inherit_from = "defaults.muted_color")]
103    pub placeholder_color: Option<Rgba>,
104    /// Text cursor (caret) color.
105    pub caret_color: Option<Rgba>,
106    /// Text selection highlight color.
107    #[theme(inherit_from = "defaults.text_selection_background")]
108    pub selection_background: Option<Rgba>,
109    /// Text color inside the selection highlight.
110    #[theme(inherit_from = "defaults.text_selection_color")]
111    pub selection_text_color: Option<Rgba>,
112    /// Minimum field height in logical pixels.
113    #[serde(rename = "min_height_px")]
114    #[theme(check = "non_negative")]
115    pub min_height: Option<f32>,
116    /// Opacity multiplier when disabled (0.0-1.0).
117    #[theme(range = "0.0..=1.0", inherit_from = "defaults.disabled_opacity")]
118    pub disabled_opacity: Option<f32>,
119    /// Input text color when disabled.
120    #[theme(inherit_from = "defaults.disabled_text_color")]
121    pub disabled_text_color: Option<Rgba>,
122    /// Border color when the input is hovered.
123    #[theme(category = "soft_option")]
124    pub hover_border_color: Option<Rgba>,
125    /// Border color when the input has focus.
126    #[theme(category = "soft_option")]
127    pub focus_border_color: Option<Rgba>,
128    /// Input background when disabled.
129    #[theme(category = "soft_option")]
130    pub disabled_background: Option<Rgba>,
131    /// Input text font specification.
132    #[theme(nested, resolved_type = "ResolvedFontSpec")]
133    pub font: Option<FontSpec>,
134    /// Input border specification.
135    #[theme(nested, resolved_type = "ResolvedBorderSpec")]
136    pub border: Option<WidgetBorderSpec>,
137}
138
139// ── 2.5 Checkbox / Radio Button ────────────────────────────────────────────
140
141/// Checkbox and radio button theme: colors, indicator, label font, border, and interactive states.
142#[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    /// Checkbox background color.
148    #[theme(inherit_from = "defaults.background_color")]
149    pub background_color: Option<Rgba>,
150    /// Indicator background when checked.
151    #[theme(inherit_from = "defaults.accent_color")]
152    pub checked_background: Option<Rgba>,
153    /// Indicator (check mark / radio dot) color.
154    #[theme(inherit_from = "defaults.text_color")]
155    pub indicator_color: Option<Rgba>,
156    /// Indicator (check mark / radio dot) width in logical pixels.
157    #[serde(rename = "indicator_width_px")]
158    #[theme(check = "non_negative")]
159    pub indicator_width: Option<f32>,
160    /// Space between indicator and label.
161    #[serde(rename = "label_gap_px")]
162    #[theme(check = "non_negative")]
163    pub label_gap: Option<f32>,
164    /// Opacity multiplier when disabled (0.0-1.0).
165    #[theme(range = "0.0..=1.0", inherit_from = "defaults.disabled_opacity")]
166    pub disabled_opacity: Option<f32>,
167    /// Checkbox label text color when disabled.
168    #[theme(inherit_from = "defaults.disabled_text_color")]
169    pub disabled_text_color: Option<Rgba>,
170    /// Checkbox background on hover.
171    #[theme(category = "soft_option")]
172    pub hover_background: Option<Rgba>,
173    /// Checkbox background when disabled.
174    #[theme(category = "soft_option")]
175    pub disabled_background: Option<Rgba>,
176    /// Indicator background when unchecked.
177    #[theme(category = "soft_option")]
178    pub unchecked_background: Option<Rgba>,
179    /// Border color when unchecked.
180    #[theme(category = "soft_option")]
181    pub unchecked_border_color: Option<Rgba>,
182    /// Checkbox label font specification.
183    #[theme(nested, resolved_type = "ResolvedFontSpec")]
184    pub font: Option<FontSpec>,
185    /// Checkbox border specification.
186    #[theme(nested, resolved_type = "ResolvedBorderSpec")]
187    pub border: Option<WidgetBorderSpec>,
188}
189
190// ── 2.6 Menu ────────────────────────────────────────────────────────────────
191
192/// Popup and context menu appearance.
193#[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    /// Menu panel background fill.
200    #[theme(inherit_from = "defaults.background_color")]
201    pub background_color: Option<Rgba>,
202    /// Separator line color between menu items.
203    #[theme(inherit_from = "defaults.border.color")]
204    pub separator_color: Option<Rgba>,
205    /// Height of a single menu item row.
206    #[serde(rename = "row_height_px")]
207    #[theme(check = "non_negative")]
208    pub row_height: Option<f32>,
209    /// Space between a menu item's icon and its label.
210    #[serde(rename = "icon_text_gap_px")]
211    #[theme(check = "non_negative")]
212    pub icon_text_gap: Option<f32>,
213    /// Menu item icon size in logical pixels.
214    #[serde(rename = "icon_size_px")]
215    #[theme(check = "non_negative", inherit_from = "defaults.icon_sizes.toolbar")]
216    pub icon_size: Option<f32>,
217    /// Menu item background on hover.
218    #[theme(inherit_from = "defaults.selection_background")]
219    pub hover_background: Option<Rgba>,
220    /// Menu item text color on hover.
221    #[theme(inherit_from = "defaults.selection_text_color")]
222    pub hover_text_color: Option<Rgba>,
223    /// Disabled menu item text color.
224    #[theme(inherit_from = "defaults.disabled_text_color")]
225    pub disabled_text_color: Option<Rgba>,
226    /// Menu item font specification.
227    #[theme(nested, resolved_type = "ResolvedFontSpec")]
228    pub font: Option<FontSpec>,
229    /// Menu border specification.
230    #[theme(nested, resolved_type = "ResolvedBorderSpec")]
231    pub border: Option<WidgetBorderSpec>,
232}
233
234// ── 2.7 Tooltip ─────────────────────────────────────────────────────────────
235
236/// Tooltip popup appearance.
237#[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    /// Tooltip background fill.
243    #[theme(inherit_from = "defaults.background_color")]
244    pub background_color: Option<Rgba>,
245    /// Maximum tooltip width before wrapping.
246    #[serde(rename = "max_width_px")]
247    #[theme(check = "non_negative")]
248    pub max_width: Option<f32>,
249    /// Tooltip font specification.
250    #[theme(nested, resolved_type = "ResolvedFontSpec")]
251    pub font: Option<FontSpec>,
252    /// Tooltip border specification.
253    #[theme(nested, resolved_type = "ResolvedBorderSpec")]
254    pub border: Option<WidgetBorderSpec>,
255}
256
257// ── 2.8 Scrollbar ───────────────────────────────────────────────────────────
258
259/// Scrollbar colors and geometry.
260#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
261#[serde_with::skip_serializing_none]
262#[serde(default)]
263pub struct ScrollbarTheme {
264    /// Scrollbar track (gutter) color.
265    pub track_color: Option<Rgba>,
266    /// Scrollbar thumb color.
267    #[theme(inherit_from = "defaults.muted_color")]
268    pub thumb_color: Option<Rgba>,
269    /// Thumb color on hover.
270    #[theme(inherit_from = "defaults.muted_color")]
271    pub thumb_hover_color: Option<Rgba>,
272    /// Scrollbar groove width in logical pixels.
273    #[serde(rename = "groove_width_px")]
274    #[theme(check = "non_negative")]
275    pub groove_width: Option<f32>,
276    /// Minimum thumb length in logical pixels.
277    #[serde(rename = "min_thumb_length_px")]
278    #[theme(check = "non_negative")]
279    pub min_thumb_length: Option<f32>,
280    /// Width of the thumb rail within the scrollbar.
281    #[serde(rename = "thumb_width_px")]
282    #[theme(check = "non_negative")]
283    pub thumb_width: Option<f32>,
284    /// Whether the scrollbar overlays content instead of taking layout space.
285    pub overlay_mode: Option<bool>,
286    /// Thumb color when pressed/dragging.
287    #[theme(category = "soft_option")]
288    pub thumb_active_color: Option<Rgba>,
289}
290
291// ── 2.9 Slider ──────────────────────────────────────────────────────────────
292
293/// Slider control colors and geometry.
294#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
295#[serde_with::skip_serializing_none]
296#[serde(default)]
297pub struct SliderTheme {
298    /// Filled portion of the slider track.
299    #[theme(inherit_from = "defaults.accent_color")]
300    pub fill_color: Option<Rgba>,
301    /// Unfilled track color.
302    #[theme(inherit_from = "defaults.muted_color")]
303    pub track_color: Option<Rgba>,
304    /// Thumb (handle) color.
305    #[theme(inherit_from = "defaults.surface_color")]
306    pub thumb_color: Option<Rgba>,
307    /// Track height in logical pixels.
308    #[serde(rename = "track_height_px")]
309    #[theme(check = "non_negative")]
310    pub track_height: Option<f32>,
311    /// Thumb diameter in logical pixels.
312    #[serde(rename = "thumb_diameter_px")]
313    #[theme(check = "non_negative")]
314    pub thumb_diameter: Option<f32>,
315    /// Tick mark length in logical pixels.
316    #[serde(rename = "tick_mark_length_px")]
317    #[theme(check = "non_negative")]
318    pub tick_mark_length: Option<f32>,
319    /// Opacity multiplier when disabled (0.0-1.0).
320    #[theme(range = "0.0..=1.0", inherit_from = "defaults.disabled_opacity")]
321    pub disabled_opacity: Option<f32>,
322    /// Thumb color on hover.
323    #[theme(category = "soft_option")]
324    pub thumb_hover_color: Option<Rgba>,
325    /// Filled track color when disabled.
326    #[theme(category = "soft_option")]
327    pub disabled_fill_color: Option<Rgba>,
328    /// Unfilled track color when disabled.
329    #[theme(category = "soft_option")]
330    pub disabled_track_color: Option<Rgba>,
331    /// Thumb color when disabled.
332    #[theme(category = "soft_option")]
333    pub disabled_thumb_color: Option<Rgba>,
334}
335
336// ── 2.10 Progress Bar ───────────────────────────────────────────────────────
337
338/// Progress bar colors and geometry.
339#[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    /// Filled progress bar color.
345    #[theme(inherit_from = "defaults.accent_color")]
346    pub fill_color: Option<Rgba>,
347    /// Background track color.
348    #[theme(inherit_from = "defaults.muted_color")]
349    pub track_color: Option<Rgba>,
350    /// Bar height in logical pixels.
351    #[serde(rename = "track_height_px")]
352    #[theme(check = "non_negative")]
353    pub track_height: Option<f32>,
354    /// Minimum bar width in logical pixels.
355    #[serde(rename = "min_width_px")]
356    #[theme(check = "non_negative")]
357    pub min_width: Option<f32>,
358    /// Progress bar border specification.
359    #[theme(nested, resolved_type = "ResolvedBorderSpec")]
360    pub border: Option<WidgetBorderSpec>,
361}
362
363// ── 2.11 Tab Bar ─────────────────────────────────────────────────────────────
364
365/// Tab bar colors and sizing.
366#[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    /// Inactive tab background.
373    #[theme(inherit_from = "defaults.background_color")]
374    pub background_color: Option<Rgba>,
375    /// Active (selected) tab background.
376    #[theme(inherit_from = "defaults.background_color")]
377    pub active_background: Option<Rgba>,
378    /// Active (selected) tab text color.
379    #[theme(inherit_from = "defaults.text_color")]
380    pub active_text_color: Option<Rgba>,
381    /// Tab bar strip background.
382    #[theme(inherit_from = "defaults.background_color")]
383    pub bar_background: Option<Rgba>,
384    /// Minimum tab width in logical pixels.
385    #[serde(rename = "min_width_px")]
386    #[theme(check = "non_negative")]
387    pub min_width: Option<f32>,
388    /// Minimum tab height in logical pixels.
389    #[serde(rename = "min_height_px")]
390    #[theme(check = "non_negative")]
391    pub min_height: Option<f32>,
392    /// Tab text color on hover.
393    pub hover_text_color: Option<Rgba>,
394    /// Tab background on hover.
395    #[theme(category = "soft_option")]
396    pub hover_background: Option<Rgba>,
397    /// Tab font specification.
398    #[theme(nested, resolved_type = "ResolvedFontSpec")]
399    pub font: Option<FontSpec>,
400    /// Tab border specification.
401    #[theme(nested, resolved_type = "ResolvedBorderSpec")]
402    pub border: Option<WidgetBorderSpec>,
403}
404
405// ── 2.12 Sidebar ─────────────────────────────────────────────────────────────
406
407/// Sidebar panel background, selection, and hover colors.
408#[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    /// Sidebar panel background fill.
415    #[theme(inherit_from = "defaults.background_color")]
416    pub background_color: Option<Rgba>,
417    /// Selected item background color.
418    #[theme(inherit_from = "defaults.selection_background")]
419    pub selection_background: Option<Rgba>,
420    /// Selected item text color.
421    #[theme(inherit_from = "defaults.selection_text_color")]
422    pub selection_text_color: Option<Rgba>,
423    /// Hovered item background color.
424    #[theme(inherit_from = "defaults.background_color")]
425    pub hover_background: Option<Rgba>,
426    /// Sidebar font specification.
427    #[theme(nested, resolved_type = "ResolvedFontSpec")]
428    pub font: Option<FontSpec>,
429    /// Sidebar border specification.
430    #[theme(nested, resolved_type = "ResolvedBorderSpec")]
431    pub border: Option<WidgetBorderSpec>,
432}
433
434// ── 2.13 Toolbar ─────────────────────────────────────────────────────────────
435
436/// Toolbar sizing, spacing, and font.
437#[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    /// Toolbar background color.
443    #[theme(inherit_from = "defaults.background_color")]
444    pub background_color: Option<Rgba>,
445    /// Toolbar height in logical pixels.
446    #[serde(rename = "bar_height_px")]
447    #[theme(check = "non_negative")]
448    pub bar_height: Option<f32>,
449    /// Horizontal space between toolbar items.
450    #[serde(rename = "item_gap_px")]
451    #[theme(check = "non_negative")]
452    pub item_gap: Option<f32>,
453    /// Toolbar icon size in logical pixels.
454    #[serde(rename = "icon_size_px")]
455    #[theme(check = "non_negative", inherit_from = "defaults.icon_sizes.toolbar")]
456    pub icon_size: Option<f32>,
457    /// Toolbar label font specification.
458    #[theme(nested, resolved_type = "ResolvedFontSpec")]
459    pub font: Option<FontSpec>,
460    /// Toolbar border specification.
461    #[theme(nested, resolved_type = "ResolvedBorderSpec")]
462    pub border: Option<WidgetBorderSpec>,
463}
464
465// ── 2.14 Status Bar ──────────────────────────────────────────────────────────
466
467/// Status bar font and background.
468#[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    /// Status bar background color.
475    #[theme(inherit_from = "defaults.background_color")]
476    pub background_color: Option<Rgba>,
477    /// Status bar font specification.
478    #[theme(nested, resolved_type = "ResolvedFontSpec")]
479    pub font: Option<FontSpec>,
480    /// Status bar border specification.
481    #[theme(nested, resolved_type = "ResolvedBorderSpec")]
482    pub border: Option<WidgetBorderSpec>,
483}
484
485// ── 2.15 List / Table ────────────────────────────────────────────────────────
486
487/// List and table colors and row geometry.
488#[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    /// List background fill.
495    pub background_color: Option<Rgba>,
496    /// Alternate row background for striped lists.
497    pub alternate_row_background: Option<Rgba>,
498    /// Selected row highlight color.
499    #[theme(inherit_from = "defaults.selection_background")]
500    pub selection_background: Option<Rgba>,
501    /// Text color inside a selected row.
502    #[theme(inherit_from = "defaults.selection_text_color")]
503    pub selection_text_color: Option<Rgba>,
504    /// Column header background fill.
505    #[theme(inherit_from = "defaults.surface_color")]
506    pub header_background: Option<Rgba>,
507    /// Grid line color between rows/columns.
508    #[theme(inherit_from = "defaults.border.color")]
509    pub grid_color: Option<Rgba>,
510    /// Row height in logical pixels.
511    #[serde(rename = "row_height_px")]
512    #[theme(check = "non_negative")]
513    pub row_height: Option<f32>,
514    /// Hovered row background color.
515    #[theme(inherit_from = "defaults.background_color")]
516    pub hover_background: Option<Rgba>,
517    /// Hovered row text color.
518    pub hover_text_color: Option<Rgba>,
519    /// Disabled row text color.
520    #[theme(inherit_from = "defaults.disabled_text_color")]
521    pub disabled_text_color: Option<Rgba>,
522    /// List item font specification.
523    #[theme(nested, resolved_type = "ResolvedFontSpec")]
524    pub item_font: Option<FontSpec>,
525    /// Column header font specification.
526    #[theme(nested, resolved_type = "ResolvedFontSpec")]
527    pub header_font: Option<FontSpec>,
528    /// List border specification.
529    #[theme(nested, resolved_type = "ResolvedBorderSpec")]
530    pub border: Option<WidgetBorderSpec>,
531}
532
533// ── 2.16 Popover / Dropdown ──────────────────────────────────────────────────
534
535/// Popover / dropdown panel appearance.
536#[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    /// Panel background fill.
542    pub background_color: Option<Rgba>,
543    /// Popover font specification.
544    #[theme(nested, resolved_type = "ResolvedFontSpec")]
545    pub font: Option<FontSpec>,
546    /// Popover border specification.
547    #[theme(nested, resolved_type = "ResolvedBorderSpec")]
548    pub border: Option<WidgetBorderSpec>,
549}
550
551// ── 2.17 Splitter ────────────────────────────────────────────────────────────
552
553/// Splitter handle width and color.
554#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
555#[serde_with::skip_serializing_none]
556#[serde(default)]
557pub struct SplitterTheme {
558    /// Handle width in logical pixels.
559    #[serde(rename = "divider_width_px")]
560    #[theme(check = "non_negative")]
561    pub divider_width: Option<f32>,
562    /// Divider color.
563    #[theme(inherit_from = "defaults.border.color")]
564    pub divider_color: Option<Rgba>,
565    /// Divider color on hover.
566    pub hover_color: Option<Rgba>,
567}
568
569// ── 2.18 Separator ───────────────────────────────────────────────────────────
570
571/// Separator line color and width.
572#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
573#[serde_with::skip_serializing_none]
574#[serde(default)]
575pub struct SeparatorTheme {
576    /// Separator line color.
577    #[theme(inherit_from = "defaults.border.color")]
578    pub line_color: Option<Rgba>,
579    /// Separator line width in logical pixels.
580    #[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// ── 2.21 Switch / Toggle ─────────────────────────────────────────────────────
586
587/// Toggle switch track, thumb, geometry, and interactive states.
588#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
589#[serde_with::skip_serializing_none]
590#[serde(default)]
591pub struct SwitchTheme {
592    /// Track background when the switch is on.
593    #[theme(inherit_from = "defaults.accent_color")]
594    pub checked_background: Option<Rgba>,
595    /// Track background when the switch is off.
596    pub unchecked_background: Option<Rgba>,
597    /// Thumb (knob) color.
598    #[theme(inherit_from = "defaults.surface_color")]
599    pub thumb_background: Option<Rgba>,
600    /// Track width in logical pixels.
601    #[serde(rename = "track_width_px")]
602    #[theme(check = "non_negative")]
603    pub track_width: Option<f32>,
604    /// Track height in logical pixels.
605    #[serde(rename = "track_height_px")]
606    #[theme(check = "non_negative")]
607    pub track_height: Option<f32>,
608    /// Thumb diameter in logical pixels.
609    #[serde(rename = "thumb_diameter_px")]
610    #[theme(check = "non_negative")]
611    pub thumb_diameter: Option<f32>,
612    /// Track corner radius in logical pixels.
613    #[serde(rename = "track_radius_px")]
614    #[theme(check = "non_negative")]
615    pub track_radius: Option<f32>,
616    /// Opacity multiplier when disabled (0.0-1.0).
617    #[theme(range = "0.0..=1.0", inherit_from = "defaults.disabled_opacity")]
618    pub disabled_opacity: Option<f32>,
619    /// Track hover color when checked (on).
620    #[theme(category = "soft_option")]
621    pub hover_checked_background: Option<Rgba>,
622    /// Track hover color when unchecked (off).
623    #[theme(category = "soft_option")]
624    pub hover_unchecked_background: Option<Rgba>,
625    /// Track color when disabled and checked.
626    #[theme(category = "soft_option")]
627    pub disabled_checked_background: Option<Rgba>,
628    /// Track color when disabled and unchecked.
629    #[theme(category = "soft_option")]
630    pub disabled_unchecked_background: Option<Rgba>,
631    /// Thumb color when disabled.
632    #[theme(category = "soft_option")]
633    pub disabled_thumb_color: Option<Rgba>,
634}
635
636// ── 2.22 Dialog ──────────────────────────────────────────────────────────────
637
638/// Dialog sizing, spacing, button order, fonts, border, and background.
639#[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    /// Dialog background color.
646    pub background_color: Option<Rgba>,
647    /// Minimum dialog width in logical pixels.
648    #[serde(rename = "min_width_px")]
649    #[theme(check = "non_negative", min_max_pair = "max_width")]
650    pub min_width: Option<f32>,
651    /// Maximum dialog width in logical pixels.
652    #[serde(rename = "max_width_px")]
653    #[theme(check = "non_negative")]
654    pub max_width: Option<f32>,
655    /// Minimum dialog height in logical pixels.
656    #[serde(rename = "min_height_px")]
657    #[theme(check = "non_negative", min_max_pair = "max_height")]
658    pub min_height: Option<f32>,
659    /// Maximum dialog height in logical pixels.
660    #[serde(rename = "max_height_px")]
661    #[theme(check = "non_negative")]
662    pub max_height: Option<f32>,
663    /// Horizontal space between dialog buttons.
664    #[serde(rename = "button_gap_px")]
665    #[theme(check = "non_negative")]
666    pub button_gap: Option<f32>,
667    /// Icon size for dialog type icons (warning, error, etc.).
668    #[serde(rename = "icon_size_px")]
669    #[theme(check = "non_negative")]
670    pub icon_size: Option<f32>,
671    /// Platform button order convention (e.g., OK/Cancel vs Cancel/OK).
672    pub button_order: Option<DialogButtonOrder>,
673    /// Dialog title font specification.
674    #[theme(nested, resolved_type = "ResolvedFontSpec")]
675    pub title_font: Option<FontSpec>,
676    /// Dialog body font specification.
677    #[theme(nested, resolved_type = "ResolvedFontSpec")]
678    pub body_font: Option<FontSpec>,
679    /// Dialog border specification.
680    #[theme(nested, resolved_type = "ResolvedBorderSpec")]
681    pub border: Option<WidgetBorderSpec>,
682}
683
684// ── 2.23 Spinner / Progress Ring ─────────────────────────────────────────────
685
686/// Spinner / indeterminate progress indicator.
687#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
688#[serde_with::skip_serializing_none]
689#[serde(default)]
690pub struct SpinnerTheme {
691    /// Spinner arc fill color.
692    pub fill_color: Option<Rgba>,
693    /// Spinner outer diameter in logical pixels.
694    #[serde(rename = "diameter_px")]
695    #[theme(check = "non_negative")]
696    pub diameter: Option<f32>,
697    /// Minimum rendered size in logical pixels.
698    #[serde(rename = "min_diameter_px")]
699    #[theme(check = "non_negative")]
700    pub min_diameter: Option<f32>,
701    /// Arc stroke width in logical pixels.
702    #[serde(rename = "stroke_width_px")]
703    #[theme(check = "non_negative")]
704    pub stroke_width: Option<f32>,
705}
706
707// ── 2.24 ComboBox / Dropdown Trigger ─────────────────────────────────────────
708
709/// ComboBox / dropdown trigger sizing.
710#[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    /// ComboBox background color.
716    #[theme(inherit_from = "defaults.background_color")]
717    pub background_color: Option<Rgba>,
718    /// Minimum trigger height in logical pixels.
719    #[serde(rename = "min_height_px")]
720    #[theme(check = "non_negative")]
721    pub min_height: Option<f32>,
722    /// Minimum trigger width in logical pixels.
723    #[serde(rename = "min_width_px")]
724    #[theme(check = "non_negative")]
725    pub min_width: Option<f32>,
726    /// Dropdown arrow size in logical pixels.
727    #[serde(rename = "arrow_icon_size_px")]
728    #[theme(check = "non_negative")]
729    pub arrow_icon_size: Option<f32>,
730    /// Width of the arrow clickable area.
731    #[serde(rename = "arrow_area_width_px")]
732    #[theme(check = "non_negative")]
733    pub arrow_area_width: Option<f32>,
734    /// Opacity multiplier when disabled (0.0-1.0).
735    #[theme(range = "0.0..=1.0", inherit_from = "defaults.disabled_opacity")]
736    pub disabled_opacity: Option<f32>,
737    /// ComboBox text color when disabled.
738    #[theme(inherit_from = "defaults.disabled_text_color")]
739    pub disabled_text_color: Option<Rgba>,
740    /// ComboBox background on hover.
741    #[theme(category = "soft_option")]
742    pub hover_background: Option<Rgba>,
743    /// ComboBox background when disabled.
744    #[theme(category = "soft_option")]
745    pub disabled_background: Option<Rgba>,
746    /// ComboBox font specification.
747    #[theme(nested, resolved_type = "ResolvedFontSpec")]
748    pub font: Option<FontSpec>,
749    /// ComboBox border specification.
750    #[theme(nested, resolved_type = "ResolvedBorderSpec")]
751    pub border: Option<WidgetBorderSpec>,
752}
753
754// ── 2.25 Segmented Control ───────────────────────────────────────────────────
755
756/// Segmented control sizing (macOS-primary; KDE uses tab bar metrics as proxy).
757#[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    /// Segmented control background color.
763    #[theme(inherit_from = "defaults.background_color")]
764    pub background_color: Option<Rgba>,
765    /// Active segment background.
766    #[theme(inherit_from = "defaults.accent_color")]
767    pub active_background: Option<Rgba>,
768    /// Active segment text color.
769    #[theme(inherit_from = "defaults.accent_text_color")]
770    pub active_text_color: Option<Rgba>,
771    /// Segment height in logical pixels.
772    #[serde(rename = "segment_height_px")]
773    #[theme(check = "non_negative")]
774    pub segment_height: Option<f32>,
775    /// Width of the separator between segments.
776    #[serde(rename = "separator_width_px")]
777    #[theme(check = "non_negative")]
778    pub separator_width: Option<f32>,
779    /// Opacity multiplier when disabled (0.0-1.0).
780    #[theme(range = "0.0..=1.0", inherit_from = "defaults.disabled_opacity")]
781    pub disabled_opacity: Option<f32>,
782    /// Segment background on hover.
783    #[theme(category = "soft_option")]
784    pub hover_background: Option<Rgba>,
785    /// Segmented control font specification.
786    #[theme(nested, resolved_type = "ResolvedFontSpec")]
787    pub font: Option<FontSpec>,
788    /// Segmented control border specification.
789    #[theme(nested, resolved_type = "ResolvedBorderSpec")]
790    pub border: Option<WidgetBorderSpec>,
791}
792
793// ── 2.26 Card / Container ────────────────────────────────────────────────────
794
795/// Card / container colors and geometry.
796#[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    /// Card background fill.
802    #[theme(inherit_from = "defaults.surface_color")]
803    pub background_color: Option<Rgba>,
804    /// Card border specification.
805    #[theme(nested, resolved_type = "ResolvedBorderSpec")]
806    pub border: Option<WidgetBorderSpec>,
807}
808
809// ── 2.27 Expander / Disclosure ───────────────────────────────────────────────
810
811/// Expander / disclosure row geometry.
812#[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    /// Collapsed header row height in logical pixels.
818    #[serde(rename = "header_height_px")]
819    #[theme(check = "non_negative")]
820    pub header_height: Option<f32>,
821    /// Disclosure arrow size in logical pixels.
822    #[serde(rename = "arrow_icon_size_px")]
823    #[theme(check = "non_negative")]
824    pub arrow_icon_size: Option<f32>,
825    /// Expander header background on hover.
826    #[theme(category = "soft_option")]
827    pub hover_background: Option<Rgba>,
828    /// Disclosure arrow/chevron color.
829    #[theme(category = "soft_option")]
830    pub arrow_color: Option<Rgba>,
831    /// Expander font specification.
832    #[theme(nested, resolved_type = "ResolvedFontSpec")]
833    pub font: Option<FontSpec>,
834    /// Expander border specification.
835    #[theme(nested, resolved_type = "ResolvedBorderSpec")]
836    pub border: Option<WidgetBorderSpec>,
837}
838
839// ── 2.28 Link ────────────────────────────────────────────────────────────────
840
841/// Hyperlink colors and underline setting.
842#[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    /// Visited link text color.
848    #[theme(inherit_from = "defaults.link_color")]
849    pub visited_text_color: Option<Rgba>,
850    /// Whether links are underlined.
851    pub underline_enabled: Option<bool>,
852    /// Link background fill (typically transparent).
853    pub background_color: Option<Rgba>,
854    /// Link background on hover.
855    pub hover_background: Option<Rgba>,
856    /// Link text color on hover.
857    pub hover_text_color: Option<Rgba>,
858    /// Link text color when pressed/active.
859    pub active_text_color: Option<Rgba>,
860    /// Link text color when disabled.
861    #[theme(inherit_from = "defaults.disabled_text_color")]
862    pub disabled_text_color: Option<Rgba>,
863    /// Link font specification.
864    #[theme(nested, resolved_type = "ResolvedFontSpec")]
865    pub font: Option<FontSpec>,
866}
867
868// -- Layout (top-level, not per-variant) ------------------------------------------
869
870/// Layout spacing constants shared between light and dark variants.
871///
872/// Unlike other widget themes, LayoutTheme lives on [`crate::Theme`] (top-level)
873/// rather than [`crate::ThemeMode`] because spacing is variant-independent.
874// Phase 93-05 G5: LayoutTheme keeps `skip_inventory` so it does NOT register
875// in the per-variant WidgetFieldInfo registry (it is top-level, not per-variant),
876// but also derives ThemeFields so lint_toml can look up its fields in the
877// non-widget FieldInfo registry under the key "LayoutTheme".
878#[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    /// Space between adjacent widgets in logical pixels.
886    #[serde(rename = "widget_gap_px")]
887    #[theme(check = "non_negative")]
888    pub widget_gap: Option<f32>,
889    /// Padding inside containers in logical pixels.
890    #[serde(rename = "container_margin_px")]
891    #[theme(check = "non_negative")]
892    pub container_margin: Option<f32>,
893    /// Padding inside the main window in logical pixels.
894    #[serde(rename = "window_margin_px")]
895    #[theme(check = "non_negative")]
896    pub window_margin: Option<f32>,
897    /// Space between major content sections in logical pixels.
898    #[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    // Test widget using derive (validates derive macro works in test context)
913    /// Test widget for macro verification.
914    #[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    // === ResolvedFontSpec tests ===
928
929    #[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    // === derive(ThemeWidget) generated struct tests ===
944
945    #[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    // === merge tests for generated structs ===
998
999    #[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")); // preserved
1047        assert_eq!(font.size, Some(FontSize::Px(12.0))); // preserved
1048        assert_eq!(font.weight, Some(700)); // overlay sets
1049    }
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    // === impl_merge! optional_nested clause direct tests ===
1096
1097    // Verify the optional_nested clause directly on a FontSpec-containing struct
1098    #[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")); // preserved
1168        assert_eq!(f.size, Some(FontSize::Px(14.0))); // overlay wins
1169        assert_eq!(f.weight, Some(400)); // overlay sets
1170    }
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        // Some(FontSpec::default()) with all-None sub-fields counts as empty (D-2 fix).
1181        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    // === ButtonTheme tests ===
1201
1202    #[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")); // preserved
1239        assert_eq!(f.weight, Some(700)); // overlay
1240    }
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    // === WindowTheme tests ===
1264
1265    #[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    // === DialogTheme tests ===
1294
1295    #[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    // === SplitterTheme tests ===
1324
1325    #[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    // === SeparatorTheme tests ===
1367
1368    #[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    // === All 25 widget theme defaults are empty ===
1378
1379    #[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    // === Representative TOML round-trips ===
1409
1410    #[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    // === SC4: Dual optional_nested (font + border) test widget ===
1483
1484    // SC4: Verify derive handles dual optional_nested (font + border)
1485    /// Test widget with both font and border nested sub-structs.
1486    #[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")); // preserved
1587        assert_eq!(font.size, Some(FontSize::Px(14.0))); // overlay sets
1588    }
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    // === LayoutTheme tests ===
1614
1615    // === validate_widget() generation tests ===
1616
1617    #[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        // soft_option fields pass through as Option
1658        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(); // all None
1665        let mut missing = Vec::new();
1666        let _ = ResolvedButtonTheme::validate_widget(&button, "button", 96.0, &mut missing);
1667        // option fields should be recorded as missing
1668        assert!(missing.contains(&"button.background_color".to_string()));
1669        assert!(missing.contains(&"button.min_width".to_string()));
1670        // font (optional_nested) should be recorded
1671        assert!(missing.contains(&"button.font".to_string()));
1672        // border (optional_nested) should be recorded
1673        assert!(missing.contains(&"button.border".to_string()));
1674        // soft_option fields should NOT be recorded as missing
1675        assert!(!missing.iter().any(|m| m.contains("active_background")));
1676        assert!(!missing.iter().any(|m| m.contains("disabled_background")));
1677    }
1678
1679    // === LayoutTheme tests ===
1680
1681    #[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        // overlay widget_gap replaces base
1731        assert_eq!(base.widget_gap, Some(8.0));
1732        // base container_margin preserved
1733        assert_eq!(base.container_margin, Some(10.0));
1734        // overlay section_gap added
1735        assert_eq!(base.section_gap, Some(24.0));
1736        // window_margin stays None
1737        assert!(base.window_margin.is_none());
1738    }
1739}