crabshell-ui 0.5.0

Widgets, styles, layout, text and text editing, focus, hit testing and invalidation for Crabshell
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
//! Scroll views and lists: offsets, clamping, the wheel and building only
//! the rows in view.

use super::{Counter, Harness, node_at, paths, pixels, rect_at, wheel};
use crate::{
  Align, Button, Column, Icon, ListView, Point, PointerButton, Rect, Row, ScrollSource, ScrollView,
  Style, Text, Wheel, WheelAxis, Window,
};

/// A 50-pixel-tall scroll view of ten 20-pixel icons in a column.
fn ten_icons(h: &mut Harness, offset: crabshell_reactive::Signal<f32>) -> Window {
  let column = (0..10).fold(Column::new(), |column, _| {
    column.child(Icon::new("x").size(20))
  });
  let row = Row::new().align(Align::Start).child(
    ScrollView::new(column)
      .offset(offset)
      .style(Style::new().width(20.0).height(50.0)),
  );
  h.window(h.panel().child(row), 100.0, 100.0)
}

/// Where the column's first icon is.
fn first_icon(window: &Window) -> Rect {
  rect_at(window, &[0, 0, 0, 0])
}

#[test]
fn the_offset_moves_the_child_up_and_stops_at_either_end() {
  let mut h = Harness::new();
  let offset = h.cx.signal(30.0);
  let window = ten_icons(&mut h, offset);
  assert_eq!(rect_at(&window, &[0, 0]), Rect::new(0.0, 0.0, 20.0, 50.0));
  assert_eq!(first_icon(&window).y, -30.0);
  // 200 pixels of icons in a 50-pixel box scroll at most 150.
  offset.set(1000.0);
  h.frame(&window);
  assert_eq!(first_icon(&window).y, -150.0);
  offset.set(-5.0);
  h.frame(&window);
  assert_eq!(first_icon(&window).y, 0.0);
  // What the view reaches is cut to its box.
  assert_eq!(
    node_at(window.view().root(), &[0, 0]).bounds(),
    Rect::new(0.0, 0.0, 20.0, 50.0)
  );
}

#[test]
fn the_wheel_and_touchpad_scroll_the_view_under_the_pointer() {
  let mut h = Harness::new();
  let offset = h.cx.signal(0.0);
  let window = ten_icons(&mut h, offset);
  window.pointer_scroll(wheel(120));
  assert_eq!(offset.get(), 0.0, "nothing under the pointer yet");
  window.pointer_motion(Point::new(10.0, 10.0));
  window.pointer_scroll(wheel(120));
  assert_eq!(offset.get(), 48.0);
  h.frame(&window);
  assert_eq!(first_icon(&window).y, -48.0);
  window.pointer_scroll(pixels(-8.0));
  assert_eq!(offset.get(), 40.0);
  // Scrolling stops at the end instead of running past it.
  h.frame(&window);
  window.pointer_scroll(wheel(120 * 10));
  assert_eq!(offset.get(), 150.0);
  h.frame(&window);
  window.pointer_scroll(pixels(f32::NAN));
  assert_eq!(offset.get(), 150.0);
}

#[test]
fn a_button_with_on_scroll_takes_the_wheel_and_one_without_lets_it_through() {
  let mut h = Harness::new();
  let offset = h.cx.signal(0.0);
  let steps = Counter::default();
  let s = steps.clone();
  let column = Column::new()
    .child(Button::new(Icon::new("x").size(20)).on_scroll(move |_, _| s.hit()))
    .child(Button::new(Icon::new("x").size(20)))
    .child(Icon::new("x").size(100));
  let scroll = ScrollView::new(column)
    .offset(offset)
    .style(Style::new().height(50.0));
  let window = h.window(h.panel().child(scroll), 100.0, 100.0);
  window.pointer_motion(Point::new(10.0, 10.0));
  window.pointer_scroll(wheel(120));
  assert_eq!((steps.get(), offset.get()), (1, 0.0));
  window.pointer_motion(Point::new(10.0, 30.0));
  window.pointer_scroll(wheel(120));
  assert_eq!((steps.get(), offset.get()), (1, 48.0));
}

/// A list of `count` numbered rows, 20 pixels each, in a 100-pixel list.
fn numbers(
  h: &mut Harness,
  count: crabshell_reactive::Signal<u32>,
) -> (Window, crabshell_reactive::Signal<f32>) {
  let offset = h.cx.signal(0.0);
  let list = ListView::new(
    move || (0..count.get()).collect::<Vec<_>>(),
    |n| *n,
    |_, n| Text::new(move || n.get().to_string()),
  )
  .row_height(20)
  .height(100)
  .offset(offset);
  let window = h.window(h.panel().child(list), 100.0, 200.0);
  (window, offset)
}

