makeover-immediate 0.70.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
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
//! The immediate-mode renderer for [`makeover_layout`], written against egui.
//!
//! <!-- wiki: makeover-immediate -->
//!
//! egui's `Visuals.widgets.*.bg_stroke` is one stroke with no per-side
//! control, so the two-tone lit edge is painted here by hand
//! ([`paint_bevel`]).
//!
//! # What this crate draws
//!
//! The parts of the description that carry no vocabulary member: depth
//! ([`frame`], [`paint_bevel`]), the resolved colours ([`Palette`]), a table's
//! per-frame facts and cell tones ([`table`]), the token and the waiting
//! marks ([`piece`]), and the egui visuals and metrics a host starts from
//! ([`host`]).
//!
//! The vocabulary members (fields, columns, meters, controls, facts, figures
//! and charts) are drawn by `quasi-immediate`, which owns those types through
//! `quasi-router` and calls into this crate for everything above. The style
//! types it draws them with stay here: [`FieldStyle`], [`Editing`],
//! [`piece::PieceStyle`] and [`table::TableStyle`].
//!
//! # What this crate does and does not own
//!
//! It owns the expression: two mitred polylines for a bevel and a `Frame` for
//! a filled region. It owns no colours and makes no substitutions: the caller
//! supplies [`Palette`] already resolved.
//!
//! Every radius, margin, stroke width and floor arrives in a style type
//! ([`FrameStyle`], [`FieldStyle`], [`piece::PieceStyle`],
//! [`table::TableStyle`], [`host::Metrics`]). The focus ring and target floor
//! in [`host::Metrics`] default to what `makeover-webview` emits.
//!
//! `makeover` itself is linked only by the `theme` feature, for
//! `Palette::from_theme`; it embeds every shipped theme file.
//!
//! # Pressed state
//!
//! There is no cascade to carry a pressed state, so each call site asks
//! [`makeover_layout::Depth::pressed`] for the depth a pressed region takes.
//!
//! # Overlays
//!
//! [`frame`] hands [`Palette::cast`] to the `egui::Frame` for any depth whose
//! fill is [`Fill::Overlay`], keyed off the fill rather than the variant.
//!
//! # Focus and chrome
//!
//! egui decides what is reachable and what holds the keyboard, and paints the
//! one focus ring; this crate draws no ring of its own. The terms are defined
//! in `makeover_layout`'s crate header, "Reach, focus and the focus ring".
//!
//! App-level chrome is not drawn here. `quasi-router` names the affordances
//! that outlive one screen and `quasi-immediate` answers them; this crate
//! depends on `makeover-layout` and not on `quasi-router`.

#![forbid(unsafe_code)]

use egui::{Color32, CornerRadius, Margin, Painter, Rect, Shape, Stroke, Ui};
use makeover_layout::{Bevel, Depth, Edge, Fill, HEAT_BANDS, Heat, Tone};

pub mod host;
pub mod piece;
pub mod table;

