crcbl-ui 0.20.0

Crucible immediate-mode GUI
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
//! Dock layouts: the value's own editing, a nested layout's geometry, a drag
//! written back into the value, the clamping a nested divider keeps, a layout
//! saved and restored into a tree that never saw it, one name held twice, and
//! a layout nested four levels deep.

use super::*;
use crate::tree::{DockLayout, DockSide, Response, SplitAxis};

/// How wide the dock is, in pixels.
const WIDTH: f32 = 240.0;
/// How tall it is.
const HEIGHT: f32 = 120.0;
/// Each pane's minimum length along its split.
const MIN: [f32; 2] = [30.0, 40.0];
/// `default.css`'s divider thickness.
const DIVIDER: f32 = 4.0;

/// What one frame of the dock page built.
struct DockPage {
    dock: Response,
    /// The block each pane's builder made, by the pane's name, in build order.
    panes: Vec<(String, NodeKey)>,
}

impl DockPage {
    /// The key of the block the pane called `name` built.
    fn pane(&self, name: &str) -> NodeKey {
        self.panes
            .iter()
            .find(|(each, _)| each == name)
            .map(|(_, key)| *key)
            .unwrap_or_else(|| panic!("{name} was not built"))
    }

    /// Every pane's name, in build order.
    fn names(&self) -> Vec<&str> {
        self.panes.iter().map(|(name, _)| name.as_str()).collect()
    }
}

fn dock_page(
    ui: &mut Ui,
    layout: &mut DockLayout,
    pointer: PointerInput,
    nav: NavInput,
) -> DockPage {
    frame(ui, pointer, nav, |ui| {
        let mut panes = Vec::new();
        let mut dock = None;
        ui.block(
            "",
            &[
                Declaration::Width(LengthAuto::Px(WIDTH)),
                Declaration::Height(LengthAuto::Px(HEIGHT)),
            ],
            |ui| {
                dock = Some(ui.dock("#docks", layout, MIN, |ui, name| {
                    let key = ui.block("", &[], |_| {}).key;
                    panes.push((name.to_owned(), key));
                }));
            },
        );
        DockPage {
            dock: dock.expect("the dock is built inside the page"),
            panes,
        }
    })
}

/// The three-pane layout the geometry tests use:
///
/// ```text
/// ┌────────────┬──────────────┐
/// │            │   viewport   │
/// │  outliner  ├──────────────┤
/// │            │   console    │
/// └────────────┴──────────────┘
/// ```
fn three_panes() -> DockLayout {
    DockLayout::split(
        SplitAxis::Row,
        DockLayout::pane("outliner"),
        DockLayout::split(
            SplitAxis::Column,
            DockLayout::pane("viewport"),
            DockLayout::pane("console"),
        ),
    )
}

/// The pane block that holds `inner`: the `.dock-pane` its builder built into.
fn pane_of(ui: &Ui, inner: NodeKey) -> NodeKey {
    let index = ui
        .nodes
        .iter()
        .position(|node| node.key == inner)
        .expect("built this frame");
    let parent = ui.nodes[index].parent.expect("a pane holds it");
    ui.nodes[parent].key
}

fn width(ui: &Ui, key: NodeKey) -> f32 {
    let (min, max) = rect(ui, key);
    max.x - min.x
}

fn height(ui: &Ui, key: NodeKey) -> f32 {
    let (min, max) = rect(ui, key);
    max.y - min.y
}

/// **The layout value edits as a tree of splits**: a pane comes out by
/// collapsing the split that held it into its sibling, docks back beside
/// another on any side, and every refused edit changes nothing at all.
#[test]
fn the_layout_value_removes_docks_and_moves_panes() {
    let mut layout = three_panes();
    assert_eq!(layout.panes(), ["outliner", "viewport", "console"]);
    assert!(layout.holds("console") && !layout.holds("assets"));

    let mut without = layout.clone();
    assert!(without.remove_pane("viewport"));
    assert_eq!(
        without,
        DockLayout::split(
            SplitAxis::Row,
            DockLayout::pane("outliner"),
            DockLayout::pane("console"),
        ),
        "the split that held it did not collapse into its sibling"
    );
    assert!(!without.remove_pane("viewport"), "removed twice");

    let mut only = DockLayout::pane("solo");
    assert!(!only.remove_pane("solo"), "the layout was emptied");
    assert_eq!(only, DockLayout::pane("solo"));

    let mut docked = layout.clone();
    assert!(docked.dock("assets", "console", DockSide::Bottom));
    assert_eq!(
        docked.panes(),
        ["outliner", "viewport", "console", "assets"]
    );
    assert!(!docked.dock("assets", "console", DockSide::Bottom), "twice");
    assert!(
        !docked.dock("new", "nowhere", DockSide::Left),
        "no such pane"
    );
    assert!(!docked.dock("console", "console", DockSide::Left), "itself");

    // A move is the two together, and a refused one leaves the value alone.
    let before = layout.clone();
    assert!(!layout.move_pane("console", "nowhere", DockSide::Left));
    assert_eq!(layout, before, "a refused move changed the layout");
    assert!(layout.move_pane("console", "outliner", DockSide::Left));
    assert_eq!(
        layout,
        DockLayout::split(
            SplitAxis::Row,
            DockLayout::split(
                SplitAxis::Row,
                DockLayout::pane("console"),
                DockLayout::pane("outliner"),
            ),
            DockLayout::pane("viewport"),
        ),
        "the pane did not move to the left of the outliner"
    );
}