/// The numbers of the rows built.
fn rows_built(window: &Window) -> Vec<String> {
  let view = window.view();
  // ListView, its scroll view, the rows' column; after the spacer, rows.
  let column = node_at(view.root(), &[0, 0, 0]);
  column
    .children()
    .skip(1)
    .map(
      |row| match row.children().next().map(|text| text.content()) {
        Some(crate::Content::Text(text)) => text.content().to_owned(),
        _ => String::from("?"),
      },
    )
    .collect()
}

#[test]
fn a_list_builds_only_the_rows_in_view_and_frees_the_rest() {
  let mut h = Harness::new();
  let count = h.cx.signal(1000);
  let (window, offset) = numbers(&mut h, count);
  h.frame(&window);
  // Rows 0 to 4 show; one more is built below.
  assert_eq!(rows_built(&window), ["0", "1", "2", "3", "4", "5"]);
  let built = h.runtime.node_count();

  offset.set(10_000.0);
  h.frame(&window);
  h.frame(&window);
  // Rows 500 to 504 show, with one more each side.
  assert_eq!(
    rows_built(&window),
    ["499", "500", "501", "502", "503", "504", "505"]
  );
  let row = |index: usize| rect_at(&window, &[0, 0, 0, index + 1]);
  assert_eq!(row(1).y, 0.0, "row 500 is at the top");
  // As many rows as before, give or take the extra one above.
  assert!(
    h.runtime.node_count() <= built + 8,
    "{} > {built}",
    h.runtime.node_count()
  );
  assert!(
    paths(&window)
      .iter()
      .any(|path| path.starts_with("PanelWindow[DP-1]/ListView"))
  );
}

#[test]
fn a_list_passes_its_scroll_bar_on() {
  let mut h = Harness::new();
  let list = ListView::new(
    || (0..50).collect::<Vec<u32>>(),
    |n| *n,
    |_, n| Text::new(move || n.get().to_string()),
  )
  .row_height(20)
  .height(100)
  .scroll_bar(Style::new());
  let window = h.window(h.panel().child(list), 100.0, 200.0);
  // The list's scroll view: 100 of 1000 pixels shown.
  let bar = node_at(window.view().root(), &[0, 0]).scroll_bar();
  assert_eq!(
    bar.map(|(rect, _)| rect),
    Some(Rect::new(94.0, 0.0, 6.0, 16.0))
  );
}

#[test]
fn a_list_that_shrinks_while_scrolled_shows_its_last_rows() {
  let mut h = Harness::new();
  let count = h.cx.signal(1000);
  let (window, offset) = numbers(&mut h, count);
  offset.set(10_000.0);
  h.frame(&window);
  count.set(8);
  h.frame(&window);
  h.frame(&window);
  // Eight rows scroll at most 60 pixels: rows 3 to 7 show.
  assert_eq!(rows_built(&window), ["2", "3", "4", "5", "6", "7"]);
}

#[test]
fn current_scrolls_as_little_as_needed_to_show_its_row() {
  let mut h = Harness::new();
  let current = h.cx.signal(Some(0_usize));
  let offset = h.cx.signal(0.0);
  let list = ListView::new(
    || (0..100).collect::<Vec<u32>>(),
    |n| *n,
    |_, n| Text::new(move || n.get().to_string()),
  )
  .row_height(20)
  .height(100)
  .current(move || current.get())
  .offset(offset);
  let window = h.window(h.panel().child(list), 100.0, 200.0);
  current.set(Some(4));
  h.frame(&window);
  assert_eq!(offset.get(), 0.0, "row 4 already shows");
  current.set(Some(5));
  h.frame(&window);
  assert_eq!(offset.get(), 20.0, "row 5 at the bottom");
  current.set(Some(50));
  h.frame(&window);
  assert_eq!(offset.get(), 920.0);
  current.set(Some(10));
  h.frame(&window);
  assert_eq!(offset.get(), 200.0, "row 10 at the top");
  current.set(None);
  h.frame(&window);
  assert_eq!(offset.get(), 200.0);
}

#[test]
fn dropping_a_list_frees_everything_it_made() {
  let mut h = Harness::new();
  let before = h.runtime.node_count();
  let count = h.cx.signal(100);
  let (window, offset) = numbers(&mut h, count);
  offset.set(500.0);
  h.frame(&window);
  drop(window);
  // The two signals the test made outlive the window.
  assert_eq!(h.runtime.node_count(), before + 2);
}

