hydrolysis-m3 0.3.0

Material 3 widget theme for WaterUI self-drawn backends
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
#![cfg_attr(
    test,
    allow(clippy::float_cmp, reason = "tests assert exact widget-metric values")
)]
//! Material Design 3 widget metrics and drawing primitives.
//!
//! This crate is a style package: [`Material3`] implements the backend-neutral
//! widget chrome contract from `waterui-backend-core` and the
//! [`hydrolysis::Style`] contract the rendered Hydrolysis runtime is
//! constructed with — `hydrolysis::run(app, Material3::defaults())`.

pub mod button_group;
pub mod chip;
pub mod color;
pub mod dialog;
pub mod drag_handle;
pub mod elevation;
pub mod fab;
pub mod fab_menu;
pub mod icon_button;
pub mod material_badge;
pub mod material_card;
pub mod material_divider;
pub mod material_list;
pub mod material_menu;
pub mod material_navigation;
pub mod material_snackbar;
pub mod material_tabs;
pub mod navigation_bar;
pub mod navigation_drawer;
pub mod navigation_rail;
pub mod segmented_button;
pub mod toolbar;
pub mod tooltip;

#[cfg(test)]
mod layout_test_support;

mod controls;
mod icon_paths;
mod icons;
mod layout;
pub mod material_shapes;
mod navigation;
mod semantics;
pub mod split_button;
mod theme;

pub(crate) use controls::{button, input, picker, progress, slider, stepper, toggle};
pub(crate) use layout::{badge, card, divider, list, menu, scroll, snackbar, table};
pub(crate) use navigation::{navigation as navigation_chrome, tabs};
pub(crate) use theme::dimensions;

use core::cell::OnceCell;

use vello::kurbo::{BezPath, Point, Rect};
use waterui::Plugin as _;
use waterui::reactive::{Computed, Signal, SignalExt as _};
use waterui::text::font::Font;
use waterui::theme::{self as waterui_theme, ColorScheme, ColorSettings, Theme};
pub use waterui_backend_core::widget::{
    BadgeMetrics, Brush, ButtonMetrics, DividerMetrics, DrawContext, InputFieldMetrics,
    InteractionFocusBinding, InteractionMotion, InteractionStyle, ListDividerMetrics, ListMetrics,
    ListRowMetrics, ListSectionMetrics, ListTrailingControlMetrics, ModalInteraction,
    NavigationMetrics, NavigationMotion, PickerMetrics, PressWave, PressWaves,
    ProgressIndicatorStyle, ProgressMetrics, ProgressMotion, RadioIndicatorState,
    RadioSelectionMotion, SliderMetrics, StepperEnd, StepperMetrics, TableMetrics, TabsMetrics,
    TextCaretMotion, TextContextMenuMetrics, ToggleMetrics, WidgetInteractionState, WidgetTheme,
};
use waterui_controls::button::{ButtonSize, ButtonStyle};
use waterui_controls::toggle::ToggleStyle;
use waterui_core::Environment;
use waterui_form::picker::PickerStyle;
use waterui_graphics::color::Color;

