waft-material 0.17.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
//! Flutter counterpart: material_ui's `ink_decoration.dart`.
//!
//! `Ink.image` waits with `DecorationImage`.

use std::fmt;
use std::rc::Rc;

use waft_embedder::{Canvas, Color, Matrix4, Offset};
use waft_foundation::{
    App, DiagnosticPropertiesBuilder, DiagnosticsProperty, Handle, Listener, OptionRetained, Ref,
};
use waft_painting::{
    BoxDecoration, BoxPainter, DecorationRef, EdgeInsets, EdgeInsetsGeometry, ImageConfiguration,
    get_as_translation,
};
use waft_rendering::{AnyRenderBox, BoxConstraints};
use waft_widgets::{
    BuildContext, Builder, ConstrainedBox, GlobalKey, IntoWidget, KeyRef, Padding, SizedBox, State,
    StateData, StatefulWidget, Visibility, WidgetRef, create_local_image_configuration,
};

use crate::debug::debug_check_has_material;
use crate::material::{
    AnyMaterialInkController, InkFeature, InkFeatureData, InkFeatureLeaf, InkFeatureLeafData,
    Material,
};

/// A convenience widget for drawing images and other decorations on [`Material`]
/// widgets, so that [`InkWell`](crate::InkWell) and [`InkResponse`](crate::InkResponse)
/// splashes will render over them.
///
/// Ink splashes and highlights, as rendered by [`InkWell`](crate::InkWell) and similar
/// widgets, are actually painted on the underlying [`Material`], which is typically
/// below the children of the [`Material`] widget. This is problematic if a child of the
/// [`Material`] has its own decoration, which would cover the ink effects.
///
/// The [`Ink`] widget fixes this by painting on the [`Material`] directly, below the ink
/// effects.
///
/// The [`padding`](Self::padding) is applied around the [`child`](Self::child); the
/// decoration's padding is added to it.
///
/// [`Ink`] is not a replacement for a `Container`: it paints a decoration on the
/// material, not around it, so the [`Material`]'s clip is the decoration's clip.
///
/// See also:
///
///  * `Container`, a more generic form of this widget which paints itself,
///    rather that deferring to the nearest [`Material`] widget.
///  * [`InkDecoration`], the [`InkFeature`] subclass used by this widget to paint
///    on [`Material`] widgets.
///  * [`InkWell`](crate::InkWell) and [`InkResponse`](crate::InkResponse), which also draw on
///    [`Material`] widgets.
pub struct Ink {
    pub key: Option<KeyRef>,

    /// The [`child`](Self::child) contained by the container.
    ///
    /// If null, this widget's size will expand to fill the box constraints, or, when
    /// [`width`](Self::width) or [`height`](Self::height) is given, that size.
    pub child: Option<WidgetRef>,

    /// Empty space to inscribe inside the [`decoration`](Self::decoration). The
    /// [`child`](Self::child), if any, is placed inside this padding.
    ///
    /// This padding is in addition to any padding inherent in the
    /// [`decoration`](Self::decoration) (see `Decoration::padding`).
    pub padding: Option<EdgeInsetsGeometry>,

    /// Dart's `color:` argument: a shorthand for "decoration: BoxDecoration(color: color)".
    pub color: Option<Color>,

    /// The decoration to paint on the nearest ancestor [`Material`] widget.
    ///
    /// A shorthand for specifying just a solid color is available in the
    /// constructor: set the `color` argument instead of the `decoration`
    /// argument.
    ///
    /// A shorthand for specifying just an image is also available using the
    /// `Ink.image` constructor.
    pub decoration: Option<DecorationRef>,

    /// A width to apply to the [`decoration`](Self::decoration) and the
    /// [`child`](Self::child). The width includes any [`padding`](Self::padding).
    pub width: Option<f64>,

    /// A height to apply to the [`decoration`](Self::decoration) and the
    /// [`child`](Self::child). The height includes any [`padding`](Self::padding).
    pub height: Option<f64>,
}

impl fmt::Debug for Ink {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("Ink")
            .field("padding", &self.padding)
            .field("bg", &self.effective_decoration())
            .finish_non_exhaustive()
    }
}

