frus-widgets 0.5.0

frus — declarative widget tree
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
//! Widgets that **withhold** part of the frame: [`IgnorePointer`] and
//! [`AbsorbPointer`] take a subtree out of the input path, [`Visibility`] and
//! [`Offstage`] take it out of the picture, [`ExcludeSemantics`] takes it out of the
//! accessibility tree.
//!
//! They all express the same idea — *this subtree is built, but part of what it
//! produced does not count* — and they share one mechanism, [`ModalBarrier`], applied by the
//! walk in `ui.rs`: the subtree is walked normally, then whatever it added to the
//! selected registries is dropped again.
//!
//! Dropping afterwards rather than skipping beforehand is what makes them **exact**.
//! A widget deep inside can register a click target, a focus stop, a scrollable area,
//! a drag handle or an accessibility node, and it does so without knowing that
//! something above it is holding the whole subtree out of the frame. Removing at the
//! barrier catches every one of those, including the ones added by widgets written
//! later.
//!
//! ## Which to reach for
//!
//! | | laid out | painted | takes input | blocks what is behind |
//! |---|---|---|---|---|
//! | [`IgnorePointer`] | yes | yes | no | no — input falls through |
//! | [`AbsorbPointer`] | yes | yes | no | yes — input stops here |
//! | [`Visibility`] hidden, keeping its size | yes | no | no | no |
//! | [`Visibility`] hidden | no | no | no | no |
//! | [`Offstage`] | no | no | no | no |
//! | [`ExcludeSemantics`] | yes | yes | yes | n/a |
//!
//! The difference between the first two is the one that matters and is easy to get
//! backwards: a disabled control that should let a click reach the card underneath is
//! an `IgnorePointer`; a shield over a screen that is busy, which must swallow every
//! stray tap, is an `AbsorbPointer`.

use frus_core::{Rect, Scene};
use frus_layout::{Dimension, Style};

use crate::interaction::Status;
use crate::theme::Theme;
use crate::widget::Widget;

/// What a subtree is not allowed to contribute to the frame.
///
/// Returned by [`Widget::barrier`]; the walk applies it once the subtree has been
/// visited, by discarding what that subtree added.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Default)]
pub struct ModalBarrier {
    /// Drops the subtree's input targets: clicks, long presses, focus stops,
    /// scrollable areas, scrollbars, drag handles, reorder handles and interactive
    /// viewports.
    pub pointer: bool,
    /// Makes the barrier itself an input target that carries no message, so input
    /// landing on it stops there instead of reaching whatever is painted behind. Only
    /// meaningful together with `pointer`.
    pub absorb: bool,
    /// Drops the subtree's primitives — laid out and measured, but not drawn.
    pub paint: bool,
    /// Drops the subtree's accessibility nodes.
    pub semantics: bool,
}

impl ModalBarrier {
    /// A barrier that lets everything through — what a widget with no opinion returns.
    pub const NONE: Self = Self {
        pointer: false,
        absorb: false,
        paint: false,
        semantics: false,
    };

    /// `true` when this barrier would change nothing, so the walk can skip it.
    pub fn is_none(&self) -> bool {
        *self == Self::NONE
    }
}

/// The style of a box that takes no room at all.
fn collapsed() -> Style {
    Style {
        width: Dimension::Length(0.0),
        height: Dimension::Length(0.0),
        ..Default::default()
    }
}

/// Makes its child **invisible to input** while leaving it laid out and painted.
///
/// Input passes straight through to whatever is behind — which is the whole difference
/// from [`AbsorbPointer`].
///
/// ```ignore
/// IgnorePointer::new(row).ignoring(saving)   // inert while a save is in flight
/// ```
///
/// The subtree keeps its accessibility nodes: a screen reader can still read a form
/// that is momentarily inert, which is more useful than having it vanish. Wrap it in
/// [`ExcludeSemantics`] as well if it really should be unreachable.
pub struct IgnorePointer<Msg = crate::callback::Callback> {
    ignoring: bool,
    children: Vec<Box<dyn Widget<Msg>>>,
}

impl<Msg> IgnorePointer<Msg> {
    /// Takes `child` out of the input path.
    pub fn new(child: impl Widget<Msg> + 'static) -> Self {
        Self {
            ignoring: true,
            children: vec![Box::new(child)],
        }
    }

    /// Turns the barrier on or off from a condition — `false` leaves the child fully
    /// interactive, so a caller does not have to build two different trees.
    pub fn ignoring(mut self, ignoring: bool) -> Self {
        self.ignoring = ignoring;
        self
    }
}

