waft-widgets 0.18.2

Widget framework and 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
//! Flutter counterpart: `widgets/dual_transition_builder.dart`.

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

use waft_animation::{
    AnimationRef, AnimationStatus, AnimationStatusListener, ProxyAnimation, ReverseAnimation,
    k_always_complete_animation, k_always_dismissed_animation,
};
use waft_foundation::{App, Handle, OptionRetained, Ref};

use crate::framework::{
    BuildContext, IntoWidget, KeyRef, State, StateData, StatefulWidget, WidgetRef,
};

/// Builder callback used by [`DualTransitionBuilder`].
///
/// The builder is expected to return a transition powered by the provided
/// `animation` and wrapping the provided `child`.
///
/// The `animation` provided to the builder always runs forward from 0.0 to 1.0.
///
/// An optional `child` widget which represents a pre-built widget subtree that
/// does not depend on the animation's value.
///
/// Passing a pre-built widget here and incorporating it into the returned
/// widget tree avoids rebuilding it for every frame of the animation and
/// can improve performance significantly in some cases.
pub type AnimatedTransitionBuilder =
    Rc<dyn Fn(&mut App, BuildContext, AnimationRef<f64>, Option<&WidgetRef>) -> WidgetRef>;

/// A transition builder that animates its [`child`](Self::child) based on the
/// [`AnimationStatus`] of the provided [`animation`](Self::animation).
///
/// This widget can be used to specify different enter and exit transitions for
/// a [`child`](Self::child).
///
/// While the [`animation`](Self::animation) runs forward, the [`child`](Self::child) is
/// animated according to [`forward_builder`](Self::forward_builder) and while the
/// [`animation`](Self::animation) is running in reverse, it is animated according to
/// [`reverse_builder`](Self::reverse_builder).
///
/// Using this builder allows the widget tree to maintain its shape by nesting
/// the enter and exit transitions. This ensures that no state information of
/// any descendant widget is lost when the transition starts or completes.
pub struct DualTransitionBuilder {
    pub key: Option<KeyRef>,

    /// The animation that drives the [`child`](Self::child)'s transition.
    ///
    /// When this animation runs forward, the [`child`](Self::child) transitions as specified
    /// by [`forward_builder`](Self::forward_builder). When it runs in reverse, the child
    /// transitions according to [`reverse_builder`](Self::reverse_builder).
    pub animation: AnimationRef<f64>,

    /// A builder for the transition that makes [`child`](Self::child) appear on screen.
    ///
    /// The [`child`](Self::child) should be fully visible when the provided `animation`
    /// reaches 1.0.
    ///
    /// The `animation` provided to this builder is running forward from 0.0 to
    /// 1.0 when [`animation`](Self::animation) runs _forward_. When
    /// [`animation`](Self::animation) runs in reverse, the given `animation` is set to
    /// `k_always_complete_animation`.
    ///
    /// See also:
    ///
    ///  * [`reverse_builder`](Self::reverse_builder), which builds the transition for making
    ///    the [`child`](Self::child) disappear from the screen.
    pub forward_builder: AnimatedTransitionBuilder,

    /// A builder for a transition that makes [`child`](Self::child) disappear from the
    /// screen.
    ///
    /// The [`child`](Self::child) should be fully invisible when the provided `animation`
    /// reaches 1.0.
    ///
    /// The `animation` provided to this builder is running forward from 0.0 to
    /// 1.0 when [`animation`](Self::animation) runs in _reverse_. When
    /// [`animation`](Self::animation) runs forward, the given `animation` is set to
    /// `k_always_dismissed_animation`.
    ///
    /// See also:
    ///
    ///  * [`forward_builder`](Self::forward_builder), which builds the transition for making
    ///    the [`child`](Self::child) appear on screen.
    pub reverse_builder: AnimatedTransitionBuilder,

    /// The widget below this [`DualTransitionBuilder`] in the tree.
    ///
    /// This child widget will be wrapped by the transitions built by
    /// [`forward_builder`](Self::forward_builder) and
    /// [`reverse_builder`](Self::reverse_builder).
    ///
    /// If a pre-built subtree is provided as the [`child`](Self::child), it will be passed to
    /// the [`reverse_builder`](Self::reverse_builder), and the result of that will in turn be
    /// passed to the [`forward_builder`](Self::forward_builder). This allows the builders to
    /// incorporate the subtree without rebuilding it on every frame.
    ///
    /// Using this pre-built child is entirely optional, but can improve
    /// performance significantly in some cases and is therefore a good practice.
    pub child: Option<WidgetRef>,
}

