makeover-immediate 0.67.0

The immediate-mode renderer for makeover-layout, backed by egui: no cascade, no retained tree, one stroke per widget.
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
//! The described things that are not fields, tables or frames, and carry no
//! vocabulary member: a token and a wait.
//!
//! The vocabulary members (a meter, a control, facts, a figure, a chart) are
//! drawn by `quasi-immediate`, with the [`PieceStyle`] held here, so the sizes
//! every egui host draws them at stay in one place. `makeover-tui`'s `piece`
//! module is the same split for a terminal, and the name is shared for that
//! reason.
//!
//! # What "in egui" changes, and what it does not
//!
//! The semantics are `makeover-tui`'s, deliberately: a badge is round and a
//! chip is square, and a wait draws a bar only when something is counting it.
//! Those are description-level readings and they do not get a second opinion
//! per host.
//!
//! What differs is forced by the target rather than chosen. A terminal spends a
//! whole cell on a character and returns a `Line` for the caller to place; egui
//! paints an arbitrary rect and answers a [`Response`], so every function here
//! draws into the `Ui` it is given and hands back what the user did to it.
//! Nothing here takes a `focused` flag: egui owns focus, which is the rule the
//! crate header states.

use egui::{Response, RichText, Sense, Ui, Vec2};
use makeover_layout::{Awaiting, Token, Tone, progress_reading};
use makeover_timing::{MotionPreference, blink};
use std::time::Duration;

use crate::Palette;

/// The sizes a widget cannot derive from the description.
///
/// Every number a caller might reasonably want different, in one place, on the
/// footing [`FrameStyle`](crate::FrameStyle) and [`FieldStyle`](crate::FieldStyle)
/// already establish: every size arrives from the caller.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct PieceStyle {
    /// How tall a meter's bar is drawn.
    pub meter_height: f32,
    /// How wide a meter's bar runs, or `None` to take the width on offer.
    ///
    /// `None` is the honest default in immediate mode: a bar in a side panel and
    /// a bar in a wide pane are the same description, and the available width is
    /// the only thing either of them knows.
    pub meter_width: Option<f32>,
    /// How tall a chart stands, in points.
    ///
    /// A chart's own, not [`meter_height`](Self::meter_height): a meter is a
    /// rule set into a line of text and a chart is a figure with room of its
    /// own. `makeover-webview` defers the same number to `--chart-height` for
    /// the same reason, and 200 is the same default.
    pub chart_height: f32,
    /// The corner radius on a meter's trough and on a token.
    pub radius: u8,
    /// Inside a token, around its label.
    pub token_padding: Vec2,
    /// Between a figure's value and its caption.
    pub figure_gap: f32,
    /// How much larger a figure's value is drawn than the body text.
    ///
    /// A multiplier rather than a size, so a figure scales with whatever text
    /// style the app has set rather than pinning a point size this crate has no
    /// business choosing.
    pub figure_scale: f32,
    /// The side of the activity mark, square.
    ///
    /// Small on purpose. The mark says one thing and a reader should have to
    /// look at it to read it, which is the difference between an indicator and
    /// an animation competing with the content it sits beside.
    pub mark_size: f32,
}

impl Default for PieceStyle {
    /// Bars at 6pt taking the width on offer, a figure at double text size, and
    /// the activity mark a square a little larger than a bar is tall.
    fn default() -> Self {
        Self {
            meter_height: 6.0,
            meter_width: None,
            chart_height: 200.0,
            radius: 3,
            token_padding: Vec2::new(6.0, 2.0),
            figure_gap: 2.0,
            figure_scale: 2.0,
            mark_size: 8.0,
        }
    }
}