impl<Msg: Clone> Widget<Msg> for IgnorePointer<Msg> {
    fn style(&self) -> Style {
        Style::default()
    }

    fn children(&self) -> &[Box<dyn Widget<Msg>>] {
        &self.children
    }

    fn paint(&self, _bounds: Rect, _status: Status, _theme: &Theme, _scene: &mut Scene) {}

    fn on_click(&self) -> Option<Msg> {
        None
    }

    fn barrier(&self) -> Option<ModalBarrier> {
        self.ignoring.then_some(ModalBarrier {
            pointer: true,
            ..ModalBarrier::NONE
        })
    }
}

/// Makes its child invisible to input **and stops there**: the barrier is itself an
/// input target, so anything landing on it is swallowed rather than reaching what is
/// painted behind.
///
/// This is the shield over a screen that is busy, and the backdrop of a modal.
///
/// ```ignore
/// AbsorbPointer::new(screen).absorbing(loading)
/// ```
pub struct AbsorbPointer<Msg = crate::callback::Callback> {
    absorbing: bool,
    children: Vec<Box<dyn Widget<Msg>>>,
}

impl<Msg> AbsorbPointer<Msg> {
    /// Takes `child` out of the input path and swallows what lands on it.
    pub fn new(child: impl Widget<Msg> + 'static) -> Self {
        Self {
            absorbing: true,
            children: vec![Box::new(child)],
        }
    }

    /// Turns the barrier on or off from a condition.
    pub fn absorbing(mut self, absorbing: bool) -> Self {
        self.absorbing = absorbing;
        self
    }
}

impl<Msg: Clone> Widget<Msg> for AbsorbPointer<Msg> {
    fn style(&self) -> Style {
        Style::default()
    }

    fn children(&self) -> &[Box<dyn Widget<Msg>>] {
        &self.children
    }

    fn paint(&self, _bounds: Rect, _status: Status, _theme: &Theme, _scene: &mut Scene) {}

    fn on_click(&self) -> Option<Msg> {
        None
    }

    fn barrier(&self) -> Option<ModalBarrier> {
        self.absorbing.then_some(ModalBarrier {
            pointer: true,
            absorb: true,
            ..ModalBarrier::NONE
        })
    }
}

/// Hides its child from assistive technologies while leaving it visible and
/// interactive — for decoration that would only add noise to a screen reader, or for a
/// label the control beside it already announces.
///
/// ```ignore
/// ExcludeSemantics::new(Icon::new(icons::CHEVRON))   // the button already says "next"
/// ```
pub struct ExcludeSemantics<Msg = crate::callback::Callback> {
    excluding: bool,
    children: Vec<Box<dyn Widget<Msg>>>,
}

impl<Msg> ExcludeSemantics<Msg> {
    /// Removes `child`'s subtree from the accessibility tree.
    pub fn new(child: impl Widget<Msg> + 'static) -> Self {
        Self {
            excluding: true,
            children: vec![Box::new(child)],
        }
    }

    /// Turns the exclusion on or off from a condition.
    pub fn excluding(mut self, excluding: bool) -> Self {
        self.excluding = excluding;
        self
    }
}

impl<Msg: Clone> Widget<Msg> for ExcludeSemantics<Msg> {
    fn style(&self) -> Style {
        Style::default()
    }

    fn children(&self) -> &[Box<dyn Widget<Msg>>] {
        &self.children
    }

    fn paint(&self, _bounds: Rect, _status: Status, _theme: &Theme, _scene: &mut Scene) {}

    fn on_click(&self) -> Option<Msg> {
        None
    }

    fn barrier(&self) -> Option<ModalBarrier> {
        self.excluding.then_some(ModalBarrier {
            semantics: true,
            ..ModalBarrier::NONE
        })
    }
}

/// Takes its child **out of the layout entirely**: no box, no paint, no input, no
/// accessibility. The surrounding row or column closes up as if the child were not
/// written at all.
///
/// ```ignore
/// Offstage::new(panel).offstage(!expanded)
/// ```
///
/// The child is not built into the tree while offstage, so it holds no retained state
/// — a caret position, a scroll offset — and starts fresh when it comes back. That is
/// the right trade for a branch that is genuinely gone; [`Visibility::maintain_size`]
/// is the one to reach for when the box has to stay.
pub struct Offstage<Msg = crate::callback::Callback> {
    offstage: bool,
    children: Vec<Box<dyn Widget<Msg>>>,
}