impl Ink {
    /// Paints a decoration (which can be a simple color) on a [`Material`]; Dart's named
    /// arguments are the setters.
    ///
    /// The [`height`](Self::height) and [`width`](Self::width) values include the
    /// [`padding`](Self::padding).
    ///
    /// The `color` argument is a shorthand for
    /// `decoration: BoxDecoration::new().color(color)`, which means you cannot supply
    /// both a `color` and a `decoration` argument. If you want to have both a
    /// `color` and a `decoration`, you can pass the color as the `color`
    /// argument to the `BoxDecoration`.
    ///
    /// If there is no intention to render anything on this decoration, consider
    /// using a `Container` with a `BoxConstraints` instead.
    pub fn new() -> Ink {
        Ink {
            key: None,
            child: None,
            padding: None,
            color: None,
            decoration: None,
            width: None,
            height: None,
        }
    }

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

    /// Dart `Ink(padding:)`.
    pub fn padding(mut self, padding: impl Into<EdgeInsetsGeometry>) -> Ink {
        let padding = padding.into();
        debug_assert!(padding.is_non_negative());
        self.padding = Some(padding);
        self
    }

    /// Dart `Ink(color:)`.
    pub fn color(mut self, color: Color) -> Ink {
        self.color = Some(color);
        self.debug_assert_color_or_decoration();
        self
    }

    /// Dart `Ink(decoration:)`.
    pub fn decoration(mut self, decoration: impl Into<DecorationRef>) -> Ink {
        let decoration = decoration.into();
        debug_assert!(decoration.debug_assert_is_valid());
        self.decoration = Some(decoration);
        self.debug_assert_color_or_decoration();
        self
    }

    /// Dart `Ink(width:)`.
    pub fn width(mut self, width: f64) -> Ink {
        self.width = Some(width);
        self
    }

    /// Dart `Ink(height:)`.
    pub fn height(mut self, height: f64) -> Ink {
        self.height = Some(height);
        self
    }

    /// Dart `Ink(child:)`.
    #[cfg_attr(debug_assertions, track_caller)]
    pub fn child<K>(mut self, child: impl IntoWidget<K>) -> Ink {
        self.child = Some(child.into_widget());
        self
    }

    fn debug_assert_color_or_decoration(&self) {
        debug_assert!(
            self.color.is_none() || self.decoration.is_none(),
            "Cannot provide both a color and a decoration\nThe color argument is just a \
             shorthand for \"decoration: BoxDecoration(color: color)\"."
        );
    }

    /// Dart's `decoration` field, as its constructor fills it.
    pub fn effective_decoration(&self) -> Option<DecorationRef> {
        match (&self.decoration, self.color) {
            (Some(decoration), _) => Some(decoration.clone()),
            (None, Some(color)) => Some(DecorationRef::new(BoxDecoration::new().color(color))),
            (None, None) => None,
        }
    }

    fn padding_including_decoration(&self) -> EdgeInsetsGeometry {
        let decoration_padding = self
            .effective_decoration()
            .map(|decoration| decoration.padding());
        match (self.padding, decoration_padding) {
            (None, None) => EdgeInsets::ZERO.into(),
            (None, Some(padding)) => padding,
            (Some(padding), None) => padding,
            (Some(padding), Some(decoration_padding)) => padding.add(decoration_padding),
        }
    }
}

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

impl StatefulWidget for Ink {
    type State = InkState;

    fn key(&self) -> Option<&KeyRef> {
        self.key.as_ref()
    }

    fn debug_fill_properties(&self, _app: &App, properties: &mut DiagnosticPropertiesBuilder) {
        properties.add(
            DiagnosticsProperty::<EdgeInsetsGeometry>::new("padding", self.padding)
                .default_value(None),
        );
        properties.add(
            DiagnosticsProperty::<DecorationRef>::new("bg", self.decoration.clone())
                .default_value(None),
        );
    }

    fn create_state(&self) -> InkState {
        InkState {
            state: StateData::new(),
            box_key: GlobalKey::new(),
            ink: None,
        }
    }
}

/// Dart's `_InkState`.
pub struct InkState {
    state: StateData<Ink>,
    box_key: GlobalKey,
    ink: Option<Ref<InkDecoration>>,
}

impl InkState {
    fn handle_removed(self: Handle<Self>, app: &mut App) {
        app.get_mut(self).ink = None;
    }