/// A badge or a chip.
///
/// A badge is the table model's (wiki `table-model`), as `makeover-webview`
/// draws it: a fill of its tone surface inside a one-point edge in its tone,
/// the label in content ink. A neutral badge fills with the raised surface and
/// takes the border for its edge. The tone is never the ink, which measured
/// 1.34:1 as text on goingson's warning.
///
/// A chip is outlined in its tone, and filled while latched.
///
/// **A chip answers a click and a badge does not**, which is
/// [`Token::interactive`] and is the whole difference between the members. The
/// `Response` comes back either way, so a caller that presses a badge is
/// pressing something this function said was not interactive; the sense is what
/// makes egui agree.
///
/// `latched` is a chip that is switched on, and it fills rather than outlines. A
/// terminal has to collide latched with focus because it has one spare axis for
/// two facts; egui does not, so it does not.
///
/// A chip's removable half is not drawn, on `makeover-tui`'s reasoning: a second
/// control inside a token is a question for whoever owns the interaction rather
/// than for a drawing.
pub fn token(
    ui: &mut Ui,
    label: &str,
    kind: Token,
    tone: Tone,
    latched: bool,
    palette: &Palette,
    style: &PieceStyle,
) -> Response {
    let painted = palette.tone(tone);
    let radius = style.radius;
    let sense = if kind.interactive() {
        Sense::click()
    } else {
        Sense::hover()
    };

    // Laid out before the rect is allocated, because a token is exactly as wide
    // as what it says plus its padding: there is no box to fit text into here,
    // the way a table cell has one.
    // A token's words are content ink. A status colour is a fill, an edge or
    // a glyph, never the colour of words (wiki `quasi-vocabulary-findings`,
    // toned text), so the tone stays on the outline and a latched toned chip
    // fills from the tone's surface the way a badge does. A latched neutral
    // chip keeps its inverted fill: it carries no status, and the inversion is
    // what tells it from one at rest.
    let neutral = tone == Tone::Neutral;
    let ink = match kind {
        Token::Chip { .. } if latched && neutral => palette.page,
        _ => palette.content,
    };
    let galley = ui.painter().layout_no_wrap(
        label.to_owned(),
        egui::TextStyle::Body.resolve(ui.style()),
        ink,
    );
    let size = galley.size() + style.token_padding * 2.0;
    let (rect, response) = ui.allocate_exact_size(size, sense);

    if kind == Token::Badge {
        ui.painter().rect(
            rect,
            radius,
            palette.tone_surface(tone),
            egui::Stroke::new(1.0, palette.tone_edge(tone)),
            egui::StrokeKind::Inside,
        );
    } else if latched && neutral {
        ui.painter().rect_filled(rect, radius, painted);
    } else if latched {
        ui.painter().rect(
            rect,
            radius,
            palette.tone_surface(tone),
            egui::Stroke::new(1.0, painted),
            egui::StrokeKind::Inside,
        );
    } else {
        ui.painter().rect_stroke(
            rect,
            radius,
            egui::Stroke::new(1.0, painted),
            egui::StrokeKind::Inside,
        );
    }
    ui.painter()
        .galley(rect.center() - galley.size() / 2.0, galley, ink);

    // Say what was drawn, because painting it says nothing.
    //
    // A token allocates its rect and paints the text straight onto it, so
    // nothing reaches the accessibility tree unless it is said here: an
    // interactive chip would be a control a mouse can press and a screen reader
    // cannot find, and a badge text nobody can read out.
    //
    // A chip that latches says so through `selected`, which is what a screen
    // reader announces as pressed. That is `latched`'s whole meaning: the key
    // is held down.
    let role = if kind.interactive() {
        egui::WidgetType::Button
    } else {
        egui::WidgetType::Label
    };
    response.widget_info(|| {
        let mut info = egui::WidgetInfo::labeled(role, ui.is_enabled(), label);
        if kind.interactive() {
            info.selected = Some(latched);
        }
        info
    });
    response
}

/// What a host can see about a wait that is running.
pub use makeover_layout::Progress;