/// The resolved colours this renderer needs, as flat values.
///
/// Built by the app from whatever it already uses to resolve a theme, then
/// held and reused.
///
/// `#[non_exhaustive]`, so a colour added here is not a breaking change: build
/// one with `Palette::from_theme` (the `theme` feature), or start from
/// [`Palette::two_tone`] and set every colour the app resolves.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub struct Palette {
    /// `surface-page`.
    pub page: Color32,
    /// `surface-raised`.
    pub raised: Color32,
    /// `surface-overlay`.
    pub overlay: Color32,
    /// `surface-well`. Required: makeover derives it for every theme.
    pub well: Color32,
    /// `surface-sunken`.
    ///
    /// A surface set back from the one it sits on, by colour and with no edge;
    /// a well has an edge. Required: every theme makeover embeds authors it.
    pub sunken: Color32,
    /// `bevel-light`.
    pub bevel_light: Color32,
    /// `bevel-dark`.
    pub bevel_dark: Color32,
    /// `elevation`.
    ///
    /// The colour a surface that floats over the page (a menu, a tooltip, a
    /// modal) is cast onto it with: a translucent near-black on every theme.
    /// A surface in the layout takes a bevel instead. [`Palette::cast`] is the
    /// shadow to hand an [`egui::Frame`].
    pub elevation: Color32,
    /// `content`.
    ///
    /// Ordinary text.
    pub content: Color32,
    /// `content-secondary`.
    ///
    /// Inactive but usable: it still answers a press. The middle tone of the
    /// three (wiki `three-tone-convention`), and the one an unchosen option in
    /// a choice field takes. Distinct from
    /// [`content_disabled`](Self::content_disabled), which
    /// `State::Disabled` resolves to.
    ///
    /// A step of `content` toward the page, derived at load by `makeover` and
    /// read off the resolved theme like any other token.
    pub content_secondary: Color32,
    /// `content-muted`.
    ///
    /// A field's hint, a caption, a reading: text that was never a control.
    /// Held to body text's floor.
    pub content_muted: Color32,
    /// `content-disabled`.
    ///
    /// What [`makeover_layout::State::Disabled`] resolves to, by token: the
    /// label of a control that will not answer, fainter than any hint.
    pub content_disabled: Color32,
    /// `action-primary`.
    ///
    /// What a control is drawn in, and the intent
    /// [`CellPart`](makeover_layout::CellPart) separates from a cell's text.
    pub action: Color32,
    /// `content-on-action`: ink that stays readable on [`action`](Self::action).
    ///
    /// Resolved by makeover: the theme's page or content where one reads at
    /// 4.5:1 on the accent, black or white otherwise. The label of the leading
    /// control, the one control filled with `action`.
    pub content_on_action: Color32,
    /// `danger`.
    ///
    /// A field's error message, a destructive control, a bar that has run over.
    pub danger: Color32,
    /// `success`.
    pub success: Color32,
    /// `warning`.
    pub warning: Color32,
    /// `info`.
    pub info: Color32,
    /// `border`, the authored line colour.
    ///
    /// A neutral badge's edge.
    pub border: Color32,
    /// `info-surface`: raised with 12 percent of `info`. A badge's fill.
    pub info_surface: Color32,
    /// `success-surface`.
    pub success_surface: Color32,
    /// `warning-surface`.
    pub warning_surface: Color32,
    /// `danger-surface`.
    pub danger_surface: Color32,
    /// `row-hover`: the row under the pointer, at 9 percent.
    pub row_hover: Color32,
    /// `row-rule`: the hairline between rows and around a table, at 26
    /// percent.
    pub row_rule: Color32,
    /// `row-selected`: a selected row, raised with 18 percent of the content
    /// ink (a neutral-ramp step). A fill and never a foreground.
    pub row_selected: Color32,
    /// `heat-0` to `heat-4`: the measure ramp, quietest first, from the
    /// raised ground to the cursor row's mix. Read through
    /// [`heat`](Self::heat).
    pub heats: [Color32; HEAT_BANDS as usize],
}

impl Palette {
    /// Every surface `page` and every ink `ink`, with no cast shadow.
    ///
    /// A starting point for the setters: an app that resolves its own colours
    /// starts here and sets each one. A colour added to this type later
    /// starts at one of these two.
    #[must_use]
    pub const fn two_tone(page: Color32, ink: Color32) -> Self {
        Self {
            page,
            raised: page,
            overlay: page,
            well: page,
            sunken: page,
            bevel_light: page,
            bevel_dark: ink,
            elevation: Color32::TRANSPARENT,
            content: ink,
            content_secondary: ink,
            content_muted: ink,
            content_disabled: ink,
            action: ink,
            content_on_action: page,
            danger: ink,
            success: ink,
            warning: ink,
            info: ink,
            border: ink,
            info_surface: page,
            success_surface: page,
            warning_surface: page,
            danger_surface: page,
            row_hover: page,
            row_rule: ink,
            row_selected: page,
            heats: [page; HEAT_BANDS as usize],
        }
    }

    /// Set [`page`](Self::page).
    #[must_use]
    pub const fn page(mut self, colour: Color32) -> Self {
        self.page = colour;
        self
    }

    /// Set [`raised`](Self::raised).
    #[must_use]
    pub const fn raised(mut self, colour: Color32) -> Self {
        self.raised = colour;
        self
    }

    /// Set [`overlay`](Self::overlay).
    #[must_use]
    pub const fn overlay(mut self, colour: Color32) -> Self {
        self.overlay = colour;
        self
    }

    /// Set [`well`](Self::well).
    #[must_use]
    pub const fn well(mut self, colour: Color32) -> Self {
        self.well = colour;
        self
    }

