waft-material 0.9.1

Material Design widgets for Waft
Documentation
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
//! Flutter counterpart: material_ui's `menu_theme.dart`.

use std::fmt::{self, Debug};

use waft_foundation::App;
use waft_widgets::{
    BuildContext, InheritedTheme, InheritedWidget, IntoWidget, KeyRef, WidgetRef,
    WidgetStatePropertyRef,
};

use crate::menu_style::MenuStyle;
use crate::theme::Theme;

/// Defines the configuration of the submenus created by the `SubmenuButton`,
/// `MenuBar`, or `MenuAnchor` widgets.
///
/// Descendant widgets obtain the current [`MenuThemeData`] object using
/// [`MenuTheme::of`].
///
/// Typically, a [`MenuThemeData`] is specified as part of the overall `Theme`
/// with `ThemeData::menu_theme`. Otherwise, [`MenuTheme`] can be used to configure
/// its own widget subtree.
///
/// All [`MenuThemeData`] properties are `null` by default. If any of these
/// properties are null, the menu bar will provide its own defaults.
///
/// See also:
///
/// * `ThemeData`, which describes the overall theme for the application.
/// * `MenuBarThemeData`, which describes the theme for the menu bar itself in a
///   `MenuBar` widget.
#[derive(Clone, Default)]
pub struct MenuThemeData {
    /// The [`MenuStyle`] of a `SubmenuButton` menu.
    ///
    /// Any values not set in the [`MenuStyle`] will use the menu default for that
    /// property.
    pub style: Option<MenuStyle>,

    /// If provided, the widget replaces the default `SubmenuButton` arrow icon.
    ///
    /// Resolves in the following states:
    ///  * `WidgetState::Disabled`.
    ///  * `WidgetState::Hovered`.
    ///  * `WidgetState::Focused`.
    pub submenu_icon: Option<WidgetStatePropertyRef<Option<WidgetRef>>>,
}

impl MenuThemeData {
    /// Creates a const set of properties used to configure [`MenuTheme`].
    pub fn new() -> MenuThemeData {
        MenuThemeData::default()
    }

    /// Dart `MenuThemeData(style:)`.
    pub fn style(mut self, style: MenuStyle) -> MenuThemeData {
        self.style = Some(style);
        self
    }

    /// Dart `MenuThemeData(submenuIcon:)`.
    pub fn submenu_icon(
        mut self,
        submenu_icon: WidgetStatePropertyRef<Option<WidgetRef>>,
    ) -> MenuThemeData {
        self.submenu_icon = Some(submenu_icon);
        self
    }

    /// Linearly interpolate between two menu button themes.
    pub fn lerp(
        a: Option<&MenuThemeData>,
        b: Option<&MenuThemeData>,
        t: f64,
    ) -> Option<MenuThemeData> {
        match (a, b) {
            (None, None) => return None,
            (Some(a), Some(b)) if std::ptr::eq(a, b) => return Some(a.clone()),
            _ => {}
        }
        Some(MenuThemeData {
            style: MenuStyle::lerp(
                a.and_then(|a| a.style.as_ref()),
                b.and_then(|b| b.style.as_ref()),
                t,
            ),
            submenu_icon: if t < 0.5 {
                a.and_then(|a| a.submenu_icon.clone())
            } else {
                b.and_then(|b| b.submenu_icon.clone())
            },
        })
    }
}

impl PartialEq for MenuThemeData {
    fn eq(&self, other: &MenuThemeData) -> bool {
        if std::ptr::eq(self, other) {
            return true;
        }
        other.style == self.style && other.submenu_icon == self.submenu_icon
    }
}

impl Debug for MenuThemeData {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let mut properties = f.debug_struct("MenuThemeData");
        if let Some(style) = &self.style {
            properties.field("style", style);
        }
        if let Some(submenu_icon) = &self.submenu_icon {
            properties.field("submenuIcon", submenu_icon);
        }
        properties.finish()
    }
}