    fn build_child(self: Handle<Self>, app: &mut App, context: BuildContext) -> WidgetRef {
        // By creating the InkDecoration from within a Builder widget, we can
        // use the RenderBox of the Padding widget.
        let decoration = self.widget(app).effective_decoration();
        let is_visible = Visibility::of(app, context);
        let configuration = create_local_image_configuration(app, context, None);
        match app.get(self).ink.clone() {
            None => {
                let controller = Material::of(app, context);
                let box_key = app.get(self).box_key.clone();
                let reference_box = box_key
                    .current_context(app)
                    .expect("the padding is mounted")
                    .find_render_object(app)
                    .and_then(|render_object| render_object.as_box())
                    .expect("the padding is a render box");
                let ink = InkDecoration::new(
                    app,
                    decoration,
                    is_visible,
                    configuration,
                    controller,
                    reference_box,
                    Some(Listener::handle_method(self, Self::handle_removed)),
                );
                app.get_mut(self).ink = Some(ink);
            }
            Some(ink) => {
                ink.set_decoration(app, decoration);
                ink.set_is_visible(app, is_visible);
                ink.set_configuration(app, configuration);
            }
        }
        self.widget(app).child.clone().unwrap_or_else(|| {
            ConstrainedBox::new(BoxConstraints::expand(None, None)).into_widget()
        })
    }
}

impl State for InkState {
    type Widget = Ink;
    waft_widgets::state_accessors!();

    fn deactivate(self: Handle<Self>, app: &mut App) {
        if let Some(ink) = app.get(self).ink.handle() {
            InkFeatureLeaf::dispose(ink, app);
        }
        debug_assert!(app.get(self).ink.is_none());
    }

    fn build(self: Handle<Self>, app: &mut App, context: BuildContext) -> WidgetRef {
        debug_assert!(debug_check_has_material(app, context));
        let widget = self.widget(app);
        let padding = widget.padding_including_decoration();
        let (width, height) = (widget.width, widget.height);
        let box_key = app.get(self).box_key.clone();
        let mut result = Padding::new(padding)
            .key(box_key.into())
            .child(Builder::new(move |app, context| {
                self.build_child(app, context)
            }))
            .into_widget();
        if width.is_some() || height.is_some() {
            let mut sized = SizedBox::new();
            if let Some(width) = width {
                sized = sized.width(width);
            }
            if let Some(height) = height {
                sized = sized.height(height);
            }
            result = sized.child(result).into_widget();
        }
        result
    }
}

/// A decoration on a part of a [`Material`].
///
/// This object is rarely created directly. Instead of creating an ink
/// decoration directly, consider using an [`Ink`] widget, which uses this class
/// in combination with [`Padding`] and [`ConstrainedBox`] to draw a decoration on a
/// [`Material`].
///
/// See also:
///
///  * [`Ink`], the corresponding widget.
///  * [`InkResponse`](crate::InkResponse), which uses gestures to trigger ink highlights and
///    ink splashes in the parent [`Material`].
///  * [`InkWell`](crate::InkWell), which is a rectangular [`InkResponse`](crate::InkResponse)
///    (the most common type of ink response).
///  * [`Material`], which is the widget on which the ink is painted.
pub struct InkDecoration {
    ink_feature: InkFeatureData,
    painter: Option<Box<dyn BoxPainter>>,
    decoration: Option<DecorationRef>,
    is_visible: bool,
    configuration: ImageConfiguration,
}

impl InkDecoration {
    /// Draws a decoration on a [`Material`].
    ///
    /// Dart's default `is_visible` is true.
    pub fn new(
        app: &mut App,
        decoration: Option<DecorationRef>,
        is_visible: bool,
        configuration: ImageConfiguration,
        controller: AnyMaterialInkController,
        reference_box: AnyRenderBox,
        on_removed: Option<Listener>,
    ) -> Ref<InkDecoration> {
        let ink_feature = InkFeatureData::new(app, controller, reference_box, on_removed);
        let this = app.create(InkDecoration {
            ink_feature,
            painter: None,
            decoration: None,
            is_visible: true,
            configuration,
        });
        this.set_decoration(app, decoration);
        this.set_is_visible(app, is_visible);
        controller.add_ink_feature(app, this.erase());
        this
    }

    /// What to paint on the [`Material`].
    ///
    /// The decoration is painted at the position and size of the `reference_box`,
    /// on the [`Material`] that owns the `controller`.
    pub fn decoration(self: Handle<Self>, app: &App) -> Option<&DecorationRef> {
        app.get(self).decoration.as_ref()
    }