#[test]
fn a_row_that_panics_as_it_is_built_is_logged_and_the_rest_show() {
  let mut h = Harness::new();
  let list = ListView::new(
    || (0..5).collect::<Vec<u32>>(),
    |n| *n,
    |_, n| {
      assert!(n.get_untracked() != 2, "row failure");
      Text::new(move || n.get().to_string())
    },
  )
  .row_height(20)
  .height(100);
  let logs = super::capture_logs(|| {
    let window = h.window(h.panel().child(list), 100.0, 200.0);
    h.frame(&window);
    // Row 2 shows empty in its place.
    assert_eq!(rows_built(&window), ["0", "1", "?", "3", "4"]);
  });
  assert!(logs.contains("PanelWindow[DP-1]/ListView"), "{logs}");
  assert!(logs.contains("row failure"), "{logs}");
}

#[test]
fn scrolls_before_the_next_layout_add_up() {
  let mut h = Harness::new();
  let offset = h.cx.signal(0.0);
  let window = ten_icons(&mut h, offset);
  window.pointer_motion(Point::new(10.0, 10.0));
  window.pointer_scroll(wheel(120));
  window.pointer_scroll(wheel(120));
  assert_eq!(offset.get(), 96.0);
  // A config's own write counts too.
  offset.set(10.0);
  window.pointer_scroll(pixels(5.0));
  assert_eq!(offset.get(), 15.0);
}

#[test]
fn scrolling_with_an_offset_whose_owner_is_gone_does_nothing() {
  let mut h = Harness::new();
  let gone = h.cx.child();
  let offset = gone.signal(0.0);
  let window = ten_icons(&mut h, offset);
  gone.owner().dispose();
  window.pointer_motion(Point::new(10.0, 10.0));
  window.pointer_scroll(wheel(120));
  h.frame(&window);
}

#[test]
fn the_wheel_scrolls_a_list_and_current_allows_for_its_padding() {
  let mut h = Harness::new();
  let current = h.cx.signal(None::<usize>);
  let offset = h.cx.signal(0.0);
  let list = ListView::new(
    || (0..100).collect::<Vec<u32>>(),
    |n| *n,
    |_, n| Text::new(move || n.get().to_string()),
  )
  .row_height(20)
  .height(100)
  .current(move || current.get())
  .offset(offset)
  .style(Style::new().padding(10, 0));
  let window = h.window(h.panel().child(list), 100.0, 200.0);
  window.pointer_motion(Point::new(10.0, 50.0));
  window.pointer_scroll(wheel(120));
  assert_eq!(offset.get(), 48.0);
  // 80 pixels show inside the padding: row 7 ends at 160.
  offset.set(0.0);
  current.set(Some(7));
  h.frame(&window);
  assert_eq!(offset.get(), 80.0);
}

#[test]
fn current_allows_for_padding_that_differs_above_and_below() {
  let mut h = Harness::new();
  let current = h.cx.signal(None::<usize>);
  let offset = h.cx.signal(0.0);
  let list = ListView::new(
    || (0..100).collect::<Vec<u32>>(),
    |n| *n,
    |_, n| Text::new(move || n.get().to_string()),
  )
  .row_height(20)
  .height(100)
  .current(move || current.get())
  .offset(offset)
  .style(Style::new().padding_top(10).padding_bottom(30));
  let window = h.window(h.panel().child(list), 100.0, 200.0);
  // 60 pixels show between the paddings: row 7 ends at 160.
  current.set(Some(7));
  h.frame(&window);
  assert_eq!(offset.get(), 100.0);
}

/// A 50 by 20 horizontal view of ten 20-pixel icons in a row.
fn ten_across(h: &mut Harness, offset: crabshell_reactive::Signal<f32>) -> Window {
  let row = (0..10).fold(Row::new(), |row, _| row.child(Icon::new("x").size(20)));
  let view = ScrollView::new(row)
    .horizontal(true)
    .offset(offset)
    .style(Style::new().width(50.0).height(20.0));
  let outer = Row::new().align(Align::Start).child(view);
  h.window(h.panel().child(outer), 100.0, 100.0)
}

fn sideways(axis: WheelAxis, source: ScrollSource) -> Wheel {
  Wheel {
    source,
    x: axis,
    y: WheelAxis::default(),
  }
}