/// An inherited widget that defines the configuration in this widget's
/// descendants for menus created by the `SubmenuButton`, `MenuBar`, or
/// `MenuAnchor` widgets.
///
/// Values specified here are used for `SubmenuButton`'s menu properties that
/// are not given an explicit non-null value.
///
/// See also:
///
/// * [`MenuThemeData`], a configuration object that holds attributes of a menu
///   used by this theme.
/// * `MenuBarTheme`, which does the same thing for the `MenuBar` widget.
/// * `MenuBar`, a widget that manages `MenuItemButton`s.
/// * `MenuAnchor`, a widget that creates a region that has a submenu.
/// * `MenuItemButton`, a widget that is a selectable item in a menu bar menu.
/// * `SubmenuButton`, a widget that specifies an item with a cascading submenu
///   in a `MenuBar` menu.
#[derive(Debug)]
pub struct MenuTheme {
    pub key: Option<KeyRef>,
    /// The properties for `MenuBar` and `MenuItemButton` in this widget's
    /// descendants.
    pub data: MenuThemeData,
    pub child: WidgetRef,
}

impl MenuTheme {
    /// Creates a const theme that controls the configurations for the menus
    /// created by the `SubmenuButton` or `MenuAnchor` widgets.
    pub fn new<K>(data: MenuThemeData, child: impl IntoWidget<K>) -> MenuTheme {
        MenuTheme {
            key: None,
            data,
            child: child.into_widget(),
        }
    }

    /// Dart `MenuTheme(key:)`.
    pub fn key(mut self, key: KeyRef) -> MenuTheme {
        self.key = Some(key);
        self
    }

    /// Returns the closest instance of this class's [`data`](Self::data) value that encloses
    /// the given context. If there is no ancestor, it returns
    /// `ThemeData::menu_theme`.
    ///
    /// Typical usage is as follows:
    ///
    /// ```text
    /// let theme = MenuTheme::of(app, context);
    /// ```
    pub fn of(app: &mut App, context: BuildContext) -> MenuThemeData {
        match context.depend_on_inherited_widget_of_exact_type::<MenuTheme>(app) {
            Some(menu_theme) => menu_theme.data.clone(),
            None => Theme::of(app, context).menu_theme.clone(),
        }
    }
}

impl InheritedTheme for MenuTheme {
    fn wrap(&self, _app: &mut App, _context: BuildContext, child: WidgetRef) -> WidgetRef {
        MenuTheme::new(self.data.clone(), child).into_widget()
    }
}

impl InheritedWidget for MenuTheme {
    fn key(&self) -> Option<&KeyRef> {
        self.key.as_ref()
    }

    fn child(&self) -> &WidgetRef {
        &self.child
    }

    fn update_should_notify(&self, old_widget: &MenuTheme) -> bool {
        self.data != old_widget.data
    }

    fn as_inherited_theme(&self) -> Option<&dyn InheritedTheme> {
        Some(self)
    }
}

#[cfg(test)]
pub(crate) mod tests {
    use std::rc::Rc;

    use waft_embedder::{Color, Rect};
    use waft_painting::{
        BeveledRectangleBorder, EdgeInsetsGeometry, OutlinedBorderRef, ShapeBorder, StadiumBorder,
    };
    use waft_rendering::BoxConstraints;
    use waft_services::{LogicalKeyboardKey, PhysicalKeyboardKey};
    use waft_widgets::{
        Axis, Builder, Column, ConstrainedBox, DefaultTextStyle, Expanded, Icon, Text, WidgetState,
        WidgetStateProperty, WidgetStatePropertyAll, WidgetStates,
    };

    use waft_widgets::testing::{
        Finder, TestPointer, WidgetTester, expect, find, finds_one_widget, test_widgets,
    };

    use super::*;
    use crate::button_style::ButtonStyle;
    use crate::colors::Colors;
    use crate::icons::Icons;
    use crate::material::Material;
    use crate::menu_anchor::{MenuBar, MenuItemButton, MenuPanel, SubmenuButton};
    use crate::menu_bar_theme::{MenuBarTheme, MenuBarThemeData};
    use crate::test_support::material_app;
    use crate::text_button::TextButton;
    use crate::theme_data::ThemeData;
    use crate::tooltip::tests::m2;

    /// The labels of the menus these tests build: Dart's `TestMenu` of `menu_theme_test.dart`
    /// and `menu_bar_theme_test.dart`.
    pub(crate) mod test_menu {
        pub(crate) const MAIN_MENU_0: &str = "Menu 0";
        pub(crate) const MAIN_MENU_1: &str = "Menu 1";
        pub(crate) const MAIN_MENU_2: &str = "Menu 2";
        pub(crate) const SUB_MENU_00: &str = "Sub Menu 00";
        pub(crate) const SUB_MENU_10: &str = "Sub Menu 10";
        pub(crate) const SUB_MENU_11: &str = "Sub Menu 11";
        pub(crate) const SUB_MENU_12: &str = "Sub Menu 12";
        pub(crate) const SUB_MENU_20: &str = "Sub Menu 20";
        pub(crate) const SUB_SUB_MENU_110: &str = "Sub Sub Menu 110";
        pub(crate) const SUB_SUB_MENU_111: &str = "Sub Sub Menu 111";
        pub(crate) const SUB_SUB_MENU_112: &str = "Sub Sub Menu 112";
        pub(crate) const SUB_SUB_MENU_113: &str = "Sub Sub Menu 113";
    }