pub use button_group::{
    ButtonGroup, ConnectedButton, ConnectedButtonGroup, GroupButton, button_group,
    connected_button, connected_button_group, group_button,
};
pub use chip::{
    AssistChip, FilterChip, InputChip, OutlinedChip, SuggestionChip, assist_chip, filter_chip,
    input_chip, suggestion_chip,
};
pub use dialog::{Dialog, DialogAction, dialog, dialog_action};
pub use drag_handle::{VerticalDragHandle, vertical_drag_handle};
pub use elevation::{MaterialElevation, MaterialElevationLevel, material_elevation};
pub use fab::{
    ExtendedFab, Fab, FabSize, FabSizeTokens, FabVariantTokens, PrimaryFab, SecondaryFab,
    SurfaceFab, TertiaryFab, extended_fab, fab,
};
pub use fab_menu::{FabMenuItem, FloatingActionButtonMenu, fab_menu, fab_menu_item};
pub use icon_button::{
    FilledIconButton, FilledTonalIconButton, IconButton, IconButtonSize, IconButtonSizeTokens,
    IconButtonVariantTokens, OutlinedIconButton, SelectedOutlinedIconButton,
    SelectedStandardIconButton, StandardIconButton, filled_icon_button, filled_tonal_icon_button,
    icon_button, outlined_icon_button,
};
pub use material_badge::{MaterialBadge, material_badge};
pub use material_card::{MaterialCard, material_card};
pub use material_color_utils::dynamic::{
    color_spec::{Platform as MaterialColorPlatform, SpecVersion as MaterialColorSpecVersion},
    variant::Variant as MaterialColorVariant,
};
/// The ARGB seed color the Material You generators take (`Argb(0xAARRGGBB)`),
/// re-exported so `Material3::with_seed` / `MaterialColorSource::new` are callable
/// without naming the color-utils crate directly.
pub use material_color_utils::utils::color_utils::Argb;
pub use material_divider::{MaterialDivider, material_divider};
pub use material_list::{MaterialList, MaterialListItem, material_list, material_list_item};
pub use material_menu::{
    MaterialMenu, MaterialMenuCommand, MaterialMenuItem, MaterialMenuItemBuilder, material_menu,
    material_menu_divider, material_menu_icon_label, material_menu_item, material_sub_menu,
};
pub use material_navigation::{
    MaterialNavigationView, material_large_top_app_bar, material_navigation_view,
    material_small_top_app_bar,
};
pub use material_snackbar::{MaterialSnackbar, material_snackbar};
pub use material_tabs::{MaterialTab, MaterialTabs, material_tab, material_tabs};
pub use navigation_bar::{NavigationBar, NavigationTab, navigation_bar, navigation_tab};
pub use navigation_drawer::{
    NavigationDrawer, NavigationDrawerItem, navigation_drawer, navigation_drawer_item,
};
pub use navigation_rail::{
    NavigationRail, NavigationRailItem, NavigationRailLayout, navigation_rail, navigation_rail_item,
};
pub use segmented_button::{
    OutlinedSegmentedButton, OutlinedSegmentedButtonSet, SegmentedButtonShape,
    outlined_segmented_button, outlined_segmented_button_set,
};
pub use split_button::{
    FilledSplitButton, SplitButton, SplitButtonVariantTokens, TonalSplitButton, split_button,
};
pub use theme::colors::{
    MaterialColorMode, MaterialColorScheme, MaterialColorSchemes, MaterialColorSource,
    MaterialContrastLevel, MaterialRoleColor,
};
/// The Material Design 3 motion token scale — the duration and easing tokens
/// this theme's component motion is built from, re-exported so app and backend
/// code can animate on the same scale instead of re-deriving the numbers.
pub use theme::motion::tokens as motion_tokens;
pub use toolbar::{
    DockedToolbar, FloatingToolbar, FloatingToolbarStyle, docked_toolbar, floating_toolbar,
};
pub use tooltip::{PlainTooltip, RichTooltip, TooltipAnchor, plain_tooltip, rich_tooltip};

#[derive(Debug)]
/// Material Design 3 style for the Hydrolysis runtime.
///
/// `Material3` is both the [`WidgetTheme`] the backend resolves widget chrome
/// through and the [`hydrolysis::Style`] whose `install_tokens` writes the
/// Material color and typography tokens into the environment:
/// `hydrolysis::run(app, Material3::defaults())`.
///
/// A dynamic `Material3` ([`Material3::defaults`]) binds to the color-scheme
/// signal of the first environment `install_tokens` installs it into and
/// follows that signal for the rest of its lifetime; every later environment
/// the same instance is installed into is rebound to that signal, so paint
/// and tokens can never diverge. Cloning produces a fresh, unbound style: the
/// clone binds to the first environment *it* is installed into, never to the
/// original's signal.
pub struct Material3 {
    colors: Material3Colors,
}

impl Clone for Material3 {
    fn clone(&self) -> Self {
        Self {
            colors: self.colors.clone(),
        }
    }
}

#[derive(Debug)]
#[allow(
    clippy::large_enum_variant,
    reason = "a `Material3` holds exactly one of these; the variant size difference is immaterial and boxing would add needless indirection"
)]
enum Material3Colors {
    /// One fixed color scheme, resolved at construction.
    Static(MaterialColorScheme),
    /// A light/dark pair that follows the environment's color-scheme signal;
    /// the signal binds on the first `install_tokens` and stays bound.
    Dynamic {
        light: MaterialColorScheme,
        dark: MaterialColorScheme,
        scheme: OnceCell<Computed<ColorScheme>>,
    },
}

