Skip to main content

waft_material/
popup_menu_theme.rs

1//! Flutter counterpart: material_ui's `popup_menu_theme.dart`.
2
3use waft_embedder::{Color, lerp_double};
4use waft_foundation::{App, DiagnosticsProperty, DoubleProperty, EnumProperty};
5use waft_painting::{ColorProperty, EdgeInsetsGeometry, ShapeBorderRef, TextStyle};
6use waft_services::MouseCursorRef;
7use waft_widgets::{
8    BuildContext, InheritedTheme, InheritedWidget, IntoWidget, KeyRef, WidgetRef,
9    WidgetStateProperty, WidgetStatePropertyRef,
10};
11
12use crate::theme::Theme;
13
14/// Used to configure how the `PopupMenuButton` positions its popup menu.
15#[derive(Clone, Copy, Debug, PartialEq, Eq)]
16pub enum PopupMenuPosition {
17    /// Menu is positioned over the anchor.
18    Over,
19
20    /// Menu is positioned under the anchor.
21    Under,
22}
23
24/// Defines the visual properties of the routes used to display popup menus
25/// as well as `PopupMenuItem` and `PopupMenuDivider` widgets.
26///
27/// Descendant widgets obtain the current [`PopupMenuThemeData`] object
28/// using [`PopupMenuTheme::of`]. Instances of [`PopupMenuThemeData`] can be
29/// customized with [`PopupMenuThemeData::copy_with`].
30///
31/// Typically, a [`PopupMenuThemeData`] is specified as part of the
32/// overall `Theme` with `ThemeData::popup_menu_theme`. Otherwise,
33/// [`PopupMenuTheme`] can be used to configure its own widget subtree.
34///
35/// All [`PopupMenuThemeData`] properties are `null` by default.
36/// If any of these properties are null, the popup menu will provide its
37/// own defaults.
38///
39/// See also:
40///
41///  * `ThemeData`, which describes the overall theme information for the
42///    application.
43#[derive(Clone, Debug, Default)]
44pub struct PopupMenuThemeData {
45    /// The background color of the popup menu.
46    pub color: Option<Color>,
47
48    /// The shape of the popup menu.
49    pub shape: Option<ShapeBorderRef>,
50
51    /// If specified, the padding of the popup menu.
52    ///
53    /// If `PopupMenuButton::menu_padding` is provided, [`menu_padding`](Self::menu_padding) is
54    /// ignored.
55    pub menu_padding: Option<EdgeInsetsGeometry>,
56
57    /// The elevation of the popup menu.
58    pub elevation: Option<f64>,
59
60    /// The color used to paint shadow below the popup menu.
61    pub shadow_color: Option<Color>,
62
63    /// The color used as an overlay on [`color`](Self::color) of the popup menu.
64    pub surface_tint_color: Option<Color>,
65
66    /// The text style of items in the popup menu.
67    pub text_style: Option<TextStyle>,
68
69    /// You can use this to specify a different style of the label
70    /// when the popup menu item is enabled and disabled.
71    pub label_text_style: Option<WidgetStatePropertyRef<Option<TextStyle>>>,
72
73    /// If specified, defines the feedback property for `PopupMenuButton`.
74    ///
75    /// If `PopupMenuButton::enable_feedback` is provided,
76    /// [`enable_feedback`](Self::enable_feedback) is ignored.
77    pub enable_feedback: Option<bool>,
78
79    /// {@macro material_ui.popupmenu.mouseCursor}
80    ///
81    /// If specified, overrides the default value of `PopupMenuItem::mouse_cursor`.
82    pub mouse_cursor: Option<WidgetStatePropertyRef<Option<MouseCursorRef>>>,
83
84    /// Whether the popup menu is positioned over or under the popup menu button.
85    ///
86    /// When not set, the position defaults to [`PopupMenuPosition::Over`] which makes the
87    /// popup menu appear directly over the button that was used to create it.
88    pub position: Option<PopupMenuPosition>,
89
90    /// The color of the icon in the popup menu button.
91    pub icon_color: Option<Color>,
92
93    /// The size of the icon in the popup menu button.
94    pub icon_size: Option<f64>,
95}
96
97crate::theme_data_getters::theme_data_getters! {
98    /// Dart's getters of `PopupMenuThemeData`: the theme data answers with its fields, and a defaults
99    /// subclass (Dart's `_...Defaults...(context)`) computes the ones it overrides when they
100    /// are read.
101    pub trait PopupMenuThemeDataGetters for PopupMenuThemeData, fields: popup_menu_theme_data {
102        color: Option<Color>,
103        shape: Option<ShapeBorderRef>,
104        menu_padding: Option<EdgeInsetsGeometry>,
105        elevation: Option<f64>,
106        shadow_color: Option<Color>,
107        surface_tint_color: Option<Color>,
108        text_style: Option<TextStyle>,
109        label_text_style: Option<WidgetStatePropertyRef<Option<TextStyle>>>,
110        enable_feedback: Option<bool>,
111        mouse_cursor: Option<WidgetStatePropertyRef<Option<MouseCursorRef>>>,
112        position: Option<PopupMenuPosition>,
113        icon_color: Option<Color>,
114        icon_size: Option<f64>,
115    }
116}
117
118impl PopupMenuThemeData {
119    /// Creates the set of properties used to configure [`PopupMenuTheme`].
120    pub fn new() -> PopupMenuThemeData {
121        PopupMenuThemeData::default()
122    }
123
124    /// Dart `PopupMenuThemeData(color:)`.
125    pub fn color(mut self, color: Color) -> PopupMenuThemeData {
126        self.color = Some(color);
127        self
128    }
129
130    /// Dart `PopupMenuThemeData(shape:)`.
131    pub fn shape(mut self, shape: impl Into<ShapeBorderRef>) -> PopupMenuThemeData {
132        self.shape = Some(shape.into());
133        self
134    }
135
136    /// Dart `PopupMenuThemeData(menuPadding:)`.
137    pub fn menu_padding(
138        mut self,
139        menu_padding: impl Into<EdgeInsetsGeometry>,
140    ) -> PopupMenuThemeData {
141        let menu_padding = menu_padding.into();
142        self.menu_padding = Some(menu_padding);
143        self
144    }
145
146    /// Dart `PopupMenuThemeData(elevation:)`.
147    pub fn elevation(mut self, elevation: f64) -> PopupMenuThemeData {
148        self.elevation = Some(elevation);
149        self
150    }
151
152    /// Dart `PopupMenuThemeData(shadowColor:)`.
153    pub fn shadow_color(mut self, shadow_color: Color) -> PopupMenuThemeData {
154        self.shadow_color = Some(shadow_color);
155        self
156    }
157
158    /// Dart `PopupMenuThemeData(surfaceTintColor:)`.
159    pub fn surface_tint_color(mut self, surface_tint_color: Color) -> PopupMenuThemeData {
160        self.surface_tint_color = Some(surface_tint_color);
161        self
162    }
163
164    /// Dart `PopupMenuThemeData(textStyle:)`.
165    pub fn text_style(mut self, text_style: TextStyle) -> PopupMenuThemeData {
166        self.text_style = Some(text_style);
167        self
168    }
169
170    /// Dart `PopupMenuThemeData(labelTextStyle:)`.
171    pub fn label_text_style(
172        mut self,
173        label_text_style: WidgetStatePropertyRef<Option<TextStyle>>,
174    ) -> PopupMenuThemeData {
175        self.label_text_style = Some(label_text_style);
176        self
177    }
178
179    /// Dart `PopupMenuThemeData(enableFeedback:)`.
180    pub fn enable_feedback(mut self, enable_feedback: bool) -> PopupMenuThemeData {
181        self.enable_feedback = Some(enable_feedback);
182        self
183    }
184
185    /// Dart `PopupMenuThemeData(mouseCursor:)`.
186    pub fn mouse_cursor(
187        mut self,
188        mouse_cursor: WidgetStatePropertyRef<Option<MouseCursorRef>>,
189    ) -> PopupMenuThemeData {
190        self.mouse_cursor = Some(mouse_cursor);
191        self
192    }
193
194    /// Dart `PopupMenuThemeData(position:)`.
195    pub fn position(mut self, position: PopupMenuPosition) -> PopupMenuThemeData {
196        self.position = Some(position);
197        self
198    }
199
200    /// Dart `PopupMenuThemeData(iconColor:)`.
201    pub fn icon_color(mut self, icon_color: Color) -> PopupMenuThemeData {
202        self.icon_color = Some(icon_color);
203        self
204    }
205
206    /// Dart `PopupMenuThemeData(iconSize:)`.
207    pub fn icon_size(mut self, icon_size: f64) -> PopupMenuThemeData {
208        self.icon_size = Some(icon_size);
209        self
210    }
211
212    /// Creates a copy of this object with the given fields replaced with the
213    /// new values.
214    ///
215    /// Dart's named arguments are the fluent setters on the copy
216    /// (`data.copy_with().elevation(2.0)`).
217    pub fn copy_with(&self) -> PopupMenuThemeData {
218        self.clone()
219    }
220
221    /// Linearly interpolate between two popup menu themes.
222    ///
223    /// If both arguments are null, then null is returned.
224    ///
225    /// {@macro dart.ui.shadow.lerp}
226    pub fn lerp(
227        a: Option<&PopupMenuThemeData>,
228        b: Option<&PopupMenuThemeData>,
229        t: f64,
230    ) -> Option<PopupMenuThemeData> {
231        match (a, b) {
232            (None, None) => return None,
233            (Some(a), Some(b)) if std::ptr::eq(a, b) => return Some(a.clone()),
234            _ => {}
235        }
236        Some(PopupMenuThemeData {
237            color: Color::lerp(a.and_then(|a| a.color), b.and_then(|b| b.color), t),
238            shape: ShapeBorderRef::lerp(
239                a.and_then(|a| a.shape.as_ref()),
240                b.and_then(|b| b.shape.as_ref()),
241                t,
242            ),
243            menu_padding: EdgeInsetsGeometry::lerp(
244                a.and_then(|a| a.menu_padding),
245                b.and_then(|b| b.menu_padding),
246                t,
247            ),
248            elevation: lerp_double(a.and_then(|a| a.elevation), b.and_then(|b| b.elevation), t),
249            shadow_color: Color::lerp(
250                a.and_then(|a| a.shadow_color),
251                b.and_then(|b| b.shadow_color),
252                t,
253            ),
254            surface_tint_color: Color::lerp(
255                a.and_then(|a| a.surface_tint_color),
256                b.and_then(|b| b.surface_tint_color),
257                t,
258            ),
259            text_style: TextStyle::lerp(
260                a.and_then(|a| a.text_style.as_ref()),
261                b.and_then(|b| b.text_style.as_ref()),
262                t,
263            ),
264            label_text_style: <dyn WidgetStateProperty<Option<TextStyle>>>::lerp_optional(
265                a.and_then(|a| a.label_text_style.clone()),
266                b.and_then(|b| b.label_text_style.clone()),
267                t,
268                |a, b, t| TextStyle::lerp(a.as_ref(), b.as_ref(), t),
269            ),
270            enable_feedback: pick(a, b, t, |theme| theme.enable_feedback),
271            mouse_cursor: pick(a, b, t, |theme| theme.mouse_cursor.clone()),
272            position: pick(a, b, t, |theme| theme.position),
273            icon_color: Color::lerp(
274                a.and_then(|a| a.icon_color),
275                b.and_then(|b| b.icon_color),
276                t,
277            ),
278            icon_size: lerp_double(a.and_then(|a| a.icon_size), b.and_then(|b| b.icon_size), t),
279        })
280    }
281}
282
283/// Dart's `t < 0.5 ? a?.field : b?.field`.
284fn pick<T>(
285    a: Option<&PopupMenuThemeData>,
286    b: Option<&PopupMenuThemeData>,
287    t: f64,
288    field: impl Fn(&PopupMenuThemeData) -> Option<T>,
289) -> Option<T> {
290    if t < 0.5 {
291        a.and_then(&field)
292    } else {
293        b.and_then(&field)
294    }
295}
296
297impl PartialEq for PopupMenuThemeData {
298    fn eq(&self, other: &PopupMenuThemeData) -> bool {
299        if std::ptr::eq(self, other) {
300            return true;
301        }
302        other.color == self.color
303            && other.shape == self.shape
304            && other.menu_padding == self.menu_padding
305            && other.elevation == self.elevation
306            && other.shadow_color == self.shadow_color
307            && other.surface_tint_color == self.surface_tint_color
308            && other.text_style == self.text_style
309            && other.label_text_style == self.label_text_style
310            && other.enable_feedback == self.enable_feedback
311            && other.mouse_cursor == self.mouse_cursor
312            && other.position == self.position
313            && other.icon_color == self.icon_color
314            && other.icon_size == self.icon_size
315    }
316}
317
318/// An inherited widget that defines the configuration for
319/// popup menus in this widget's subtree.
320///
321/// Values specified here are used for popup menu properties that are not
322/// given an explicit non-null value.
323#[derive(Debug)]
324pub struct PopupMenuTheme {
325    pub key: Option<KeyRef>,
326    /// The properties for descendant popup menu widgets.
327    pub data: PopupMenuThemeData,
328    pub child: WidgetRef,
329}
330
331impl PopupMenuTheme {
332    /// Creates a popup menu theme that controls the configurations for
333    /// popup menus in its widget subtree.
334    #[cfg_attr(debug_assertions, track_caller)]
335    pub fn new<K>(data: PopupMenuThemeData, child: impl IntoWidget<K>) -> PopupMenuTheme {
336        PopupMenuTheme {
337            key: None,
338            data,
339            child: child.into_widget(),
340        }
341    }
342
343    /// Dart `PopupMenuTheme(key:)`.
344    pub fn key(mut self, key: KeyRef) -> PopupMenuTheme {
345        self.key = Some(key);
346        self
347    }
348
349    /// The closest instance of this class's [`data`](Self::data) value that encloses the given
350    /// context. If there is no ancestor, it returns `ThemeData::popup_menu_theme`.
351    /// Applications can assume that the returned value will not be null.
352    ///
353    /// Typical usage is as follows:
354    ///
355    /// ```text
356    /// let theme = PopupMenuTheme::of(app, context);
357    /// ```
358    pub fn of(app: &mut App, context: BuildContext) -> PopupMenuThemeData {
359        match context.depend_on_inherited_widget_of_exact_type::<PopupMenuTheme>(app) {
360            Some(popup_menu_theme) => popup_menu_theme.data.clone(),
361            None => Theme::of(app, context).popup_menu_theme.clone(),
362        }
363    }
364}
365
366impl InheritedTheme for PopupMenuTheme {
367    fn wrap(&self, _app: &mut App, _context: BuildContext, child: WidgetRef) -> WidgetRef {
368        PopupMenuTheme::new(self.data.clone(), child).into_widget()
369    }
370}
371
372impl InheritedWidget for PopupMenuTheme {
373    fn key(&self) -> Option<&KeyRef> {
374        self.key.as_ref()
375    }
376
377    fn child(&self) -> &WidgetRef {
378        &self.child
379    }
380
381    fn update_should_notify(&self, old_widget: &PopupMenuTheme) -> bool {
382        self.data != old_widget.data
383    }
384
385    fn as_inherited_theme(&self) -> Option<&dyn InheritedTheme> {
386        Some(self)
387    }
388}
389
390impl waft_foundation::Diagnosticable for PopupMenuThemeData {
391    fn debug_fill_properties(&self, properties: &mut waft_foundation::DiagnosticPropertiesBuilder) {
392        properties.add(ColorProperty::new("color", self.color).default_value(None));
393        properties.add(
394            DiagnosticsProperty::<ShapeBorderRef>::new("shape", self.shape.clone())
395                .default_value(None),
396        );
397        properties.add(
398            DiagnosticsProperty::<EdgeInsetsGeometry>::new("menuPadding", self.menu_padding)
399                .default_value(None),
400        );
401        properties.add(DoubleProperty::new("elevation", self.elevation).default_value(None));
402        properties.add(ColorProperty::new("shadowColor", self.shadow_color).default_value(None));
403        properties.add(
404            ColorProperty::new("surfaceTintColor", self.surface_tint_color).default_value(None),
405        );
406        properties.add(
407            DiagnosticsProperty::<TextStyle>::new("text style", self.text_style.clone())
408                .default_value(None),
409        );
410        properties.add(
411            DiagnosticsProperty::<String>::new(
412                "labelTextStyle",
413                self.label_text_style
414                    .as_deref()
415                    .map(|property| property.to_string()),
416            )
417            .default_value(None),
418        );
419        properties.add(
420            DiagnosticsProperty::<bool>::new("enableFeedback", self.enable_feedback)
421                .default_value(None),
422        );
423        properties.add(
424            DiagnosticsProperty::<String>::new(
425                "mouseCursor",
426                self.mouse_cursor
427                    .as_deref()
428                    .map(|property| property.to_string()),
429            )
430            .default_value(None),
431        );
432        properties.add(
433            EnumProperty::<PopupMenuPosition>::new("position", self.position).default_value(None),
434        );
435        properties.add(ColorProperty::new("iconColor", self.icon_color).default_value(None));
436        properties.add(DoubleProperty::new("iconSize", self.icon_size).default_value(None));
437    }
438}
439
440impl std::fmt::Display for PopupMenuThemeData {
441    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
442        f.write_str(&waft_foundation::Diagnosticable::to_string(self))
443    }
444}
445
446#[cfg(test)]
447mod tests {
448    //! Ported from `test/popup_menu_theme_test.dart`; the `debugFillProperties` cases wait
449    //! for diagnostics, and `hashCode` for `Hash`.
450
451    use waft_embedder::{Offset, Radius, Size};
452    use waft_painting::{
453        BeveledRectangleBorder, BorderRadiusGeometry, BorderSide, RoundedRectangleBorder,
454    };
455    use waft_services::{SystemMouseCursor, SystemMouseCursors};
456    use waft_widgets::{
457        AnyElement, Column, DefaultTextStyle, GlobalKey, Padding, SingleChildScrollView, Text,
458        WidgetState, WidgetStates,
459    };
460
461    use waft_widgets::testing::{TestPointer, WidgetTester, find, test_widgets};
462
463    use super::*;
464    use crate::colors::Colors;
465    use crate::icons::Icons;
466    use crate::list_tile::ListTile;
467    use crate::material::Material;
468    use crate::popup_menu::{
469        CheckedPopupMenuItem, PopupMenuButton, PopupMenuDivider, PopupMenuEntryRef, PopupMenuItem,
470    };
471    use crate::theme_data::ThemeData;
472    use crate::tooltip::tests::{m2, m3, pump_app};
473
474    /// Builds `wrap(probe)` and returns what `read` saw at the probe's context.
475    fn probe<T: 'static>(
476        tester: &mut WidgetTester,
477        wrap: impl FnOnce(&App, WidgetRef) -> WidgetRef,
478        read: impl Fn(&mut App, BuildContext) -> T + 'static,
479    ) -> T {
480        let seen = std::rc::Rc::new(std::cell::RefCell::new(None));
481        let probe = waft_widgets::Builder::new({
482            let seen = std::rc::Rc::clone(&seen);
483            move |app, context| {
484                *seen.borrow_mut() = Some(read(app, context));
485                waft_widgets::SizedBox::shrink().into_widget()
486            }
487        })
488        .into_widget();
489        let root = wrap(&tester.cell.borrow(), probe);
490        tester.pump_widget(root);
491        let value = seen.borrow_mut().take();
492        value.expect("the probe built")
493    }
494
495    fn cursor_resolver() -> WidgetStatePropertyRef<Option<MouseCursorRef>> {
496        <dyn WidgetStateProperty<Option<MouseCursorRef>>>::resolve_with(|states| {
497            if states.contains(&WidgetState::Disabled) {
498                return Some(SystemMouseCursors::CONTEXT_MENU.into());
499            }
500            Some(SystemMouseCursors::ALIAS.into())
501        })
502    }
503
504    /// Dart's `_popupMenuThemeM2()`.
505    fn popup_menu_theme_m2() -> PopupMenuThemeData {
506        PopupMenuThemeData::new()
507            .color(Colors::ORANGE.primary())
508            .shape(BeveledRectangleBorder::new(
509                BorderSide::NONE,
510                BorderRadiusGeometry::all(Radius::circular(12.0)),
511            ))
512            .elevation(12.0)
513            .text_style(
514                TextStyle::new()
515                    .color(Color::new(0xffffffff))
516                    .text_baseline(waft_embedder::TextBaseline::Alphabetic),
517            )
518            .mouse_cursor(cursor_resolver())
519    }
520
521    /// Dart's `_popupMenuThemeM3()`.
522    fn popup_menu_theme_m3() -> PopupMenuThemeData {
523        PopupMenuThemeData::new()
524            .color(Colors::ORANGE.primary())
525            .shape(BeveledRectangleBorder::new(
526                BorderSide::NONE,
527                BorderRadiusGeometry::all(Radius::circular(12.0)),
528            ))
529            .menu_padding(EdgeInsetsGeometry::symmetric(9.0, 0.0))
530            .elevation(12.0)
531            .shadow_color(Color::new(0xff00ff00))
532            .surface_tint_color(Color::new(0xff00ff00))
533            .label_text_style(<dyn WidgetStateProperty<Option<TextStyle>>>::resolve_with(
534                |states| {
535                    if states.contains(&WidgetState::Disabled) {
536                        return Some(
537                            TextStyle::new()
538                                .color(Color::new(0xfff99ff0))
539                                .font_size(12.0),
540                        );
541                    }
542                    Some(
543                        TextStyle::new()
544                            .color(Color::new(0xfff12099))
545                            .font_size(17.0),
546                    )
547                },
548            ))
549            .mouse_cursor(cursor_resolver())
550            .icon_color(Color::new(0xfff12099))
551            .icon_size(17.0)
552    }
553
554    fn enabled() -> WidgetStates {
555        WidgetStates::new()
556    }
557
558    fn disabled() -> WidgetStates {
559        let mut states = WidgetStates::new();
560        states.insert(WidgetState::Disabled);
561        states
562    }
563
564    #[test]
565    fn popup_menu_theme_data_copy_with_equality_basics() {
566        assert_eq!(
567            PopupMenuThemeData::new(),
568            PopupMenuThemeData::new().copy_with()
569        );
570    }
571
572    #[test]
573    fn popup_menu_theme_data_lerp_special_cases() {
574        assert!(PopupMenuThemeData::lerp(None, None, 0.0).is_none());
575        let data = PopupMenuThemeData::new();
576        assert_eq!(
577            PopupMenuThemeData::lerp(Some(&data), Some(&data), 0.5),
578            Some(data)
579        );
580    }
581
582    #[test]
583    fn popup_menu_theme_data_null_fields_by_default() {
584        let popup_menu_theme = PopupMenuThemeData::new();
585        assert_eq!(popup_menu_theme.color, None);
586        assert!(popup_menu_theme.shape.is_none());
587        assert_eq!(popup_menu_theme.menu_padding, None);
588        assert_eq!(popup_menu_theme.elevation, None);
589        assert_eq!(popup_menu_theme.shadow_color, None);
590        assert_eq!(popup_menu_theme.surface_tint_color, None);
591        assert_eq!(popup_menu_theme.text_style, None);
592        assert!(popup_menu_theme.label_text_style.is_none());
593        assert_eq!(popup_menu_theme.enable_feedback, None);
594        assert!(popup_menu_theme.mouse_cursor.is_none());
595    }
596
597    fn element_of(tester: &WidgetTester, key: &GlobalKey) -> AnyElement {
598        key.current_context(&tester.cell.borrow())
599            .expect("the keyed widget is mounted")
600    }
601
602    /// The last `Material` in the tree: the menu's.
603    fn menu_material(tester: &WidgetTester) -> AnyElement {
604        *find::by_type::<Material>()
605            .evaluate(tester)
606            .last()
607            .expect("the menu's Material")
608    }
609
610    /// Dart's `find.descendant(of: find.byKey(key), matching: find.byType(DefaultTextStyle))
611    /// .last`'s style.
612    fn item_text_style(tester: &WidgetTester, key: &GlobalKey) -> TextStyle {
613        let item = element_of(tester, key);
614        let text_style = *tester
615            .descendants_of_type::<DefaultTextStyle>(item)
616            .last()
617            .expect("a DefaultTextStyle in the item");
618        tester.widget(text_style, |text_style: &DefaultTextStyle| {
619            text_style.style.clone()
620        })
621    }
622
623    /// The `n`th `ListTile`'s `title_text_style`.
624    fn list_tile_title_text_style(tester: &WidgetTester, last: bool) -> Option<TextStyle> {
625        let tiles = find::by_type::<ListTile>().evaluate(tester);
626        let tile = if last { tiles.last() } else { tiles.first() };
627        tester.widget(*tile.expect("a ListTile"), |tile: &ListTile| {
628            tile.title_text_style.clone()
629        })
630    }
631
632    fn menu_padding(tester: &WidgetTester) -> Option<EdgeInsetsGeometry> {
633        let scroll_view = tester.element(find::by_type::<SingleChildScrollView>());
634        tester.widget(scroll_view, |scroll_view: &SingleChildScrollView| {
635            scroll_view.padding
636        })
637    }
638
639    fn icon_color_and_size(tester: &WidgetTester) -> (Option<Color>, Size) {
640        let more = Icons::adaptive().more(&tester.cell.borrow());
641        let icon = tester.element(find::by_icon(&more).first());
642        (
643            tester.glyph_style(icon).color.as_deref().copied(),
644            tester.get_rect(tester.render_box_of(icon)).size(),
645        )
646    }
647
648    fn cursor(cursor: SystemMouseCursor) -> MouseCursorRef {
649        cursor.into()
650    }
651
652    /// Dart's mouse gesture of the cases: added at the origin, moved over the item keyed
653    /// `over`, and, with `down`, pressed over the item keyed `down`; the active cursor after
654    /// each.
655    fn cursors_over(
656        tester: &mut WidgetTester,
657        over: &GlobalKey,
658        down: Option<&GlobalKey>,
659    ) -> (MouseCursorRef, Option<MouseCursorRef>) {
660        let mut gesture = TestPointer::mouse(1, waft_gestures::K_PRIMARY_BUTTON);
661        tester.add_pointer(&mut gesture, Offset::ZERO);
662        let at = tester.get_center(over);
663        tester.move_to(&mut gesture, at, false);
664        tester.pump_and_settle();
665        let over_cursor = tester.active_cursor(1);
666        let down_cursor = down.map(|down| {
667            let at = tester.get_center(down);
668            tester.down(&mut gesture, at);
669            tester.pump_and_settle();
670            tester.active_cursor(1)
671        });
672        (over_cursor, down_cursor)
673    }
674
675    /// The column with the padded or bare button keyed `button_key` of the cases.
676    fn button_column(
677        tester: &mut WidgetTester,
678        theme: impl FnOnce(&App) -> ThemeData,
679        padded: bool,
680        button: PopupMenuButton<()>,
681    ) {
682        pump_app(tester, theme, move |_app| {
683            let button = if padded {
684                // The padding makes sure the menu has enough space around it to
685                // get properly aligned when displayed (`_kMenuScreenPadding`).
686                Padding::new(EdgeInsetsGeometry::all(8.0))
687                    .child(button)
688                    .into_widget()
689            } else {
690                button.into_widget()
691            };
692            Material::new()
693                .child(Column::new().children(vec![button]))
694                .into_widget()
695        });
696    }
697
698    fn keyed_item(key: &GlobalKey, text: &str, enabled: bool) -> PopupMenuEntryRef<()> {
699        PopupMenuEntryRef::new(
700            PopupMenuItem::new(Some(Text::new(text)))
701                .key(key.clone().into())
702                .enabled(enabled),
703        )
704    }
705
706    fn checked_item(checked: bool, text: &str) -> PopupMenuEntryRef<()> {
707        PopupMenuEntryRef::new(
708            CheckedPopupMenuItem::new()
709                .checked(checked)
710                .child(Text::new(text)),
711        )
712    }
713
714    #[test]
715    fn passing_no_popup_menu_theme_data_returns_defaults() {
716        test_widgets(|tester| {
717            let popup_button_key = GlobalKey::new();
718            let enabled_popup_item_key = GlobalKey::new();
719            let disabled_popup_item_key = GlobalKey::new();
720            let theme = m3(&tester.cell.borrow());
721            let (enabled_key, disabled_key) = (
722                enabled_popup_item_key.clone(),
723                disabled_popup_item_key.clone(),
724            );
725            button_column(
726                tester,
727                m3,
728                true,
729                PopupMenuButton::new(move |_app, _context| {
730                    vec![
731                        keyed_item(&enabled_key, "Enabled PopupMenuItem", true),
732                        PopupMenuEntryRef::new(PopupMenuDivider::new()),
733                        keyed_item(&disabled_key, "Disabled PopupMenuItem", false),
734                        checked_item(false, "Unchecked item"),
735                        checked_item(true, "Checked item"),
736                    ]
737                })
738                .key(popup_button_key.clone().into()),
739            );
740
741            // Test default button icon color.
742            assert_eq!(
743                icon_color_and_size(tester).0,
744                theme.icon_theme.color.as_deref().copied()
745            );
746
747            let at = tester.get_center(&popup_button_key);
748            tester.tap_at(at, 1);
749            tester.pump_and_settle();
750
751            let button = menu_material(tester);
752            tester.widget(button, |button: &Material| {
753                assert_eq!(button.color, Some(theme.color_scheme.surface_container()));
754                assert_eq!(button.shadow_color, Some(theme.color_scheme.shadow()));
755                assert_eq!(button.surface_tint_color, Some(Colors::TRANSPARENT));
756                let shape: ShapeBorderRef = ShapeBorderRef::new(RoundedRectangleBorder::new(
757                    BorderSide::NONE,
758                    BorderRadiusGeometry::all(Radius::circular(4.0)),
759                ));
760                assert_eq!(button.shape, Some(shape));
761                assert_eq!(button.elevation, 3.0);
762            });
763
764            let label = item_text_style(tester, &enabled_popup_item_key);
765            assert_eq!(label.font_family.as_deref(), Some("Roboto"));
766            assert_eq!(
767                label.color.as_deref().copied(),
768                Some(theme.color_scheme.on_surface())
769            );
770
771            // Test disabled text color
772            #[allow(deprecated)]
773            let disabled_color = theme.color_scheme.on_surface().with_opacity(0.38);
774            let label = item_text_style(tester, &disabled_popup_item_key);
775            assert_eq!(label.color.as_deref().copied(), Some(disabled_color));
776
777            let top_left_button = tester
778                .get_rect(
779                    tester.render_box_of(tester.element(find::by_type::<PopupMenuButton<()>>())),
780                )
781                .top_left();
782            let top_left_menu = tester.get_rect(tester.render_box_of(button)).top_left();
783            assert_eq!(top_left_menu, top_left_button);
784
785            let (over, down) = cursors_over(
786                tester,
787                &disabled_popup_item_key,
788                Some(&enabled_popup_item_key),
789            );
790            assert!(*over == *cursor(SystemMouseCursors::BASIC));
791            assert!(*down.expect("pressed") == *cursor(SystemMouseCursors::BASIC));
792
793            // Test unchecked CheckedPopupMenuItem label.
794            let title = list_tile_title_text_style(tester, false);
795            assert_eq!(
796                title.and_then(|style| style.color.as_deref().copied()),
797                Some(theme.color_scheme.on_surface())
798            );
799
800            // Test checked CheckedPopupMenuItem label.
801            let title = list_tile_title_text_style(tester, true);
802            assert_eq!(
803                title.and_then(|style| style.color.as_deref().copied()),
804                Some(theme.color_scheme.on_surface())
805            );
806
807            // Check popup menu padding.
808            assert_eq!(
809                menu_padding(tester),
810                Some(EdgeInsetsGeometry::symmetric(8.0, 0.0))
811            );
812        });
813    }
814
815    #[test]
816    fn popup_menu_uses_values_from_popup_menu_theme_data() {
817        test_widgets(|tester| {
818            let popup_menu_theme = popup_menu_theme_m3();
819            let popup_button_key = GlobalKey::new();
820            let enabled_popup_item_key = GlobalKey::new();
821            let disabled_popup_item_key = GlobalKey::new();
822            let (enabled_key, disabled_key) = (
823                enabled_popup_item_key.clone(),
824                disabled_popup_item_key.clone(),
825            );
826            let theme = popup_menu_theme.clone();
827            button_column(
828                tester,
829                move |app| ThemeData::builder().popup_menu_theme(theme).build(app),
830                false,
831                PopupMenuButton::new(move |_app, _context| {
832                    vec![
833                        keyed_item(&disabled_key, "disabled", false),
834                        PopupMenuEntryRef::new(PopupMenuDivider::new()),
835                        PopupMenuEntryRef::new(
836                            PopupMenuItem::new(Some(Text::new("enabled")))
837                                .key(enabled_key.clone().into())
838                                .on_tap(waft_foundation::Listener::new(|_app| {})),
839                        ),
840                        checked_item(false, "Unchecked item"),
841                        checked_item(true, "Checked item"),
842                    ]
843                })
844                // The padding is used in the positioning of the menu when the
845                // position is `PopupMenuPosition.under`. Setting it to zero makes
846                // it easier to test.
847                .padding(EdgeInsetsGeometry::ZERO)
848                .key(popup_button_key.clone().into()),
849            );
850
851            assert_eq!(
852                icon_color_and_size(tester),
853                (popup_menu_theme.icon_color, Size::new(17.0, 17.0))
854            );
855
856            let at = tester.get_center(&popup_button_key);
857            tester.tap_at(at, 1);
858            tester.pump_and_settle();
859
860            let button = menu_material(tester);
861            tester.widget(button, |button: &Material| {
862                assert_eq!(button.color, Some(Colors::ORANGE.primary()));
863                assert_eq!(button.surface_tint_color, Some(Color::new(0xff00ff00)));
864                assert_eq!(button.shadow_color, Some(Color::new(0xff00ff00)));
865                assert_eq!(button.shape, popup_menu_theme.shape);
866                assert_eq!(button.elevation, 12.0);
867            });
868
869            let label_text_style = popup_menu_theme.label_text_style.clone().expect("set");
870            assert_eq!(
871                Some(item_text_style(tester, &enabled_popup_item_key)),
872                label_text_style.resolve(&enabled())
873            );
874
875            // Test disabled text color
876            assert_eq!(
877                Some(item_text_style(tester, &disabled_popup_item_key)),
878                label_text_style.resolve(&disabled())
879            );
880
881            let mouse_cursor = popup_menu_theme.mouse_cursor.clone().expect("set");
882            let (over, down) = cursors_over(
883                tester,
884                &disabled_popup_item_key,
885                Some(&enabled_popup_item_key),
886            );
887            assert!(*over == *mouse_cursor.resolve(&disabled()).expect("a cursor"));
888            assert!(
889                *down.expect("pressed") == *mouse_cursor.resolve(&enabled()).expect("a cursor")
890            );
891
892            // Test unchecked CheckedPopupMenuItem label.
893            assert_eq!(
894                list_tile_title_text_style(tester, false),
895                label_text_style.resolve(&enabled())
896            );
897
898            // Test checked CheckedPopupMenuItem label.
899            assert_eq!(
900                list_tile_title_text_style(tester, true),
901                label_text_style.resolve(&enabled())
902            );
903
904            // Check popup menu padding.
905            assert_eq!(menu_padding(tester), popup_menu_theme.menu_padding);
906        });
907    }
908
909    #[test]
910    fn popup_menu_widget_properties_take_priority_over_theme() {
911        test_widgets(|tester| {
912            let popup_menu_theme = popup_menu_theme_m3();
913            let popup_button_key = GlobalKey::new();
914            let popup_item_key = GlobalKey::new();
915
916            let color = Color::new(0xfff11fff);
917            let surface_tint_color = Color::new(0xfff12fff);
918            let shadow_color = Color::new(0xfff13fff);
919            let shape = RoundedRectangleBorder::new(
920                BorderSide::NONE,
921                BorderRadiusGeometry::all(Radius::circular(9.0)),
922            );
923            let elevation = 7.0;
924            let text_style = TextStyle::new()
925                .color(Color::new(0xfff14fff))
926                .font_size(19.0);
927            let icon_color = Color::new(0xfff15fff);
928            let icon_size = 21.5;
929
930            let item_key = popup_item_key.clone();
931            let style = text_style.clone();
932            button_column(
933                tester,
934                move |app| {
935                    ThemeData::builder()
936                        .popup_menu_theme(popup_menu_theme)
937                        .build(app)
938                },
939                false,
940                PopupMenuButton::new(move |_app, _context| {
941                    vec![
942                        PopupMenuEntryRef::new(
943                            PopupMenuItem::new(Some(Text::new("Example")))
944                                .key(item_key.clone().into())
945                                .label_text_style(
946                                    <dyn WidgetStateProperty<Option<TextStyle>>>::all(Some(
947                                        style.clone(),
948                                    )),
949                                )
950                                .mouse_cursor(cursor(SystemMouseCursors::FORBIDDEN)),
951                        ),
952                        PopupMenuEntryRef::new(
953                            CheckedPopupMenuItem::new()
954                                .checked(true)
955                                .label_text_style(
956                                    <dyn WidgetStateProperty<Option<TextStyle>>>::all(Some(
957                                        style.clone(),
958                                    )),
959                                )
960                                .child(Text::new("Checked item")),
961                        ),
962                    ]
963                })
964                .key(popup_button_key.clone().into())
965                .elevation(elevation)
966                .shadow_color(shadow_color)
967                .surface_tint_color(surface_tint_color)
968                .color(color)
969                .shape(shape)
970                .menu_padding(EdgeInsetsGeometry::ZERO)
971                .icon_color(icon_color)
972                .icon_size(icon_size),
973            );
974
975            assert_eq!(
976                icon_color_and_size(tester),
977                (Some(icon_color), Size::new(icon_size, icon_size))
978            );
979
980            let at = tester.get_center(&popup_button_key);
981            tester.tap_at(at, 1);
982            tester.pump_and_settle();
983
984            let button = menu_material(tester);
985            tester.widget(button, |button: &Material| {
986                assert_eq!(button.color, Some(color));
987                let shape: ShapeBorderRef = ShapeBorderRef::new(shape);
988                assert_eq!(button.shape, Some(shape));
989                assert_eq!(button.elevation, elevation);
990                assert_eq!(button.shadow_color, Some(shadow_color));
991                assert_eq!(button.surface_tint_color, Some(surface_tint_color));
992            });
993
994            assert_eq!(item_text_style(tester, &popup_item_key), text_style);
995
996            let (over, _) = cursors_over(tester, &popup_item_key, None);
997            assert!(*over == *cursor(SystemMouseCursors::FORBIDDEN));
998
999            // Test CheckedPopupMenuItem label.
1000            assert_eq!(list_tile_title_text_style(tester, false), Some(text_style));
1001
1002            // Check popup menu padding.
1003            assert_eq!(menu_padding(tester), Some(EdgeInsetsGeometry::ZERO));
1004        });
1005    }
1006
1007    #[test]
1008    fn material2_passing_no_popup_menu_theme_data_returns_defaults() {
1009        test_widgets(|tester| {
1010            let popup_button_key = GlobalKey::new();
1011            let enabled_popup_item_key = GlobalKey::new();
1012            let disabled_popup_item_key = GlobalKey::new();
1013            let theme = m2(&tester.cell.borrow());
1014            let (enabled_key, disabled_key) = (
1015                enabled_popup_item_key.clone(),
1016                disabled_popup_item_key.clone(),
1017            );
1018            button_column(
1019                tester,
1020                m2,
1021                true,
1022                PopupMenuButton::new(move |_app, _context| {
1023                    vec![
1024                        keyed_item(&enabled_key, "Enabled PopupMenuItem", true),
1025                        PopupMenuEntryRef::new(PopupMenuDivider::new()),
1026                        keyed_item(&disabled_key, "Disabled PopupMenuItem", false),
1027                    ]
1028                })
1029                .key(popup_button_key.clone().into()),
1030            );
1031
1032            let at = tester.get_center(&popup_button_key);
1033            tester.tap_at(at, 1);
1034            tester.pump_and_settle();
1035
1036            let button = menu_material(tester);
1037            tester.widget(button, |button: &Material| {
1038                assert_eq!(button.color, None);
1039                assert!(button.shape.is_none());
1040                assert_eq!(button.elevation, 8.0);
1041            });
1042
1043            let enabled_text = item_text_style(tester, &enabled_popup_item_key);
1044            assert_eq!(enabled_text.font_family.as_deref(), Some("Roboto"));
1045            assert_eq!(
1046                enabled_text.color.as_deref().copied(),
1047                Some(Color::new(0xdd000000))
1048            );
1049
1050            let disabled_text = item_text_style(tester, &disabled_popup_item_key);
1051            assert_eq!(
1052                disabled_text.color.as_deref().copied(),
1053                Some(theme.disabled_color)
1054            );
1055
1056            let top_left_button = tester
1057                .get_rect(
1058                    tester.render_box_of(tester.element(find::by_type::<PopupMenuButton<()>>())),
1059                )
1060                .top_left();
1061            let top_left_menu = tester.get_rect(tester.render_box_of(button)).top_left();
1062            assert_eq!(top_left_menu, top_left_button);
1063
1064            let (over, down) = cursors_over(
1065                tester,
1066                &disabled_popup_item_key,
1067                Some(&enabled_popup_item_key),
1068            );
1069            assert!(*over == *cursor(SystemMouseCursors::BASIC));
1070            assert!(*down.expect("pressed") == *cursor(SystemMouseCursors::BASIC));
1071
1072            // Check popup menu padding.
1073            assert_eq!(
1074                menu_padding(tester),
1075                Some(EdgeInsetsGeometry::symmetric(8.0, 0.0))
1076            );
1077        });
1078    }
1079
1080    #[test]
1081    fn material2_popup_menu_uses_values_from_popup_menu_theme_data() {
1082        test_widgets(|tester| {
1083            let popup_menu_theme = popup_menu_theme_m2();
1084            let popup_button_key = GlobalKey::new();
1085            let enabled_popup_item_key = GlobalKey::new();
1086            let disabled_popup_item_key = GlobalKey::new();
1087            let (enabled_key, disabled_key) = (
1088                enabled_popup_item_key.clone(),
1089                disabled_popup_item_key.clone(),
1090            );
1091            let theme = popup_menu_theme.clone();
1092            button_column(
1093                tester,
1094                move |app| {
1095                    ThemeData::builder()
1096                        .popup_menu_theme(theme)
1097                        .use_material3(false)
1098                        .build(app)
1099                },
1100                false,
1101                PopupMenuButton::new(move |_app, _context| {
1102                    vec![
1103                        keyed_item(&disabled_key, "disabled", false),
1104                        PopupMenuEntryRef::new(PopupMenuDivider::new()),
1105                        PopupMenuEntryRef::new(
1106                            PopupMenuItem::new(Some(Text::new("enabled")))
1107                                .key(enabled_key.clone().into())
1108                                .on_tap(waft_foundation::Listener::new(|_app| {})),
1109                        ),
1110                    ]
1111                })
1112                .padding(EdgeInsetsGeometry::ZERO)
1113                .key(popup_button_key.clone().into()),
1114            );
1115
1116            let at = tester.get_center(&popup_button_key);
1117            tester.tap_at(at, 1);
1118            tester.pump_and_settle();
1119
1120            let button = menu_material(tester);
1121            tester.widget(button, |button: &Material| {
1122                assert_eq!(button.color, popup_menu_theme.color);
1123                assert_eq!(button.shape, popup_menu_theme.shape);
1124                assert_eq!(Some(button.elevation), popup_menu_theme.elevation);
1125            });
1126
1127            assert_eq!(
1128                Some(item_text_style(tester, &enabled_popup_item_key)),
1129                popup_menu_theme.text_style
1130            );
1131
1132            let mouse_cursor = popup_menu_theme.mouse_cursor.clone().expect("set");
1133            let (over, down) = cursors_over(
1134                tester,
1135                &disabled_popup_item_key,
1136                Some(&enabled_popup_item_key),
1137            );
1138            assert!(*over == *mouse_cursor.resolve(&disabled()).expect("a cursor"));
1139            assert!(
1140                *down.expect("pressed") == *mouse_cursor.resolve(&enabled()).expect("a cursor")
1141            );
1142        });
1143    }
1144
1145    #[test]
1146    fn material2_popup_menu_widget_properties_take_priority_over_theme() {
1147        test_widgets(|tester| {
1148            let popup_menu_theme = popup_menu_theme_m2();
1149            let popup_button_key = GlobalKey::new();
1150            let popup_item_key = GlobalKey::new();
1151
1152            let color = Colors::PURPLE.primary();
1153            let surface_tint_color = Colors::AMBER.primary();
1154            let shadow_color = Colors::GREEN.primary();
1155            let shape = RoundedRectangleBorder::new(
1156                BorderSide::NONE,
1157                BorderRadiusGeometry::all(Radius::circular(9.0)),
1158            );
1159            let elevation = 7.0;
1160            let text_style = TextStyle::new()
1161                .color(Color::new(0xffffffef))
1162                .font_size(19.0);
1163
1164            let item_key = popup_item_key.clone();
1165            let style = text_style.clone();
1166            // Dart's case builds the default theme, Material 3, with the Material 2 popup menu
1167            // theme.
1168            button_column(
1169                tester,
1170                move |app| {
1171                    ThemeData::builder()
1172                        .popup_menu_theme(popup_menu_theme)
1173                        .build(app)
1174                },
1175                false,
1176                PopupMenuButton::new(move |_app, _context| {
1177                    vec![PopupMenuEntryRef::new(
1178                        PopupMenuItem::new(Some(Text::new("Example")))
1179                            .key(item_key.clone().into())
1180                            .label_text_style(<dyn WidgetStateProperty<Option<TextStyle>>>::all(
1181                                Some(style.clone()),
1182                            ))
1183                            .mouse_cursor(cursor(SystemMouseCursors::FORBIDDEN)),
1184                    )]
1185                })
1186                .key(popup_button_key.clone().into())
1187                .elevation(elevation)
1188                .shadow_color(shadow_color)
1189                .surface_tint_color(surface_tint_color)
1190                .color(color)
1191                .shape(shape),
1192            );
1193
1194            let at = tester.get_center(&popup_button_key);
1195            tester.tap_at(at, 1);
1196            tester.pump_and_settle();
1197
1198            let button = menu_material(tester);
1199            tester.widget(button, |button: &Material| {
1200                assert_eq!(button.color, Some(color));
1201                let shape: ShapeBorderRef = ShapeBorderRef::new(shape);
1202                assert_eq!(button.shape, Some(shape));
1203                assert_eq!(button.elevation, elevation);
1204                assert_eq!(button.shadow_color, Some(shadow_color));
1205                assert_eq!(button.surface_tint_color, Some(surface_tint_color));
1206            });
1207
1208            assert_eq!(item_text_style(tester, &popup_item_key), text_style);
1209
1210            let (over, _) = cursors_over(tester, &popup_item_key, None);
1211            assert!(*over == *cursor(SystemMouseCursors::FORBIDDEN));
1212        });
1213    }
1214
1215    #[test]
1216    fn of_returns_the_closest_popup_menu_theme_over_theme_data() {
1217        test_widgets(|tester| {
1218            let widget_theme = PopupMenuThemeData::new().elevation(7.0);
1219            let expected = widget_theme.clone();
1220            let seen = probe(
1221                tester,
1222                move |app, child| {
1223                    let data = ThemeData::builder()
1224                        .popup_menu_theme(PopupMenuThemeData::new().elevation(3.0))
1225                        .build(app);
1226                    Theme::new(data, PopupMenuTheme::new(widget_theme.clone(), child)).into_widget()
1227                },
1228                PopupMenuTheme::of,
1229            );
1230            assert_eq!(seen, expected);
1231        });
1232    }
1233
1234    #[test]
1235    fn of_returns_the_theme_data_popup_menu_theme_without_an_ancestor() {
1236        test_widgets(|tester| {
1237            let expected = PopupMenuThemeData::new().elevation(3.0);
1238            let theme_data_theme = expected.clone();
1239            let seen = probe(
1240                tester,
1241                move |app, child| {
1242                    let data = ThemeData::builder()
1243                        .popup_menu_theme(theme_data_theme.clone())
1244                        .build(app);
1245                    Theme::new(data, child).into_widget()
1246                },
1247                PopupMenuTheme::of,
1248            );
1249            assert_eq!(seen, expected);
1250        });
1251    }
1252
1253    #[test]
1254    fn popup_menu_theme_data_lerps_each_field() {
1255        let a = PopupMenuThemeData::new()
1256            .color(Colors::BLACK)
1257            .elevation(2.0)
1258            .icon_size(10.0)
1259            .enable_feedback(true)
1260            .position(PopupMenuPosition::Over);
1261        let b = PopupMenuThemeData::new()
1262            .color(Colors::WHITE)
1263            .elevation(6.0)
1264            .icon_size(20.0)
1265            .enable_feedback(false)
1266            .position(PopupMenuPosition::Under);
1267        let halfway = PopupMenuThemeData::lerp(Some(&a), Some(&b), 0.5).expect("both sides");
1268        assert_eq!(
1269            halfway.color,
1270            Color::lerp(Some(Colors::BLACK), Some(Colors::WHITE), 0.5)
1271        );
1272        assert_eq!(halfway.elevation, Some(4.0));
1273        assert_eq!(halfway.icon_size, Some(15.0));
1274        assert_eq!(halfway.enable_feedback, Some(false));
1275        assert_eq!(halfway.position, Some(PopupMenuPosition::Under));
1276        let early = PopupMenuThemeData::lerp(Some(&a), Some(&b), 0.25).expect("both sides");
1277        assert_eq!(early.enable_feedback, Some(true));
1278        assert_eq!(early.position, Some(PopupMenuPosition::Over));
1279    }
1280
1281    #[test]
1282    fn update_should_notify_only_when_the_data_differs() {
1283        let theme = |elevation: f64| {
1284            PopupMenuTheme::new(
1285                PopupMenuThemeData::new().elevation(elevation),
1286                waft_widgets::SizedBox::shrink(),
1287            )
1288        };
1289        let old = theme(1.0);
1290        assert!(!theme(1.0).update_should_notify(&old));
1291        assert!(theme(2.0).update_should_notify(&old));
1292    }
1293    // Flutter's "Default PopupMenuThemeData debugFillProperties".
1294    #[test]
1295    fn a_popup_menu_theme_data_describes_nothing_by_default() {
1296        assert_eq!(
1297            waft_widgets::testing::describe_properties(|properties| {
1298                waft_foundation::Diagnosticable::debug_fill_properties(
1299                    &PopupMenuThemeData::new(),
1300                    properties,
1301                )
1302            }),
1303            Vec::<String>::new()
1304        );
1305    }
1306}