#[test]
fn a_horizontal_view_lays_its_child_out_at_full_width_and_scrolls_sideways() {
  let mut h = Harness::new();
  let offset = h.cx.signal(30.0);
  let window = ten_across(&mut h, offset);
  assert_eq!(rect_at(&window, &[0, 0, 0]).width, 200.0);
  assert_eq!(first_icon(&window).x, -30.0);
  offset.set(1000.0);
  h.frame(&window);
  assert_eq!(first_icon(&window).x, -150.0);
  offset.set(0.0);
  h.frame(&window);
  window.pointer_motion(Point::new(10.0, 10.0));
  // A turned wheel scrolls it sideways, having nothing else to do.
  window.pointer_scroll(wheel(120));
  assert_eq!(offset.get(), 48.0);
  let tilt = WheelAxis {
    pixels: 15.0,
    notches: 1.0,
    stop: false,
  };
  window.pointer_scroll(sideways(tilt, ScrollSource::WheelTilt));
  assert_eq!(offset.get(), 96.0);
  let finger = WheelAxis {
    pixels: -6.0,
    ..WheelAxis::default()
  };
  window.pointer_scroll(sideways(finger, ScrollSource::Finger));
  assert_eq!(offset.get(), 90.0);
  // A touchpad's up and down is for a view around it.
  window.pointer_scroll(pixels(10.0));
  assert_eq!(offset.get(), 90.0);
}

#[test]
fn the_innermost_view_that_can_still_move_takes_the_wheel() {
  let mut h = Harness::new();
  let (inner, outer) = (h.cx.signal(0.0), h.cx.signal(0.0));
  let column = (0..3).fold(Column::new(), |column, _| {
    column.child(Icon::new("x").size(20))
  });
  let content = Column::new()
    .child(
      ScrollView::new(column)
        .offset(inner)
        .style(Style::new().height(30.0)),
    )
    .child(Icon::new("x").size(100));
  let view = ScrollView::new(content)
    .offset(outer)
    .style(Style::new().height(50.0));
  let window = h.window(h.panel().child(view), 100.0, 100.0);
  window.pointer_motion(Point::new(10.0, 10.0));
  window.pointer_scroll(wheel(120));
  assert_eq!(
    (inner.get(), outer.get()),
    (30.0, 0.0),
    "the inner one, to its end"
  );
  h.frame(&window);
  window.pointer_scroll(wheel(120));
  assert_eq!(
    (inner.get(), outer.get()),
    (30.0, 48.0),
    "then the outer one"
  );
  h.frame(&window);
  // Over the inner view again, up moves it first: it can.
  window.pointer_scroll(wheel(-120));
  assert_eq!(
    (inner.get(), outer.get()),
    (30.0, 0.0),
    "out of sight above"
  );
  h.frame(&window);
  window.pointer_scroll(wheel(-120));
  assert_eq!((inner.get(), outer.get()), (0.0, 0.0));
}

/// A 40 by 100 view of 200 pixels of icons, with a bordered box and a
/// four-pixel bar.
fn barred(h: &mut Harness, offset: crabshell_reactive::Signal<f32>) -> (Window, Counter) {
  let clicks = Counter::default();
  let c = clicks.clone();
  let column = Column::new()
    .child(Button::new(Icon::new("x").size(40)).on_click(move |_| c.hit()))
    .child(Icon::new("x").size(160));
  let view = ScrollView::new(column)
    .offset(offset)
    .scroll_bar(
      Style::new()
        .width(4.0)
        .radius(2.0)
        .background(crate::Color::rgb(1, 2, 3)),
    )
    .style(Style::new().width(40.0).height(100.0));
  let row = Row::new().align(Align::Start).child(view);
  (h.window(h.panel().child(row), 100.0, 200.0), clicks)
}

fn bar(window: &Window) -> Option<Rect> {
  node_at(window.view().root(), &[0, 0])
    .scroll_bar()
    .map(|(rect, _)| rect)
}

#[test]
fn a_scroll_bar_is_as_long_as_the_part_shown_and_placed_by_the_offset() {
  let mut h = Harness::new();
  let offset = h.cx.signal(0.0);
  let (window, _) = barred(&mut h, offset);
  // A 100-pixel view of 200 shows half: a 50-pixel handle at the top.
  assert_eq!(bar(&window), Some(Rect::new(36.0, 0.0, 4.0, 50.0)));
  offset.set(50.0);
  h.frame(&window);
  assert_eq!(bar(&window), Some(Rect::new(36.0, 25.0, 4.0, 50.0)));
  // Content that fits shows none, and a view without one never does.
  let fits = ScrollView::new(Icon::new("x").size(20))
    .scroll_bar(Style::new())
    .style(Style::new().height(50.0));
  let plain = ScrollView::new(Icon::new("x").size(200)).style(Style::new().height(50.0));
  let row = Row::new().align(Align::Start).child(fits).child(plain);
  let other = h.window(h.panel().child(row), 100.0, 100.0);
  assert_eq!(node_at(other.view().root(), &[0, 0]).scroll_bar(), None);
  assert_eq!(node_at(other.view().root(), &[0, 1]).scroll_bar(), None);
}