impl Debug for DualTransitionBuilder {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("DualTransitionBuilder")
            .field("key", &self.key)
            .field("animation", &self.animation)
            .field("child", &self.child)
            .finish_non_exhaustive()
    }
}

impl DualTransitionBuilder {
    /// Creates a [`DualTransitionBuilder`].
    pub fn new(
        animation: AnimationRef<f64>,
        forward_builder: impl Fn(
            &mut App,
            BuildContext,
            AnimationRef<f64>,
            Option<&WidgetRef>,
        ) -> WidgetRef
        + 'static,
        reverse_builder: impl Fn(
            &mut App,
            BuildContext,
            AnimationRef<f64>,
            Option<&WidgetRef>,
        ) -> WidgetRef
        + 'static,
    ) -> DualTransitionBuilder {
        DualTransitionBuilder {
            key: None,
            animation,
            forward_builder: Rc::new(forward_builder),
            reverse_builder: Rc::new(reverse_builder),
            child: None,
        }
    }

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

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

impl StatefulWidget for DualTransitionBuilder {
    type State = DualTransitionBuilderState;

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

    fn create_state(&self) -> DualTransitionBuilderState {
        DualTransitionBuilderState {
            state: StateData::new(),
            effective_animation_status: AnimationStatus::Dismissed,
            forward_animation: None,
            reverse_animation: None,
        }
    }
}

/// Dart's `_DualTransitionBuilderState`.
///
/// The two proxies are Dart's field initialisers; they need the `App`, so `init_state` makes
/// them before anything reads them.
pub struct DualTransitionBuilderState {
    state: StateData<DualTransitionBuilder>,
    effective_animation_status: AnimationStatus,
    forward_animation: Option<Ref<ProxyAnimation>>,
    reverse_animation: Option<Ref<ProxyAnimation>>,
}

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

impl DualTransitionBuilderState {
    fn forward_animation(self: Handle<Self>, app: &App) -> Handle<ProxyAnimation> {
        app.get(self)
            .forward_animation
            .handle()
            .expect("created in init_state")
    }

    fn reverse_animation(self: Handle<Self>, app: &App) -> Handle<ProxyAnimation> {
        app.get(self)
            .reverse_animation
            .handle()
            .expect("created in init_state")
    }

    fn animation_listener(self: Handle<Self>, app: &mut App, animation_status: AnimationStatus) {
        let old_effective = app.get(self).effective_animation_status;
        let effective = calculate_effective_animation_status(old_effective, animation_status);
        app.get_mut(self).effective_animation_status = effective;
        if old_effective != effective {
            self.update_animations(app);
        }
    }

    fn update_animations(self: Handle<Self>, app: &mut App) {
        let animation = self.widget(app).animation.clone();
        let forward_animation = self.forward_animation(app);
        let reverse_animation = self.reverse_animation(app);
        match app.get(self).effective_animation_status {
            AnimationStatus::Dismissed | AnimationStatus::Forward => {
                forward_animation.set_parent(app, Some(animation));
                let dismissed = k_always_dismissed_animation(app);
                reverse_animation.set_parent(app, Some(dismissed));
            }
            AnimationStatus::Reverse | AnimationStatus::Completed => {
                let complete = k_always_complete_animation(app);
                forward_animation.set_parent(app, Some(complete));
                let reversed = ReverseAnimation::new(app, animation);
                reverse_animation.set_parent(app, Some(reversed.into_erased()));
            }
        }
    }
}

/// When a transition is interrupted midway we just want to play the ongoing
/// animation in reverse. Switching to the actual reverse transition would
/// yield a disjoint experience since the forward and reverse transitions are
/// very different.
fn calculate_effective_animation_status(
    last_effective: AnimationStatus,
    current: AnimationStatus,
) -> AnimationStatus {
    match current {
        AnimationStatus::Dismissed | AnimationStatus::Completed => current,
        AnimationStatus::Forward => match last_effective {
            AnimationStatus::Dismissed | AnimationStatus::Completed | AnimationStatus::Forward => {
                current
            }
            AnimationStatus::Reverse => last_effective,
        },
        AnimationStatus::Reverse => match last_effective {
            AnimationStatus::Dismissed | AnimationStatus::Completed | AnimationStatus::Reverse => {
                current
            }
            AnimationStatus::Forward => last_effective,
        },
    }
}

impl State for DualTransitionBuilderState {
    type Widget = DualTransitionBuilder;
    crate::state_accessors!();