/// **A nested layout lays its panes out where its splits say**: every pane in
/// the value is built once, each inside its own `.dock-pane`, and the nested
/// column split divides the right-hand side of the row split.
#[test]
fn a_nested_layout_builds_every_pane_where_its_splits_say() {
    let mut ui = Ui::new();
    let mut layout = three_panes();
    dock_page(&mut ui, &mut layout, idle(), NavInput::default());
    let page = dock_page(&mut ui, &mut layout, idle(), NavInput::default());
    assert_eq!(page.names(), ["outliner", "viewport", "console"]);

    let outliner = pane_of(&ui, page.pane("outliner"));
    let viewport = pane_of(&ui, page.pane("viewport"));
    let console = pane_of(&ui, page.pane("console"));

    let shared = (WIDTH - DIVIDER) / 2.0;
    assert_eq!(width(&ui, outliner), shared, "the row split is not even");
    assert_eq!(width(&ui, viewport), shared);
    assert_eq!(width(&ui, console), shared);
    assert_eq!(height(&ui, outliner), HEIGHT, "the left pane is not full");
    assert_eq!(
        height(&ui, viewport),
        (HEIGHT - DIVIDER) / 2.0,
        "the column split is not even"
    );
    assert_eq!(rect(&ui, viewport).1.y + DIVIDER, rect(&ui, console).0.y);
    assert_eq!(rect(&ui, outliner).1.x + DIVIDER, rect(&ui, viewport).0.x);
}

#[test]
fn oversized_content_stays_inside_the_nested_dock_layout() {
    let mut ui = Ui::new();
    let mut layout = three_panes();
    for _ in 0..2 {
        let mut panes = Vec::new();
        frame(&mut ui, idle(), NavInput::default(), |ui| {
            ui.block(
                "#container",
                &[
                    Declaration::Width(LengthAuto::Px(WIDTH)),
                    Declaration::Height(LengthAuto::Px(HEIGHT)),
                ],
                |ui| {
                    ui.dock("#docks", &mut layout, MIN, |ui, name| {
                        let content = ui.block(
                            "",
                            &[
                                Declaration::Width(LengthAuto::Px(PAGE)),
                                Declaration::Height(LengthAuto::Px(PAGE)),
                                Declaration::FlexShrink(0.0),
                            ],
                            |_| {},
                        );
                        panes.push((name.to_owned(), content.key));
                    });
                },
            );
        });
        assert_eq!(panes.len(), layout.panes().len());
        for (name, content) in panes {
            let pane = pane_of(&ui, content);
            let expected_height = if name == "outliner" {
                HEIGHT
            } else {
                (HEIGHT - DIVIDER) / 2.0
            };
            assert_eq!(width(&ui, pane), (WIDTH - DIVIDER) / 2.0, "{name}");
            assert_eq!(height(&ui, pane), expected_height, "{name}");
            let (min, max) = rect(&ui, pane);
            assert!(min.x >= 0.0 && min.y >= 0.0, "{name}: {min:?}");
            assert!(max.x <= WIDTH && max.y <= HEIGHT, "{name}: {max:?}");
        }
    }
}

