smudge-core 0.1.0

Widget tree, reactive bindings, layout, paint and damage tracking for the Smudge GUI library
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
//! Behavior tests for hit testing, hover and press.
//!
//! Every test drives the same `App::handle_event` a window does, through the
//! harness, and observes the handlers the tree runs.

use std::cell::{Cell, RefCell};
use std::rc::Rc;

use smudge_core::element::{IntoElement, show};
use smudge_core::geometry::{Color, Point};
use smudge_core::input::{InputEvent, PointerButton};
use smudge_core::reactive::{self, prelude::*};
use smudge_core::style::px;
use smudge_core::widget::panel;
use smudge_test::Harness;

/// A counter shared with a handler.
type Count = Rc<Cell<u32>>;

/// A counter with a handler closure that increments it.
fn press_counter() -> (Count, impl FnMut()) {
    let count = Rc::new(Cell::new(0u32));
    let handler = {
        let count = Rc::clone(&count);
        move || count.set(count.get() + 1)
    };
    (count, handler)
}

/// A log of hover changes, shared between a test and its handler.
type HoverLog = Rc<RefCell<Vec<(&'static str, bool)>>>;

/// A log of hover changes with a handler closure that appends to it.
fn hover_log(name: &'static str) -> (HoverLog, impl FnMut(bool)) {
    let log = Rc::new(RefCell::new(Vec::new()));
    let handler = {
        let log = Rc::clone(&log);
        move |hovered: bool| log.borrow_mut().push((name, hovered))
    };
    (log, handler)
}

/// Wraps a node under test in a plain parent.
///
/// The layout pass sizes the root to the whole viewport, whatever its style
/// says, so a node with a size of its own has to sit under the root.
fn scene(child: impl IntoElement) -> impl IntoElement {
    panel().child(child)
}

#[test]
fn a_click_on_a_panel_presses_it_once() {
    let (presses, on_press) = press_counter();
    let mut harness = Harness::new(100.0, 60.0, 1.0, move || {
        scene(
            panel()
                .width(px(40.0))
                .height(px(20.0))
                .background(Color::BLACK)
                .on_press(on_press),
        )
    });
    harness.frame();

    harness.click(Point { x: 10.0, y: 5.0 });
    assert_eq!(presses.get(), 1, "a click inside the panel presses it");

    harness.click(Point { x: 80.0, y: 50.0 });
    assert_eq!(
        presses.get(),
        1,
        "a click outside the panel presses nothing"
    );
}

#[test]
fn pressing_moving_off_and_releasing_does_not_press() {
    let (presses, on_press) = press_counter();
    let mut harness = Harness::new(100.0, 60.0, 1.0, move || {
        scene(
            panel()
                .width(px(40.0))
                .height(px(20.0))
                .background(Color::BLACK)
                .on_press(on_press),
        )
    });
    harness.frame();

    let inside = Point { x: 10.0, y: 5.0 };
    let outside = Point { x: 80.0, y: 50.0 };
    harness.event(InputEvent::PointerDown {
        position: inside,
        button: PointerButton::Primary,
    });
    harness.move_to(outside);
    harness.event(InputEvent::PointerUp {
        position: outside,
        button: PointerButton::Primary,
    });
    assert_eq!(presses.get(), 0, "the release happened off the panel");

    harness.event(InputEvent::PointerDown {
        position: inside,
        button: PointerButton::Primary,
    });
    harness.move_to(outside);
    harness.move_to(inside);
    harness.event(InputEvent::PointerUp {
        position: inside,
        button: PointerButton::Primary,
    });
    assert_eq!(
        presses.get(),
        1,
        "the release happened over the panel again"
    );
}

#[test]
fn a_child_over_its_parent_takes_the_press() {
    let (parent_presses, parent_on_press) = press_counter();
    let (child_presses, child_on_press) = press_counter();
    let mut harness = Harness::new(100.0, 60.0, 1.0, move || {
        scene(
            panel()
                .width(px(60.0))
                .height(px(60.0))
                .background(Color::BLACK)
                .on_press(parent_on_press)
                .child(
                    panel()
                        .width(px(40.0))
                        .height(px(40.0))
                        .background(Color::WHITE)
                        .on_press(child_on_press),
                ),
        )
    });
    harness.frame();

    harness.click(Point { x: 30.0, y: 30.0 });
    assert_eq!(
        child_presses.get(),
        1,
        "the child is painted above the parent"
    );
    assert_eq!(
        parent_presses.get(),
        0,
        "the press does not reach the parent"
    );
}

#[test]
fn a_node_is_not_hit_beyond_its_parents_clip() {
    let (presses, on_press) = press_counter();
    let mut harness = Harness::new(100.0, 60.0, 1.0, move || {
        scene(
            panel().width(px(40.0)).height(px(40.0)).clip(true).child(
                panel()
                    .width(px(80.0))
                    .height(px(80.0))
                    .background(Color::BLACK)
                    .on_press(on_press),
            ),
        )
    });
    harness.frame();

    harness.click(Point { x: 20.0, y: 10.0 });
    assert_eq!(presses.get(), 1, "the visible part of the child is hit");

    harness.click(Point { x: 60.0, y: 10.0 });
    assert_eq!(
        presses.get(),
        1,
        "the part of the child the parent clips away is not hit"
    );
}

#[test]
fn a_disabled_node_receives_no_presses() {
    let (disabled_presses, disabled_on_press) = press_counter();
    let (enabled_presses, enabled_on_press) = press_counter();
    let mut harness = Harness::new(100.0, 60.0, 1.0, move || {
        scene(
            panel()
                .width(px(80.0))
                .height(px(40.0))
                .child(
                    panel()
                        .width(px(40.0))
                        .height(px(40.0))
                        .background(Color::BLACK)
                        .disabled(true)
                        .on_press(disabled_on_press),
                )
                .child(
                    panel()
                        .width(px(40.0))
                        .height(px(40.0))
                        .background(Color::rgb(200, 60, 60))
                        .on_press(enabled_on_press),
                ),
        )
    });
    harness.frame();

    harness.click(Point { x: 20.0, y: 20.0 });
    assert_eq!(disabled_presses.get(), 0, "the disabled node is not hit");

    harness.click(Point { x: 60.0, y: 20.0 });
    assert_eq!(enabled_presses.get(), 1, "the enabled sibling is hit");
}

#[test]
fn moving_between_siblings_swaps_hover_in_order() {
    let (left_log, left_on_hover) = hover_log("left");
    let (right_log, right_on_hover) = hover_log("right");
    let mut harness = Harness::new(100.0, 60.0, 1.0, move || {
        scene(
            panel()
                .width(px(80.0))
                .height(px(20.0))
                .child(
                    panel()
                        .width(px(40.0))
                        .height(px(20.0))
                        .background(Color::BLACK)
                        .on_hover(left_on_hover),
                )
                .child(
                    panel()
                        .width(px(40.0))
                        .height(px(20.0))
                        .background(Color::WHITE)
                        .on_hover(right_on_hover),
                ),
        )
    });
    harness.frame();

    harness.move_to(Point { x: 20.0, y: 10.0 });
    assert_eq!(*left_log.borrow(), [("left", true)]);
    assert!(right_log.borrow().is_empty());

    harness.move_to(Point { x: 60.0, y: 10.0 });
    assert_eq!(*left_log.borrow(), [("left", true), ("left", false)]);
    assert_eq!(*right_log.borrow(), [("right", true)]);
}

#[test]
fn moves_during_a_held_press_stay_with_the_captured_node() {
    let (presses, on_press) = press_counter();
    let (log, on_hover) = hover_log("panel");
    let mut harness = Harness::new(100.0, 60.0, 1.0, move || {
        scene(
            panel()
                .width(px(40.0))
                .height(px(20.0))
                .background(Color::BLACK)
                .on_press(on_press)
                .on_hover(on_hover),
        )
    });
    harness.frame();

    let inside = Point { x: 10.0, y: 5.0 };
    let outside = Point { x: 80.0, y: 50.0 };
    harness.move_to(inside);
    assert_eq!(*log.borrow(), [("panel", true)]);

    harness.event(InputEvent::PointerDown {
        position: inside,
        button: PointerButton::Primary,
    });
    harness.move_to(outside);
    assert_eq!(
        *log.borrow(),
        [("panel", true)],
        "the captured node keeps the pointer while the press is held"
    );

    harness.event(InputEvent::PointerUp {
        position: outside,
        button: PointerButton::Primary,
    });
    assert_eq!(
        *log.borrow(),
        [("panel", true), ("panel", false)],
        "the pointer follows the cursor again after the release"
    );
    assert_eq!(
        presses.get(),
        0,
        "the release happened off the captured node"
    );
}

#[test]
fn a_press_outside_a_popup_runs_its_outside_handler() {
    let (outside_presses, on_press_outside) = press_counter();
    let (child_presses, child_on_press) = press_counter();
    let mut harness = Harness::new(100.0, 60.0, 1.0, move || {
        scene(
            panel()
                .width(px(30.0))
                .height(px(20.0))
                .background(Color::BLACK)
                .on_press_outside(on_press_outside)
                .child(
                    panel()
                        .width(px(10.0))
                        .height(px(10.0))
                        .background(Color::WHITE)
                        .on_press(child_on_press),
                ),
        )
    });
    harness.frame();

    harness.click(Point { x: 5.0, y: 5.0 });
    assert_eq!(child_presses.get(), 1);
    assert_eq!(
        outside_presses.get(),
        0,
        "a press on a descendant is not outside the popup"
    );

    harness.click(Point { x: 20.0, y: 15.0 });
    assert_eq!(
        outside_presses.get(),
        0,
        "a press on the popup itself is not outside it"
    );

    harness.click(Point { x: 60.0, y: 30.0 });
    assert_eq!(outside_presses.get(), 1, "a press elsewhere is outside");
}

#[test]
fn another_button_during_a_held_press_keeps_the_capture() {
    let (log, on_hover) = hover_log("panel");
    let mut harness = Harness::new(100.0, 60.0, 1.0, move || {
        scene(
            panel()
                .width(px(40.0))
                .height(px(20.0))
                .background(Color::BLACK)
                .on_press(|| {})
                .on_hover(on_hover),
        )
    });
    harness.frame();

    let inside = Point { x: 10.0, y: 5.0 };
    let outside = Point { x: 80.0, y: 50.0 };
    harness.move_to(inside);
    harness.event(InputEvent::PointerDown {
        position: inside,
        button: PointerButton::Primary,
    });
    harness.event(InputEvent::PointerDown {
        position: outside,
        button: PointerButton::Secondary,
    });

    assert_eq!(
        *log.borrow(),
        [("panel", true)],
        "a secondary press while the primary is held leaves the captured node hovered"
    );
}

#[test]
fn a_press_on_the_content_of_a_disabled_node_runs_none_of_its_handlers() {
    let (presses, on_press) = press_counter();
    let mut harness = Harness::new(100.0, 60.0, 1.0, move || {
        scene(
            panel()
                .width(px(40.0))
                .height(px(40.0))
                .on_press(on_press)
                .disabled(true)
                .child(panel().width(px(10.0)).height(px(10.0))),
        )
    });
    harness.frame();

    harness.click(Point { x: 5.0, y: 5.0 });

    assert_eq!(
        presses.get(),
        0,
        "a disabled node swallows a press on its content"
    );
}

#[test]
fn a_container_stays_hovered_over_a_disabled_control_inside_it() {
    let (log, on_card_hover) = hover_log("card");
    let (control_log, on_control_hover) = hover_log("control");
    let mut harness = Harness::new(100.0, 60.0, 1.0, move || {
        scene(
            panel()
                .width(px(60.0))
                .height(px(40.0))
                .on_hover(on_card_hover)
                .child(
                    panel()
                        .width(px(30.0))
                        .height(px(30.0))
                        .focusable()
                        .on_hover(on_control_hover)
                        .disabled(true)
                        .child(panel().width(px(10.0)).height(px(10.0))),
                ),
        )
    });
    harness.frame();

    harness.move_to(Point { x: 50.0, y: 35.0 });
    harness.move_to(Point { x: 5.0, y: 5.0 });
    harness.move_to(Point { x: 50.0, y: 35.0 });

    assert_eq!(
        *log.borrow(),
        [("card", true)],
        "the card stays hovered while the pointer crosses the disabled control"
    );
    assert!(
        control_log.borrow().is_empty(),
        "a disabled control hears no hover"
    );
}

#[test]
fn a_press_released_over_a_disabled_control_inside_the_node_still_presses_it() {
    let (presses, on_press) = press_counter();
    let mut harness = Harness::new(100.0, 60.0, 1.0, move || {
        scene(
            panel()
                .width(px(60.0))
                .height(px(40.0))
                .on_press(on_press)
                .child(
                    panel()
                        .width(px(30.0))
                        .height(px(30.0))
                        .focusable()
                        .disabled(true)
                        .child(panel().width(px(10.0)).height(px(10.0))),
                ),
        )
    });
    harness.frame();

    harness.event(InputEvent::PointerDown {
        position: Point { x: 50.0, y: 35.0 },
        button: PointerButton::Primary,
    });
    harness.event(InputEvent::PointerUp {
        position: Point { x: 5.0, y: 5.0 },
        button: PointerButton::Primary,
    });

    assert_eq!(
        presses.get(),
        1,
        "the release landed inside the pressed card"
    );
}

#[test]
fn a_node_disabled_during_its_press_does_not_run_on_press() {
    let (disabled, set_disabled) = reactive::signal_local(false);
    let (presses, on_press) = press_counter();
    let mut harness = Harness::new(100.0, 60.0, 1.0, move || {
        scene(
            panel()
                .width(px(60.0))
                .height(px(40.0))
                .on_press(on_press)
                .disabled(move || disabled.get())
                .child(panel().width(px(20.0)).height(px(20.0)).on_hover(|_| {})),
        )
    });
    harness.frame();

    harness.event(InputEvent::PointerDown {
        position: Point { x: 50.0, y: 35.0 },
        button: PointerButton::Primary,
    });
    set_disabled.set(true);
    harness.frame();
    harness.event(InputEvent::PointerUp {
        position: Point { x: 10.0, y: 10.0 },
        button: PointerButton::Primary,
    });

    assert_eq!(
        presses.get(),
        0,
        "a node disabled mid-press runs no on_press"
    );
}

#[test]
fn a_hidden_or_disabled_node_hears_no_press_outside() {
    let (hidden_presses, on_hidden_outside) = press_counter();
    let (disabled_presses, on_disabled_outside) = press_counter();
    let mut harness = Harness::new(100.0, 60.0, 1.0, move || {
        scene(
            panel()
                .width(px(60.0))
                .height(px(20.0))
                .child(
                    panel()
                        .width(px(20.0))
                        .height(px(20.0))
                        .on_press_outside(on_hidden_outside)
                        .hidden(true),
                )
                .child(
                    panel()
                        .width(px(20.0))
                        .height(px(20.0))
                        .on_press_outside(on_disabled_outside)
                        .disabled(true),
                ),
        )
    });
    harness.frame();

    harness.click(Point { x: 80.0, y: 50.0 });

    assert_eq!(
        hidden_presses.get(),
        0,
        "a closed popup hears no outside press"
    );
    assert_eq!(
        disabled_presses.get(),
        0,
        "a disabled node's handlers never run"
    );
}

/// A log of pointer positions, shared between a test and its handler.
type PointLog = Rc<RefCell<Vec<Point>>>;

/// A log of positions with a handler closure that appends to it.
fn point_log() -> (PointLog, impl FnMut(Point)) {
    let log = Rc::new(RefCell::new(Vec::new()));
    let handler = {
        let log = Rc::clone(&log);
        move |position: Point| log.borrow_mut().push(position)
    };
    (log, handler)
}

#[test]
fn a_drag_sends_every_move_and_the_release_to_the_pressed_node() {
    let (moves, on_move) = point_log();
    let (ups, on_up) = point_log();
    let mut harness = Harness::new(100.0, 60.0, 1.0, move || {
        scene(
            panel()
                .row()
                .child(
                    panel()
                        .width(px(40.0))
                        .height(px(20.0))
                        .on_pointer_move(on_move)
                        .on_pointer_up(on_up),
                )
                .child(panel().width(px(40.0)).height(px(20.0)).on_press(|| {})),
        )
    });
    harness.frame();

    let inside = Point { x: 10.0, y: 5.0 };
    let beside = Point { x: 60.0, y: 5.0 };
    let outside = Point { x: 90.0, y: 50.0 };
    harness.button_down(inside);
    harness.move_to(beside);
    harness.event(InputEvent::PointerLeft);
    harness.move_to(outside);
    harness.button_up(outside);
    assert_eq!(
        *moves.borrow(),
        [inside, beside, outside],
        "the pressed node hears every move of the drag, over a sibling and \
         after the pointer left and came back"
    );
    assert_eq!(
        *ups.borrow(),
        [outside],
        "the release reaches the pressed node away from it"
    );

    moves.borrow_mut().clear();
    harness.move_to(beside);
    harness.move_to(inside);
    assert_eq!(
        *moves.borrow(),
        [inside],
        "with no press held, only the node under the pointer hears a move"
    );
}

#[test]
fn a_press_held_across_a_scroll_hears_positions_from_where_the_node_went() {
    let (moves, on_move) = point_log();
    let (ups, on_up) = point_log();
    let (offset, set_offset) = reactive::signal_local(0.0_f32);
    let mut harness = Harness::new(100.0, 60.0, 1.0, move || {
        scene(
            panel()
                .height(px(40.0))
                .clip(true)
                .scroll_offset(move || Point {
                    x: offset.get(),
                    y: 0.0,
                })
                .child(
                    panel()
                        .width(px(40.0))
                        .height(px(20.0))
                        .on_press(|| {})
                        .on_pointer_move(on_move)
                        .on_pointer_up(on_up),
                ),
        )
    });
    harness.frame();

    harness.button_down(Point { x: 20.0, y: 5.0 });
    set_offset.set(10.0);
    harness.frame();
    harness.move_to(Point { x: 20.0, y: 5.0 });
    harness.button_up(Point { x: 20.0, y: 5.0 });

    assert_eq!(
        *moves.borrow(),
        [Point { x: 20.0, y: 5.0 }, Point { x: 30.0, y: 5.0 }],
        "the node moved 10 to the left under the held pointer"
    );
    assert_eq!(*ups.borrow(), [Point { x: 30.0, y: 5.0 }]);
}

#[test]
fn pointer_handlers_measure_from_the_node_and_follow_its_scroll() {
    let (downs, on_down) = point_log();
    let (moves, on_move) = point_log();
    let (ups, on_up) = point_log();
    let (offset, set_offset) = reactive::signal_local(0.0_f32);
    let mut harness = Harness::new(100.0, 60.0, 1.0, move || {
        scene(
            panel()
                .padding(px(10.0))
                .height(px(40.0))
                .clip(true)
                .scroll_offset(move || Point {
                    x: offset.get(),
                    y: 0.0,
                })
                .child(
                    panel()
                        .width(px(40.0))
                        .height(px(20.0))
                        .margin(px(5.0))
                        .on_pointer_down(on_down)
                        .on_pointer_move(on_move)
                        .on_pointer_up(on_up),
                ),
        )
    });
    harness.frame();

    harness.button_down(Point { x: 18.0, y: 17.0 });
    harness.move_to(Point { x: 30.0, y: 20.0 });
    harness.button_up(Point { x: 30.0, y: 20.0 });
    set_offset.set(10.0);
    harness.frame();
    harness.button_down(Point { x: 18.0, y: 17.0 });

    assert_eq!(
        *downs.borrow(),
        [Point { x: 3.0, y: 2.0 }, Point { x: 13.0, y: 2.0 }],
        "a press is relative to the node, which the scroll moved 10 to the left"
    );
    assert_eq!(
        *moves.borrow(),
        [
            Point { x: 3.0, y: 2.0 },
            Point { x: 15.0, y: 5.0 },
            Point { x: 13.0, y: 2.0 }
        ],
        "every move a press brings is relative to the node too"
    );
    assert_eq!(*ups.borrow(), [Point { x: 15.0, y: 5.0 }]);
}

#[test]
fn a_second_press_without_a_release_ends_the_first_drag() {
    let (ups, on_up) = point_log();
    let mut harness = Harness::new(100.0, 60.0, 1.0, move || {
        scene(
            panel()
                .row()
                .child(
                    panel()
                        .width(px(40.0))
                        .height(px(20.0))
                        .on_pointer_up(on_up),
                )
                .child(panel().width(px(40.0)).height(px(20.0)).on_press(|| {})),
        )
    });
    harness.frame();

    harness.button_down(Point { x: 10.0, y: 5.0 });
    harness.button_down(Point { x: 60.0, y: 5.0 });

    assert_eq!(
        *ups.borrow(),
        [Point { x: 60.0, y: 5.0 }],
        "the first node hears its press end where the second press landed"
    );
}

#[test]
fn a_disabled_node_hears_no_moves_or_release() {
    let (moves, on_move) = point_log();
    let (ups, on_up) = point_log();
    let (disabled, set_disabled) = reactive::signal_local(false);
    let mut harness = Harness::new(100.0, 60.0, 1.0, move || {
        scene(
            panel()
                .width(px(40.0))
                .height(px(20.0))
                .disabled(move || disabled.get())
                .on_pointer_move(on_move)
                .on_pointer_up(on_up),
        )
    });
    harness.frame();

    let inside = Point { x: 10.0, y: 5.0 };
    harness.button_down(inside);
    set_disabled.set(true);
    harness.frame();
    harness.move_to(Point { x: 20.0, y: 5.0 });
    harness.button_up(inside);
    assert_eq!(*moves.borrow(), [inside], "only the move before disabling");
    assert!(ups.borrow().is_empty(), "a disabled node hears no release");
}

#[test]
fn removing_the_pressed_node_lets_hover_follow_the_pointer_again() {
    let (shown, set_shown) = reactive::signal_local(true);
    let (log, on_hover) = hover_log("sibling");
    let mut harness = Harness::new(100.0, 60.0, 1.0, move || {
        scene(
            panel()
                .row()
                .child(show(
                    move || shown.get(),
                    || panel().width(px(40.0)).height(px(20.0)).on_press(|| {}),
                ))
                .child(panel().width(px(40.0)).height(px(20.0)).on_hover(on_hover)),
        )
    });
    harness.frame();

    harness.button_down(Point { x: 10.0, y: 5.0 });
    set_shown.set(false);
    harness.frame();
    harness.move_to(Point { x: 10.0, y: 5.0 });
    assert_eq!(
        *log.borrow(),
        [("sibling", true)],
        "the sibling took the place of the removed node and is hovered"
    );
}