impl Clone for Material3Colors {
    fn clone(&self) -> Self {
        match self {
            Self::Static(colors) => Self::Static(*colors),
            Self::Dynamic { light, dark, .. } => Self::Dynamic {
                light: *light,
                dark: *dark,
                scheme: OnceCell::new(),
            },
        }
    }
}

impl Material3 {
    /// The default Material Design 3 style: baseline light/dark color roles
    /// that follow the app's color-scheme signal.
    #[must_use]
    pub const fn defaults() -> Self {
        Self {
            colors: Material3Colors::Dynamic {
                light: MaterialColorScheme::baseline_light(),
                dark: MaterialColorScheme::baseline_dark(),
                scheme: OnceCell::new(),
            },
        }
    }

    /// The dark Material Design 3 baseline color scheme.
    #[must_use]
    pub const fn dark() -> Self {
        Self::with_colors(MaterialColorScheme::baseline_dark())
    }

    /// A Material Design 3 style from explicit Material color roles.
    #[must_use]
    pub const fn with_colors(colors: MaterialColorScheme) -> Self {
        Self {
            colors: Material3Colors::Static(colors),
        }
    }

    /// A Material Design 3 style generated from a Material You seed color.
    #[must_use]
    pub fn with_seed(seed: Argb) -> Self {
        Self::with_seed_mode(seed, MaterialColorMode::Light)
    }

    /// A Material Design 3 style generated from a seed color and mode.
    #[must_use]
    pub fn with_seed_mode(seed: Argb, mode: MaterialColorMode) -> Self {
        Self::with_source(MaterialColorSource::new(seed), mode)
    }

    /// A Material Design 3 style generated from a complete Material You source.
    #[must_use]
    pub fn with_source(source: MaterialColorSource, mode: MaterialColorMode) -> Self {
        Self::with_colors(source.scheme(mode))
    }

    /// A Material Design 3 style picking one scheme from a paired
    /// light/dark Material You scheme set.
    #[must_use]
    pub const fn with_color_schemes(
        schemes: &MaterialColorSchemes,
        mode: MaterialColorMode,
    ) -> Self {
        Self::with_colors(schemes.scheme(mode))
    }

    /// Return the Material color roles this style resolves to.
    ///
    /// For the dynamic constructors the roles follow the color-scheme signal
    /// bound during `install_tokens`; a `Material3` that was never installed
    /// has no signal to read and this method panics.
    #[must_use]
    pub fn colors(&self) -> MaterialColorScheme {
        self.colors.current()
    }
}

impl Material3Colors {
    fn current(&self) -> MaterialColorScheme {
        match self {
            Self::Static(colors) => *colors,
            Self::Dynamic {
                light,
                dark,
                scheme,
            } => material_scheme_for_color_scheme(
                *light,
                *dark,
                scheme
                    .get()
                    .expect("a `Material3` reads its color scheme only after `install_tokens`")
                    .get(),
            ),
        }
    }
}

impl hydrolysis::Style for Material3 {
    /// Writes the Material color and typography tokens into `env`, over the
    /// framework defaults the runtime installs first.
    ///
    /// A dynamic scheme binds on first install: it takes `env`'s color-scheme
    /// signal if one is installed, else binds a constant [`ColorScheme::Light`]
    /// signal. On every install the bound signal is written into `env`, so an
    /// environment carrying a different signal is rebound to it and the tokens
    /// always match what the style paints.
    fn install_tokens(&self, env: &mut Environment) {
        match &self.colors {
            Material3Colors::Static(colors) => insert_static_tokens(env, *colors),
            Material3Colors::Dynamic {
                light,
                dark,
                scheme,
            } => {
                let scheme = scheme.get_or_init(|| {
                    waterui_theme::installed_color_scheme(env)
                        .unwrap_or_else(|| Computed::constant(ColorScheme::Light))
                });
                Theme::new().color_scheme(scheme.clone()).install(env);
                insert_dynamic_tokens(env, scheme, *light, *dark);
            }
        }
    }
}

