Skip to main content

native_theme/model/widgets/
mod.rs

1// Per-widget struct pairs: all 26 per-variant widgets + LayoutTheme use #[derive(ThemeWidget)].
2
3use crate::Rgba;
4use crate::model::border::{ResolvedWidgetBorder, WidgetBorderSpec};
5use crate::model::{
6    ArrowSide, DialogButtonOrder, DialogEntranceStyle, FontSpec, ResolvedFontSpec, TabIndicatorSide,
7};
8use native_theme_derive::{ThemeFields, ThemeWidget};
9
10// ── 2.2 Window / Application Chrome ────────────────────────────────────────
11
12/// Window chrome: background, title bar colors, inactive states, geometry.
13#[serde_with::skip_serializing_none]
14#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
15#[serde(default)]
16#[theme_inherit(border_kind = "full_lg", font = "title_bar_font")]
17pub struct WindowTheme {
18    /// Main window background fill.
19    #[theme(inherit_from = "defaults.background_color")]
20    pub background_color: Option<Rgba>,
21    /// Active title bar background fill.
22    #[theme(inherit_from = "defaults.surface_color")]
23    pub title_bar_background: Option<Rgba>,
24    /// Title bar background when the window is unfocused.
25    pub inactive_title_bar_background: Option<Rgba>,
26    /// Title bar text color when the window is unfocused.
27    pub inactive_title_bar_text_color: Option<Rgba>,
28    /// Title bar font specification.
29    #[theme(nested, resolved_type = "ResolvedFontSpec")]
30    pub title_bar_font: Option<FontSpec>,
31    /// Window border specification.
32    #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
33    pub border: Option<WidgetBorderSpec>,
34}
35
36// ── 2.3 Button ──────────────────────────────────────────────────────────────
37
38/// Push button: colors, sizing, spacing, geometry.
39#[serde_with::skip_serializing_none]
40#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
41#[serde(default)]
42#[theme_inherit(border_kind = "full", font = "font")]
43pub struct ButtonTheme {
44    /// Default button background fill.
45    #[theme(inherit_from = "defaults.background_color")]
46    pub background_color: Option<Rgba>,
47    /// Primary / accent button background fill.
48    #[theme(inherit_from = "defaults.accent_color")]
49    pub primary_background: Option<Rgba>,
50    /// Primary / accent button text/icon color.
51    #[theme(inherit_from = "defaults.accent_text_color")]
52    pub primary_text_color: Option<Rgba>,
53    /// Minimum button width in logical pixels.
54    #[serde(rename = "min_width_px")]
55    #[theme(check = "non_negative")]
56    pub min_width: Option<f32>,
57    /// Minimum button height in logical pixels.
58    #[serde(rename = "min_height_px")]
59    #[theme(check = "non_negative")]
60    pub min_height: Option<f32>,
61    /// Space between icon and label.
62    #[serde(rename = "icon_text_gap_px")]
63    #[theme(check = "non_negative")]
64    pub icon_text_gap: Option<f32>,
65    /// Opacity multiplier when the button is disabled (0.0-1.0), applied to
66    /// the whole button on top of its disabled colours (see
67    /// [`ThemeDefaults::disabled_opacity`](crate::model::ThemeDefaults::disabled_opacity)).
68    #[theme(range = "0.0..=1.0", inherit_from = "defaults.disabled_opacity")]
69    pub disabled_opacity: Option<f32>,
70    /// Button background on hover.
71    #[theme(inherit_from = "defaults.background_color")]
72    pub hover_background: Option<Rgba>,
73    /// Button text color on hover.
74    pub hover_text_color: Option<Rgba>,
75    /// Button text color when pressed/active.
76    pub active_text_color: Option<Rgba>,
77    /// Button text color when disabled.
78    #[theme(inherit_from = "defaults.disabled_text_color")]
79    pub disabled_text_color: Option<Rgba>,
80    /// Button background when pressed/active.
81    #[theme(category = "soft_option")]
82    pub active_background: Option<Rgba>,
83    /// Button background when disabled; `None`, the enabled background.
84    #[theme(category = "soft_option")]
85    pub disabled_background: Option<Rgba>,
86    /// Background of a toggle button that is on (checked): Breeze's
87    /// `Button` mixed an eighth towards `ButtonText`, WinUI's accent fill,
88    /// libadwaita's pressed fill, Material's `secondary`. `None` where the
89    /// platform states none (AppKit); a connector then shows the pressed
90    /// pair, `active_background` and `active_text_color`
91    /// (docs/platform-facts.md §2.3).
92    #[theme(category = "soft_option")]
93    pub checked_background: Option<Rgba>,
94    /// Label color of a toggle button that is on; `None`, as for
95    /// `checked_background`, the pressed pair's (docs/platform-facts.md §2.3).
96    #[theme(category = "soft_option")]
97    pub checked_text_color: Option<Rgba>,
98    /// Button label font specification.
99    #[theme(nested, resolved_type = "ResolvedFontSpec")]
100    pub font: Option<FontSpec>,
101    /// Button border specification.
102    #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
103    pub border: Option<WidgetBorderSpec>,
104}
105
106// ── 2.4 Text Input ──────────────────────────────────────────────────────────
107
108/// Single-line and multi-line text input fields: everything of a multi-line
109/// field but its padding, which is [`TextAreaTheme`]'s.
110#[serde_with::skip_serializing_none]
111#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
112#[serde(default)]
113#[theme_inherit(border_kind = "full", font = "font")]
114pub struct InputTheme {
115    /// Input field background fill.
116    #[theme(inherit_from = "defaults.background_color")]
117    pub background_color: Option<Rgba>,
118    /// Placeholder text color.
119    #[theme(inherit_from = "defaults.muted_color")]
120    pub placeholder_color: Option<Rgba>,
121    /// Text cursor (caret) color.
122    pub caret_color: Option<Rgba>,
123    /// Text selection highlight color.
124    #[theme(inherit_from = "defaults.text_selection_background")]
125    pub selection_background: Option<Rgba>,
126    /// Text color inside the selection highlight.
127    #[theme(inherit_from = "defaults.text_selection_color")]
128    pub selection_text_color: Option<Rgba>,
129    /// Minimum field height in logical pixels.
130    #[serde(rename = "min_height_px")]
131    #[theme(check = "non_negative")]
132    pub min_height: Option<f32>,
133    /// Opacity multiplier when disabled (0.0-1.0), applied to the whole
134    /// widget on top of its disabled colours (see
135    /// [`ThemeDefaults::disabled_opacity`](crate::model::ThemeDefaults::disabled_opacity)).
136    #[theme(range = "0.0..=1.0", inherit_from = "defaults.disabled_opacity")]
137    pub disabled_opacity: Option<f32>,
138    /// Input text color when disabled.
139    #[theme(inherit_from = "defaults.disabled_text_color")]
140    pub disabled_text_color: Option<Rgba>,
141    /// Border color when the input is hovered.
142    #[theme(category = "soft_option")]
143    pub hover_border_color: Option<Rgba>,
144    /// Border color when the input has focus.
145    #[theme(category = "soft_option")]
146    pub focus_border_color: Option<Rgba>,
147    /// Input background when disabled; `None`, the enabled background.
148    #[theme(category = "soft_option")]
149    pub disabled_background: Option<Rgba>,
150    /// Input text font specification.
151    #[theme(nested, resolved_type = "ResolvedFontSpec")]
152    pub font: Option<FontSpec>,
153    /// Input border specification.
154    #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
155    pub border: Option<WidgetBorderSpec>,
156}
157
158// ── 2.29 Text Area (multi-line) ──────────────────────────────────────────────
159
160/// Multi-line text field: the padding in which it differs from the
161/// single-line field. Everything else a text area shows -- its fill, text,
162/// placeholder, caret, selection, states and font -- is [`InputTheme`]'s.
163#[serde_with::skip_serializing_none]
164#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
165#[serde(default)]
166pub struct TextAreaTheme {
167    /// Text area border specification. Its padding sides are the multi-line
168    /// field's own, `None` where the platform states none
169    /// (docs/platform-facts.md §2.29); its colour, corner radius, line width
170    /// and shadow inherit `input.border`'s: the platforms frame both fields
171    /// alike.
172    #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
173    pub border: Option<WidgetBorderSpec>,
174}
175
176// ── 2.5 Checkbox / Radio Button ────────────────────────────────────────────
177
178/// Checkbox and radio button theme: colors, indicator, label font, border, and interactive states.
179#[serde_with::skip_serializing_none]
180#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
181#[serde(default)]
182#[theme_inherit(border_kind = "full", font = "font")]
183pub struct CheckboxTheme {
184    /// Checkbox background color.
185    #[theme(inherit_from = "defaults.background_color")]
186    pub background_color: Option<Rgba>,
187    /// Indicator background when checked.
188    #[theme(inherit_from = "defaults.accent_color")]
189    pub checked_background: Option<Rgba>,
190    /// Indicator (check mark / radio dot) color.
191    #[theme(inherit_from = "defaults.accent_text_color")]
192    pub indicator_color: Option<Rgba>,
193    /// Side length of the checkbox indicator (square), or diameter of the
194    /// radio indicator (circle), in logical pixels: the whole indicator, not
195    /// the mark drawn inside it (docs/platform-facts.md:984).
196    #[serde(rename = "indicator_width_px")]
197    #[theme(check = "non_negative")]
198    pub indicator_width: Option<f32>,
199    /// Diameter of the radio indicator (circle) in logical pixels, where the
200    /// platform sizes it apart from the checkbox's square: Material's radio is
201    /// 20 across, its checkbox 18. `None` where the platform sizes both alike,
202    /// and the radio is `indicator_width` across (docs/platform-facts.md §2.5).
203    #[serde(rename = "radio_indicator_width_px")]
204    #[theme(category = "soft_option", check = "non_negative")]
205    pub radio_indicator_width: Option<f32>,
206    /// Diameter of the filled dot a selected radio button draws at the centre
207    /// of its indicator, in logical pixels. `None` where the platform states
208    /// no dot size: AppKit draws its own (docs/platform-facts.md §2.5).
209    #[serde(rename = "radio_dot_diameter_px")]
210    #[theme(category = "soft_option", check = "non_negative")]
211    pub radio_dot_diameter: Option<f32>,
212    /// Stroke width of the check mark a checked checkbox draws, in logical
213    /// pixels. `None` where the platform states none: WinUI's mark is a font
214    /// glyph and AppKit publishes none (docs/platform-facts.md §2.5).
215    #[serde(rename = "check_mark_stroke_width_px")]
216    #[theme(category = "soft_option", check = "non_negative")]
217    pub check_mark_stroke_width: Option<f32>,
218    /// Space between indicator and label.
219    #[serde(rename = "label_gap_px")]
220    #[theme(check = "non_negative")]
221    pub label_gap: Option<f32>,
222    /// Opacity multiplier when disabled (0.0-1.0), applied to the whole
223    /// widget on top of its disabled colours (see
224    /// [`ThemeDefaults::disabled_opacity`](crate::model::ThemeDefaults::disabled_opacity)).
225    #[theme(range = "0.0..=1.0", inherit_from = "defaults.disabled_opacity")]
226    pub disabled_opacity: Option<f32>,
227    /// Checkbox label text color when disabled.
228    #[theme(inherit_from = "defaults.disabled_text_color")]
229    pub disabled_text_color: Option<Rgba>,
230    /// Checkbox background on hover.
231    #[theme(category = "soft_option")]
232    pub hover_background: Option<Rgba>,
233    /// Checkbox background when disabled; `None`, the enabled box of its
234    /// state (checked or unchecked).
235    #[theme(category = "soft_option")]
236    pub disabled_background: Option<Rgba>,
237    /// Indicator background when unchecked.
238    #[theme(category = "soft_option")]
239    pub unchecked_background: Option<Rgba>,
240    /// Border color when unchecked.
241    #[theme(category = "soft_option")]
242    pub unchecked_border_color: Option<Rgba>,
243    /// Checkbox label font specification.
244    #[theme(nested, resolved_type = "ResolvedFontSpec")]
245    pub font: Option<FontSpec>,
246    /// Checkbox border specification.
247    #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
248    pub border: Option<WidgetBorderSpec>,
249}
250
251// ── 2.6 Menu ────────────────────────────────────────────────────────────────
252
253/// Popup and context menu appearance.
254#[serde_with::skip_serializing_none]
255#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
256#[serde(default)]
257#[theme_layer(border_kind = "none")]
258#[theme_inherit(font = "font")]
259pub struct MenuTheme {
260    /// Menu panel background fill.
261    #[theme(inherit_from = "defaults.background_color")]
262    pub background_color: Option<Rgba>,
263    /// Separator line color between menu items.
264    #[theme(inherit_from = "defaults.border.color")]
265    pub separator_color: Option<Rgba>,
266    /// Height of a single menu item row. `None` where the platform states
267    /// no fixed row height: KDE's menu items size to their content with a
268    /// floor, which this field cannot carry (docs/platform-facts.md §2.6).
269    #[serde(rename = "row_height_px")]
270    #[theme(category = "soft_option", check = "non_negative")]
271    pub row_height: Option<f32>,
272    /// Space between a menu item's icon and its label.
273    #[serde(rename = "icon_text_gap_px")]
274    #[theme(check = "non_negative")]
275    pub icon_text_gap: Option<f32>,
276    /// Menu item icon size in logical pixels.
277    #[serde(rename = "icon_size_px")]
278    #[theme(check = "non_negative", inherit_from = "defaults.icon_sizes.toolbar")]
279    pub icon_size: Option<f32>,
280    /// Menu item background on hover. It may be translucent, a layer over the
281    /// menu's `background_color` (kde-breeze states `#3daee94d`, windows-11
282    /// `#00000009` light and `#ffffff0f` dark): lay it over that fill, with
283    /// [`composite_over`](crate::color::composite_over) where the toolkit
284    /// replaces the fill rather than painting the highlight over it.
285    #[theme(inherit_from = "defaults.selection_background")]
286    pub hover_background: Option<Rgba>,
287    /// Menu item text color on hover.
288    #[theme(inherit_from = "defaults.selection_text_color")]
289    pub hover_text_color: Option<Rgba>,
290    /// Disabled menu item text color.
291    #[theme(inherit_from = "defaults.disabled_text_color")]
292    pub disabled_text_color: Option<Rgba>,
293    /// Menu item font specification.
294    #[theme(nested, resolved_type = "ResolvedFontSpec")]
295    pub font: Option<FontSpec>,
296    /// Menu border specification: its padding insets an item's contents from
297    /// the edges of the item's highlight. Its corner radius is the platform's
298    /// menu radius, which KDE gives a hovered item's highlight and Material the
299    /// menu's container (the iced connector rounds a drop-down's panel with
300    /// it, the egui connector a menu's items). It has no colour of its own:
301    /// the menu's popup frame is the popover's, `popover.border`
302    /// (docs/platform-facts.md §2.6, §2.16). No bundled preset states this border's colour or width; unstated,
303    /// they resolve to transparent and 0.
304    #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
305    pub border: Option<WidgetBorderSpec>,
306}
307
308// ── 2.7 Tooltip ─────────────────────────────────────────────────────────────
309
310/// Tooltip popup appearance.
311#[serde_with::skip_serializing_none]
312#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
313#[serde(default)]
314#[theme_inherit(border_kind = "full", font = "font")]
315pub struct TooltipTheme {
316    /// Tooltip background fill.
317    #[theme(inherit_from = "defaults.background_color")]
318    pub background_color: Option<Rgba>,
319    /// Maximum tooltip width before wrapping.
320    #[serde(rename = "max_width_px")]
321    #[theme(check = "non_negative")]
322    pub max_width: Option<f32>,
323    /// Delay in milliseconds between the pointer coming to rest on an element
324    /// and its tooltip showing. `None` where the platform states none: AppKit
325    /// documents no delay (docs/platform-facts.md §2.7).
326    #[serde(rename = "show_delay_ms")]
327    #[theme(category = "soft_option")]
328    pub show_delay: Option<u16>,
329    /// Tooltip font specification.
330    #[theme(nested, resolved_type = "ResolvedFontSpec")]
331    pub font: Option<FontSpec>,
332    /// Tooltip border specification.
333    #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
334    pub border: Option<WidgetBorderSpec>,
335}
336
337// ── 2.8 Scrollbar ───────────────────────────────────────────────────────────
338
339/// Scrollbar colors and geometry.
340#[serde_with::skip_serializing_none]
341#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
342#[serde(default)]
343pub struct ScrollbarTheme {
344    /// Scrollbar track (gutter) color. A transparent track means the platform
345    /// draws no groove: the view under the bar shows beside the handle
346    /// (kde-breeze, macos-monterey, macos-tahoe and windows-11 state one).
347    pub track_color: Option<Rgba>,
348    /// Scrollbar thumb color.
349    #[theme(inherit_from = "defaults.muted_color")]
350    pub thumb_color: Option<Rgba>,
351    /// Thumb color on hover.
352    #[theme(inherit_from = "defaults.muted_color")]
353    pub thumb_hover_color: Option<Rgba>,
354    /// Scrollbar groove width in logical pixels.
355    #[serde(rename = "groove_width_px")]
356    #[theme(check = "non_negative")]
357    pub groove_width: Option<f32>,
358    /// Minimum thumb length in logical pixels.
359    #[serde(rename = "min_thumb_length_px")]
360    #[theme(check = "non_negative")]
361    pub min_thumb_length: Option<f32>,
362    /// Width of the thumb rail within the scrollbar.
363    #[serde(rename = "thumb_width_px")]
364    #[theme(check = "non_negative")]
365    pub thumb_width: Option<f32>,
366    /// Whether the scrollbar overlays content instead of taking layout space.
367    pub overlay_mode: Option<bool>,
368    /// Thumb color when pressed/dragging.
369    #[theme(category = "soft_option")]
370    pub thumb_active_color: Option<Rgba>,
371}
372
373// ── 2.9 Slider ──────────────────────────────────────────────────────────────
374
375/// Slider control colors and geometry.
376#[serde_with::skip_serializing_none]
377#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
378#[serde(default)]
379pub struct SliderTheme {
380    /// Filled portion of the slider track.
381    #[theme(inherit_from = "defaults.accent_color")]
382    pub fill_color: Option<Rgba>,
383    /// Unfilled track color.
384    #[theme(inherit_from = "defaults.muted_color")]
385    pub track_color: Option<Rgba>,
386    /// Thumb (handle) color.
387    #[theme(inherit_from = "defaults.surface_color")]
388    pub thumb_color: Option<Rgba>,
389    /// Track height in logical pixels.
390    #[serde(rename = "track_height_px")]
391    #[theme(check = "non_negative")]
392    pub track_height: Option<f32>,
393    /// Thumb diameter in logical pixels.
394    #[serde(rename = "thumb_diameter_px")]
395    #[theme(check = "non_negative")]
396    pub thumb_diameter: Option<f32>,
397    /// Tick mark length in logical pixels.
398    #[serde(rename = "tick_mark_length_px")]
399    #[theme(check = "non_negative")]
400    pub tick_mark_length: Option<f32>,
401    /// Opacity multiplier when disabled (0.0-1.0), applied to the whole
402    /// widget on top of its disabled colours (see
403    /// [`ThemeDefaults::disabled_opacity`](crate::model::ThemeDefaults::disabled_opacity)).
404    #[theme(range = "0.0..=1.0", inherit_from = "defaults.disabled_opacity")]
405    pub disabled_opacity: Option<f32>,
406    /// Thumb color on hover.
407    #[theme(category = "soft_option")]
408    pub thumb_hover_color: Option<Rgba>,
409    /// Filled track color when disabled; `None`, the enabled colour (as for
410    /// the two below).
411    #[theme(category = "soft_option")]
412    pub disabled_fill_color: Option<Rgba>,
413    /// Unfilled track color when disabled.
414    #[theme(category = "soft_option")]
415    pub disabled_track_color: Option<Rgba>,
416    /// Thumb color when disabled.
417    #[theme(category = "soft_option")]
418    pub disabled_thumb_color: Option<Rgba>,
419}
420
421// ── 2.10 Progress Bar ───────────────────────────────────────────────────────
422
423/// Progress bar colors and geometry.
424#[serde_with::skip_serializing_none]
425#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
426#[serde(default)]
427#[theme_inherit(border_kind = "full")]
428pub struct ProgressBarTheme {
429    /// Filled progress bar color.
430    #[theme(inherit_from = "defaults.accent_color")]
431    pub fill_color: Option<Rgba>,
432    /// Background track color.
433    #[theme(inherit_from = "defaults.muted_color")]
434    pub track_color: Option<Rgba>,
435    /// Bar height in logical pixels.
436    #[serde(rename = "track_height_px")]
437    #[theme(check = "non_negative")]
438    pub track_height: Option<f32>,
439    /// Minimum bar width in logical pixels.
440    #[serde(rename = "min_width_px")]
441    #[theme(check = "non_negative")]
442    pub min_width: Option<f32>,
443    /// Progress bar border specification.
444    #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
445    pub border: Option<WidgetBorderSpec>,
446}
447
448// ── 2.11 Tab Bar ─────────────────────────────────────────────────────────────
449
450/// Tab bar colors and sizing.
451#[serde_with::skip_serializing_none]
452#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
453#[serde(default)]
454#[theme_layer(border_kind = "none")]
455#[theme_inherit(font = "font")]
456pub struct TabTheme {
457    /// Inactive tab background.
458    #[theme(inherit_from = "defaults.background_color")]
459    pub background_color: Option<Rgba>,
460    /// Active (selected) tab background.
461    #[theme(inherit_from = "defaults.background_color")]
462    pub active_background: Option<Rgba>,
463    /// Active (selected) tab text color.
464    #[theme(inherit_from = "defaults.text_color")]
465    pub active_text_color: Option<Rgba>,
466    /// Tab bar strip background.
467    #[theme(inherit_from = "defaults.background_color")]
468    pub bar_background: Option<Rgba>,
469    /// Minimum tab width in logical pixels.
470    #[serde(rename = "min_width_px")]
471    #[theme(check = "non_negative")]
472    pub min_width: Option<f32>,
473    /// Minimum tab height in logical pixels.
474    #[serde(rename = "min_height_px")]
475    #[theme(check = "non_negative")]
476    pub min_height: Option<f32>,
477    /// Space between adjacent tabs in logical pixels. `None` where the
478    /// platform states none: AppKit publishes no tab spacing
479    /// (docs/platform-facts.md §2.11).
480    #[serde(rename = "item_gap_px")]
481    #[theme(category = "soft_option", check = "non_negative")]
482    pub item_gap: Option<f32>,
483    /// Color of the line that marks the active tab: Breeze's `Highlight`
484    /// strip, libadwaita's accent, Material's `primary` indicator. `None`
485    /// where the platform marks the active tab without one, by its fill and
486    /// border (docs/platform-facts.md §2.11); a connector draws the line only
487    /// where the theme states its color, width and side.
488    #[theme(category = "soft_option")]
489    pub active_indicator_color: Option<Rgba>,
490    /// Thickness of the active tab's indicator line in logical pixels:
491    /// KDE 3, GNOME 4, Material 3 (docs/platform-facts.md §2.11).
492    #[serde(rename = "active_indicator_width_px")]
493    #[theme(category = "soft_option", check = "non_negative")]
494    pub active_indicator_width: Option<f32>,
495    /// Which edge of the active tab its indicator line lies along, for tabs
496    /// above their pages: KDE top, GNOME and Material bottom
497    /// (docs/platform-facts.md §2.11).
498    #[theme(category = "soft_option")]
499    pub active_indicator_side: Option<TabIndicatorSide>,
500    /// Radius of the outward curves at the selected tab's two bottom corners,
501    /// which spread its fill into the bar's bottom edge, as WinUI 3's `TabView`
502    /// draws its selected tab (4, against 8 on its top corners). Where it is
503    /// stated, the selected tab's outline (`border`) has no bottom edge and
504    /// runs on down the curves. `None` where the platform's selected tab does
505    /// not curve out at its feet: all but Windows; macOS publishes no shape
506    /// (docs/platform-facts.md §2.11).
507    #[serde(rename = "active_outward_corner_radius_px")]
508    #[theme(category = "soft_option", check = "non_negative")]
509    pub active_outward_corner_radius: Option<f32>,
510    /// Tab text color on hover.
511    pub hover_text_color: Option<Rgba>,
512    /// Tab background on hover.
513    #[theme(category = "soft_option")]
514    pub hover_background: Option<Rgba>,
515    /// Tab font specification.
516    #[theme(nested, resolved_type = "ResolvedFontSpec")]
517    pub font: Option<FontSpec>,
518    /// Tab border specification.
519    #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
520    pub border: Option<WidgetBorderSpec>,
521}
522
523// ── 2.12 Sidebar ─────────────────────────────────────────────────────────────
524
525/// Sidebar panel background, selection, and hover colors.
526#[serde_with::skip_serializing_none]
527#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
528#[serde(default)]
529#[theme_layer(border_kind = "partial")]
530#[theme_inherit(border_kind = "partial", font = "font")]
531pub struct SidebarTheme {
532    /// Sidebar panel background fill.
533    #[theme(inherit_from = "defaults.background_color")]
534    pub background_color: Option<Rgba>,
535    /// Selected item background color.
536    #[theme(inherit_from = "defaults.selection_background")]
537    pub selection_background: Option<Rgba>,
538    /// Selected item text color.
539    #[theme(inherit_from = "defaults.selection_text_color")]
540    pub selection_text_color: Option<Rgba>,
541    /// Hovered item background color; unstated, the sidebar's own
542    /// `background_color`, no tint (a widget-to-widget rule,
543    /// `resolve_widget_to_widget`).
544    pub hover_background: Option<Rgba>,
545    /// Sidebar font specification.
546    #[theme(nested, resolved_type = "ResolvedFontSpec")]
547    pub font: Option<FontSpec>,
548    /// Sidebar border specification.
549    #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
550    pub border: Option<WidgetBorderSpec>,
551}
552
553// ── 2.13 Toolbar ─────────────────────────────────────────────────────────────
554
555/// Toolbar sizing, spacing, and font.
556#[serde_with::skip_serializing_none]
557#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
558#[serde(default)]
559#[theme_inherit(border_kind = "full", font = "font")]
560pub struct ToolbarTheme {
561    /// Toolbar background color.
562    #[theme(inherit_from = "defaults.background_color")]
563    pub background_color: Option<Rgba>,
564    /// Toolbar height in logical pixels. `None` where the platform states
565    /// no toolbar height: KDE's toolbar sizes to its content, and GNOME's
566    /// `.toolbar` sets no minimum height (docs/platform-facts.md §2.13).
567    #[serde(rename = "bar_height_px")]
568    #[theme(category = "soft_option", check = "non_negative")]
569    pub bar_height: Option<f32>,
570    /// Horizontal space between toolbar items. `None` where the theme cites
571    /// no source for one (docs/platform-facts.md §2.13 states it for every
572    /// platform, but a colour scheme has none).
573    #[serde(rename = "item_gap_px")]
574    #[theme(category = "soft_option", check = "non_negative")]
575    pub item_gap: Option<f32>,
576    /// Toolbar icon size in logical pixels.
577    #[serde(rename = "icon_size_px")]
578    #[theme(check = "non_negative", inherit_from = "defaults.icon_sizes.toolbar")]
579    pub icon_size: Option<f32>,
580    /// Toolbar label font specification.
581    #[theme(nested, resolved_type = "ResolvedFontSpec")]
582    pub font: Option<FontSpec>,
583    /// Toolbar border specification.
584    #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
585    pub border: Option<WidgetBorderSpec>,
586}
587
588// ── 2.14 Status Bar ──────────────────────────────────────────────────────────
589
590/// Status bar font and background.
591#[serde_with::skip_serializing_none]
592#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
593#[serde(default)]
594#[theme_layer(border_kind = "partial")]
595#[theme_inherit(border_kind = "partial", font = "font")]
596pub struct StatusBarTheme {
597    /// Status bar background color.
598    #[theme(inherit_from = "defaults.background_color")]
599    pub background_color: Option<Rgba>,
600    /// Status bar font specification.
601    #[theme(nested, resolved_type = "ResolvedFontSpec")]
602    pub font: Option<FontSpec>,
603    /// Status bar border specification.
604    #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
605    pub border: Option<WidgetBorderSpec>,
606}
607
608// ── 2.15 List / Table ────────────────────────────────────────────────────────
609
610/// List and table colors and row geometry.
611#[serde_with::skip_serializing_none]
612#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
613#[serde(default)]
614#[theme_inherit(border_kind = "full", font = "item_font")]
615#[theme_inherit(font = "header_font")]
616pub struct ListTheme {
617    /// List background fill.
618    pub background_color: Option<Rgba>,
619    /// Alternate row background for striped lists.
620    pub alternate_row_background: Option<Rgba>,
621    /// Selected row highlight color.
622    #[theme(inherit_from = "defaults.selection_background")]
623    pub selection_background: Option<Rgba>,
624    /// Text color inside a selected row.
625    #[theme(inherit_from = "defaults.selection_text_color")]
626    pub selection_text_color: Option<Rgba>,
627    /// Column header background fill.
628    #[theme(inherit_from = "defaults.surface_color")]
629    pub header_background: Option<Rgba>,
630    /// Grid line color between rows/columns: a table's grid. A separating
631    /// line elsewhere takes `separator.line_color`.
632    #[theme(inherit_from = "defaults.border.color")]
633    pub grid_color: Option<Rgba>,
634    /// Row height in logical pixels. `None` where the platform states no row
635    /// height: KDE's rows size to their content, and GNOME's plain list sets
636    /// no minimum height (docs/platform-facts.md §2.15).
637    #[serde(rename = "row_height_px")]
638    #[theme(category = "soft_option", check = "non_negative")]
639    pub row_height: Option<f32>,
640    /// Column header row height in logical pixels. `None` where the platform
641    /// states none: KDE's header sizes to its content, and WinUI has no
642    /// column header (docs/platform-facts.md §2.15).
643    #[serde(rename = "header_height_px")]
644    #[theme(category = "soft_option", check = "positive")]
645    pub header_height: Option<f32>,
646    /// Hovered row background color; unstated, the list's own
647    /// `background_color`, no tint (a widget-to-widget rule,
648    /// `resolve_widget_to_widget`). It may be translucent, a layer over the
649    /// row's fill (kde-breeze states `#3daee94d`, windows-11 `#00000009` light
650    /// and `#ffffff0f` dark): lay it over that fill, with
651    /// [`composite_over`](crate::color::composite_over) where the toolkit
652    /// replaces the fill rather than painting the highlight over it.
653    pub hover_background: Option<Rgba>,
654    /// Hovered row text color.
655    pub hover_text_color: Option<Rgba>,
656    /// Disabled row text color.
657    #[theme(inherit_from = "defaults.disabled_text_color")]
658    pub disabled_text_color: Option<Rgba>,
659    /// List item font specification.
660    #[theme(nested, resolved_type = "ResolvedFontSpec")]
661    pub item_font: Option<FontSpec>,
662    /// Column header font specification.
663    #[theme(nested, resolved_type = "ResolvedFontSpec")]
664    pub header_font: Option<FontSpec>,
665    /// List border specification.
666    #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
667    pub border: Option<WidgetBorderSpec>,
668}
669
670// ── 2.16 Popover / Dropdown ──────────────────────────────────────────────────
671
672/// Popover / dropdown panel appearance.
673#[serde_with::skip_serializing_none]
674#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
675#[serde(default)]
676#[theme_inherit(border_kind = "full_lg", font = "font")]
677pub struct PopoverTheme {
678    /// Panel background fill.
679    pub background_color: Option<Rgba>,
680    /// Popover font specification.
681    #[theme(nested, resolved_type = "ResolvedFontSpec")]
682    pub font: Option<FontSpec>,
683    /// Popover border specification.
684    #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
685    pub border: Option<WidgetBorderSpec>,
686}
687
688// ── 2.17 Splitter ────────────────────────────────────────────────────────────
689
690/// Splitter handle width and color.
691#[serde_with::skip_serializing_none]
692#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
693#[serde(default)]
694pub struct SplitterTheme {
695    /// Handle width in logical pixels.
696    #[serde(rename = "divider_width_px")]
697    #[theme(check = "non_negative")]
698    pub divider_width: Option<f32>,
699    /// Divider color.
700    #[theme(inherit_from = "defaults.border.color")]
701    pub divider_color: Option<Rgba>,
702    /// Divider color on hover.
703    pub hover_color: Option<Rgba>,
704}
705
706// ── 2.18 Separator ───────────────────────────────────────────────────────────
707
708/// Separator line color and width.
709#[serde_with::skip_serializing_none]
710#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
711#[serde(default)]
712pub struct SeparatorTheme {
713    /// Separator line color.
714    #[theme(inherit_from = "defaults.border.color")]
715    pub line_color: Option<Rgba>,
716    /// Separator line width in logical pixels.
717    #[serde(rename = "line_width_px")]
718    #[theme(check = "non_negative", inherit_from = "defaults.border.line_width")]
719    pub line_width: Option<f32>,
720}
721
722// ── 2.21 Switch / Toggle ─────────────────────────────────────────────────────
723
724/// Toggle switch track, thumb, geometry, and interactive states.
725#[serde_with::skip_serializing_none]
726#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
727#[serde(default)]
728pub struct SwitchTheme {
729    /// Track background when the switch is on.
730    #[theme(inherit_from = "defaults.accent_color")]
731    pub checked_background: Option<Rgba>,
732    /// Track background when the switch is off.
733    pub unchecked_background: Option<Rgba>,
734    /// Thumb (knob) color; while the switch is off, `unchecked_thumb_background`
735    /// where the theme states one.
736    #[theme(inherit_from = "defaults.surface_color")]
737    pub thumb_background: Option<Rgba>,
738    /// Thumb color while the switch is off, where the platform colours it
739    /// apart: Material's `outline`, WinUI's `TextFillColorSecondary`,
740    /// libadwaita's `$slider_color`. `None` where the thumb is one colour in
741    /// both states, `thumb_background` (docs/platform-facts.md §2.21).
742    #[theme(category = "soft_option")]
743    pub unchecked_thumb_background: Option<Rgba>,
744    /// Track width in logical pixels.
745    #[serde(rename = "track_width_px")]
746    #[theme(check = "non_negative")]
747    pub track_width: Option<f32>,
748    /// Track height in logical pixels.
749    #[serde(rename = "track_height_px")]
750    #[theme(check = "non_negative")]
751    pub track_height: Option<f32>,
752    /// Thumb diameter in logical pixels; while the switch is off,
753    /// `unchecked_thumb_diameter` where the theme states one. A thumb
754    /// shorter than the track is centred in it; a taller one overhangs it
755    /// above and below and sits flush with its ends, as qqc2-desktop-style's
756    /// (docs/platform-facts.md §2.21).
757    #[serde(rename = "thumb_diameter_px")]
758    #[theme(check = "non_negative")]
759    pub thumb_diameter: Option<f32>,
760    /// Thumb diameter while the switch is off, in logical pixels, where the
761    /// platform sizes it apart: Material's is 16 off, 24 on. `None` where the
762    /// thumb is one size in both states, `thumb_diameter`
763    /// (docs/platform-facts.md §2.21).
764    #[serde(rename = "unchecked_thumb_diameter_px")]
765    #[theme(category = "soft_option", check = "non_negative")]
766    pub unchecked_thumb_diameter: Option<f32>,
767    /// Track corner radius in logical pixels.
768    #[serde(rename = "track_radius_px")]
769    #[theme(check = "non_negative")]
770    pub track_radius: Option<f32>,
771    /// Opacity multiplier when disabled (0.0-1.0), applied to the whole
772    /// widget on top of its disabled colours (see
773    /// [`ThemeDefaults::disabled_opacity`](crate::model::ThemeDefaults::disabled_opacity)).
774    #[theme(range = "0.0..=1.0", inherit_from = "defaults.disabled_opacity")]
775    pub disabled_opacity: Option<f32>,
776    /// Track hover color when checked (on).
777    #[theme(category = "soft_option")]
778    pub hover_checked_background: Option<Rgba>,
779    /// Track hover color when unchecked (off).
780    #[theme(category = "soft_option")]
781    pub hover_unchecked_background: Option<Rgba>,
782    /// Track color when disabled and checked; `None`, the enabled colour (as
783    /// for the two below).
784    #[theme(category = "soft_option")]
785    pub disabled_checked_background: Option<Rgba>,
786    /// Track color when disabled and unchecked.
787    #[theme(category = "soft_option")]
788    pub disabled_unchecked_background: Option<Rgba>,
789    /// Thumb color when disabled.
790    #[theme(category = "soft_option")]
791    pub disabled_thumb_color: Option<Rgba>,
792    /// The off track's outline, `track_border_line_width` wide inside the
793    /// track: WinUI's `ToggleSwitchStrokeOff`, Material's
794    /// `unselected-track-outline-color`, qqc2-desktop-style's
795    /// `handleBorderColor`. `None` draws no outline, as libadwaita and
796    /// macOS (docs/platform-facts.md §2.21).
797    #[theme(category = "soft_option")]
798    pub unchecked_track_border_color: Option<Rgba>,
799    /// The on track's outline: qqc2-desktop-style's `highlightColor`. `None`
800    /// draws none, as WinUI and Material, which outline only the off track
801    /// (docs/platform-facts.md §2.21).
802    #[theme(category = "soft_option")]
803    pub checked_track_border_color: Option<Rgba>,
804    /// The off track's outline when disabled; `None`, the enabled one (as
805    /// for the one below).
806    #[theme(category = "soft_option")]
807    pub disabled_unchecked_track_border_color: Option<Rgba>,
808    /// The on track's outline when disabled.
809    #[theme(category = "soft_option")]
810    pub disabled_checked_track_border_color: Option<Rgba>,
811    /// The track outline's width in logical pixels, on and off; `None`
812    /// draws no outline.
813    #[serde(rename = "track_border_line_width_px")]
814    #[theme(category = "soft_option", check = "non_negative")]
815    pub track_border_line_width: Option<f32>,
816    /// The thumb's outline, `thumb_border_line_width` wide inside the thumb,
817    /// on and off: qqc2-desktop-style's `handleBorderColor`. `None` draws
818    /// none (docs/platform-facts.md §2.21).
819    #[theme(category = "soft_option")]
820    pub thumb_border_color: Option<Rgba>,
821    /// The thumb outline's width in logical pixels; `None` draws no outline.
822    #[serde(rename = "thumb_border_line_width_px")]
823    #[theme(category = "soft_option", check = "non_negative")]
824    pub thumb_border_line_width: Option<f32>,
825}
826
827// ── 2.22 Dialog ──────────────────────────────────────────────────────────────
828
829/// Dialog sizing, spacing, button order, fonts, border, and background.
830#[serde_with::skip_serializing_none]
831#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
832#[serde(default)]
833#[theme_inherit(border_kind = "full_lg", font = "title_font")]
834#[theme_inherit(font = "body_font")]
835pub struct DialogTheme {
836    /// Dialog background color.
837    pub background_color: Option<Rgba>,
838    /// Minimum dialog width in logical pixels.
839    #[serde(rename = "min_width_px")]
840    #[theme(check = "non_negative", min_max_pair = "max_width")]
841    pub min_width: Option<f32>,
842    /// Maximum dialog width in logical pixels.
843    #[serde(rename = "max_width_px")]
844    #[theme(check = "non_negative")]
845    pub max_width: Option<f32>,
846    /// Minimum dialog height in logical pixels.
847    #[serde(rename = "min_height_px")]
848    #[theme(check = "non_negative", min_max_pair = "max_height")]
849    pub min_height: Option<f32>,
850    /// Maximum dialog height in logical pixels.
851    #[serde(rename = "max_height_px")]
852    #[theme(check = "non_negative")]
853    pub max_height: Option<f32>,
854    /// Horizontal space between dialog buttons.
855    #[serde(rename = "button_gap_px")]
856    #[theme(check = "non_negative")]
857    pub button_gap: Option<f32>,
858    /// Icon size for dialog type icons (warning, error, etc.).
859    #[serde(rename = "icon_size_px")]
860    #[theme(check = "non_negative")]
861    pub icon_size: Option<f32>,
862    /// Platform button order convention (e.g., OK/Cancel vs Cancel/OK).
863    pub button_order: Option<DialogButtonOrder>,
864    /// How the dialog moves onto the screen as it opens: scaling up while it
865    /// fades in, or fading in while it rises into place. `None` where the
866    /// platform states none: AppKit names no dialog motion
867    /// (docs/platform-facts.md §2.22).
868    #[theme(category = "soft_option")]
869    pub entrance: Option<DialogEntranceStyle>,
870    /// Dialog title font specification.
871    #[theme(nested, resolved_type = "ResolvedFontSpec")]
872    pub title_font: Option<FontSpec>,
873    /// Dialog body font specification.
874    #[theme(nested, resolved_type = "ResolvedFontSpec")]
875    pub body_font: Option<FontSpec>,
876    /// Dialog border specification.
877    #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
878    pub border: Option<WidgetBorderSpec>,
879}
880
881// ── 2.23 Spinner / Progress Ring ─────────────────────────────────────────────
882
883/// Spinner / indeterminate progress indicator.
884#[serde_with::skip_serializing_none]
885#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
886#[serde(default)]
887pub struct SpinnerTheme {
888    /// Spinner arc fill color.
889    pub fill_color: Option<Rgba>,
890    /// Spinner outer diameter in logical pixels.
891    #[serde(rename = "diameter_px")]
892    #[theme(check = "non_negative")]
893    pub diameter: Option<f32>,
894    /// Minimum rendered size in logical pixels.
895    #[serde(rename = "min_diameter_px")]
896    #[theme(check = "non_negative")]
897    pub min_diameter: Option<f32>,
898    /// Arc stroke width in logical pixels.
899    #[serde(rename = "stroke_width_px")]
900    #[theme(check = "non_negative")]
901    pub stroke_width: Option<f32>,
902}
903
904// ── 2.24 ComboBox / Dropdown Trigger ─────────────────────────────────────────
905
906/// ComboBox / dropdown trigger sizing.
907#[serde_with::skip_serializing_none]
908#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
909#[serde(default)]
910#[theme_inherit(border_kind = "full", font = "font")]
911pub struct ComboBoxTheme {
912    /// ComboBox background color.
913    #[theme(inherit_from = "defaults.background_color")]
914    pub background_color: Option<Rgba>,
915    /// Minimum trigger height in logical pixels.
916    #[serde(rename = "min_height_px")]
917    #[theme(check = "non_negative")]
918    pub min_height: Option<f32>,
919    /// Minimum trigger width in logical pixels.
920    #[serde(rename = "min_width_px")]
921    #[theme(check = "non_negative")]
922    pub min_width: Option<f32>,
923    /// Dropdown arrow size in logical pixels.
924    #[serde(rename = "arrow_icon_size_px")]
925    #[theme(check = "non_negative")]
926    pub arrow_icon_size: Option<f32>,
927    /// Width of the arrow clickable area, in logical pixels. `None` where the
928    /// theme states no width (docs/platform-facts.md §2.24): GNOME's dropdown
929    /// draws its arrow inline, macOS's width is only a measured range
930    /// (~16–18px), and the iOS and Material platform presets and the community
931    /// colour-scheme presets cite none.
932    #[serde(rename = "arrow_area_width_px")]
933    #[theme(category = "soft_option", check = "non_negative")]
934    pub arrow_area_width: Option<f32>,
935    /// Opacity multiplier when disabled (0.0-1.0), applied to the whole
936    /// widget on top of its disabled colours (see
937    /// [`ThemeDefaults::disabled_opacity`](crate::model::ThemeDefaults::disabled_opacity)).
938    #[theme(range = "0.0..=1.0", inherit_from = "defaults.disabled_opacity")]
939    pub disabled_opacity: Option<f32>,
940    /// ComboBox text color when disabled.
941    #[theme(inherit_from = "defaults.disabled_text_color")]
942    pub disabled_text_color: Option<Rgba>,
943    /// ComboBox background on hover.
944    #[theme(category = "soft_option")]
945    pub hover_background: Option<Rgba>,
946    /// ComboBox background when disabled; `None`, the enabled background.
947    #[theme(category = "soft_option")]
948    pub disabled_background: Option<Rgba>,
949    /// ComboBox font specification.
950    #[theme(nested, resolved_type = "ResolvedFontSpec")]
951    pub font: Option<FontSpec>,
952    /// ComboBox border specification.
953    #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
954    pub border: Option<WidgetBorderSpec>,
955}
956
957// ── 2.25 Segmented Control ───────────────────────────────────────────────────
958
959/// Segmented control sizing (macOS-primary; KDE uses tab bar metrics as proxy).
960#[serde_with::skip_serializing_none]
961#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
962#[serde(default)]
963#[theme_inherit(border_kind = "full", font = "font")]
964pub struct SegmentedControlTheme {
965    /// Segmented control background color.
966    #[theme(inherit_from = "defaults.background_color")]
967    pub background_color: Option<Rgba>,
968    /// Active segment background.
969    #[theme(inherit_from = "defaults.accent_color")]
970    pub active_background: Option<Rgba>,
971    /// Active segment text color.
972    #[theme(inherit_from = "defaults.accent_text_color")]
973    pub active_text_color: Option<Rgba>,
974    /// Segment height in logical pixels.
975    #[serde(rename = "segment_height_px")]
976    #[theme(check = "non_negative")]
977    pub segment_height: Option<f32>,
978    /// Width of the separator between segments.
979    #[serde(rename = "separator_width_px")]
980    #[theme(check = "non_negative")]
981    pub separator_width: Option<f32>,
982    /// Opacity multiplier when disabled (0.0-1.0), applied to the whole
983    /// widget on top of its disabled colours (see
984    /// [`ThemeDefaults::disabled_opacity`](crate::model::ThemeDefaults::disabled_opacity)).
985    #[theme(range = "0.0..=1.0", inherit_from = "defaults.disabled_opacity")]
986    pub disabled_opacity: Option<f32>,
987    /// Segment background on hover.
988    #[theme(category = "soft_option")]
989    pub hover_background: Option<Rgba>,
990    /// Segmented control font specification.
991    #[theme(nested, resolved_type = "ResolvedFontSpec")]
992    pub font: Option<FontSpec>,
993    /// Segmented control border specification.
994    #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
995    pub border: Option<WidgetBorderSpec>,
996}
997
998// ── 2.26 Card / Container ────────────────────────────────────────────────────
999
1000/// Card / container colors and geometry.
1001#[serde_with::skip_serializing_none]
1002#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
1003#[serde(default)]
1004#[theme_layer(border_kind = "none")]
1005pub struct CardTheme {
1006    /// Card background fill.
1007    #[theme(inherit_from = "defaults.surface_color")]
1008    pub background_color: Option<Rgba>,
1009    /// Card border specification.
1010    #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
1011    pub border: Option<WidgetBorderSpec>,
1012}
1013
1014// ── 2.27 Expander / Disclosure ───────────────────────────────────────────────
1015
1016/// Expander / disclosure row geometry.
1017#[serde_with::skip_serializing_none]
1018#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
1019#[serde(default)]
1020#[theme_inherit(border_kind = "full", font = "font")]
1021pub struct ExpanderTheme {
1022    /// Collapsed header row height in logical pixels.
1023    #[serde(rename = "header_height_px")]
1024    #[theme(check = "non_negative")]
1025    pub header_height: Option<f32>,
1026    /// Disclosure arrow size in logical pixels.
1027    #[serde(rename = "arrow_icon_size_px")]
1028    #[theme(check = "non_negative")]
1029    pub arrow_icon_size: Option<f32>,
1030    /// Expander header background on hover.
1031    #[theme(category = "soft_option")]
1032    pub hover_background: Option<Rgba>,
1033    /// Disclosure arrow/chevron color.
1034    #[theme(category = "soft_option")]
1035    pub arrow_color: Option<Rgba>,
1036    /// Which end of the header row the disclosure arrow sits at: before the
1037    /// title, or at the row's end. `None` where the theme states none
1038    /// (docs/platform-facts.md §2.27).
1039    #[theme(category = "soft_option")]
1040    pub arrow_side: Option<ArrowSide>,
1041    /// Space between the arrow's icon box (`arrow_icon_size` square) and the
1042    /// title after it, or, for a trailing arrow, the header content before
1043    /// it, in logical pixels. `None` where the platform states none: AppKit
1044    /// documents no disclosure geometry (docs/platform-facts.md §2.27).
1045    #[serde(rename = "arrow_gap_px")]
1046    #[theme(category = "soft_option", check = "non_negative")]
1047    pub arrow_gap: Option<f32>,
1048    /// Horizontal distance from the expander's leading inner edge (inside
1049    /// its frame, where it has one) to the content it reveals, in logical
1050    /// pixels. `None` where the platform states none: AppKit documents no
1051    /// disclosure geometry (docs/platform-facts.md §2.27).
1052    #[serde(rename = "content_indent_px")]
1053    #[theme(category = "soft_option", check = "non_negative")]
1054    pub content_indent: Option<f32>,
1055    /// Whether the expander draws a frame (its `border`) around its header
1056    /// and the content it reveals: KDE's has none, libadwaita's and WinUI's
1057    /// are framed. `None` where the theme states none
1058    /// (docs/platform-facts.md §2.27).
1059    #[theme(category = "soft_option")]
1060    pub frame_enabled: Option<bool>,
1061    /// Expander font specification.
1062    #[theme(nested, resolved_type = "ResolvedFontSpec")]
1063    pub font: Option<FontSpec>,
1064    /// Expander border specification.
1065    #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
1066    pub border: Option<WidgetBorderSpec>,
1067}
1068
1069// ── 2.28 Link ────────────────────────────────────────────────────────────────
1070
1071/// Hyperlink colors and underline setting.
1072#[serde_with::skip_serializing_none]
1073#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
1074#[serde(default)]
1075#[theme_inherit(font = "font")]
1076pub struct LinkTheme {
1077    /// Visited link text color.
1078    #[theme(inherit_from = "defaults.link_color")]
1079    pub visited_text_color: Option<Rgba>,
1080    /// Whether links are underlined.
1081    pub underline_enabled: Option<bool>,
1082    /// Link background fill (typically transparent).
1083    pub background_color: Option<Rgba>,
1084    /// Link background on hover.
1085    pub hover_background: Option<Rgba>,
1086    /// Link text color on hover.
1087    pub hover_text_color: Option<Rgba>,
1088    /// Link text color when pressed/active.
1089    pub active_text_color: Option<Rgba>,
1090    /// Link text color when disabled.
1091    #[theme(inherit_from = "defaults.disabled_text_color")]
1092    pub disabled_text_color: Option<Rgba>,
1093    /// Link font specification.
1094    #[theme(nested, resolved_type = "ResolvedFontSpec")]
1095    pub font: Option<FontSpec>,
1096}
1097
1098// -- Layout (top-level, not per-variant) ------------------------------------------
1099
1100/// Layout spacing constants shared between light and dark variants.
1101///
1102/// Unlike other widget themes, LayoutTheme lives on [`crate::Theme`] (top-level)
1103/// rather than [`crate::ThemeMode`] because spacing is variant-independent.
1104// Phase 93-05 G5: LayoutTheme keeps `skip_inventory` so it does NOT register
1105// in the per-variant WidgetFieldInfo registry (it is top-level, not per-variant),
1106// but also derives ThemeFields so lint_toml can look up its fields in the
1107// non-widget FieldInfo registry under the key "LayoutTheme".
1108#[serde_with::skip_serializing_none]
1109#[derive(
1110    Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget, ThemeFields,
1111)]
1112#[serde(default)]
1113#[theme_layer(skip_inventory)]
1114pub struct LayoutTheme {
1115    /// Space between adjacent widgets in logical pixels.
1116    #[serde(rename = "widget_gap_px")]
1117    #[theme(check = "non_negative")]
1118    pub widget_gap: Option<f32>,
1119    /// Padding inside containers in logical pixels.
1120    #[serde(rename = "container_margin_px")]
1121    #[theme(check = "non_negative")]
1122    pub container_margin: Option<f32>,
1123    /// Padding inside the main window in logical pixels.
1124    #[serde(rename = "window_margin_px")]
1125    #[theme(check = "non_negative")]
1126    pub window_margin: Option<f32>,
1127    /// Space between major content sections in logical pixels.
1128    #[serde(rename = "section_gap_px")]
1129    #[theme(check = "non_negative")]
1130    pub section_gap: Option<f32>,
1131}
1132
1133#[cfg(test)]
1134#[allow(clippy::unwrap_used, clippy::expect_used, dead_code)]
1135mod tests {
1136    use super::*;
1137    use crate::Rgba;
1138    use crate::model::border::{ResolvedWidgetBorder, WidgetBorderSpec};
1139    use crate::model::font::FontSize;
1140    use crate::model::{DialogButtonOrder, FontSpec};
1141
1142    // Test widget using derive (validates derive macro works in test context)
1143    /// Test widget for macro verification.
1144    #[serde_with::skip_serializing_none]
1145    #[derive(
1146        Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget,
1147    )]
1148    #[serde(default)]
1149    #[theme_layer(skip_inventory)]
1150    pub struct TestWidget {
1151        pub size: Option<f32>,
1152        pub label: Option<String>,
1153        #[theme(nested, resolved_type = "ResolvedFontSpec")]
1154        pub font: Option<FontSpec>,
1155    }
1156
1157    // === ResolvedFontSpec tests ===
1158
1159    #[test]
1160    fn resolved_font_spec_fields_are_concrete() {
1161        let rfs = ResolvedFontSpec {
1162            family: "Inter".into(),
1163            size: 14.0,
1164            defined_size: Some(crate::model::font::FontSize::Px(14.0)),
1165            weight: 400,
1166            style: crate::model::font::FontStyle::Normal,
1167            color: crate::Rgba::rgb(0, 0, 0),
1168        };
1169        assert_eq!(rfs.family.as_ref(), "Inter");
1170        assert_eq!(rfs.size, 14.0);
1171        assert_eq!(rfs.weight, 400);
1172    }
1173
1174    // === derive(ThemeWidget) generated struct tests ===
1175
1176    #[test]
1177    fn generated_option_struct_has_option_fields() {
1178        let w = TestWidget::default();
1179        assert!(w.size.is_none());
1180        assert!(w.label.is_none());
1181        assert!(w.font.is_none());
1182    }
1183
1184    #[test]
1185    fn generated_option_struct_is_empty_by_default() {
1186        assert!(TestWidget::default().is_empty());
1187    }
1188
1189    #[test]
1190    fn generated_option_struct_not_empty_when_size_set() {
1191        let w = TestWidget {
1192            size: Some(24.0),
1193            ..Default::default()
1194        };
1195        assert!(!w.is_empty());
1196    }
1197
1198    #[test]
1199    fn generated_option_struct_not_empty_when_font_set() {
1200        let w = TestWidget {
1201            font: Some(FontSpec {
1202                size: Some(FontSize::Px(14.0)),
1203                ..Default::default()
1204            }),
1205            ..Default::default()
1206        };
1207        assert!(!w.is_empty());
1208    }
1209
1210    #[test]
1211    fn generated_resolved_struct_has_concrete_fields() {
1212        let resolved = ResolvedTestWidget {
1213            size: 24.0,
1214            label: "Click me".into(),
1215            font: ResolvedFontSpec {
1216                family: "Inter".into(),
1217                size: 14.0,
1218                defined_size: Some(crate::model::font::FontSize::Px(14.0)),
1219                weight: 400,
1220                style: crate::model::font::FontStyle::Normal,
1221                color: crate::Rgba::rgb(0, 0, 0),
1222            },
1223        };
1224        assert_eq!(resolved.size, 24.0);
1225        assert_eq!(resolved.label, "Click me");
1226        assert_eq!(resolved.font.family.as_ref(), "Inter");
1227    }
1228
1229    // === merge tests for generated structs ===
1230
1231    #[test]
1232    fn generated_merge_option_field_overlay_wins() {
1233        let mut base = TestWidget {
1234            size: Some(20.0),
1235            ..Default::default()
1236        };
1237        let overlay = TestWidget {
1238            size: Some(24.0),
1239            ..Default::default()
1240        };
1241        base.merge(&overlay);
1242        assert_eq!(base.size, Some(24.0));
1243    }
1244
1245    #[test]
1246    fn generated_merge_option_field_none_preserves_base() {
1247        let mut base = TestWidget {
1248            size: Some(20.0),
1249            ..Default::default()
1250        };
1251        let overlay = TestWidget::default();
1252        base.merge(&overlay);
1253        assert_eq!(base.size, Some(20.0));
1254    }
1255
1256    #[test]
1257    fn generated_merge_optional_nested_both_some_merges_inner() {
1258        let mut base = TestWidget {
1259            font: Some(FontSpec {
1260                family: Some("Noto Sans".into()),
1261                size: Some(FontSize::Px(12.0)),
1262                weight: None,
1263                ..Default::default()
1264            }),
1265            ..Default::default()
1266        };
1267        let overlay = TestWidget {
1268            font: Some(FontSpec {
1269                family: None,
1270                size: None,
1271                weight: Some(700),
1272                ..Default::default()
1273            }),
1274            ..Default::default()
1275        };
1276        base.merge(&overlay);
1277        let font = base.font.as_ref().unwrap();
1278        assert_eq!(font.family.as_deref(), Some("Noto Sans")); // preserved
1279        assert_eq!(font.size, Some(FontSize::Px(12.0))); // preserved
1280        assert_eq!(font.weight, Some(700)); // overlay sets
1281    }
1282
1283    #[test]
1284    fn generated_merge_optional_nested_none_plus_some_clones() {
1285        let mut base = TestWidget::default();
1286        let overlay = TestWidget {
1287            font: Some(FontSpec {
1288                family: Some("Inter".into()),
1289                size: Some(FontSize::Px(14.0)),
1290                weight: Some(400),
1291                ..Default::default()
1292            }),
1293            ..Default::default()
1294        };
1295        base.merge(&overlay);
1296        let font = base.font.as_ref().unwrap();
1297        assert_eq!(font.family.as_deref(), Some("Inter"));
1298        assert_eq!(font.size, Some(FontSize::Px(14.0)));
1299        assert_eq!(font.weight, Some(400));
1300    }
1301
1302    #[test]
1303    fn generated_merge_optional_nested_some_plus_none_preserves_base() {
1304        let mut base = TestWidget {
1305            font: Some(FontSpec {
1306                family: Some("Inter".into()),
1307                size: Some(FontSize::Px(14.0)),
1308                weight: Some(400),
1309                ..Default::default()
1310            }),
1311            ..Default::default()
1312        };
1313        let overlay = TestWidget::default();
1314        base.merge(&overlay);
1315        let font = base.font.as_ref().unwrap();
1316        assert_eq!(font.family.as_deref(), Some("Inter"));
1317    }
1318
1319    #[test]
1320    fn generated_merge_optional_nested_none_plus_none_stays_none() {
1321        let mut base = TestWidget::default();
1322        let overlay = TestWidget::default();
1323        base.merge(&overlay);
1324        assert!(base.font.is_none());
1325    }
1326
1327    // === impl_merge! optional_nested clause direct tests ===
1328
1329    // Verify the optional_nested clause directly on a FontSpec-containing struct
1330    #[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize)]
1331    struct WithFont {
1332        name: Option<String>,
1333        font: Option<FontSpec>,
1334    }
1335
1336    impl_merge!(WithFont {
1337        option { name }
1338        optional_nested { font }
1339    });
1340
1341    #[test]
1342    fn impl_merge_optional_nested_none_none_stays_none() {
1343        let mut base = WithFont::default();
1344        let overlay = WithFont::default();
1345        base.merge(&overlay);
1346        assert!(base.font.is_none());
1347    }
1348
1349    #[test]
1350    fn impl_merge_optional_nested_some_none_preserves_base() {
1351        let mut base = WithFont {
1352            font: Some(FontSpec {
1353                size: Some(FontSize::Px(12.0)),
1354                ..Default::default()
1355            }),
1356            ..Default::default()
1357        };
1358        let overlay = WithFont::default();
1359        base.merge(&overlay);
1360        assert_eq!(base.font.as_ref().unwrap().size, Some(FontSize::Px(12.0)));
1361    }
1362
1363    #[test]
1364    fn impl_merge_optional_nested_none_some_clones_overlay() {
1365        let mut base = WithFont::default();
1366        let overlay = WithFont {
1367            font: Some(FontSpec {
1368                family: Some("Inter".into()),
1369                ..Default::default()
1370            }),
1371            ..Default::default()
1372        };
1373        base.merge(&overlay);
1374        assert_eq!(base.font.as_ref().unwrap().family.as_deref(), Some("Inter"));
1375    }
1376
1377    #[test]
1378    fn impl_merge_optional_nested_some_some_merges_inner() {
1379        let mut base = WithFont {
1380            font: Some(FontSpec {
1381                family: Some("Noto".into()),
1382                size: Some(FontSize::Px(11.0)),
1383                weight: None,
1384                ..Default::default()
1385            }),
1386            ..Default::default()
1387        };
1388        let overlay = WithFont {
1389            font: Some(FontSpec {
1390                family: None,
1391                size: Some(FontSize::Px(14.0)),
1392                weight: Some(400),
1393                ..Default::default()
1394            }),
1395            ..Default::default()
1396        };
1397        base.merge(&overlay);
1398        let f = base.font.as_ref().unwrap();
1399        assert_eq!(f.family.as_deref(), Some("Noto")); // preserved
1400        assert_eq!(f.size, Some(FontSize::Px(14.0))); // overlay wins
1401        assert_eq!(f.weight, Some(400)); // overlay sets
1402    }
1403
1404    #[test]
1405    fn impl_merge_optional_nested_is_empty_none() {
1406        let w = WithFont::default();
1407        assert!(w.is_empty());
1408    }
1409
1410    #[test]
1411    fn impl_merge_optional_nested_is_empty_some_default() {
1412        // Some(FontSpec::default()) with all-None sub-fields counts as empty (D-2 fix).
1413        let w = WithFont {
1414            font: Some(FontSpec::default()),
1415            ..Default::default()
1416        };
1417        assert!(w.is_empty());
1418    }
1419
1420    #[test]
1421    fn impl_merge_optional_nested_is_not_empty_when_populated() {
1422        let w = WithFont {
1423            font: Some(FontSpec {
1424                size: Some(FontSize::Px(14.0)),
1425                ..Default::default()
1426            }),
1427            ..Default::default()
1428        };
1429        assert!(!w.is_empty());
1430    }
1431
1432    // === ButtonTheme tests ===
1433
1434    #[test]
1435    fn button_theme_default_is_empty() {
1436        assert!(ButtonTheme::default().is_empty());
1437    }
1438
1439    #[test]
1440    fn button_theme_not_empty_when_set() {
1441        let b = ButtonTheme {
1442            background_color: Some(Rgba::rgb(200, 200, 200)),
1443            min_width: Some(64.0),
1444            ..Default::default()
1445        };
1446        assert!(!b.is_empty());
1447    }
1448
1449    #[test]
1450    fn button_theme_merge_font_optional_nested() {
1451        let mut base = ButtonTheme {
1452            font: Some(FontSpec {
1453                family: Some("Noto Sans".into()),
1454                size: Some(FontSize::Px(11.0)),
1455                weight: None,
1456                ..Default::default()
1457            }),
1458            ..Default::default()
1459        };
1460        let overlay = ButtonTheme {
1461            font: Some(FontSpec {
1462                family: None,
1463                weight: Some(700),
1464                ..Default::default()
1465            }),
1466            ..Default::default()
1467        };
1468        base.merge(&overlay);
1469        let f = base.font.as_ref().unwrap();
1470        assert_eq!(f.family.as_deref(), Some("Noto Sans")); // preserved
1471        assert_eq!(f.weight, Some(700)); // overlay
1472    }
1473
1474    #[test]
1475    fn button_theme_toml_round_trip_with_font_and_border() {
1476        let b = ButtonTheme {
1477            background_color: Some(Rgba::rgb(200, 200, 200)),
1478            font: Some(FontSpec {
1479                family: Some("Inter".into()),
1480                size: Some(FontSize::Px(14.0)),
1481                weight: Some(400),
1482                ..Default::default()
1483            }),
1484            border: Some(WidgetBorderSpec {
1485                corner_radius: Some(4.0),
1486                ..Default::default()
1487            }),
1488            ..Default::default()
1489        };
1490        let toml_str = toml::to_string(&b).unwrap();
1491        let b2: ButtonTheme = toml::from_str(&toml_str).unwrap();
1492        assert_eq!(b, b2);
1493    }
1494
1495    // === WindowTheme tests ===
1496
1497    #[test]
1498    fn window_theme_has_new_fields() {
1499        let w = WindowTheme {
1500            inactive_title_bar_background: Some(Rgba::rgb(180, 180, 180)),
1501            inactive_title_bar_text_color: Some(Rgba::rgb(120, 120, 120)),
1502            title_bar_font: Some(FontSpec {
1503                weight: Some(700),
1504                ..Default::default()
1505            }),
1506            border: Some(WidgetBorderSpec {
1507                corner_radius: Some(4.0),
1508                shadow_enabled: Some(true),
1509                ..Default::default()
1510            }),
1511            ..Default::default()
1512        };
1513        assert!(!w.is_empty());
1514        assert!(w.inactive_title_bar_background.is_some());
1515        assert!(w.inactive_title_bar_text_color.is_some());
1516        assert!(w.title_bar_font.is_some());
1517        assert!(w.border.is_some());
1518    }
1519
1520    #[test]
1521    fn window_theme_default_is_empty() {
1522        assert!(WindowTheme::default().is_empty());
1523    }
1524
1525    // === DialogTheme tests ===
1526
1527    #[test]
1528    fn dialog_theme_button_order_works() {
1529        let d = DialogTheme {
1530            button_order: Some(DialogButtonOrder::PrimaryRight),
1531            min_width: Some(300.0),
1532            ..Default::default()
1533        };
1534        assert_eq!(d.button_order, Some(DialogButtonOrder::PrimaryRight));
1535        assert_eq!(d.min_width, Some(300.0));
1536        assert!(!d.is_empty());
1537    }
1538
1539    #[test]
1540    fn dialog_theme_button_order_toml_round_trip() {
1541        let d = DialogTheme {
1542            button_order: Some(DialogButtonOrder::PrimaryLeft),
1543            ..Default::default()
1544        };
1545        let toml_str = toml::to_string(&d).unwrap();
1546        let d2: DialogTheme = toml::from_str(&toml_str).unwrap();
1547        assert_eq!(d, d2);
1548    }
1549
1550    #[test]
1551    fn dialog_theme_default_is_empty() {
1552        assert!(DialogTheme::default().is_empty());
1553    }
1554
1555    // === SplitterTheme tests ===
1556
1557    #[test]
1558    fn splitter_theme_single_field_merge() {
1559        let mut base = SplitterTheme {
1560            divider_width: Some(4.0),
1561            ..Default::default()
1562        };
1563        let overlay = SplitterTheme {
1564            divider_width: Some(6.0),
1565            ..Default::default()
1566        };
1567        base.merge(&overlay);
1568        assert_eq!(base.divider_width, Some(6.0));
1569    }
1570
1571    #[test]
1572    fn splitter_theme_merge_none_preserves_base() {
1573        let mut base = SplitterTheme {
1574            divider_width: Some(4.0),
1575            ..Default::default()
1576        };
1577        let overlay = SplitterTheme::default();
1578        base.merge(&overlay);
1579        assert_eq!(base.divider_width, Some(4.0));
1580    }
1581
1582    #[test]
1583    fn splitter_theme_default_is_empty() {
1584        assert!(SplitterTheme::default().is_empty());
1585    }
1586
1587    #[test]
1588    fn splitter_theme_not_empty_when_set() {
1589        assert!(
1590            !SplitterTheme {
1591                divider_width: Some(4.0),
1592                ..Default::default()
1593            }
1594            .is_empty()
1595        );
1596    }
1597
1598    // === SeparatorTheme tests ===
1599
1600    #[test]
1601    fn separator_theme_single_field() {
1602        let s = SeparatorTheme {
1603            line_color: Some(Rgba::rgb(200, 200, 200)),
1604            ..Default::default()
1605        };
1606        assert!(!s.is_empty());
1607    }
1608
1609    // === All 25 widget theme defaults are empty ===
1610
1611    #[test]
1612    fn all_widget_theme_defaults_are_empty() {
1613        assert!(WindowTheme::default().is_empty());
1614        assert!(ButtonTheme::default().is_empty());
1615        assert!(InputTheme::default().is_empty());
1616        assert!(CheckboxTheme::default().is_empty());
1617        assert!(MenuTheme::default().is_empty());
1618        assert!(TooltipTheme::default().is_empty());
1619        assert!(ScrollbarTheme::default().is_empty());
1620        assert!(SliderTheme::default().is_empty());
1621        assert!(ProgressBarTheme::default().is_empty());
1622        assert!(TabTheme::default().is_empty());
1623        assert!(SidebarTheme::default().is_empty());
1624        assert!(ToolbarTheme::default().is_empty());
1625        assert!(StatusBarTheme::default().is_empty());
1626        assert!(ListTheme::default().is_empty());
1627        assert!(PopoverTheme::default().is_empty());
1628        assert!(SplitterTheme::default().is_empty());
1629        assert!(SeparatorTheme::default().is_empty());
1630        assert!(SwitchTheme::default().is_empty());
1631        assert!(DialogTheme::default().is_empty());
1632        assert!(SpinnerTheme::default().is_empty());
1633        assert!(ComboBoxTheme::default().is_empty());
1634        assert!(SegmentedControlTheme::default().is_empty());
1635        assert!(CardTheme::default().is_empty());
1636        assert!(ExpanderTheme::default().is_empty());
1637        assert!(LinkTheme::default().is_empty());
1638    }
1639
1640    // === Representative TOML round-trips ===
1641
1642    #[test]
1643    fn input_theme_toml_round_trip() {
1644        let t = InputTheme {
1645            background_color: Some(Rgba::rgb(255, 255, 255)),
1646            font: Some(FontSpec {
1647                family: Some("Noto Sans".into()),
1648                ..Default::default()
1649            }),
1650            border: Some(WidgetBorderSpec {
1651                color: Some(Rgba::rgb(180, 180, 180)),
1652                corner_radius: Some(4.0),
1653                ..Default::default()
1654            }),
1655            ..Default::default()
1656        };
1657        let toml_str = toml::to_string(&t).unwrap();
1658        let t2: InputTheme = toml::from_str(&toml_str).unwrap();
1659        assert_eq!(t, t2);
1660    }
1661
1662    #[test]
1663    fn switch_theme_toml_round_trip() {
1664        let s = SwitchTheme {
1665            checked_background: Some(Rgba::rgb(0, 120, 215)),
1666            track_width: Some(40.0),
1667            track_height: Some(20.0),
1668            thumb_diameter: Some(14.0),
1669            track_radius: Some(10.0),
1670            ..Default::default()
1671        };
1672        let toml_str = toml::to_string(&s).unwrap();
1673        let s2: SwitchTheme = toml::from_str(&toml_str).unwrap();
1674        assert_eq!(s, s2);
1675    }
1676
1677    #[test]
1678    fn card_theme_with_border() {
1679        let c = CardTheme {
1680            background_color: Some(Rgba::rgb(255, 255, 255)),
1681            border: Some(WidgetBorderSpec {
1682                corner_radius: Some(8.0),
1683                shadow_enabled: Some(true),
1684                ..Default::default()
1685            }),
1686        };
1687        assert!(!c.is_empty());
1688    }
1689
1690    #[test]
1691    fn link_theme_has_underline_enabled_bool_field() {
1692        let l = LinkTheme {
1693            visited_text_color: Some(Rgba::rgb(100, 0, 200)),
1694            underline_enabled: Some(true),
1695            ..Default::default()
1696        };
1697        assert!(!l.is_empty());
1698        assert_eq!(l.underline_enabled, Some(true));
1699    }
1700
1701    #[test]
1702    fn status_bar_theme_has_font_and_background() {
1703        let s = StatusBarTheme {
1704            background_color: Some(Rgba::rgb(240, 240, 240)),
1705            font: Some(FontSpec {
1706                size: Some(FontSize::Px(11.0)),
1707                ..Default::default()
1708            }),
1709            ..Default::default()
1710        };
1711        assert!(!s.is_empty());
1712    }
1713
1714    // === SC4: Dual optional_nested (font + border) test widget ===
1715
1716    // SC4: Verify derive handles dual optional_nested (font + border)
1717    /// Test widget with both font and border nested sub-structs.
1718    #[serde_with::skip_serializing_none]
1719    #[derive(
1720        Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget,
1721    )]
1722    #[serde(default)]
1723    #[theme_layer(skip_inventory)]
1724    pub struct DualNestedTestWidget {
1725        pub background: Option<Rgba>,
1726        pub min_height: Option<f32>,
1727        #[theme(nested, resolved_type = "ResolvedFontSpec")]
1728        pub font: Option<FontSpec>,
1729        #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
1730        pub border: Option<WidgetBorderSpec>,
1731    }
1732
1733    #[test]
1734    fn dual_nested_default_is_empty() {
1735        assert!(DualNestedTestWidget::default().is_empty());
1736    }
1737
1738    #[test]
1739    fn dual_nested_field_names() {
1740        assert_eq!(DualNestedTestWidget::FIELD_NAMES.len(), 4);
1741        assert!(DualNestedTestWidget::FIELD_NAMES.contains(&"background"));
1742        assert!(DualNestedTestWidget::FIELD_NAMES.contains(&"min_height"));
1743        assert!(DualNestedTestWidget::FIELD_NAMES.contains(&"font"));
1744        assert!(DualNestedTestWidget::FIELD_NAMES.contains(&"border"));
1745    }
1746
1747    #[test]
1748    fn dual_nested_not_empty_when_font_set() {
1749        let w = DualNestedTestWidget {
1750            font: Some(FontSpec {
1751                family: Some("Inter".into()),
1752                ..Default::default()
1753            }),
1754            ..Default::default()
1755        };
1756        assert!(!w.is_empty());
1757    }
1758
1759    #[test]
1760    fn dual_nested_not_empty_when_border_set() {
1761        let w = DualNestedTestWidget {
1762            border: Some(WidgetBorderSpec {
1763                color: Some(Rgba::rgb(100, 100, 100)),
1764                ..Default::default()
1765            }),
1766            ..Default::default()
1767        };
1768        assert!(!w.is_empty());
1769    }
1770
1771    #[test]
1772    fn dual_nested_merge_both_nested() {
1773        let mut base = DualNestedTestWidget {
1774            font: Some(FontSpec {
1775                family: Some("Noto Sans".into()),
1776                ..Default::default()
1777            }),
1778            ..Default::default()
1779        };
1780        let overlay = DualNestedTestWidget {
1781            border: Some(WidgetBorderSpec {
1782                corner_radius: Some(4.0),
1783                ..Default::default()
1784            }),
1785            ..Default::default()
1786        };
1787        base.merge(&overlay);
1788        assert!(base.font.is_some());
1789        assert!(base.border.is_some());
1790        assert_eq!(
1791            base.font.as_ref().and_then(|f| f.family.as_deref()),
1792            Some("Noto Sans")
1793        );
1794        assert_eq!(
1795            base.border.as_ref().and_then(|b| b.corner_radius),
1796            Some(4.0)
1797        );
1798    }
1799
1800    #[test]
1801    fn dual_nested_merge_inner_font_fields() {
1802        let mut base = DualNestedTestWidget {
1803            font: Some(FontSpec {
1804                family: Some("Noto Sans".into()),
1805                ..Default::default()
1806            }),
1807            ..Default::default()
1808        };
1809        let overlay = DualNestedTestWidget {
1810            font: Some(FontSpec {
1811                size: Some(FontSize::Px(14.0)),
1812                ..Default::default()
1813            }),
1814            ..Default::default()
1815        };
1816        base.merge(&overlay);
1817        let font = base.font.as_ref().unwrap();
1818        assert_eq!(font.family.as_deref(), Some("Noto Sans")); // preserved
1819        assert_eq!(font.size, Some(FontSize::Px(14.0))); // overlay sets
1820    }
1821
1822    #[test]
1823    fn dual_nested_toml_round_trip() {
1824        let w = DualNestedTestWidget {
1825            background: Some(Rgba::rgb(240, 240, 240)),
1826            min_height: Some(32.0),
1827            font: Some(FontSpec {
1828                family: Some("Inter".into()),
1829                size: Some(FontSize::Px(14.0)),
1830                weight: Some(400),
1831                ..Default::default()
1832            }),
1833            border: Some(WidgetBorderSpec {
1834                color: Some(Rgba::rgb(180, 180, 180)),
1835                corner_radius: Some(4.0),
1836                line_width: Some(1.0),
1837                ..Default::default()
1838            }),
1839        };
1840        let toml_str = toml::to_string(&w).unwrap();
1841        let w2: DualNestedTestWidget = toml::from_str(&toml_str).unwrap();
1842        assert_eq!(w, w2);
1843    }
1844
1845    // === LayoutTheme tests ===
1846
1847    // === validate_widget() generation tests ===
1848
1849    #[test]
1850    fn button_validate_widget_extracts_all_fields() {
1851        let button = ButtonTheme {
1852            background_color: Some(Rgba::rgb(200, 200, 200)),
1853            primary_background: Some(Rgba::rgb(0, 120, 215)),
1854            primary_text_color: Some(Rgba::rgb(255, 255, 255)),
1855            min_width: Some(80.0),
1856            min_height: Some(32.0),
1857            icon_text_gap: Some(8.0),
1858            disabled_opacity: Some(0.4),
1859            hover_background: Some(Rgba::rgb(210, 210, 210)),
1860            hover_text_color: Some(Rgba::rgb(0, 0, 0)),
1861            active_text_color: Some(Rgba::rgb(0, 0, 0)),
1862            disabled_text_color: Some(Rgba::rgb(128, 128, 128)),
1863            active_background: Some(Rgba::rgb(180, 180, 180)),
1864            disabled_background: Some(Rgba::rgb(220, 220, 220)),
1865            checked_background: Some(Rgba::rgb(190, 190, 190)),
1866            checked_text_color: None,
1867            font: Some(FontSpec {
1868                family: Some("Inter".into()),
1869                size: Some(FontSize::Px(14.0)),
1870                weight: Some(400),
1871                style: Some(crate::model::font::FontStyle::Normal),
1872                color: Some(Rgba::rgb(0, 0, 0)),
1873            }),
1874            border: Some(WidgetBorderSpec {
1875                color: Some(Rgba::rgb(100, 100, 100)),
1876                corner_radius: Some(4.0),
1877                line_width: Some(1.0),
1878                shadow_enabled: Some(false),
1879                padding_top: Some(6.0),
1880                padding_right: Some(12.0),
1881                padding_bottom: Some(6.0),
1882                padding_left: Some(12.0),
1883            }),
1884        };
1885        let mut missing = Vec::new();
1886        let resolved = ResolvedButtonTheme::validate_widget(&button, "button", 96.0, &mut missing);
1887        assert!(missing.is_empty(), "unexpected missing: {missing:?}");
1888        assert_eq!(resolved.background_color, Rgba::rgb(200, 200, 200));
1889        assert_eq!(resolved.min_width, 80.0);
1890        assert_eq!(resolved.font.family.as_ref(), "Inter");
1891        assert_eq!(resolved.font.size, 14.0);
1892        assert_eq!(resolved.border.corner_radius, 4.0);
1893        // soft_option fields pass through as Option
1894        assert_eq!(resolved.active_background, Some(Rgba::rgb(180, 180, 180)));
1895        assert_eq!(resolved.disabled_background, Some(Rgba::rgb(220, 220, 220)));
1896        assert_eq!(resolved.checked_background, Some(Rgba::rgb(190, 190, 190)));
1897        assert_eq!(resolved.checked_text_color, None);
1898    }
1899
1900    #[test]
1901    fn button_validate_widget_records_missing_fields() {
1902        let button = ButtonTheme::default(); // all None
1903        let mut missing = Vec::new();
1904        let _ = ResolvedButtonTheme::validate_widget(&button, "button", 96.0, &mut missing);
1905        // option fields should be recorded as missing
1906        assert!(missing.contains(&"button.background_color".to_string()));
1907        assert!(missing.contains(&"button.min_width_px".to_string()));
1908        // font (optional_nested) should be recorded
1909        assert!(missing.contains(&"button.font".to_string()));
1910        // border (optional_nested) should be recorded
1911        assert!(missing.contains(&"button.border".to_string()));
1912        // soft_option fields should NOT be recorded as missing
1913        assert!(!missing.iter().any(|m| m.contains("active_background")));
1914        assert!(!missing.iter().any(|m| m.contains("disabled_background")));
1915    }
1916
1917    // === LayoutTheme tests ===
1918
1919    #[test]
1920    fn layout_theme_default_is_empty() {
1921        assert!(LayoutTheme::default().is_empty());
1922    }
1923
1924    #[test]
1925    fn layout_theme_not_empty_when_widget_gap_set() {
1926        let l = LayoutTheme {
1927            widget_gap: Some(8.0),
1928            ..Default::default()
1929        };
1930        assert!(!l.is_empty());
1931    }
1932
1933    #[test]
1934    fn layout_theme_field_names() {
1935        assert_eq!(LayoutTheme::FIELD_NAMES.len(), 4);
1936        assert!(LayoutTheme::FIELD_NAMES.contains(&"widget_gap_px"));
1937        assert!(LayoutTheme::FIELD_NAMES.contains(&"container_margin_px"));
1938        assert!(LayoutTheme::FIELD_NAMES.contains(&"window_margin_px"));
1939        assert!(LayoutTheme::FIELD_NAMES.contains(&"section_gap_px"));
1940    }
1941
1942    #[test]
1943    fn layout_theme_toml_round_trip() {
1944        let l = LayoutTheme {
1945            widget_gap: Some(8.0),
1946            container_margin: Some(12.0),
1947            window_margin: Some(16.0),
1948            section_gap: Some(24.0),
1949        };
1950        let toml_str = toml::to_string(&l).unwrap();
1951        let l2: LayoutTheme = toml::from_str(&toml_str).unwrap();
1952        assert_eq!(l, l2);
1953    }
1954
1955    #[test]
1956    fn layout_theme_merge() {
1957        let mut base = LayoutTheme {
1958            widget_gap: Some(6.0),
1959            container_margin: Some(10.0),
1960            ..Default::default()
1961        };
1962        let overlay = LayoutTheme {
1963            widget_gap: Some(8.0),
1964            section_gap: Some(24.0),
1965            ..Default::default()
1966        };
1967        base.merge(&overlay);
1968        // overlay widget_gap replaces base
1969        assert_eq!(base.widget_gap, Some(8.0));
1970        // base container_margin preserved
1971        assert_eq!(base.container_margin, Some(10.0));
1972        // overlay section_gap added
1973        assert_eq!(base.section_gap, Some(24.0));
1974        // window_margin stays None
1975        assert!(base.window_margin.is_none());
1976    }
1977}