/// The activity mark: one small square, blinking.
///
/// Rule 2 of wiki `loading-and-progress-standard`, and the thing that replaced
/// `Ui::spinner` here. A spinner turns at a rate it invented and reads as
/// progress; this claims nothing beyond "something is happening", which is the
/// whole of what an unmeasured wait knows.
///
/// **[`MotionPreference::Reduced`] stills the mark rather than removing it.**
/// egui has no `prefers-reduced-motion`, so the preference arrives from
/// whatever the host asked its own platform, the input
/// `makeover_timing::activity_blink` takes. A still mark still says something is happening; hiding it
/// would answer a request nobody made.
///
/// The cadence is `makeover_timing::Cadence::Activity` and is not a number this
/// crate chooses, so a browser, a terminal and an egui window blink together.
///
/// Repaint is asked for at the next flip rather than every frame: a blinking
/// mark should not turn a window that is otherwise idle into one that renders
/// continuously.
pub fn activity(
    ui: &mut Ui,
    motion: MotionPreference,
    palette: &Palette,
    style: &PieceStyle,
) -> Response {
    let (rect, response) = ui.allocate_exact_size(Vec2::splat(style.mark_size), Sense::hover());
    let elapsed = Duration::try_from_secs_f64(ui.input(|input| input.time)).unwrap_or_default();
    let (lit, until) = blink(elapsed, motion);
    if let Some(until) = until {
        ui.ctx().request_repaint_after(until);
    }
    // Lit is the accent, dark is the trough it sits in. Not "drawn and not
    // drawn": a mark that vanishes half the time is a hole in the layout, and
    // the reader loses where to look between blinks.
    let colour = if lit { palette.action } else { palette.sunken };
    ui.painter().rect_filled(rect, style.radius, colour);
    response
}