    /// Set [`sunken`](Self::sunken).
    #[must_use]
    pub const fn sunken(mut self, colour: Color32) -> Self {
        self.sunken = colour;
        self
    }

    /// Set [`bevel_light`](Self::bevel_light).
    #[must_use]
    pub const fn bevel_light(mut self, colour: Color32) -> Self {
        self.bevel_light = colour;
        self
    }

    /// Set [`bevel_dark`](Self::bevel_dark).
    #[must_use]
    pub const fn bevel_dark(mut self, colour: Color32) -> Self {
        self.bevel_dark = colour;
        self
    }

    /// Set [`elevation`](Self::elevation).
    #[must_use]
    pub const fn elevation(mut self, colour: Color32) -> Self {
        self.elevation = colour;
        self
    }

    /// Set [`content`](Self::content).
    #[must_use]
    pub const fn content(mut self, colour: Color32) -> Self {
        self.content = colour;
        self
    }

    /// Set [`content_secondary`](Self::content_secondary).
    #[must_use]
    pub const fn content_secondary(mut self, colour: Color32) -> Self {
        self.content_secondary = colour;
        self
    }

    /// Set [`content_muted`](Self::content_muted).
    #[must_use]
    pub const fn content_muted(mut self, colour: Color32) -> Self {
        self.content_muted = colour;
        self
    }

    /// Set [`content_disabled`](Self::content_disabled).
    #[must_use]
    pub const fn content_disabled(mut self, colour: Color32) -> Self {
        self.content_disabled = colour;
        self
    }

    /// Set [`action`](Self::action).
    #[must_use]
    pub const fn action(mut self, colour: Color32) -> Self {
        self.action = colour;
        self
    }

    /// Set [`content_on_action`](Self::content_on_action).
    #[must_use]
    pub const fn content_on_action(mut self, colour: Color32) -> Self {
        self.content_on_action = colour;
        self
    }

    /// Set [`danger`](Self::danger).
    #[must_use]
    pub const fn danger(mut self, colour: Color32) -> Self {
        self.danger = colour;
        self
    }

    /// Set [`success`](Self::success).
    #[must_use]
    pub const fn success(mut self, colour: Color32) -> Self {
        self.success = colour;
        self
    }

    /// Set [`warning`](Self::warning).
    #[must_use]
    pub const fn warning(mut self, colour: Color32) -> Self {
        self.warning = colour;
        self
    }

    /// Set [`info`](Self::info).
    #[must_use]
    pub const fn info(mut self, colour: Color32) -> Self {
        self.info = colour;
        self
    }

    /// Set [`border`](Self::border).
    #[must_use]
    pub const fn border(mut self, colour: Color32) -> Self {
        self.border = colour;
        self
    }

    /// Set [`info_surface`](Self::info_surface).
    #[must_use]
    pub const fn info_surface(mut self, colour: Color32) -> Self {
        self.info_surface = colour;
        self
    }

    /// Set [`success_surface`](Self::success_surface).
    #[must_use]
    pub const fn success_surface(mut self, colour: Color32) -> Self {
        self.success_surface = colour;
        self
    }

    /// Set [`warning_surface`](Self::warning_surface).
    #[must_use]
    pub const fn warning_surface(mut self, colour: Color32) -> Self {
        self.warning_surface = colour;
        self
    }

    /// Set [`danger_surface`](Self::danger_surface).
    #[must_use]
    pub const fn danger_surface(mut self, colour: Color32) -> Self {
        self.danger_surface = colour;
        self
    }

    /// Set [`row_hover`](Self::row_hover).
    #[must_use]
    pub const fn row_hover(mut self, colour: Color32) -> Self {
        self.row_hover = colour;
        self
    }

    /// Set [`row_rule`](Self::row_rule).
    #[must_use]
    pub const fn row_rule(mut self, colour: Color32) -> Self {
        self.row_rule = colour;
        self
    }

    /// Set [`row_selected`](Self::row_selected).
    #[must_use]
    pub const fn row_selected(mut self, colour: Color32) -> Self {
        self.row_selected = colour;
        self
    }

    /// Set [`heats`](Self::heats).
    #[must_use]
    pub const fn heats(mut self, ramp: [Color32; HEAT_BANDS as usize]) -> Self {
        self.heats = ramp;
        self
    }

