Skip to main content

frus_widgets/
widgettheme.rs

1//! **Per-widget defaults**: the middle term of `what the caller said ?? what the theme
2//! says ?? what the framework ships`.
3//!
4//! Three milestones in a row ended on the same missing piece. An application could
5//! override one card's elevation, one divider's height, one splash's colour — and had
6//! no way to say *every card in this application*, short of writing its own wrapper
7//! around each widget. The reference resolves nearly every property through exactly
8//! this chain, and only the middle term was absent here.
9//!
10//! Every field is an `Option`, and `None` means "the framework's own default" — so a
11//! theme that sets nothing behaves exactly as no theme at all, and a theme that sets one
12//! field changes one thing.
13//!
14//! ```ignore
15//! let mut theme = Theme::dark();
16//! theme.widgets.card.elevation = Some(0.0);       // a flat application
17//! theme.widgets.divider.height = Some(1.0);       // hairlines, flush
18//! theme.widgets.ink.color = Some(accent.fade(0.2));
19//! ```
20//!
21//! **Layout properties are included** — a divider's height, a card's margin, a drawer's
22//! width — which is why [`Widget::style_themed`](crate::Widget::style_themed) exists
23//! beside `style`. A theme that could only reach paint would be able to recolour a
24//! divider but not make one thin, which is the setting an application actually wants.
25
26use frus_core::{BorderRadius, Color, Insets, ShapeBorder, TextAlign, TextOverflow, TextStyle};
27
28use crate::card::CardVariant;
29
30/// **The shape a box takes**, on the rungs everything here is resolved on
31/// (`card.dart`, `button_style.dart`, and every other `shape` in the reference).
32///
33/// The caller's word first, then the theme's shape, then the theme's plain **radius** read
34/// as a rounded rectangle, then the widget's own default.
35///
36/// The third rung is the one worth explaining. A radius was the only thing a theme could
37/// say until milestone 450, and applications have written them; a theme that names a
38/// `shape` outranks one that names only a `radius`, and naming both is naming the shape.
39pub fn resolve_shape(
40    own: Option<ShapeBorder>,
41    themed: Option<ShapeBorder>,
42    radius: Option<BorderRadius>,
43    fallback: ShapeBorder,
44) -> ShapeBorder {
45    own.or(themed)
46        .or_else(|| radius.map(ShapeBorder::rounded))
47        .unwrap_or(fallback)
48}
49
50/// The per-widget defaults carried by a [`Theme`](crate::Theme).
51///
52/// Adding a widget here is adding a field: the pattern is one `Option` per builder the
53/// widget already has, resolved in the same order everywhere.
54#[derive(Clone, Debug, Default, PartialEq)]
55pub struct WidgetThemes {
56    /// Defaults for [`Alert`](crate::Alert).
57    pub alert: AlertTheme,
58    /// Defaults for [`Dialog`](crate::Dialog) and [`AlertDialog`](crate::AlertDialog).
59    pub dialog: DialogTheme,
60    /// Which glyphs the four named buttons carry.
61    pub action_icons: ActionIconTheme,
62    /// Defaults for [`AppBar`](crate::AppBar).
63    pub app_bar: AppBarTheme,
64    /// Defaults for [`Autocomplete`](crate::Autocomplete).
65    pub autocomplete: AutocompleteTheme,
66    /// Defaults for [`Badge`](crate::Badge).
67    pub badge: BadgeTheme,
68    /// Defaults for [`MaterialBanner`](crate::MaterialBanner).
69    pub banner: BannerTheme,
70    /// Defaults for [`BottomAppBar`](crate::BottomAppBar).
71    pub bottom_app_bar: BottomAppBarTheme,
72    /// Defaults for [`BottomSheet`](crate::BottomSheet).
73    pub bottom_sheet: BottomSheetTheme,
74    /// Defaults for [`Breadcrumb`](crate::Breadcrumb).
75    pub breadcrumb: BreadcrumbTheme,
76    /// Defaults for [`Button`](crate::Button).
77    pub button: ButtonTheme,
78    /// Defaults for [`Card`](crate::Card).
79    pub card: CardTheme,
80    /// Defaults for [`Checkbox`](crate::Checkbox).
81    pub checkbox: CheckboxTheme,
82    /// Defaults for [`Chip`](crate::Chip).
83    pub chip: ChipTheme,
84    /// Defaults for [`DatePicker`](crate::DatePicker).
85    pub date_picker: DatePickerTheme,
86    /// Defaults for [`Divider`](crate::Divider).
87    pub divider: DividerTheme,
88    /// Defaults for [`Drawer`](crate::Drawer).
89    pub drawer: DrawerTheme,
90    /// Defaults for [`ListTile`](crate::ListTile).
91    pub list_tile: ListTileTheme,
92    /// Defaults for [`DropdownButton`](crate::DropdownButton) and its options.
93    pub dropdown: DropdownTheme,
94    /// Defaults for [`ExpansionTile`](crate::ExpansionTile).
95    pub expansion_tile: ExpansionTileTheme,
96    /// Defaults for [`ExpansionPanelList`](crate::ExpansionPanelList).
97    pub expansion_panel_list: ExpansionPanelListTheme,
98    /// Defaults for [`FloatingActionButton`](crate::FloatingActionButton).
99    pub fab: FabTheme,
100    /// Defaults for a form's error summary, [`ErrorSummary`](crate::ErrorSummary).
101    pub form: FormTheme,
102    /// Defaults for [`GridTileBar`](crate::GridTileBar).
103    pub grid_tile_bar: GridTileBarTheme,
104    /// Defaults for [`Icon`](crate::Icon).
105    pub icon: IconTheme,
106    /// Defaults for [`IconButton`](crate::IconButton).
107    pub icon_button: IconButtonTheme,
108    /// Defaults for the **ink ripple** — every surface that splashes, including [`InkWell`](crate::InkWell) and [`Button`](crate::Button).
109    pub ink: InkTheme,
110    /// Defaults for [`Kanban`](crate::Kanban).
111    pub kanban: KanbanTheme,
112    /// Defaults for [`ReorderableList`](crate::ReorderableList).
113    pub reorderable: ReorderableTheme,
114    /// Defaults for [`Kbd`](crate::Kbd).
115    pub kbd: KbdTheme,
116    /// Defaults for [`PopupMenuButton`](crate::PopupMenuButton) and its items.
117    pub menu: MenuTheme,
118    /// Defaults for [`NavigationBar`](crate::NavigationBar).
119    pub nav_bar: NavBarTheme,
120    /// Defaults for [`NavigationRail`](crate::NavigationRail) and [`BottomBar`](crate::BottomBar).
121    pub nav_rail: NavRailTheme,
122    /// Defaults for [`NavigationDrawer`](crate::NavigationDrawer).
123    pub nav_drawer: NavDrawerTheme,
124    /// Defaults for the **scrollbars** the framework draws over a scrollable.
125    pub scrollbar: ScrollbarTheme,
126    /// Defaults for [`SearchBar`](crate::SearchBar).
127    pub search_bar: SearchBarTheme,
128    /// Defaults for the view a [`SearchAnchor`](crate::SearchAnchor) opens.
129    pub search_view: SearchViewTheme,
130    /// Defaults for the two progress indicators.
131    pub progress: ProgressTheme,
132    /// Defaults for [`RadioGroup`](crate::RadioGroup).
133    pub radio: RadioTheme,
134    /// Defaults for [`SegmentedButton`](crate::SegmentedButton).
135    pub segmented: SegmentedTheme,
136    /// Defaults for [`Slider`](crate::Slider) and [`RangeSlider`](crate::RangeSlider).
137    pub slider: SliderTheme,
138    /// Defaults for [`SnackBar`](crate::SnackBar).
139    pub snack_bar: SnackBarTheme,
140    /// Defaults for [`Steps`](crate::Steps).
141    pub steps: StepsTheme,
142    /// Defaults for [`Switch`](crate::Switch).
143    pub switch: SwitchTheme,
144    /// Defaults for [`TabPageSelector`](crate::TabPageSelector).
145    pub page_selector: PageSelectorTheme,
146    /// Defaults for [`TabBar`](crate::TabBar).
147    pub tab_bar: TabBarTheme,
148    /// Defaults for [`Table`](crate::Table).
149    pub table: TableTheme,
150    /// The text style that text takes when it names none of its own.
151    pub text: DefaultTextStyle,
152    /// Defaults for [`MenuBar`](crate::MenuBar) and its menus.
153    pub menu_bar: MenuBarTheme,
154    /// The window's three buttons, when the application paints them on the title bar's line
155    /// (milestone 640).
156    pub caption_buttons: CaptionButtonsTheme,
157    /// The colours of a [`WindowMenuBar`](crate::WindowMenuBar)'s line (milestone 642).
158    pub title_bar: TitleBarTheme,
159    /// How a selection in text that is not a field looks: a
160    /// [`selectable`](crate::Text::selectable) text's, and a
161    /// [`SelectionArea`](crate::SelectionArea)'s.
162    pub text_selection: TextSelectionTheme,
163    /// Defaults for [`TextField`](crate::TextField).
164    pub text_field: TextFieldTheme,
165    /// Defaults for [`TimePicker`](crate::TimePicker) and [`TimeRange`](crate::TimeRange).
166    pub time_picker: TimePickerTheme,
167    /// Defaults for [`Timeline`](crate::Timeline).
168    pub timeline: TimelineTheme,
169    /// Defaults for [`ToggleButtons`](crate::ToggleButtons).
170    pub toggle_buttons: ToggleButtonsTheme,
171    /// Defaults for [`Tooltip`](crate::Tooltip).
172    pub tooltip: TooltipTheme,
173    /// Defaults for [`Tree`](crate::Tree).
174    pub tree: TreeTheme,
175}
176
177/// How a selection in text that is not a field looks — a
178/// [`selectable`](crate::Text::selectable) text's and a [`SelectionArea`](crate::SelectionArea)'s.
179///
180/// A field has its own ([`TextFieldTheme::handle_color`]); this is for the words around it.
181/// [`SelectionArea::selection_color`](crate::SelectionArea::selection_color) and
182/// [`SelectionArea::handle_color`](crate::SelectionArea::handle_color) set it for one area.
183#[derive(Clone, Copy, Debug, Default, PartialEq)]
184pub struct TextSelectionTheme {
185    /// The highlight under the selected words. Unset, the theme's `selection`.
186    pub selection_color: Option<Color>,
187    /// The handles under a touch selection. Unset, the scheme's `primary`.
188    pub handle_color: Option<Color>,
189}
190
191impl TextSelectionTheme {
192    /// The highlight, resolved against `theme`.
193    pub fn selection_color_in(&self, theme: &crate::Theme) -> Color {
194        self.selection_color.unwrap_or(theme.selection)
195    }
196
197    /// The handles' colour, resolved against `theme`.
198    pub fn handle_color_in(&self, theme: &crate::Theme) -> Color {
199        self.handle_color.unwrap_or(theme.scheme.primary)
200    }
201}
202
203/// Defaults for [`Badge`](crate::Badge).
204///
205/// A badge is an **alert** rather than an accent, which is why its untold fill is the
206/// scheme's `error` and not its `primary`. The two sizes are the reference's: `small_size`
207/// is the diameter of a badge with no label, `large_size` the height of one that carries
208/// a count.
209#[derive(Clone, Copy, Debug, Default, PartialEq)]
210pub struct BadgeTheme {
211    /// The pill's fill.
212    pub background_color: Option<Color>,
213    /// The label's colour on that fill.
214    pub text_color: Option<Color>,
215    /// The label's type.
216    pub text_style: Option<TextStyle>,
217    /// The diameter of a badge with no label.
218    pub small_size: Option<f32>,
219    /// The height of a badge that carries one.
220    pub large_size: Option<f32>,
221    /// The label's room either side.
222    pub padding: Option<f32>,
223}
224
225/// Defaults for [`Checkbox`](crate::Checkbox).
226///
227/// A checkbox is two controls wearing one name: ticked it is a **filled box** with a
228/// mark punched through it, unticked it is an **outline** and nothing else. The colours
229/// do not carry over between the two, which is why they are named apart rather than as
230/// one "active"/"inactive" pair.
231#[derive(Clone, Debug, Default, PartialEq)]
232pub struct CheckboxTheme {
233    /// The box's fill, ticked.
234    pub fill_color: Option<Color>,
235    /// The tick drawn on that fill.
236    pub check_color: Option<Color>,
237    /// The outline, unticked and at rest.
238    pub border_color: Option<Color>,
239    /// The outline under a pointer, a finger or focus. The reference resolves this side
240    /// per state, and an outline that did not answer would look inert.
241    pub active_border_color: Option<Color>,
242    /// The box's corner radius.
243    pub radius: Option<f32>,
244    /// The label beside it.
245    pub label_color: Option<Color>,
246    /// **How much room it reserves for a finger** — the reference's per-widget say over
247    /// the theme's (`checkbox.dart:512`). Unset, the theme's own answer.
248    pub tap_target: Option<crate::theme::TapTarget>,
249    /// The halo under a pointer, the keyboard or a finger, state by state. Unset, the
250    /// reference's (milestone 634).
251    pub overlay_color: Option<crate::WidgetStateProperty<Color>>,
252    /// That halo's radius. Unset, 20.
253    pub splash_radius: Option<f32>,
254    /// How compact a checkbox is. Unset, the standard density, whatever the theme's.
255    pub visual_density: Option<crate::VisualDensity>,
256}
257
258/// Defaults for [`RadioGroup`](crate::RadioGroup).
259#[derive(Clone, Debug, Default, PartialEq)]
260pub struct RadioTheme {
261    /// The ring and the dot of the chosen option.
262    pub selected_color: Option<Color>,
263    /// The ring of an option that is not chosen, at rest.
264    pub border_color: Option<Color>,
265    /// That ring under a pointer, a finger or focus.
266    pub active_border_color: Option<Color>,
267    /// The labels.
268    pub label_color: Option<Color>,
269    /// **How much room it reserves for a finger** — the reference's per-widget say over
270    /// the theme's (`radio.dart:734`). Unset, the theme's own answer.
271    pub tap_target: Option<crate::theme::TapTarget>,
272    /// The halo under a pointer, the keyboard or a finger, state by state. Unset, the
273    /// reference's (milestone 635).
274    pub overlay_color: Option<crate::WidgetStateProperty<Color>>,
275    /// That halo's radius. Unset, 20.
276    pub splash_radius: Option<f32>,
277    /// How compact a radio is. Unset, the theme's density.
278    pub visual_density: Option<crate::VisualDensity>,
279}
280
281/// Defaults for [`Slider`](crate::Slider) and [`RangeSlider`](crate::RangeSlider).
282#[derive(Clone, Debug, Default, PartialEq)]
283pub struct SliderTheme {
284    /// The value bubble's type. The reference calls it the *value indicator* and sets it in
285    /// `labelLarge`.
286    pub value_indicator_text_style: Option<TextStyle>,
287    /// The travelled part of the track.
288    pub active_track_color: Option<Color>,
289    /// The part still to travel.
290    pub inactive_track_color: Option<Color>,
291    /// The thumb's fill.
292    pub thumb_color: Option<Color>,
293    /// The ring around the thumb.
294    pub thumb_border_color: Option<Color>,
295    /// How far a thumb sits off the track at rest — a slider's, and each of a range
296    /// slider's. Unset, the reference's 1.
297    pub thumb_elevation: Option<f32>,
298    /// And while it is held. Unset, the reference's 6.
299    pub pressed_thumb_elevation: Option<f32>,
300    /// The track's height (milestone 648, as the rest below). Unset, the reference's 4; the
301    /// travelled part is 2 more.
302    pub track_height: Option<f32>,
303    /// The part between a slider's value and its secondary value.
304    pub secondary_active_track_color: Option<Color>,
305    /// The ticks on the travelled part. Unset, `on_primary` at 38 %.
306    pub active_tick_mark_color: Option<Color>,
307    /// The ticks on the rest. Unset, `on_surface_variant` at 38 %.
308    pub inactive_tick_mark_color: Option<Color>,
309    /// A disabled slider's travelled part.
310    pub disabled_active_track_color: Option<Color>,
311    /// A disabled slider's rest of the track.
312    pub disabled_inactive_track_color: Option<Color>,
313    /// A disabled slider's thumb.
314    pub disabled_thumb_color: Option<Color>,
315    /// The halo around the thumb, per state.
316    pub overlay_color: Option<crate::WidgetStateProperty<Color>>,
317    /// The value indicator's fill. Unset, `primary`.
318    pub value_indicator_color: Option<Color>,
319    /// When the value indicator shows. Unset, only on a slider with divisions.
320    pub show_value_indicator: Option<crate::ShowValueIndicator>,
321}
322
323/// Defaults for [`Switch`](crate::Switch).
324#[derive(Clone, Debug, Default, PartialEq)]
325pub struct SwitchTheme {
326    /// The track, on.
327    pub track_color: Option<Color>,
328    /// The track, off.
329    pub inactive_track_color: Option<Color>,
330    /// The thumb, on.
331    pub thumb_color: Option<Color>,
332    /// The thumb, off.
333    pub inactive_thumb_color: Option<Color>,
334    /// The thumb in any state, on or off — before `thumb_color` and `inactive_thumb_color`
335    /// (milestone 637).
336    pub thumb_colors: Option<crate::WidgetStateProperty<Color>>,
337    /// The track in any state, on or off — before `track_color` and
338    /// `inactive_track_color`.
339    pub track_colors: Option<crate::WidgetStateProperty<Color>>,
340    /// The rule round the track in any state. Unset, `outline` round an off track and none
341    /// round an on one.
342    pub track_outline_color: Option<crate::WidgetStateProperty<Color>>,
343    /// How wide that rule is. Unset, 2.
344    pub track_outline_width: Option<f32>,
345    /// The halo round the thumb, state by state. Unset, `primary` round an on switch and
346    /// `on_surface` round an off one, 8 % under a pointer and 10 % focused or pressed.
347    pub overlay_color: Option<crate::WidgetStateProperty<Color>>,
348    /// The halo's radius. Unset, 20.
349    pub splash_radius: Option<f32>,
350    /// The room either side of the track. Unset, 4 left and right.
351    pub padding: Option<Insets>,
352    /// The glyph inside the thumb, on. Unset, the scheme's `on_primary_container`
353    /// (`switch.dart:2338`).
354    pub icon_color: Option<Color>,
355    /// The glyph inside the thumb, off. Unset, the scheme's `surface_container_highest`
356    /// (`switch.dart:2349`) — the track's own colour, so the glyph reads as a hole in the
357    /// thumb rather than as a mark on it.
358    pub inactive_icon_color: Option<Color>,
359    /// **How much room it reserves for a finger** — the reference's per-widget say over
360    /// the theme's (`switch.dart:603`). Unset, the theme's own answer.
361    pub tap_target: Option<crate::theme::TapTarget>,
362}
363
364/// The text style a **subtree** hands down — the reference's `DefaultTextStyle`, and an
365/// inherited widget there for the reason it is a theme entry here: an app bar, a list
366/// tile or a dialog wants every run of words inside it to read the same way without
367/// reaching into each one, including the ones it never sees because a caller passed them
368/// in already assembled.
369///
370/// It is the reference's shape exactly: a [`TextStyle`] plus the four questions that are
371/// about the **box** rather than the type. It carried its own copy of every typographic
372/// field until `TextStyle` learned to say *unset*; now the style is just a style.
373///
374/// A [`Text`](crate::Text) resolves `what the caller said ?? what this says ?? what the
375/// framework ships`, field by field, and **a default the caller did not choose does not
376/// count as having said something** — which is what an `Option` per field means and what
377/// `TextStyle::new(16.0)` could not express.
378///
379/// [`DefaultTextStyle::around`] wraps a subtree with one, and that is how
380/// [`AppBar::toolbar_text_style`](crate::AppBar::toolbar_text_style) delivers its own.
381#[derive(Clone, Copy, Debug, Default, PartialEq)]
382pub struct DefaultTextStyle {
383    /// The type: size, weight, slant, colour, decoration — each answered or left open.
384    pub style: TextStyle,
385    /// Where the lines sit inside the box.
386    pub align: Option<TextAlign>,
387    /// Whether the text wraps at the width it is given.
388    pub soft_wrap: Option<bool>,
389    /// What becomes of text that does not fit.
390    pub overflow: Option<TextOverflow>,
391    /// At most this many lines.
392    pub max_lines: Option<usize>,
393    /// Whether the texts in this subtree **take part in a selection that spans them** — set by
394    /// [`SelectionArea`](crate::SelectionArea) and by nothing else. Unlike the fields above it is
395    /// not a matter of how a text looks, and it never turns off once on: a nested area is still
396    /// inside the outer one.
397    pub selectable: bool,
398}
399
400impl DefaultTextStyle {
401    /// Nothing said at all — what a theme carries until something sets a field.
402    pub const NONE: Self = Self {
403        style: TextStyle::NONE,
404        align: None,
405        soft_wrap: None,
406        overflow: None,
407        max_lines: None,
408        selectable: false,
409    };
410
411    /// A handover of type and nothing else.
412    pub const fn from_text_style(style: TextStyle) -> Self {
413        Self {
414            style,
415            ..Self::NONE
416        }
417    }
418
419    /// This style with `over`'s answers laid on top, **field by field**: where `over` said
420    /// nothing, this one's answer survives.
421    ///
422    /// The operation an inherited style needs at every level it passes through — two
423    /// nested subtrees each setting one field must leave a text wearing both.
424    #[must_use]
425    pub fn merge(self, over: Self) -> Self {
426        Self {
427            style: self.style.merge(over.style),
428            align: over.align.or(self.align),
429            soft_wrap: over.soft_wrap.or(self.soft_wrap),
430            overflow: over.overflow.or(self.overflow),
431            max_lines: over.max_lines.or(self.max_lines),
432            selectable: self.selectable || over.selectable,
433        }
434    }
435
436    /// Wraps `child` so that every [`Text`](crate::Text) in its subtree wears this style
437    /// where it has not answered for itself — the reference's `DefaultTextStyle` widget.
438    ///
439    /// **Merged onto** whatever an enclosing subtree already handed down rather than
440    /// replacing it, so two nested wrappers each setting one field leave a text wearing
441    /// both:
442    ///
443    /// ```ignore
444    /// DefaultTextStyle::from_text_style(TextStyle::NONE.color(muted))
445    ///     .around(a_column_of_labels)
446    /// ```
447    pub fn around<Msg: 'static>(
448        self,
449        child: impl crate::Widget<Msg> + 'static,
450    ) -> crate::Themed<Msg> {
451        crate::Themed::tweak(move |t| t.widgets.text = t.widgets.text.merge(self), child)
452    }
453}
454
455/// Defaults for [`Icon`](crate::Icon) — the reference's `IconTheme`, which is an
456/// **inherited** widget there for the same reason this is scoped here: an app bar, a
457/// list tile or a button bar wants every glyph inside it one colour without recolouring
458/// the words beside them.
459///
460/// `Themed::tweak` is how a subtree sets it, and that is exactly how
461/// [`AppBar::icon_theme`](crate::AppBar::icon_theme) delivers its own.
462#[derive(Clone, Copy, Debug, Default, PartialEq)]
463pub struct IconTheme {
464    /// The glyph's colour. Unset, the scheme's `on_surface` — an icon is text's peer,
465    /// not a decoration.
466    pub color: Option<Color>,
467    /// The square's side, in logical pixels. Unset, 24: the grid the icons are drawn on.
468    pub size: Option<f32>,
469}
470
471/// Defaults for [`AppBar`](crate::AppBar).
472#[derive(Clone, Copy, Debug, Default, PartialEq)]
473pub struct AppBarTheme {
474    /// Whether the title is centred. Unset, the **platform**'s convention decides, which
475    /// is the one place the framework's last word is a system convention rather than a
476    /// taste of its own.
477    pub center_title: Option<bool>,
478    /// The title's type.
479    pub title_style: Option<TextStyle>,
480    /// The bar's surface.
481    pub background: Option<Color>,
482    /// What is drawn on it — the title's colour.
483    pub foreground: Option<Color>,
484    /// How far off the page the bar sits. Unset, the bar is flat, as the reference's is.
485    pub elevation: Option<f32>,
486    /// The toolbar's height.
487    pub height: Option<f32>,
488    /// The colour of the shadow an elevated bar casts. Unset, **transparent**, as the
489    /// reference's app bar defaults are (line 2542): a shadow is cast only where a colour is
490    /// named.
491    pub shadow_color: Option<Color>,
492    /// The colour laid over the surface in proportion to the elevation — Material 3's
493    /// way of showing height, and the one that still reads on a dark background.
494    pub surface_tint: Option<Color>,
495    /// **What shape the bar is** — the reference's `AppBarTheme.shape`. Unset, square.
496    ///
497    /// It was an `Option<BorderRadius>` under this name until milestone 455: the last
498    /// theme field left carrying the reference's *word* with a corner radius behind it.
499    pub shape: Option<ShapeBorder>,
500}
501
502/// Defaults for [`TextField`](crate::TextField).
503#[derive(Clone, Copy, Debug, Default, PartialEq)]
504pub struct TextFieldTheme {
505    /// The container's fill. A filled field takes the theme's high surface container by
506    /// default; an outlined one has none.
507    pub fill: Option<Color>,
508    /// The border, or the underline, at rest.
509    pub border_color: Option<Color>,
510    /// The border once focused.
511    pub focused_border_color: Option<Color>,
512    /// Border, label and helper colour while an error is showing.
513    pub error_color: Option<Color>,
514    /// The same under the pointer: an errored field **deepens** on hover
515    /// (`input_decorator.dart:5981`). Unset, the scheme's `on_error_container`.
516    pub error_hover_color: Option<Color>,
517    /// The value's colour.
518    pub text_color: Option<Color>,
519    /// The label and the hint, at rest.
520    pub label_color: Option<Color>,
521    /// The label once focused.
522    pub focused_label_color: Option<Color>,
523    /// The helper line.
524    pub helper_color: Option<Color>,
525    /// The prefix and suffix icons.
526    pub icon_color: Option<Color>,
527    /// The handles under a touch selection. Unset, the scheme's `primary`.
528    pub handle_color: Option<Color>,
529    /// Corner radius.
530    pub radius: Option<f32>,
531    /// Border weight at rest.
532    pub border_width: Option<f32>,
533    /// Border weight once focused.
534    pub focused_border_width: Option<f32>,
535}
536
537/// Defaults for [`Button`](crate::Button): a style for each kind of button — the
538/// reference's `ElevatedButtonTheme`, `FilledButtonTheme`, `OutlinedButtonTheme` and
539/// `TextButtonTheme` — and, under them, plain values for every kind (milestone 632).
540#[derive(Clone, Debug, Default, PartialEq)]
541pub struct ButtonTheme {
542    /// How an elevated button looks, state by state.
543    pub elevated_style: Option<crate::ButtonStyle>,
544    /// How a filled button looks — tonal and danger ones included, as the reference's
545    /// tonal button shares the filled button's theme.
546    pub filled_style: Option<crate::ButtonStyle>,
547    /// How an outlined button looks.
548    pub outlined_style: Option<crate::ButtonStyle>,
549    /// How a text button looks.
550    pub text_button_style: Option<crate::ButtonStyle>,
551    /// **What shape it is** (`shape_border.dart`), over the plain `radius` below:
552    /// a button's, whose default is a **pill** (`button_style.dart`). Unset, the widget decides.
553    pub shape: Option<ShapeBorder>,
554    /// The surface under the label, whatever the variant would have used.
555    pub color: Option<Color>,
556    /// The label's colour.
557    pub label_color: Option<Color>,
558    /// The label's type.
559    pub label_style: Option<TextStyle>,
560    /// The outline's colour.
561    pub border_color: Option<Color>,
562    /// Its thickness; `0.0` removes it.
563    pub border_width: Option<f32>,
564    /// The corner radii. Unset, a button is a stadium.
565    pub radius: Option<BorderRadius>,
566    /// The room either side of the label.
567    pub padding: Option<f32>,
568    /// The button's height.
569    pub height: Option<f32>,
570    /// The narrowest it will be, however short its label.
571    pub min_width: Option<f32>,
572    /// How far it sits off the surface, **in every state**. Unset, the variant's own
573    /// heights, which move with the state — see [`Button::elevation`](crate::Button::elevation).
574    pub elevation: Option<f32>,
575}
576
577/// Defaults for [`Card`](crate::Card).
578#[derive(Clone, Copy, Debug, Default, PartialEq)]
579pub struct CardTheme {
580    /// **What shape it is** (`shape_border.dart`), over the plain `radius` below:
581    /// a card's. Unset, the widget decides.
582    pub shape: Option<ShapeBorder>,
583    /// Which of the three cards an untold `Card::new()` is.
584    pub variant: Option<CardVariant>,
585    /// How far off the surface it sits.
586    pub elevation: Option<f32>,
587    /// Its background, overriding the variant's tone.
588    pub color: Option<Color>,
589    /// Its corner radii.
590    pub radius: Option<BorderRadius>,
591    /// The room it leaves around itself.
592    pub margin: Option<f32>,
593    /// The room it leaves inside itself.
594    pub padding: Option<f32>,
595}
596
597/// Defaults for [`Chip`](crate::Chip).
598#[derive(Clone, Copy, Debug, Default, PartialEq)]
599pub struct ChipTheme {
600    /// **What shape it is** (`shape_border.dart`), over the plain `radius` below:
601    /// a chip's. Unset, the widget decides.
602    pub shape: Option<ShapeBorder>,
603    /// The surface under an unselected chip.
604    pub color: Option<Color>,
605    /// The surface under a selected one.
606    pub selected_color: Option<Color>,
607    /// The label's colour when unselected.
608    pub label_color: Option<Color>,
609    /// The label's colour when selected.
610    pub selected_label_color: Option<Color>,
611    /// The label's type.
612    pub label_style: Option<TextStyle>,
613    /// The outline's colour.
614    pub border_color: Option<Color>,
615    /// Its thickness; `0.0` removes it.
616    pub border_width: Option<f32>,
617    /// The corner radii.
618    pub radius: Option<BorderRadius>,
619    /// The room inside the outline.
620    pub padding: Option<f32>,
621    /// The room on either side of the label.
622    pub label_padding: Option<f32>,
623    /// The chip's height.
624    pub height: Option<f32>,
625    /// The size of a leading icon, a checkmark or a delete cross.
626    pub icon_size: Option<f32>,
627    /// Whether a selected chip shows a checkmark.
628    pub show_checkmark: Option<bool>,
629}
630
631/// Defaults for [`ListTile`](crate::ListTile) — the reference's `ListTileThemeData`.
632///
633/// Every field is what the tile would otherwise decide for itself, on the usual rungs: the
634/// tile's own word, then this, then the framework's. An application that wants all its
635/// tiles rounded, or all its selected rows tinted, says it **once** here rather than on
636/// every tile it ever builds.
637#[derive(Clone, Copy, Debug, Default, PartialEq)]
638pub struct ListTileTheme {
639    /// The tile's surface. Unset, transparent — a tile takes the colour of what it sits on.
640    pub tile_color: Option<Color>,
641    /// The surface while the tile is the chosen one.
642    pub selected_tile_color: Option<Color>,
643    /// The colour its words and slots take while it is the chosen one.
644    pub selected_color: Option<Color>,
645    /// The two slots' icon colour.
646    pub icon_color: Option<Color>,
647    /// The title's and subtitle's colour.
648    pub text_color: Option<Color>,
649    /// What shape the tile is — taken by its surface and by its ink.
650    pub shape: Option<ShapeBorder>,
651    /// The room kept inside the tile, round its content.
652    pub content_padding: Option<Insets>,
653    /// The title's type.
654    pub title_style: Option<TextStyle>,
655    /// The subtitle's.
656    pub subtitle_style: Option<TextStyle>,
657    /// The gap between the slots and the text column.
658    pub title_gap: Option<f32>,
659    /// How much room the leading slot is guaranteed, so the text lines up down a list.
660    pub min_leading_width: Option<f32>,
661    /// The tile's minimum height, over the one its line count asks for.
662    pub min_height: Option<f32>,
663    /// Whether tiles are the tighter kind.
664    pub dense: Option<bool>,
665}
666
667/// Defaults for [`LinearProgressIndicator`](crate::LinearProgressIndicator) and
668/// [`CircularProgressIndicator`](crate::CircularProgressIndicator) — the reference's
669/// `ProgressIndicatorThemeData`.
670///
671/// Neither of them read a theme at all before this, and between them they had **two**
672/// builders: a width and a size. Everything else — the height of the bar, the colour of
673/// its track, the colour of the fill — was decided inside `paint` where nothing could
674/// reach it.
675#[derive(Clone, Copy, Debug, Default, PartialEq)]
676pub struct ProgressTheme {
677    /// The colour of the moving part: the bar's fill and the ring's dots. Unset,
678    /// `primary` (`progress_indicator.dart:1618`).
679    pub color: Option<Color>,
680    /// The colour of the bar's track — the part not yet filled. Unset,
681    /// `secondary_container` (`progress_indicator.dart:1621`).
682    pub linear_track_color: Option<Color>,
683    /// How tall the bar is. Unset, four (`progress_indicator.dart:1624`).
684    pub linear_min_height: Option<f32>,
685    /// The circle **behind the arc** of a circular indicator. Unset, none in the 2023 look;
686    /// in the newer one `secondary_container` for a determinate indicator and none for an
687    /// indeterminate one (`progress_indicator.dart:1590`).
688    pub circular_track_color: Option<Color>,
689    /// The corners of the bar and of its track. Unset, square in the 2023 look and 2 px in
690    /// the newer one (`progress_indicator.dart:1627`).
691    pub border_radius: Option<BorderRadius>,
692    /// The dot at the far end of the track, which says where the bar is going, in the
693    /// newer look. Unset, `primary` (`progress_indicator.dart:1630`).
694    pub stop_indicator_color: Option<Color>,
695    /// That dot's radius, in the newer look. Unset, two (`progress_indicator.dart:1633`).
696    /// Zero draws none.
697    pub stop_indicator_radius: Option<f32>,
698    /// The gap left between a line and the track, in the newer look. Unset, four
699    /// (`progress_indicator.dart:1636`).
700    pub track_gap: Option<f32>,
701    /// **Which look** a bar takes when it does not say: the 2023 one (`true`), or the newer
702    /// one with a gap, a stop dot and rounded ends (`false`). Unset, the 2023 one, as the
703    /// reference's default (`progress_indicator.dart:595`, milestone 629).
704    pub year2023: Option<bool>,
705    /// How thick a circular indicator's arc is. Unset, four
706    /// (`progress_indicator.dart:1593`).
707    pub stroke_width: Option<f32>,
708    /// Where that arc's line sits on the circle: `-1` inside it, `0` centred on it, `1`
709    /// outside. Unset, centred in the 2023 look and inside in the newer one
710    /// (`progress_indicator.dart:1596`, milestone 630).
711    pub stroke_align: Option<f32>,
712    /// How the arc's ends are drawn. Unset, flat — square while spinning — in the 2023 look
713    /// and round in the newer one (`progress_indicator.dart:754`).
714    pub stroke_cap: Option<frus_core::StrokeCap>,
715    /// The side of a circular indicator's circle. Unset, 36 in the 2023 look and 40 in the
716    /// newer one (`progress_indicator.dart:1552`, `:1599`).
717    pub circular_size: Option<f32>,
718    /// The room around a circular indicator's circle. Unset, none in the 2023 look and four
719    /// on every side in the newer one (`progress_indicator.dart:1608`).
720    pub circular_track_padding: Option<f32>,
721}
722
723/// Defaults for [`Tooltip`](crate::Tooltip) — the reference's `TooltipThemeData`.
724///
725/// A tooltip is the one widget an application is likely to use on *every* icon it draws,
726/// so saying what one looks like on each of them is saying it a hundred times.
727#[derive(Clone, Copy, Debug, Default, PartialEq)]
728pub struct TooltipTheme {
729    /// The bubble's surface. Unset, `inverse_surface` — a tooltip is a label **over**
730    /// the interface, not another panel of it.
731    pub background: Option<Color>,
732    /// The label's type. Unset, `body_small`.
733    pub text_style: Option<TextStyle>,
734    /// The label's colour. Unset, `on_inverse_surface`.
735    pub text_color: Option<Color>,
736    /// Where the lines sit once the label has wrapped. Unset, the start edge, as the
737    /// reference's `_defaultTextAlign` is (`tooltip.dart:398`).
738    pub text_align: Option<TextAlign>,
739    /// The room kept round the label.
740    pub padding: Option<Insets>,
741    /// What shape the bubble is.
742    pub shape: Option<ShapeBorder>,
743    /// The radius of its corners, for a theme that would rather give the number than the
744    /// shape. Outranked by [`shape`](Self::shape).
745    pub radius: Option<f32>,
746    /// How wide the bubble may get before the label wraps.
747    pub max_width: Option<f32>,
748}
749
750/// Defaults for [`ExpansionPanelList`](crate::ExpansionPanelList).
751///
752/// A list of panels is one **surface** that splits, so what it needs said once is the
753/// surface: its tone, its corners, the room an open panel is lifted by, and the hairline
754/// between two shut ones.
755#[derive(Clone, Copy, Debug, Default, PartialEq)]
756pub struct ExpansionPanelListTheme {
757    /// The surface the panels are drawn on. Unset, the scheme's low container — the tone
758    /// a card takes, because that is what a run of shut panels is.
759    pub background: Option<Color>,
760    /// The corner radius of a card: the outer corners of a run, and all four of an open
761    /// panel's.
762    pub radius: Option<f32>,
763    /// The room an open panel is given either side of it, which is what makes it read as
764    /// lifted out of the card rather than merely coloured differently.
765    pub gap: Option<f32>,
766    /// The hairline between two shut panels of one card.
767    pub divider_color: Option<Color>,
768    /// How far the cards sit off the page. Unset, the reference's 2; `0.0` is flat.
769    pub elevation: Option<f32>,
770}
771
772/// Defaults for [`ExpansionTile`](crate::ExpansionTile) — the reference's
773/// `ExpansionTileThemeData`.
774///
775/// The tile already had every one of these as a **builder**; what it had nowhere was a
776/// place to say them **once**. A settings screen is a column of these, and an
777/// application that wants its open sections tinted said so on each of them.
778///
779/// Every colour comes in a pair, because an expansion tile is two things: the row that
780/// is always there, and the row while what it hides is showing.
781#[derive(Clone, Copy, Debug, Default, PartialEq)]
782pub struct ExpansionTileTheme {
783    /// The row's surface while the tile is **open**.
784    pub background: Option<Color>,
785    /// And while it is shut.
786    pub collapsed_background: Option<Color>,
787    /// The title's colour while it is open.
788    pub text_color: Option<Color>,
789    /// And while it is shut.
790    pub collapsed_text_color: Option<Color>,
791    /// The chevron's colour while it is open.
792    pub icon_color: Option<Color>,
793    /// And while it is shut.
794    pub collapsed_icon_color: Option<Color>,
795    /// The room kept inside the row, round its content.
796    pub tile_padding: Option<Insets>,
797    /// The room kept round what the tile hides, while it is showing.
798    pub children_padding: Option<Insets>,
799    /// What shape the row is while the tile is open.
800    pub shape: Option<ShapeBorder>,
801    /// And while it is shut. Deliberately **not** falling back to
802    /// [`shape`](Self::shape): the reference keeps the two apart
803    /// (`expansion_tile_theme.dart:55`), and a tile that is square when shut and rounded
804    /// when open is a design, not a mistake.
805    pub collapsed_shape: Option<ShapeBorder>,
806}
807
808/// Defaults for [`FloatingActionButton`](crate::FloatingActionButton) — the
809/// reference's `FloatingActionButtonThemeData`.
810#[derive(Clone, Copy, Debug, Default, PartialEq)]
811pub struct FabTheme {
812    /// The surface. Unset, `primary_container`
813    /// (`floating_action_button.dart:810`) — **not** `primary`, which is what a filled
814    /// button takes and what this framework's `fab_button` helper was giving it.
815    pub background: Option<Color>,
816    /// What is drawn on it. Unset, `on_primary_container`.
817    pub foreground: Option<Color>,
818    /// How far off the page it sits at rest. Unset, six.
819    pub elevation: Option<f32>,
820    /// And under a pointer. Unset, eight — whatever the resting height is, as the reference's
821    /// build resolves it (line 517).
822    pub hover_elevation: Option<f32>,
823    /// What shape it is. Unset, the corner its size asks for — sixteen, twelve or
824    /// twenty-eight (`floating_action_button.dart:816`).
825    pub shape: Option<ShapeBorder>,
826    /// The radius of its corners, for a theme that would rather give the number than the
827    /// shape. Outranked by [`shape`](Self::shape).
828    pub radius: Option<f32>,
829    /// How big the glyph inside is. Unset, the size's own — twenty-four, or
830    /// thirty-six on a large one.
831    pub icon_size: Option<f32>,
832    /// An extended button's type. Unset, `label_large`.
833    pub label_style: Option<TextStyle>,
834    /// The room either side of an extended button's content.
835    pub extended_padding: Option<f32>,
836    /// The gap between an extended button's glyph and its words. Unset, eight.
837    pub extended_gap: Option<f32>,
838}
839
840/// Which glyphs the framework's four named buttons carry — the reference's
841/// `ActionIconTheme` (`action_icons_theme.dart`).
842///
843/// Unset, each takes the framework's own, and the back arrow takes the platform's: a
844/// chevron where the platform's own back control is a chevron, an arrow everywhere else.
845/// An application with its own icon set should not have to leave four of the framework's
846/// showing through.
847#[derive(Clone, Copy, Debug, Default, PartialEq)]
848pub struct ActionIconTheme {
849    /// The glyph on a [`BackButton`](crate::BackButton).
850    pub back: Option<crate::IconData>,
851    /// On a [`CloseButton`](crate::CloseButton).
852    pub close: Option<crate::IconData>,
853    /// On a [`DrawerButton`](crate::DrawerButton).
854    pub drawer: Option<crate::IconData>,
855    /// On an [`EndDrawerButton`](crate::EndDrawerButton).
856    pub end_drawer: Option<crate::IconData>,
857}
858
859/// Defaults for [`Divider`](crate::Divider).
860#[derive(Clone, Copy, Debug, Default, PartialEq)]
861pub struct DividerTheme {
862    /// The room the separator takes in the layout.
863    pub height: Option<f32>,
864    /// The thickness of the line drawn inside that room.
865    pub thickness: Option<f32>,
866    /// Its colour.
867    pub color: Option<Color>,
868    /// Its inset from the leading edge.
869    pub indent: Option<f32>,
870    /// Its inset from the trailing edge.
871    pub end_indent: Option<f32>,
872}
873
874/// Defaults for [`Drawer`](crate::Drawer).
875///
876/// The rounding is on the **inner** edge only — the one that meets the content — and
877/// the outer edge stays square against the window it is docked to, which is what the
878/// reference's own shape resolves to. Which edge that is follows the direction: the
879/// panel does not know which side of the screen it landed on until it paints.
880#[derive(Clone, Copy, Debug, Default, PartialEq)]
881pub struct DrawerTheme {
882    /// **What shape a leading panel is** — the reference's `DrawerThemeData.shape`
883    /// (`drawer.dart:268`). Unset, the framework rounds the panel's *inner* edge by
884    /// [`DRAWER_RADIUS`](crate::DRAWER_RADIUS).
885    pub shape: Option<ShapeBorder>,
886    /// **And a trailing one** — the reference's `endShape` (`drawer.dart:269`), which is a
887    /// separate field rather than a mirror of the first because a panel's rounded edge is
888    /// the one facing the page, and that is the opposite side.
889    ///
890    /// A trailing panel does **not** fall back to [`shape`](Self::shape): a theme that
891    /// named only the leading panel's shape has said nothing about the other one, and the
892    /// framework's own default is a better answer than a shape rounded on the wrong edge.
893    pub end_shape: Option<ShapeBorder>,
894    /// The panel's width.
895    pub width: Option<f32>,
896    /// The panel's fill.
897    pub background_color: Option<Color>,
898    /// The hairline on the panel's inner edge.
899    pub border_color: Option<Color>,
900    /// That hairline's thickness; `0.0` removes it.
901    pub border_width: Option<f32>,
902    /// The rounding of the **inner** edge's two corners — the edge that meets the
903    /// content. The outer one stays square against the window.
904    pub radius: Option<f32>,
905    /// How far off the surface the panel sits. `0.0` casts no shadow, and neither does a
906    /// height with no [`shadow_color`](Self::shadow_color).
907    pub elevation: Option<f32>,
908    /// The shadow's colour. Unset, **transparent**, as the reference's Material 3 drawer is
909    /// (its defaults, line 795): a panel is lifted by its tone, and shadowed only on request.
910    pub shadow_color: Option<Color>,
911    /// The scrim behind a modal panel, **alpha included**.
912    pub scrim_color: Option<Color>,
913}
914
915/// Defaults for [`SegmentedButton`](crate::SegmentedButton).
916#[derive(Clone, Copy, Debug, Default, PartialEq)]
917pub struct SegmentedTheme {
918    /// The fill under the chosen segment.
919    pub selected_color: Option<Color>,
920    /// The labels' colour.
921    pub label_color: Option<Color>,
922    /// The chosen segment's label colour, and its checkmark's.
923    pub selected_label_color: Option<Color>,
924    /// The outline's colour, and the hairlines' between segments.
925    pub border_color: Option<Color>,
926    /// Their thickness; `0.0` removes both.
927    pub border_width: Option<f32>,
928    /// The group's outer radius. Unset, the ends are stadium-rounded.
929    pub radius: Option<f32>,
930    /// The control's height.
931    pub height: Option<f32>,
932    /// The room either side of a label.
933    pub padding: Option<f32>,
934    /// The labels' type.
935    pub label_style: Option<TextStyle>,
936    /// The checkmark's size.
937    pub icon_size: Option<f32>,
938    /// Whether the chosen segment carries a checkmark.
939    pub show_selected_icon: Option<bool>,
940}
941
942/// Defaults for [`TabBar`](crate::TabBar) — the bar, its labels and its indicator.
943#[derive(Clone, Copy, Debug, Default, PartialEq)]
944pub struct TabBarTheme {
945    /// Which of the two bars an untold `TabBar::new()` is.
946    pub variant: Option<crate::tabs::TabBarVariant>,
947    /// The indicator's colour.
948    pub indicator_color: Option<Color>,
949    /// Its thickness — and, on a primary bar, the radius of its top corners.
950    pub indicator_weight: Option<f32>,
951    /// The **selected** label's colour.
952    pub label_color: Option<Color>,
953    /// Every other label's colour.
954    pub unselected_label_color: Option<Color>,
955    /// The labels' type.
956    pub label_style: Option<TextStyle>,
957    /// The colour of the hairline between the bar and what it labels.
958    pub divider_color: Option<Color>,
959    /// Its thickness; `0.0` removes it.
960    pub divider_height: Option<f32>,
961    /// The room on either side of a label.
962    pub label_padding: Option<f32>,
963    /// The tabs' height, the indicator excluded.
964    pub tab_height: Option<f32>,
965    /// Where the tabs sit when they do not fill the bar.
966    pub alignment: Option<crate::tabs::TabAlignment>,
967}
968
969/// Defaults for [`TabPageSelector`](crate::TabPageSelector) — the row of dots that says
970/// which page of several you are on.
971#[derive(Clone, Copy, Debug, Default, PartialEq)]
972pub struct PageSelectorTheme {
973    /// A dot's diameter.
974    pub size: Option<f32>,
975    /// The gap between two dots.
976    pub gap: Option<f32>,
977    /// What the dot you are on is filled with. Unset, the accent.
978    pub color: Option<Color>,
979    /// The ring every dot is drawn with.
980    pub border_color: Option<Color>,
981}
982
983/// Defaults for [`IconButton`](crate::IconButton).
984#[derive(Clone, Copy, Debug, Default, PartialEq)]
985pub struct IconButtonTheme {
986    /// The box's side.
987    pub size: Option<f32>,
988    /// The glyph's size inside it.
989    pub icon_size: Option<f32>,
990    /// The surface under the glyph.
991    pub color: Option<Color>,
992    /// The glyph's colour.
993    pub icon_color: Option<Color>,
994    /// The outline's colour.
995    pub border_color: Option<Color>,
996    /// Its thickness; `0.0` removes it.
997    pub border_width: Option<f32>,
998    /// The corner radii. Unset, an icon button is a circle.
999    pub radius: Option<BorderRadius>,
1000    /// **How much room it reserves for a finger** — the reference's per-widget say over
1001    /// the theme's (`icon_button.dart:708`). Unset, the theme's own answer.
1002    pub tap_target: Option<crate::theme::TapTarget>,
1003}
1004
1005/// Defaults for the **ink ripple** — every surface that splashes, including
1006/// [`InkWell`](crate::InkWell) and [`Button`](crate::Button).
1007#[derive(Clone, Copy, Debug, Default, PartialEq)]
1008pub struct InkTheme {
1009    /// The splash colour, **alpha included**. A widget that computes its own from its
1010    /// surface (a button splashing in its `on` colour) still yields to this when it is
1011    /// set: an application that has chosen an ink colour has chosen it everywhere.
1012    pub color: Option<Color>,
1013}
1014
1015/// Defaults for [`SnackBar`](crate::SnackBar).
1016///
1017/// The reference's Material 3 snackbar sets its content in `bodyMedium` and its action in
1018/// `labelLarge`, and both are read from the type scale rather than written down here.
1019#[derive(Clone, Copy, Debug, Default, PartialEq)]
1020pub struct SnackBarTheme {
1021    /// **What shape it is** (`shape_border.dart`), over the plain `radius` below:
1022    /// a snack bar's, which its behaviour already decides — see [`crate::SnackBarBehavior`]. Unset, the widget decides.
1023    pub shape: Option<ShapeBorder>,
1024    /// **Where its bars sit**, and therefore what they look like. Unset, the reference's
1025    /// `Fixed` (`snack_bar.dart:986`). See [`SnackBarBehavior`](crate::SnackBarBehavior).
1026    pub behavior: Option<crate::toast::SnackBarBehavior>,
1027    /// What a **floating** bar keeps clear of the page. Unset, the reference's
1028    /// `insetPadding` (`snack_bar.dart:989`). Silent under `Fixed`.
1029    pub inset_padding: Option<Insets>,
1030    /// A **floating** bar's width, instead of the room it is given. Unset, the room it is
1031    /// given. Silent under `Fixed`, where a width would contradict the behaviour.
1032    pub width: Option<f32>,
1033    /// The message's type.
1034    pub content_text_style: Option<TextStyle>,
1035    /// The action's type.
1036    pub action_text_style: Option<TextStyle>,
1037    /// The bar's surface. Unset, the scheme's `inverse_surface`.
1038    pub background_color: Option<Color>,
1039    /// The message's colour. Unset, the scheme's `on_inverse_surface`.
1040    pub text_color: Option<Color>,
1041    /// The action's colour. Unset, the scheme's `inverse_primary` — the one role in the
1042    /// scheme whose whole reason for existing is being legible on an inverted surface.
1043    pub action_text_color: Option<Color>,
1044    /// The close cross's colour. Unset, the scheme's `on_inverse_surface`
1045    /// (`snack_bar.dart:995`).
1046    pub close_icon_color: Option<Color>,
1047    /// The stripe down a notification's leading edge, whichever kind it is. Unset, the
1048    /// kind decides.
1049    pub accent_color: Option<Color>,
1050    /// The stripe for a **success**, the one kind Material 3 has no role for. Unset, a
1051    /// green of this crate's own choosing.
1052    pub success_color: Option<Color>,
1053    /// The corner. Unset, the reference's 4 for a **floating** bar and **nothing at all**
1054    /// for a fixed one, which is flush against the edges and has nothing to round.
1055    pub radius: Option<f32>,
1056    /// How far off the page it sits. Unset, the reference's 6.
1057    pub elevation: Option<f32>,
1058}
1059
1060/// Defaults for [`PopupMenuButton`](crate::PopupMenuButton) and its items.
1061#[derive(Clone, Copy, Debug, Default, PartialEq)]
1062pub struct MenuTheme {
1063    /// The items' type.
1064    pub text_style: Option<TextStyle>,
1065    /// **The panel's surface.** Unset, `surface_container` — a menu is a distinct area
1066    /// within the surface, not a thing that floats above it in a different colour
1067    /// (`popup_menu.dart:1858`).
1068    pub background: Option<Color>,
1069    /// What shape the panel is.
1070    pub shape: Option<ShapeBorder>,
1071    /// The radius of its corners, for a theme that would rather give the number than the
1072    /// shape. Outranked by [`shape`](Self::shape).
1073    pub radius: Option<f32>,
1074    /// How far off the page the panel sits, in pixels. Unset, three
1075    /// (`popup_menu.dart:1839`).
1076    pub elevation: Option<f32>,
1077    /// The colour of the panel's shadow. Unset, the scheme's shadow at 30 %, the
1078    /// framework's colour for a height; [`Color::TRANSPARENT`] casts none.
1079    pub shadow_color: Option<Color>,
1080    /// The room kept **above and below** the rows, inside the panel
1081    /// (`popup_menu.dart:1872`).
1082    pub padding: Option<Insets>,
1083    /// The room kept either side of a row's label (`popup_menu.dart:1876`).
1084    pub item_padding: Option<Insets>,
1085    /// How tall one row is. Unset, the smallest box a finger can be asked to hit.
1086    pub item_height: Option<f32>,
1087    /// **An outline round the panel.** Unset, none: the panel's shadow says it is off the
1088    /// page. A desktop's menus draw a hairline as well (milestone 636).
1089    pub border: Option<frus_core::BorderSide>,
1090    /// **How much room a separator takes**, its line in the middle. Unset, the divider's own.
1091    pub divider_height: Option<f32>,
1092}
1093
1094impl MenuTheme {
1095    /// This theme, with `other`'s answer wherever this one says nothing.
1096    pub fn or(self, other: MenuTheme) -> MenuTheme {
1097        MenuTheme {
1098            text_style: self.text_style.or(other.text_style),
1099            background: self.background.or(other.background),
1100            shape: self.shape.or(other.shape),
1101            radius: self.radius.or(other.radius),
1102            elevation: self.elevation.or(other.elevation),
1103            shadow_color: self.shadow_color.or(other.shadow_color),
1104            padding: self.padding.or(other.padding),
1105            item_padding: self.item_padding.or(other.item_padding),
1106            item_height: self.item_height.or(other.item_height),
1107            border: self.border.or(other.border),
1108            divider_height: self.divider_height.or(other.divider_height),
1109        }
1110    }
1111
1112    /// **A desktop's menus** (milestone 636): 13 px words on 26 px rows, 12 px either side,
1113    /// 4 px above and below the rows, a 6 px corner, a hairline in `outline_variant`, a low
1114    /// shadow, and 9 px separators — what an application's menus on Linux, macOS and Windows
1115    /// look like, rather than a phone's 48 px rows.
1116    pub fn desktop(theme: &crate::Theme) -> MenuTheme {
1117        MenuTheme {
1118            text_style: Some(TextStyle::new(13.0)),
1119            background: None,
1120            shape: None,
1121            radius: Some(6.0),
1122            elevation: Some(2.0),
1123            shadow_color: None,
1124            padding: Some(Insets::new(4.0, 0.0, 4.0, 0.0)),
1125            item_padding: Some(Insets::new(0.0, 12.0, 0.0, 12.0)),
1126            item_height: Some(26.0),
1127            border: Some(frus_core::BorderSide::new(
1128                theme.scheme.outline_variant,
1129                1.0,
1130            )),
1131            divider_height: Some(9.0),
1132        }
1133    }
1134}
1135
1136/// **The window's three buttons**, as the application paints them on the title bar's line
1137/// (milestone 640). Every colour optional: unset, the desktop's.
1138#[derive(Clone, Copy, Debug, Default, PartialEq)]
1139pub struct CaptionButtonsTheme {
1140    /// The glyphs. Unset, the line's foreground ([`TitleBarTheme`], the system's), then
1141    /// `on_surface`.
1142    pub glyph_color: Option<Color>,
1143    /// The glyphs of a window that is not the active one. Unset, the line's inactive
1144    /// foreground, then the glyph half way to the line.
1145    pub inactive_glyph_color: Option<Color>,
1146    /// Under the pointer. Unset, the glyph at 8 % over the line.
1147    pub hover_color: Option<Color>,
1148    /// Pressed. Unset, the glyph at 4 % over the line.
1149    pub pressed_color: Option<Color>,
1150    /// The close button under the pointer. Unset, the desktop's red.
1151    pub close_hover_color: Option<Color>,
1152    /// The close button pressed. Unset, a darker red.
1153    pub close_pressed_color: Option<Color>,
1154    /// The close glyph on red. Unset, white.
1155    pub close_glyph_hover_color: Option<Color>,
1156}
1157
1158/// **The colours of a [`WindowMenuBar`](crate::WindowMenuBar)'s line** (milestone 642), on the
1159/// title bar's line or under the system's.
1160///
1161/// Every colour optional. Unset, **the system's**: on the title bar's line, the window's
1162/// caption as the desktop draws it — light or dark as the system's apps are, the accent
1163/// colour where the person asked for it on title bars, quieter on a window that is not the
1164/// active one. Where the system says nothing — off the line — the
1165/// [`MenuBarTheme`]'s, then `surface_container` and `on_surface`.
1166///
1167/// What it says reaches everything on the line: the bar's words and their highlight, and the
1168/// window's three buttons' glyphs and washes, unless their own themes say otherwise.
1169#[derive(Clone, Copy, Debug, Default, PartialEq)]
1170pub struct TitleBarTheme {
1171    /// The line's surface.
1172    pub background: Option<Color>,
1173    /// The words and glyphs on it.
1174    pub foreground: Option<Color>,
1175    /// The line's surface on a window that is not the active one. Unset, `background`'s
1176    /// answer for an inactive window.
1177    pub inactive_background: Option<Color>,
1178    /// The words and glyphs on a window that is not the active one. Unset, `foreground`'s
1179    /// answer for an inactive window.
1180    pub inactive_foreground: Option<Color>,
1181}
1182
1183/// Defaults for [`MenuBar`](crate::MenuBar): the bar, the words on it, and the menus it opens
1184/// (milestone 636).
1185///
1186/// Unset, a bar on a desktop theme (Linux, macOS, Windows) is a desktop's — 30 px tall,
1187/// 13 px words 8 px either side, a rounded highlight on the word under the pointer and on
1188/// the word whose menu is open — and on a phone's theme it keeps the 48 px a finger needs.
1189#[derive(Clone, Copy, Debug, Default, PartialEq)]
1190pub struct MenuBarTheme {
1191    /// How tall the bar is.
1192    pub height: Option<f32>,
1193    /// The bar's surface. Unset, `surface_container`.
1194    pub background: Option<Color>,
1195    /// The room at the bar's ends, around the row of words.
1196    pub padding: Option<Insets>,
1197    /// The room either side of a word.
1198    pub item_padding: Option<Insets>,
1199    /// The words' type.
1200    pub text_style: Option<TextStyle>,
1201    /// The words' colour. Unset, `on_surface`.
1202    pub foreground: Option<Color>,
1203    /// The highlight behind the word under the pointer, and behind the word whose menu is
1204    /// open. Unset, `on_surface` over the bar, at 8 % and 12 %.
1205    pub highlight: Option<Color>,
1206    /// The highlight's corners.
1207    pub item_radius: Option<f32>,
1208    /// The room the highlight keeps above and below it, inside the bar.
1209    pub item_inset: Option<f32>,
1210    /// **The menus the bar opens.** What this says outranks the desktop's menus and then the
1211    /// application's [`MenuTheme`].
1212    pub menus: MenuTheme,
1213}
1214
1215/// Defaults for [`DropdownButton`](crate::DropdownButton) and its options.
1216///
1217/// The `menu_*` fields are the **panel** its options float on. They are this theme's and
1218/// not [`MenuTheme`]'s, because the reference's dropdown button does not read the menu
1219/// theme either: its list has its own height, eight, where a menu has three.
1220#[derive(Clone, Copy, Debug, Default, PartialEq)]
1221pub struct DropdownTheme {
1222    /// The value's and the options' type.
1223    pub text_style: Option<TextStyle>,
1224    /// The panel's surface. Unset, `surface_container`, the popup menu's.
1225    pub menu_background: Option<Color>,
1226    /// What shape the panel is.
1227    pub menu_shape: Option<ShapeBorder>,
1228    /// The radius of the panel's corners, for a theme that would rather give the number
1229    /// than the shape. Outranked by [`menu_shape`](Self::menu_shape).
1230    pub menu_radius: Option<f32>,
1231    /// How far off the page the panel sits, in pixels. Unset, eight, the reference's.
1232    pub menu_elevation: Option<f32>,
1233    /// The colour of the panel's shadow. Unset, the scheme's shadow at 30 %;
1234    /// [`Color::TRANSPARENT`] casts none.
1235    pub menu_shadow_color: Option<Color>,
1236    /// The room kept **above and below** the options, inside the panel. Unset, eight.
1237    pub menu_padding: Option<Insets>,
1238}
1239
1240/// Defaults for [`Autocomplete`](crate::Autocomplete) and its suggestions.
1241#[derive(Clone, Copy, Debug, Default, PartialEq)]
1242pub struct AutocompleteTheme {
1243    /// The suggestions' type.
1244    pub text_style: Option<TextStyle>,
1245}
1246
1247/// Defaults for [`Table`](crate::Table).
1248///
1249/// The reference names the two apart — a heading is `titleSmall`, a cell is `bodyMedium` —
1250/// which is why one `text_style` would be the wrong shape here.
1251#[derive(Clone, Copy, Debug, Default, PartialEq)]
1252pub struct TableTheme {
1253    /// The column headings' type.
1254    pub heading_text_style: Option<TextStyle>,
1255    /// The cells' type.
1256    pub data_text_style: Option<TextStyle>,
1257}
1258
1259/// Defaults for [`DatePicker`](crate::DatePicker).
1260#[derive(Clone, Copy, Debug, Default, PartialEq)]
1261pub struct DatePickerTheme {
1262    /// The days' type.
1263    pub day_text_style: Option<TextStyle>,
1264    /// The weekday initials above them.
1265    pub weekday_text_style: Option<TextStyle>,
1266}
1267
1268/// Defaults for the **scrollbars** the framework draws over a scrollable.
1269///
1270/// The thumb is a **fade of one colour**, not three colours: at rest, warmed towards its
1271/// hovered value under a pointer, and at its held value the moment it is grabbed. A theme
1272/// substitutes the colour being faded and may move the three levels; it does not hand
1273/// over three finished colours, because interpolating between those means interpolating
1274/// colours and this framework has been bitten by doing that in the wrong space more than
1275/// once. Fading one colour is the arithmetic that was already right.
1276///
1277/// There is no field for a **track**. The framework paints none — the reference's is
1278/// transparent unless a caller asks for one — and a field that painted nothing whatever
1279/// it was set to would be worse than no field.
1280#[derive(Clone, Copy, Debug, Default, PartialEq)]
1281pub struct ScrollbarTheme {
1282    /// The thumb's thickness. Unset, 8, or 4 under a theme whose platform is Android —
1283    /// and it is the **thumb's**, not a slot's: the margin holds it clear of the edge
1284    /// rather than shrinking it to fit.
1285    pub thickness: Option<f32>,
1286    /// How far the thumb is held clear of the edge it runs along. Unset, 2, or none under
1287    /// an Android theme.
1288    pub margin: Option<f32>,
1289    /// How short the thumb is allowed to get on a very long page. Unset, 48 — below
1290    /// which it stops reading as a handle and stops being one to grab.
1291    pub min_thumb_length: Option<f32>,
1292    /// The thumb's corner radius. Unset, half its thickness, which is a pill — or square
1293    /// ends under an Android theme.
1294    pub radius: Option<f32>,
1295    /// The colour the thumb is a fade of. Unset, the scheme's `on_surface`.
1296    pub thumb_color: Option<Color>,
1297    /// Its opacity at rest. Unset, 0.30 on a dark surface and 0.10 on a light one; under an
1298    /// Android theme, with no `thumb_color` either, the thumb rests an opaque grey instead.
1299    pub opacity: Option<f32>,
1300    /// Its opacity with a pointer near it, which it warms towards. Unset, 0.65 and 0.50.
1301    pub hover_opacity: Option<f32>,
1302    /// Its opacity while it is held. Unset, 0.75 and 0.60. This one does not fade in —
1303    /// the hand is already on it, and a fade would only lag behind the grab.
1304    pub drag_opacity: Option<f32>,
1305    /// Whether a pointer can wake, hover and drag the thumb. Unset, it can — except under
1306    /// a theme whose platform is Android, where the bar only shows where the page is
1307    /// (`scrollbar.dart:218`).
1308    pub interactive: Option<bool>,
1309}
1310
1311/// Defaults for [`NavigationBar`](crate::NavigationBar) — the bar at the **head** of a
1312/// screen, not the one along the bottom, which is `NavRailTheme`.
1313///
1314/// There is no field for the back button's size. The bar names one explicitly when it
1315/// builds the button, and an explicit argument outranks a theme — a field here would be
1316/// one that the widget never reads, which is worse than an absent one. A theme that wants
1317/// a different back button sets [`IconButtonTheme`] and drops the bar's own override.
1318#[derive(Clone, Copy, Debug, Default, PartialEq)]
1319pub struct NavBarTheme {
1320    /// The room the bar takes. Unset, 56 — the reference's toolbar height.
1321    pub height: Option<f32>,
1322    /// The bar's own padding. Unset, nothing above or below and a leading inset that
1323    /// clears the back-gesture zone, so the button stays clickable without starting a
1324    /// swipe.
1325    pub padding: Option<Insets>,
1326    /// What it is painted on. Unset, the theme's background.
1327    pub background: Option<Color>,
1328    /// The title's type. Unset, the theme's `title_large` — a bar title is a *title*, not
1329    /// body text. Its `color`, when set, is the title's colour.
1330    pub title_style: Option<TextStyle>,
1331    /// The hairline along the bottom edge. Unset, the scheme's `outline_variant`.
1332    pub divider_color: Option<Color>,
1333    /// How thick that hairline is. Unset, one pixel.
1334    pub divider_thickness: Option<f32>,
1335}
1336
1337/// Defaults for [`NavigationRail`](crate::NavigationRail) and [`BottomBar`](crate::BottomBar).
1338#[derive(Clone, Debug, Default, PartialEq)]
1339pub struct NavRailTheme {
1340    /// **The shape of a selected destination's indicator** (`navigation_rail.dart:1148`).
1341    /// Unset, the reference's pill.
1342    pub indicator_shape: Option<frus_core::ShapeBorder>,
1343    /// **The highlight over a destination, per state** — over the framework's own state
1344    /// layer, and under the destination's own word (`navigation_bar.dart:232`).
1345    ///
1346    /// The first field here that is not a plain value but a
1347    /// [`WidgetStateProperty`](crate::WidgetStateProperty). It owns a `Vec`, which is why
1348    /// this struct and [`WidgetThemes`] stopped being `Copy` in milestone 448 — a theme
1349    /// that weighed eight kilobytes had no business being copied implicitly anyway.
1350    pub overlay_color: Option<crate::widgetstate::WidgetStateProperty<frus_core::Color>>,
1351    /// The destinations' labels.
1352    pub label_text_style: Option<TextStyle>,
1353    /// The count carried by a destination's badge.
1354    pub badge_text_style: Option<TextStyle>,
1355    /// The **rail's** surface. Unset, the scheme's `surface`.
1356    pub background_color: Option<Color>,
1357    /// The pill behind the selected destination. Unset, the scheme's
1358    /// `secondary_container` — **opaque**, as the reference's is.
1359    pub indicator_color: Option<Color>,
1360    /// The selected destination's glyph. Unset, `on_secondary_container`: it is drawn on
1361    /// the indicator, so it takes the indicator's content colour.
1362    pub selected_icon_color: Option<Color>,
1363    /// An unselected destination's glyph. Unset, `on_surface_variant`.
1364    pub unselected_icon_color: Option<Color>,
1365    /// The selected destination's label. Unset, `on_surface` — the label sits *below* the
1366    /// indicator rather than on it, which is why it is not the indicator's content colour.
1367    pub selected_label_color: Option<Color>,
1368    /// An unselected destination's label. Unset, `on_surface` on a rail and
1369    /// `on_surface_variant` on a bar, which is the one place the reference gives the two
1370    /// different answers.
1371    pub unselected_label_color: Option<Color>,
1372    /// The destinations' glyphs. Unset, the reference's 24.
1373    pub icon_size: Option<f32>,
1374    /// Whether a **rail's** selected destination gets an indicator behind its glyph.
1375    /// Unset, `true` (`navigation_rail.dart:1233`). `false` is the arrangement that
1376    /// predates it, where the selected destination says so in the accent instead.
1377    pub use_indicator: Option<bool>,
1378    /// How far off the page a **rail** sits. Unset, `0` — flat, as the reference's is
1379    /// (`navigation_rail.dart:1236`), the rail being separated by a rule and not by a
1380    /// shadow.
1381    pub elevation: Option<f32>,
1382    /// The **bottom bar's** surface, a rung higher than the rail's. Unset, the scheme's
1383    /// `surface_container`.
1384    ///
1385    /// The reference keeps a theme object per navigation widget and gives them different
1386    /// defaults; this crate keeps one for the two, so the two surfaces are two fields
1387    /// rather than two structs.
1388    pub bar_background_color: Option<Color>,
1389}
1390
1391/// Defaults for [`SearchBar`](crate::SearchBar) — the reference's `SearchBarThemeData`.
1392///
1393/// Every field there is a `WidgetStateProperty`, resolved against the bar's own state; here
1394/// they are plain values, with one exception that matters and several that do not. The
1395/// exception is the highlight, and this framework already answers it: a state layer is one
1396/// rule applied from the ground toward the ink, so a bar does not need a colour per state
1397/// to light under a pointer. The rest — a fill, a shape or a padding that changes when the
1398/// bar is hovered — are things the reference *can* say and its own defaults never do.
1399#[derive(Clone, Copy, Debug, Default, PartialEq)]
1400pub struct SearchBarTheme {
1401    /// The bar's fill. Unset, the scheme's `surface_container_high`
1402    /// (`search_anchor.dart:1859`).
1403    pub background_color: Option<Color>,
1404    /// The colour its shadow is cast in, **alpha included**. Unset, the scheme's `shadow`
1405    /// at 30 %.
1406    pub shadow_color: Option<Color>,
1407    /// How far off the page it sits. Unset, `6` (`search_anchor.dart:1863`).
1408    pub elevation: Option<f32>,
1409    /// Its shape. Unset, a stadium (`search_anchor.dart:1892`).
1410    pub shape: Option<frus_core::ShapeBorder>,
1411    /// Its corners, read as a rounded rectangle when no shape was named.
1412    pub radius: Option<BorderRadius>,
1413    /// An outline around it. Unset, none — the reference has no default side
1414    /// (`search_anchor.dart:1888`), a raised surface being told apart by its shadow.
1415    pub side: Option<frus_core::BorderSide>,
1416    /// The room inside it. Unset, `8` either side, applied twice (once around the row and
1417    /// once around the field), which is where the sixteen between an icon and the first
1418    /// letter comes from.
1419    pub padding: Option<frus_core::Insets>,
1420    /// The narrowest it will go. Unset, `360`.
1421    pub min_width: Option<f32>,
1422    /// The widest. Unset, `800`.
1423    pub max_width: Option<f32>,
1424    /// Its height. Unset, `56`.
1425    pub height: Option<f32>,
1426    /// The value's type. Unset, `bodyLarge` in `on_surface`.
1427    pub text_style: Option<TextStyle>,
1428    /// The hint's. Unset, the value's, then `bodyLarge` in `on_surface_variant` — the
1429    /// reference falls back to the value's style **before** its own default, so a bar told
1430    /// to use one type does not say its hint in another.
1431    pub hint_style: Option<TextStyle>,
1432}
1433
1434/// Defaults for the view a [`SearchAnchor`](crate::SearchAnchor) opens — the reference's
1435/// `SearchViewThemeData`.
1436///
1437/// Kept apart from [`SearchBarTheme`] because the reference keeps them apart, and because
1438/// the two disagree where it matters: the view's shape depends on whether it is the screen,
1439/// its header is taller than a bar when it is, and it has a rule under that header that a
1440/// bar has nothing to do with.
1441#[derive(Clone, Copy, Debug, Default, PartialEq)]
1442pub struct SearchViewTheme {
1443    /// The view's fill. Unset, the scheme's `surface_container_high`
1444    /// (`search_anchor.dart:1936`) — the same rung the bar takes, so one grows out of the
1445    /// other rather than changing colour on the way.
1446    pub background_color: Option<Color>,
1447    /// How far off the page it sits. Unset, `6`.
1448    pub elevation: Option<f32>,
1449    /// Its shape. Unset, corners of `28` floating and square full-screen.
1450    pub shape: Option<frus_core::ShapeBorder>,
1451    /// Its corners, read as a rounded rectangle when no shape was named.
1452    pub radius: Option<BorderRadius>,
1453    /// An outline around it. Unset, none (`search_anchor.dart:1944`).
1454    pub side: Option<frus_core::BorderSide>,
1455    /// The rule under the header. Unset, the scheme's `outline`
1456    /// (`search_anchor.dart:1967`).
1457    pub divider_color: Option<Color>,
1458    /// The header's height. Unset, `72` full-screen and a bar's `56` floating.
1459    pub header_height: Option<f32>,
1460    /// The header's type. Unset, `bodyLarge` in `on_surface`.
1461    pub header_text_style: Option<TextStyle>,
1462    /// The header hint's. Unset, `bodyLarge` in `on_surface_variant`.
1463    pub header_hint_style: Option<TextStyle>,
1464    /// The narrowest the view goes. Unset, `360`.
1465    pub min_width: Option<f32>,
1466    /// The shortest. Unset, `240`.
1467    pub min_height: Option<f32>,
1468    /// The room either side of the header's contents. Unset, `8`.
1469    pub bar_padding: Option<frus_core::Insets>,
1470}
1471
1472/// Defaults for [`NavigationDrawer`](crate::NavigationDrawer).
1473///
1474/// The reference keeps `NavigationDrawerThemeData` apart from the rail's and the bar's
1475/// (`navigation_drawer_theme.dart`) and this follows it, where [`NavRailTheme`] holds two
1476/// widgets at once. The reason is the defaults: a drawer's surface, type step, indicator
1477/// size and tile height all differ from a rail's, and a shared struct would have had to
1478/// carry a second copy of every one of them.
1479#[derive(Clone, Debug, Default, PartialEq)]
1480pub struct NavDrawerTheme {
1481    /// The panel's surface. Unset, the scheme's `surface_container_low`
1482    /// (`navigation_drawer.dart:740`) — a rung above a rail's `surface`, the drawer being
1483    /// a sheet over the page rather than a strip beside it.
1484    pub background_color: Option<Color>,
1485    /// How far off the page the panel sits. Unset, `1` (`navigation_drawer.dart:729`).
1486    pub elevation: Option<f32>,
1487    /// The shadow's colour. Unset, **transparent**, as the reference's navigation drawer
1488    /// defaults are (line 746): the panel's height is its tone, and a shadow is cast only
1489    /// where a colour is named.
1490    pub shadow_color: Option<Color>,
1491    /// The pill behind the selected destination. Unset, the scheme's
1492    /// `secondary_container`.
1493    pub indicator_color: Option<Color>,
1494    /// That pill's shape. Unset, a stadium (`navigation_drawer.dart:731`).
1495    pub indicator_shape: Option<frus_core::ShapeBorder>,
1496    /// That pill's box, `(width, height)`. Unset, `336 x 56`
1497    /// (`navigation_drawer.dart:732`). The width is a **ceiling**: the pill never grows
1498    /// past the room its tile has, which is what keeps 336 inside a 304-wide panel.
1499    pub indicator_size: Option<(f32, f32)>,
1500    /// The highlight over a destination, per state — over the framework's state layer, and
1501    /// under the destination's own word.
1502    pub overlay_color: Option<crate::widgetstate::WidgetStateProperty<frus_core::Color>>,
1503    /// A tile's height. Unset, `56` (`navigation_drawer.dart:730`).
1504    pub tile_height: Option<f32>,
1505    /// The room either side of a tile. Unset, `12` left and right
1506    /// (`navigation_drawer.dart:69`).
1507    pub tile_padding: Option<frus_core::Insets>,
1508    /// The destinations' glyphs. Unset, `24`.
1509    pub icon_size: Option<f32>,
1510    /// The destinations' labels. Unset, `labelLarge` (`navigation_drawer.dart:768`) — a
1511    /// step above a rail's, a drawer's label having a line to itself.
1512    pub label_text_style: Option<TextStyle>,
1513    /// The count a destination carries. Unset, `labelSmall`.
1514    pub badge_text_style: Option<TextStyle>,
1515    /// A selected destination's glyph **and** label. Unset, `on_secondary_container`:
1516    /// here the indicator is the whole row, so both stand on it and both take its content
1517    /// colour — the one place this differs from a rail, where the label sits outside the
1518    /// pill.
1519    pub selected_color: Option<Color>,
1520    /// An unselected destination's glyph and label. Unset, `on_surface_variant`.
1521    pub unselected_color: Option<Color>,
1522}
1523
1524/// Defaults for [`Alert`](crate::Alert) — the message box, not the dialog. See
1525/// [`DialogTheme`] for [`AlertDialog`](crate::AlertDialog).
1526#[derive(Clone, Copy, Debug, Default, PartialEq)]
1527pub struct AlertTheme {
1528    /// The heading's type.
1529    pub title_text_style: Option<TextStyle>,
1530    /// The message's type.
1531    pub content_text_style: Option<TextStyle>,
1532}
1533
1534/// Defaults for [`BottomAppBar`](crate::BottomAppBar).
1535#[derive(Clone, Copy, Debug, Default, PartialEq)]
1536pub struct BottomAppBarTheme {
1537    /// The bar's surface. Unset, the scheme's `surface_container`.
1538    pub color: Option<Color>,
1539}
1540
1541/// Defaults for [`BottomSheet`](crate::BottomSheet).
1542#[derive(Clone, Copy, Debug, Default, PartialEq)]
1543pub struct BottomSheetTheme {
1544    /// **What shape the sheet is** — the reference's `BottomSheetThemeData.shape`. Unset,
1545    /// the framework rounds the **top** corners only: the bottom edge is flush against the
1546    /// window, and rounding it would cut two notches out of the screen.
1547    pub shape: Option<ShapeBorder>,
1548    /// The radius of those top two corners, for a theme that would rather give the number
1549    /// than the shape. Outranked by [`shape`](Self::shape).
1550    pub radius: Option<f32>,
1551    /// The sheet's surface. Unset, the scheme's `surface_container_low`.
1552    pub background_color: Option<Color>,
1553}
1554
1555/// Defaults for [`MaterialBanner`](crate::MaterialBanner).
1556#[derive(Clone, Copy, Debug, Default, PartialEq)]
1557pub struct BannerTheme {
1558    /// The banner's colour. Unset, a low container tone.
1559    pub color: Option<Color>,
1560    /// What the surface is tinted towards for its elevation. Unset, nothing is.
1561    pub surface_tint: Option<Color>,
1562    /// The shadow's colour. Unset, there is none.
1563    pub shadow_color: Option<Color>,
1564    /// The rule along the bottom, drawn only where the banner is flat. Unset, the
1565    /// scheme's `outlineVariant`.
1566    pub divider_color: Option<Color>,
1567    /// How far off the page it sits. Unset, `0`: flat, with a rule under it — see
1568    /// [`BANNER_ELEVATION`](crate::BANNER_ELEVATION).
1569    pub elevation: Option<f32>,
1570    /// The padding around the message row. Unset, it depends on where the actions went.
1571    pub padding: Option<Insets>,
1572    /// The margin around the banner. Unset, it depends on the elevation.
1573    pub margin: Option<Insets>,
1574    /// What the leading slot is held off the message by. Unset, 16 at its trailing edge.
1575    pub leading_padding: Option<Insets>,
1576    /// What the message is set in. Unset, `bodyMedium`.
1577    pub content_text_style: Option<TextStyle>,
1578}
1579
1580/// Defaults for [`Dialog`](crate::Dialog) and [`AlertDialog`](crate::AlertDialog).
1581#[derive(Clone, Copy, Debug, Default, PartialEq)]
1582pub struct DialogTheme {
1583    /// The surface's colour. Unset, the scheme's `surfaceContainerHigh`.
1584    pub color: Option<Color>,
1585    /// How far off the page it sits. Unset, 6.
1586    pub elevation: Option<f32>,
1587    /// The shadow's colour. Unset, **transparent**: the reference's Material 3 dialog
1588    /// shows its height by its container tone, not by a drop shadow.
1589    pub shadow_color: Option<Color>,
1590    /// What the surface is tinted towards for its elevation. Unset, nothing is — see
1591    /// [`Self::shadow_color`] for why.
1592    pub surface_tint: Option<Color>,
1593    /// **What shape it is** (`dialog.dart`). Unset, a 28-radius rounded rectangle.
1594    ///
1595    /// It carried the reference's *name* and a `BorderRadius` until milestone 451, which
1596    /// is the deviation this field is the clearest case of: `shape` in the reference is a
1597    /// `ShapeBorder`, and a corner radius is one of the things one can be.
1598    pub shape: Option<ShapeBorder>,
1599    /// How far the dialog is held off the window's edges. Unset, 40 across and 24 down.
1600    pub inset_padding: Option<Insets>,
1601    /// The glyph above the title. Unset, the scheme's `secondary`.
1602    pub icon_color: Option<Color>,
1603    /// The heading's type. Unset, `headlineSmall`.
1604    pub title_text_style: Option<TextStyle>,
1605    /// What the dialog says. Unset, `bodyMedium`.
1606    pub content_text_style: Option<TextStyle>,
1607}
1608
1609/// Defaults for [`Steps`](crate::Steps).
1610#[derive(Clone, Copy, Debug, Default, PartialEq)]
1611pub struct StepsTheme {
1612    /// The caption under each marker.
1613    pub label_text_style: Option<TextStyle>,
1614    /// The number inside the marker. It is a **glyph on a circle** rather than something
1615    /// read at length, so the framework's own default does not pass through the reader's
1616    /// font setting — a theme that sets this one takes that decision back.
1617    pub index_text_style: Option<TextStyle>,
1618}
1619
1620/// Defaults for [`Tree`](crate::Tree).
1621#[derive(Clone, Copy, Debug, Default, PartialEq)]
1622pub struct TreeTheme {
1623    /// The rows' type.
1624    pub text_style: Option<TextStyle>,
1625}
1626
1627/// Defaults for [`Timeline`](crate::Timeline).
1628#[derive(Clone, Copy, Debug, Default, PartialEq)]
1629pub struct TimelineTheme {
1630    /// An entry's heading.
1631    pub title_text_style: Option<TextStyle>,
1632    /// The line under it.
1633    pub detail_text_style: Option<TextStyle>,
1634}
1635
1636/// Defaults for [`Breadcrumb`](crate::Breadcrumb).
1637///
1638/// The reference has no breadcrumb, so its type is argued rather than read: a trail is a
1639/// **secondary** line of navigation above the page's own content, which is `bodyMedium`.
1640#[derive(Clone, Copy, Debug, Default, PartialEq)]
1641pub struct BreadcrumbTheme {
1642    /// The segments' type, the separators included.
1643    pub text_style: Option<TextStyle>,
1644}
1645
1646/// Defaults for [`ReorderableList`](crate::ReorderableList)'s grip.
1647///
1648/// The grip is the one part of a reorderable list the framework draws itself, so it is the
1649/// one part a theme has anything to say about — the rows are the application's.
1650#[derive(Clone, Copy, Debug, Default, PartialEq)]
1651pub struct ReorderableTheme {
1652    /// The glyph the grip carries.
1653    pub handle_icon: Option<crate::IconData>,
1654    /// Its colour, over the muted foreground.
1655    pub handle_color: Option<Color>,
1656    /// Its size.
1657    pub handle_icon_size: Option<f32>,
1658}
1659
1660/// Defaults for [`Kanban`](crate::Kanban).
1661///
1662/// The reference has no board, so its type is argued: a card is a small piece of content
1663/// read on its own, which is `bodyLarge` — the step the reference gives a list tile's title
1664/// and this framework already gives a `Tree` row.
1665#[derive(Clone, Copy, Debug, Default, PartialEq)]
1666pub struct KanbanTheme {
1667    /// A text card's label.
1668    pub card_text_style: Option<TextStyle>,
1669    /// A column's heading over its cards.
1670    pub column_title_text_style: Option<TextStyle>,
1671}
1672
1673/// Defaults for [`Form`](crate::Form)'s error summary.
1674///
1675/// The reference has no summary list, so its type is argued: a bullet restates an error
1676/// already shown under its field, which is `bodySmall` — the step the reference gives the
1677/// helper line those errors come from.
1678#[derive(Clone, Copy, Debug, Default, PartialEq)]
1679pub struct FormTheme {
1680    /// A summary bullet's type.
1681    pub bullet_text_style: Option<TextStyle>,
1682    /// The summary's heading over them.
1683    pub summary_title_text_style: Option<TextStyle>,
1684}
1685
1686/// Defaults for [`TimePicker`](crate::TimePicker) and [`TimeRange`](crate::TimeRange).
1687///
1688/// The reference names three of these four. Its dial is `bodyLarge`, its help line
1689/// `labelMedium`, and its day period `titleMedium` — which is the same step as the dial and
1690/// is why the AM/PM cells here are simply cells. The **preview** is the fourth: the
1691/// reference puts an editable pair of fields at `displayMedium` where this widget shows one
1692/// read-only line above two grids, so it takes the heading step that line is.
1693#[derive(Clone, Copy, Debug, Default, PartialEq)]
1694pub struct TimePickerTheme {
1695    /// The hour, minute and AM/PM cells.
1696    pub dial_text_style: Option<TextStyle>,
1697    /// The `HH:MM` line above them.
1698    pub preview_text_style: Option<TextStyle>,
1699    /// The "Hour" and "Minute" lines over each grid.
1700    pub help_text_style: Option<TextStyle>,
1701    /// The "Start" and "End" headings of a [`TimeRange`](crate::TimeRange).
1702    pub range_label_text_style: Option<TextStyle>,
1703}
1704
1705/// Defaults for [`Kbd`](crate::Kbd).
1706///
1707/// The reference has no key cap, so its type is argued rather than read: a shortcut hint is
1708/// a **label**, and a key cap is the one place in this framework where the glyphs stand for
1709/// what is printed on a keyboard, hence the monospaced default.
1710#[derive(Clone, Copy, Debug, Default, PartialEq)]
1711pub struct KbdTheme {
1712    /// The cap's label.
1713    pub text_style: Option<TextStyle>,
1714}
1715
1716/// Defaults for [`ToggleButtons`](crate::ToggleButtons).
1717///
1718/// The three border colours are named apart although the reference defaults all three to
1719/// the same value (`toggle_buttons.dart:601`, `:635`, `:651`): a bank is one object and
1720/// its outline does not break up because one of its buttons is on, but an application
1721/// that wants the chosen pair marked out needs somewhere to say so.
1722#[derive(Clone, Debug, Default, PartialEq)]
1723pub struct ToggleButtonsTheme {
1724    /// What is drawn in a button that is off — its text, its glyph, anything under it
1725    /// that reads the theme for a colour.
1726    pub color: Option<Color>,
1727    /// The same, for a button that is on.
1728    pub selected_color: Option<Color>,
1729    /// The same, when the bank cannot be pressed.
1730    pub disabled_color: Option<Color>,
1731    /// A button's ground, per state. A plain colour — `WidgetStateProperty::all` —
1732    /// fills every button rather than only the ones that are on, as the reference's does.
1733    pub fill_color: Option<crate::WidgetStateProperty<Color>>,
1734    /// The hairline around and beside a button that is off.
1735    pub border_color: Option<Color>,
1736    /// The hairline around and beside a button that is on. A seam between an on button and
1737    /// an off one takes this, from either side.
1738    pub selected_border_color: Option<Color>,
1739    /// The hairline when the bank cannot be pressed.
1740    pub disabled_border_color: Option<Color>,
1741    /// The hairline's width, around the bank and between its buttons.
1742    pub border_width: Option<f32>,
1743    /// The **bank's** corners: the buttons at its two ends take a pair each, and the ones
1744    /// between them are square.
1745    pub border_radius: Option<BorderRadius>,
1746    /// The type any text in the bank takes. Its colour is ignored — that is the three
1747    /// content colours' to answer, and it depends on the state.
1748    pub text_style: Option<TextStyle>,
1749    /// The smallest a button may be across.
1750    pub min_width: Option<f32>,
1751    /// And down. Untold, both are the tap target.
1752    pub min_height: Option<f32>,
1753    /// The largest. Untold, unbounded.
1754    pub max_width: Option<f32>,
1755    /// Likewise.
1756    pub max_height: Option<f32>,
1757}
1758
1759/// Defaults for [`GridTileBar`](crate::GridTileBar).
1760///
1761/// The two heights are two fields and not one, because it is the **content** that picks
1762/// between them: a bar with a title and a subtitle is 68 and any other is 48. An
1763/// application setting one has not thereby said anything about the other.
1764#[derive(Clone, Copy, Debug, Default, PartialEq)]
1765pub struct GridTileBarTheme {
1766    /// What is drawn behind the words. Untold, nothing at all: the picture is the
1767    /// background, which is the arrangement the widget is for.
1768    pub background_color: Option<Color>,
1769    /// The colour of the words and glyphs on it. Untold, white — the bar stands on a
1770    /// photograph, and a photograph has no brightness the theme knows about.
1771    pub foreground_color: Option<Color>,
1772    /// The title's type. Untold, the scale's `title_medium`.
1773    pub title_style: Option<TextStyle>,
1774    /// The subtitle's. Untold, `body_small`.
1775    pub subtitle_style: Option<TextStyle>,
1776    /// How tall a bar carrying one line is.
1777    pub height: Option<f32>,
1778    /// How tall one carrying a title **and** a subtitle is.
1779    pub two_line_height: Option<f32>,
1780}
1781
1782#[cfg(test)]
1783mod tests {
1784    /// **The rungs a shape is resolved on**, and the third one in particular: a radius
1785    /// was all a theme could say until milestone 450, and applications have written them.
1786    /// A theme naming a `shape` outranks one naming only a `radius`; naming both is
1787    /// naming the shape.
1788    #[test]
1789    fn a_shape_outranks_a_radius_and_a_caller_outranks_both() {
1790        use super::{resolve_shape, BorderRadius, ShapeBorder};
1791        let fallback = ShapeBorder::stadium();
1792        let told = ShapeBorder::circle();
1793        let themed = ShapeBorder::beveled(3.0);
1794
1795        assert_eq!(resolve_shape(None, None, None, fallback), fallback);
1796        assert_eq!(
1797            resolve_shape(None, None, Some(BorderRadius::uniform(4.0)), fallback),
1798            ShapeBorder::rounded(4.0),
1799            "a plain radius still speaks"
1800        );
1801        assert_eq!(
1802            resolve_shape(
1803                None,
1804                Some(themed),
1805                Some(BorderRadius::uniform(4.0)),
1806                fallback
1807            ),
1808            themed,
1809            "and a shape beside it outranks it"
1810        );
1811        assert_eq!(
1812            resolve_shape(
1813                Some(told),
1814                Some(themed),
1815                Some(BorderRadius::uniform(4.0)),
1816                fallback
1817            ),
1818            told,
1819            "and the caller outranks the theme"
1820        );
1821    }
1822
1823    use super::*;
1824    use crate::card::{Card, CardVariant, CARD_MARGIN};
1825    use crate::divider::{Divider, DIVIDER_SPACE};
1826    use crate::flex::Flex;
1827    use crate::runtime::Runtime;
1828    use crate::theme::{TextTheme, Theme};
1829    use crate::ui::build_ui;
1830    use crate::widget::Widget;
1831    use frus_core::{Color, Primitive, Rect, Size};
1832
1833    #[derive(Clone, Debug, PartialEq)]
1834    enum Msg {}
1835
1836    /// Builds the widget **inside a sized parent**, which is where a margin and an
1837    /// `Auto` width mean anything, and returns the frame's primitives.
1838    fn framed(widget: impl Widget<Msg> + 'static, theme: &Theme) -> Vec<Primitive> {
1839        let tree = Flex::column().width(200.0).height(100.0).child(widget);
1840        build_ui(&tree, Size::new(200.0, 100.0), &Runtime::default(), theme)
1841            .scene()
1842            .primitives()
1843            .to_vec()
1844    }
1845
1846    /// The first crisp box the tree paints — the widget's own surface, past any shadow.
1847    fn painted_rect(widget: impl Widget<Msg> + 'static, theme: &Theme) -> Rect {
1848        framed(widget, theme)
1849            .iter()
1850            .find_map(|p| match p {
1851                Primitive::Rect { rect, blur, .. } if *blur == 0.0 => Some(*rect),
1852                _ => None,
1853            })
1854            .expect("the widget paints a box")
1855    }
1856
1857    #[test]
1858    fn the_theme_reaches_layout_and_not_only_paint() {
1859        // The point of `style_themed`. A divider's *height* is a layout property, and a
1860        // theme that could not set it would be able to recolour a separator but not make
1861        // one thin — which is the setting an application actually asks for.
1862        let plain = Theme::default();
1863        let mut thin = Theme::default();
1864        thin.widgets.divider.height = Some(1.0);
1865
1866        // The line is centred in its box, so a taller box puts it further down; the box
1867        // itself is what the theme moved.
1868        // The line is centred in its box: a 16 px box puts it at 7.5, a 1 px box at 0.
1869        let tall = painted_rect(Divider::new(), &plain);
1870        let thin_line = painted_rect(Divider::new(), &thin);
1871        assert!(
1872            tall.y > thin_line.y,
1873            "the themed divider's box is shorter: {tall:?} against {thin_line:?}"
1874        );
1875        assert_eq!(tall.height, 1.0, "the line itself is unchanged");
1876        assert_eq!(thin_line.height, 1.0);
1877    }
1878
1879    #[test]
1880    fn the_caller_outranks_the_theme_and_the_theme_outranks_the_framework() {
1881        // The whole chain in one assertion per link, on a layout property so that both
1882        // halves of the resolution are exercised.
1883        let plain = Theme::default();
1884        let mut themed = Theme::default();
1885        themed.widgets.card.margin = Some(20.0);
1886
1887        let x = |card: Card<Msg>, theme: &Theme| painted_rect(card, theme).x;
1888
1889        assert_eq!(x(Card::new(), &plain), CARD_MARGIN, "the framework's");
1890        assert_eq!(x(Card::new(), &themed), 20.0, "the theme's");
1891        assert_eq!(
1892            x(Card::new().margin(2.0), &themed),
1893            2.0,
1894            "the caller's, over the theme's"
1895        );
1896    }
1897
1898    #[test]
1899    fn a_theme_can_change_what_an_untold_widget_is() {
1900        // Not just a number: the *variant* is themeable, so an application can be flat
1901        // throughout without writing `.filled()` at every call site.
1902        let mut flat = Theme::default();
1903        flat.widgets.card.variant = Some(CardVariant::Filled);
1904        let shadows = |theme: &Theme| crate::shadowprobe::casts(&framed(Card::<Msg>::new(), theme));
1905        assert_eq!(shadows(&Theme::default()), 1, "elevated by default");
1906        assert_eq!(shadows(&flat), 0, "flat because the theme says so");
1907    }
1908
1909    #[test]
1910    fn the_ink_colour_is_themeable_even_where_a_widget_computes_its_own() {
1911        // A `Button` derives its splash from its own `on` colour, which is the right
1912        // default and the wrong thing to insist on: an application that has chosen an
1913        // ink colour has chosen it for every surface.
1914        let mine = Color::rgb8(255, 0, 128);
1915        let mut theme = Theme::default();
1916        theme.widgets.ink.color = Some(mine);
1917        // An enabled one: a button with nothing to do is disabled, and does not splash.
1918        let button = crate::button::Button::<()>::new("Go").on_press(());
1919        assert_eq!(
1920            Widget::<()>::ink(&button, &theme).map(|i| i.color),
1921            Some(mine)
1922        );
1923        // And a plain surface takes it too.
1924        assert_eq!(crate::ink::default_splash(&theme), mine);
1925    }
1926
1927    #[test]
1928    fn changing_a_theme_invalidates_the_layout_cache() {
1929        // The cache keys on a fingerprint of the *effective* style, which now includes
1930        // the theme's say. If it did not, a theme swap would keep the old geometry and
1931        // the change would appear only after something else moved.
1932        let runtime = Runtime::default();
1933        let tree = Flex::<Msg>::column()
1934            .width(200.0)
1935            .height(100.0)
1936            .child(Divider::new());
1937        let plain = Theme::default();
1938        let mut thin = Theme::default();
1939        thin.widgets.divider.height = Some(1.0);
1940
1941        let height = |theme: &Theme| {
1942            build_ui(&tree, Size::new(200.0, 100.0), &runtime, theme)
1943                .scene()
1944                .primitives()
1945                .iter()
1946                .find_map(|p| match p {
1947                    Primitive::Rect { rect, .. } => Some(rect.y),
1948                    _ => None,
1949                })
1950                .expect("a line")
1951        };
1952        // The same runtime, and therefore the same cache, across both builds.
1953        let first = height(&plain);
1954        let second = height(&thin);
1955        assert_ne!(
1956            first, second,
1957            "a themed size must not be served from the cache of an unthemed one"
1958        );
1959        assert_eq!(height(&plain), first, "and back again");
1960    }
1961
1962    #[test]
1963    fn the_defaults_are_still_reachable_through_an_empty_theme() {
1964        let plain = Theme::default();
1965        assert_eq!(
1966            Widget::<Msg>::style_themed(&Divider::new(), &plain).height,
1967            frus_layout::Dimension::Length(DIVIDER_SPACE)
1968        );
1969    }
1970
1971    /// The size every `Primitive::Text` in a frame was drawn at, in the order they were
1972    /// painted. A widget's type is not reachable any other way — these widgets paint their
1973    /// labels instead of laying them out.
1974    fn text_sizes(widget: impl Widget<Msg> + 'static, theme: &Theme) -> Vec<f32> {
1975        framed(widget, theme)
1976            .iter()
1977            .filter_map(|p| match p {
1978                Primitive::Text { size, .. } => Some(*size),
1979                _ => None,
1980            })
1981            .collect()
1982    }
1983
1984    /// The weight of the first text in a frame.
1985    fn first_weight(widget: impl Widget<Msg> + 'static, theme: &Theme) -> Option<u16> {
1986        framed(widget, theme).iter().find_map(|p| match p {
1987            Primitive::Text { weight, .. } => Some(weight.to_u16()),
1988            _ => None,
1989        })
1990    }
1991
1992    #[test]
1993    fn a_widget_no_longer_decides_its_own_type() {
1994        // Milestone 413. Twelve widgets set their text in a private constant that no theme
1995        // and no caller could reach, and one of them had **drifted two pixels from the
1996        // reference** without anybody being able to see it. Each is checked here at the
1997        // step the reference names, and then moved by a theme — which is the part that was
1998        // impossible before, and the reason the drift went unseen.
1999        let plain = Theme::default();
2000
2001        // A snackbar's content is `bodyMedium` — 14 px, not the 16 the constant said.
2002        assert_eq!(
2003            text_sizes(crate::toast::SnackBar::<Msg>::new("Saved"), &plain),
2004            vec![plain.text.body_medium.size.unwrap()]
2005        );
2006        let mut loud = Theme::default();
2007        loud.widgets.snack_bar.content_text_style = Some(TextStyle::new(30.0));
2008        assert_eq!(
2009            text_sizes(crate::toast::SnackBar::<Msg>::new("Saved"), &loud),
2010            vec![30.0],
2011            "the theme has a say"
2012        );
2013        assert_eq!(
2014            text_sizes(
2015                crate::toast::SnackBar::<Msg>::new("Saved").content_text_style(TextStyle::new(9.0)),
2016                &loud
2017            ),
2018            vec![9.0],
2019            "and the caller has the last word over it"
2020        );
2021
2022        // A key cap is a label, and monospaced.
2023        let kbd = || crate::kbd::Kbd::new("Ctrl");
2024        assert_eq!(
2025            text_sizes(kbd(), &plain),
2026            vec![plain.text.label_medium.size.unwrap()]
2027        );
2028        assert_eq!(
2029            framed(kbd(), &plain).iter().find_map(|p| match p {
2030                Primitive::Text { family, .. } => Some(*family),
2031                _ => None,
2032            }),
2033            Some(Some(frus_core::FontFamily::Monospace)),
2034            "a cap stands for what is printed on a keyboard"
2035        );
2036
2037        // A tree row is a list tile's title.
2038        let tree = || {
2039            crate::tree::Tree::<Msg>::new(|_| -> Msg { unreachable!() })
2040                .node(1, 0, "root", false, false)
2041        };
2042        assert_eq!(
2043            text_sizes(tree(), &plain),
2044            vec![plain.text.body_large.size.unwrap()]
2045        );
2046        assert_eq!(
2047            text_sizes(tree().text_style(TextStyle::new(7.0)), &plain),
2048            vec![7.0],
2049            "said on the widget, whatever order the builders came in"
2050        );
2051    }
2052
2053    #[test]
2054    fn the_reference_names_a_table_s_two_rows_apart() {
2055        // A data table's heading is `titleSmall` and its cells `bodyMedium` — **two
2056        // different steps**, which one `SIZE` constant for the whole widget could not say.
2057        let theme = Theme::default();
2058        let table = crate::table::Table::<Msg>::new(1)
2059            .header(&["Name"])
2060            .row(&["Ada"]);
2061        assert_eq!(
2062            text_sizes(table, &theme),
2063            vec![
2064                theme.text.title_small.size.unwrap(),
2065                theme.text.body_medium.size.unwrap(),
2066            ]
2067        );
2068        // And the heading carries the medium weight the step does.
2069        let heading = crate::table::Table::<Msg>::new(1).header(&["Name"]);
2070        assert_eq!(
2071            first_weight(heading, &theme),
2072            Some(frus_core::FontWeight::Medium.to_u16())
2073        );
2074    }
2075
2076    #[test]
2077    fn a_table_carries_its_own_word_down_to_cells_it_did_not_build_directly() {
2078        // `Table` and `DatePicker` hand their override down the **theme**
2079        // (`Widget::theme_override`) rather than through the cells' fields: a table builds
2080        // cells in half a dozen places and a calendar has five constructors, and a value
2081        // carried down the theme reaches all of them without any of them being taught to
2082        // pass it on.
2083        let theme = Theme::default();
2084        let table = crate::table::Table::<Msg>::new(1)
2085            .header(&["Name"])
2086            .row(&["Ada"])
2087            .heading_text_style(TextStyle::new(21.0))
2088            .data_text_style(TextStyle::new(8.0));
2089        assert_eq!(text_sizes(table, &theme), vec![21.0, 8.0]);
2090        // Saying nothing costs nothing: no override, no theme to allocate.
2091        assert!(Widget::<Msg>::theme_override(
2092            &crate::table::Table::<Msg>::new(1).header(&["Name"]),
2093            &theme
2094        )
2095        .is_none());
2096    }
2097
2098    #[test]
2099    fn the_un_themed_path_reads_the_same_scale_as_the_themed_one() {
2100        // `Widget::style` has no theme — it is what the transparent wrappers ask a child
2101        // when they want its size. It answers from `TextTheme::M3`, the same const
2102        // `Theme::default()` carries, rather than from a fallback constant beside it: two
2103        // numbers that have to agree is the shape the last five milestones were about.
2104        assert_eq!(TextTheme::M3, Theme::default().text);
2105        let kbd = crate::kbd::Kbd::new("Ctrl");
2106        assert_eq!(
2107            Widget::<Msg>::style(&kbd),
2108            Widget::<Msg>::style_themed(&kbd, &Theme::default()),
2109            "the same widget, sized the same way, with and without a theme in hand"
2110        );
2111    }
2112
2113    #[test]
2114    fn the_last_seven_widgets_stop_deciding_their_own_type() {
2115        // Milestone 414, the tail of 413. Five of these seven turned out to be **read**
2116        // from the reference after all, and the note that sent them here said only two
2117        // were — which is the same mistake as the constants themselves, an estimate
2118        // standing in for a look.
2119        let plain = Theme::default();
2120
2121        // Argued: a trail is a *secondary* line of navigation, `bodyMedium`.
2122        let trail = || {
2123            crate::breadcrumb::Breadcrumb::<Msg>::new(|_| -> Msg { unreachable!() }).crumb("Home")
2124        };
2125        assert_eq!(
2126            text_sizes(trail(), &plain),
2127            vec![plain.text.body_medium.size.unwrap()]
2128        );
2129        assert_eq!(
2130            text_sizes(trail().text_style(TextStyle::new(9.0)), &plain),
2131            vec![9.0],
2132            "and a caller can still say otherwise"
2133        );
2134        let mut themed = Theme::default();
2135        themed.widgets.breadcrumb.text_style = Some(TextStyle::new(31.0));
2136        assert_eq!(text_sizes(trail(), &themed), vec![31.0]);
2137    }
2138
2139    #[test]
2140    fn a_bar_titles_at_the_reference_s_weight() {
2141        // The app bar's title was a private `TextStyle::new(22.0).weight(Medium)`: the size
2142        // right and **the weight wrong**, because `titleLarge` is regular. Nothing tested it
2143        // — the one test that looked compared it against the constant it came from, which is
2144        // a tautology, not a check.
2145        let plain = Theme::default();
2146        assert_eq!(
2147            first_weight(crate::navbar::NavigationBar::<Msg>::new("Inbox"), &plain),
2148            Some(frus_core::FontWeight::Regular.to_u16())
2149        );
2150        assert_eq!(
2151            text_sizes(crate::navbar::NavigationBar::<Msg>::new("Inbox"), &plain),
2152            vec![plain.text.title_large.size.unwrap()],
2153            "and a navigation bar titles at 22, not at a private 20"
2154        );
2155    }
2156
2157    #[test]
2158    fn a_theme_that_says_nothing_is_the_absence_of_a_theme() {
2159        // The whole contract of `None`: a fresh theme must carry no opinions at all, or
2160        // every widget's built-in default silently becomes unreachable.
2161        assert_eq!(Theme::default().widgets, WidgetThemes::default());
2162        assert_eq!(WidgetThemes::default().card.elevation, None);
2163        assert_eq!(WidgetThemes::default().divider.height, None);
2164        assert_eq!(WidgetThemes::default().drawer.width, None);
2165        assert_eq!(WidgetThemes::default().ink.color, None);
2166        assert_eq!(WidgetThemes::default().tab_bar.indicator_color, None);
2167        assert_eq!(WidgetThemes::default().chip.height, None);
2168        assert_eq!(WidgetThemes::default().button.height, None);
2169        assert_eq!(WidgetThemes::default().segmented.height, None);
2170        assert_eq!(WidgetThemes::default().icon_button.size, None);
2171        assert_eq!(WidgetThemes::default().snack_bar.content_text_style, None);
2172        assert_eq!(WidgetThemes::default().table.heading_text_style, None);
2173        assert_eq!(WidgetThemes::default().date_picker.day_text_style, None);
2174        assert_eq!(WidgetThemes::default().kbd.text_style, None);
2175        assert_eq!(WidgetThemes::default().breadcrumb.text_style, None);
2176        assert_eq!(WidgetThemes::default().kanban.card_text_style, None);
2177        assert_eq!(WidgetThemes::default().form.bullet_text_style, None);
2178        assert_eq!(WidgetThemes::default().time_picker.dial_text_style, None);
2179        assert_eq!(
2180            WidgetThemes::default().slider.value_indicator_text_style,
2181            None
2182        );
2183    }
2184}