/// Installs the `WaterUI` theme tokens and Material component themes for one
/// fixed color scheme.
fn insert_static_tokens(env: &mut Environment, colors: MaterialColorScheme) {
    let color_scheme = match colors.mode {
        MaterialColorMode::Light => ColorScheme::Light,
        MaterialColorMode::Dark => ColorScheme::Dark,
    };
    Theme::new()
        .color_scheme(color_scheme)
        .colors(
            ColorSettings::new()
                .background(colors.background.resolved())
                .surface(colors.surface.resolved())
                .surface_variant(colors.surface_variant.resolved())
                .border(colors.outline.resolved())
                .foreground(colors.on_surface.resolved())
                .muted_foreground(colors.on_surface_variant.resolved())
                .accent(colors.primary.resolved())
                .accent_foreground(colors.on_primary.resolved())
                .accent_container(colors.primary_container.resolved())
                .tertiary(colors.tertiary.resolved())
                .tertiary_container(colors.tertiary_container.resolved())
                .selection_container(colors.secondary_container.resolved())
                .selection_foreground(colors.on_secondary_container.resolved())
                .error(colors.error.resolved())
                .error_foreground(colors.on_error.resolved()),
        )
        .install(env);
    theme::typography::defaults(env);
    env.insert(colors);
    env.insert(card::theme(&colors));
    env.insert(fab::theme());
    env.insert(snackbar::theme(&colors));
}

/// Installs the paired light/dark schemes bound to `scheme`, the
/// environment's color-scheme signal.
fn insert_dynamic_tokens(
    env: &mut Environment,
    scheme: &Computed<ColorScheme>,
    light: MaterialColorScheme,
    dark: MaterialColorScheme,
) {
    project_color_tokens(env, scheme, light, dark);
    theme::typography::defaults(env);
    let initial = material_scheme_for_color_scheme(light, dark, scheme.get());
    env.insert(initial);
    env.insert(MaterialColorSchemes::new(
        MaterialColorSource::default(),
        light,
        dark,
    ));
    env.insert(card::theme(&initial));
    env.insert(fab::theme());
    env.insert(snackbar::theme(&initial));
}

/// Projects each `WaterUI` color token onto the Material role that carries it,
/// as a signal that re-resolves when the color scheme flips.
fn project_color_tokens(
    env: &mut Environment,
    scheme: &Computed<ColorScheme>,
    light: MaterialColorScheme,
    dark: MaterialColorScheme,
) {
    macro_rules! project {
        ($($token:ident => $role:ident),* $(,)?) => {
            $(
                project_color_token::<waterui_theme::color::$token>(
                    env,
                    scheme,
                    light,
                    dark,
                    |colors| colors.$role,
                );
            )*
        };
    }

    project! {
        Background => background,
        Surface => surface,
        SurfaceVariant => surface_variant,
        Border => outline,
        Foreground => on_surface,
        MutedForeground => on_surface_variant,
        Accent => primary,
        AccentForeground => on_primary,
        AccentContainer => primary_container,
        Tertiary => tertiary,
        TertiaryContainer => tertiary_container,
        SelectionContainer => secondary_container,
        SelectionForeground => on_secondary_container,
        Error => error,
        ErrorForeground => on_error,
    }
}

fn project_color_token<T: 'static>(
    env: &mut Environment,
    scheme: &Computed<ColorScheme>,
    light: MaterialColorScheme,
    dark: MaterialColorScheme,
    role: fn(MaterialColorScheme) -> MaterialRoleColor,
) {
    let signal = scheme
        .map(move |scheme| role(material_scheme_for_color_scheme(light, dark, scheme)).resolved())
        .computed();
    waterui_theme::install_color_signal::<T>(env, signal);
}

const fn material_scheme_for_color_scheme(
    light: MaterialColorScheme,
    dark: MaterialColorScheme,
    scheme: ColorScheme,
) -> MaterialColorScheme {
    match scheme {
        ColorScheme::Light => light,
        ColorScheme::Dark => dark,
    }
}

impl Default for Material3 {
    fn default() -> Self {
        Self::defaults()
    }
}

impl WidgetTheme for Material3 {
    fn interaction_motion(&self) -> InteractionMotion {
        theme::motion::interaction()
    }

    fn progress_motion(&self) -> ProgressMotion {
        theme::motion::progress()
    }

    fn text_caret_motion(&self) -> TextCaretMotion {
        theme::motion::text_caret()
    }

    fn navigation_motion(&self) -> NavigationMotion {
        theme::motion::navigation()
    }

    fn button_metrics(&self, style: ButtonStyle, size: ButtonSize) -> ButtonMetrics {
        button::metrics(style, size)
    }