    /// Every colour, read from a resolved makeover theme.
    ///
    /// # Errors
    ///
    /// [`MissingToken`] naming the first token the theme does not resolve.
    /// makeover derives every one of these for every shipped theme, so this
    /// fails only on a theme file missing a base intent.
    #[cfg(feature = "theme")]
    pub fn from_theme(tokens: &makeover::SemanticTokens) -> Result<Self, MissingToken> {
        use makeover::Token;
        let colour = |token: Token| {
            tokens
                .rgba(token)
                .map(|(r, g, b, a)| Color32::from_rgba_unmultiplied(r, g, b, a))
                .ok_or(MissingToken(token))
        };
        Ok(Self {
            page: colour(Token::SurfacePage)?,
            raised: colour(Token::SurfaceRaised)?,
            overlay: colour(Token::SurfaceOverlay)?,
            well: colour(Token::SurfaceWell)?,
            sunken: colour(Token::SurfaceSunken)?,
            bevel_light: colour(Token::BevelLight)?,
            bevel_dark: colour(Token::BevelDark)?,
            elevation: colour(Token::Elevation)?,
            content: colour(Token::Content)?,
            content_secondary: colour(Token::ContentSecondary)?,
            content_muted: colour(Token::ContentMuted)?,
            content_disabled: colour(Token::ContentDisabled)?,
            action: colour(Token::Action)?,
            content_on_action: colour(Token::ContentOnAction)?,
            danger: colour(Token::Danger)?,
            success: colour(Token::Success)?,
            warning: colour(Token::Warning)?,
            info: colour(Token::Info)?,
            border: colour(Token::Border)?,
            info_surface: colour(Token::InfoSurface)?,
            success_surface: colour(Token::SuccessSurface)?,
            warning_surface: colour(Token::WarningSurface)?,
            danger_surface: colour(Token::DangerSurface)?,
            row_hover: colour(Token::RowHover)?,
            row_rule: colour(Token::RowRule)?,
            row_selected: colour(Token::RowSelected)?,
            heats: [
                colour(Token::Heat0)?,
                colour(Token::Heat1)?,
                colour(Token::Heat2)?,
                colour(Token::Heat3)?,
                colour(Token::Heat4)?,
            ],
        })
    }
}

/// A token `Palette::from_theme` needed and the theme did not resolve.
#[cfg(feature = "theme")]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct MissingToken(pub makeover::Token);

#[cfg(feature = "theme")]
impl std::fmt::Display for MissingToken {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "the theme resolves no `{}`", self.0.as_str())
    }
}

#[cfg(feature = "theme")]
impl std::error::Error for MissingToken {}

impl Palette {
    /// Resolve a surface intent, or `None` for one this renderer does not know.
    ///
    /// A plain lookup with no substitution. Every [`Fill`] this renderer
    /// knows, `Fill::Sunken` included, is answered with `Some`.
    #[must_use]
    pub const fn fill(&self, fill: Fill) -> Option<Color32> {
        match fill {
            Fill::Page => Some(self.page),
            Fill::Raised => Some(self.raised),
            Fill::Overlay => Some(self.overlay),
            Fill::Well => Some(self.well),
            Fill::Sunken => Some(self.sunken),
            _ => None,
        }
    }

    /// The colour a [`Tone`] reads as.
    ///
    /// [`Tone::Neutral`] and a tone this renderer has not learnt (`Tone` is
    /// `#[non_exhaustive]`) read as [`content`](Self::content).
    #[must_use]
    pub const fn tone(&self, tone: Tone) -> Color32 {
        match tone {
            Tone::Neutral => self.content,
            Tone::Info => self.info,
            Tone::Success => self.success,
            Tone::Warning => self.warning,
            Tone::Danger => self.danger,
            // A tone this renderer has not learnt yet reads as an ordinary
            // fact rather than as a status it might misstate.
            _ => self.content,
        }
    }

    /// The fill a measure band sits on, or `None` at band 0, which is the
    /// ground and draws nothing. A band past the last reads as the last.
    #[must_use]
    pub const fn heat(&self, heat: Heat) -> Option<Color32> {
        let band = heat.0 as usize;
        if band == 0 {
            None
        } else if band < self.heats.len() {
            Some(self.heats[band])
        } else {
            Some(self.heats[self.heats.len() - 1])
        }
    }