/// **Dragging a divider moves both panes and writes the new position into the
/// layout value**, which is what makes the layout the thing a save writes; and
/// a nested divider still clamps to both panes' minimums.
#[test]
fn a_drag_moves_both_panes_writes_the_value_and_clamps() {
    let mut ui = Ui::new();
    let mut layout = three_panes();
    dock_page(&mut ui, &mut layout, idle(), NavInput::default());
    let page = dock_page(&mut ui, &mut layout, idle(), NavInput::default());
    let DockLayout::Split { position, .. } = &layout else {
        panic!("the root is a split");
    };
    assert_eq!(*position, None, "a still layout carries a position");

    let outer = pane_of(&ui, page.pane("outliner"));
    let right = pane_of(&ui, page.pane("viewport"));
    let grip = centre(&ui, outer) + Vec2::new(width(&ui, outer) / 2.0 + DIVIDER / 2.0, 0.0);
    let before = (width(&ui, outer), width(&ui, right));

    dock_page(&mut ui, &mut layout, press(grip), NavInput::default());
    let dragged = dock_page(
        &mut ui,
        &mut layout,
        press(grip + Vec2::new(-40.0, 0.0)),
        NavInput::default(),
    );
    assert!(dragged.dock.changed, "the drag was not reported");
    let laid = dock_page(
        &mut ui,
        &mut layout,
        release(grip + Vec2::new(-40.0, 0.0)),
        NavInput::default(),
    );
    assert_eq!(
        width(&ui, pane_of(&ui, laid.pane("outliner"))),
        before.0 - 40.0,
        "the first pane did not follow the drag"
    );
    assert_eq!(
        width(&ui, pane_of(&ui, laid.pane("viewport"))),
        before.1 + 40.0,
        "the second pane did not follow the drag"
    );
    let DockLayout::Split { position, .. } = &layout else {
        panic!("the root is a split");
    };
    assert_eq!(
        *position,
        Some(before.0 - 40.0),
        "the drag was not written into the layout"
    );

    // The nested divider clamps to the minimums of the two panes it divides.
    // Its own position lives in the nested `Split`, not the root's.
    // The grip moves with the divider, so each drag takes it from the frame it
    // starts on.
    let drag = |ui: &mut Ui, layout: &mut DockLayout, by: f32| {
        let settled = dock_page(ui, layout, idle(), NavInput::default());
        let viewport = pane_of(ui, settled.pane("viewport"));
        let grip =
            centre(ui, viewport) + Vec2::new(0.0, height(ui, viewport) / 2.0 + DIVIDER / 2.0);
        let to = grip + Vec2::new(0.0, by);
        dock_page(ui, layout, press(grip), NavInput::default());
        dock_page(ui, layout, press(to), NavInput::default());
        dock_page(ui, layout, release(to), NavInput::default())
    };
    let down = drag(&mut ui, &mut layout, 500.0);
    assert_eq!(
        height(&ui, pane_of(&ui, down.pane("console"))),
        MIN[1],
        "the second pane of the nested split went under its minimum"
    );
    let up = drag(&mut ui, &mut layout, -500.0);
    assert_eq!(
        height(&ui, pane_of(&ui, up.pane("viewport"))),
        MIN[0],
        "the first pane of the nested split went under its minimum"
    );
    let DockLayout::Split { second, .. } = &layout else {
        panic!("the root is a split");
    };
    let DockLayout::Split { position, .. } = &**second else {
        panic!("the right-hand side is a split");
    };
    assert_eq!(
        *position,
        Some(MIN[0]),
        "the nested divider's clamped position is not in the layout"
    );
}

/// **A layout saved and restored lays out exactly as it did**: the value
/// carries every divider, so a tree that has never seen the layout — a fresh
/// `Ui`, as a restart is — puts every pane where the saved one had it.
#[test]
fn a_saved_layout_restores_into_a_tree_that_never_saw_it() {
    let mut ui = Ui::new();
    let mut layout = three_panes();
    dock_page(&mut ui, &mut layout, idle(), NavInput::default());
    let page = dock_page(&mut ui, &mut layout, idle(), NavInput::default());

    // Move both dividers, so neither is where an even share would put it.
    let outer = pane_of(&ui, page.pane("outliner"));
    let grip = centre(&ui, outer) + Vec2::new(width(&ui, outer) / 2.0 + DIVIDER / 2.0, 0.0);
    for offset in [Vec2::ZERO, Vec2::new(-52.0, 0.0), Vec2::new(-52.0, 0.0)] {
        dock_page(
            &mut ui,
            &mut layout,
            press(grip + offset),
            NavInput::default(),
        );
    }
    let moved = dock_page(&mut ui, &mut layout, idle(), NavInput::default());
    let viewport = pane_of(&ui, moved.pane("viewport"));
    let inner = centre(&ui, viewport) + Vec2::new(0.0, height(&ui, viewport) / 2.0 + DIVIDER / 2.0);
    for offset in [Vec2::ZERO, Vec2::new(0.0, -21.0), Vec2::new(0.0, -21.0)] {
        dock_page(
            &mut ui,
            &mut layout,
            press(inner + offset),
            NavInput::default(),
        );
    }
    let shown = dock_page(&mut ui, &mut layout, idle(), NavInput::default());
    let want: Vec<(Vec2, Vec2)> = shown
        .names()
        .iter()
        .map(|name| rect(&ui, pane_of(&ui, shown.pane(name))))
        .collect();
    let even = (WIDTH - DIVIDER) / 2.0;
    assert!(
        (want[0].1.x - want[0].0.x - even).abs() > 1.0,
        "the dividers never moved, so restoring proves nothing"
    );

    // The save: the value, and only the value.
    let saved = layout.clone();
    drop(ui);

    let mut restored = saved.clone();
    let mut fresh = Ui::new();
    dock_page(&mut fresh, &mut restored, idle(), NavInput::default());
    let after = dock_page(&mut fresh, &mut restored, idle(), NavInput::default());
    let got: Vec<(Vec2, Vec2)> = after
        .names()
        .iter()
        .map(|name| rect(&fresh, pane_of(&fresh, after.pane(name))))
        .collect();
    assert_eq!(after.names(), shown.names());
    assert_eq!(got, want, "the restored layout is not the saved one");
    assert_eq!(restored, saved, "showing a layout changed it");
}