    fn button_label_color(&self, style: ButtonStyle, disabled: bool) -> Option<Color> {
        Some(button::label_color(&self.colors(), style, disabled))
    }

    fn button_label_font(&self, _style: ButtonStyle) -> Option<Font> {
        Some(theme::typography::label_large())
    }

    fn draw_button_chrome(
        &self,
        draw: &mut dyn DrawContext,
        bounds: Rect,
        style: ButtonStyle,
        state: WidgetInteractionState,
    ) {
        button::draw_chrome(&self.colors(), draw, bounds, style, state);
    }

    fn draw_button_state_layer(
        &self,
        draw: &mut dyn DrawContext,
        bounds: Rect,
        style: ButtonStyle,
        state: WidgetInteractionState,
    ) {
        button::draw_state_layer(&self.colors(), draw, bounds, style, state);
    }

    fn draw_interaction_state_layer(
        &self,
        draw: &mut dyn DrawContext,
        bounds: Rect,
        radii: vello::kurbo::RoundedRectRadii,
        color: vello::peniko::Color,
        state: WidgetInteractionState,
    ) {
        theme::state_layer::draw_bounded(draw, bounds, radii, color, state);
    }

    fn toggle_metrics(&self, style: ToggleStyle) -> ToggleMetrics {
        toggle::metrics(style)
    }

    fn toggle_value_animation(&self) -> waterui::animation::Animation {
        theme::motion::toggle_value()
    }

    fn draw_toggle_switch(
        &self,
        draw: &mut dyn DrawContext,
        bounds: Rect,
        progress: f32,
        selected: bool,
        state: WidgetInteractionState,
    ) {
        toggle::draw_switch(&self.colors(), draw, bounds, progress, selected, state);
    }

    fn draw_toggle_switch_state_layer(
        &self,
        draw: &mut dyn DrawContext,
        bounds: Rect,
        progress: f32,
        selected: bool,
        state: WidgetInteractionState,
    ) {
        toggle::draw_switch_state_layer(&self.colors(), draw, bounds, progress, selected, state);
    }

    fn draw_toggle_checkbox(
        &self,
        draw: &mut dyn DrawContext,
        bounds: Rect,
        progress: f32,
        state: WidgetInteractionState,
    ) {
        toggle::draw_checkbox(&self.colors(), draw, bounds, progress, state);
    }

    fn draw_toggle_checkbox_state_layer(
        &self,
        draw: &mut dyn DrawContext,
        bounds: Rect,
        progress: f32,
        state: WidgetInteractionState,
    ) {
        toggle::draw_checkbox_state_layer(&self.colors(), draw, bounds, progress, state);
    }

    fn stepper_metrics(&self) -> StepperMetrics {
        stepper::metrics()
    }

    fn draw_stepper_button(
        &self,
        draw: &mut dyn DrawContext,
        bounds: Rect,
        end: StepperEnd,
        state: WidgetInteractionState,
    ) {
        stepper::draw_button(&self.colors(), draw, bounds, end, state);
    }

    fn draw_stepper_decrement_icon(&self, draw: &mut dyn DrawContext, bounds: Rect) {
        stepper::draw_decrement_icon(&self.colors(), draw, bounds);
    }

    fn draw_stepper_increment_icon(&self, draw: &mut dyn DrawContext, bounds: Rect) {
        stepper::draw_increment_icon(&self.colors(), draw, bounds);
    }

    fn draw_stepper_button_state_layer(
        &self,
        draw: &mut dyn DrawContext,
        bounds: Rect,
        end: StepperEnd,
        state: WidgetInteractionState,
    ) {
        stepper::draw_button_state_layer(&self.colors(), draw, bounds, end, state);
    }

    fn input_field_metrics(&self) -> InputFieldMetrics {
        input::metrics()
    }

    fn input_placeholder_color(&self) -> Color {
        input::placeholder_color(&self.colors())
    }

    fn input_selection_brush(&self) -> Brush {
        input::selection_brush(&self.colors())
    }

    fn input_caret_brush(&self, opacity: f32) -> Brush {
        input::caret_brush(&self.colors(), opacity)
    }

    fn draw_input_field(
        &self,
        draw: &mut dyn DrawContext,
        bounds: Rect,
        state: WidgetInteractionState,
    ) {
        input::draw_field(&self.colors(), draw, bounds, state);
    }