    /// What a badge of this tone is filled with: its tone surface, or the
    /// raised surface for [`Tone::Neutral`], as `makeover-webview` fills one.
    #[must_use]
    pub const fn tone_surface(&self, tone: Tone) -> Color32 {
        match tone {
            Tone::Neutral => self.raised,
            Tone::Info => self.info_surface,
            Tone::Success => self.success_surface,
            Tone::Warning => self.warning_surface,
            Tone::Danger => self.danger_surface,
            _ => self.raised,
        }
    }

    /// What a badge of this tone is edged with: its tone, or
    /// [`border`](Self::border) for [`Tone::Neutral`], whose tone is the ink.
    #[must_use]
    pub const fn tone_edge(&self, tone: Tone) -> Color32 {
        match tone {
            Tone::Neutral => self.border,
            other => self.tone(other),
        }
    }

    /// The cast shadow for a surface that overlays the page.
    ///
    /// An [`egui::Shadow`] in [`elevation`](Self::elevation), for
    /// [`egui::Frame::shadow`]: `makeover-webview`'s overlay cast, a hard
    /// offset of `[3, 3]` down and right with no blur and no spread.
    /// [`host::visuals`] gives egui's own windows and popups the same shadow.
    ///
    /// ```no_run
    /// # let palette: makeover_immediate::Palette = unimplemented!();
    /// # let ui: &mut egui::Ui = unimplemented!();
    /// egui::Frame::popup(ui.style())
    ///     .shadow(palette.cast())
    ///     .show(ui, |ui| { ui.label("over the page"); });
    /// ```
    #[must_use]
    pub const fn cast(&self) -> egui::Shadow {
        egui::Shadow {
            offset: [3, 3],
            blur: 0,
            spread: 0,
            color: self.elevation,
        }
    }

    /// Resolve a bevel edge intent.
    #[must_use]
    pub const fn edge(&self, edge: Edge) -> Color32 {
        match edge {
            Edge::Light => self.bevel_light,
            Edge::Dark => self.bevel_dark,
            // An edge this renderer has not learnt is drawn as the border, the
            // one line every surface already has.
            _ => self.border,
        }
    }
}

/// The geometry a framed region is drawn with.
///
/// Every field is a value the caller resolves: radius and border width from
/// `makeover-geometry`, margins from its relational gaps.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct FrameStyle {
    /// Corner radius. Square under the Platinum default.
    pub radius: CornerRadius,
    /// Inner margin between the frame and its contents.
    pub margin: Margin,
    /// Bevel stroke width, in points.
    pub stroke: f32,
}

impl Default for FrameStyle {
    /// A one-point square frame with no inner margin.
    fn default() -> Self {
        Self {
            radius: CornerRadius::ZERO,
            margin: Margin::ZERO,
            stroke: f32::from(makeover_geometry::Stroke::Hairline.px()),
        }
    }
}

/// Paint a two-tone edge just inside `rect`.
///
/// Adds two polylines and nothing else, so it composes over what is already
/// painted: over an [`egui::TextEdit`] after `ui.add`, for one.
///
/// The polylines are inset by half a stroke. The first, in the tone
/// [`Bevel::edges`] gives the top and left, runs bottom-left, top-left,
/// top-right; the second, in the other tone, runs top-right, bottom-right,
/// bottom-left, and stops at bottom-right for a bevel that does not draw its
/// bottom. Each is one three-point line, so egui mitres its corner. The second
/// is drawn over the first, so the two corners where they meet take its tone.
pub fn paint_bevel(painter: &Painter, rect: Rect, bevel: Bevel, palette: &Palette, stroke: f32) {
    let (top_left, bottom_right) = bevel.edges();

    // Inset by half a stroke so the line lands inside `rect` rather than
    // straddling its edge, which on a fractional-scale display is the
    // difference between one crisp pixel and two dim ones.
    let r = rect.shrink(stroke / 2.0);

    painter.add(Shape::line(
        vec![r.left_bottom(), r.left_top(), r.right_top()],
        Stroke::new(stroke, palette.edge(top_left)),
    ));
    // Three points close the box, two leave the bottom open: the shaded run
    // comes down the right side and stops. That is the folder tab, and it is
    // the same edge the browser draws by dropping the shadow's vertical
    // offset. The lit polyline is untouched either way, so the join is the
    // only thing that changes.
    let shaded = if bevel.draws_bottom() {
        vec![r.right_top(), r.right_bottom(), r.left_bottom()]
    } else {
        vec![r.right_top(), r.right_bottom()]
    };
    painter.add(Shape::line(
        shaded,
        Stroke::new(stroke, palette.edge(bottom_right)),
    ));
}