/// **A pane moved between docks takes its content with it and nothing else
/// moves**: the layout is edited as a value and the next frame builds it.
#[test]
fn moving_a_pane_between_docks_rebuilds_it_where_the_value_says() {
    let mut ui = Ui::new();
    let mut layout = three_panes();
    dock_page(&mut ui, &mut layout, idle(), NavInput::default());
    let before = dock_page(&mut ui, &mut layout, idle(), NavInput::default());
    let console = pane_of(&ui, before.pane("console"));
    assert!(
        rect(&ui, console).0.x > rect(&ui, pane_of(&ui, before.pane("outliner"))).1.x,
        "the console did not start on the right"
    );

    assert!(layout.move_pane("console", "outliner", DockSide::Bottom));
    dock_page(&mut ui, &mut layout, idle(), NavInput::default());
    let after = dock_page(&mut ui, &mut layout, idle(), NavInput::default());
    assert_eq!(after.names(), ["outliner", "console", "viewport"]);
    let outliner = pane_of(&ui, after.pane("outliner"));
    let console = pane_of(&ui, after.pane("console"));
    let viewport = pane_of(&ui, after.pane("viewport"));
    assert_eq!(
        rect(&ui, outliner).1.y + DIVIDER,
        rect(&ui, console).0.y,
        "the console is not under the outliner"
    );
    assert_eq!(
        height(&ui, viewport),
        HEIGHT,
        "the viewport did not take the whole right side"
    );
}

/// **Two panes of one name in a hand-built layout build as two panes, and the
/// tree never sees a duplicate key**: each pane's block is keyed by its name
/// under the split pane that holds it, and no two panes of a dock share that
/// parent, so the second keeps a key of its own without the tree having to
/// derive one or warn. The editing methods then refuse to move the name, since
/// taking one copy out still leaves it held.
#[test]
fn a_hand_built_layout_with_one_name_twice_builds_two_panes() {
    let logs = crcbl_core::log::capture();
    let mut ui = Ui::new();
    let mut layout = DockLayout::split(
        SplitAxis::Row,
        DockLayout::pane("twin"),
        DockLayout::split(
            SplitAxis::Column,
            DockLayout::pane("twin"),
            DockLayout::pane("console"),
        ),
    );
    assert_eq!(layout.panes(), ["twin", "twin", "console"]);
    dock_page(&mut ui, &mut layout, idle(), NavInput::default());
    let page = dock_page(&mut ui, &mut layout, idle(), NavInput::default());
    assert_eq!(page.names(), ["twin", "twin", "console"]);

    assert!(
        ui.duplicate_keys().is_empty(),
        "the tree reported a duplicate key: {:?}",
        ui.duplicate_keys()
    );
    let warnings = logs
        .records()
        .into_iter()
        .filter(|record| record.message.contains("share the key"))
        .count();
    assert_eq!(warnings, 0, "the tree warned of a duplicate key");

    let left = pane_of(&ui, page.panes[0].1);
    let right = pane_of(&ui, page.panes[1].1);
    assert_ne!(left, right, "the two panes share one key, and so its state");
    assert_eq!(width(&ui, left), (WIDTH - DIVIDER) / 2.0);
    assert_eq!(height(&ui, left), HEIGHT);
    assert_eq!(height(&ui, right), (HEIGHT - DIVIDER) / 2.0);
    assert_eq!(rect(&ui, left).1.x + DIVIDER, rect(&ui, right).0.x);

    let before = layout.clone();
    assert!(!layout.move_pane("twin", "console", DockSide::Left));
    assert_eq!(
        layout, before,
        "a refused move of a doubled name changed it"
    );
}