    /// Dart's `createTestMenus` styling arguments of `menu_theme_test.dart`.
    #[derive(Default)]
    pub(crate) struct ThemeTestMenus {
        pub(crate) item_overlay: Option<Color>,
        pub(crate) item_background: Option<Color>,
        pub(crate) item_foreground: Option<Color>,
        pub(crate) item_padding: Option<EdgeInsetsGeometry>,
        pub(crate) menu_background: Option<Color>,
        pub(crate) menu_padding: Option<EdgeInsetsGeometry>,
        pub(crate) menu_shape: Option<OutlinedBorderRef>,
        pub(crate) menu_elevation: Option<f64>,
        pub(crate) item_shape: Option<OutlinedBorderRef>,
    }

    fn all<T: Clone + std::fmt::Debug + PartialEq + 'static>(
        value: T,
    ) -> WidgetStatePropertyRef<Option<T>> {
        Rc::new(WidgetStatePropertyAll::new(Some(value)))
    }

    /// Dart's `createTestMenus(onPressed: onPressed, ...)`, with an `onPressed` that does
    /// nothing.
    pub(crate) fn theme_test_menus(options: ThemeTestMenus) -> Vec<WidgetRef> {
        use test_menu::*;
        let mut menu_style = MenuStyle::new();
        menu_style.padding = options.menu_padding.map(all);
        menu_style.background_color = options.menu_background.map(all);
        menu_style.elevation = options.menu_elevation.map(all);
        menu_style.shape = options.menu_shape.map(all);
        let mut item_style = ButtonStyle::new();
        item_style.padding = options.item_padding.map(all);
        item_style.shape = options.item_shape.map(all);
        item_style.foreground_color = options.item_foreground.map(all);
        item_style.background_color = options.item_background.map(all);
        item_style.overlay_color = options.item_overlay.map(all);
        let item = |label: &str| {
            MenuItemButton::new()
                .on_pressed(waft_foundation::Listener::new(|_app| {}))
                .child(Text::new(label))
                .into_widget()
        };
        vec![
            SubmenuButton::new(vec![item(SUB_MENU_00)], Some(Text::new(MAIN_MENU_0))).into_widget(),
            SubmenuButton::new(
                vec![
                    MenuItemButton::new()
                        .on_pressed(waft_foundation::Listener::new(|_app| {}))
                        .style(item_style)
                        .child(Text::new(SUB_MENU_10))
                        .into_widget(),
                    SubmenuButton::new(
                        vec![
                            item(SUB_SUB_MENU_110),
                            item(SUB_SUB_MENU_111),
                            item(SUB_SUB_MENU_112),
                            item(SUB_SUB_MENU_113),
                        ],
                        Some(Text::new(SUB_MENU_11)),
                    )
                    .into_widget(),
                    item(SUB_MENU_12),
                ],
                Some(Text::new(MAIN_MENU_1)),
            )
            .menu_style(menu_style)
            .into_widget(),
            SubmenuButton::new(
                // Always disabled.
                vec![
                    MenuItemButton::new()
                        .child(Text::new(SUB_MENU_20))
                        .into_widget(),
                ],
                Some(Text::new(MAIN_MENU_2)),
            )
            .into_widget(),
        ]
    }

    /// Dart's `findMenuPanels(orientation)`.
    pub(crate) fn menu_panels(orientation: Axis) -> Finder {
        find::by_widget_predicate("a _MenuPanel of the orientation", move |_app, widget| {
            waft_widgets::downcast_widget::<MenuPanel>(widget)
                .is_some_and(|panel| panel.orientation == orientation)
        })
    }

    /// The first `Material` under the only panel of `orientation`, read through `read`.
    pub(crate) fn panel_material<R>(
        tester: &WidgetTester,
        orientation: Axis,
        read: impl FnOnce(&Material) -> R,
    ) -> R {
        let material = find::descendant(
            menu_panels(orientation).first(),
            find::by_type::<Material>(),
        )
        .first();
        tester.widget(material, read)
    }

    fn shape_is(material: &Material, expected: &dyn ShapeBorder) -> bool {
        material
            .shape
            .as_ref()
            .is_some_and(|shape| shape.eq_shape(expected))
    }

    /// The bar of `menu_theme_test.dart`'s two widget cases: `MenuBarTheme(bar_style)` over
    /// `MenuTheme(menu_style)` over `Column([bar, Expanded(Placeholder())])`.
    fn pump_themed_bar(
        tester: &mut WidgetTester,
        bar_theme: MenuBarThemeData,
        menu_theme: MenuThemeData,
        bar: impl Fn() -> WidgetRef + 'static,
    ) {
        let root = {
            let app = tester.cell.borrow();
            material_app(
                m2(&app),
                Material::new()
                    .child(Builder::new(move |_app, _context| {
                        MenuBarTheme::new(
                            bar_theme.clone(),
                            MenuTheme::new(
                                menu_theme.clone(),
                                Column::new().children(vec![
                                    bar(),
                                    Expanded::new(ConstrainedBox::new(BoxConstraints::expand(
                                        None, None,
                                    )))
                                    .into_widget(),
                                ]),
                            ),
                        )
                        .into_widget()
                    }))
                    .into_widget(),
            )
        };
        tester.pump_widget(root);
    }

    /// The menu theme of both widget cases.
    pub(crate) fn red_stadium_menu_style() -> MenuStyle {
        MenuStyle::new()
            .background_color(all(Colors::RED.primary()))
            .elevation(all(15.0))
            .shape(all(OutlinedBorderRef::new(StadiumBorder::default())))
            .padding(all(EdgeInsetsGeometry::directional(10.0, 10.0, 10.0, 10.0)))
    }

    /// The menu bar theme of both widget cases.
    pub(crate) fn green_menu_style() -> MenuStyle {
        MenuStyle::new()
            .background_color(all(Colors::GREEN.primary()))
            .elevation(all(20.0))
    }

    /// The `MenuBar` of the 'Constructor parameters override theme parameters' cases.
    pub(crate) fn overriding_bar() -> WidgetRef {
        MenuBar::new(theme_test_menus(ThemeTestMenus {
            menu_background: Some(Colors::CYAN.primary()),
            menu_elevation: Some(18.0),
            menu_padding: Some(EdgeInsetsGeometry::directional(14.0, 14.0, 14.0, 14.0)),
            menu_shape: Some(OutlinedBorderRef::new(BeveledRectangleBorder::default())),
            item_background: Some(Colors::AMBER.primary()),
            item_foreground: Some(Colors::GREY.primary()),
            item_overlay: Some(Colors::BLUE_GREY.primary()),
            item_padding: Some(EdgeInsetsGeometry::directional(11.0, 11.0, 11.0, 11.0)),
            item_shape: Some(OutlinedBorderRef::new(StadiumBorder::default())),
        }))
        .style(
            MenuStyle::new()
                .background_color(all(Colors::BLUE.primary()))
                .elevation(all(10.0))
                .padding(all(EdgeInsetsGeometry::directional(12.0, 12.0, 12.0, 12.0))),
        )
        .into_widget()
    }

    /// The asserts the 'Constructor parameters override theme parameters' cases share.
    pub(crate) fn assert_constructor_parameters_override_theme_parameters(tester: &WidgetTester) {
        use test_menu::*;
        assert_eq!(
            tester.get_rect(menu_panels(Axis::Horizontal).first()),
            Rect::from_ltrb(226.0, 0.0, 574.0, 72.0)
        );
        panel_material(tester, Axis::Horizontal, |material| {
            assert_eq!(material.elevation, 10.0);
            assert_eq!(material.color, Some(Colors::BLUE.primary()));
        });

        assert_eq!(
            tester.get_rect(menu_panels(Axis::Vertical)),
            Rect::from_ltrb(332.0, 60.0, 574.0, 232.0)
        );
        panel_material(tester, Axis::Vertical, |material| {
            assert_eq!(material.elevation, 18.0);
            assert_eq!(material.color, Some(Colors::CYAN.primary()));
            assert!(shape_is(material, &BeveledRectangleBorder::default()));
        });

        let menu_item = find::descendant(
            menu_panels(Axis::Vertical).last(),
            find::by_type::<MenuItemButton>(),
        )
        .first();
        assert_eq!(
            tester.get_rect(menu_item),
            Rect::from_ltrb(346.0, 74.0, 560.0, 122.0)
        );
        let menu_item_material =
            find::ancestor(find::text(SUB_MENU_10), find::by_type::<Material>()).first();
        tester.widget(menu_item_material, |material: &Material| {
            assert_eq!(material.color, Some(Colors::AMBER.primary()));
            assert_eq!(material.elevation, 0.0);
            assert!(shape_is(material, &StadiumBorder::default()));
        });
        let label_style =
            find::ancestor(find::text(SUB_MENU_10), find::by_type::<DefaultTextStyle>()).first();
        tester.widget(label_style, |style: &DefaultTextStyle| {
            assert_eq!(style.style.color, Some(Colors::GREY.primary().into()));
        });
        let text_button =
            find::ancestor(find::text(SUB_MENU_10), find::by_type::<TextButton>()).first();
        let overlay = tester.widget(text_button, |button: &TextButton| {
            crate::button_style_button::ButtonStyleButton::button_style_button_data(button)
                .style
                .as_ref()
                .and_then(|style| style.overlay_color.clone())
        });
        let hovered: WidgetStates = [WidgetState::Hovered].into_iter().collect();
        assert_eq!(
            overlay.and_then(|overlay| overlay.resolve(&hovered)),
            Some(Colors::BLUE_GREY.primary())
        );
    }

    // menu_theme_test.dart 'MenuThemeData defaults'.
    #[test]
    fn a_new_menu_theme_data_sets_nothing() {
        let menu_theme_data = MenuThemeData::new();
        assert!(menu_theme_data.style.is_none());
        assert!(menu_theme_data.submenu_icon.is_none());
    }

    // menu_theme_test.dart 'MenuThemeData lerp special cases'.
    #[test]
    fn lerp_of_nothing_is_nothing_and_of_one_theme_with_itself_is_that_theme() {
        assert!(MenuThemeData::lerp(None, None, 0.0).is_none());
        let data = MenuThemeData::new();
        assert_eq!(
            MenuThemeData::lerp(Some(&data), Some(&data), 0.5),
            Some(data)
        );
    }

    // menu_theme_test.dart 'theme is honored'.
    #[test]
    fn a_menu_theme_styles_the_submenus_and_a_menu_bar_theme_the_bar() {
        test_widgets(|tester| {
            pump_themed_bar(
                tester,
                MenuBarThemeData::new().style(green_menu_style()),
                MenuThemeData::new().style(red_stadium_menu_style()),
                || MenuBar::new(theme_test_menus(ThemeTestMenus::default())).into_widget(),
            );

            // Open a test menu.
            tester.tap(find::text(test_menu::MAIN_MENU_1));
            tester.pump();
            assert_eq!(
                tester.get_rect(menu_panels(Axis::Horizontal).first()),
                Rect::from_ltrb(234.0, 0.0, 566.0, 48.0)
            );
            panel_material(tester, Axis::Horizontal, |material| {
                assert_eq!(material.elevation, 20.0);
                assert_eq!(material.color, Some(Colors::GREEN.primary()));
            });

            assert_eq!(
                tester.get_rect(menu_panels(Axis::Vertical)),
                Rect::from_ltrb(336.0, 48.0, 570.0, 212.0)
            );
            panel_material(tester, Axis::Vertical, |material| {
                assert_eq!(material.elevation, 15.0);
                assert_eq!(material.color, Some(Colors::RED.primary()));
            });
        });
    }

    // menu_theme_test.dart 'Constructor parameters override theme parameters'.
    #[test]
    fn a_menu_bars_and_its_buttons_own_styles_override_the_themes() {
        test_widgets(|tester| {
            pump_themed_bar(
                tester,
                MenuBarThemeData::new().style(green_menu_style()),
                MenuThemeData::new().style(red_stadium_menu_style()),
                overriding_bar,
            );

            // Open a test menu.
            tester.tap(find::text(test_menu::MAIN_MENU_1));
            tester.pump();

            assert_constructor_parameters_override_theme_parameters(tester);
        });
    }

    /// Dart's `tester.sendKeyEvent(LogicalKeyboardKey.arrowDown)`.
    fn send_arrow_down(tester: &mut WidgetTester) {
        tester.send_key_event(
            PhysicalKeyboardKey::ARROW_DOWN,
            LogicalKeyboardKey::ARROW_DOWN,
        );
    }

    // menu_theme_test.dart 'SubmenuButton.submenuIcon updates default arrow icon'.
    #[test]
    fn a_menu_themes_submenu_icon_resolves_against_the_buttons_states() {
        test_widgets(|tester| {
            use test_menu::*;
            let controller = waft_widgets::MenuController::new(&mut tester.cell.borrow_mut())
                .into_erased::<waft_widgets::AnyMenuController>();
            let disabled_icon = Icons::close_fullscreen();
            let hovered_icon = Icons::ac_unit();
            let focused_icon = Icons::zoom_out();
            let default_icon = Icons::minimize();
            let icons = (
                disabled_icon.clone(),
                hovered_icon.clone(),
                focused_icon.clone(),
                default_icon.clone(),
            );
            let submenu_icon: WidgetStatePropertyRef<Option<WidgetRef>> =
                <dyn WidgetStateProperty<Option<WidgetRef>>>::resolve_with(move |states| {
                    let (disabled, hovered, focused, default) = icons.clone();
                    if states.contains(&WidgetState::Disabled) {
                        return Some(Icon::new(Some(disabled)).into_widget());
                    }
                    if states.contains(&WidgetState::Hovered) {
                        return Some(Icon::new(Some(hovered)).into_widget());
                    }
                    if states.contains(&WidgetState::Focused) {
                        return Some(Icon::new(Some(focused)).into_widget());
                    }
                    Some(Icon::new(Some(default)).into_widget())
                });

            let build_menu = |tester: &mut WidgetTester,
                              icon: Option<WidgetStatePropertyRef<Option<WidgetRef>>>,
                              enabled: bool| {
                let root = {
                    let app = tester.cell.borrow();
                    let mut menu_theme = MenuThemeData::new();
                    menu_theme.submenu_icon = icon;
                    let menu_children = if enabled {
                        vec![
                            MenuItemButton::new()
                                .child(Text::new(MAIN_MENU_0))
                                .into_widget(),
                        ]
                    } else {
                        Vec::new()
                    };
                    material_app(
                        ThemeData::builder().menu_theme(menu_theme).build(&app),
                        Material::new()
                            .child(
                                MenuBar::new(vec![
                                    SubmenuButton::new(
                                        vec![
                                            SubmenuButton::new(
                                                menu_children,
                                                Some(Text::new(SUB_SUB_MENU_110)),
                                            )
                                            .into_widget(),
                                        ],
                                        Some(Text::new(SUB_MENU_00)),
                                    )
                                    .into_widget(),
                                ])
                                .controller(controller.clone()),
                            )
                            .into_widget(),
                    )
                };
                tester.pump_widget(root);
            };

            build_menu(tester, None, true);
            tester.tap(find::text(SUB_MENU_00));
            tester.pump();

            expect(
                tester,
                &find::by_icon(&Icons::arrow_right()),
                finds_one_widget(),
            );

            controller.close(&mut tester.cell.borrow_mut());
            tester.pump();

            build_menu(tester, Some(Rc::clone(&submenu_icon)), true);
            tester.pump_and_settle();

            tester.tap(find::text(SUB_MENU_00));
            tester.pump();
            expect(tester, &find::by_icon(&default_icon), finds_one_widget());

            send_arrow_down(tester);
            tester.pump();
            expect(tester, &find::by_icon(&focused_icon), finds_one_widget());

            controller.close(&mut tester.cell.borrow_mut());
            tester.pump();

            tester.tap(find::text(SUB_MENU_00));
            tester.pump();
            // Dart's `hoverOver`: a new mouse moved over the text, then a settle.
            let at = tester.get_center(find::text(SUB_SUB_MENU_110));
            let mut mouse = TestPointer::mouse(1, 0);
            tester.add_pointer(&mut mouse, waft_embedder::Offset::ZERO);
            tester.move_to(&mut mouse, at, false);
            tester.pump_and_settle();
            tester.pump();
            expect(tester, &find::by_icon(&hovered_icon), finds_one_widget());

            controller.close(&mut tester.cell.borrow_mut());
            tester.pump();

            build_menu(tester, Some(submenu_icon), false);
            tester.tap(find::text(SUB_MENU_00));
            tester.pump();
            expect(tester, &find::by_icon(&disabled_icon), finds_one_widget());
        });
    }
}