/// A wait, drawn from what is actually known about it.
///
/// The branch is `Awaiting::is_determinate` and one more question the
/// description cannot answer: whether anything is watching the transfer. A bar
/// needs both a total and a numerator, so a described amount with no
/// [`Progress::delivered`] beside it draws the mark and the total, not an
/// empty trough that implies someone is counting.
///
/// **What the bar may not do**, from rule 1 of wiki
/// `loading-and-progress-standard` and from `Awaiting`'s own docs: what is done
/// over what there is, plus the time it has taken. Never a remaining time, an
/// arrival time, or a rate extrapolated forward. A prediction is wrong the
/// moment the transfer stalls, and being confidently wrong is worse than being
/// honestly indeterminate.
///
/// The reading is the two raw numbers, as a meter's is. The unit is the
/// app's (bytes for an upload, rows for an import), and a renderer that
/// guessed at one would be formatting a quantity it was deliberately not told
/// about.
pub fn awaiting(
    ui: &mut Ui,
    awaiting: Awaiting,
    progress: Progress,
    motion: MotionPreference,
    palette: &Palette,
    style: &PieceStyle,
) -> Response {
    let Some(total) = awaiting.amount else {
        return activity(ui, motion, palette, style);
    };
    let Some(done) = progress.delivered else {
        // Known size, nothing counting it: the mark, and the total beside it
        // in the reading's ink, so the reader learns how much is coming.
        return ui
            .horizontal(|ui| {
                let mark = activity(ui, motion, palette, style);
                ui.label(RichText::new(total.to_string()).color(palette.content_muted));
                mark
            })
            .inner;
    };
    let reading = progress_reading(done, total, progress.elapsed);
    // With no width asked for, the bar takes what is left after the reading and
    // the gap before it, so the reading stays on screen. Taking all of the
    // available width pushed it past the edge.
    let width = style.meter_width.unwrap_or_else(|| {
        let text = RichText::new(&reading).color(palette.content_muted);
        let galley = egui::WidgetText::from(text).into_galley(
            ui,
            Some(egui::TextWrapMode::Extend),
            f32::INFINITY,
            egui::TextStyle::Body,
        );
        (ui.available_width() - galley.size().x - ui.spacing().item_spacing.x).max(1.0)
    });
    ui.horizontal(|ui| {
        let (rect, response) =
            ui.allocate_exact_size(Vec2::new(width, style.meter_height), Sense::hover());
        ui.painter().rect_filled(rect, style.radius, palette.sunken);
        // A total of zero is no payload rather than a finished one, which is a
        // meter's reading of the same case. Over-delivery clamps because a rect
        // cannot be longer than itself.
        let share = if total == 0 {
            0.0
        } else {
            #[expect(
                clippy::cast_precision_loss,
                reason = "a byte count past 2^53 is not a wait anyone is watching a bar for"
            )]
            let share = (done as f64 / total as f64).min(1.0);
            share
        };
        #[expect(
            clippy::cast_possible_truncation,
            reason = "a share is 0..=1 and the product is a width in points"
        )]
        let filled = (f64::from(rect.width()) * share) as f32;
        if filled > 0.0 {
            let mut fill = rect;
            fill.set_width(filled);
            ui.painter().rect_filled(fill, style.radius, palette.action);
        }
        ui.label(RichText::new(reading).color(palette.content_muted));
        response
    })
    .inner
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::tests::palette;

    /// What the accessibility tree says a widget drew.
    fn announced(
        draw: impl FnMut(&mut Ui),
    ) -> Vec<(
        egui::accesskit::Role,
        String,
        Option<egui::accesskit::Toggled>,
    )> {
        let ctx = egui::Context::default();
        ctx.enable_accesskit();
        let mut draw = draw;
        let input = || egui::RawInput {
            screen_rect: Some(egui::Rect::from_min_size(
                egui::Pos2::ZERO,
                egui::vec2(600.0, 400.0),
            )),
            ..Default::default()
        };
        // A frame's texture changes are the host's to upload, and egui 0.36
        // refuses to have them dropped unread. No host here, so they are
        // cleared by hand.
        ctx.run_ui(input(), &mut draw).textures_delta.clear();
        let mut out = ctx.run_ui(input(), &mut draw);
        out.textures_delta.clear();
        out.platform_output
            .accesskit_update
            .expect("accesskit is on")
            .nodes
            .iter()
            .map(|(_, node)| {
                (
                    node.role(),
                    node.label()
                        .or_else(|| node.value())
                        .unwrap_or_default()
                        .to_owned(),
                    node.toggled(),
                )
            })
            .collect()
    }

    /// The colour each run of words was painted in, by its text.
    fn inked(draw: impl FnMut(&mut Ui)) -> Vec<(String, egui::Color32)> {
        fn walk(shape: &egui::Shape, out: &mut Vec<(String, egui::Color32)>) {
            match shape {
                egui::Shape::Text(t) => {
                    let format = t.galley.job.sections.first().map(|s| s.format.color);
                    let colour = format
                        .filter(|c| *c != egui::Color32::PLACEHOLDER)
                        .unwrap_or(t.fallback_color);
                    out.push((t.galley.job.text.clone(), colour));
                }
                egui::Shape::Vec(shapes) => shapes.iter().for_each(|s| walk(s, out)),
                _ => {}
            }
        }
        let ctx = egui::Context::default();
        let mut draw = draw;
        let input = egui::RawInput {
            screen_rect: Some(egui::Rect::from_min_size(
                egui::Pos2::ZERO,
                egui::vec2(600.0, 400.0),
            )),
            ..Default::default()
        };
        let mut output = ctx.run_ui(input, &mut draw);
        output.textures_delta.clear();
        let mut out = Vec::new();
        for clipped in &output.shapes {
            walk(&clipped.shape, &mut out);
        }
        out
    }

    #[test]
    fn a_toned_tokens_words_are_content_whether_or_not_it_is_latched() {
        // Toned text ruling: a status colour is a fill or an edge, never words.
        let p = palette();
        let style = PieceStyle::default();
        for kind in [Token::Badge, Token::Chip { removable: false }] {
            for latched in [false, true] {
                let drawn = inked(|ui| {
                    token(ui, "overdue", kind, Tone::Danger, latched, &p, &style);
                });
                let (_, colour) = drawn
                    .iter()
                    .find(|(text, _)| text == "overdue")
                    .unwrap_or_else(|| panic!("nothing painted: {drawn:?}"));
                assert_eq!(*colour, p.content, "{kind:?} latched {latched}");
            }
        }
    }

    #[test]
    fn a_chip_is_announced_as_a_control_and_says_whether_it_is_held() {
        // A token paints its own text onto its own rect, so without saying what
        // it drew it reaches the tree as nothing: pressable by a mouse and
        // invisible to everything else.
        let p = palette();
        let style = PieceStyle::default();
        let drawn = announced(|ui| {
            token(
                ui,
                "C#",
                Token::Chip { removable: false },
                Tone::Neutral,
                true,
                &p,
                &style,
            );
        });

        let chip = drawn
            .iter()
            .find(|(role, name, _)| *role == egui::accesskit::Role::Button && name == "C#")
            .unwrap_or_else(|| panic!("the chip is not in the tree: {drawn:?}"));
        assert_eq!(
            chip.2,
            Some(egui::accesskit::Toggled::True),
            "a latched chip is held down and says so: {drawn:?}"
        );
    }

    #[test]
    fn a_badge_is_announced_as_the_text_it_is() {
        // Not a control, and not nothing either: a badge is a word on the
        // screen and painting it is not the same as saying it.
        let p = palette();
        let style = PieceStyle::default();
        let drawn = announced(|ui| {
            token(ui, "wav", Token::Badge, Tone::Neutral, false, &p, &style);
        });

        assert!(
            drawn
                .iter()
                .any(|(role, name, _)| *role == egui::accesskit::Role::Label && name == "wav"),
            "{drawn:?}"
        );
        assert!(
            !drawn
                .iter()
                .any(|(role, _, _)| *role == egui::accesskit::Role::Button),
            "a badge answers nothing and must not claim to: {drawn:?}"
        );
    }

    #[test]
    fn every_tone_resolves_and_no_two_share_a_colour() {
        // The reason the three status intents arrived together: a resolver
        // missing one has to invent a colour for it.
        let p = palette();
        let all = [
            p.tone(Tone::Neutral),
            p.tone(Tone::Info),
            p.tone(Tone::Success),
            p.tone(Tone::Warning),
            p.tone(Tone::Danger),
        ];
        for (i, a) in all.iter().enumerate() {
            for b in &all[i + 1..] {
                assert_ne!(a, b, "two tones resolved to one colour");
            }
        }
        assert_eq!(p.tone(Tone::Neutral), p.content, "neutral is ordinary text");
    }

    #[test]
    fn a_wait_draws_a_bar_only_when_something_is_counting_it() {
        // The described total is half of what a bar needs. Without a numerator
        // the honest drawing is the mark, not an empty trough implying that
        // someone is watching bytes land.
        let p = palette();
        let style = PieceStyle::default();
        egui::__run_test_ui(|ui| {
            awaiting(
                ui,
                Awaiting::unmeasured(),
                Progress::default(),
                MotionPreference::Full,
                &p,
                &style,
            );
            awaiting(
                ui,
                Awaiting::of(41_943_040),
                Progress::default(),
                MotionPreference::Full,
                &p,
                &style,
            );
            awaiting(
                ui,
                Awaiting::of(41_943_040),
                Progress {
                    delivered: Some(10_485_760),
                    elapsed: Some(Duration::from_secs(3)),
                },
                MotionPreference::Full,
                &p,
                &style,
            );
            // A zero payload is no payload, and over-delivery clamps.
            awaiting(
                ui,
                Awaiting::of(0),
                Progress {
                    delivered: Some(9),
                    elapsed: None,
                },
                MotionPreference::Full,
                &p,
                &style,
            );
            awaiting(
                ui,
                Awaiting::of(4),
                Progress {
                    delivered: Some(9),
                    elapsed: None,
                },
                MotionPreference::Full,
                &p,
                &style,
            );
        });
    }

    #[test]
    fn reduced_motion_stills_the_mark_and_does_not_remove_it() {
        // `activity_blink(Reduced)` is None, which means lit and still. A renderer
        // that drew nothing would have answered a request nobody made.
        let p = palette();
        let style = PieceStyle::default();
        egui::__run_test_ui(|ui| {
            let still = activity(ui, MotionPreference::Reduced, &p, &style);
            let blinking = activity(ui, MotionPreference::Full, &p, &style);
            assert_eq!(
                still.rect.size(),
                blinking.rect.size(),
                "the mark occupies the same space either way"
            );
        });
    }

    #[test]
    fn a_chip_answers_a_click_and_a_badge_does_not() {
        // `Token::interactive` is the whole difference between the members, and
        // the sense is what makes egui agree with it.
        let p = palette();
        let style = PieceStyle::default();
        egui::__run_test_ui(|ui| {
            let badge = token(ui, "beta", Token::Badge, Tone::Info, false, &p, &style);
            assert!(!badge.sense.senses_click(), "a badge answers no click");

            let chip = token(
                ui,
                "drums",
                Token::Chip { removable: false },
                Tone::Neutral,
                false,
                &p,
                &style,
            );
            assert!(chip.sense.senses_click(), "a chip answers a click");
        });
    }

    #[test]
    fn an_unwatched_measured_wait_draws_the_mark_and_the_total() {
        // A described amount with nothing delivered yet: the mark, then the
        // total in the reading's ink. No bar, since nothing is counting.
        let ctx = egui::Context::default();
        ctx.set_fonts(egui::FontDefinitions::default());
        let p = palette();
        let style = PieceStyle::default();
        let mut output = ctx.run_ui(egui::RawInput::default(), |ui| {
            awaiting(
                ui,
                Awaiting::of(41_943_040),
                Progress::default(),
                MotionPreference::Reduced,
                &p,
                &style,
            );
        });
        let shapes = std::mem::take(&mut output.shapes);
        output.drop_without_applying_deltas();
        let texts: Vec<(String, egui::Color32)> = shapes
            .iter()
            .filter_map(|clipped| match &clipped.shape {
                egui::Shape::Text(text) => Some((
                    text.galley.text().to_owned(),
                    text.galley.job.sections.first()?.format.color,
                )),
                _ => None,
            })
            .collect();
        let rects = shapes
            .iter()
            .filter(|clipped| matches!(clipped.shape, egui::Shape::Rect(_)))
            .count();
        assert_eq!(texts.len(), 1, "{texts:?}");
        assert_eq!(texts[0].0, "41943040");
        assert_eq!(texts[0].1, p.content_muted, "the reading's ink");
        assert_eq!(rects, 1, "the mark alone, no trough");
    }

    #[test]
    fn a_wait_keeps_its_reading_inside_the_panel() {
        // A bar that takes all of the available width leaves the reading nowhere
        // to go, so it lands past the panel edge. Real fonts, because the
        // reading's width is what the bar has to make room for, and the test
        // harness otherwise loads none. One pass, because egui grows a viewport
        // to fit its content and would otherwise hide the overflow.
        let ctx = egui::Context::default();
        ctx.set_fonts(egui::FontDefinitions::default());
        ctx.memory_mut(|m| m.options.max_passes = std::num::NonZeroUsize::new(1).unwrap());
        let p = palette();
        let style = PieceStyle::default();
        let mut used = 0.0f32;
        let mut budget = 0.0f32;
        let input = egui::RawInput {
            screen_rect: Some(egui::Rect::from_min_size(
                egui::Pos2::ZERO,
                egui::Vec2::new(300.0, 400.0),
            )),
            ..Default::default()
        };
        let output = ctx.run_ui(input, |ui| {
            let left = ui.min_rect().left();
            budget = ui.available_width();
            awaiting(
                ui,
                Awaiting::of(41_943_040),
                Progress {
                    delivered: Some(10_485_760),
                    elapsed: Some(Duration::from_secs(3)),
                },
                MotionPreference::Full,
                &p,
                &style,
            );
            used = ui.min_rect().right() - left;
        });
        output.drop_without_applying_deltas();
        assert!(
            used <= budget + 0.5,
            "the bar and its reading drew to {used}, past the {budget}pt on offer"
        );
    }
}