/// **No editing method makes a name appear twice**: [`DockLayout::dock`]
/// refuses a name the layout holds, beside every pane and on every side, and
/// every move of every pane to every side of every other keeps each name
/// exactly once.
#[test]
fn the_editing_methods_never_make_a_name_appear_twice() {
    let sides = [
        DockSide::Left,
        DockSide::Right,
        DockSide::Top,
        DockSide::Bottom,
    ];
    let layout = three_panes();
    let names = layout.panes();
    let mut sorted = names.clone();
    sorted.sort_unstable();
    for name in &names {
        for beside in &names {
            for side in sides {
                let mut docked = layout.clone();
                assert!(
                    !docked.dock(name, beside, side),
                    "docked a second {name} {side:?} of {beside}"
                );
                assert_eq!(docked, layout, "a refused dock changed the layout");

                let mut moved = layout.clone();
                let did = moved.move_pane(name, beside, side);
                assert_eq!(did, name != beside, "{name} {side:?} of {beside}");
                let mut after = moved.panes();
                after.sort_unstable();
                assert_eq!(after, sorted, "{name} {side:?} of {beside}");
            }
        }
    }
}

/// **A dock nested four levels deep lays every pane out inside every split
/// that holds it**: each pane is built once, at a rectangle with room in it,
/// and that rectangle sits inside each of its ancestors' up to the dock.
///
/// ```text
/// ┌──────┬──────────────┐
/// │      │      b       │
/// │  a   ├──────┬───────┤
/// │      │  c   │   d   │
/// │      │      ├───────┤
/// │      │      │   e   │
/// └──────┴──────┴───────┘
/// ```
#[test]
fn a_dock_nested_four_deep_keeps_every_pane_inside_its_splits() {
    let mut layout = DockLayout::split(
        SplitAxis::Row,
        DockLayout::pane("a"),
        DockLayout::split(
            SplitAxis::Column,
            DockLayout::pane("b"),
            DockLayout::split(
                SplitAxis::Row,
                DockLayout::pane("c"),
                DockLayout::split(
                    SplitAxis::Column,
                    DockLayout::pane("d"),
                    DockLayout::pane("e"),
                ),
            ),
        ),
    );
    let mut ui = Ui::new();
    let mut built = Vec::new();
    let mut dock = None;
    for _ in 0..2 {
        built.clear();
        dock = Some(frame(&mut ui, idle(), NavInput::default(), |ui| {
            ui.dock("#deep", &mut layout, MIN, |ui, name| {
                built.push((name.to_owned(), ui.block("", &[], |_| {}).key));
            })
        }));
    }
    let dock = dock.expect("built").key;
    assert_eq!(
        built
            .iter()
            .map(|(name, _)| name.as_str())
            .collect::<Vec<_>>(),
        ["a", "b", "c", "d", "e"]
    );

    let (dock_min, dock_max) = rect(&ui, dock);
    assert_eq!(
        dock_max - dock_min,
        Vec2::splat(PAGE),
        "the dock is not full"
    );
    for (name, inner) in &built {
        let pane = pane_of(&ui, *inner);
        let (min, max) = rect(&ui, pane);
        assert!(
            max.x - min.x >= MIN[0] && max.y - min.y >= MIN[0],
            "{name} has no room: {min:?}..{max:?}"
        );
        let mut index = ui
            .nodes
            .iter()
            .position(|node| node.key == pane)
            .expect("built this frame");
        let mut ancestors = 0;
        while ui.nodes[index].key != dock {
            index = ui.nodes[index].parent.expect("the dock holds every pane");
            let (outer_min, outer_max) = rect(&ui, ui.nodes[index].key);
            assert!(
                min.x >= outer_min.x
                    && min.y >= outer_min.y
                    && max.x <= outer_max.x
                    && max.y <= outer_max.y,
                "{name} at {min:?}..{max:?} leaves {outer_min:?}..{outer_max:?}"
            );
            ancestors += 1;
        }
        assert!(ancestors >= 2, "{name} was not checked against a split");
    }
    let deepest = pane_of(&ui, built[4].1);
    assert_eq!(
        height(&ui, deepest),
        ((PAGE - DIVIDER) / 2.0 - DIVIDER) / 2.0,
        "the fourth level's split is not even"
    );
}