impl<Msg> Offstage<Msg> {
    /// Removes `child` from the layout.
    pub fn new(child: impl Widget<Msg> + 'static) -> Self {
        Self {
            offstage: true,
            children: vec![Box::new(child)],
        }
    }

    /// Turns it on or off from a condition; `false` lays the child out normally.
    pub fn offstage(mut self, offstage: bool) -> Self {
        self.offstage = offstage;
        self
    }
}

impl<Msg: Clone> Widget<Msg> for Offstage<Msg> {
    fn style(&self) -> Style {
        if self.offstage {
            collapsed()
        } else {
            Style::default()
        }
    }

    fn children(&self) -> &[Box<dyn Widget<Msg>>] {
        if self.offstage {
            &[]
        } else {
            &self.children
        }
    }

    fn paint(&self, _bounds: Rect, _status: Status, _theme: &Theme, _scene: &mut Scene) {}

    fn on_click(&self) -> Option<Msg> {
        None
    }
}

/// Shows or hides its child, with a say in **how much of it survives** being hidden.
///
/// The plain form collapses the child away entirely, as [`Offstage`] does:
///
/// ```ignore
/// Visibility::new(banner).visible(has_error)
/// ```
///
/// `maintain_size` keeps the box — the child still measures and still takes its space,
/// it is simply not drawn. That is what stops a row from twitching as a spinner comes
/// and goes, and what lets two alternating labels of different widths hold a column
/// steady:
///
/// ```ignore
/// Visibility::new(spinner).visible(loading).maintain_size()
/// ```
///
/// `replacement` puts something else in the collapsed child's place instead — a
/// spacer, a placeholder, a shorter message.
pub struct Visibility<Msg = crate::callback::Callback> {
    visible: bool,
    maintain_size: bool,
    maintain_interactivity: bool,
    maintain_semantics: bool,
    /// At most one entry. A `Vec` rather than an `Option` so `children` can hand out a
    /// slice without building one.
    child: Vec<Box<dyn Widget<Msg>>>,
    replacement: Vec<Box<dyn Widget<Msg>>>,
}

impl<Msg> Visibility<Msg> {
    /// Shows `child`. Combine with [`visible`](Self::visible) to make it conditional.
    pub fn new(child: impl Widget<Msg> + 'static) -> Self {
        Self {
            visible: true,
            maintain_size: false,
            maintain_interactivity: false,
            maintain_semantics: false,
            child: vec![Box::new(child)],
            replacement: Vec::new(),
        }
    }

    /// Whether the child is shown.
    pub fn visible(mut self, visible: bool) -> Self {
        self.visible = visible;
        self
    }

    /// Keeps the child's **box** while hidden: it is laid out and measured as usual,
    /// but not drawn, not clickable and not read out.
    pub fn maintain_size(mut self) -> Self {
        self.maintain_size = true;
        self
    }

    /// Keeps the child **taking input** while hidden. Only meaningful together with
    /// [`maintain_size`](Self::maintain_size), and rarely what you want: an invisible
    /// control that still reacts surprises everyone but its author.
    pub fn maintain_interactivity(mut self) -> Self {
        self.maintain_interactivity = true;
        self
    }

    /// Keeps the child in the **accessibility tree** while hidden — for content that
    /// is visually redundant but should still be announced.
    pub fn maintain_semantics(mut self) -> Self {
        self.maintain_semantics = true;
        self
    }

    /// What to show in the child's place when it is hidden **and** its box is not
    /// maintained.
    pub fn replacement(mut self, replacement: impl Widget<Msg> + 'static) -> Self {
        self.replacement = vec![Box::new(replacement)];
        self
    }

    /// `true` when the child is in the tree this frame (shown, or hidden but still
    /// occupying its box).
    fn keeps_child(&self) -> bool {
        self.visible || self.maintain_size
    }
}

impl<Msg: Clone> Widget<Msg> for Visibility<Msg> {
    fn style(&self) -> Style {
        if self.keeps_child() || !self.replacement.is_empty() {
            Style::default()
        } else {
            collapsed()
        }
    }

    fn children(&self) -> &[Box<dyn Widget<Msg>>] {
        if self.keeps_child() {
            &self.child
        } else {
            &self.replacement
        }
    }

    fn paint(&self, _bounds: Rect, _status: Status, _theme: &Theme, _scene: &mut Scene) {}

    fn on_click(&self) -> Option<Msg> {
        None
    }