    fn init_state(self: Handle<Self>, app: &mut App) {
        let forward_animation = ProxyAnimation::new(app, None);
        let reverse_animation = ProxyAnimation::new(app, None);
        let state = app.get_mut(self);
        state.forward_animation = Some(forward_animation);
        state.reverse_animation = Some(reverse_animation);
        let animation = self.widget(app).animation.handle();
        app.get_mut(self).effective_animation_status = animation.status(app);
        animation.add_status_listener(
            app,
            AnimationStatusListener::handle_method(self, Self::animation_listener),
        );
        self.update_animations(app);
    }

    fn did_update_widget(self: Handle<Self>, app: &mut App, old_widget: &DualTransitionBuilder) {
        let animation = self.widget(app).animation.handle();
        if old_widget.animation != animation {
            old_widget.animation.remove_status_listener(
                app,
                &AnimationStatusListener::handle_method(self, Self::animation_listener),
            );
            animation.add_status_listener(
                app,
                AnimationStatusListener::handle_method(self, Self::animation_listener),
            );
            let status = animation.status(app);
            self.animation_listener(app, status);
        }
    }

    fn dispose(self: Handle<Self>, app: &mut App) {
        let animation = self.widget(app).animation.handle();
        animation.remove_status_listener(
            app,
            &AnimationStatusListener::handle_method(self, Self::animation_listener),
        );
    }

    fn build(self: Handle<Self>, app: &mut App, context: BuildContext) -> WidgetRef {
        let widget = self.widget(app);
        let forward_builder = Rc::clone(&widget.forward_builder);
        let reverse_builder = Rc::clone(&widget.reverse_builder);
        let child = widget.child.clone();
        let state = app.get(self);
        let forward_animation: AnimationRef<f64> = state
            .forward_animation
            .as_ref()
            .expect("created in init_state")
            .erase();
        let reverse_animation: AnimationRef<f64> = state
            .reverse_animation
            .as_ref()
            .expect("created in init_state")
            .erase();
        let reversed = reverse_builder(app, context, reverse_animation, child.as_ref());
        forward_builder(app, context, forward_animation, Some(&reversed))
    }
}

#[cfg(test)]
mod tests {
    use std::cell::Cell;
    use std::time::Duration;
    use waft_animation::Drive;
    use waft_foundation::Ref;

    use waft_animation::{AnimationBehavior, AnimationController, AnyAnimation, Tween};
    use waft_embedder::Color;

    use super::*;
    use crate::testing::{TestVSync, WidgetTester, test_widgets};
    use crate::widgets::basic::{Center, SizedBox};
    use crate::widgets::container::Container;
    use crate::widgets::transitions::{FadeTransition, ScaleTransition};

    /// What the two builders were last given: Dart's `_getScale` and `_getOpacity` read the
    /// `ScaleTransition` and `FadeTransition` the builders return, whose animations these are.
    #[derive(Clone, Default)]
    struct Observed {
        scale: Rc<Cell<Option<AnyAnimation<f64>>>>,
        opacity: Rc<Cell<Option<AnyAnimation<f64>>>>,
    }

    impl Observed {
        fn scale(&self, app: &App) -> f64 {
            self.scale.get().expect("built").value(app)
        }

        fn opacity(&self, app: &App) -> f64 {
            self.opacity.get().expect("built").value(app)
        }
    }

    fn controller(app: &mut App, value: Option<f64>) -> Ref<AnimationController> {
        AnimationController::new(
            app,
            value,
            Some(Duration::from_millis(300)),
            None,
            0.0,
            1.0,
            AnimationBehavior::Normal,
            TestVSync,
        )
    }

    fn tree(animation: AnimationRef<f64>, observed: &Observed, child: WidgetRef) -> WidgetRef {
        let scale = Rc::clone(&observed.scale);
        let opacity = Rc::clone(&observed.opacity);
        Center::new()
            .child(
                DualTransitionBuilder::new(
                    animation,
                    move |_app, _context, animation, child| {
                        scale.set(Some(animation.handle()));
                        ScaleTransition::new(animation)
                            .child(child.expect("a child").clone())
                            .into_widget()
                    },
                    move |app, _context, animation, child| {
                        let tween = Tween::new(app, Some(1.0), Some(0.0));
                        let faded = animation.drive(app, tween);
                        opacity.set(Some(faded.handle()));
                        FadeTransition::new(faded)
                            .child(child.expect("a child").clone())
                            .into_widget()
                    },
                )
                .child(child),
            )
            .into_widget()
    }

