waft-material 0.14.0

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
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
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
//! Flutter counterpart: material_ui's `action_buttons.dart`.

use waft_embedder::{Color, TargetPlatform};
use waft_foundation::{App, K_IS_WEB, Listener};
use waft_widgets::{
    BuildContext, Icon, IconData, IntoWidget, KeyRef, Navigator, Semantics, StandardComponentType,
    StatelessWidget, WidgetBuilder, WidgetRef,
};

use crate::action_icons_theme::{ActionIconTheme, ActionIconThemeData};
use crate::button_style::ButtonStyle;
use crate::debug::debug_check_has_material_localizations;
use crate::icon_button::IconButton;
use crate::icons::Icons;
use crate::material_localizations::MaterialLocalizations;
use crate::scaffold::{Scaffold, scaffold_drawer_expanded_of, scaffold_end_drawer_expanded_of};
use crate::theme::Theme;

/// What `_ActionButton` reads of its subclass: the fields Dart's constructor passes to
/// `IconButton` through `super`.
struct ActionButtonFields<'a> {
    color: Option<Color>,
    style: &'a Option<ButtonStyle>,
    on_pressed: &'a Option<Listener>,
    icon: &'a WidgetRef,
    standard_component: Option<StandardComponentType>,
}

/// Dart's abstract `_ActionButton extends IconButton`: a Material Design icon button whose
/// subclasses name the tooltip and the default behaviour of a press.
///
/// A subclass is a widget that builds through [`ActionButton::build`]; the base class's
/// `build` never returns the subclass itself but a plain `IconButton`.
trait ActionButton: Sized {
    fn fields(&self) -> ActionButtonFields<'_>;

    /// This returns the appropriate tooltip text for this action button.
    fn get_tooltip(app: &mut App, context: BuildContext) -> String;

    /// This is the default function that is called when `on_pressed` is set
    /// to null.
    fn on_pressed_callback(app: &mut App, context: BuildContext);

    fn build(&self, app: &mut App, context: BuildContext) -> WidgetRef {
        debug_assert!(debug_check_has_material_localizations(app, context));
        let fields = self.fields();
        let on_pressed = fields.on_pressed.clone();
        let mut button = IconButton::new(
            Some(Listener::new(move |app| match &on_pressed {
                Some(on_pressed) => on_pressed.call(app),
                None => Self::on_pressed_callback(app, context),
            })),
            fields.icon.clone(),
        )
        .tooltip(Self::get_tooltip(app, context));
        if let Some(standard_component) = fields.standard_component {
            button = button.key(standard_component.key());
        }
        if let Some(style) = fields.style {
            button = button.style(style.clone());
        }
        if let Some(color) = fields.color {
            button = button.color(color);
        }
        button.into_widget()
    }
}

/// Dart's `_ActionIcon`.
#[derive(Debug)]
struct ActionIcon {
    icon_builder_callback: fn(&ActionIconThemeData) -> &Option<WidgetBuilder>,
    get_icon: fn(&mut App, BuildContext) -> IconData,
    get_android_semantics_label: fn(&dyn MaterialLocalizations) -> String,
}

impl StatelessWidget for ActionIcon {
    fn build(&self, app: &mut App, context: BuildContext) -> WidgetRef {
        let action_icon_theme = ActionIconTheme::of(app, context);
        let icon_builder = action_icon_theme
            .as_ref()
            .and_then(|theme| (self.icon_builder_callback)(theme).clone());
        if let Some(icon_builder) = icon_builder {
            return icon_builder(app, context);
        }

        let data = (self.get_icon)(app, context);
        // This can't use the platform from Theme because it is the Android OS that
        // expects the duplicated tooltip and label.
        let semantics_label = match app.platform().target_platform() {
            TargetPlatform::Android => Some((self.get_android_semantics_label)(
                &*<dyn MaterialLocalizations>::of(app, context),
            )),
            TargetPlatform::Fuchsia
            | TargetPlatform::Linux
            | TargetPlatform::Windows
            | TargetPlatform::IOS
            | TargetPlatform::MacOS => None,
        };

        let mut icon = Icon::new(Some(data));
        if let Some(semantics_label) = semantics_label {
            icon = icon.semantic_label(semantics_label);
        }
        icon.into_widget()
    }
}