    /// Sets [`decoration`](Self::decoration).
    pub fn set_decoration(self: Handle<Self>, app: &mut App, value: Option<DecorationRef>) {
        if value == app.get(self).decoration {
            return;
        }
        let controller = InkFeature::controller(self, app);
        let painter = value.as_ref().map(|decoration| {
            decoration.create_box_painter(Some(Rc::new(move |app: &mut App| {
                controller.mark_needs_paint(app)
            })))
        });
        let ink = app.get_mut(self);
        ink.decoration = value;
        if let Some(mut old_painter) = std::mem::replace(&mut ink.painter, painter) {
            old_painter.dispose();
        }
        controller.mark_needs_paint(app);
    }

    /// Whether the decoration should be painted.
    ///
    /// Defaults to true.
    pub fn is_visible(self: Handle<Self>, app: &App) -> bool {
        app.get(self).is_visible
    }

    /// Sets [`is_visible`](Self::is_visible).
    pub fn set_is_visible(self: Handle<Self>, app: &mut App, value: bool) {
        if value == app.get(self).is_visible {
            return;
        }
        app.get_mut(self).is_visible = value;
        InkFeature::controller(self, app).mark_needs_paint(app);
    }

    /// The configuration to pass to the `BoxPainter` obtained from the
    /// [`decoration`](Self::decoration), when painting.
    ///
    /// The `ImageConfiguration::size` field is ignored (and replaced by the size
    /// of the `reference_box`, at paint time).
    pub fn configuration(self: Handle<Self>, app: &App) -> &ImageConfiguration {
        &app.get(self).configuration
    }

    /// Sets [`configuration`](Self::configuration).
    pub fn set_configuration(self: Handle<Self>, app: &mut App, value: ImageConfiguration) {
        if value == app.get(self).configuration {
            return;
        }
        app.get_mut(self).configuration = value;
        InkFeature::controller(self, app).mark_needs_paint(app);
    }
}

impl InkFeatureLeafData for InkDecoration {
    fn ink_feature(&self) -> &InkFeatureData {
        &self.ink_feature
    }

    fn ink_feature_mut(&mut self) -> &mut InkFeatureData {
        &mut self.ink_feature
    }
}

impl InkFeatureLeaf for InkDecoration {
    fn dispose(self: Handle<Self>, app: &mut App) {
        if let Some(mut painter) = app.get_mut(self).painter.take() {
            painter.dispose();
        }
        InkFeature::dispose(self, app);
    }

    fn paint_feature(self: Handle<Self>, app: &mut App, canvas: &mut Canvas, transform: &Matrix4) {
        if app.get(self).painter.is_none() || !self.is_visible(app) {
            return;
        }
        let origin_offset = get_as_translation(*transform);
        let size = InkFeature::reference_box(self, app).size(app);
        let sized_configuration =
            self.configuration(app)
                .copy_with(None, None, None, None, Some(size), None);
        let painter = app.get_mut(self).painter.as_mut().expect("checked above");
        match origin_offset {
            None => {
                canvas.save();
                canvas.concat(transform);
                painter.paint(canvas, Offset::ZERO, &sized_configuration);
                canvas.restore();
            }
            Some(origin_offset) => {
                painter.paint(canvas, origin_offset, &sized_configuration);
            }
        }
    }
}

#[cfg(test)]
mod tests {
    use std::time::Duration;

    use waft_embedder::{Rect, Size};
    use waft_widgets::Center;

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

    use super::*;
    use crate::colors::Colors;
    use crate::ink_well::InkWell;
    use crate::test_support::{PaintInspection, path_like};
    use crate::theme::Theme;
    use crate::theme_data::ThemeData;
    use waft_rendering::testing::RecordedCall;

    #[test]
    fn the_ink_widget_expands_when_no_dimensions_are_set() {
        test_widgets(|tester| {
            let key = GlobalKey::new();
            tester.pump_widget(
                Material::new()
                    .child(Ink::new().key(key.clone().into()))
                    .into_widget(),
            );
            assert_eq!(tester.get_size(&key), Size::new(800.0, 600.0));
        });
    }

    #[test]
    fn the_ink_widget_fits_the_specified_size() {
        test_widgets(|tester| {
            let key = GlobalKey::new();
            tester.pump_widget(
                Material::new()
                    .child(
                        // used to constrain to child's size
                        Center::new().child(
                            Ink::new()
                                .key(key.clone().into())
                                .height(150.0)
                                .width(200.0),
                        ),
                    )
                    .into_widget(),
            );
            tester.pump_and_settle();
            assert_eq!(tester.get_size(&key), Size::new(200.0, 150.0));
        });
    }