    fn green_box() -> WidgetRef {
        Container::new()
            .color(Color::new(0xFF00FF00))
            .height(100.0)
            .width(100.0)
            .into_widget()
    }

    fn ms(millis: u64) -> Duration {
        Duration::from_millis(millis)
    }

    fn assert_scale_and_opacity(
        tester: &WidgetTester,
        observed: &Observed,
        scale: f64,
        opacity: f64,
    ) {
        let app = tester.cell.borrow();
        assert_eq!(observed.scale(&app), scale);
        assert_eq!(observed.opacity(&app), opacity);
    }

    /// Pumps the tree for `controller`.
    fn pump_tree(
        tester: &mut WidgetTester,
        controller: &Ref<AnimationController>,
        child: WidgetRef,
    ) -> Observed {
        let observed = Observed::default();
        tester.pump_widget(tree(controller.erase(), &observed, child));
        observed
    }

    #[test]
    fn runs_animations() {
        test_widgets(|tester| {
            let controller = tester.update(|app| controller(app, None));
            let observed = pump_tree(tester, &controller, green_box());
            assert_scale_and_opacity(tester, &observed, 0.0, 1.0);

            tester.update(|app| controller.forward(app, None));
            tester.pump();
            tester.pump_by(ms(150));
            assert_scale_and_opacity(tester, &observed, 0.5, 1.0);

            tester.pump_by(ms(150));
            assert_scale_and_opacity(tester, &observed, 1.0, 1.0);

            tester.pump_by(ms(300));
            assert_scale_and_opacity(tester, &observed, 1.0, 1.0);

            tester.update(|app| controller.reverse(app, None));
            tester.pump();
            tester.pump_by(ms(150));
            assert_scale_and_opacity(tester, &observed, 1.0, 0.5);

            tester.pump_by(ms(150));
            assert_scale_and_opacity(tester, &observed, 1.0, 0.0);

            tester.pump_by(ms(300));
            assert_scale_and_opacity(tester, &observed, 0.0, 1.0);
            tester.update(|app| controller.dispose(app));
        });
    }

    /// Not a Dart case: the proxies and the `ReverseAnimation` a state made are freed once the
    /// unmounted tree lets go of them, as Dart's collector frees them.
    #[test]
    fn a_disposed_state_frees_its_proxies_and_reverse_animation() {
        test_widgets(|tester| {
            let controller = tester.update(|app| controller(app, Some(1.0)));
            let forward: Rc<Cell<Option<AnyAnimation<f64>>>> = Rc::default();
            let reverse: Rc<Cell<Option<AnyAnimation<f64>>>> = Rc::default();
            let tree = {
                let (forward, reverse) = (Rc::clone(&forward), Rc::clone(&reverse));
                DualTransitionBuilder::new(
                    controller.erase(),
                    move |_app, _context, animation, child| {
                        forward.set(Some(animation.handle()));
                        child.cloned().expect("a child")
                    },
                    move |_app, _context, animation, child| {
                        reverse.set(Some(animation.handle()));
                        child.cloned().expect("a child")
                    },
                )
                .child(green_box())
                .into_widget()
            };
            tester.pump_widget(Center::new().child(tree));
            let proxies = [forward, reverse].map(|built| built.get().expect("the builder ran"));
            let reverse_parent = {
                let app = tester.cell.borrow();
                let reverse = app
                    .handle::<ProxyAnimation>(proxies[1].id())
                    .expect("the reverse proxy");
                reverse
                    .parent(&app)
                    .expect("a completed animation is reversed")
            };

            tester.pump_widget(SizedBox::new());
            let app = tester.cell.borrow();
            for freed in [proxies[0].id(), proxies[1].id(), reverse_parent.id()] {
                assert!(!app.contains(freed), "{freed:?} is freed");
            }
            assert!(
                app.contains(&controller),
                "the widget's animation is its owner's"
            );
        });
    }