    fn draw_input_field_state_layer(
        &self,
        draw: &mut dyn DrawContext,
        bounds: Rect,
        state: WidgetInteractionState,
    ) {
        input::draw_state_layer(&self.colors(), draw, bounds, state);
    }

    fn text_context_menu_metrics(&self) -> TextContextMenuMetrics {
        menu::text_context_metrics()
    }

    fn draw_text_context_menu_panel(&self, draw: &mut dyn DrawContext, bounds: Rect) {
        menu::draw_text_context_panel(&self.colors(), draw, bounds);
    }

    fn draw_text_context_menu_separator(&self, draw: &mut dyn DrawContext, bounds: Rect) {
        menu::draw_text_context_separator(&self.colors(), draw, bounds);
    }

    fn picker_metrics(&self, style: PickerStyle) -> PickerMetrics {
        picker::metrics(style)
    }

    fn radio_selection_motion(&self) -> RadioSelectionMotion {
        theme::motion::radio_selection()
    }

    fn draw_picker_indicator(&self, draw: &mut dyn DrawContext, bounds: Rect) {
        picker::draw_indicator(&self.colors(), draw, bounds);
    }

    fn draw_picker_state_layer(
        &self,
        draw: &mut dyn DrawContext,
        bounds: Rect,
        state: WidgetInteractionState,
    ) {
        picker::draw_state_layer(&self.colors(), draw, bounds, state);
    }

    fn draw_picker_popup(&self, draw: &mut dyn DrawContext, popup_rect: Rect) {
        picker::draw_popup(&self.colors(), draw, popup_rect);
    }

    fn draw_picker_popup_row_background(
        &self,
        draw: &mut dyn DrawContext,
        row_rect: Rect,
        selected: bool,
    ) {
        picker::draw_popup_row_background(&self.colors(), draw, row_rect, selected);
    }

    fn draw_picker_popup_row_state_layer(
        &self,
        draw: &mut dyn DrawContext,
        row_rect: Rect,
        selected: bool,
        state: WidgetInteractionState,
    ) {
        picker::draw_popup_row_state_layer(&self.colors(), draw, row_rect, selected, state);
    }

    fn draw_picker_separator(&self, draw: &mut dyn DrawContext, separator: Rect) {
        picker::draw_separator(&self.colors(), draw, separator);
    }

    fn draw_radio_indicator(
        &self,
        draw: &mut dyn DrawContext,
        center: Point,
        radius: f64,
        state: RadioIndicatorState,
    ) {
        picker::draw_radio_indicator(&self.colors(), draw, center, radius, state);
    }

    fn draw_radio_state_layer(
        &self,
        draw: &mut dyn DrawContext,
        center: Point,
        radius: f64,
        selected: bool,
        state: WidgetInteractionState,
    ) {
        picker::draw_radio_state_layer(&self.colors(), draw, center, radius, selected, state);
    }

    fn segmented_picker_label_color(&self, selected: bool) -> Option<Color> {
        Some(picker::segmented_label_color(&self.colors(), selected))
    }

    fn draw_segmented_picker_container(
        &self,
        draw: &mut dyn DrawContext,
        bounds: Rect,
        segment_count: usize,
    ) {
        picker::draw_segmented_container(&self.colors(), draw, bounds, segment_count);
    }

    fn draw_segmented_picker_segment(
        &self,
        draw: &mut dyn DrawContext,
        bounds: Rect,
        selected: bool,
        is_first: bool,
        is_last: bool,
    ) {
        picker::draw_segmented_segment(&self.colors(), draw, bounds, selected, is_first, is_last);
    }

    fn draw_segmented_picker_state_layer(
        &self,
        draw: &mut dyn DrawContext,
        bounds: Rect,
        selected: bool,
        is_first: bool,
        is_last: bool,
        state: WidgetInteractionState,
    ) {
        picker::draw_segmented_state_layer(
            &self.colors(),
            draw,
            bounds,
            selected,
            is_first,
            is_last,
            state,
        );
    }

    fn slider_metrics(&self) -> SliderMetrics {
        slider::metrics()
    }

    fn draw_slider_track(
        &self,
        draw: &mut dyn DrawContext,
        track_rect: Rect,
        fill_rect: Rect,
        state: WidgetInteractionState,
    ) {
        slider::draw_track(&self.colors(), draw, track_rect, fill_rect, state);
    }