/// Draw a region at a given [`Depth`]: its fill and its edge, together.
///
/// [`Depth::Flat`] gets neither and shows whatever it sits on. A depth whose
/// fill this palette does not resolve goes unfilled and keeps its bevel. An
/// overlay fill also takes [`Palette::cast`].
pub fn frame<R>(
    ui: &mut Ui,
    depth: Depth,
    palette: &Palette,
    style: FrameStyle,
    add_contents: impl FnOnce(&mut Ui) -> R,
) -> R {
    let mut f = egui::Frame::new()
        .corner_radius(style.radius)
        .inner_margin(style.margin);
    // Two ways there is no fill to paint, and they collapse to the same
    // outcome: the depth names none (Depth::Flat), or it names one this
    // renderer cannot resolve. Either way the frame goes unfilled and the
    // bevel below carries the depth on its own, which is the rule this
    // module already documents for Flat.
    if let Some(fill) = depth.fill().and_then(|f| palette.fill(f)) {
        f = f.fill(fill);
    }
    // A surface that overlays the page is cast onto it, with
    // [`Palette::cast`]. Keyed off the fill rather than the variant, so it stays right for whatever else the description calls an
    // overlay later.
    if depth.fill() == Some(Fill::Overlay) {
        f = f.shadow(palette.cast());
    }
    let framed = f.show(ui, add_contents);
    if let Some(bevel) = depth.bevel() {
        paint_bevel(
            ui.painter(),
            framed.response.rect,
            bevel,
            palette,
            style.stroke,
        );
    }
    framed.inner
}

/// The geometry a field group is drawn with.
///
/// The fields themselves are drawn by `quasi-immediate`. Every number here is
/// a `makeover-geometry` value the caller resolves, as in [`FrameStyle`],
/// which it embeds.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct FieldStyle {
    /// The well a text control sits in.
    pub frame: FrameStyle,
    /// Between a field's own parts: its label, its control, its hint and its
    /// error.
    pub gap: f32,
    /// Between one field and the next.
    pub group_gap: f32,
    /// What marks a required field, appended to its label. `"*"` by default.
    pub required_marker: &'static str,
}

impl Default for FieldStyle {
    /// The default frame, no gaps, and an asterisk.
    fn default() -> Self {
        Self {
            frame: FrameStyle::default(),
            gap: 0.0,
            group_gap: 0.0,
            required_marker: "*",
        }
    }
}

/// What the field currently holds, borrowed from wherever the app keeps it.
///
/// Handed to `quasi-immediate`'s field, which writes through it as the user
/// edits.
///
/// The editable counterpart of [`makeover_layout::Value`], which the other
/// renderers read back after the fact. The description carries neither.
///
/// `#[non_exhaustive]`: a host builds these and does not match on them.
#[derive(Debug, Default)]
#[non_exhaustive]
pub enum Editing<'a> {
    /// Nothing to edit. The control is drawn and does not answer.
    #[default]
    Absent,
    /// The buffer behind anything that takes typed text, a select included:
    /// what a select holds is the `value` of one of its options.
    Text(&'a mut String),
    /// A checkbox, on or off.
    On(&'a mut bool),
    /// The values of a [`FieldKind::Checklist`](makeover_layout::FieldKind::Checklist)'s ticked options.
    ///
    /// Ticking pushes the option's value and unticking removes it, so the
    /// order is the order things were ticked in.
    Ticked(&'a mut Vec<String>),
    /// The two buffers behind a [`FieldKind::Interval`](makeover_layout::FieldKind::Interval), lower first.
    ///
    /// Either end may be empty while the other stands: an open end
    /// ("over 120 BPM").
    Between {
        /// The lower end's buffer.
        lower: &'a mut String,
        /// The upper end's buffer.
        upper: &'a mut String,
    },
}

#[cfg(test)]
mod tests;