    #[test]
    fn the_ink_widget_expands_on_a_unspecified_dimension() {
        test_widgets(|tester| {
            let key = GlobalKey::new();
            tester.pump_widget(
                Material::new()
                    .child(
                        // used to constrain to child's size
                        Center::new().child(Ink::new().key(key.clone().into()).height(150.0)),
                    )
                    .into_widget(),
            );
            tester.pump_and_settle();
            assert_eq!(tester.get_size(&key), Size::new(800.0, 150.0));
        });
    }

    fn m2_ink_frame(tester: &WidgetTester, ink: Option<Color>) -> WidgetRef {
        let ink_well = InkWell::new()
            .splash_color(Colors::GREEN.primary())
            .on_tap(Listener::new(|_app| {}));
        let child = match ink {
            Some(color) => Ink::new()
                .color(color)
                .width(200.0)
                .height(200.0)
                .child(ink_well)
                .into_widget(),
            None => ink_well.into_widget(),
        };
        let data = ThemeData::builder()
            .use_material3(false)
            .build(&tester.cell.borrow());
        Theme::new(
            data,
            waft_widgets::Directionality::new(
                waft_embedder::TextDirection::Ltr,
                Material::new().child(Center::new().child(child)),
            ),
        )
        .into_widget()
    }

    /// Dart's `paints..rect(rect: rect, color: rect_color)..circle(color: circle_color)` on the
    /// material.
    fn paints_rect_then_circle(
        tester: &WidgetTester,
        rect_color: Color,
        rect: Rect,
        circle_color: Color,
    ) -> bool {
        use waft_rendering::testing::{PaintCall, paints};
        paints(
            tester.ink_list().ops(),
            &[
                PaintCall::rect_at(rect, Some(rect_color)),
                PaintCall::circle(Some(circle_color)),
            ],
        )
        .is_ok()
    }

    #[test]
    fn material2_does_the_ink_widget_render_anything() {
        test_widgets(|tester| {
            let blue = Colors::BLUE.primary();
            let red = Colors::RED.primary();
            let green = Colors::GREEN.primary();
            let ink_rect = Rect::from_ltrb(300.0, 200.0, 500.0, 400.0);
            let widget = m2_ink_frame(tester, Some(blue));
            tester.pump_widget(widget);

            let mut gesture = TestPointer::touch(1);
            tester.down(&mut gesture, WidgetTester::SIZE.center(Offset::ZERO));
            tester.pump(); // start gesture
            tester.pump_by(Duration::from_millis(200)); // wait for splash to be well under way

            let box_ = tester.first::<crate::material::RenderInkFeatures>();
            assert!(
                paints_rect_then_circle(tester, blue, ink_rect, green),
                "{:?}",
                tester.ink_calls()
            );

            let widget = m2_ink_frame(tester, Some(red));
            tester.pump_widget(widget);
            assert_eq!(tester.first::<crate::material::RenderInkFeatures>(), box_);
            assert!(
                paints_rect_then_circle(tester, red, ink_rect, green),
                "{:?}",
                tester.ink_calls()
            );

            // this is at a different depth in the tree so it's now a new InkWell
            let widget = m2_ink_frame(tester, None);
            tester.pump_widget(widget);
            assert_eq!(tester.first::<crate::material::RenderInkFeatures>(), box_);
            let drawn = tester.ink_calls();
            assert!(
                !drawn
                    .iter()
                    .any(|drawn| matches!(drawn, RecordedCall::Rect { .. }))
            );
            assert!(!drawn.iter().any(|drawn| path_like(drawn).is_some()));

            tester.up(&gesture);
        });
    }

    #[test]
    fn ink_with_is_visible_false_does_not_paint() {
        test_widgets(|tester| {
            let test_color = Color::new(0xffff1234);
            let ink_widget = |is_visible: bool| {
                Material::new()
                    .child(
                        Visibility::maintain(
                            Ink::new().decoration(BoxDecoration::new().color(test_color)),
                        )
                        .visible(is_visible),
                    )
                    .into_widget()
            };
            let has_test_color = |drawn: &[RecordedCall]| {
                drawn
                    .iter()
                    .any(|drawn| matches!(drawn, RecordedCall::Rect { color, .. } if color.to_argb32() == test_color.to_argb32()))
            };

            tester.pump_widget(ink_widget(true));
            assert!(has_test_color(&tester.ink_calls()));

            tester.pump_widget(ink_widget(false));
            assert!(!has_test_color(&tester.ink_calls()));
        });
    }
}