    fn draw_slider_thumb(
        &self,
        draw: &mut dyn DrawContext,
        center: Point,
        radius: f64,
        state: WidgetInteractionState,
    ) {
        slider::draw_thumb(&self.colors(), draw, center, radius, state);
    }

    fn draw_slider_thumb_state_layer(
        &self,
        draw: &mut dyn DrawContext,
        center: Point,
        radius: f64,
        state: WidgetInteractionState,
    ) {
        slider::draw_thumb_state_layer(&self.colors(), draw, center, radius, state);
    }

    fn progress_metrics(&self, style: ProgressIndicatorStyle) -> ProgressMetrics {
        progress::metrics(style)
    }

    fn draw_progress_linear_track(
        &self,
        draw: &mut dyn DrawContext,
        bounds: Rect,
        active_end: Option<f64>,
    ) {
        progress::draw_linear_track(&self.colors(), draw, bounds, active_end);
    }

    fn draw_progress_linear_fill(&self, draw: &mut dyn DrawContext, bounds: Rect) {
        progress::draw_linear_fill(&self.colors(), draw, bounds);
    }

    fn draw_progress_linear_indeterminate(
        &self,
        draw: &mut dyn DrawContext,
        bounds: Rect,
        elapsed: core::time::Duration,
        four_color: bool,
    ) {
        progress::draw_linear_indeterminate(&self.colors(), draw, bounds, elapsed, four_color);
    }

    fn draw_progress_circular_track(
        &self,
        draw: &mut dyn DrawContext,
        center: Point,
        radius: f64,
        width: f64,
        active_turns: Option<f64>,
    ) {
        progress::draw_circular_track(&self.colors(), draw, center, radius, width, active_turns);
    }

    fn draw_progress_circular_fill(&self, draw: &mut dyn DrawContext, path: &BezPath, width: f64) {
        progress::draw_circular_fill(&self.colors(), draw, path, width);
    }

    fn draw_progress_loading(
        &self,
        draw: &mut dyn DrawContext,
        bounds: Rect,
        elapsed: core::time::Duration,
        four_color: bool,
    ) {
        progress::draw_loading(&self.colors(), draw, bounds, elapsed, four_color);
    }

    fn draw_progress_circular_indeterminate(
        &self,
        draw: &mut dyn DrawContext,
        center: Point,
        radius: f64,
        width: f64,
        elapsed: core::time::Duration,
        four_color: bool,
    ) {
        progress::draw_circular_indeterminate(
            &self.colors(),
            draw,
            center,
            radius,
            width,
            elapsed,
            four_color,
        );
    }

    fn navigation_metrics(&self) -> NavigationMetrics {
        navigation_chrome::metrics()
    }

    fn draw_navigation_bar(&self, draw: &mut dyn DrawContext, bounds: Rect, background: &Brush) {
        navigation_chrome::draw_bar(draw, bounds, background);
    }

    fn draw_navigation_bar_separator(&self, draw: &mut dyn DrawContext, bounds: Rect) {
        navigation_chrome::draw_bar_separator(&self.colors(), draw, bounds);
    }

    fn draw_navigation_back_button(&self, draw: &mut dyn DrawContext, bounds: Rect) {
        navigation_chrome::draw_back_button(&self.colors(), draw, bounds);
    }

    fn tabs_metrics(&self) -> TabsMetrics {
        tabs::metrics()
    }

    fn draw_tabs_bar(&self, draw: &mut dyn DrawContext, bounds: Rect, top_edge: bool) {
        tabs::draw_bar(&self.colors(), draw, bounds, top_edge);
    }

    fn draw_tabs_highlight(&self, draw: &mut dyn DrawContext, bounds: Rect) {
        tabs::draw_highlight(&self.colors(), draw, bounds);
    }

    fn draw_tabs_button_state_layer(
        &self,
        draw: &mut dyn DrawContext,
        bounds: Rect,
        selected: bool,
        state: WidgetInteractionState,
    ) {
        tabs::draw_button_state_layer(&self.colors(), draw, bounds, selected, state);
    }

    fn draw_scroll_indicator(&self, draw: &mut dyn DrawContext, bounds: Rect) {
        scroll::draw_indicator(&self.colors(), draw, bounds);
    }

    fn divider_metrics(&self) -> DividerMetrics {
        divider::metrics()
    }