    #[test]
    fn keeps_state() {
        test_widgets(|tester| {
            let controller = tester.update(|app| controller(app, None));
            let probe = Probe::default();
            pump_tree(tester, &controller, probe.widget());
            assert_eq!((probe.inits.get(), probe.disposes.get()), (1, 0));

            for direction in [AnimationController::forward, AnimationController::reverse] {
                tester.update(|app| direction(controller.handle(), app, None));
                for step in [0, 150, 150, 300] {
                    tester.pump_by(ms(step));
                    assert_eq!((probe.inits.get(), probe.disposes.get()), (1, 0));
                }
            }
            tester.update(|app| controller.dispose(app));
        });
    }

    #[test]
    fn does_not_jump_when_interrupted_forward() {
        test_widgets(|tester| {
            let controller = tester.update(|app| controller(app, None));
            let observed = pump_tree(tester, &controller, green_box());
            assert_scale_and_opacity(tester, &observed, 0.0, 1.0);

            tester.update(|app| controller.forward(app, None));
            tester.pump();
            tester.pump_by(ms(150));
            assert_scale_and_opacity(tester, &observed, 0.5, 1.0);

            tester.update(|app| controller.reverse(app, None));
            assert_scale_and_opacity(tester, &observed, 0.5, 1.0);
            tester.pump();
            assert_scale_and_opacity(tester, &observed, 0.5, 1.0);

            tester.pump_by(ms(75));
            assert_scale_and_opacity(tester, &observed, 0.25, 1.0);

            tester.pump_by(ms(75));
            assert_scale_and_opacity(tester, &observed, 0.0, 1.0);

            tester.pump_by(ms(300));
            assert_scale_and_opacity(tester, &observed, 0.0, 1.0);
            tester.update(|app| controller.dispose(app));
        });
    }

    #[test]
    fn does_not_jump_when_interrupted_reverse() {
        test_widgets(|tester| {
            let controller = tester.update(|app| controller(app, Some(1.0)));
            let observed = pump_tree(tester, &controller, green_box());
            assert_scale_and_opacity(tester, &observed, 1.0, 1.0);

            tester.update(|app| controller.reverse(app, None));
            tester.pump();
            tester.pump_by(ms(150));
            assert_scale_and_opacity(tester, &observed, 1.0, 0.5);

            tester.update(|app| controller.forward(app, None));
            assert_scale_and_opacity(tester, &observed, 1.0, 0.5);
            tester.pump();
            assert_scale_and_opacity(tester, &observed, 1.0, 0.5);

            tester.pump_by(ms(75));
            assert_scale_and_opacity(tester, &observed, 1.0, 0.75);

            tester.pump_by(ms(75));
            assert_scale_and_opacity(tester, &observed, 1.0, 1.0);

            tester.pump_by(ms(300));
            assert_scale_and_opacity(tester, &observed, 1.0, 1.0);
            tester.update(|app| controller.dispose(app));
        });
    }

    /// Dart's `_StatefulTestWidget`, counting its state's life: `same(state)` is one `init_state`
    /// and no `dispose`.
    #[derive(Clone, Default)]
    struct Probe {
        inits: Rc<Cell<u32>>,
        disposes: Rc<Cell<u32>>,
    }

    impl Probe {
        fn widget(&self) -> WidgetRef {
            ProbeWidget {
                probe: self.clone(),
            }
            .into_widget()
        }
    }

    #[derive(Debug)]
    struct ProbeWidget {
        probe: Probe,
    }

    impl Debug for Probe {
        fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
            f.write_str("Probe")
        }
    }

    impl StatefulWidget for ProbeWidget {
        type State = ProbeState;

        fn create_state(&self) -> ProbeState {
            ProbeState {
                state: StateData::new(),
            }
        }
    }

    struct ProbeState {
        state: StateData<ProbeWidget>,
    }

    impl State for ProbeState {
        type Widget = ProbeWidget;
        crate::state_accessors!();

        fn init_state(self: Handle<Self>, app: &mut App) {
            let inits = &self.widget(app).probe.inits;
            inits.set(inits.get() + 1);
        }

        fn dispose(self: Handle<Self>, app: &mut App) {
            let disposes = &self.widget(app).probe.disposes;
            disposes.set(disposes.get() + 1);
        }

        fn build(self: Handle<Self>, _app: &mut App, _context: BuildContext) -> WidgetRef {
            SizedBox::new().width(10.0).height(10.0).into_widget()
        }
    }
}