/// Defines one of Dart's `_ActionButton` subclasses: a widget with `IconButton`'s `key`,
/// `color`, `style` and `onPressed`, and the icon its constructor passes to `super`.
macro_rules! action_button_widget {
    (
        $(#[$meta:meta])*
        $name:ident, icon: $icon:ident, standard_component: $standard_component:expr,
        tooltip: $tooltip:ident, on_pressed: |$app:ident, $context:ident| $on_pressed:expr
    ) => {
        $(#[$meta])*
        #[derive(Debug)]
        pub struct $name {
            pub key: Option<KeyRef>,
            pub color: Option<Color>,
            pub style: Option<ButtonStyle>,
            pub on_pressed: Option<Listener>,
            icon: WidgetRef,
            standard_component: Option<StandardComponentType>,
        }

        impl $name {
            #[doc = concat!("Dart `", stringify!($name), "()`.")]
            pub fn new() -> $name {
                $name {
                    key: None,
                    color: None,
                    style: None,
                    on_pressed: None,
                    icon: $icon::new().into_widget(),
                    standard_component: $standard_component,
                }
            }

            #[doc = concat!("Dart `", stringify!($name), "(key:)`.")]
            pub fn key(mut self, key: KeyRef) -> $name {
                self.key = Some(key);
                self
            }

            #[doc = concat!("Dart `", stringify!($name), "(color:)`.")]
            pub fn color(mut self, color: Color) -> $name {
                self.color = Some(color);
                self
            }

            #[doc = concat!("Dart `", stringify!($name), "(style:)`.")]
            pub fn style(mut self, style: ButtonStyle) -> $name {
                self.style = Some(style);
                self
            }

            #[doc = concat!("Dart `", stringify!($name), "(onPressed:)`.")]
            pub fn on_pressed(mut self, on_pressed: Listener) -> $name {
                self.on_pressed = Some(on_pressed);
                self
            }
        }

        impl Default for $name {
            fn default() -> $name {
                $name::new()
            }
        }

        impl ActionButton for $name {
            fn fields(&self) -> ActionButtonFields<'_> {
                ActionButtonFields {
                    color: self.color,
                    style: &self.style,
                    on_pressed: &self.on_pressed,
                    icon: &self.icon,
                    standard_component: self.standard_component,
                }
            }

            fn get_tooltip(app: &mut App, context: BuildContext) -> String {
                <dyn MaterialLocalizations>::of(app, context).$tooltip()
            }

            fn on_pressed_callback($app: &mut App, $context: BuildContext) {
                $on_pressed
            }
        }

        impl StatelessWidget for $name {
            fn key(&self) -> Option<&KeyRef> {
                self.key.as_ref()
            }

            fn build(&self, app: &mut App, context: BuildContext) -> WidgetRef {
                ActionButton::build(self, app, context)
            }
        }
    };
}

/// Dart's `Semantics(expanded:)` around `DrawerButtonIcon`'s and `EndDrawerButtonIcon`'s
/// `_ActionIcon`, from the scaffold read `expanded_of`.
fn with_expanded_semantics(
    app: &mut App,
    context: BuildContext,
    expanded_of: fn(&mut App, BuildContext) -> Option<bool>,
    action_icon: ActionIcon,
) -> WidgetRef {
    let mut semantics = Semantics::new();
    if let Some(expanded) = expanded_of(app, context) {
        semantics = semantics.expanded(expanded);
    }
    semantics.child(action_icon).into_widget()
}

/// Defines one of Dart's `*ButtonIcon` widgets, each a `_ActionIcon` whose builder comes from
/// the action icon theme, and whose Android semantics label is the localized `$label`. The
/// drawer icons name `expanded:`, the scaffold read Dart's `Semantics(expanded:)` around them
/// takes.
macro_rules! action_icon_widget {
    (@wrap $app:ident, $context:ident, $action_icon:ident) => {
        $action_icon.into_widget()
    };
    (@wrap $app:ident, $context:ident, $action_icon:ident, $expanded:path) => {
        with_expanded_semantics($app, $context, $expanded, $action_icon)
    };
    (
        $(#[$meta:meta])*
        $name:ident, builder: $builder:ident, get_icon: |$app:ident, $context:ident| $get_icon:expr,
        android_semantics_label: $label:ident $(, expanded: $expanded:path)?
    ) => {
        $(#[$meta])*
        #[derive(Debug, Default)]
        pub struct $name {
            pub key: Option<KeyRef>,
        }

        impl $name {
            #[doc = concat!("Dart `", stringify!($name), "()`.")]
            pub fn new() -> $name {
                $name::default()
            }

            #[doc = concat!("Dart `", stringify!($name), "(key:)`.")]
            pub fn key(mut self, key: KeyRef) -> $name {
                self.key = Some(key);
                self
            }
        }

        impl StatelessWidget for $name {
            fn key(&self) -> Option<&KeyRef> {
                self.key.as_ref()
            }

            fn build(&self, _app: &mut App, _context: BuildContext) -> WidgetRef {
                let action_icon = ActionIcon {
                    icon_builder_callback: |action_icon_theme| &action_icon_theme.$builder,
                    get_icon: |$app, $context| $get_icon,
                    get_android_semantics_label: |material_localization| {
                        material_localization.$label()
                    },
                };
                action_icon_widget!(@wrap _app, _context, action_icon $(, $expanded)?)
            }
        }
    };
}

action_icon_widget!(
    /// A "back" icon that's appropriate for the current [`TargetPlatform`].
    ///
    /// The current platform is determined by querying for the ambient `Theme`.
    ///
    /// See also:
    ///
    ///  * [`BackButton`], an `IconButton` with a [`BackButtonIcon`] that calls
    ///    `Navigator::maybe_pop` to return to the previous route.
    ///  * `IconButton`, which is a more general widget for creating buttons
    ///    with icons.
    ///  * `Icon`, a Material Design icon.
    ///  * `ThemeData::platform`, which specifies the current platform.
    BackButtonIcon,
    builder: back_button_icon_builder,
    get_icon: |app, context| {
        if K_IS_WEB {
            // Always use 'Icons.arrow_back' as a back_button icon in web.
            return Icons::arrow_back();
        }
        match Theme::of(app, context).platform {
            TargetPlatform::Android
            | TargetPlatform::Fuchsia
            | TargetPlatform::Linux
            | TargetPlatform::Windows => Icons::arrow_back(),
            TargetPlatform::IOS | TargetPlatform::MacOS => Icons::arrow_back_ios_new_rounded(),
        }
    },
    android_semantics_label: back_button_tooltip
);

action_button_widget!(
    /// A Material Design back icon button.
    ///
    /// A [`BackButton`] is an `IconButton` with a "back" icon appropriate for the
    /// current [`TargetPlatform`]. When pressed, the back button calls
    /// `Navigator::maybe_pop` to return to the previous route unless a custom
    /// [`on_pressed`](Self::on_pressed) callback is provided.
    ///
    /// The [`on_pressed`](Self::on_pressed) callback can, for instance, be used to pop the
    /// platform's navigation stack via `SystemNavigator` instead of Flutter's `Navigator` in
    /// add-to-app situations.
    ///
    /// In Material Design 3, both [`style`](Self::style)'s `ButtonStyle::icon_color` and
    /// [`color`](Self::color) are used to override the default icon color of [`BackButton`]. If
    /// both exist, the `ButtonStyle::icon_color` will override [`color`](Self::color) for states
    /// where `ButtonStyle::foreground_color` resolves to non-null.
    ///
    /// When deciding to display a [`BackButton`], consider using
    /// `ModalRoute::can_pop_of(context)` to check whether the current route can be
    /// popped. If that value is false (e.g., because the current route is the
    /// initial route), the [`BackButton`] will not have any effect when pressed,
    /// which could frustrate the user.
    ///
    /// Requires one of its ancestors to be a `Material` widget.
    ///
    /// See also:
    ///
    ///  * `AppBar`, which automatically uses a [`BackButton`] in its
    ///    `AppBar::leading` slot when the `Scaffold` has no `Drawer` and the
    ///    current `Route` is not the `Navigator`'s first route.
    ///  * [`BackButtonIcon`], which is useful if you need to create a back button
    ///    that responds differently to being pressed.
    ///  * `IconButton`, which is a more general widget for creating buttons with
    ///    icons.
    ///  * [`CloseButton`], an alternative which may be more appropriate for leaf
    ///    node pages in the navigation tree.
    BackButton,
    icon: BackButtonIcon,
    standard_component: Some(StandardComponentType::BackButton),
    tooltip: back_button_tooltip,
    on_pressed: |app, context| {
        Navigator::maybe_pop(app, context, None);
    }
);

action_icon_widget!(
    /// A "close" icon that's appropriate for the current [`TargetPlatform`].
    ///
    /// The current platform is determined by querying for the ambient `Theme`.
    ///
    /// See also:
    ///
    ///  * [`CloseButton`], an `IconButton` with a [`CloseButtonIcon`] that calls
    ///    `Navigator::maybe_pop` to return to the previous route.
    ///  * `IconButton`, which is a more general widget for creating buttons
    ///    with icons.
    ///  * `Icon`, a Material Design icon.
    ///  * `ThemeData::platform`, which specifies the current platform.
    CloseButtonIcon,
    builder: close_button_icon_builder,
    get_icon: |_app, _context| Icons::close(),
    android_semantics_label: close_button_tooltip
);

action_button_widget!(
    /// A Material Design close icon button.
    ///
    /// A [`CloseButton`] is an `IconButton` with a "close" icon. When pressed, the
    /// close button calls `Navigator::maybe_pop` to return to the previous route.
    ///
    /// The [`on_pressed`](Self::on_pressed) callback can, for instance, be used to pop the
    /// platform's navigation stack via `SystemNavigator` instead of Flutter's `Navigator` in
    /// add-to-app situations.
    ///
    /// In Material Design 3, both [`style`](Self::style)'s `ButtonStyle::icon_color` and
    /// [`color`](Self::color) are used to override the default icon color of [`CloseButton`]. If
    /// both exist, the `ButtonStyle::icon_color` will override [`color`](Self::color) for states
    /// where `ButtonStyle::foreground_color` resolves to non-null.
    ///
    /// Use a [`CloseButton`] instead of a [`BackButton`] on fullscreen dialogs or
    /// pages that may solicit additional actions to close.
    ///
    /// See also:
    ///
    ///  * `AppBar`, which automatically uses a [`CloseButton`] in its
    ///    `AppBar::leading` slot when appropriate.
    ///  * [`BackButton`], which is more appropriate for middle nodes in the
    ///    navigation tree or where pages can be popped instantaneously with
    ///    no user data consequence.
    ///  * `IconButton`, to create other Material Design icon buttons.
    CloseButton,
    icon: CloseButtonIcon,
    standard_component: Some(StandardComponentType::CloseButton),
    tooltip: close_button_tooltip,
    on_pressed: |app, context| {
        Navigator::maybe_pop(app, context, None);
    }
);

action_icon_widget!(
    /// A "drawer" icon that's appropriate for the current [`TargetPlatform`].
    ///
    /// The current platform is determined by querying for the ambient `Theme`.
    ///
    /// See also:
    ///
    ///  * [`DrawerButton`], an `IconButton` with a [`DrawerButtonIcon`] that calls
    ///    `ScaffoldState::open_drawer` to open the `Scaffold::drawer`.
    ///  * [`EndDrawerButton`], an `IconButton` with an [`EndDrawerButtonIcon`] that
    ///    calls `ScaffoldState::open_end_drawer` to open the `Scaffold::end_drawer`.
    ///  * `IconButton`, which is a more general widget for creating buttons
    ///    with icons.
    ///  * `Icon`, a Material Design icon.
    ///  * `ThemeData::platform`, which specifies the current platform.
    DrawerButtonIcon,
    builder: drawer_button_icon_builder,
    get_icon: |_app, _context| Icons::menu(),
    android_semantics_label: open_app_drawer_tooltip,
    expanded: scaffold_drawer_expanded_of
);

action_button_widget!(
    /// A Material Design drawer icon button.
    ///
    /// A [`DrawerButton`] is an `IconButton` with a "drawer" icon. When pressed, the
    /// close button calls `ScaffoldState::open_drawer` to the `Scaffold::drawer`.
    ///
    /// The default behaviour on press can be overridden with
    /// [`on_pressed`](Self::on_pressed).
    ///
    /// See also:
    ///
    ///  * [`EndDrawerButton`], an `IconButton` with an [`EndDrawerButtonIcon`] that
    ///    calls `ScaffoldState::open_end_drawer` to open the `Scaffold::end_drawer`.
    ///  * `IconButton`, which is a more general widget for creating buttons
    ///    with icons.
    ///  * `Icon`, a Material Design icon.
    ///  * `ThemeData::platform`, which specifies the current platform.
    DrawerButton,
    icon: DrawerButtonIcon,
    standard_component: Some(StandardComponentType::DrawerButton),
    tooltip: open_app_drawer_tooltip,
    on_pressed: |app, context| {
        Scaffold::of(app, context).open_drawer(app);
    }
);

action_icon_widget!(
    /// A "end drawer" icon that's appropriate for the current [`TargetPlatform`].
    ///
    /// The current platform is determined by querying for the ambient `Theme`.
    ///
    /// See also:
    ///
    ///  * [`DrawerButton`], an `IconButton` with a [`DrawerButtonIcon`] that calls
    ///    `ScaffoldState::open_drawer` to open the `Scaffold::drawer`.
    ///  * [`EndDrawerButton`], an `IconButton` with an [`EndDrawerButtonIcon`] that
    ///    calls `ScaffoldState::open_end_drawer` to open the `Scaffold::end_drawer`
    ///  * `IconButton`, which is a more general widget for creating buttons
    ///    with icons.
    ///  * `Icon`, a Material Design icon.
    ///  * `ThemeData::platform`, which specifies the current platform.
    EndDrawerButtonIcon,
    builder: end_drawer_button_icon_builder,
    get_icon: |_app, _context| Icons::menu(),
    android_semantics_label: open_app_drawer_tooltip,
    expanded: scaffold_end_drawer_expanded_of
);

action_button_widget!(
    /// A Material Design end drawer icon button.
    ///
    /// A [`EndDrawerButton`] is an `IconButton` with a "drawer" icon. When pressed, the
    /// end drawer button calls `ScaffoldState::open_end_drawer` to open the
    /// `Scaffold::end_drawer`.
    ///
    /// The default behaviour on press can be overridden with
    /// [`on_pressed`](Self::on_pressed).
    ///
    /// See also:
    ///
    ///  * [`DrawerButton`], an `IconButton` with a [`DrawerButtonIcon`] that calls
    ///    `ScaffoldState::open_drawer` to open a drawer.
    ///  * `IconButton`, which is a more general widget for creating buttons
    ///    with icons.
    ///  * `Icon`, a Material Design icon.
    ///  * `ThemeData::platform`, which specifies the current platform.
    EndDrawerButton,
    icon: EndDrawerButtonIcon,
    standard_component: None,
    tooltip: open_app_drawer_tooltip,
    on_pressed: |app, context| {
        Scaffold::of(app, context).open_end_drawer(app);
    }
);

#[cfg(test)]
mod tests {
    //! The cases of `back_button_test.dart` and `drawer_button_test.dart` that pin behaviour; the
    //! semantics and the semantics-tree cases wait on accessibility.

    use std::cell::Cell;
    use std::rc::Rc;

    use waft_embedder::{Offset, Size, TargetPlatform};
    use waft_foundation::Handle;
    use waft_services::{MouseCursorRef, SystemMouseCursors};
    use waft_widgets::{
        AnyElement, Builder, Center, Column, GlobalKey, PageRouteBuilder, RoutePageBuilder,
        SizedBox, Text, WidgetStatePropertyAll,
    };

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

    use super::*;
    use crate::colors::Colors;
    use crate::drawer::Drawer;
    use crate::material::Material;
    use crate::scaffold::{Scaffold, ScaffoldState};
    use crate::test_support::material_app;
    use crate::theme::Theme;
    use crate::theme_data::ThemeData;

    fn pump_app(tester: &mut WidgetTester, home: WidgetRef) {
        let root = {
            let app = tester.cell.borrow();
            material_app(ThemeData::new(&app), home)
        };
        tester.pump_widget(root);
    }

    fn app_scaffold(tester: &mut WidgetTester, scaffold: Scaffold) {
        pump_app(tester, scaffold.into_widget());
    }

    fn material<K>(child: impl IntoWidget<K>) -> WidgetRef {
        Material::new().child(child).into_widget()
    }

    fn tap(tester: &mut WidgetTester, element: AnyElement) {
        let center = tester.get_center(element);
        tester.tap_at(center, 1);
    }

    fn only<W: 'static>(tester: &WidgetTester) -> AnyElement {
        let found = find::by_type::<W>().evaluate(tester);
        assert_eq!(found.len(), 1);
        found[0]
    }

    fn counter(count: &Rc<Cell<usize>>) -> Listener {
        let count = Rc::clone(count);
        Listener::new(move |_app| count.set(count.get() + 1))
    }

    fn red_icon_color() -> ButtonStyle {
        ButtonStyle::new().icon_color(Rc::new(WidgetStatePropertyAll::new(Some(
            Colors::RED.primary(),
        ))))
    }

    /// The colour of the glyph the button's `Icon` paints: Dart's `tester.firstWidget<RichText>(
    /// find.descendant(of: find.byType(Button), matching: find.byType(RichText))).text.style!.color`.
    fn glyph_color(tester: &WidgetTester) -> Option<Color> {
        let icon = find::by_type::<Icon>().evaluate(tester)[0];
        tester
            .glyph_style(icon)
            .color
            .as_ref()
            .map(|color| color.color())
    }

    /// The context of the home page, to push a route from.
    #[derive(Clone, Default)]
    struct Home(Rc<Cell<Option<BuildContext>>>);

    impl Home {
        fn page(&self) -> WidgetRef {
            let slot = Rc::clone(&self.0);
            Builder::new(move |_app, context| {
                slot.set(Some(context));
                material(Text::new("Home"))
            })
            .into_widget()
        }

        /// Dart's `navigator.pushNamed('/next')` of a route that builds `next`.
        fn push(&self, tester: &WidgetTester, next: impl Fn() -> WidgetRef + 'static) {
            let mut app = tester.cell.borrow_mut();
            let page_builder: RoutePageBuilder = Rc::new(move |_app, _context, _, _| next());
            let route = PageRouteBuilder::new(&mut app, page_builder);
            let context = self.0.get().expect("the home page built");
            drop(Navigator::push(&mut app, context, route.erase()));
        }
    }

    /// The tester, on the page `next` builds above the home page.
    fn on_next_page(tester: &mut WidgetTester, next: impl Fn() -> WidgetRef + 'static) -> Home {
        let home = Home::default();
        pump_app(tester, home.page());
        home.push(tester, next);
        tester.pump_and_settle();
        home
    }

    fn on_home(tester: &WidgetTester) -> bool {
        !find::text("Home").evaluate(tester).is_empty()
    }

    // 'BackButton control test'
    #[test]
    fn a_back_button_pops_the_route() {
        test_widgets(|tester| {
            let _home = on_next_page(tester, || material(Center::new().child(BackButton::new())));

            let button = only::<BackButton>(tester);
            tap(tester, button);
            tester.pump_and_settle();

            assert_eq!(find::text("Home").evaluate(tester).len(), 1);
        });
    }

    // 'BackButton onPressed overrides default pop behavior'
    #[test]
    fn a_back_buttons_on_pressed_overrides_the_pop() {
        test_widgets(|tester| {
            let calls = Rc::new(Cell::new(0));
            let _home = on_next_page(tester, {
                let calls = Rc::clone(&calls);
                move || material(Center::new().child(BackButton::new().on_pressed(counter(&calls))))
            });

            assert!(!on_home(tester)); // Start off on the second page.
            assert_eq!(calls.get(), 0);
            let button = only::<BackButton>(tester);
            tap(tester, button);
            tester.pump_and_settle();

            // We're still on the second page.
            assert!(!on_home(tester));
            // But the custom callback is called.
            assert_eq!(calls.get(), 1);
        });
    }

    // 'CloseButton onPressed overrides default pop behavior'
    #[test]
    fn a_close_buttons_on_pressed_overrides_the_pop() {
        test_widgets(|tester| {
            let calls = Rc::new(Cell::new(0));
            let _home = on_next_page(tester, {
                let calls = Rc::clone(&calls);
                move || {
                    material(Center::new().child(CloseButton::new().on_pressed(counter(&calls))))
                }
            });

            assert!(!on_home(tester));
            assert_eq!(calls.get(), 0);
            let button = only::<CloseButton>(tester);
            tap(tester, button);
            tester.pump_and_settle();

            assert!(!on_home(tester));
            assert_eq!(calls.get(), 1);
        });
    }

    // The default pop of 'BackButton control test', for the close button.
    #[test]
    fn a_close_button_pops_the_route() {
        test_widgets(|tester| {
            let _home = on_next_page(tester, || material(Center::new().child(CloseButton::new())));

            let button = only::<CloseButton>(tester);
            tap(tester, button);
            tester.pump_and_settle();

            assert_eq!(find::text("Home").evaluate(tester).len(), 1);
        });
    }

    /// The icons of the `Icon`s the tester found, in tree order.
    fn icons(tester: &WidgetTester) -> Vec<Option<IconData>> {
        find::by_type::<Icon>()
            .evaluate(tester)
            .into_iter()
            .map(|element| tester.widget(element, |icon: &Icon| icon.icon.clone()))
            .collect()
    }

    /// Dart's `Theme(data: ThemeData(platform: platform), child: icon)` for the five platforms,
    /// in Dart's order: Android, iOS, Linux, macOS, Windows.
    fn icon_on_each_platform(tester: &mut WidgetTester, icon: impl Fn() -> WidgetRef) {
        let platforms = [
            TargetPlatform::Android,
            TargetPlatform::IOS,
            TargetPlatform::Linux,
            TargetPlatform::MacOS,
            TargetPlatform::Windows,
        ];
        let children: Vec<WidgetRef> = {
            let app = tester.cell.borrow();
            platforms
                .into_iter()
                .map(|platform| {
                    Theme::new(ThemeData::builder().platform(platform).build(&app), icon())
                        .into_widget()
                })
                .collect()
        };
        pump_app(tester, Column::new().children(children).into_widget());
    }

    // 'BackButton icon'
    #[test]
    fn a_back_button_icon_is_the_ios_arrow_on_ios_and_macos() {
        test_widgets(|tester| {
            icon_on_each_platform(tester, || BackButtonIcon::new().into_widget());

            let [android, ios, linux, macos, windows] = &icons(tester)[..] else {
                panic!("one icon for each platform");
            };
            assert_eq!(ios == android, K_IS_WEB);
            assert!(linux == android);
            assert_eq!(macos == android, K_IS_WEB);
            assert!(macos == ios);
            assert!(windows == android);
        });
    }

    // 'DrawerButton icon'
    #[test]
    fn a_drawer_button_icon_is_the_same_on_every_platform() {
        test_widgets(|tester| {
            icon_on_each_platform(tester, || DrawerButtonIcon::new().into_widget());

            let icons = icons(tester);
            assert!(icons.iter().all(|icon| *icon == icons[0]));
            assert_eq!(icons[0], Some(Icons::menu()));
        });
    }

    // The platform choice of `CloseButtonIcon` and `EndDrawerButtonIcon`.
    #[test]
    fn a_close_icon_and_an_end_drawer_icon_are_the_same_on_every_platform() {
        test_widgets(|tester| {
            icon_on_each_platform(tester, || CloseButtonIcon::new().into_widget());
            let close_icons = icons(tester);
            assert!(close_icons.iter().all(|icon| *icon == Some(Icons::close())));

            icon_on_each_platform(tester, || EndDrawerButtonIcon::new().into_widget());
            let end_drawer_icons = icons(tester);
            assert!(
                end_drawer_icons
                    .iter()
                    .all(|icon| *icon == Some(Icons::menu()))
            );
        });
    }

    // The tooltip each button gives its `IconButton`, which Dart's semantics cases read as
    // 'Back', 'Close' and 'Open navigation menu'.
    #[test]
    fn each_action_button_gives_its_icon_button_the_localized_tooltip() {
        test_widgets(|tester| {
            let buttons: Vec<WidgetRef> = vec![
                BackButton::new().into_widget(),
                CloseButton::new().into_widget(),
                DrawerButton::new().into_widget(),
                EndDrawerButton::new().into_widget(),
            ];
            pump_app(tester, material(Column::new().children(buttons)));

            let tooltips: Vec<Option<String>> = find::by_type::<IconButton>()
                .evaluate(tester)
                .into_iter()
                .map(|element| tester.widget(element, |button: &IconButton| button.tooltip.clone()))
                .collect();
            assert_eq!(
                tooltips,
                vec![
                    Some("Back".to_string()),
                    Some("Close".to_string()),
                    Some("Open navigation menu".to_string()),
                    Some("Open navigation menu".to_string()),
                ]
            );
        });
    }

    // The keys that mark a standard component, which each button gives its `IconButton`.
    #[test]
    fn action_buttons_mark_their_icon_button_as_a_standard_component() {
        test_widgets(|tester| {
            let buttons: Vec<WidgetRef> = vec![
                BackButton::new().into_widget(),
                CloseButton::new().into_widget(),
                DrawerButton::new().into_widget(),
                EndDrawerButton::new().into_widget(),
            ];
            pump_app(tester, material(Column::new().children(buttons)));

            let keys: Vec<Option<KeyRef>> = find::by_type::<IconButton>()
                .evaluate(tester)
                .into_iter()
                .map(|element| tester.widget(element, |button: &IconButton| button.key.clone()))
                .collect();
            assert_eq!(
                keys,
                vec![
                    Some(StandardComponentType::BackButton.key()),
                    Some(StandardComponentType::CloseButton.key()),
                    Some(StandardComponentType::DrawerButton.key()),
                    None,
                ]
            );
        });
    }

    /// Dart's `MaterialApp(home: Material(child: button))` with the glyph colour read back.
    fn glyph_color_of<K>(tester: &mut WidgetTester, button: impl IntoWidget<K>) -> Option<Color> {
        pump_app(tester, material(button));
        glyph_color(tester)
    }

    // 'BackButton color'
    #[test]
    fn a_back_buttons_color_colors_its_icon() {
        test_widgets(|tester| {
            assert_eq!(
                glyph_color_of(tester, BackButton::new().color(Colors::RED.primary())),
                Some(Colors::RED.primary())
            );
        });
    }

    // 'BackButton color with ButtonStyle'
    #[test]
    fn a_back_buttons_style_icon_color_colors_its_icon() {
        test_widgets(|tester| {
            assert_eq!(
                glyph_color_of(tester, BackButton::new().style(red_icon_color())),
                Some(Colors::RED.primary())
            );
        });
    }

    // 'BackButton.style.iconColor parameter overrides BackButton.color'
    #[test]
    fn a_back_buttons_style_icon_color_overrides_its_color() {
        test_widgets(|tester| {
            assert_eq!(
                glyph_color_of(
                    tester,
                    BackButton::new()
                        .color(Colors::GREEN.primary())
                        .style(red_icon_color())
                ),
                Some(Colors::RED.primary())
            );
        });
    }

    // 'CloseButton color'
    #[test]
    fn a_close_buttons_color_colors_its_icon() {
        test_widgets(|tester| {
            assert_eq!(
                glyph_color_of(tester, CloseButton::new().color(Colors::RED.primary())),
                Some(Colors::RED.primary())
            );
        });
    }

    // 'CloseButton color with ButtonStyle'
    #[test]
    fn a_close_buttons_style_icon_color_colors_its_icon() {
        test_widgets(|tester| {
            assert_eq!(
                glyph_color_of(tester, CloseButton::new().style(red_icon_color())),
                Some(Colors::RED.primary())
            );
        });
    }

    // 'CloseButton.style.iconColor parameter overrides CloseButton.color'
    #[test]
    fn a_close_buttons_style_icon_color_overrides_its_color() {
        test_widgets(|tester| {
            assert_eq!(
                glyph_color_of(
                    tester,
                    CloseButton::new()
                        .color(Colors::GREEN.primary())
                        .style(red_icon_color())
                ),
                Some(Colors::RED.primary())
            );
        });
    }

    // 'DrawerButton color'
    #[test]
    fn a_drawer_buttons_color_colors_its_icon() {
        test_widgets(|tester| {
            assert_eq!(
                glyph_color_of(tester, DrawerButton::new().color(Colors::RED.primary())),
                Some(Colors::RED.primary())
            );
        });
    }

    // 'DrawerButton color with ButtonStyle'
    #[test]
    fn a_drawer_buttons_style_icon_color_colors_its_icon() {
        test_widgets(|tester| {
            assert_eq!(
                glyph_color_of(tester, DrawerButton::new().style(red_icon_color())),
                Some(Colors::RED.primary())
            );
        });
    }

    // 'EndDrawerButton color'
    #[test]
    fn an_end_drawer_buttons_color_colors_its_icon() {
        test_widgets(|tester| {
            assert_eq!(
                glyph_color_of(tester, EndDrawerButton::new().color(Colors::RED.primary())),
                Some(Colors::RED.primary())
            );
        });
    }

    // 'EndDrawerButton color with ButtonStyle'
    #[test]
    fn an_end_drawer_buttons_style_icon_color_colors_its_icon() {
        test_widgets(|tester| {
            assert_eq!(
                glyph_color_of(tester, EndDrawerButton::new().style(red_icon_color())),
                Some(Colors::RED.primary())
            );
        });
    }

    // 'DrawerButton control test'
    #[test]
    fn a_drawer_button_opens_the_drawer() {
        test_widgets(|tester| {
            app_scaffold(
                tester,
                Scaffold::new()
                    .body(DrawerButton::new())
                    .drawer(Drawer::new()),
            );
            tester.pump_and_settle();

            assert!(find::by_type::<Drawer>().evaluate(tester).is_empty());

            let button = only::<DrawerButton>(tester);
            tap(tester, button);
            tester.pump_and_settle();

            assert_eq!(find::by_type::<Drawer>().evaluate(tester).len(), 1);
        });
    }

    // 'EndDrawerButton control test'
    #[test]
    fn an_end_drawer_button_opens_the_end_drawer() {
        test_widgets(|tester| {
            app_scaffold(
                tester,
                Scaffold::new()
                    .body(EndDrawerButton::new())
                    .end_drawer(Drawer::new()),
            );
            tester.pump_and_settle();

            assert!(find::by_type::<Drawer>().evaluate(tester).is_empty());

            let button = only::<EndDrawerButton>(tester);
            tap(tester, button);
            tester.pump_and_settle();

            assert_eq!(find::by_type::<Drawer>().evaluate(tester).len(), 1);
        });
    }

    // 'DrawerButton onPressed overrides default end drawer open behaviour'
    #[test]
    fn a_drawer_buttons_on_pressed_overrides_opening_the_drawer() {
        test_widgets(|tester| {
            let calls = Rc::new(Cell::new(0));
            app_scaffold(
                tester,
                Scaffold::new()
                    .body(Center::new().child(DrawerButton::new().on_pressed(counter(&calls))))
                    .drawer(Drawer::new()),
            );
            tester.pump_and_settle();

            assert!(find::by_type::<Drawer>().evaluate(tester).is_empty());
            assert_eq!(calls.get(), 0);
            let button = only::<DrawerButton>(tester);
            tap(tester, button);
            tester.pump_and_settle();

            // Drawer is still closed
            assert!(find::by_type::<Drawer>().evaluate(tester).is_empty());
            // The custom callback is called.
            assert_eq!(calls.get(), 1);
        });
    }

    // 'EndDrawerButton onPressed overrides default end drawer open behaviour'
    #[test]
    fn an_end_drawer_buttons_on_pressed_overrides_opening_the_end_drawer() {
        test_widgets(|tester| {
            let calls = Rc::new(Cell::new(0));
            app_scaffold(
                tester,
                Scaffold::new()
                    .body(Center::new().child(EndDrawerButton::new().on_pressed(counter(&calls))))
                    .end_drawer(Drawer::new()),
            );
            tester.pump_and_settle();

            assert!(find::by_type::<Drawer>().evaluate(tester).is_empty());
            assert_eq!(calls.get(), 0);
            let button = only::<EndDrawerButton>(tester);
            tap(tester, button);
            tester.pump_and_settle();

            assert!(find::by_type::<Drawer>().evaluate(tester).is_empty());
            assert_eq!(calls.get(), 1);
        });
    }

    /// A scaffold with both drawers and both drawer buttons in its body.
    fn scaffold_with_both_drawers(
        tester: &mut WidgetTester,
        buttons: Vec<WidgetRef>,
    ) -> Handle<ScaffoldState> {
        let key = GlobalKey::new();
        app_scaffold(
            tester,
            Scaffold::new()
                .key(key.clone().into())
                .body(Center::new().child(Column::new().children(buttons)))
                .drawer(Drawer::new())
                .end_drawer(Drawer::new()),
        );
        tester.pump_and_settle();
        key.current_state::<ScaffoldState>(&tester.cell.borrow_mut())
            .expect("a mounted scaffold")
    }

    // The `openDrawer` each drawer button calls, against the scaffold's state.
    #[test]
    fn a_drawer_button_opens_only_the_drawer() {
        test_widgets(|tester| {
            let state = scaffold_with_both_drawers(
                tester,
                vec![
                    EndDrawerButton::new().into_widget(),
                    DrawerButton::new().into_widget(),
                ],
            );

            let button = only::<DrawerButton>(tester);
            tap(tester, button);
            tester.pump_and_settle();

            assert!(state.is_drawer_open(&tester.cell.borrow()));
            assert!(!state.is_end_drawer_open(&tester.cell.borrow()));
        });
    }

    // The `openEndDrawer` each drawer button calls, against the scaffold's state.
    #[test]
    fn an_end_drawer_button_opens_only_the_end_drawer() {
        test_widgets(|tester| {
            let state = scaffold_with_both_drawers(
                tester,
                vec![
                    DrawerButton::new().into_widget(),
                    EndDrawerButton::new().into_widget(),
                ],
            );

            let button = only::<EndDrawerButton>(tester);
            tap(tester, button);
            tester.pump_and_settle();

            assert!(!state.is_drawer_open(&tester.cell.borrow()));
            assert!(state.is_end_drawer_open(&tester.cell.borrow()));
        });
    }

    /// Dart's `MaterialApp(home: Center(child: SizedBox.shrink(child: Scaffold(body: button))))`.
    fn size_at_zero_area<W: 'static, K>(
        tester: &mut WidgetTester,
        button: impl IntoWidget<K>,
    ) -> Size {
        pump_app(
            tester,
            Center::new()
                .child(SizedBox::shrink().child(Scaffold::new().body(button)))
                .into_widget(),
        );
        let element = only::<W>(tester);
        tester.get_size(element)
    }

    // 'EndDrawerButton does not crash at zero area'
    #[test]
    fn an_end_drawer_button_has_no_size_at_zero_area() {
        test_widgets(|tester| {
            assert_eq!(
                size_at_zero_area::<EndDrawerButton, _>(tester, EndDrawerButton::new()),
                Size::ZERO
            );
        });
    }

    // 'CloseButton does not crash at zero area'
    #[test]
    fn a_close_button_has_no_size_at_zero_area() {
        test_widgets(|tester| {
            assert_eq!(
                size_at_zero_area::<CloseButton, _>(tester, CloseButton::new()),
                Size::ZERO
            );
        });
    }

    // 'DrawerButton does not crash at zero area'
    #[test]
    fn a_drawer_button_has_no_size_at_zero_area() {
        test_widgets(|tester| {
            assert_eq!(
                size_at_zero_area::<DrawerButton, _>(tester, DrawerButton::new()),
                Size::ZERO
            );
        });
    }

    // 'BackButton renders at zero area'
    #[test]
    fn a_back_button_icon_is_empty_at_zero_area() {
        test_widgets(|tester| {
            let _ = size_at_zero_area::<BackButton, _>(tester, BackButton::new());
            pump_app(
                tester,
                Center::new()
                    .child(SizedBox::shrink().child(Scaffold::new().body(BackButton::new())))
                    .into_widget(),
            );
            let icon = only::<BackButtonIcon>(tester);
            let size = tester.get_size(icon);
            assert!(size.is_empty());
        });
    }

    /// The cursor under a mouse the tester moved onto the centre of the button.
    fn cursor_over<W: 'static, K>(
        tester: &mut WidgetTester,
        button: impl IntoWidget<K>,
    ) -> MouseCursorRef {
        pump_app(tester, material(button));
        let mut mouse = TestPointer::mouse(1, 0);
        tester.add_pointer(&mut mouse, Offset::new(1000.0, 1000.0));
        let center = tester.get_center(only::<W>(tester));
        tester.move_to(&mut mouse, center, false);
        tester.pump_by(std::time::Duration::ZERO);
        tester.active_cursor(1)
    }

    fn default_cursor() -> MouseCursorRef {
        if K_IS_WEB {
            SystemMouseCursors::CLICK.into()
        } else {
            SystemMouseCursors::BASIC.into()
        }
    }

    fn cell_cursor_style() -> ButtonStyle {
        let cell: MouseCursorRef = SystemMouseCursors::CELL.into();
        ButtonStyle::new().mouse_cursor(Rc::new(WidgetStatePropertyAll::new(Some(cell))))
    }

    // 'BackButton has expected default mouse cursor on hover'
    #[test]
    fn a_back_button_has_the_default_mouse_cursor_on_hover() {
        test_widgets(|tester| {
            assert!(*cursor_over::<BackButton, _>(tester, BackButton::new()) == *default_cursor());
        });
    }

    // 'CloseButton has expected default mouse cursor on hover'
    #[test]
    fn a_close_button_has_the_default_mouse_cursor_on_hover() {
        test_widgets(|tester| {
            assert!(
                *cursor_over::<CloseButton, _>(tester, CloseButton::new()) == *default_cursor()
            );
        });
    }

    // 'DrawerButton has expected default mouse cursor on hover'
    #[test]
    fn a_drawer_button_has_the_default_mouse_cursor_on_hover() {
        test_widgets(|tester| {
            assert!(
                *cursor_over::<DrawerButton, _>(tester, DrawerButton::new()) == *default_cursor()
            );
        });
    }

    // 'EndDrawerButton has expected default mouse cursor on hover'
    #[test]
    fn an_end_drawer_button_has_the_default_mouse_cursor_on_hover() {
        test_widgets(|tester| {
            assert!(
                *cursor_over::<EndDrawerButton, _>(tester, EndDrawerButton::new())
                    == *default_cursor()
            );
        });
    }

    // 'BackButton has expected mouse cursor when explicitly configured'
    #[test]
    fn a_back_button_uses_the_mouse_cursor_its_style_gives() {
        test_widgets(|tester| {
            let cell: MouseCursorRef = SystemMouseCursors::CELL.into();
            assert!(
                *cursor_over::<BackButton, _>(tester, BackButton::new().style(cell_cursor_style()))
                    == *cell
            );
        });
    }

    // 'CloseButton has expected mouse cursor when explicitly configured'
    #[test]
    fn a_close_button_uses_the_mouse_cursor_its_style_gives() {
        test_widgets(|tester| {
            let cell: MouseCursorRef = SystemMouseCursors::CELL.into();
            assert!(
                *cursor_over::<CloseButton, _>(
                    tester,
                    CloseButton::new().style(cell_cursor_style())
                ) == *cell
            );
        });
    }

    // 'DrawerButton has expected mouse cursor when explicitly configured'
    #[test]
    fn a_drawer_button_uses_the_mouse_cursor_its_style_gives() {
        test_widgets(|tester| {
            let cell: MouseCursorRef = SystemMouseCursors::CELL.into();
            assert!(
                *cursor_over::<DrawerButton, _>(
                    tester,
                    DrawerButton::new().style(cell_cursor_style())
                ) == *cell
            );
        });
    }

    // 'EndDrawerButton has expected mouse cursor when explicitly configured'
    #[test]
    fn an_end_drawer_button_uses_the_mouse_cursor_its_style_gives() {
        test_widgets(|tester| {
            let cell: MouseCursorRef = SystemMouseCursors::CELL.into();
            assert!(
                *cursor_over::<EndDrawerButton, _>(
                    tester,
                    EndDrawerButton::new().style(cell_cursor_style())
                ) == *cell
            );
        });
    }
}