    fn draw_divider(&self, draw: &mut dyn DrawContext, bounds: Rect) {
        divider::draw(&self.colors(), draw, bounds);
    }

    fn badge_metrics(&self) -> BadgeMetrics {
        badge::metrics()
    }

    fn badge_label_color(&self) -> Color {
        badge::label_color(&self.colors())
    }

    fn badge_label_font(&self) -> Font {
        theme::typography::label_small()
    }

    fn draw_badge_small(&self, draw: &mut dyn DrawContext, bounds: Rect) {
        badge::draw_small(&self.colors(), draw, bounds);
    }

    fn draw_badge_large(&self, draw: &mut dyn DrawContext, bounds: Rect) {
        badge::draw_large(&self.colors(), draw, bounds);
    }

    fn list_metrics(&self) -> ListMetrics {
        list::metrics()
    }

    fn draw_list_row_background(&self, draw: &mut dyn DrawContext, bounds: Rect, alternate: bool) {
        list::draw_row_background(&self.colors(), draw, bounds, alternate);
    }

    fn draw_list_move_control(&self, draw: &mut dyn DrawContext, bounds: Rect) {
        list::draw_move_control(&self.colors(), draw, bounds);
    }

    fn draw_list_move_control_state_layer(
        &self,
        draw: &mut dyn DrawContext,
        bounds: Rect,
        state: WidgetInteractionState,
    ) {
        list::draw_move_control_state_layer(&self.colors(), draw, bounds, state);
    }

    fn draw_list_delete_control(&self, draw: &mut dyn DrawContext, bounds: Rect) {
        list::draw_delete_control(&self.colors(), draw, bounds);
    }

    fn draw_list_delete_control_state_layer(
        &self,
        draw: &mut dyn DrawContext,
        bounds: Rect,
        state: WidgetInteractionState,
    ) {
        list::draw_delete_control_state_layer(&self.colors(), draw, bounds, state);
    }

    fn draw_list_swipe_dismiss_background(
        &self,
        draw: &mut dyn DrawContext,
        bounds: Rect,
        progress: f64,
        toward_start: bool,
    ) {
        list::draw_swipe_dismiss_background(&self.colors(), draw, bounds, progress, toward_start);
    }

    fn draw_list_row_lifted(&self, draw: &mut dyn DrawContext, bounds: Rect, elevation: f64) {
        list::draw_row_lifted(&self.colors(), draw, bounds, elevation);
    }

    fn draw_list_separator(&self, draw: &mut dyn DrawContext, bounds: Rect) {
        list::draw_separator(&self.colors(), draw, bounds);
    }

    fn table_metrics(&self) -> TableMetrics {
        table::metrics()
    }

    fn draw_table_background(&self, draw: &mut dyn DrawContext, bounds: Rect) {
        table::draw_background(&self.colors(), draw, bounds);
    }

    fn draw_table_header_background(&self, draw: &mut dyn DrawContext, bounds: Rect) {
        table::draw_header_background(&self.colors(), draw, bounds);
    }

    fn draw_table_cell_border(&self, draw: &mut dyn DrawContext, bounds: Rect) {
        table::draw_cell_border(&self.colors(), draw, bounds);
    }

    fn draw_table_column_separator(&self, draw: &mut dyn DrawContext, from: Point, to: Point) {
        table::draw_column_separator(&self.colors(), draw, from, to);
    }
}

fn lerp_channel(start: f32, end: f32, t: f32) -> f32 {
    (end - start).mul_add(t, start)
}

fn lerp_color(
    start: vello::peniko::Color,
    end: vello::peniko::Color,
    t: f32,
) -> vello::peniko::Color {
    let t = t.clamp(0.0, 1.0);
    let start = start.to_rgba8();
    let end = end.to_rgba8();
    vello::peniko::Color::new([
        lerp_channel(f32::from(start.r) / 255.0, f32::from(end.r) / 255.0, t),
        lerp_channel(f32::from(start.g) / 255.0, f32::from(end.g) / 255.0, t),
        lerp_channel(f32::from(start.b) / 255.0, f32::from(end.b) / 255.0, t),
        lerp_channel(f32::from(start.a) / 255.0, f32::from(end.a) / 255.0, t),
    ])
}

fn lerp_f64(start: f64, end: f64, t: f32) -> f64 {
    (end - start).mul_add(f64::from(t.clamp(0.0, 1.0)), start)
}