#[test]
fn a_bar_sits_inside_the_border_and_along_the_bottom_of_a_horizontal_view() {
  let mut h = Harness::new();
  let row = (0..10).fold(Row::new(), |row, _| row.child(Icon::new("x").size(20)));
  let view = ScrollView::new(row)
    .horizontal(true)
    .scroll_bar(Style::new())
    .style(
      Style::new()
        .width(54.0)
        .height(30.0)
        .border(2.0, crate::Color::rgb(0, 0, 0)),
    );
  let outer = Row::new().align(Align::Start).child(view);
  let window = h.window(h.panel().child(outer), 100.0, 100.0);
  // 54 of 204 shown would be 13 of the 50 inside the border, under the
  // shortest handle; 6 thick by default.
  assert_eq!(bar(&window), Some(Rect::new(2.0, 22.0, 16.0, 6.0)));
}

#[test]
fn dragging_the_bar_scrolls_and_a_press_beside_it_pages() {
  let mut h = Harness::new();
  let offset = h.cx.signal(0.0);
  let (window, clicks) = barred(&mut h, offset);
  // The handle's 50 pixels of room stand for 100 of content.
  window.pointer_motion(Point::new(38.0, 10.0));
  window.pointer_button_at(PointerButton::Left, true, 0);
  window.pointer_motion(Point::new(60.0, 35.0));
  assert_eq!(offset.get(), 50.0);
  window.pointer_motion(Point::new(38.0, 500.0));
  assert_eq!(offset.get(), 100.0);
  window.pointer_button_at(PointerButton::Left, false, 50);
  window.pointer_motion(Point::new(38.0, 600.0));
  assert_eq!(offset.get(), 100.0, "let go");
  h.frame(&window);
  // The handle is at 50 to 100 now; a press above it pages up.
  window.pointer_motion(Point::new(38.0, 20.0));
  window.pointer_button_at(PointerButton::Left, true, 100);
  window.pointer_button_at(PointerButton::Left, false, 150);
  assert_eq!(offset.get(), 0.0);
  h.frame(&window);
  // The bar covers the button below it, which doesn't click.
  assert_eq!(clicks.get(), 0);
  window.pointer_motion(Point::new(10.0, 20.0));
  window.pointer_button_at(PointerButton::Left, true, 200);
  window.pointer_button_at(PointerButton::Left, false, 250);
  assert_eq!(clicks.get(), 1);
}

#[test]
fn a_button_drawn_over_a_view_keeps_its_press_from_the_bar_and_a_drag() {
  let mut h = Harness::new();
  let offset = h.cx.signal(0.0);
  let (left, right) = (Counter::default(), Counter::default());
  let (l, r) = (left.clone(), right.clone());
  let corner = |align| Style::new().align_self(Align::Start).justify_self(align);
  let overlay = crate::Stack::new()
    .child(
      ScrollView::new(Icon::new("x").size(400))
        .offset(offset)
        .scroll_bar(Style::new())
        .style(Style::new().width(40.0).height(100.0)),
    )
    .child(
      Button::new(Icon::new("x").size(10))
        .style(corner(Align::Start))
        .on_click(move |_| l.hit()),
    )
    .child(
      Button::new(Icon::new("x").size(10))
        .style(corner(Align::End))
        .on_click(move |_| r.hit()),
    );
  let row = Row::new().align(Align::Start).child(overlay);
  let window = h.window(h.panel().child(row), 100.0, 200.0);
  // The close button in the corner sits in the bar's track, below the
  // handle once the view is scrolled.
  offset.set(300.0);
  h.frame(&window);
  window.pointer_motion(Point::new(37.0, 5.0));
  window.pointer_button_at(PointerButton::Left, true, 0);
  window.pointer_button_at(PointerButton::Left, false, 50);
  assert_eq!((right.get(), offset.get()), (1, 300.0), "no page");
  // A move past the threshold on the other button doesn't drag the view.
  window.pointer_motion_at(Point::new(5.0, 5.0), 100);
  window.pointer_button_at(PointerButton::Left, true, 100);
  window.pointer_motion_at(Point::new(5.0, 40.0), 200);
  window.pointer_motion_at(Point::new(5.0, 5.0), 300);
  window.pointer_button_at(PointerButton::Left, false, 400);
  assert_eq!((left.get(), offset.get()), (1, 300.0), "no drag");
}