    fn barrier(&self) -> Option<ModalBarrier> {
        // Only the "hidden but still occupying its box" case needs a barrier: the
        // collapsed case has no child in the tree to withhold anything.
        if self.visible || !self.maintain_size {
            return None;
        }
        Some(ModalBarrier {
            pointer: !self.maintain_interactivity,
            absorb: false,
            paint: true,
            semantics: !self.maintain_semantics,
        })
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::{build_ui, Button, Container, Runtime, SingleChildScrollView, Text};
    use frus_core::{Color, Point, Primitive, Size};

    fn ui_of(root: &dyn Widget<i32>) -> crate::Ui<i32> {
        build_ui(
            root,
            Size::new(100.0, 100.0),
            &Runtime::default(),
            &crate::Theme::dark(),
        )
    }

    /// A 100 × 100 red box emitting `msg` when clicked.
    fn button(msg: i32) -> Container<i32> {
        Container::new()
            .width(100.0)
            .height(100.0)
            .color(Color::rgb(1.0, 0.0, 0.0))
            .on_click(msg)
    }

    /// The centre of the surface — inside every box these tests build.
    fn centre() -> Point {
        Point::new(50.0, 50.0)
    }

    #[test]
    fn ignoring_takes_the_subtree_out_of_the_input_path() {
        let plain =
            crate::Flex::<i32>::column().child(IgnorePointer::new(button(1)).ignoring(false));
        let ui = ui_of(&plain);
        assert_eq!(
            ui.hit(centre()).and_then(|id| ui.msg_for(id)),
            Some(1),
            "ignoring(false) leaves the child fully interactive"
        );

        let ignored = crate::Flex::<i32>::column().child(IgnorePointer::new(button(1)));
        let ui = ui_of(&ignored);
        assert!(ui.hit(centre()).is_none());
    }

    #[test]
    fn ignoring_lets_input_reach_what_is_behind() {
        // Two overlapping layers: the ignored one is painted on top.
        let root = crate::Stack::<i32>::new()
            .width(100.0)
            .height(100.0)
            .layer(button(1))
            .layer(IgnorePointer::new(button(2)));
        let ui = ui_of(&root);
        assert_eq!(
            ui.hit(centre()).and_then(|id| ui.msg_for(id)),
            Some(1),
            "the click falls through the ignored layer to the one underneath"
        );
    }

    #[test]
    fn absorbing_stops_input_at_the_barrier() {
        let root = crate::Stack::<i32>::new()
            .width(100.0)
            .height(100.0)
            .layer(button(1))
            .layer(AbsorbPointer::new(button(2)));
        let ui = ui_of(&root);
        let id = ui.hit(centre()).expect("the barrier is itself a target");
        assert_eq!(
            ui.msg_for(id),
            None,
            "it swallows the click rather than emitting anything"
        );
    }

    #[test]
    fn absorbing_can_be_turned_off_from_a_condition() {
        let root = crate::Stack::<i32>::new()
            .width(100.0)
            .height(100.0)
            .layer(button(1))
            .layer(AbsorbPointer::new(button(2)).absorbing(false));
        let ui = ui_of(&root);
        assert_eq!(ui.hit(centre()).and_then(|id| ui.msg_for(id)), Some(2));
    }

    #[test]
    fn a_barrier_still_paints_its_child() {
        let root = crate::Flex::<i32>::column().child(IgnorePointer::new(button(1)));
        let ui = ui_of(&root);
        assert!(
            ui.scene()
                .primitives()
                .iter()
                .any(|p| matches!(p, Primitive::Rect { color, .. } if color.r > 0.5)),
            "an ignored subtree is invisible to input, not to the eye"
        );
    }

    /// The barrier acts on what the subtree registered, not on what the barrier widget
    /// itself declares — so a target several levels down is caught too.
    #[test]
    fn a_target_deep_inside_is_caught() {
        let deep = crate::Flex::<i32>::column().child(
            crate::Flex::<i32>::column().child(crate::Flex::<i32>::column().child(button(1))),
        );
        let root = crate::Flex::<i32>::column().child(IgnorePointer::new(deep));
        let ui = ui_of(&root);
        assert!(ui.hit(centre()).is_none());
    }

    #[test]
    fn a_scrollable_inside_a_barrier_stops_scrolling() {
        let long = SingleChildScrollView::<i32>::new()
            .width(100.0)
            .height(100.0)
            .child(Container::new().width(100.0).height(1000.0));
        let root = crate::Flex::<i32>::column().child(IgnorePointer::new(long));
        let ui = ui_of(&root);
        assert!(
            ui.scroll_hit(centre()).is_none(),
            "the wheel has nothing to scroll through a barrier"
        );
    }

    /// A widget that annotates itself for assistive technologies — the only kind
    /// [`ExcludeSemantics`] has anything to remove.
    fn announced() -> Button<i32> {
        Button::new("Send").on_press(1)
    }

    #[test]
    fn excluding_semantics_leaves_input_and_paint_alone() {
        let visible = crate::Flex::<i32>::column().child(announced());
        let plain = ui_of(&visible);
        assert!(
            !plain.semantics().is_empty(),
            "the fixture has something to exclude"
        );
        // A point inside the button, which sits at the top of the column.
        let on_the_button = Point::new(20.0, 12.0);
        assert!(plain.hit(on_the_button).is_some(), "and it is clickable");

        let root = crate::Flex::<i32>::column().child(ExcludeSemantics::new(announced()));
        let ui = ui_of(&root);
        assert!(
            ui.semantics().is_empty(),
            "gone from the accessibility tree"
        );
        assert!(ui.hit(on_the_button).is_some(), "and still clickable");
    }

    #[test]
    fn an_ignored_subtree_keeps_its_semantics() {
        let root = crate::Flex::<i32>::column().child(IgnorePointer::new(announced()));
        let ui = ui_of(&root);
        assert!(
            !ui.semantics().is_empty(),
            "a momentarily inert form is still worth reading out"
        );
        assert!(
            ui.hit(Point::new(20.0, 12.0)).is_none(),
            "but it takes no input"
        );
    }

    #[test]
    fn offstage_takes_no_room() {
        let shown = crate::Flex::<i32>::column()
            .child(Offstage::new(button(1)).offstage(false))
            .child(Text::new("after"));
        let ui = ui_of(&shown);
        assert!(ui.hit(centre()).is_some());

        let hidden = crate::Flex::<i32>::column()
            .child(Offstage::new(button(1)))
            .child(Text::new("after"));
        let ui = ui_of(&hidden);
        assert!(ui.hit(centre()).is_none());
        assert!(
            ui.scene()
                .primitives()
                .iter()
                .all(|p| !matches!(p, Primitive::Rect { color, .. } if color.r > 0.5)),
            "an offstage child is not painted either"
        );
    }

    #[test]
    fn a_hidden_visibility_collapses_by_default() {
        let root = crate::Flex::<i32>::column().child(Visibility::new(button(1)).visible(false));
        let ui = ui_of(&root);
        assert!(ui.hit(centre()).is_none());
        assert_eq!(
            Widget::<i32>::children(&Visibility::new(button(1)).visible(false)).len(),
            0,
            "no child in the tree at all"
        );
    }

    #[test]
    fn maintaining_the_size_keeps_the_box_but_not_the_paint() {
        let hidden = || Visibility::new(button(1)).visible(false).maintain_size();
        let root = crate::Flex::<i32>::column().child(hidden());
        let ui = ui_of(&root);
        assert!(
            ui.scene()
                .primitives()
                .iter()
                .all(|p| !matches!(p, Primitive::Rect { color, .. } if color.r > 0.5)),
            "not drawn"
        );
        assert!(ui.hit(centre()).is_none(), "and not clickable");
        assert_eq!(
            Widget::<i32>::children(&hidden()).len(),
            1,
            "but still laid out, so the row does not twitch"
        );
    }

    #[test]
    fn maintained_interactivity_survives_the_barrier() {
        let root = crate::Flex::<i32>::column().child(
            Visibility::new(button(1))
                .visible(false)
                .maintain_size()
                .maintain_interactivity(),
        );
        let ui = ui_of(&root);
        assert_eq!(ui.hit(centre()).and_then(|id| ui.msg_for(id)), Some(1));
    }

    #[test]
    fn a_replacement_takes_the_hidden_childs_place() {
        let root = crate::Flex::<i32>::column().child(
            Visibility::new(button(1))
                .visible(false)
                .replacement(button(2)),
        );
        let ui = ui_of(&root);
        assert_eq!(
            ui.hit(centre()).and_then(|id| ui.msg_for(id)),
            Some(2),
            "the replacement is an ordinary child, barrier-free"
        );
    }

    #[test]
    fn a_widget_that_withholds_nothing_declares_no_barrier() {
        assert_eq!(Widget::<i32>::barrier(&Visibility::new(button(1))), None);
        assert_eq!(
            Widget::<i32>::barrier(&IgnorePointer::new(button(1)).ignoring(false)),
            None
        );
    }
}