makeover_layout/lib.rs
1//! The renderer-agnostic half of the make-family design system.
2//!
3//! <!-- wiki: makeover-layout -->
4//!
5//! `makeover` answers *what colour*, and varies by theme. `makeover-geometry`
6//! answers *how much space*, and varies by density and surface. This crate
7//! answers *what the thing is*, and varies by nothing.
8//!
9//! # The deferral rule
10//!
11//! A description names intents and relationships, never values. Say
12//! [`Fill::Raised`], never `#D9DDF4`. Say `Gap::Peer`, never `6px`. What is
13//! left once colour and spacing are deferred is **composition**: which edges
14//! are lit, what inverts on press, what nests in what.
15//!
16//! The constraint that shapes all of it: a renderer that can only paint
17//! rectangles has to be able to express the result. egui has no
18//! `box-shadow: inset` and one stroke per widget with no per-side control; a
19//! terminal has box-drawing characters and one cell of resolution, and cannot
20//! draw a two-tone lit edge at all. A description that assumes per-side edges
21//! is a CSS description wearing a neutral name. So this crate names the
22//! *intent* — this region is a well — and each renderer chooses an expression
23//! it can actually produce, including dropping half of one.
24//!
25//! # Scope
26//!
27//! Depth came first: the bevel and the surfaces it shapes. That much was
28//! settled the hard way — the vocabulary here was read off audiofiles'
29//! `ui::theme` and `ui::widgets`, which are the only implementation written
30//! by a consumer with no CSS, then checked against both webview apps. All
31//! three agreed once Balanced Breakfast's fills were corrected.
32//!
33//! 0.2.0 adds the rest of the description, each member drawn the same way,
34//! from what the three apps already hand-write rather than from a taxonomy:
35//!
36//! - Components. [`Token`] (badge against chip), [`Notice`] (toast against
37//! banner), [`RowPart`], [`Heading`], [`Selector`], [`Readiness`], and
38//! [`Tone`], which is the one intent family they share.
39//! - Schemas. [`Field`] for forms and [`Column`] for lists and tables.
40//! - Structure. [`Region`] for the parts of a screen, [`Arrangement`] for how
41//! a screen is put together.
42//!
43//! **Validation** was absent on purpose here, on the grounds that neither app
44//! had a shared story. That reasoning is retired — see 0.11.0 below, which is
45//! where the constraints arrived and why the argument did not survive contact
46//! with what the apps were measured to do.
47//!
48//! 0.3.0 closes a gap the first real adoption found, which is what adopting
49//! against goingson first was for. [`Selector`] described only the *chosen*
50//! option, so an unchosen one fell through to [`Depth::Flat`] and no renderer
51//! drew it; goingson's tab strip recesses its unchosen tabs by hand and could
52//! not delete the line, because being recessed is *why* the chosen tab reads as
53//! coming forward. So [`Selector::unchosen`] joins `chosen`, and saying it
54//! needed [`Fill::Sunken`] and [`Depth::Sunken`]: a surface set back by colour
55//! with no edge, which is neither a well nor level-with.
56//!
57//! 0.7.0 adds [`State`], the interaction axis, closing the gap that adopting
58//! against three apps rather than one made visible. The description named
59//! rest and, through [`Depth::pressed`], pressed. It named neither focus nor
60//! disabled, so `makeover-webview` emitted a hover rule and stopped, and each
61//! consumer completed the primitive from outside by out-specifying a rule it
62//! did not own: 19 such rules in goingson, 21 in the MNW server, a further set
63//! in Balanced Breakfast, and three focus rings that do not match. The axis is
64//! deliberately two members wide, because hover and pressed belong where they
65//! already are. [`State`]'s own docs carry that argument.
66//!
67//! 0.8.0 finishes [`Field`], which described a field well enough to label it and
68//! not well enough to draw it. Writing `makeover-webview`'s form emitter found
69//! three things missing and the renderer supplied all three from outside: the
70//! current value, a select's options, and the placeholder. Two of those move
71//! here and one does not.
72//!
73//! - [`Field::placeholder`] is user-facing text sitting beside `label` and
74//! `hint`. There was never a reading on which it was renderer state; it was
75//! outside only because adding a field to a published struct is breaking.
76//! - [`Field::options`] moves because every renderer needs them and each was
77//! going to invent its own shape. [`Choice`] is the shape `makeover-webview`
78//! already arrived at, taken as-is rather than redesigned.
79//! - The current value stays renderer-side and is not coming here. It is the
80//! one of the three that is genuinely state: a webview reads it out of the
81//! DOM, an immediate-mode renderer holds a `&mut` to the app's own field, and
82//! a description that carried it would be a form model.
83//!
84//! 0.9.0 opens [`RowPart`], which was the last closed enum in the vocabulary,
85//! and adds [`RowPart::Tokens`]. Both halves come from the same finding, made
86//! by the first two real screens described through the router rather than by
87//! reading a stylesheet.
88//!
89//! A goingson project card carries two trailing badges, a type and a toned
90//! status; a contact card carries a primary email *and* a strip of tags. `Meta`
91//! is one slot and one string, so both ports joined their facts with a
92//! separator and lost what the second one was: a status reads as text where it
93//! used to read as colour. [`Token`] already says exactly the right thing — a
94//! small labelled thing with a kind, a tone and an optional action — and could
95//! only ever be a node in its own right, never inside a row.
96//!
97//! So the missing thing was permission rather than a concept. `Tokens` is that
98//! permission, and `#[non_exhaustive]` arrives with it so the next member is not
99//! a lockstep event across three renderers. The pairing is the point: this
100//! enum's own consumer in `makeover-webview` carried a comment predicting it
101//! would stop compiling one day, which is a lockstep break written down and
102//! waited for rather than prevented.
103//!
104//! Balanced Breakfast was checked before the member was added, because one
105//! consumer wanting something is not evidence. It packs a count and two icon
106//! buttons into the same single `Meta` slot while leaving `Actions` empty, so
107//! the slot was already straining under a second consumer for a different
108//! reason.
109//!
110//! 0.10.0 adds [`Meter`], a proportion carried as a pair rather than as a
111//! percentage. Its own docs carry the argument; the short form is that the
112//! percentage shape had already been tried in goingson and had already needed a
113//! companion flag to recover what rounding and clamping threw away.
114//!
115//! 0.11.0 is four members from the quasi proving ground, batched into one
116//! release because pre-1.0 a minor is breaking and a cascade is nine repos.
117//! Three findings that arrived with them turned out not to belong here at all:
118//! this crate has no notion of an action, a route or a destination, so anything
119//! asking what a control *calls* was never the vocabulary's to say.
120//!
121//! - [`Figure`], a value with a caption. goingson had five of them across five
122//! screens with five class vocabularies for the one shape, which is the
123//! divergence this crate exists to end, sitting in plain sight and counted for
124//! the first time.
125//! - [`RowPart::Proportion`], so a [`Meter`] can sit in a row. `Meter` reached
126//! two of its seven sites at 0.10.0 and the other five are row-shaped. Exactly
127//! [`RowPart::Tokens`]'s problem with a different payload, and it takes
128//! `Tokens`' answer: the part carries the description of a bar, not a node.
129//! - [`Field::max_length`], [`Field::min`] and [`Field::max`], joining
130//! [`Field::required`], which had been sitting here as the sole constraint
131//! while the header above claimed there were none. The set stops before
132//! `pattern`, which fails the renderer test and is one site in one app.
133//! - [`FieldKind::File`]. Every host has an honest answer — a native picker, an
134//! `<input type="file">`, a path prompt, an argument — and it carries no
135//! accepted-types list because `accept` appears at zero sites in either app.
136//!
137//! The evidence rule changed under these, and it is worth recording because four
138//! earlier decisions were made under the old one. The two-app test said a shape
139//! earns a word once a second app wants it. It is backwards: a rule that
140//! withholds a word until a second app has duplicated the code guarantees the
141//! duplication, and app three writes it a third time. The bar is now generic
142//! against bespoke — is this furniture any app would have, or is it this app's
143//! own? Bespoke keeps [`Region::Bespoke`], which already carries a completion
144//! heatmap and is the right answer for a calendar nobody will build twice.
145//!
146//! 0.12.0 is two more from the same proving ground, and the same sorting
147//! happened first: six findings came out of a measurement of goingson's whole
148//! frontend, and four of them turned out to be asking what a control *calls*,
149//! which this crate cannot say. The two that were really here:
150//!
151//! - [`Readiness`] grows from two states to four. It named `Ready` and
152//! `Pending` and stopped, so a screen whose list came back empty had nothing
153//! to say about it; goingson draws an empty state at 27 sites and Balanced
154//! Breakfast at 9. `Empty` and `Failed` are the same axis rather than a new
155//! member beside it, because a region shows one of the four and never two.
156//! `#[non_exhaustive]` arrives with them, the pairing [`RowPart`] made at
157//! 0.9.0 and for the same reason.
158//! - [`Column::sortable`], [`Column::sorted`] and [`Sort`]. The one finding in
159//! the set that completes a member rather than adding one: `Column` shipped
160//! with a width and a priority and could not say that a table is ordered by a
161//! column, so a described table could draw no caret and offer no reordering.
162//!
163//! 0.14.0 is two additive members on two `#[non_exhaustive]` enums, released
164//! together because publishing twice for that is waste and the cascade below
165//! this crate is nine repos.
166//!
167//! - [`Depth::Overlay`]. The enum could say raised, well, sunken and flat, and
168//! could not say that a surface sits *over* the page. Every renderer already
169//! had the surface — `makeover-tui`'s `Palette::overlay`,
170//! `makeover-immediate`'s `Palette::elevation`, `makeover-webview`'s
171//! `--elevation-overlay` — and none of them could be reached from a
172//! description. buckets_of_money has 16 modals waiting on it.
173//! - [`CellPart`], which is [`RowPart`] for tables. A row's parts have carried
174//! their own content intent since 0.2.0, so `.row-actions` inherits rather
175//! than taking a text colour; a table cell had no such vocabulary and
176//! `makeover-webview` emitted one undifferentiated `.cell`, so a button in a
177//! cell was painted as text. The four members are the four things quasi's
178//! `Cell` was measured to hold, and the count is in that crate's history
179//! rather than assumed here.
180//!
181//! 0.15.0 adds [`FieldKind::Date`] and [`FieldKind::DateTime`], on the argument
182//! [`FieldKind::Email`] was admitted on: a webview emits a different `type=`,
183//! which is a native picker, the platform's validation and a different keyboard
184//! on a touch device. Described as text with a "YYYY-MM-DD" hint, all three are
185//! lost.
186//!
187//! Two members and not one or five, from a count rather than from symmetry: 13
188//! sites of `date` and 13 of `datetime-local` across the MNW server and
189//! goingson, and zero of `time`, `month` or `week`. The wire format each takes
190//! is named here as [`DATE_FORMAT`] and [`DATETIME_FORMAT`], because a host
191//! left to pick its own would disagree with a server silently, and
192//! [`FieldKind::temporal`] is the pair asked about once rather than at each
193//! renderer. `FieldKind`'s own comment claiming `radio` was the last HTML input
194//! type missing was already false when 0.8.1 wrote it; these are what it was
195//! missing.
196//!
197//! What each of the 0.12.0 findings deliberately leaves out is the address — what pressing a
198//! header calls, and where an empty state's "Add your first project" button
199//! goes. That is the boundary this crate is defined by, and four findings moved
200//! across it rather than being answered here.
201//!
202//! 0.19.0 narrows [`State`] to [`State::Disabled`] alone. `State::Focus` is
203//! gone: a description never states what has focus, because what focus *is*
204//! differs per host and every renderer had already decided for itself — the
205//! webview draws it from `:focus-visible`, egui refused the variant outright,
206//! and quasi-tui honoured it once at startup and overrode it thereafter.
207//!
208//! 0.20.0 adds [`Region::Widget`], the third tier, and `#[non_exhaustive]` to
209//! [`Region`] with it. Every vocabulary finding until now had two answers
210//! available — grow the primitive set, or [`Region::Bespoke`] — and a whole
211//! class of thing is wrong for both. A carousel is not a primitive, because a
212//! terminal has none and that is the test `Node::Html` failed. It is not
213//! bespoke either, because bespoke is what one app owns and every part of a
214//! carousel is furniture plus members this crate already has.
215//!
216//! The cost of the binary was that refusing a primitive was expensive: the app
217//! hand-rolls the thing forever, so the pressure always ran toward growing the
218//! primitive set with one host's idioms. A named assembly changes what "no"
219//! costs without changing what the vocabulary can say.
220//!
221//! MNW's carousel is the first consumer and was the finding that started it: one
222//! partial, three pages, an ordered set of frames with a position, prev/next and
223//! a dot strip, all of it sayable already and none of it nameable. See wiki
224//! `widget-tier` for the ownership model, which is why this member carries a
225//! name a renderer may decline to know.
226//!
227//! 0.21.0 adds [`Image`] and [`Fit`], found by trying to describe MNW's
228//! carousel under 0.20.0's widget tier and getting one step in. Nothing named a
229//! picture. The vocabulary could say a number with a caption, a badge, a meter
230//! and a table, and could not say the thing three of MNW's public pages are
231//! mostly made of.
232//!
233//! It reads as an oversight and is a measurement: 24 `<img>` sites across 22
234//! MNW templates, against one in goingson and none in Balanced Breakfast or
235//! audiofiles. A picture is furniture a *content platform* has, and MNW is the
236//! only one in the tree, so the evidence never arrived from the two-app
237//! direction the earlier rule looked in. Under the generic-against-bespoke bar
238//! it is not close: a picture is not one app's own.
239//!
240//! A primitive rather than a widget, which is worth stating now that the tier
241//! makes it a real question. A widget is an assembly of things already sayable
242//! and a picture is a leaf, assembled from nothing. It also passes the test
243//! `Node::Html` failed — every host has an honest answer, including a terminal,
244//! which has a graphics protocol or has [`Image::alt`].
245//!
246//! [`Image`] carries no source, the split [`Act`] already makes: an address is
247//! not this crate's to hold. See its own docs, which is where the argument is.
248//!
249//! 0.22.0 finishes [`Image`], which 0.21.0 shipped unable to say how much room
250//! a picture needs. Without that a renderer cannot reserve space, so a picture
251//! occupies nothing until its bytes arrive and then takes its full height at
252//! once. Measured on MNW's landing page: a 478px jump per frame and a
253//! cumulative layout shift of 0.087 for the page.
254//!
255//! - [`Image::intrinsic`], the picture's own dimensions, carried as [`Extent`].
256//! A fact about the asset rather than a display size, which is what keeps it
257//! on this side of the deferral rule: 5120x3412 is what the file *is*, and no
258//! renderer can learn it without fetching the bytes.
259//! - [`Loading`], and the default flips to [`Loading::Eager`]. 0.21.0 emitted
260//! the webview's `loading="lazy"` for every picture, which read one
261//! consumer's habit as a rule. Deferring a picture that is on screen at first
262//! paint saves nothing and makes its shift land later. The carousel is the
263//! case that proves this cannot be one renderer-wide setting: its first frame
264//! is on screen and its others are not, in one widget, at one moment.
265//!
266//! 0.23.0 adds [`Showing`], which is three open findings collapsing into one
267//! member. A tab group could not say which tab was open, a carousel could not
268//! say which frame was up, and a disclosure could not say whether its child was
269//! showing. All three are the same missing sentence, and while it was missing a
270//! renderer had two moves: match on a widget name, or draw every child.
271//!
272//! So the widget tier was taking the blame for a gap one level below it. With
273//! this a renderer derives its chrome from the description — labels get a strip,
274//! no labels get previous/position/next — once, for every widget there will ever
275//! be, and [`Region::Widget`]'s name goes back to being app vocabulary a
276//! renderer may decline to know.
277//!
278//! Only the kind lives here. Which child is up, and what each child is called,
279//! sit with whatever holds the regions, the same split [`Selector`] already made
280//! against `Node::Select`.
281//!
282//! # Reach, focus and the focus ring
283//!
284//! Three terms, and no others, for what 0.19.0 moved out of the description.
285//! **Reach** is which things can take focus and in what order; a browser reads
286//! it off the document, a TUI derives it from draw order, egui from its own id
287//! stack. **Focus** is which reached thing has the keyboard right now: the
288//! renderer's, live, never described and never round-tripped through a
289//! description. The **focus ring** is the visible cue; the token (`focus-ring`,
290//! derived by `makeover` from the action colour) is the one shared artifact and
291//! the drawing is the renderer's. Retired as names for any of this: "focus
292//! stroke", "focus cue", "wants focus". "Caret" is a different thing — the text
293//! cursor inside a field — and keeps its name.
294//!
295//! # Where the description stops
296//!
297//! The rule is that a member is added when an app needs a fact the vocabulary
298//! cannot state, and refused when what it wants is presentation it should be
299//! asking a renderer for. That is the whole test. It is not a quota, and the
300//! goal is every screen described.
301//!
302//! ## What the timeline refusal got wrong, 2026-08-15
303//!
304//! This section used to read "a day-plan timeline, a kanban board and a
305//! calendar are not describable here and will not become describable", and it
306//! propagated: 12 files across three apps, three libraries and the design wiki
307//! cited it, including audiofiles and the MNW server, neither of which has a
308//! timeline. It is withdrawn, and [`Track`] is the member it was refusing.
309//!
310//! The error was pricing. The argument assumed a timeline needs a component
311//! library's worth of vocabulary, and nobody measured it. Held against
312//! goingson's `day-planning-render.js`, the members it actually needed and
313//! could not get were two integers: where a thing starts, and how long it
314//! lasts. Labels, gridlines, item bodies and tones were all furniture this
315//! crate already named. A refusal that expensive should have carried a
316//! measurement, and did not.
317//!
318//! The reasoning underneath it survives and is still the test: slot heights,
319//! gridline colour, how overlapping things stack, which hour scrolls into view.
320//! Those are presentation, they stay the renderer's, and [`Track`] carries none
321//! of them. What changed is the conclusion, not the principle.
322//!
323//! ## The other two, measured 2026-08-15
324//!
325//! The same sentence refused a kanban board and a calendar. Both were counted
326//! the way the timeline should have been, and neither came out where the
327//! refusal put it.
328//!
329//! **Kanban: one member, and it is [`Region::Columns`].** Held against
330//! goingson's `tasks-kanban.js`, every card fact was already sayable — title,
331//! project, due date, the blocked and unblocks badges, subtask progress, the
332//! open action and the context menu are `Row`'s existing parts. A column is a
333//! heading, a count and a list. What nothing could say was that the columns are
334//! *peers*: [`Arrangement`] offers list-detail and sidebar-content, and a board
335//! described as either is a lie about the screen. Dragging a card between
336//! columns never entered into it — a drop's effect is "set status", a discrete
337//! action `Row`'s menu already carries, and the drag itself is affordance.
338//!
339//! **Calendar: no members, and no consumer.** A month grid renders today as a
340//! [`Table`](crate::Column): seven weekday columns, weeks as rows, blanks for
341//! the offset. goingson's monthly review reached this conclusion before this
342//! note did and describes its month as a list of days that had something on
343//! them, marking today with an ordinary badge. What the tree actually contains
344//! is two completion heatmaps — one scalar per day — and no calendar at all:
345//! `events-calendar.js` was deleted 2026-08-11 in favour of a segmented list,
346//! and no MNW template mentions one. So the refusal was defending a screen
347//! nobody has. If one is built, measure again; the facts already fit and only
348//! the grid's shape would be in question.
349//!
350//! The pattern worth keeping from all three: one sentence refused three things
351//! for one reason, and the reason was wrong three different ways. Count the
352//! members.
353//!
354//! [`Region::Bespoke`] remains for the genuinely app-owned, and its
355//! justification does not depend on the withdrawn claim. The
356//! description names the *place* and the app owns the contents, so a screen
357//! containing a timeline is still a whole screen and still routable. Without
358//! it, the four goingson screens that make the app worth using would need a
359//! second, undescribed path beside the router, and two paths is how a
360//! vocabulary starts drifting from its app again.
361//!
362//! [`Region::Widget`] sits between that limit and the primitives, and it does
363//! not move the limit. A widget is an assembly of members this crate *already*
364//! has, under a name a renderer may or may not recognise. Anything that needs a
365//! member the vocabulary does not have is still a finding about the vocabulary
366//! or still bespoke; naming an assembly buys no new expressive power, which is
367//! exactly why it is safe to let the set grow outside this crate.
368
369#![forbid(unsafe_code)]
370
371/// A colour intent this crate refers to but never resolves.
372///
373/// The string is the token name `makeover` publishes, so a renderer can look
374/// it up without this crate knowing what colour came back.
375pub trait Intent {
376 /// The `makeover` intent token this resolves against.
377 fn token(self) -> &'static str;
378}
379
380/// Which way the light falls across a two-tone edge.
381///
382/// The whole content of a bevel, once colour and thickness are deferred. The
383/// light is always assumed to come from the top left: every consumer measured
384/// agreed on that and none of them ever varied it, so it is an invariant here
385/// rather than a parameter.
386///
387/// # The two corners that belong to both edges
388///
389/// Top-right and bottom-left are where the lit run meets the shaded one, and
390/// the description's claim is that they belong to *both*. How a renderer says
391/// that is its own business, because the answer is bounded by resolution and
392/// not by taste:
393///
394/// - A terminal cell is roughly 8x17 device pixels, so giving the whole corner
395/// to one tone thickens that edge by a cell and reads as one run overrunning
396/// the other. A half-cell glyph divides the cell already, so `makeover-tui`
397/// splits it and recovers real information. Its box-drawing fallback cannot:
398/// a single stroke has no half to give, so there both corners go to dark.
399/// - A pixel bevel is a one-point stroke by default, which makes the corner a
400/// one-point square. There is nothing to divide — a diagonal seam across one
401/// point is sub-pixel, and antialiasing renders it as the blend a mitred join
402/// already produces. So `makeover-immediate` mitres and is *not* diverging;
403/// it is the same rule at a resolution where the split degenerates.
404///
405/// Stated here so the difference reads as a decision rather than as drift. A
406/// renderer with room to divide the corner should; one without should mitre or
407/// pick the shaded tone, and neither is a bug.
408#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
409pub enum Bevel {
410 /// Lit from the top left: light on top and left, dark on bottom and right.
411 Raised,
412 /// The same edge inverted, which is also the pressed state of anything
413 /// that draws itself [`Bevel::Raised`].
414 Inset,
415}
416
417impl Bevel {
418 /// The edge intents, as `(top_left, bottom_right)`.
419 ///
420 /// Split out from any painting because the inversion *is* the idea, and
421 /// it is the one part every renderer implements identically.
422 #[must_use]
423 pub const fn edges(self) -> (Edge, Edge) {
424 match self {
425 Self::Raised => (Edge::Light, Edge::Dark),
426 Self::Inset => (Edge::Dark, Edge::Light),
427 }
428 }
429
430 /// Pressing inverts. A raised control reads as inset while held.
431 ///
432 /// Stated here rather than left to each consumer because a cascade can
433 /// carry a pressed state and an immediate-mode renderer cannot: audiofiles
434 /// resolves this per call site, eighteen times.
435 #[must_use]
436 pub const fn pressed(self) -> Self {
437 match self {
438 Self::Raised => Self::Inset,
439 Self::Inset => Self::Raised,
440 }
441 }
442}
443
444/// One side of a bevel, named by the intent it takes.
445#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
446pub enum Edge {
447 /// The lit side.
448 Light,
449 /// The shadowed side.
450 Dark,
451}
452
453impl Intent for Edge {
454 fn token(self) -> &'static str {
455 match self {
456 Self::Light => "bevel-light",
457 Self::Dark => "bevel-dark",
458 }
459 }
460}
461
462/// A surface intent a region is filled with.
463///
464/// `#[non_exhaustive]`, so a renderer must carry a wildcard arm and a new
465/// member is additive rather than breaking. Added 0.4.0, after [`Sunken`]
466/// (an additive member, 0.3.0) hard-broke `makeover-tui` and
467/// `makeover-immediate` at compile time and left neither able to move until
468/// both published. The vocabulary exists to grow and the renderers exist to
469/// disagree about how much of it they answer, so growth must not be a
470/// lockstep event. The renderer's wildcard is not a hole: [`Fill`] is
471/// resolved through a fallible lookup, and a missing intent is answered with
472/// structure rather than with a substituted colour.
473///
474/// [`Sunken`]: Fill::Sunken
475#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
476#[non_exhaustive]
477pub enum Fill {
478 /// The page behind everything.
479 Page,
480 /// A surface lifted off the page: cards, controls, menus, toasts.
481 Raised,
482 /// A surface floating above the page rather than resting on it.
483 Overlay,
484 /// The inside of a well.
485 Well,
486 /// A surface set back from the one it sits on, by colour and nothing else.
487 ///
488 /// Not a well. A well is a hole with an edge, and the two are authored in
489 /// opposite directions: `makeover` derives `surface-well` by inverting
490 /// against the theme's own content colour, while `surface-sunken` is
491 /// authored and free to sit darker than raised (goingson's does). Naming
492 /// only the well left the recessed-with-no-edge surface unsayable, which is
493 /// what an unchosen tab is: it recedes so the chosen one can come forward,
494 /// and it carries no bevel of its own.
495 ///
496 /// Added 0.3.0, from goingson's tab strip, which hand-writes exactly this
497 /// and could not delete the line because no member described it.
498 Sunken,
499}
500
501// No `fallback` here, deliberately. An earlier cut had `Fill::Well` fall back
502// to `Fill::Page` so a consumer on makeover 2.2.0, which has no `surface-well`,
503// had something to paint. makeover-tui found that wrong within a day: page is
504// the surface a well is usually cut into, so on a terminal that substitution
505// produces exactly the invisibility it was meant to prevent, and the right
506// answer there is a drawn edge rather than a different colour.
507//
508// Substituting one intent for another is renderer policy. The description says
509// what the region is and stops.
510
511impl Intent for Fill {
512 fn token(self) -> &'static str {
513 match self {
514 Self::Page => "surface-page",
515 Self::Raised => "surface-raised",
516 Self::Overlay => "surface-overlay",
517 Self::Well => "surface-well",
518 Self::Sunken => "surface-sunken",
519 }
520 }
521}
522
523/// How a region sits relative to the surface behind it.
524///
525/// Fill and bevel are named together because naming them apart is what let
526/// them disagree. Every consumer measured had at least one region carrying a
527/// raised bevel over a recessed fill: audiofiles fixed it in `raised_frame`
528/// and recorded the bug in its doc comment, and Balanced Breakfast still had
529/// twelve of them a year later. A single name for the pair makes that
530/// unrepresentable.
531/// `#[non_exhaustive]` for the same reason as [`Fill`], and in the same
532/// release: a depth this renderer has no drawing for should cost it a
533/// wildcard arm, not a compile error and a wait on someone else's publish.
534#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
535#[non_exhaustive]
536pub enum Depth {
537 /// Level with its surroundings. No edge.
538 Flat,
539 /// A card laid on the panel it sits in.
540 Raised,
541 /// A hole in the panel, with content down inside it. For anything the
542 /// user looks *into*: a table body, a tag tree, a text field.
543 Well,
544 /// Set back from what it sits on, by colour alone. No edge.
545 ///
546 /// The one member carrying a fill without a bevel, so a renderer cannot
547 /// assume the two arrive together. That is deliberate and it is still the
548 /// pairing rule: both halves come off the same `Depth`, so they cannot
549 /// disagree, and here one half is legitimately absent.
550 ///
551 /// Distinct from [`Depth::Flat`], which has no fill either and inherits.
552 /// Recessed and level-with are different claims, and only one of them
553 /// needs a colour.
554 Sunken,
555 /// A surface sitting *over* the page rather than in it. A modal, a popover,
556 /// a menu.
557 ///
558 /// Takes elevation and no bevel: a surface overlaying the page is lifted
559 /// off it, and a surface in the page is cut into it. That is the same
560 /// pairing rule the rest of the enum holds, applied to the one case where
561 /// the separation is not an edge at all — the lift and the scrim behind it
562 /// are already saying where the surface is.
563 ///
564 /// Every renderer had the surface before it had this variant.
565 /// `makeover-tui` carries `Palette::overlay`, `makeover-immediate` gained
566 /// `Palette::elevation` at 0.10.0, and `makeover-webview` emits
567 /// `--elevation-overlay`. What was missing was the route from a description
568 /// to any of them, which is why this is one variant rather than a feature.
569 Overlay,
570}
571
572impl Depth {
573 /// The edge this depth is drawn with, if it has one.
574 #[must_use]
575 pub const fn bevel(self) -> Option<Bevel> {
576 match self {
577 // Sunken joins Flat here, for the opposite reason: Flat has no edge
578 // because nothing separates it from its surroundings, and Sunken has
579 // none because its colour is already doing the separating.
580 Self::Flat | Self::Sunken => None,
581 // A third reason to have no edge, which is why it gets its own arm
582 // rather than joining the two above: an overlay is separated by the
583 // lift and by the scrim behind it, so an edge would be a second
584 // answer to a question already answered.
585 Self::Overlay => None,
586 Self::Raised => Some(Bevel::Raised),
587 Self::Well => Some(Bevel::Inset),
588 }
589 }
590
591 /// The surface this depth is filled with.
592 ///
593 /// [`Depth::Flat`] has no fill of its own: it inherits whatever it sits on,
594 /// which is the difference between level-with and painted-the-same-colour.
595 #[must_use]
596 pub const fn fill(self) -> Option<Fill> {
597 match self {
598 Self::Flat => None,
599 Self::Raised => Some(Fill::Raised),
600 Self::Well => Some(Fill::Well),
601 Self::Sunken => Some(Fill::Sunken),
602 Self::Overlay => Some(Fill::Overlay),
603 }
604 }
605
606 /// Pressing a raised region reads as a well, and nothing else moves.
607 ///
608 /// [`Depth::Overlay`] is untouched along with the rest: an overlay is a
609 /// surface, not a control, so there is nothing there to press.
610 #[must_use]
611 pub const fn pressed(self) -> Self {
612 match self {
613 Self::Raised => Self::Well,
614 other => other,
615 }
616 }
617}
618
619/// An interaction state a region can be in, beside whatever [`Depth`] it is.
620///
621/// Orthogonal to depth on purpose. A disabled button is still [`Depth::Raised`]
622/// and a disabled field is still a [`Depth::Well`], so folding either member
623/// into `Depth` would make [`Depth::bevel`] and [`Depth::fill`] answer for
624/// something that is not a depth, and would leave disabled-button and
625/// disabled-field sharing one variant that cannot tell them apart.
626///
627/// # Why hover and pressed are not members
628///
629/// The line is whether every renderer has the state to express, not whether CSS
630/// does. Hover is renderer policy and `makeover-webview` says so in its own
631/// header: a terminal and an immediate-mode painter have no pointer hovering
632/// over anything, and pressed already arrives through [`Bevel::pressed`] and
633/// [`Depth::pressed`], where it belongs, because pressing is a depth inversion
634/// rather than a separate condition.
635///
636/// Focus and disabled are different in kind. A TUI has a focused widget and a
637/// greyed-out one; so does egui. Both were unsayable here, so all three webview
638/// consumers supplied them from outside the primitive by out-specifying rules
639/// they did not own: goingson alone carries 19 of them, and the MNW server
640/// another 21. That is the divergence this crate exists to end, arriving one
641/// layer down.
642///
643/// # The principle this encodes
644///
645/// A primitive owns every state it implies. A renderer that emits a hover rule
646/// for a thing owes disabled and the capability answer for that same thing,
647/// because anything less exports the completion work to N consumers who will
648/// each do it differently.
649///
650/// Focus is not on that list and was removed from this axis in 0.19.0. It is
651/// the renderer's, decided after the description; see the crate header, "Reach,
652/// focus and the focus ring", for the three terms and who owns each.
653///
654/// `#[non_exhaustive]` for the reason [`Fill`] and [`Depth`] carry it: growth
655/// must not be a lockstep event across the three renderers.
656#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
657#[non_exhaustive]
658pub enum State {
659 /// Present, visible, and not answering.
660 ///
661 /// Not the same as absent, and deliberately not a [`Fill`]: a disabled
662 /// control keeps the surface it always had and stops responding, so what
663 /// changes is its content and its interactivity rather than what it is.
664 Disabled,
665}
666
667impl State {
668 /// Whether a region in this state stops answering the pointer.
669 ///
670 /// Stated in the description rather than left to each renderer, on the same
671 /// reasoning as [`Bevel::pressed`]: a cascade carries it for free and an
672 /// immediate-mode renderer resolves it per call site, so leaving it unsaid
673 /// means resolving it once per consumer and disagreeing.
674 #[must_use]
675 pub const fn suppresses_interaction(self) -> bool {
676 // A match rather than a bare `true`, so a member added to this
677 // `#[non_exhaustive]` axis has to answer the question rather than
678 // inheriting an answer.
679 match self {
680 Self::Disabled => true,
681 }
682 }
683}
684
685impl Intent for State {
686 fn token(self) -> &'static str {
687 match self {
688 // Reusing the muted content intent rather than minting a
689 // `disabled` colour. Disabled is a reduction and not a status, and
690 // `makeover-webview`'s progress rules already record the reading
691 // that `content-muted` is what disabled looks like.
692 Self::Disabled => "content-muted",
693 }
694 }
695}
696
697/// What a region is saying, when it is saying something.
698///
699/// The one intent family shared by badges, notices and nothing else. Kept
700/// separate from [`Fill`] because a surface is where a thing sits and a tone is
701/// what it means, and the three apps agree on the four statuses:
702/// `info_banner` / `warning_banner` in audiofiles, `.toast-info` /
703/// `.toast-success` / `.toast-error` in goingson, `.toast.success` /
704/// `.toast.error` in Balanced Breakfast.
705///
706/// The per-tag palette (`category-one` through `category-six`) is deliberately
707/// not here. Which colour a *particular* tag takes is app domain, and both
708/// webview apps already carry it as a `data-color` attribute.
709#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
710pub enum Tone {
711 /// No status. Reads as ordinary de-emphasised content.
712 Neutral,
713 /// Something worth knowing and nothing to do about it.
714 Info,
715 /// Something finished and it worked.
716 Success,
717 /// Something the user should look at before continuing.
718 Warning,
719 /// Something broken, or something about to be destroyed.
720 Danger,
721}
722
723impl Intent for Tone {
724 fn token(self) -> &'static str {
725 match self {
726 // Neutral has no status token of its own. It takes the muted
727 // content intent, which is what both webview apps already spell as
728 // `data-color="muted"`.
729 Self::Neutral => "content-muted",
730 Self::Info => "info",
731 Self::Success => "success",
732 Self::Warning => "warning",
733 Self::Danger => "danger",
734 }
735 }
736}
737
738/// A small labelled thing that sits inside something else.
739///
740/// Two members, because the three apps drew three taxonomies and only one line
741/// runs through all of them: does it answer a click. audiofiles has
742/// `classification_badge` (a label) against `tag_chip`, `tag_chip_removable`
743/// and `selectable_tag` (all of which do). Balanced Breakfast has `.tag` and
744/// `.badge` against `.tag-chip`. goingson is the one that has to move: its
745/// `.tag` and `.badge` are a single CSS rule, so every call site has to be read
746/// to decide which of the two it always was.
747///
748/// The evidence that a chip is a real concept rather than a badge with a
749/// cursor: audiofiles inverts its bevel on press and Balanced Breakfast latches
750/// `.tag-chip.active` with the inset bevel. Two independent arrivals at "a chip
751/// holds itself down", which is exactly what [`Depth::pressed`] already says.
752#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
753pub enum Token {
754 /// Non-interactive status or count. Answers no click.
755 Badge,
756 /// An interactive or removable token. Answers a click, and latches if it
757 /// stands for a filter that is either on or off.
758 Chip {
759 /// Whether it carries its own remove affordance.
760 removable: bool,
761 },
762}
763
764impl Token {
765 /// Whether this answers a click.
766 ///
767 /// The whole difference between the two members, and the reason a renderer
768 /// with no hover (a touch surface, a terminal) can still tell them apart.
769 #[must_use]
770 pub const fn interactive(self) -> bool {
771 matches!(self, Self::Chip { .. })
772 }
773
774 /// How it sits, given whether it is currently latched down.
775 ///
776 /// A badge is flat: it is a label, and giving it an edge would say it can
777 /// be pressed. A chip is raised, and inset while latched.
778 #[must_use]
779 pub const fn depth(self, latched: bool) -> Depth {
780 match self {
781 Self::Badge => Depth::Flat,
782 Self::Chip { .. } if latched => Depth::Well,
783 Self::Chip { .. } => Depth::Raised,
784 }
785 }
786}
787
788/// Something the app is telling the user, unprompted.
789///
790/// Two concepts, not one with a placement. They differ in more than where they
791/// sit: a toast is transient, stacked and self-dismissing, and a banner is
792/// persistent, in flow, one per region, and dismissed by fixing the condition
793/// it reports. Folding them into one member with a placement parameter would
794/// make lifetime, stacking and dismissal all placement-dependent, which is the
795/// description leaking renderer policy.
796///
797/// All three apps have banners: `info_banner` and `warning_banner` in
798/// audiofiles, five of them in goingson (sync, sync-result, vacation-day,
799/// timer-active, past-review), `.update-banner` in Balanced Breakfast. The two
800/// webview apps also have toasts. So neither member is speculative, and no app
801/// gains a concept it lacks except audiofiles, whose renderer may legitimately
802/// decline to draw a toast at all.
803#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
804pub enum Notice {
805 /// Transient, stacked, dismisses itself.
806 Toast,
807 /// Persistent, in flow, one per region, dismissed by fixing the cause.
808 Banner,
809}
810
811impl Notice {
812 /// Whether it goes away on its own.
813 #[must_use]
814 pub const fn transient(self) -> bool {
815 matches!(self, Self::Toast)
816 }
817
818 /// How it sits.
819 ///
820 /// A toast floats above the page rather than resting on it, which is
821 /// [`Fill::Overlay`]'s whole reason to exist. A banner is a card in the
822 /// flow. Both are raised, and they are raised off different things.
823 #[must_use]
824 pub const fn fill(self) -> Fill {
825 match self {
826 Self::Toast => Fill::Overlay,
827 Self::Banner => Fill::Raised,
828 }
829 }
830}
831
832/// The parts of a list row.
833///
834/// Four to begin with, taken from Balanced Breakfast, which was the only
835/// consumer that had all of them (`row-primary`, `row-secondary`, `row-meta`,
836/// `row-actions`). audiofiles has two and no slot structure at all, so it gains
837/// meta and actions as real work rather than a rename; goingson moves off
838/// `task-row` / `task-cell`.
839///
840/// [`Tokens`](Self::Tokens) joined at 0.9.0, and `#[non_exhaustive]` with it.
841/// See the crate header for why the two arrived together.
842///
843/// # Meta against Tokens
844///
845/// The line is whether the thing has its own standing. `Meta` is one short
846/// trailing fact about the row, written as text: a count, a size, a date.
847/// `Tokens` is a set of small labelled things, each of which can be toned and
848/// can answer a click. "3 files" is meta. A status badge that is amber, and a
849/// tag you can click to filter by, are tokens.
850///
851/// Keeping them apart is what a single widened slot would have foreclosed. A
852/// renderer can right-align one string and cannot usefully do the same to a
853/// strip of chips, and a fact that is not clickable should not be drawn as
854/// though it were.
855#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
856#[non_exhaustive]
857pub enum RowPart {
858 /// The thing itself. What the row is called.
859 Primary,
860 /// Supporting text under the primary.
861 Secondary,
862 /// A short trailing fact: a count, a size, a date.
863 Meta,
864 /// Controls that act on this row.
865 Actions,
866 /// Small labelled things belonging to the row: badges, chips, tags.
867 ///
868 /// Each carries its own [`Token`] kind and [`Tone`], so a renderer with no
869 /// colour still has the kind to work with, and one with no chips still has
870 /// the label. That is the constrained-consumer test this vocabulary exists
871 /// to pass, and it is why the tone lives on the token rather than on the
872 /// part.
873 Tokens,
874 /// How much of a set the row's thing has done: a [`Meter`] in the row.
875 ///
876 /// Added 0.11.0, `da5666ae`, and it is [`Tokens`](Self::Tokens)'s problem
877 /// again with a different payload. [`Meter`] arrived at 0.10.0 and closed
878 /// two of the seven sites that asked for it; the other five sit in rows, and
879 /// a row holds no nodes by the ruling that a row part may not carry an
880 /// arbitrary node — the door through which a description becomes a
881 /// templating language. So the part carries the *description of a bar*
882 /// rather than a node, exactly as `Tokens` carries tags rather than nodes.
883 ///
884 /// Without it a row flattens the proportion into [`Meta`](Self::Meta) as
885 /// "3/7 subtasks", which keeps both numbers and loses the reading, the same
886 /// way a toned status badge read as prose before `Tokens`.
887 Proportion,
888}
889
890impl RowPart {
891 /// The content intent the part takes.
892 #[must_use]
893 pub const fn intent(self) -> &'static str {
894 match self {
895 Self::Primary => "content",
896 Self::Secondary => "content-secondary",
897 Self::Meta => "content-muted",
898 // Actions carry controls rather than text, so they inherit.
899 Self::Actions => "content",
900 // So do tokens: each one carries its own tone, and a part-level
901 // intent underneath it would fight the token that sits on it.
902 Self::Tokens => "content",
903 // And so does a proportion, for the same reason: the meter carries
904 // the tone, and it is about the ratio rather than about the row.
905 Self::Proportion => "content",
906 }
907 }
908}
909
910/// How far down the heading tree a title sits.
911///
912/// Three, and only the three that are actually headings. The bands those used
913/// to be filed with (goingson's `.page-header`, Balanced Breakfast's `.header`
914/// and `.detail-header`) are arrangement, not type, and live at
915/// [`Region::Band`]. One of them contains no text at all.
916#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
917pub enum Heading {
918 /// Names the whole screen. One per screen.
919 Page,
920 /// Names a block within the screen.
921 Section,
922 /// Names a sub-block inside an already-named section.
923 Subsection,
924}
925
926impl Heading {
927 /// Whether a rule follows the heading.
928 ///
929 /// audiofiles' `section_header` draws a separator and its
930 /// `subsection_label` deliberately does not, which is the only thing
931 /// distinguishing the two once weight and colour are deferred.
932 #[must_use]
933 pub const fn separated(self) -> bool {
934 matches!(self, Self::Section)
935 }
936}
937
938/// A control that picks between things.
939///
940/// Three, because three distinct behaviours are in play and collapsing any two
941/// loses something. A segmented control picks a value; a tab picks a pane; a
942/// toggle picks nothing and simply holds itself on or off.
943#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
944pub enum Selector {
945 /// Exactly one of N, and the options abut.
946 Segmented,
947 /// Independent on or off, on its own.
948 Toggle,
949 /// Navigation between panes. The folder semantic.
950 Tabs,
951}
952
953impl Selector {
954 /// How the chosen option sits.
955 ///
956 /// Held in for a segmented control and a toggle, which is the same shape
957 /// pressing produces and the whole economy of the idiom: one appearance,
958 /// two reasons to wear it. A tab is the exception, because the selected
959 /// folder tab comes *forward* to join the pane it opens.
960 #[must_use]
961 pub const fn chosen(self) -> Depth {
962 match self {
963 Self::Segmented | Self::Toggle => Depth::Well,
964 Self::Tabs => Depth::Raised,
965 }
966 }
967
968 /// How the options that were *not* picked sit.
969 ///
970 /// Added 0.3.0. Describing only [`Selector::chosen`] left the unchosen
971 /// option falling through to [`Depth::Flat`], which says it is level with
972 /// the strip it sits in, and no renderer emitted anything for it. That is
973 /// wrong in both directions and goingson proved it: its unchosen tabs are
974 /// recessed by hand, and being recessed is *why* the chosen one reads as
975 /// coming forward. Against a flat strip, a raised chosen tab is a bevel
976 /// drawn on the strip's own colour, which is a much weaker folder effect
977 /// than the contrast the idiom is named after.
978 ///
979 /// Each member is the inverse of its chosen state, which is the whole
980 /// content of "picked" once colour is deferred:
981 ///
982 /// - Tabs recede, so the chosen one comes forward.
983 /// - A segment and a toggle stand up, so the chosen one is held in.
984 #[must_use]
985 pub const fn unchosen(self) -> Depth {
986 match self {
987 Self::Tabs => Depth::Sunken,
988 Self::Segmented | Self::Toggle => Depth::Raised,
989 }
990 }
991
992 /// Whether the options touch.
993 ///
994 /// The gap is the entire difference between a segmented control and a row
995 /// of buttons that happen to sit near each other, which is what audiofiles'
996 /// `segmented_control` says in its own comment and why it zeroes the
997 /// spacing by hand.
998 #[must_use]
999 pub const fn abutting(self) -> bool {
1000 matches!(self, Self::Segmented | Self::Tabs)
1001 }
1002}
1003
1004/// What is in a region right now.
1005///
1006/// The state, not the shimmer. Whether pending paints a skeleton, a spinner or
1007/// nothing at all is renderer policy, the same class of decision that got
1008/// `Fill::fallback` deleted from this crate. goingson and Balanced Breakfast
1009/// each grew a skeleton with differently-named parts; both keep them, as the
1010/// webview renderer's expression of [`Readiness::Pending`]. audiofiles has none
1011/// and needs none, because an immediate-mode renderer simply repaints.
1012///
1013/// # Four states and not two, as of 0.12.0
1014///
1015/// `703f4cd2`. It named `Ready` and `Pending` and stopped, so a described screen
1016/// whose list came back empty had to render an empty region or invent its own
1017/// placeholder text, and neither says what it is. goingson draws one at 27 sites
1018/// across 12 files and Balanced Breakfast at 9, with a class family that had
1019/// already drifted into `empty-state`, `empty-state--error`, `error-state` and
1020/// six more.
1021///
1022/// The four are one axis because they are mutually exclusive: a region shows its
1023/// content, or a sign that it is coming, or a sign that there is none, or a sign
1024/// that it broke. Never two. That is the test for one enum against several
1025/// fields, and it is why this grew rather than a new member arriving beside it.
1026///
1027/// # What is not here
1028///
1029/// **The message.** "No projects yet" is content, and this names a state. It
1030/// lives with whatever holds the region — in quasi's case a `Slot` — alongside
1031/// the action that leads out of the emptiness, since an address is the one thing
1032/// this crate never names.
1033///
1034/// **How much room it gets.** goingson's `--compact`, `--dashboard` and
1035/// `--padded` are the same state at three sizes, and a size is
1036/// `makeover-geometry`'s question. Naming them here would be this crate stating
1037/// values again.
1038///
1039/// **The icon.** Presentation, and each host has its own answer or none.
1040#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1041#[non_exhaustive]
1042pub enum Readiness {
1043 /// The content is here.
1044 Ready,
1045 /// The content is on its way.
1046 Pending,
1047 /// The content arrived and there is none of it.
1048 ///
1049 /// Not a failure. An empty list is the normal state of a new install, and a
1050 /// renderer that drew it in a danger tone would be reporting a fault where
1051 /// there is none.
1052 Empty,
1053 /// The content did not arrive.
1054 Failed,
1055}
1056
1057impl Readiness {
1058 /// Whether the region draws its own content, or something standing in for
1059 /// it.
1060 ///
1061 /// The question every renderer asks first, so it is answered once here
1062 /// rather than by a `matches!` in each. A state added later is a stand-in
1063 /// until proven otherwise: falling back to drawing content that may not be
1064 /// there is the worse of the two mistakes.
1065 #[must_use]
1066 pub const fn shows_content(self) -> bool {
1067 matches!(self, Self::Ready)
1068 }
1069
1070 /// What the state means, for a renderer choosing a colour.
1071 ///
1072 /// Derived rather than carried, which is the opposite of [`Meter`] and
1073 /// [`Figure`], and the difference is worth stating: a proportion's meaning
1074 /// depends on what is being counted and only the app knows it, while
1075 /// "nothing here yet" and "this broke" mean the same thing in every app that
1076 /// will ever have them.
1077 #[must_use]
1078 pub const fn tone(self) -> Tone {
1079 match self {
1080 Self::Failed => Tone::Danger,
1081 _ => Tone::Neutral,
1082 }
1083 }
1084}
1085
1086/// How much of a set is done.
1087///
1088/// Added 0.10.0. Nine sites across the two webview apps drew a bar and nothing
1089/// here named one, so every described screen concatenated the two numbers into
1090/// its heading text instead: "Subtasks 3/7", "Time Tracking 45m tracked / 30m
1091/// est, over". Every fact survives that and the reading does not, which is the
1092/// same loss `RowPart::Tokens` closed when a toned status badge became prose.
1093///
1094/// # Why a pair and not a percentage
1095///
1096/// Both numbers, not the percentage the apps compute from them. The percentage
1097/// was the obvious shape and it had already been tried: goingson's
1098/// `Task::time_progress` divides, rounds, and then clamps to 100, which throws
1099/// away the one case the bar exists to show — 45 minutes tracked against a
1100/// 30-minute estimate. It carries a separate `is_over_estimate` boolean beside
1101/// it to recover the fact the clamp dropped. A pair keeps the over-run without a
1102/// companion flag, and [`percent`](Meter::percent) is still one call away for a
1103/// renderer that wants it.
1104///
1105/// The pair is also what the apps already have at every site. All seven
1106/// determinate bars write the ratio into the accessible layer and never the
1107/// percentage: `title="3/7 subtasks"`, `aria-label="3 of 7 subtasks completed"`,
1108/// a milestone's own `3/7` span. Given 43 nothing can recover "3 of 7", so a
1109/// percentage member would have made [`label`](Meter::label) mandatory at every
1110/// call site, which is the concatenated text this member removes, moved one
1111/// layer down.
1112///
1113/// # What this is not
1114///
1115/// The progress of an *operation*. Two of the nine sites are that — goingson's
1116/// focus timer, Balanced Breakfast's feed fetch — and they get nothing here, on
1117/// purpose. Both are imperative controllers over a live handle, driven by a tick
1118/// or an event stream, and a description is built once and dropped. Holding one
1119/// would mean growing a way to update a description between renders, which is a
1120/// different feature. [`Readiness::Pending`] and a [`Notice::Toast`] carry the
1121/// honest part.
1122///
1123/// The two cases are distinguishable in the markup rather than by taste: every
1124/// determinate bar in both apps carries a tone, and neither operation bar
1125/// carries one. Two codebases drew that line the same way without coordinating.
1126#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1127pub struct Meter<'a> {
1128 /// How much is done. May exceed [`total`](Self::total), and that is the
1129 /// case worth drawing.
1130 pub done: u32,
1131 /// How much there is to do. Zero means there is no set, not that the set is
1132 /// complete.
1133 pub total: u32,
1134 /// What the proportion means right now.
1135 ///
1136 /// Carried rather than derived, because no renderer can work it out. The
1137 /// same 90% is [`Tone::Success`] on a subtask rollup and [`Tone::Danger`] on
1138 /// a time estimate, and goingson picks between them from `is_over_estimate`,
1139 /// a fact about the data and not about the number.
1140 pub tone: Tone,
1141 /// What is being counted, if the bar says so: "subtasks", "tasks".
1142 ///
1143 /// The noun, not the ratio. A renderer builds "3 of 7 subtasks" from this
1144 /// and the two numbers; handing it the assembled string would put the
1145 /// sentence order in the description, where a terminal at one line and a
1146 /// tooltip want different ones.
1147 pub label: Option<&'a str>,
1148}
1149
1150impl<'a> Meter<'a> {
1151 /// A proportion with no tone and no label.
1152 #[must_use]
1153 pub const fn new(done: u32, total: u32) -> Self {
1154 Self {
1155 done,
1156 total,
1157 tone: Tone::Neutral,
1158 label: None,
1159 }
1160 }
1161
1162 /// What the proportion means.
1163 #[must_use]
1164 pub const fn tone(mut self, tone: Tone) -> Self {
1165 self.tone = tone;
1166 self
1167 }
1168
1169 /// What is being counted.
1170 #[must_use]
1171 pub const fn label(mut self, label: &'a str) -> Self {
1172 self.label = Some(label);
1173 self
1174 }
1175
1176 /// How full the bar is, 0 to 100, clamped.
1177 ///
1178 /// For drawing, which is the only thing a clamped number is good for. Ask
1179 /// [`overflowing`](Self::overflowing) before reporting it as a fact, or this
1180 /// is `time_progress`'s bug again with the clamp moved.
1181 ///
1182 /// An empty set reads as 0. Nothing is done, because there is nothing to do
1183 /// and no bar to fill; the apps guard on the count before drawing at all.
1184 #[must_use]
1185 pub const fn percent(&self) -> u8 {
1186 if self.total == 0 {
1187 return 0;
1188 }
1189 let scaled = (self.done as u64 * 100) / self.total as u64;
1190 if scaled > 100 { 100 } else { scaled as u8 }
1191 }
1192
1193 /// Whether more is done than there was to do.
1194 ///
1195 /// The fact [`percent`](Self::percent) destroys, kept reachable so a
1196 /// renderer can mark the over-run rather than drawing a full bar and
1197 /// implying it landed exactly.
1198 #[must_use]
1199 pub const fn overflowing(&self) -> bool {
1200 self.done > self.total
1201 }
1202
1203 /// Whether there is a set at all.
1204 ///
1205 /// A meter over nothing is sayable on purpose, for the same reason a field
1206 /// with no options is: it is what an app with an unloaded count actually
1207 /// has, and a renderer that shows an empty bar says so on screen rather than
1208 /// dividing by zero.
1209 #[must_use]
1210 pub const fn is_empty(&self) -> bool {
1211 self.total == 0
1212 }
1213}
1214
1215/// One figure with a caption: a number and what it counts.
1216///
1217/// The dashboard shape. A large value over a small caption, several of them in a
1218/// strip: a current streak, a completion rate, a total. Added 0.11.0,
1219/// `93c6a174`, after goingson turned out to have five of them across five
1220/// screens with five class vocabularies for the one shape — `task-overview-stat`,
1221/// `stat-box`, `month-stat-item`, `contact-summary-stat`, `sync-stat`. Four put
1222/// the value above the caption and one inverts it, which is drift inside the
1223/// shape rather than a second shape.
1224///
1225/// # Why the value is text
1226///
1227/// "17", "84%", "12/30", "3d". A figure is whatever the app computed, already
1228/// formatted, and the formatting is the app's because only it knows whether the
1229/// number is a percentage, a duration or a ratio. This carries none of the
1230/// arithmetic [`Meter`] carries, and that is the difference between them: a
1231/// meter is a proportion a renderer draws, and a figure is a fact a renderer
1232/// sets in type.
1233///
1234/// # Tone is carried, for [`Meter`]'s reason
1235///
1236/// Three of the five sites tone the figure by their own means — `red`/`blue` on
1237/// the weekly review, a `${type}` class on the monthly one, `sync-stat-warn` on
1238/// sync. So tone is carried at every site that needs it and derived at none, and
1239/// no renderer can work out that a streak of zero is worth colouring.
1240///
1241/// # What is not here
1242///
1243/// Whether the figure answers a click. One of the five is a control — sync's
1244/// "Not Applied: 3" opens the list — and an action is not something this crate
1245/// can name: nothing here knows what a route is. That belongs beside the figure
1246/// in whatever layer holds the actions, the same way a row's activation sits
1247/// beside its parts rather than inside them.
1248///
1249/// The arrangement is not here either. Several figures in a strip is a set, and
1250/// a renderer given them one at a time cannot tell it is looking at one; the
1251/// layer that holds the tree is where the set gets said.
1252#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1253pub struct Figure<'a> {
1254 /// The number, formatted the way the app means it to read.
1255 pub value: &'a str,
1256 /// What it counts. The caption under the value.
1257 pub caption: &'a str,
1258 /// How the value has moved, if the app is tracking that.
1259 ///
1260 /// Added 0.13.0. Text, for [`value`](Self::value)'s reason: only the app
1261 /// knows whether a move reads as `+12.5%`, `+3` or `2x`, and a renderer
1262 /// handed a number would have to guess.
1263 ///
1264 /// This is what [`tone`](Self::tone) was for and had no consumer of. The MNW
1265 /// server has four screens whose stat card is a label, a value and a delta,
1266 /// and the delta is the toned part: the figure itself is an ordinary fact
1267 /// and it is the movement that reads as good or bad. Without this the delta
1268 /// has to be folded into the caption, which loses the tone and reads as a
1269 /// longer caption rather than as a second, smaller line.
1270 pub change: Option<&'a str>,
1271 /// What the figure means right now. [`Tone::Neutral`] is an ordinary fact.
1272 ///
1273 /// Applies to [`change`](Self::change) where there is one, since that is the
1274 /// part that carries the judgement, and to the value where there is not.
1275 pub tone: Tone,
1276}
1277
1278impl<'a> Figure<'a> {
1279 /// A figure that is an ordinary fact.
1280 #[must_use]
1281 pub const fn new(value: &'a str, caption: &'a str) -> Self {
1282 Self {
1283 value,
1284 caption,
1285 change: None,
1286 tone: Tone::Neutral,
1287 }
1288 }
1289
1290 /// How the value has moved.
1291 #[must_use]
1292 pub const fn change(mut self, change: &'a str) -> Self {
1293 self.change = Some(change);
1294 self
1295 }
1296
1297 /// What the figure means.
1298 #[must_use]
1299 pub const fn tone(mut self, tone: Tone) -> Self {
1300 self.tone = tone;
1301 self
1302 }
1303}
1304
1305/// Something the user can do, and what it costs to say so.
1306///
1307/// Added 0.17.0, out of `quasi-tui`: the terminal renderer had drawn one of
1308/// these for months and every other consumer that wanted a button had written
1309/// its own, because this layer named [`RowPart::Actions`] as a *slot* and never
1310/// named the thing that goes in it. Beside [`Meter`] and [`Figure`] for the
1311/// reason those are here: a renderer that is handed the parts has to decide how
1312/// to say them, and a renderer that is handed a finished string has already had
1313/// the decision made for it.
1314///
1315/// No address. Where a control goes is the app's business and every host
1316/// follows it differently — an `hx-get`, a protocol URL, a function call — so
1317/// the description says what the control *is* and the caller keeps what it
1318/// does. That is the same split [`Choice`] makes.
1319///
1320/// No confirmation flag either, and that one is a finding rather than an
1321/// omission: a question asked *after* a control is pressed belongs to whatever
1322/// is holding the interaction, and a renderer that drew it would be asking
1323/// before there was anything to answer.
1324/// How a picture sits in the box it is given.
1325///
1326/// An intent rather than a value, so a renderer picks the expression it has:
1327/// `object-fit` in a webview, a texture's UV rect in egui, and in a terminal a
1328/// choice about how many cells the blit gets. Named because MNW already makes
1329/// the distinction deliberately at 17 sites and makes it three different ways,
1330/// which is a policy the app decided rather than one a shared crate would be
1331/// picking by accident.
1332#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
1333#[non_exhaustive]
1334pub enum Fit {
1335 /// The picture's own proportions, and the box takes the height they imply.
1336 ///
1337 /// The default because it is the only one that shows the whole picture at
1338 /// its own shape, so a renderer that ignores this enum entirely is still
1339 /// right about the common case. A screenshot wants this; the shipped MNW
1340 /// carousel sets no `object-fit` at all, which is this.
1341 #[default]
1342 Natural,
1343 /// Fill the box and crop whatever does not fit.
1344 ///
1345 /// For a picture in a slot whose shape the layout fixed: a thumbnail, an
1346 /// avatar, cover art. 15 of MNW's 17 sites.
1347 Cover,
1348 /// Fit inside the box whole, leaving space on two sides.
1349 ///
1350 /// The letterbox. For when the whole picture matters more than filling the
1351 /// space, and the space is not the picture's shape.
1352 Contain,
1353}
1354
1355/// A picture, and what it says to someone who is not looking at it.
1356///
1357/// # No source
1358///
1359/// [`Act`]'s split, for [`Act`]'s reason. A source is an address, and this
1360/// crate has no notion of an address: it says what a thing *is* and the caller
1361/// keeps what it points at. The three findings dropped from 0.11.0 were all
1362/// this same shape.
1363///
1364/// It matters more here than it does for a control, because a picture is the
1365/// one member where the address is most of what a webview needs and *none* of
1366/// what the description knows. `quasi_router::Node::Image` carries the URL, the
1367/// way it carries an `Action` for a control.
1368///
1369/// # Why [`alt`](Self::alt) is not optional
1370///
1371/// Every other host has to draw something, and for two of the three the alt
1372/// text is not a fallback but the whole rendering: a terminal without a
1373/// graphics protocol has the words and nothing else. Making it optional would
1374/// make "this picture is invisible on a terminal" the default, and the
1375/// description would be carrying a webview assumption in its shape.
1376///
1377/// An image that genuinely says nothing — a rule, a spacer, a decoration
1378/// repeating what the text beside it already said — is an empty `alt`, which is
1379/// the same thing HTML means by it and is a claim rather than an oversight.
1380#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1381pub struct Image<'a> {
1382 /// What the picture says, for anything not showing it.
1383 ///
1384 /// Empty means the picture is decorative and adds nothing to the text
1385 /// around it. See the type's own docs on why this is not an `Option`.
1386 pub alt: &'a str,
1387 /// A visible line under the picture, where the app wants one.
1388 ///
1389 /// Distinct from [`alt`](Self::alt) and the difference is who it is for: a
1390 /// caption is content everybody reads, alt text is what stands in for the
1391 /// picture. A screenshot captioned "The library view" still needs alt text
1392 /// describing what is in the shot.
1393 pub caption: Option<&'a str>,
1394 /// How it sits in the box it is given.
1395 pub fit: Fit,
1396 /// The picture's own dimensions, where the app knows them.
1397 ///
1398 /// **Not a display size**, and that distinction is what makes this belong
1399 /// here rather than fall foul of the deferral rule. Saying a picture should
1400 /// be 320 points wide is a layout value and is not the description's to
1401 /// give. Saying the file is 5120x3412 is a fact *about the picture*, the
1402 /// same kind of fact [`alt`](Self::alt) is, and no renderer can find it out
1403 /// without fetching the bytes.
1404 ///
1405 /// # What it is for, and it is not decoration
1406 ///
1407 /// Without it a renderer cannot reserve room, so the picture occupies
1408 /// nothing until it arrives and then takes its full height at once,
1409 /// shoving everything below it down the screen. Measured on MNW's landing
1410 /// page 2026-08-14: a 478px jump per frame, and a cumulative layout shift
1411 /// of 0.087 for the page, which is most of the way to the 0.1 that counts
1412 /// as bad.
1413 ///
1414 /// Every host wants it and none can derive it. A webview writes `width` and
1415 /// `height` so the browser holds the space; egui sizes a texture; a
1416 /// terminal with a graphics protocol scales a blit into cells. This was
1417 /// missing from 0.21.0, which is the release that added [`Image`], and its
1418 /// absence is the defect rather than an omission.
1419 ///
1420 /// `None` is honest and common: a creator-uploaded image whose dimensions
1421 /// the app never recorded genuinely does not know. It means the renderer
1422 /// cannot reserve, not that the picture has no size.
1423 pub intrinsic: Option<Extent>,
1424 /// Whether the picture is needed with the screen, or can arrive later.
1425 pub loading: Loading,
1426}
1427
1428/// A picture's own pixel dimensions.
1429///
1430/// Deliberately not [`makeover_geometry`]'s business. Geometry answers *how
1431/// much space a thing should get*, which is a scale question with the same
1432/// answer on every screen. This is the intrinsic size of one asset, which is a
1433/// fact about that asset and varies per picture.
1434///
1435/// [`makeover_geometry`]: https://docs.rs/makeover-geometry
1436#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1437pub struct Extent {
1438 /// Width in the picture's own pixels.
1439 pub width: u32,
1440 /// Height in the picture's own pixels.
1441 pub height: u32,
1442}
1443
1444impl Extent {
1445 /// A picture's dimensions.
1446 #[must_use]
1447 pub const fn new(width: u32, height: u32) -> Self {
1448 Self { width, height }
1449 }
1450
1451 /// Width over height, or `None` if either side is zero.
1452 ///
1453 /// The form a renderer actually reserves space with: a box that knows its
1454 /// proportion holds the right height at any width, which is what a
1455 /// responsive picture needs and what a fixed pixel height cannot give.
1456 #[must_use]
1457 pub fn ratio(self) -> Option<f32> {
1458 (self.width > 0 && self.height > 0).then(|| self.width as f32 / self.height as f32)
1459 }
1460}
1461
1462/// When a picture is needed.
1463///
1464/// A claim about *importance and position* rather than a fetch mechanism, which
1465/// is why it is the description's to make: only the app knows whether a picture
1466/// is the first thing on the screen or the fortieth thing down a list.
1467///
1468/// # Eager is the default, and that is a correctness choice
1469///
1470/// 0.21.0 emitted the webview's `loading="lazy"` for every picture, on the
1471/// evidence that the one consumer measured wrote it. That was reading a habit
1472/// as a rule. Deferring a picture that is on screen at first paint does not
1473/// save anything -- it is needed immediately either way -- and it delays the
1474/// arrival, so the space it eventually takes is claimed later and the shift is
1475/// more visible, not less.
1476///
1477/// So the safe answer is the default and the optimisation is opted into. A
1478/// carousel is the case that proves the two cannot be one setting for the
1479/// renderer to choose: its first frame is on screen and its other frames are
1480/// not, in the same widget, at the same moment.
1481#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
1482#[non_exhaustive]
1483pub enum Loading {
1484 /// Needed with the screen. Fetch it now.
1485 #[default]
1486 Eager,
1487 /// Not on screen yet. It can wait until it is near.
1488 Lazy,
1489}
1490
1491impl<'a> Image<'a> {
1492 /// A picture that carries its own proportions.
1493 #[must_use]
1494 pub const fn new(alt: &'a str) -> Self {
1495 Self {
1496 alt,
1497 caption: None,
1498 fit: Fit::Natural,
1499 intrinsic: None,
1500 loading: Loading::Eager,
1501 }
1502 }
1503
1504 /// The picture's own dimensions, so a renderer can hold its place.
1505 #[must_use]
1506 pub const fn intrinsic(mut self, width: u32, height: u32) -> Self {
1507 self.intrinsic = Some(Extent::new(width, height));
1508 self
1509 }
1510
1511 /// This picture is not on screen yet; it can arrive when it is near.
1512 #[must_use]
1513 pub const fn lazy(mut self) -> Self {
1514 self.loading = Loading::Lazy;
1515 self
1516 }
1517
1518 /// A visible line under it.
1519 #[must_use]
1520 pub const fn caption(mut self, caption: &'a str) -> Self {
1521 self.caption = Some(caption);
1522 self
1523 }
1524
1525 /// How it sits in its box.
1526 #[must_use]
1527 pub const fn fit(mut self, fit: Fit) -> Self {
1528 self.fit = fit;
1529 self
1530 }
1531
1532 /// Whether the picture adds anything for someone not looking at it.
1533 ///
1534 /// A renderer with no way to show a picture uses this to decide between
1535 /// drawing the alt text and drawing nothing at all. Both are correct and
1536 /// the difference is this flag: standing in for a decorative rule with the
1537 /// word "decoration" is worse than leaving the space empty.
1538 #[must_use]
1539 pub const fn speaks(self) -> bool {
1540 !self.alt.is_empty()
1541 }
1542}
1543
1544/// A window of time, in minutes from the start of a day.
1545///
1546/// The axis a [`Track`] draws. Minutes rather than instants, and offsets rather
1547/// than wall-clock, because a description that carried a `DateTime` would carry
1548/// a timezone with it and the vocabulary has no business holding one. The app
1549/// knows which day this is; the description says how far along it a thing sits.
1550///
1551/// `to` is exclusive and may exceed `1440`, which is how a span that runs past
1552/// midnight is said without a second date: `Span::new(1320, 1560)` is 22:00 to
1553/// 02:00.
1554#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1555pub struct Span {
1556 from: u16,
1557 to: u16,
1558}
1559
1560impl Span {
1561 /// Midnight to midnight, the ordinary day.
1562 pub const DAY: Self = Self { from: 0, to: 1440 };
1563
1564 /// A span, clamped to a sane one.
1565 ///
1566 /// An empty or backwards span is a caller bug that should not cost a
1567 /// renderer a division by zero, so `to` is forced at least one minute past
1568 /// `from` rather than returning an error nobody can act on. Same reasoning
1569 /// as [`Share::percent`], which clamps rather than refuses.
1570 #[must_use]
1571 pub const fn new(from: u16, to: u16) -> Self {
1572 Self {
1573 from,
1574 to: if to > from { to } else { from + 1 },
1575 }
1576 }
1577
1578 /// The first minute on the axis.
1579 #[must_use]
1580 pub const fn from(self) -> u16 {
1581 self.from
1582 }
1583
1584 /// One past the last minute on the axis.
1585 #[must_use]
1586 pub const fn to(self) -> u16 {
1587 self.to
1588 }
1589
1590 /// How many minutes the axis covers. Never zero.
1591 #[must_use]
1592 pub const fn minutes(self) -> u16 {
1593 self.to - self.from
1594 }
1595
1596 /// Whether a minute falls on this axis.
1597 #[must_use]
1598 pub const fn holds(self, minute: u16) -> bool {
1599 minute >= self.from && minute < self.to
1600 }
1601}
1602
1603impl Default for Span {
1604 fn default() -> Self {
1605 Self::DAY
1606 }
1607}
1608
1609/// Where a thing sits on a [`Track`], and for how long.
1610///
1611/// The one fact a list cannot carry and the whole reason this primitive exists.
1612/// A list says what order things come in; a track says a thing starts 135
1613/// minutes along and lasts 45, which is a different claim and not derivable
1614/// from the first.
1615#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1616pub struct Placement {
1617 at: u16,
1618 minutes: u16,
1619}
1620
1621impl Placement {
1622 /// A placement, clamped to a drawable one.
1623 ///
1624 /// Zero minutes becomes one for the same reason [`Span::new`] clamps: a
1625 /// zero-height thing is invisible rather than expressive, and every
1626 /// renderer would need its own guard.
1627 #[must_use]
1628 pub const fn new(at: u16, minutes: u16) -> Self {
1629 Self {
1630 at,
1631 minutes: if minutes == 0 { 1 } else { minutes },
1632 }
1633 }
1634
1635 /// Minutes from the start of the day, matching [`Span`]'s origin.
1636 #[must_use]
1637 pub const fn at(self) -> u16 {
1638 self.at
1639 }
1640
1641 /// How long it lasts. Never zero.
1642 #[must_use]
1643 pub const fn minutes(self) -> u16 {
1644 self.minutes
1645 }
1646
1647 /// One past its last minute.
1648 #[must_use]
1649 pub const fn end(self) -> u16 {
1650 self.at + self.minutes
1651 }
1652
1653 /// Whether two placements cover any of the same time.
1654 ///
1655 /// Geometry, and deliberately not a described field. Whether an overlap is
1656 /// a *conflict* is the app's judgment -- a meeting inside a block of free
1657 /// time overlaps and is fine -- and that judgment travels the way every
1658 /// other judgment does, as a [`Tone`] on the thing itself. What a renderer
1659 /// needs in order to lay two things side by side instead of on top of each
1660 /// other is this, and it can compute it.
1661 ///
1662 /// The alternative was a `conflicts: bool` on each entry, which is state
1663 /// that can disagree with the times beside it. Two sources for one fact is
1664 /// how a screen starts rendering a conflict badge on a thing that no longer
1665 /// conflicts.
1666 #[must_use]
1667 pub const fn overlaps(self, other: Self) -> bool {
1668 self.at < other.end() && other.at < self.end()
1669 }
1670}
1671
1672/// A time axis: things placed by when they happen, rather than flowed.
1673///
1674/// # Why this is a primitive
1675///
1676/// This crate refused to name it until 2026-08-15, on the argument that a
1677/// description expressive enough to draw a timeline is a component library
1678/// wearing a description's name. The refusal is withdrawn, and it is worth
1679/// being precise about what was wrong with it, because the reasoning it used
1680/// applies to real cases and should not be discarded with it.
1681///
1682/// What a timeline needs that a [`List`](Region::Pane) does not is **one**
1683/// thing: placement. Where a thing sits is a fact about the thing, the way a
1684/// row's primary text is, and it is not derivable from order. Everything else a
1685/// day view draws -- the labels, the gridlines, the item bodies, the tones --
1686/// is furniture this vocabulary already names. Measured against goingson's
1687/// `day-planning-render.js`, the only members it needed and could not get were
1688/// `at` and `minutes`.
1689///
1690/// So the timeline was never a component library's worth of vocabulary. It was
1691/// two integers, and the refusal was priced as though it were the whole widget.
1692/// The test that matters is not "does this shape look complicated" but "how
1693/// many members does it actually add, and are they facts or presentation".
1694/// Slot heights, gridline colour, how overlaps stack and which hour scrolls
1695/// into view on open are all presentation and all stay the renderer's, which is
1696/// why they are absent here.
1697///
1698/// # What it does not carry
1699///
1700/// No pixel measure, no scroll offset, no drag affordance. A renderer draws the
1701/// span at whatever density its host uses; `makeover-geometry` owns that the
1702/// way it owns everything else measured in pixels.
1703#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1704pub struct Track {
1705 /// The window the axis covers.
1706 pub span: Span,
1707 /// The granularity a thing can be placed on, in minutes.
1708 ///
1709 /// goingson's day view is 15, giving 96 slots across a day. A renderer uses
1710 /// it to decide where gridlines fall and what a drop lands on; it does not
1711 /// constrain [`Placement`], because data arriving from a calendar does not
1712 /// respect anyone's grid.
1713 pub slot: u16,
1714 /// How often the axis labels itself, in minutes.
1715 ///
1716 /// 60 gives an hourly ruler over a 15-minute grid, which is the common
1717 /// shape and the reason this is separate from `slot`. Zero means an
1718 /// unlabelled axis.
1719 pub tick: u16,
1720}
1721
1722impl Track {
1723 /// An ordinary day: midnight to midnight, quarter-hour slots, hourly ticks.
1724 pub const DAY: Self = Self {
1725 span: Span::DAY,
1726 slot: 15,
1727 tick: 60,
1728 };
1729
1730 /// A track over `span`, with the day's usual granularity.
1731 #[must_use]
1732 pub const fn over(span: Span) -> Self {
1733 Self {
1734 span,
1735 slot: 15,
1736 tick: 60,
1737 }
1738 }
1739
1740 /// How many slots the axis holds.
1741 ///
1742 /// Rounded up, so a span that does not divide evenly by `slot` still has a
1743 /// slot covering its tail rather than dropping it. Never zero: `slot` of 0
1744 /// reads as one slot spanning the whole axis rather than a division by
1745 /// zero, since a renderer asking this question has already committed to
1746 /// drawing something.
1747 #[must_use]
1748 pub const fn slots(self) -> u16 {
1749 if self.slot == 0 {
1750 1
1751 } else {
1752 self.span.minutes().div_ceil(self.slot)
1753 }
1754 }
1755
1756 /// Where a placement sits on the axis, as a fraction from 0.0 to 1.0.
1757 ///
1758 /// The one calculation every renderer would otherwise write itself, and the
1759 /// place the three would drift apart. Clamped, so a placement outside the
1760 /// span draws at the edge rather than off it -- an event running past
1761 /// midnight is a real thing and truncating it is better than either
1762 /// panicking or drawing it somewhere impossible.
1763 #[must_use]
1764 pub fn fraction(self, minute: u16) -> f32 {
1765 let span = f32::from(self.span.minutes());
1766 let offset = f32::from(minute.saturating_sub(self.span.from()));
1767 (offset / span).clamp(0.0, 1.0)
1768 }
1769}
1770
1771impl Default for Track {
1772 fn default() -> Self {
1773 Self::DAY
1774 }
1775}
1776
1777#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1778pub struct Act<'a> {
1779 /// What the control says.
1780 pub label: &'a str,
1781 /// The key that reaches it where a host has keys.
1782 ///
1783 /// The one member written for a terminal before there was one. A webview
1784 /// hangs it off `accesskey` or ignores it; a terminal has nothing else to
1785 /// offer, so this is the whole of how a control is reached there.
1786 pub key: Option<&'a str>,
1787 /// What pressing it means. [`Tone::Danger`] is the destructive one.
1788 pub tone: Tone,
1789 /// Disabled, or nothing said.
1790 ///
1791 /// [`State::Disabled`] is what changes what a renderer may do: see
1792 /// [`State::suppresses_interaction`], which is what says a disabled control
1793 /// is drawn and not reachable. It has been the only member since 0.19.0,
1794 /// and a control's focus is not sayable here at all — see the crate header,
1795 /// "Reach, focus and the focus ring".
1796 pub state: Option<State>,
1797}
1798
1799impl<'a> Act<'a> {
1800 /// An ordinary control, reachable, with no key.
1801 #[must_use]
1802 pub const fn new(label: &'a str) -> Self {
1803 Self {
1804 label,
1805 key: None,
1806 tone: Tone::Neutral,
1807 state: None,
1808 }
1809 }
1810
1811 /// The key that reaches it.
1812 #[must_use]
1813 pub const fn key(mut self, key: &'a str) -> Self {
1814 self.key = Some(key);
1815 self
1816 }
1817
1818 /// What pressing it means.
1819 #[must_use]
1820 pub const fn tone(mut self, tone: Tone) -> Self {
1821 self.tone = tone;
1822 self
1823 }
1824
1825 /// Focus, or disabled.
1826 #[must_use]
1827 pub const fn state(mut self, state: State) -> Self {
1828 self.state = Some(state);
1829 self
1830 }
1831
1832 /// Whether the control is drawn and does not answer.
1833 #[must_use]
1834 pub fn disabled(&self) -> bool {
1835 self.state.is_some_and(State::suppresses_interaction)
1836 }
1837}
1838
1839/// A named part of a screen.
1840///
1841/// The thing `makeover-geometry` deliberately does not name: it names the space
1842/// *between* things by relationship, and nothing named the things. Six named
1843/// members, taken from what the two webview apps actually use, plus
1844/// [`Region::Bespoke`] for the parts no description should reach. Both apps'
1845/// `layout.css` currently names exactly two things, `.raised` and `.well`, so
1846/// this layer is absent rather than divergent, which makes it the cheapest of
1847/// the schemas to add and the easiest to over-build.
1848///
1849/// `#[non_exhaustive]` arrives with [`Region::Widget`], the pairing [`RowPart`]
1850/// made at 0.9.0 and [`Readiness`] at 0.12.0, and for the same reason: the
1851/// member after this one should not be a lockstep event across three renderers.
1852#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1853#[non_exhaustive]
1854pub enum Region<'a> {
1855 /// A full-width strip with a title slot and an actions cluster, either of
1856 /// which may be empty. goingson's `.page-header`, Balanced Breakfast's
1857 /// `.header` and `.detail-header` are all this, differing only in which
1858 /// slots they fill.
1859 Band,
1860 /// A persistent column beside the content, holding navigation.
1861 Sidebar,
1862 /// A region of content with its own scroll.
1863 Pane,
1864 /// Two panes side by side, where the left chooses what the right shows.
1865 Split,
1866 /// Peer regions across, all of them equals.
1867 ///
1868 /// A kanban board's columns, and the shape [`Split`](Self::Split) is not:
1869 /// a split's two panes stand in a master-detail relationship, where the
1870 /// left chooses what the right shows. These choose nothing about each
1871 /// other. Each is a whole region and the set is the arrangement.
1872 ///
1873 /// # What it does not carry
1874 ///
1875 /// **How many.** The children say, and a count here would be a second
1876 /// source for something the description already states by containing them.
1877 ///
1878 /// **How wide.** Peers are equal by definition, so there is no [`Share`] to
1879 /// state. A board whose columns wanted different widths would be a
1880 /// different member, and no app has one.
1881 ///
1882 /// **What happens when there is no room.** Scroll across, wrap, or collapse
1883 /// to one column at a time: all three are right on some host, none is
1884 /// derivable from the description, and every one of them is presentation.
1885 /// A terminal that stacks them vertically is honouring this, not degrading
1886 /// it.
1887 ///
1888 /// # Why it is not an `Arrangement`
1889 ///
1890 /// [`Arrangement`] is the page's shape, and a board is usually a region
1891 /// *inside* a page that also has a band over it. Naming it here composes;
1892 /// naming it there would make a screen either a board or a list-detail and
1893 /// never a band above a board. It also keeps [`Arrangement::share`]
1894 /// meaningful, which a peer arrangement has no answer for.
1895 Columns,
1896 /// A set of panes, one visible at a time, with a [`Selector::Tabs`] above.
1897 TabGroup,
1898 /// Content over a scrim, taking input until dismissed.
1899 Modal,
1900 /// A region this crate names the *place* of and nothing else. The app owns
1901 /// what goes in it.
1902 ///
1903 /// The escape hatch, and the thing that keeps the description honest about
1904 /// its own limits. A day-plan timeline, a kanban board, a calendar and the
1905 /// paint interaction over the timeline are not describable here and are not
1906 /// going to become describable: a description expressive enough to produce
1907 /// a timeline is a widget library wearing a description's name.
1908 ///
1909 /// But a screen containing one still has to be a screen. Without this
1910 /// member the description covers only the boring screens, and the four that
1911 /// make goingson worth using would need a second, undescribed path beside
1912 /// the router. Two paths is how the vocabulary starts drifting from the app
1913 /// again, which is the exact failure this crate exists to end.
1914 ///
1915 /// So the description says "a thing called `day-plan` goes here" and stops.
1916 /// The name is opaque: this crate never interprets it, and no renderer is
1917 /// expected to know what it means beyond handing the space over.
1918 Bespoke {
1919 /// What the app calls it. Never interpreted here.
1920 name: &'a str,
1921 },
1922 /// A named assembly of things the vocabulary already says.
1923 ///
1924 /// The third tier, between a primitive and [`Bespoke`](Self::Bespoke).
1925 /// Stated by Max 2026-08-12 answering the carousel: "something in between a
1926 /// primitive and a bespoke interface, like a widget, which is just an
1927 /// assembly of primitives." Full note: wiki `widget-tier`.
1928 ///
1929 /// # What separates it from the two members either side
1930 ///
1931 /// A primitive is a thing every renderer draws from scratch, and the test
1932 /// it has to pass is that every host has an honest answer. A carousel fails
1933 /// that test — a terminal has no carousel — which is the same refusal
1934 /// `Node::Html` got and is why the carousel sat unsayable for months.
1935 ///
1936 /// [`Bespoke`](Self::Bespoke) fails it from the other side. Bespoke is for
1937 /// what one app owns and nobody will build twice, and it carries *no*
1938 /// contents: the description names the place and stops. A carousel is
1939 /// furniture any app would have, and every part of it — an ordered set of
1940 /// frames, a position, prev and next, a strip of position indicators — is
1941 /// already sayable. Only the assembly had no name.
1942 ///
1943 /// So this member is the pair the other two are not: a name **and**
1944 /// contents. The contents are the assembly, in the region's own body, said
1945 /// in members that already exist.
1946 ///
1947 /// # Why the name does not have to be understood
1948 ///
1949 /// A renderer that recognises the name draws it the way its host does it: a
1950 /// carousel in a webview, a pager with a count in a terminal, a selector in
1951 /// egui. A renderer that does not recognise it walks the body, which is
1952 /// primitives all the way down and which it can already draw.
1953 ///
1954 /// That is what lets the widget set be **open** without every renderer
1955 /// knowing every widget. An unrecognised widget degrades to its assembly
1956 /// instead of failing, so a second or third party can name one without
1957 /// three renderers releasing in lockstep to accept it. Contrast
1958 /// [`Bespoke`](Self::Bespoke), which no renderer can degrade: there is
1959 /// nothing under it to fall back to.
1960 ///
1961 /// # What it does not do
1962 ///
1963 /// A widget is an assembly of things the vocabulary *already* says, so it
1964 /// buys no expressive power. Anything needing a member the vocabulary does
1965 /// not have is a finding about the vocabulary, and the answer to a finding
1966 /// is to add the member. A widget is never the way a primitive gets added
1967 /// by the back door.
1968 ///
1969 /// This used to say "it does not make a timeline describable, and the
1970 /// refusal in the crate header stands unchanged". The timeline is
1971 /// describable as of 2026-08-15 -- see [`Track`] -- and it got there the
1972 /// way the paragraph above says it should have: by adding the two members
1973 /// that were missing, not by dressing the screen up as an assembly.
1974 Widget {
1975 /// What the assembly is called. This crate never interprets it, and a
1976 /// renderer is free not to know it.
1977 name: &'a str,
1978 },
1979}
1980
1981impl<'a> Region<'a> {
1982 /// How the region sits on what is behind it.
1983 #[must_use]
1984 pub const fn depth(self) -> Depth {
1985 match self {
1986 Self::Band | Self::Sidebar | Self::Split | Self::TabGroup => Depth::Flat,
1987 // Flat, and it is the container rather than the columns. Each
1988 // column is its own region and brings its own depth; a well here
1989 // would put a second edge around a row of wells.
1990 Self::Columns => Depth::Flat,
1991 // A pane is looked into, the same as a table body or a tag tree.
1992 Self::Pane => Depth::Well,
1993 Self::Modal => Depth::Raised,
1994 // Flat because it inherits: a bespoke region takes the depth of
1995 // whatever frames it. An app that wants its timeline in a well puts
1996 // it in a `Pane`, which composes rather than adding a knob here.
1997 //
1998 // A widget inherits for the same reason and it matters more here,
1999 // because a widget is drawn by whichever renderer recognises it. A
2000 // depth set here would be this crate deciding that a carousel is
2001 // raised on every host, which is the kind of value the deferral
2002 // rule exists to refuse.
2003 Self::Bespoke { .. } | Self::Widget { .. } => Depth::Flat,
2004 }
2005 }
2006
2007 /// Whether this crate can say anything about the region's contents.
2008 ///
2009 /// A renderer walks the description and hands every region it understands
2010 /// to the right drawing code. This is how it tells the two apart, and the
2011 /// reason it is a method rather than a `matches!` at each renderer: there
2012 /// is exactly one opaque member and there should stay exactly one.
2013 ///
2014 /// [`Widget`](Self::Widget) is described, and that is the whole of what
2015 /// separates it from [`Bespoke`](Self::Bespoke) here. Both carry a name
2016 /// this crate never interprets; only one of them carries contents under it.
2017 /// A renderer that does not recognise a widget's name still walks its body,
2018 /// so there is nothing for it to hand over and nothing it cannot draw.
2019 #[must_use]
2020 pub const fn described(self) -> bool {
2021 !matches!(self, Self::Bespoke { .. })
2022 }
2023
2024 /// The name an app gave this region, if it gave one.
2025 ///
2026 /// [`Bespoke`](Self::Bespoke) and [`Widget`](Self::Widget) are the two
2027 /// members that carry a name, for two different purposes: one says what the
2028 /// app will fill the space with, the other says what the assembly under it
2029 /// is called. A renderer dispatching on either wants the string without
2030 /// caring which member it came from, and writing that `matches!` at each
2031 /// renderer is how the two drift apart.
2032 #[must_use]
2033 pub const fn name(self) -> Option<&'a str> {
2034 match self {
2035 Self::Bespoke { name } | Self::Widget { name } => Some(name),
2036 // Spelled out rather than a wildcard, so a member added later has
2037 // to answer whether it carries a name instead of inheriting `None`
2038 // by sitting under a `_`.
2039 Self::Band
2040 | Self::Sidebar
2041 | Self::Pane
2042 | Self::Split
2043 | Self::Columns
2044 | Self::TabGroup
2045 | Self::Modal => None,
2046 }
2047 }
2048}
2049
2050/// How many of a region's children are visible at once.
2051///
2052/// `4dcd241b`. Three findings turned out to be one sentence the vocabulary
2053/// could not say: *this region holds several children and shows some of them,
2054/// and the reader can change which.* [`Region::TabGroup`] existed with nothing
2055/// saying which tab was open, a carousel had nothing saying which frame was up,
2056/// and a disclosure had nothing saying whether its one child was showing at all.
2057///
2058/// Because the fact lived nowhere, a renderer had two moves: hardcode a widget
2059/// name, or draw every child. That is what put per-widget code in renderers, and
2060/// it was the missing member rather than the widget tier that put it there.
2061///
2062/// # What is here and what is not
2063///
2064/// The *kind*, and only the kind. Which child is currently up is the current
2065/// answer, and a layer that defers every address does not hold the current
2066/// answer either — the split [`Selector`] already makes, where this crate says
2067/// what kind of chooser a thing is and the router says which option is picked.
2068/// So a holder of regions carries the index and the per-child label beside this.
2069///
2070/// # What a renderer does with it
2071///
2072/// Derives its chrome, once, for every widget rather than per name:
2073///
2074/// - Children carrying labels get a strip of the labels, the current one marked.
2075/// - Children carrying none get previous, position, next.
2076/// - [`AtMostOne`](Self::AtMostOne) over one child gets a summary line that
2077/// opens.
2078///
2079/// The name on [`Region::Widget`] survives as app vocabulary, for a renderer
2080/// that wants to do something *special* with one, which is what it should have
2081/// been from the start.
2082///
2083/// Degradation runs the way it already did: a renderer ignoring this draws every
2084/// child, which is more content rather than less.
2085#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
2086#[non_exhaustive]
2087pub enum Showing {
2088 /// Every child, in order. What every region did before this existed.
2089 #[default]
2090 All,
2091 /// Exactly one. A carousel, a tab group.
2092 One,
2093 /// One, or none. A disclosure, which is closed until it is opened.
2094 AtMostOne,
2095}
2096
2097impl Showing {
2098 /// Whether the reader can change which child is up.
2099 ///
2100 /// The question every renderer's region arm asks before deriving any
2101 /// chrome, and a method rather than a `matches!` at each renderer for
2102 /// [`Region::name`]'s reason: three renderers writing the same comparison is
2103 /// how they come to disagree about a member added later.
2104 #[must_use]
2105 pub const fn selective(self) -> bool {
2106 !matches!(self, Self::All)
2107 }
2108
2109 /// Whether showing nothing is a legal state.
2110 ///
2111 /// True only for [`AtMostOne`](Self::AtMostOne). A renderer needs this to
2112 /// know whether its control closes as well as moves: a carousel's row moves
2113 /// between frames and never reaches empty, and a disclosure's summary line
2114 /// is the same control wearing its closed state.
2115 #[must_use]
2116 pub const fn dismissible(self) -> bool {
2117 matches!(self, Self::AtMostOne)
2118 }
2119}
2120
2121/// How much of the width an arrangement's first region takes.
2122///
2123/// `e0fd485e`. Nothing said how much room a region got, so every renderer
2124/// invented its own number and two hosts showing one screen disagreed about
2125/// its proportions. A webview never noticed, because the stylesheet answered
2126/// once for every consumer; a terminal has no stylesheet to inherit from, so
2127/// `quasi-tui` picked 24 columns for a sidebar and 40% for a list pane and
2128/// neither had anything behind it.
2129///
2130/// # A proportion, never a unit
2131///
2132/// Held as a percentage, and that is the only form it comes in. A description
2133/// carrying columns would be describing a terminal and one carrying pixels a
2134/// webview, and the whole point is that both honour the same fact: a terminal
2135/// resolves it against a column count, a webview writes it into a grid, and
2136/// neither has to know what the other did.
2137///
2138/// It is not [`makeover_geometry::Ratio`]'s job either, which was the first
2139/// guess. Geometry is scales that answer the same for every screen and takes
2140/// no input that would let a sidebar screen differ from a list-detail one.
2141///
2142/// [`makeover_geometry::Ratio`]: https://docs.rs/makeover-geometry
2143#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
2144pub struct Share(u8);
2145
2146impl Share {
2147 /// What a sidebar takes, when nobody says otherwise.
2148 ///
2149 /// A quarter. `quasi-tui` drew 24 columns, which is a quarter of a
2150 /// 96-column terminal and about a fifth of a wide one; a quarter is that
2151 /// number said in the form a webview can honour too.
2152 pub const SIDEBAR: Self = Self(25);
2153
2154 /// What the list side of a list-detail takes, when nobody says otherwise.
2155 ///
2156 /// `quasi-tui`'s 40%, which was already a proportion and is the one number
2157 /// this member did not have to invent.
2158 pub const LIST: Self = Self(40);
2159
2160 /// A share of the width, as a percentage.
2161 ///
2162 /// Clamped to 5..=95 rather than refused. A description that asked for a
2163 /// region of nothing is a bug in the app, and a renderer drawing a region
2164 /// zero cells wide reports it as a region that vanished, which is the
2165 /// hardest kind of bug to find from what is on the screen.
2166 #[must_use]
2167 pub const fn percent(percent: u8) -> Self {
2168 Self(if percent < 5 {
2169 5
2170 } else if percent > 95 {
2171 95
2172 } else {
2173 percent
2174 })
2175 }
2176
2177 /// The share as a percentage.
2178 #[must_use]
2179 pub const fn as_percent(self) -> u8 {
2180 self.0
2181 }
2182
2183 /// This share of a width, rounded to the nearest whole unit.
2184 ///
2185 /// What a terminal calls to turn the proportion into columns. At least one,
2186 /// because a region the description named should be visible: a screen
2187 /// 3 columns wide is unusable either way, and a sidebar that is there is a
2188 /// truer picture of the description than a sidebar that is not.
2189 #[must_use]
2190 pub const fn of(self, whole: u16) -> u16 {
2191 let taken = (whole as u32 * self.0 as u32).div_ceil(100);
2192 if taken == 0 { 1 } else { taken as u16 }
2193 }
2194}
2195
2196/// How a screen is laid out.
2197///
2198/// Two, and the second is not a variant of the first. goingson is list-detail,
2199/// Balanced Breakfast is sidebar plus content, and neither app has a third.
2200/// The tab group is a modifier rather than a member, because goingson uses it
2201/// *inside* the same content region rather than instead of one.
2202///
2203/// This exists at all because the router has to be able to express a screen
2204/// rather than only a control. Discovering the arrangement layer missing after
2205/// the renderers exist is a redesign; naming two now is a morning.
2206///
2207/// # Why the share rides here
2208///
2209/// `e0fd485e`. A share is per-arrangement: how much a sidebar takes and how
2210/// much a list side takes are different questions, and this enum is the only
2211/// thing that knows which one is being asked. Geometry would have had to invent
2212/// a channel to be told.
2213///
2214/// [`list_detail`](Self::list_detail) and
2215/// [`sidebar_content`](Self::sidebar_content) build these with the default
2216/// shares, so a screen that has no opinion does not have to have one.
2217#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
2218pub enum Arrangement {
2219 /// A list that chooses what the detail beside it shows.
2220 ListDetail {
2221 /// Whether the detail side is a [`Region::TabGroup`].
2222 tabbed: bool,
2223 /// How much of the width the list side takes.
2224 share: Share,
2225 },
2226 /// Navigation down the side, content filling the rest.
2227 SidebarContent {
2228 /// How much of the width the sidebar takes.
2229 share: Share,
2230 },
2231}
2232
2233impl Arrangement {
2234 /// A list and a detail beside it, at the default share.
2235 #[must_use]
2236 pub const fn list_detail(tabbed: bool) -> Self {
2237 Self::ListDetail {
2238 tabbed,
2239 share: Share::LIST,
2240 }
2241 }
2242
2243 /// A sidebar and content beside it, at the default share.
2244 #[must_use]
2245 pub const fn sidebar_content() -> Self {
2246 Self::SidebarContent {
2247 share: Share::SIDEBAR,
2248 }
2249 }
2250
2251 /// How much of the width the first region takes.
2252 #[must_use]
2253 pub const fn share(self) -> Share {
2254 match self {
2255 Self::ListDetail { share, .. } | Self::SidebarContent { share } => share,
2256 }
2257 }
2258
2259 /// The same arrangement, at this share.
2260 #[must_use]
2261 pub const fn with_share(self, share: Share) -> Self {
2262 match self {
2263 Self::ListDetail { tabbed, .. } => Self::ListDetail { tabbed, share },
2264 Self::SidebarContent { .. } => Self::SidebarContent { share },
2265 }
2266 }
2267}
2268
2269/// How wide the content of a whole screen runs.
2270///
2271/// `0eccff0d`, and [`Share`]'s sibling one level up: that one says how a
2272/// screen's width is divided between regions, this says how much of the window
2273/// the screen uses in the first place. Both are the description's, which is
2274/// what answering the two together settled.
2275///
2276/// Measured in the MNW server, where 69 of 72 templates carry exactly one of
2277/// three mutually exclusive classes and the choice is per screen. GoingsOn
2278/// reaches for `max-width` 56 times and Balanced Breakfast 12, neither with a
2279/// token for it, so three apps were solving one thing by hand.
2280///
2281/// # Named for the measure, not for MNW's classes
2282///
2283/// A renderer that is not a browser has to answer this too, and `padded-page`
2284/// tells a terminal nothing. The three say how wide the text runs, which is a
2285/// question every renderer can answer: a webview with a `max-width`, a terminal
2286/// with gutters, an immediate-mode frame with its own width.
2287///
2288/// `#[non_exhaustive]` for [`Fill`]'s reason. The set is closed today because
2289/// the measurement found three, and a fourth arriving should not be a lockstep
2290/// release across nine repos.
2291#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
2292#[non_exhaustive]
2293pub enum Measure {
2294 /// The whole width, with gutters. The default, and 53 of the 69.
2295 ///
2296 /// What a dashboard, a table and a settings screen want: the content is
2297 /// wide because the content *is* wide, and constraining it would waste the
2298 /// window.
2299 #[default]
2300 Wide,
2301 /// Capped at a comfortable page width, centred. 13 of the 69.
2302 ///
2303 /// A form, a sign-in, a purchase. Content that does not get better by
2304 /// getting wider, but is not prose either.
2305 Contained,
2306 /// Capped at a line length that reads well. 3 of the 69.
2307 ///
2308 /// Prose. The narrowest of the three, and the one with a reason outside
2309 /// taste: a line of text past roughly 75 characters costs the reader the
2310 /// return sweep.
2311 Reading,
2312}
2313
2314impl Measure {
2315 /// A stable name, for a renderer that needs to spell it.
2316 ///
2317 /// Here rather than in each renderer for [`Sort::as_str`]'s reason: three
2318 /// renderers spelling one enum is three chances to spell it differently.
2319 #[must_use]
2320 pub const fn as_str(self) -> &'static str {
2321 match self {
2322 Self::Wide => "wide",
2323 Self::Contained => "contained",
2324 Self::Reading => "reading",
2325 }
2326 }
2327}
2328
2329/// What kind of value a form field takes.
2330///
2331/// The union of the two vocabularies that diverged, which is what triggered
2332/// this crate. They have since converged on their own: both apps now have a
2333/// `renderFormField` emitting the same anatomy, and what is left differing is
2334/// the kind set, the error shape, and whether the return is a string or a node.
2335///
2336/// Validation is deliberately absent. Neither app has a shared story (goingson
2337/// validates after collecting the form data, with per-field transform hooks;
2338/// Balanced Breakfast has `required` and nothing else), and a schema that
2339/// describes fields but not constraints acquires a constraint layer per app,
2340/// which is exactly how the current divergence started. Naming it absent is a
2341/// decision; leaving it unmentioned would not be.
2342/// `#[non_exhaustive]` for the reason [`Fill`] is: renderers match on this and
2343/// the set keeps growing, so growth must not be a lockstep event. Email, Url
2344/// and Tel arriving in 0.5.0 is the second growth in two releases.
2345#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
2346#[non_exhaustive]
2347pub enum FieldKind {
2348 /// A single line of text.
2349 Text,
2350 /// A single line of text that must never be echoed, logged or round-tripped
2351 /// through anything that might persist it.
2352 Secret,
2353 /// A number.
2354 Number,
2355 /// An email address.
2356 ///
2357 /// Distinct from [`Text`](Self::Text) because the distinction is not
2358 /// decoration: a webview renderer emits `type="email"`, which on a touch
2359 /// device changes the keyboard that appears and turns on the platform's own
2360 /// validation. goingson ships to iOS, so collapsing this into text costs a
2361 /// keyboard with no `@` on it.
2362 ///
2363 /// Added 0.5.0, from goingson's contact form.
2364 Email,
2365 /// A URL. Same reasoning as [`Email`](Self::Email).
2366 ///
2367 /// Added 0.5.0, from goingson's contact-social and contact-feed forms.
2368 Url,
2369 /// A telephone number. Same reasoning as [`Email`](Self::Email), and the
2370 /// clearest case of it: the keyboard is a numeric pad rather than letters.
2371 ///
2372 /// Added 0.5.0, from goingson's contact-phone form.
2373 Tel,
2374 /// A calendar day, with no time of day in it.
2375 ///
2376 /// [`Email`](Self::Email)'s argument, and it carries further: a webview
2377 /// emits `type="date"`, which is a native picker, the platform's own
2378 /// validation, and on a touch device the date keyboard. Described as
2379 /// [`Text`](Self::Text) with a hint reading "YYYY-MM-DD", all three are
2380 /// lost and the hint is doing the platform's job in prose.
2381 ///
2382 /// The membership test passes on every host without stretching: a webview
2383 /// and a Tauri app emit the input, egui has a date picker, a terminal
2384 /// prompts for a day and can validate it, a CLI takes an argument.
2385 ///
2386 /// # The value is ISO 8601, `YYYY-MM-DD`
2387 ///
2388 /// Named here rather than left to each host, because a host that picks
2389 /// differently sends a server something it parses differently, and the
2390 /// failure is silent and per-host. It is `<input type="date">`'s own wire
2391 /// format, so the webview renderer owes nothing to honour it and the other
2392 /// hosts have one spelling to meet. [`DATE_FORMAT`] is the constant, and a
2393 /// test asserts this doc and that constant agree.
2394 ///
2395 /// Added 0.15.0, from the MNW server's git access-token expiry
2396 /// (`user_ssh_keys_tab.html`) and six further sites across the server and
2397 /// goingson.
2398 Date,
2399 /// A calendar day and a time of day together.
2400 ///
2401 /// Apart from [`Date`](Self::Date) because the question is different rather
2402 /// than more precise: "which day does this expire" and "at what moment does
2403 /// this publish" are asked by different screens and answered by different
2404 /// controls. A webview emits `type="datetime-local"` for one and
2405 /// `type="date"` for the other, and a host that collapsed them would ask
2406 /// half the tree for a precision it does not want.
2407 ///
2408 /// Both arrived together on measurement rather than on symmetry: 13 sites
2409 /// of each across the MNW server and goingson, and **zero** of `time`,
2410 /// `month` or `week`, which is why those are not here. A member added for a
2411 /// case nobody has is a member designed against nothing, which is
2412 /// [`File`](Self::File)'s reasoning about `accept` applied to a whole
2413 /// member.
2414 ///
2415 /// # The value is `YYYY-MM-DDTHH:MM`, local, with no zone
2416 ///
2417 /// `<input type="datetime-local">`'s own format, and the "local" is the
2418 /// load-bearing half: the value carries no offset and no `Z`, so the moment
2419 /// it names is only fixed once something supplies a zone. That is the app's
2420 /// business and not the description's. Seconds are absent, which is the
2421 /// browser's own default and is left as the rule rather than restated as a
2422 /// constraint. [`DATETIME_FORMAT`] is the constant.
2423 ///
2424 /// [`Field::min`] and [`Field::max`] already take "the host's own spelling
2425 /// of a bound", so a floor of *not in the past* needs nothing new here: it
2426 /// is a string in this same format.
2427 ///
2428 /// Added 0.15.0, from goingson's snooze picker and day planner and the MNW
2429 /// server's publish-at fields.
2430 DateTime,
2431 /// Several lines of text.
2432 Textarea,
2433 /// One of a fixed set, offered behind a control that shows one at a time.
2434 Select,
2435 /// One of a fixed set, with every option on screen at once.
2436 ///
2437 /// Not a presentation of [`Select`](Self::Select), which is the reading to
2438 /// resist: what differs is a property of the *question*. A choice that is
2439 /// consequential or irreversible has to be readable without opening
2440 /// anything, because a closed control shows one option and hides the rest,
2441 /// and the one it shows is whichever was current before the user had read
2442 /// the alternatives. audiofiles asks whether a library copies samples into
2443 /// its store or references them where they lie — which cannot be changed
2444 /// afterwards — and had already promoted that out of a checkbox by hand,
2445 /// with a comment giving this reason, before the description could say it.
2446 ///
2447 /// It was described here at 0.8.1 as "the one HTML input type this enum was
2448 /// missing", which was not true then and is not true now: `file` arrived at
2449 /// 0.11.0 and `date` and `datetime-local` at 0.15.0. Everything here is
2450 /// still an `<input type=...>`, a `<select>` or a `<textarea>`, and the way
2451 /// this enum grows is by a site being measured rather than by a list being
2452 /// completed, so "the last one" is not a claim it should make again.
2453 ///
2454 /// Added 0.8.1, from audiofiles' Add Library form.
2455 Radio,
2456 /// On or off.
2457 Checkbox,
2458 /// A file the user picks from wherever the host keeps files.
2459 ///
2460 /// Added 0.11.0, `844b5ae0`, from goingson's project-dashboard attachments
2461 /// column. It was filed as a router finding — a control whose destination is
2462 /// a host capability rather than an address — and splitting it is what made
2463 /// it two answers instead of one member satisfying neither. *Opening* a file
2464 /// is a one-way handoff and needs no new API. *Picking* one returns a value
2465 /// into a write, which is a form concern, which is this.
2466 ///
2467 /// The membership test passes on every host and not by a stretch: a Tauri
2468 /// app opens a native picker, a server renders `<input type="file">`, a
2469 /// terminal prompts for a path, a CLI takes an argument. That is closer to
2470 /// [`Email`](Self::Email), which exists because it changes the keyboard,
2471 /// than to anything bespoke.
2472 ///
2473 /// It carries no accepted-types list and no multiple flag, and that is
2474 /// measured rather than deferred: `accept` appears at zero sites in either
2475 /// app. A member added for a case nobody has is a member designed against
2476 /// nothing.
2477 File,
2478 /// Carried through the form and never shown.
2479 Hidden,
2480}
2481
2482/// The wire format a [`FieldKind::Date`] value takes: ISO 8601, `YYYY-MM-DD`.
2483///
2484/// A constant rather than a sentence in a doc comment, because the reason to
2485/// name the format at all is that a host picking its own would fail silently
2486/// against a server parsing another. A host that cannot emit the native control
2487/// still has one spelling to meet, and can say which one it meant.
2488pub const DATE_FORMAT: &str = "%Y-%m-%d";
2489
2490/// The wire format a [`FieldKind::DateTime`] value takes: `YYYY-MM-DDTHH:MM`,
2491/// local, carrying no zone and no seconds.
2492///
2493/// [`DATE_FORMAT`]'s sibling and there for its reason. The absent zone is a
2494/// property of the value rather than an omission: the moment is not fixed until
2495/// something outside the description supplies one.
2496pub const DATETIME_FORMAT: &str = "%Y-%m-%dT%H:%M";
2497
2498impl FieldKind {
2499 /// Whether the value the kind takes is a moment rather than a string.
2500 ///
2501 /// Named once here for the reason [`offers_options`](Self::offers_options)
2502 /// is: two kinds answer yes, and a host that has to parse or format a value
2503 /// needs to ask without spelling the pair out at each renderer. A third
2504 /// temporal kind should land here and nowhere else.
2505 ///
2506 /// The format each one takes is [`DATE_FORMAT`] and [`DATETIME_FORMAT`].
2507 #[must_use]
2508 pub const fn temporal(self) -> bool {
2509 matches!(self, Self::Date | Self::DateTime)
2510 }
2511
2512 /// Whether the field is drawn at all.
2513 #[must_use]
2514 pub const fn visible(self) -> bool {
2515 !matches!(self, Self::Hidden)
2516 }
2517
2518 /// Whether the value must be kept out of logs and diagnostics.
2519 #[must_use]
2520 pub const fn confidential(self) -> bool {
2521 matches!(self, Self::Secret)
2522 }
2523
2524 /// Where the field's own label sits.
2525 ///
2526 /// A checkbox labels itself on the right of the box; everything else takes
2527 /// a label above. Both webview apps already do this and both special-case
2528 /// it inline, which is the tell that it belongs in the description.
2529 ///
2530 /// A [`Radio`](Self::Radio) is not one of them, and the near-miss is worth
2531 /// naming: its *options* each label themselves, but the field still asks a
2532 /// question above them, so the group takes a label like everything else.
2533 #[must_use]
2534 pub const fn labels_itself(self) -> bool {
2535 matches!(self, Self::Checkbox)
2536 }
2537
2538 /// Whether the kind reads [`Field::options`].
2539 ///
2540 /// Two kinds do, so the pair is named once here rather than spelled out at
2541 /// each renderer and again in [`Field::options`]' own doc, where "every
2542 /// kind but `Select`" was true for exactly one release. A third
2543 /// option-taking kind should land here and nowhere else.
2544 #[must_use]
2545 pub const fn offers_options(self) -> bool {
2546 matches!(self, Self::Select | Self::Radio)
2547 }
2548}
2549
2550/// One option offered by a field [`FieldKind::offers_options`] accepts.
2551///
2552/// Two strings, because the submitted value and the read label are different
2553/// facts and every renderer that has tried to collapse them has had to
2554/// un-collapse them later. `makeover-webview` invented this shape writing its
2555/// form emitter and it is taken here unchanged; moving it down rather than
2556/// re-deriving it is the point, since the second and third renderers were each
2557/// going to arrive at a near-miss of it.
2558#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
2559pub struct Choice<'a> {
2560 /// What is submitted.
2561 pub value: &'a str,
2562 /// What is read.
2563 pub label: &'a str,
2564}
2565
2566impl<'a> Choice<'a> {
2567 /// An option whose submitted value is also its label.
2568 #[must_use]
2569 pub const fn plain(value: &'a str) -> Self {
2570 Self {
2571 value,
2572 label: value,
2573 }
2574 }
2575}
2576
2577/// One field of a form.
2578///
2579/// Borrowed rather than owned: a description is built, read once by a renderer,
2580/// and dropped. Nothing here outlives the screen it describes.
2581///
2582/// # What it carries, and what it does not
2583///
2584/// Stated here so the next renderer does not re-ask, which is what the first
2585/// two both did. It carries everything a renderer needs to *draw* the field:
2586/// its kind, what it is called, what it is asked for, its standing help, what
2587/// is wrong with it now, whether it is compulsory, whether it hides behind a
2588/// disclosure, its ghost text, and the options it offers.
2589///
2590/// It does not carry the **current value**, and it is not going to. That is the
2591/// one thing here that is genuinely renderer state: a webview reads it back out
2592/// of the DOM, an immediate-mode renderer holds a `&mut` to the app's own field
2593/// and writes through it, and a terminal keeps an edit buffer. A description
2594/// that carried the value would have to carry a way to write it back, at which
2595/// point it is a form model and no longer a description.
2596///
2597/// **Constraints** are here and enforcement is not, which is one line rather
2598/// than two. [`required`], [`max_length`], [`min`] and [`max`] are facts about
2599/// the *question*, so a renderer can emit its host's idiom for each — an HTML
2600/// attribute, a marked label, a clamped spinner — and the platform helps the
2601/// user before anything is submitted. Deciding that a value is wrong stays with
2602/// whoever validated, and [`error`] is that decision arriving back.
2603///
2604/// The set stops before `pattern`, and stops there on both tests at once. A
2605/// regex has an honest answer in a webview and none anywhere else: egui would
2606/// have to run it per keystroke and decide what a half-typed value means, which
2607/// is enforcement wearing description's clothes. And it is one site in goingson
2608/// and none in Balanced Breakfast, against 8 and 1 for `maxlength`. Measured
2609/// 2026-08-09, `2cbad3e2`.
2610///
2611/// [`error`]: Field::error
2612/// [`required`]: Field::required
2613/// [`max_length`]: Field::max_length
2614/// [`min`]: Field::min
2615/// [`max`]: Field::max
2616#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
2617pub struct Field<'a> {
2618 /// What kind of value it takes.
2619 pub kind: FieldKind,
2620 /// The name the value is submitted under.
2621 pub name: &'a str,
2622 /// What the user is asked for.
2623 pub label: &'a str,
2624 /// Standing help, shown whether or not anything is wrong.
2625 pub hint: Option<&'a str>,
2626 /// What is currently wrong with the value.
2627 pub error: Option<&'a str>,
2628 /// Ghost text shown while the field is empty.
2629 ///
2630 /// User-facing text, and it sits with `label` and `hint` rather than with
2631 /// the value because it is a property of the *question* and not of the
2632 /// answer. It lived renderer-side in `makeover-webview` until 0.8.0 for one
2633 /// reason and it was not a reading on where it belonged: adding a field to
2634 /// a published struct is a breaking change.
2635 ///
2636 /// Not a substitute for a label. A field labelled only by its placeholder
2637 /// loses its label the moment anything is typed, and no renderer here can
2638 /// make that not happen, so the description keeps both.
2639 pub placeholder: Option<&'a str>,
2640 /// The options offered, in the order they are offered.
2641 ///
2642 /// Empty for every kind [`FieldKind::offers_options`] rejects. A field
2643 /// described with no options is sayable on purpose: it is what an app with
2644 /// an unfinished-loading option list actually has, and a renderer showing
2645 /// an empty control says so on screen rather than in a log.
2646 ///
2647 /// Which option is *current* is not here. That is the value, and the value
2648 /// is renderer state.
2649 pub options: &'a [Choice<'a>],
2650 /// Whether the form refuses to submit without it.
2651 pub required: bool,
2652 /// The longest the value may be, in characters.
2653 ///
2654 /// Added 0.11.0 with [`min`](Self::min) and [`max`](Self::max), joining
2655 /// [`required`](Self::required), which had been the only constraint here
2656 /// since before the crate wrote down that it carried none.
2657 pub max_length: Option<u32>,
2658 /// The lowest value accepted, as the host would write it.
2659 ///
2660 /// Text rather than a number, because the bound is only a number for some
2661 /// of the kinds that take one. goingson's own sites are `min="1"` on a
2662 /// duration and `min="2026-08-09T14:30"` on a datetime, and a numeric member
2663 /// could say the first and not the second. The [`kind`](Self::kind) already
2664 /// says how to read it, the same way it does for the value.
2665 pub min: Option<&'a str>,
2666 /// The highest value accepted, as the host would write it. See
2667 /// [`min`](Self::min).
2668 pub max: Option<&'a str>,
2669 /// Whether the field lives behind a "more options" disclosure.
2670 pub extended: bool,
2671}
2672
2673impl<'a> Field<'a> {
2674 /// A plain required-nothing field of the given kind.
2675 #[must_use]
2676 pub const fn new(kind: FieldKind, name: &'a str, label: &'a str) -> Self {
2677 Self {
2678 kind,
2679 name,
2680 label,
2681 hint: None,
2682 error: None,
2683 placeholder: None,
2684 options: &[],
2685 required: false,
2686 max_length: None,
2687 min: None,
2688 max: None,
2689 extended: false,
2690 }
2691 }
2692
2693 /// A select offering the given options.
2694 ///
2695 /// One of the two kinds under-described by [`Field::new`], so it gets a
2696 /// constructor rather than leaving every call site to remember that a
2697 /// select with an empty `options` renders as an empty select.
2698 #[must_use]
2699 pub const fn select(name: &'a str, label: &'a str, options: &'a [Choice<'a>]) -> Self {
2700 Self::offering(FieldKind::Select, name, label, options)
2701 }
2702
2703 /// A radio group offering the given options.
2704 ///
2705 /// The other. Same hazard as [`select`](Self::select) and a worse one: a
2706 /// radio group with no options draws nothing at all, so a call site that
2707 /// forgot them has an empty rectangle rather than a visibly empty control.
2708 #[must_use]
2709 pub const fn radio(name: &'a str, label: &'a str, options: &'a [Choice<'a>]) -> Self {
2710 Self::offering(FieldKind::Radio, name, label, options)
2711 }
2712
2713 /// The shared body of the two constructors that take options.
2714 ///
2715 /// Private, and keyed on the kind rather than exposed, because the two
2716 /// public names are the point: a call site says which question it is
2717 /// asking, not which flag it is setting.
2718 const fn offering(
2719 kind: FieldKind,
2720 name: &'a str,
2721 label: &'a str,
2722 options: &'a [Choice<'a>],
2723 ) -> Self {
2724 Self {
2725 options,
2726 ..Self::new(kind, name, label)
2727 }
2728 }
2729
2730 /// Whether the field is currently reporting a problem.
2731 ///
2732 /// Read this rather than testing `error.is_some()` at each renderer: the
2733 /// error state has to mark the field's whole group and not only the
2734 /// message, because a renderer with no descendant selectors (egui, a
2735 /// terminal) cannot find the group from the message. goingson already marks
2736 /// the group and Balanced Breakfast does not, so goingson's shape is the
2737 /// one taken here.
2738 #[must_use]
2739 pub const fn invalid(&self) -> bool {
2740 self.error.is_some()
2741 }
2742}
2743
2744/// How much room a column asks for.
2745///
2746/// An intent, so the actual floor stays with `makeover-geometry`. goingson's
2747/// task table spells these as `minmax(200px, 1fr)`, `140px` and content-sized;
2748/// only the first three words of that survive deferral.
2749/// `#[non_exhaustive]`, for the reason [`Fill`] and [`FieldKind`] are: a
2750/// renderer matches on this and a vocabulary that grows must not break every
2751/// renderer when it does.
2752#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
2753#[non_exhaustive]
2754pub enum Width {
2755 /// Takes what it needs and no more.
2756 Content,
2757 /// A fixed share, the same at every width.
2758 Fixed,
2759 /// Absorbs whatever is left over.
2760 Fill,
2761}
2762
2763/// What a column is worth when there is not room for all of them.
2764///
2765/// Ordered: [`Priority::Optional`] drops first, [`Priority::Essential`] never
2766/// drops. This replaces addressing columns by position, which is what both
2767/// webview apps do today and is a live bug rather than only verbosity. goingson
2768/// hides mobile columns with `nth-child(n+5)` against a seven-column table, so
2769/// inserting a column silently hides the wrong one.
2770/// `#[non_exhaustive]`, same reasoning as [`Width`]. Note the ordering is the
2771/// whole point of the type, so a new tier has to be declared in its place in
2772/// the sequence rather than appended.
2773#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
2774#[non_exhaustive]
2775pub enum Priority {
2776 /// Dropped first.
2777 Optional,
2778 /// Dropped once the optional columns are gone.
2779 Secondary,
2780 /// Never dropped. Without it the row does not identify itself.
2781 Essential,
2782}
2783
2784/// One column of a table.
2785///
2786/// Described once. The grid track, the cell order and the drop behaviour are
2787/// all derived from this, rather than being three hand-written encodings that
2788/// must agree and are never checked against each other.
2789#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
2790pub struct Column<'a> {
2791 /// The heading, and the name the cell is addressed by.
2792 pub name: &'a str,
2793 /// How much room it asks for.
2794 pub width: Width,
2795 /// What it is worth when room runs out.
2796 pub priority: Priority,
2797 /// Whether the user can reorder the table by this column.
2798 ///
2799 /// `ce620871`. What reordering *calls* is not here — that is an address, and
2800 /// this crate names none — so a host pairs this with the route the way it
2801 /// pairs a row's parts with the row's activation. This says the affordance
2802 /// exists, which is what a renderer needs to draw a header a user can press
2803 /// rather than a heading they cannot.
2804 pub sortable: bool,
2805 /// Which way the table is ordered by this column, if it is.
2806 ///
2807 /// `None` on every column but the one in force. A renderer draws the caret
2808 /// from this and a webview sets `aria-sort`, which is why it is per column
2809 /// rather than a single fact on the table: the host idiom is a property of
2810 /// the header cell.
2811 ///
2812 /// Independent of [`sortable`](Self::sortable) rather than implied by it,
2813 /// because both combinations mean something. A column sorted and not
2814 /// sortable is a list ordered by a key the user cannot change, which is a
2815 /// real thing to describe and a caret worth drawing.
2816 pub sorted: Option<Sort>,
2817}
2818
2819/// Which way a column is ordered.
2820///
2821/// Two, because there is no third. "Unsorted" is [`Column::sorted`] being
2822/// `None`, and folding it in here would be the same absence said twice.
2823#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
2824pub enum Sort {
2825 /// Smallest, earliest or first alphabetically at the top.
2826 Ascending,
2827 /// The other way.
2828 Descending,
2829}
2830
2831impl Sort {
2832 /// The other direction, for a header that flips when pressed.
2833 #[must_use]
2834 pub const fn reversed(self) -> Self {
2835 match self {
2836 Self::Ascending => Self::Descending,
2837 Self::Descending => Self::Ascending,
2838 }
2839 }
2840
2841 /// What a webview writes into `aria-sort`.
2842 ///
2843 /// Named here rather than in the webview renderer because a terminal and an
2844 /// immediate-mode painter both want the same two words for a caret's label,
2845 /// and three renderers picking their own is the drift this crate ends.
2846 #[must_use]
2847 pub const fn as_str(self) -> &'static str {
2848 match self {
2849 Self::Ascending => "ascending",
2850 Self::Descending => "descending",
2851 }
2852 }
2853}
2854
2855impl<'a> Column<'a> {
2856 /// A column that absorbs slack and drops after the optional ones.
2857 #[must_use]
2858 pub const fn new(name: &'a str) -> Self {
2859 Self {
2860 name,
2861 width: Width::Fill,
2862 priority: Priority::Secondary,
2863 sortable: false,
2864 sorted: None,
2865 }
2866 }
2867
2868 /// Whether this column survives at the given cutoff.
2869 ///
2870 /// A renderer narrows by raising the cutoff, and never by counting
2871 /// positions.
2872 #[must_use]
2873 pub const fn kept_at(&self, cutoff: Priority) -> bool {
2874 (self.priority as u8) >= (cutoff as u8)
2875 }
2876}
2877
2878/// What a table cell holds.
2879///
2880/// [`RowPart`] for tables, and it exists for the same reason: a part that
2881/// carries a control is not text, and a renderer with one class for the whole
2882/// cell paints it as though it were. `makeover-webview` emitted a single
2883/// `.cell` until 0.25.0, so a button in a cell inherited the cell's content
2884/// colour, which is the exact drift [`RowPart::intent`] prevents for rows and
2885/// prevented for nothing here.
2886///
2887/// Four members, and the count is what quasi's `Cell` was measured to carry:
2888/// a value, tokens (33 cells across 22 server templates), actions (30 rows
2889/// carrying a control, 5 beside a value) and a link (35 cells across 18
2890/// templates). Nothing was added past what something holds.
2891///
2892/// `#[non_exhaustive]` for [`RowPart`]'s reason: growth here must not be a
2893/// lockstep event across three renderers.
2894///
2895/// # No hover-reveal
2896///
2897/// [`RowPart`] carried a `revealed_on_hover` until 0.13.0 retired it, and this
2898/// enum never gets one. A cell's actions are shown at rest in every consumer
2899/// measured, and a member nothing uses is one three renderers owe an answer
2900/// for.
2901#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
2902#[non_exhaustive]
2903pub enum CellPart {
2904 /// The cell's own text.
2905 Value,
2906 /// Small labelled things in the cell: a status badge, a chip.
2907 Tokens,
2908 /// Controls that act on what the row is about.
2909 Actions,
2910 /// The cell's value, where the value is itself a link.
2911 Link,
2912}
2913
2914impl CellPart {
2915 /// The content intent the part takes.
2916 ///
2917 /// One part is text and three are not, so three answer with the intent
2918 /// inheriting already gives. That is [`RowPart::intent`]'s shape with the
2919 /// text side narrower: a cell's secondary and muted readings are the
2920 /// column's business, not the cell's.
2921 #[must_use]
2922 pub const fn intent(self) -> &'static str {
2923 match self {
2924 Self::Value => "content",
2925 // A token carries its own tone, and a part-level intent underneath
2926 // it would fight the token sitting on it.
2927 Self::Tokens => "content",
2928 // Actions carry controls rather than text.
2929 Self::Actions => "content",
2930 // A link takes the action colour from the control it is, rather
2931 // than the cell's text colour from the cell it sits in.
2932 Self::Link => "content",
2933 }
2934 }
2935}
2936
2937#[cfg(test)]
2938mod tests {
2939 use super::*;
2940
2941 #[test]
2942 fn the_four_readiness_states_are_one_axis_and_only_one_shows_content() {
2943 // Mutually exclusive is the test for one enum against several fields: a
2944 // region shows its content, or that it is coming, or that there is none,
2945 // or that it broke. Never two.
2946 assert!(Readiness::Ready.shows_content());
2947 for state in [Readiness::Pending, Readiness::Empty, Readiness::Failed] {
2948 assert!(!state.shows_content());
2949 }
2950 }
2951
2952 #[test]
2953 fn a_region_shows_all_of_its_children_unless_it_says_otherwise() {
2954 // The default is the behaviour every region had before this member
2955 // existed, which is what keeps it additive: a description written
2956 // against 0.22.0 says the same thing under 0.23.0.
2957 assert_eq!(Showing::default(), Showing::All);
2958 assert!(!Showing::All.selective());
2959 }
2960
2961 #[test]
2962 fn only_a_disclosure_can_show_nothing() {
2963 // The two derived idioms differ in one respect and this is it. A
2964 // carousel's row moves between frames and never reaches empty; a
2965 // disclosure's summary line is the same control wearing its closed
2966 // state, so a renderer has to know which it is drawing.
2967 assert!(Showing::AtMostOne.dismissible());
2968 assert!(!Showing::One.dismissible());
2969 assert!(!Showing::All.dismissible());
2970
2971 // Both are selective, though. Deriving chrome is one question and
2972 // whether that chrome closes is another.
2973 assert!(Showing::One.selective());
2974 assert!(Showing::AtMostOne.selective());
2975 }
2976
2977 #[test]
2978 fn an_empty_region_is_not_a_broken_one() {
2979 // An empty list is the normal state of a new install. Drawing it in a
2980 // danger tone reports a fault where there is none, and this is the one
2981 // place the distinction is carried.
2982 assert_eq!(Readiness::Empty.tone(), Tone::Neutral);
2983 assert_eq!(Readiness::Failed.tone(), Tone::Danger);
2984 assert_eq!(Readiness::Pending.tone(), Tone::Neutral);
2985 }
2986
2987 #[test]
2988 fn a_column_can_be_sorted_without_being_sortable() {
2989 // Both combinations mean something, which is why the two fields are
2990 // independent rather than one implying the other. A list ordered by a
2991 // key the user cannot change is a real thing with a caret worth drawing.
2992 let fixed = Column {
2993 sorted: Some(Sort::Descending),
2994 ..Column::new("Created")
2995 };
2996
2997 assert!(!fixed.sortable);
2998 assert_eq!(fixed.sorted.map(Sort::as_str), Some("descending"));
2999
3000 let offered = Column {
3001 sortable: true,
3002 ..Column::new("Name")
3003 };
3004 assert_eq!(offered.sorted, None);
3005 }
3006
3007 #[test]
3008 fn a_direction_flips_and_says_what_it_is() {
3009 assert_eq!(Sort::Ascending.reversed(), Sort::Descending);
3010 assert_eq!(Sort::Descending.reversed().reversed(), Sort::Descending);
3011 assert_eq!(Sort::Ascending.as_str(), "ascending");
3012 }
3013
3014 #[test]
3015 fn a_figure_carries_its_tone_because_no_renderer_can_derive_it() {
3016 // Three of goingson's five sites tone the figure by their own means, so
3017 // tone is carried at every site that needs it and derived at none. The
3018 // same reasoning `Meter` reached, from a different direction.
3019 let streak = Figure::new("0", "Current Streak").tone(Tone::Warning);
3020 assert_eq!(streak.tone, Tone::Warning);
3021 assert_eq!(Figure::new("17", "Total").tone, Tone::Neutral);
3022 }
3023
3024 #[test]
3025 fn a_figures_change_is_the_toned_part_and_is_absent_by_default() {
3026 // 0.13.0. The MNW server's stat card is a label, a value and a delta,
3027 // across four screens, and the delta is what reads as good or bad. Tone
3028 // had no consumer before this: the figure itself is an ordinary fact.
3029 let views = Figure::new("1,204", "Views")
3030 .change("+12.5%")
3031 .tone(Tone::Success);
3032 assert_eq!(views.change, Some("+12.5%"));
3033 assert_eq!(views.tone, Tone::Success);
3034
3035 // A figure with nothing to compare against says so by having no change,
3036 // rather than by carrying an empty string a renderer has to test for.
3037 assert_eq!(Figure::new("3.1%", "Conversion").change, None);
3038 }
3039
3040 #[test]
3041 fn a_figures_value_is_text_because_only_the_app_knows_what_it_is() {
3042 // "84%", "12/30", "3d". A figure is whatever the app computed, already
3043 // formatted, and that is the line between this and `Meter`: a meter is
3044 // a proportion a renderer draws, a figure is a fact it sets in type.
3045 for value in ["84%", "12/30", "3d"] {
3046 assert_eq!(Figure::new(value, "Rate").value, value);
3047 }
3048 }
3049
3050 #[test]
3051 fn a_proportion_is_a_row_part_and_takes_no_intent_of_its_own() {
3052 // The meter carries the tone, so a part-level intent underneath would
3053 // fight it. Same answer `Tokens` needed, for the same reason.
3054 assert_eq!(RowPart::Proportion.intent(), RowPart::Tokens.intent());
3055 }
3056
3057 #[test]
3058 fn a_file_field_is_drawn_and_offers_no_options() {
3059 // It is a control the user operates, unlike `Hidden`, and it does not
3060 // pick from a list the description carries, unlike `Select`.
3061 assert!(FieldKind::File.visible());
3062 assert!(!FieldKind::File.offers_options());
3063 assert!(!FieldKind::File.confidential());
3064 }
3065
3066 #[test]
3067 fn a_constraint_is_a_fact_about_the_question_and_not_a_verdict() {
3068 // The whole model: the description carries the rule, the renderer emits
3069 // its host's idiom, and `error` is what arrives back when someone
3070 // validated. Nothing here decides a value is wrong.
3071 let field = Field {
3072 max_length: Some(100),
3073 min: Some("1"),
3074 max: Some("240"),
3075 required: true,
3076 ..Field::new(FieldKind::Number, "minutes", "Minutes")
3077 };
3078 assert!(!field.invalid());
3079
3080 // A bound is text because it is only a number for some of the kinds
3081 // that take one. goingson has both shapes live.
3082 let when = Field {
3083 min: Some("2026-08-09T14:30"),
3084 ..Field::new(FieldKind::Text, "starts", "Starts")
3085 };
3086 assert_eq!(when.min, Some("2026-08-09T14:30"));
3087 }
3088
3089 #[test]
3090 fn a_meter_keeps_the_over_run_the_percentage_throws_away() {
3091 // The whole reason this is a pair. goingson's `Task::time_progress`
3092 // clamps to 100 and then carries `is_over_estimate` beside it to say
3093 // what the clamp dropped; a meter says both from one fact.
3094 let over = Meter::new(45, 30);
3095 assert_eq!(over.percent(), 100);
3096 assert!(over.overflowing());
3097
3098 let exact = Meter::new(30, 30);
3099 assert_eq!(exact.percent(), over.percent());
3100 assert!(!exact.overflowing());
3101 }
3102
3103 #[test]
3104 fn an_empty_set_does_not_divide_by_zero() {
3105 // Sayable on purpose, so it has to be answerable. A meter over an
3106 // unloaded count is what an app actually has for a frame.
3107 let none = Meter::new(0, 0);
3108 assert_eq!(none.percent(), 0);
3109 assert!(none.is_empty());
3110 assert!(!none.overflowing());
3111 }
3112
3113 #[test]
3114 fn the_ratio_survives_where_a_percentage_would_not() {
3115 // Given 43 nothing can recover "3 of 7", which is why the numbers are
3116 // carried and the label names only the noun.
3117 let m = Meter::new(3, 7).label("subtasks");
3118 assert_eq!(m.percent(), 42);
3119 assert_eq!((m.done, m.total), (3, 7));
3120 assert_eq!(m.label, Some("subtasks"));
3121 }
3122
3123 #[test]
3124 fn tone_is_carried_because_no_renderer_can_derive_it() {
3125 // The same fullness means opposite things on two of goingson's bars,
3126 // and only the app knows which.
3127 let subtasks = Meter::new(9, 10).tone(Tone::Success);
3128 let estimate = Meter::new(9, 10).tone(Tone::Danger);
3129 assert_eq!(subtasks.percent(), estimate.percent());
3130 assert_ne!(subtasks.tone, estimate.tone);
3131 // Untoned by default: a bar says nothing about status until something
3132 // says so, the same way a row is not selectable until told.
3133 assert_eq!(Meter::new(9, 10).tone, Tone::Neutral);
3134 }
3135
3136 #[test]
3137 fn an_act_is_reachable_until_it_is_disabled() {
3138 // The one member a renderer must branch on, and since 0.19.0 the only
3139 // member there is. A stated state is not by itself a reason to stop
3140 // answering, which is the distinction `State` makes and every
3141 // hand-rolled button in the tree had to remember.
3142 assert!(!Act::new("Save").disabled());
3143 assert!(Act::new("Save").state(State::Disabled).disabled());
3144 }
3145
3146 #[test]
3147 fn an_act_carries_its_key_because_a_terminal_has_nothing_else() {
3148 // No key is the ordinary case, and the webview hosts that ignore it
3149 // are why it stayed optional.
3150 assert_eq!(Act::new("Delete").key, None);
3151 let quit = Act::new("Quit").key("q").tone(Tone::Danger);
3152 assert_eq!(quit.key, Some("q"));
3153 assert_eq!(quit.tone, Tone::Danger);
3154 }
3155
3156 #[test]
3157 fn a_meter_does_not_overflow_on_large_counts() {
3158 // done * 100 in u32 would wrap somewhere past 42 million. Counts that
3159 // size are not tasks, but a description layer that silently reports 3%
3160 // for a full bar is worse than one that is slow.
3161 let big = Meter::new(u32::MAX, u32::MAX);
3162 assert_eq!(big.percent(), 100);
3163 assert!(!big.overflowing());
3164 }
3165
3166 #[test]
3167 fn inset_is_raised_with_the_light_moved() {
3168 let (rl, rd) = Bevel::Raised.edges();
3169 let (il, id) = Bevel::Inset.edges();
3170 assert_eq!((rl, rd), (Edge::Light, Edge::Dark));
3171 assert_eq!((il, id), (rd, rl));
3172 }
3173
3174 #[test]
3175 fn pressing_twice_is_a_no_op() {
3176 for b in [Bevel::Raised, Bevel::Inset] {
3177 assert_eq!(b.pressed().pressed(), b);
3178 }
3179 }
3180
3181 #[test]
3182 fn a_raised_region_is_never_filled_with_a_recessed_surface() {
3183 // The bug this vocabulary exists to make unrepresentable.
3184 assert_eq!(Depth::Raised.fill(), Some(Fill::Raised));
3185 assert_eq!(Depth::Raised.bevel(), Some(Bevel::Raised));
3186 assert_eq!(Depth::Well.bevel(), Some(Bevel::Inset));
3187 assert_ne!(Depth::Well.fill(), Depth::Raised.fill());
3188 }
3189
3190 #[test]
3191 fn state_is_orthogonal_to_depth() {
3192 // The reason State is its own axis and not a Depth member: a disabled
3193 // button and a disabled field are both disabled and are not the same
3194 // shape, which one shared variant could not have said.
3195 assert_eq!(Depth::Raised.fill(), Some(Fill::Raised));
3196 assert_eq!(Depth::Well.fill(), Some(Fill::Well));
3197 assert!(State::Disabled.suppresses_interaction());
3198 }
3199
3200 #[test]
3201 fn only_disabled_stops_answering() {
3202 // Kept in spirit from the version where `Focus` was the counter-example:
3203 // suppressing interaction is `Disabled`'s alone, so a member added here
3204 // later does not get to inherit it by being a state.
3205 assert!(State::Disabled.suppresses_interaction());
3206 }
3207
3208 #[test]
3209 fn disabled_resolves_against_an_intent_makeover_already_derives() {
3210 // No new token, so this costs no `makeover` release.
3211 assert_eq!(State::Disabled.token(), "content-muted");
3212 }
3213
3214 #[test]
3215 fn flat_has_neither_edge_nor_fill() {
3216 assert_eq!(Depth::Flat.bevel(), None);
3217 assert_eq!(Depth::Flat.fill(), None);
3218 }
3219
3220 #[test]
3221 fn sunken_is_recessed_by_colour_with_no_edge() {
3222 // The one member carrying a fill without a bevel. A renderer that
3223 // assumes the two arrive together drops the fill silently, which is
3224 // exactly what makeover-webview did before 0.3.0.
3225 assert_eq!(Depth::Sunken.fill(), Some(Fill::Sunken));
3226 assert_eq!(Depth::Sunken.bevel(), None);
3227 }
3228
3229 #[test]
3230 fn sunken_and_flat_are_different_claims() {
3231 // Both edgeless, and only one of them needs a colour. Collapsing them
3232 // is what left an unchosen tab unsayable.
3233 assert_eq!(Depth::Flat.bevel(), Depth::Sunken.bevel());
3234 assert_ne!(Depth::Flat.fill(), Depth::Sunken.fill());
3235 }
3236
3237 #[test]
3238 fn a_sunken_surface_is_not_a_well() {
3239 // Authored in opposite directions: makeover derives surface-well by
3240 // inverting against the theme's content colour, while surface-sunken is
3241 // authored and may sit darker than raised.
3242 assert_ne!(Fill::Sunken, Fill::Well);
3243 assert_eq!(Fill::Sunken.token(), "surface-sunken");
3244 assert_eq!(Fill::Well.token(), "surface-well");
3245 }
3246
3247 #[test]
3248 fn every_selector_describes_both_of_its_states() {
3249 // The gap 0.3.0 closed. Before it, only `chosen` existed and the
3250 // unchosen option fell through to Flat at every renderer.
3251 for s in [Selector::Tabs, Selector::Segmented, Selector::Toggle] {
3252 assert_ne!(
3253 s.chosen(),
3254 s.unchosen(),
3255 "{s:?} cannot tell picked from unpicked"
3256 );
3257 }
3258 }
3259
3260 #[test]
3261 fn only_a_tab_inverts_the_other_way() {
3262 // Tabs recede so the chosen one comes forward; a segment and a toggle
3263 // stand up so the chosen one is held in. That inversion is the whole
3264 // content of "picked" once colour is deferred, and it is why the three
3265 // are not one member with a flag.
3266 assert_eq!(Selector::Tabs.unchosen(), Depth::Sunken);
3267 assert_eq!(Selector::Tabs.chosen(), Depth::Raised);
3268
3269 for s in [Selector::Segmented, Selector::Toggle] {
3270 assert_eq!(s.unchosen(), Depth::Raised);
3271 assert_eq!(s.chosen(), Depth::Well);
3272 // Held in is what pressing produces: one appearance, two reasons.
3273 assert_eq!(s.unchosen().pressed(), s.chosen());
3274 }
3275 }
3276
3277 #[test]
3278 fn pressing_a_card_makes_a_well() {
3279 assert_eq!(Depth::Raised.pressed(), Depth::Well);
3280 assert_eq!(
3281 Depth::Raised.pressed().bevel(),
3282 Depth::Raised.bevel().map(Bevel::pressed)
3283 );
3284 // Only raised regions respond to being pressed.
3285 assert_eq!(Depth::Flat.pressed(), Depth::Flat);
3286 assert_eq!(Depth::Well.pressed(), Depth::Well);
3287 // An overlay is a surface, not a control.
3288 assert_eq!(Depth::Overlay.pressed(), Depth::Overlay);
3289 }
3290
3291 #[test]
3292 fn an_overlay_is_lifted_rather_than_edged() {
3293 // The wave-2 rule: a surface over the page takes elevation, a surface
3294 // in the page takes a bevel. Both halves come off the one Depth, so
3295 // they cannot disagree.
3296 assert_eq!(Depth::Overlay.fill(), Some(Fill::Overlay));
3297 assert_eq!(Depth::Overlay.bevel(), None);
3298
3299 // Three depths have no bevel and they are not the same claim. Flat has
3300 // nothing to separate from, Sunken's colour is doing the separating,
3301 // and an overlay is separated by the lift.
3302 assert_ne!(Depth::Overlay.fill(), Depth::Sunken.fill());
3303 assert_ne!(Depth::Overlay.fill(), Depth::Flat.fill());
3304 }
3305
3306 #[test]
3307 fn intents_name_makeover_tokens_and_nothing_else() {
3308 assert_eq!(Edge::Light.token(), "bevel-light");
3309 assert_eq!(Edge::Dark.token(), "bevel-dark");
3310 assert_eq!(Fill::Raised.token(), "surface-raised");
3311 assert_eq!(Fill::Well.token(), "surface-well");
3312 // No value ever leaves this crate.
3313 for t in [
3314 Edge::Light.token(),
3315 Edge::Dark.token(),
3316 Tone::Danger.token(),
3317 Tone::Neutral.token(),
3318 State::Disabled.token(),
3319 ] {
3320 assert!(!t.starts_with('#'), "{t} looks like a value");
3321 assert!(
3322 !t.chars().next().unwrap().is_ascii_digit(),
3323 "{t} is a value"
3324 );
3325 }
3326 }
3327
3328 #[test]
3329 fn a_badge_cannot_be_pressed_and_a_chip_latches() {
3330 // The one line that runs through all three apps' taxonomies.
3331 assert!(!Token::Badge.interactive());
3332 assert!(Token::Chip { removable: false }.interactive());
3333 assert!(Token::Chip { removable: true }.interactive());
3334
3335 // A badge is a label, so giving it an edge would lie about it.
3336 assert_eq!(Token::Badge.depth(false), Depth::Flat);
3337 assert_eq!(Token::Badge.depth(true), Depth::Flat);
3338
3339 // A latched chip wears the same shape a pressed one does.
3340 let chip = Token::Chip { removable: false };
3341 assert_eq!(chip.depth(false), Depth::Raised);
3342 assert_eq!(chip.depth(true), Depth::Raised.pressed());
3343 }
3344
3345 #[test]
3346 fn a_toast_and_a_banner_differ_in_more_than_placement() {
3347 assert!(Notice::Toast.transient());
3348 assert!(!Notice::Banner.transient());
3349 // A toast floats above the page; a banner rests in the flow.
3350 assert_eq!(Notice::Toast.fill(), Fill::Overlay);
3351 assert_eq!(Notice::Banner.fill(), Fill::Raised);
3352 }
3353
3354 #[test]
3355 fn emphasis_falls_off_down_the_row() {
3356 // `revealed_on_hover` was asserted here until 0.13.0 retired it. It said
3357 // a row's actions stay hidden until hover, which stopped being true when
3358 // makeover-webview 0.23.0 showed them at rest, and nothing had consumed
3359 // it for a release either way.
3360 assert_eq!(RowPart::Primary.intent(), "content");
3361 assert_eq!(RowPart::Secondary.intent(), "content-secondary");
3362 assert_eq!(RowPart::Meta.intent(), "content-muted");
3363 }
3364
3365 #[test]
3366 fn a_token_part_carries_no_intent_of_its_own() {
3367 // Each token carries its own tone, so a part-level intent underneath
3368 // would fight the thing sitting on it. Same reasoning as actions, which
3369 // is why they answer alike.
3370 assert_eq!(RowPart::Tokens.intent(), RowPart::Actions.intent());
3371 assert_eq!(RowPart::Tokens.intent(), "content");
3372 }
3373
3374 #[test]
3375 fn the_two_temporal_kinds_are_the_two_that_name_a_moment() {
3376 // The pair is named once so a host with parsing to do asks here rather
3377 // than spelling it out, which is `offers_options`' reason.
3378 assert!(FieldKind::Date.temporal());
3379 assert!(FieldKind::DateTime.temporal());
3380
3381 for kind in [
3382 FieldKind::Text,
3383 FieldKind::Secret,
3384 FieldKind::Number,
3385 FieldKind::Email,
3386 FieldKind::Url,
3387 FieldKind::Tel,
3388 FieldKind::Textarea,
3389 FieldKind::Select,
3390 FieldKind::Radio,
3391 FieldKind::Checkbox,
3392 FieldKind::File,
3393 FieldKind::Hidden,
3394 ] {
3395 assert!(!kind.temporal(), "{kind:?}");
3396 }
3397 }
3398
3399 #[test]
3400 fn a_date_carries_no_time_and_a_datetime_carries_no_zone() {
3401 // The formats are the whole reason the members are worth naming apart
3402 // from text, so the doc comments and the constants have to agree. A
3403 // host reading one and meeting the other is the silent failure.
3404 assert_eq!(DATE_FORMAT, "%Y-%m-%d");
3405 assert!(!DATE_FORMAT.contains("%H"), "a day carries no hour");
3406
3407 assert_eq!(DATETIME_FORMAT, "%Y-%m-%dT%H:%M");
3408 assert!(
3409 DATETIME_FORMAT.starts_with(DATE_FORMAT),
3410 "a moment starts with the day it is on"
3411 );
3412 // Local, and that is a property of the value rather than an omission.
3413 assert!(!DATETIME_FORMAT.contains("%Z"), "no zone name");
3414 assert!(!DATETIME_FORMAT.ends_with('Z'), "not UTC-stamped");
3415 assert!(!DATETIME_FORMAT.contains("%S"), "no seconds by default");
3416 }
3417
3418 #[test]
3419 fn a_temporal_kind_takes_a_label_above_it_and_offers_no_options() {
3420 // Neither is a checkbox and neither is a fixed set, so both fall where
3421 // text does. Asserted because a new kind lands in three predicates and
3422 // only one of them is the interesting one.
3423 for kind in [FieldKind::Date, FieldKind::DateTime] {
3424 assert!(kind.visible(), "{kind:?}");
3425 assert!(!kind.confidential(), "{kind:?}");
3426 assert!(!kind.labels_itself(), "{kind:?}");
3427 assert!(!kind.offers_options(), "{kind:?}");
3428 }
3429 }
3430
3431 #[test]
3432 fn a_cell_part_names_an_intent_and_only_the_value_is_text() {
3433 // The table half of what RowPart::intent does for rows. A cell holding
3434 // a control and a cell holding text answered alike until 0.14.0, and a
3435 // control in a cell took the cell's text colour.
3436 assert_eq!(CellPart::Value.intent(), "content");
3437
3438 for part in [CellPart::Tokens, CellPart::Actions, CellPart::Link] {
3439 // Each for its own reason -- a token carries its tone, an action is
3440 // a control, a link takes the action colour -- and all three reach
3441 // the intent inheriting already gives.
3442 assert_eq!(part.intent(), CellPart::Value.intent(), "{part:?}");
3443 }
3444 }
3445
3446 #[test]
3447 fn every_cell_part_answers_with_a_token_and_never_a_value() {
3448 for part in [
3449 CellPart::Value,
3450 CellPart::Tokens,
3451 CellPart::Actions,
3452 CellPart::Link,
3453 ] {
3454 let intent = part.intent();
3455 assert!(!intent.is_empty(), "{part:?} names nothing");
3456 assert!(!intent.starts_with('#'), "{part:?} looks like a value");
3457 }
3458 }
3459
3460 #[test]
3461 fn a_separator_is_what_tells_a_section_from_a_subsection() {
3462 assert!(Heading::Section.separated());
3463 assert!(!Heading::Subsection.separated());
3464 assert!(!Heading::Page.separated());
3465 }
3466
3467 #[test]
3468 fn a_chosen_segment_is_held_in_and_a_chosen_tab_comes_forward() {
3469 assert_eq!(Selector::Segmented.chosen(), Depth::Well);
3470 assert_eq!(Selector::Toggle.chosen(), Depth::Well);
3471 // The exception, and the whole folder semantic: the open tab joins its
3472 // pane rather than sinking away from it.
3473 assert_eq!(Selector::Tabs.chosen(), Depth::Raised);
3474
3475 // A held-in segment is indistinguishable from a pressed raised one,
3476 // which is the economy the light model buys over a colour swap.
3477 assert_eq!(Selector::Segmented.chosen(), Depth::Raised.pressed());
3478
3479 // A toggle stands alone; the other two are built out of parts that
3480 // touch.
3481 assert!(Selector::Segmented.abutting());
3482 assert!(Selector::Tabs.abutting());
3483 assert!(!Selector::Toggle.abutting());
3484 }
3485
3486 #[test]
3487 fn columns_are_peers_and_a_split_is_not() {
3488 // The distinction the member exists for. A split's two panes stand in a
3489 // master-detail relationship; columns choose nothing about each other.
3490 // Both are flat, so depth cannot tell them apart and the doc has to.
3491 assert_eq!(Region::Columns.depth(), Depth::Flat);
3492 assert_eq!(Region::Split.depth(), Depth::Flat);
3493 assert_ne!(Region::Columns, Region::Split);
3494 }
3495
3496 #[test]
3497 fn columns_carry_no_count_and_no_share() {
3498 // The two things a board is always asked to carry and must not. How
3499 // many is what the children say; how wide is settled by "peers are
3500 // equal".
3501 //
3502 // The guard is the binding itself and it is a compile-time one: adding
3503 // a field to `Columns` stops this line compiling, which is a better
3504 // failure than any assertion about it. Written out rather than inlined
3505 // for exactly that reason.
3506 let columns: Region<'_> = Region::Columns;
3507 assert_eq!(columns.name(), None);
3508 }
3509
3510 #[test]
3511 fn columns_are_described_and_the_escape_hatch_is_still_one_member() {
3512 // A board's contents are ordinary description all the way down, so a
3513 // renderer that does not lay them across still draws every column.
3514 // Stacking them vertically is honouring this member, not degrading it.
3515 assert!(Region::Columns.described());
3516 assert!(!Region::Bespoke { name: "timeline" }.described());
3517 }
3518
3519 #[test]
3520 fn a_span_never_has_zero_minutes_however_it_is_asked_for() {
3521 // Every renderer divides by this. A caller passing a backwards or empty
3522 // span is a bug, but it is not a bug worth a panic three renderers deep.
3523 assert_eq!(Span::new(600, 600).minutes(), 1);
3524 assert_eq!(Span::new(600, 300).minutes(), 1);
3525 assert_eq!(Span::DAY.minutes(), 1440);
3526 }
3527
3528 #[test]
3529 fn a_span_can_run_past_midnight_without_a_second_date() {
3530 // 22:00 to 02:00. The alternative was carrying a date, which drags a
3531 // timezone into the vocabulary for the sake of one night shift.
3532 let overnight = Span::new(1320, 1560);
3533 assert_eq!(overnight.minutes(), 240);
3534 assert!(overnight.holds(1500));
3535 assert!(!overnight.holds(1200));
3536 }
3537
3538 #[test]
3539 fn overlap_is_computed_rather_than_declared() {
3540 // The reason Placement carries no `conflicts` flag: the times already
3541 // say it, and a second source for one fact is how a stale conflict
3542 // badge outlives the conflict.
3543 let morning = Placement::new(540, 60); // 09:00-10:00
3544 let overlapping = Placement::new(570, 60); // 09:30-10:30
3545 let after = Placement::new(600, 60); // 10:00-11:00
3546
3547 assert!(morning.overlaps(overlapping));
3548 assert!(overlapping.overlaps(morning), "overlap is symmetric");
3549 // Touching end to end is not overlapping: `to` is exclusive, so a
3550 // 10:00 start does not collide with a 10:00 end.
3551 assert!(!morning.overlaps(after));
3552 assert!(!after.overlaps(morning));
3553 }
3554
3555 #[test]
3556 fn a_placement_is_always_drawable() {
3557 assert_eq!(Placement::new(540, 0).minutes(), 1);
3558 assert_eq!(Placement::new(540, 30).end(), 570);
3559 }
3560
3561 #[test]
3562 fn a_track_places_the_fraction_every_renderer_would_otherwise_compute() {
3563 let day = Track::DAY;
3564 assert!((day.fraction(0) - 0.0).abs() < f32::EPSILON);
3565 assert!((day.fraction(720) - 0.5).abs() < f32::EPSILON);
3566 // Clamped rather than off the end: an event running past the span's
3567 // close draws at the edge, which beats panicking or drawing nowhere.
3568 assert!((day.fraction(2000) - 1.0).abs() < f32::EPSILON);
3569 }
3570
3571 #[test]
3572 fn a_track_counts_its_slots_and_never_divides_by_zero() {
3573 assert_eq!(Track::DAY.slots(), 96);
3574 assert_eq!(Track::over(Span::new(540, 1020)).slots(), 32);
3575 // A span that does not divide evenly keeps a slot for its tail.
3576 assert_eq!(Track::over(Span::new(0, 50)).slots(), 4);
3577 // slot: 0 is a caller bug that reads as one slot, not a panic.
3578 let degenerate = Track {
3579 span: Span::DAY,
3580 slot: 0,
3581 tick: 60,
3582 };
3583 assert_eq!(degenerate.slots(), 1);
3584 }
3585
3586 #[test]
3587 fn a_track_carries_facts_and_no_presentation() {
3588 // The guard on the thing the withdrawn refusal was right about. If a
3589 // pixel measure, a scroll offset or a colour ever lands on Track, the
3590 // member has stopped being a fact about the data and the timeline
3591 // really has become a component library wearing a description's name.
3592 let day = Track::DAY;
3593 assert_eq!(day.span, Span::DAY);
3594 assert_eq!(day.slot, 15);
3595 assert_eq!(day.tick, 60);
3596 // Three fields. Adding a fourth should have to come here and say why.
3597 assert_eq!(std::mem::size_of::<Track>(), 8);
3598 }
3599
3600 #[test]
3601 fn a_pane_is_looked_into_and_a_band_is_not() {
3602 assert_eq!(Region::Pane.depth(), Depth::Well);
3603 assert_eq!(Region::Modal.depth(), Depth::Raised);
3604 for r in [
3605 Region::Band,
3606 Region::Sidebar,
3607 Region::Split,
3608 Region::TabGroup,
3609 ] {
3610 assert_eq!(r.depth(), Depth::Flat, "{r:?} should carry no edge");
3611 }
3612 }
3613
3614 #[test]
3615 fn exactly_one_region_is_opaque() {
3616 // The escape hatch is one member and stays one member. If a second
3617 // undescribed region ever appears, the description has started
3618 // conceding rather than deferring.
3619 for r in [
3620 Region::Band,
3621 Region::Sidebar,
3622 Region::Pane,
3623 Region::Split,
3624 Region::TabGroup,
3625 Region::Modal,
3626 // A widget is described, and that is the whole of what separates it
3627 // from a bespoke here. Both carry a name this crate never reads;
3628 // only one of them has contents under it that a renderer which does
3629 // not know the name can still walk.
3630 Region::Widget { name: "carousel" },
3631 ] {
3632 assert!(r.described(), "{r:?} should be describable");
3633 }
3634 assert!(!Region::Bespoke { name: "day-plan" }.described());
3635 }
3636
3637 #[test]
3638 fn a_picture_that_says_nothing_is_a_claim_and_not_an_oversight() {
3639 // The distinction a renderer with no graphics protocol runs on: draw
3640 // the words, or draw nothing. Standing in for a decorative rule with
3641 // the word "decoration" is worse than leaving the space empty.
3642 assert!(Image::new("The library view, mid-import").speaks());
3643 assert!(!Image::new("").speaks());
3644 }
3645
3646 #[test]
3647 fn a_caption_and_alt_text_are_not_the_same_line() {
3648 // A caption is content everybody reads; alt text stands in for the
3649 // picture. A screenshot with a caption still needs alt text.
3650 let shot = Image::new("A file list with three rows selected").caption("The library view");
3651 assert_eq!(shot.caption, Some("The library view"));
3652 assert!(shot.speaks());
3653 assert_ne!(shot.alt, shot.caption.unwrap());
3654 }
3655
3656 #[test]
3657 fn a_picture_can_say_how_much_room_to_hold() {
3658 // The whole point: a renderer reserves from the ratio, so the space is
3659 // right at any width. A fixed height would only be right at one.
3660 let shot = Image::new("a screenshot").intrinsic(5120, 3412);
3661 let e = shot.intrinsic.expect("carried");
3662 assert_eq!((e.width, e.height), (5120, 3412));
3663 assert!((e.ratio().unwrap() - 1.5006).abs() < 0.001);
3664 }
3665
3666 #[test]
3667 fn a_picture_with_no_dimensions_reserves_nothing_rather_than_guessing() {
3668 // `None` is honest: a creator upload whose size was never recorded does
3669 // not know it. A renderer must not invent one.
3670 assert_eq!(Image::new("unknown upload").intrinsic, None);
3671 assert_eq!(Extent::new(0, 10).ratio(), None);
3672 assert_eq!(Extent::new(10, 0).ratio(), None);
3673 }
3674
3675 #[test]
3676 fn a_picture_is_wanted_now_unless_the_app_says_otherwise() {
3677 // Eager is the safe default and lazy is the opt-in, because deferring
3678 // something already on screen saves nothing and moves its shift later.
3679 assert_eq!(Image::new("hero").loading, Loading::Eager);
3680 assert_eq!(Loading::default(), Loading::Eager);
3681 assert_eq!(Image::new("frame 2").lazy().loading, Loading::Lazy);
3682 }
3683
3684 #[test]
3685 fn a_picture_keeps_its_own_proportions_unless_told_otherwise() {
3686 // The default is the one that shows the whole picture at its own shape,
3687 // so a renderer ignoring Fit entirely is still right about the common
3688 // case. The shipped MNW carousel sets no object-fit at all, which is
3689 // this.
3690 assert_eq!(Image::new("a").fit, Fit::Natural);
3691 assert_eq!(Fit::default(), Fit::Natural);
3692 assert_eq!(Image::new("a").fit(Fit::Cover).fit, Fit::Cover);
3693 }
3694
3695 #[test]
3696 fn a_widget_inherits_its_depth_the_way_a_bespoke_does() {
3697 // Stronger than the bespoke case: a widget is drawn by whichever
3698 // renderer recognises the name, so a depth chosen here would be this
3699 // crate deciding a carousel is raised on every host.
3700 assert_eq!(Region::Widget { name: "carousel" }.depth(), Depth::Flat);
3701 assert_eq!(Region::Widget { name: "pager" }.depth(), Depth::Flat);
3702 }
3703
3704 #[test]
3705 fn a_name_is_readable_without_asking_which_member_carried_it() {
3706 // A renderer dispatching on a name wants the string, not the member.
3707 // Writing that `matches!` at each renderer is how the two drift apart.
3708 assert_eq!(Region::Widget { name: "carousel" }.name(), Some("carousel"));
3709 assert_eq!(
3710 Region::Bespoke { name: "day-plan" }.name(),
3711 Some("day-plan")
3712 );
3713
3714 for r in [
3715 Region::Band,
3716 Region::Sidebar,
3717 Region::Pane,
3718 Region::Split,
3719 Region::TabGroup,
3720 Region::Modal,
3721 ] {
3722 assert_eq!(r.name(), None, "{r:?} names nothing an app chose");
3723 }
3724 }
3725
3726 #[test]
3727 fn a_bespoke_region_inherits_its_depth_rather_than_choosing_one() {
3728 // The app owns the contents, not the placement. An app that wants its
3729 // timeline in a well frames it in a Pane.
3730 assert_eq!(Region::Bespoke { name: "day-plan" }.depth(), Depth::Flat);
3731 assert_eq!(Region::Bespoke { name: "kanban" }.depth(), Depth::Flat);
3732 }
3733
3734 #[test]
3735 fn a_screen_with_a_bespoke_region_is_still_a_whole_screen() {
3736 // The argument the member exists for: goingson's day-plan has to be
3737 // routable, or the description covers only the boring screens and the
3738 // interesting four need a second path beside the router.
3739 let day_plan = [
3740 Region::Band,
3741 Region::Bespoke { name: "day-plan" },
3742 Region::Sidebar,
3743 ];
3744 assert_eq!(day_plan.iter().filter(|r| r.described()).count(), 2);
3745 assert_eq!(day_plan.iter().filter(|r| !r.described()).count(), 1);
3746 }
3747
3748 #[test]
3749 fn a_secret_field_is_marked_as_one_and_a_hidden_field_is_not_drawn() {
3750 let secret = Field::new(FieldKind::Secret, "password", "Password");
3751 assert!(secret.kind.confidential());
3752 assert!(secret.kind.visible());
3753
3754 assert!(!FieldKind::Hidden.visible());
3755 // Nothing else is confidential, or the marker means nothing.
3756 for k in [
3757 FieldKind::Text,
3758 FieldKind::Number,
3759 FieldKind::Textarea,
3760 FieldKind::Select,
3761 FieldKind::Checkbox,
3762 FieldKind::Hidden,
3763 ] {
3764 assert!(!k.confidential(), "{k:?} should not be confidential");
3765 }
3766
3767 // Only a checkbox carries its own label.
3768 assert!(FieldKind::Checkbox.labels_itself());
3769 assert!(!FieldKind::Text.labels_itself());
3770 }
3771
3772 #[test]
3773 fn a_plain_field_offers_nothing_and_a_select_offers_its_options() {
3774 let text = Field::new(FieldKind::Text, "title", "Title");
3775 assert!(text.options.is_empty());
3776 assert_eq!(text.placeholder, None);
3777
3778 let sizes = [Choice::plain("small"), Choice::plain("large")];
3779 let select = Field::select("size", "Size", &sizes);
3780 assert_eq!(select.kind, FieldKind::Select);
3781 assert_eq!(select.options.len(), 2);
3782 }
3783
3784 #[test]
3785 fn a_choice_says_what_submits_and_what_is_read_apart() {
3786 // The whole reason it is two strings. `plain` is the case where they
3787 // coincide, and it is a shorthand rather than the general shape.
3788 let plain = Choice::plain("7");
3789 assert_eq!((plain.value, plain.label), ("7", "7"));
3790
3791 let spelled = Choice {
3792 value: "7",
3793 label: "One week",
3794 };
3795 assert_ne!(spelled.value, spelled.label);
3796 }
3797
3798 #[test]
3799 fn a_radio_asks_the_same_question_as_a_select_and_is_not_the_same_kind() {
3800 // Both offer a fixed set and both read `options`, so the two
3801 // constructors differ in exactly one thing. That one thing is the
3802 // point: a renderer decides whether the alternatives are readable
3803 // without opening anything, and it can only decide that if the
3804 // description said which question was asked.
3805 let styles = [
3806 Choice {
3807 value: "copy",
3808 label: "Copy samples in",
3809 },
3810 Choice {
3811 value: "reference",
3812 label: "Reference in place",
3813 },
3814 ];
3815 let radio = Field::radio("storage", "Storage style", &styles);
3816 let select = Field::select("storage", "Storage style", &styles);
3817
3818 assert_eq!(radio.kind, FieldKind::Radio);
3819 assert_ne!(radio.kind, select.kind);
3820 assert_eq!(radio.options, select.options);
3821 assert_eq!(
3822 Field {
3823 kind: select.kind,
3824 ..radio
3825 },
3826 select
3827 );
3828 }
3829
3830 #[test]
3831 fn exactly_the_option_taking_kinds_say_so() {
3832 // The renderers branch on this rather than on a list of their own, so
3833 // a kind added without a decision here renders its options nowhere.
3834 assert!(FieldKind::Select.offers_options());
3835 assert!(FieldKind::Radio.offers_options());
3836 for kind in [
3837 FieldKind::Text,
3838 FieldKind::Secret,
3839 FieldKind::Number,
3840 FieldKind::Email,
3841 FieldKind::Url,
3842 FieldKind::Tel,
3843 FieldKind::Textarea,
3844 FieldKind::Checkbox,
3845 FieldKind::Hidden,
3846 ] {
3847 assert!(!kind.offers_options(), "{kind:?} does not offer options");
3848 }
3849 }
3850
3851 #[test]
3852 fn a_radio_group_takes_a_label_even_though_its_options_carry_their_own() {
3853 // The near-miss: each option is labelled beside its own button, so a
3854 // renderer could plausibly read the group as self-labelling and drop
3855 // the question. Checkbox is the only kind that does that.
3856 assert!(!FieldKind::Radio.labels_itself());
3857 assert!(FieldKind::Checkbox.labels_itself());
3858 }
3859
3860 #[test]
3861 fn a_select_with_no_options_is_sayable() {
3862 // An app whose option list has not loaded has exactly this. Making it
3863 // unrepresentable would push the state somewhere less visible, and a
3864 // renderer drawing an empty select reports it on screen.
3865 let loading = Field::select("project", "Project", &[]);
3866 assert!(loading.options.is_empty());
3867 }
3868
3869 #[test]
3870 fn the_description_carries_the_question_and_never_the_answer() {
3871 // The line 0.8.0 drew. Placeholder and options are properties of what
3872 // is being asked; the current value is what came back, and no field
3873 // here holds one.
3874 let f = Field {
3875 placeholder: Some("yyyy-mm-dd"),
3876 ..Field::new(FieldKind::Text, "due", "Due")
3877 };
3878 assert_eq!(f.placeholder, Some("yyyy-mm-dd"));
3879 // A placeholder is not a label, and having one does not excuse the
3880 // field from carrying the other.
3881 assert_eq!(f.label, "Due");
3882 }
3883
3884 #[test]
3885 fn a_field_reports_its_own_error_state() {
3886 let mut f = Field::new(FieldKind::Text, "title", "Title");
3887 assert!(!f.invalid());
3888 f.error = Some("Required");
3889 assert!(f.invalid());
3890 }
3891
3892 #[test]
3893 fn columns_drop_by_priority_and_never_by_position() {
3894 let cols = [
3895 Column {
3896 width: Width::Fill,
3897 priority: Priority::Essential,
3898 ..Column::new("Title")
3899 },
3900 Column {
3901 width: Width::Fixed,
3902 priority: Priority::Secondary,
3903 ..Column::new("Due")
3904 },
3905 Column {
3906 width: Width::Fixed,
3907 priority: Priority::Optional,
3908 ..Column::new("Estimate")
3909 },
3910 ];
3911
3912 // Widest: everything survives.
3913 assert_eq!(
3914 cols.iter()
3915 .filter(|c| c.kept_at(Priority::Optional))
3916 .count(),
3917 3
3918 );
3919 // Narrower: the optional column goes first.
3920 let kept: Vec<_> = cols
3921 .iter()
3922 .filter(|c| c.kept_at(Priority::Secondary))
3923 .map(|c| c.name)
3924 .collect();
3925 assert_eq!(kept, ["Title", "Due"]);
3926 // Narrowest: only what identifies the row.
3927 let kept: Vec<_> = cols
3928 .iter()
3929 .filter(|c| c.kept_at(Priority::Essential))
3930 .map(|c| c.name)
3931 .collect();
3932 assert_eq!(kept, ["Title"]);
3933 }
3934
3935 #[test]
3936 fn inserting_a_column_does_not_move_what_gets_dropped() {
3937 // The bug the ordinal form has and this form cannot: goingson hides
3938 // `nth-child(n+5)` against a seven-column table, so a column inserted
3939 // anywhere to the left silently hides a different one.
3940 let before = [
3941 Column::new("Title"),
3942 Column {
3943 width: Width::Fixed,
3944 priority: Priority::Optional,
3945 ..Column::new("Estimate")
3946 },
3947 ];
3948 let after = [
3949 Column::new("Title"),
3950 Column::new("Project"), // inserted
3951 Column {
3952 width: Width::Fixed,
3953 priority: Priority::Optional,
3954 ..Column::new("Estimate")
3955 },
3956 ];
3957
3958 fn dropped<'a>(cols: &[Column<'a>]) -> Vec<&'a str> {
3959 cols.iter()
3960 .filter(|c| !c.kept_at(Priority::Secondary))
3961 .map(|c| c.name)
3962 .collect()
3963 }
3964 assert_eq!(dropped(&before), ["Estimate"]);
3965 assert_eq!(dropped(&after), ["Estimate"]);
3966 }
3967
3968 #[test]
3969 fn an_arrangement_carries_the_tab_group_as_a_modifier() {
3970 // goingson uses the tab group inside the content region rather than
3971 // instead of one, so it is not a third arrangement.
3972 let go = Arrangement::list_detail(true);
3973 let plain = Arrangement::list_detail(false);
3974 assert_ne!(go, plain);
3975 assert_ne!(go, Arrangement::sidebar_content());
3976 }
3977
3978 #[test]
3979 fn a_share_is_a_proportion_and_resolves_the_same_way_everywhere() {
3980 // The point of the member: a terminal reading columns and a webview
3981 // reading a grid honour one fact, so two hosts showing one screen agree
3982 // about its proportions.
3983 assert_eq!(Share::LIST.as_percent(), 40);
3984 assert_eq!(Share::LIST.of(100), 40);
3985 assert_eq!(
3986 Share::SIDEBAR.of(96),
3987 24,
3988 "quasi-tui's 24 columns, said as a quarter"
3989 );
3990 }
3991
3992 #[test]
3993 fn a_region_never_resolves_to_nothing() {
3994 // A region the description named should be visible. A zero-width one
3995 // reads on screen as a region that vanished, which is the hardest kind
3996 // of bug to find from what is drawn.
3997 assert_eq!(Share::percent(5).of(1), 1);
3998 assert_eq!(Share::percent(5).of(0), 1);
3999 }
4000
4001 #[test]
4002 fn a_share_outside_the_range_is_clamped_rather_than_refused() {
4003 assert_eq!(Share::percent(0), Share::percent(5));
4004 assert_eq!(Share::percent(200), Share::percent(95));
4005 }
4006
4007 #[test]
4008 fn the_share_rides_on_the_arrangement_that_knows_which_question_it_is() {
4009 // How much a sidebar takes and how much a list side takes are different
4010 // questions, and this enum is the only thing that knows which is being
4011 // asked.
4012 assert_eq!(Arrangement::sidebar_content().share(), Share::SIDEBAR);
4013 assert_eq!(Arrangement::list_detail(false).share(), Share::LIST);
4014
4015 let narrow = Arrangement::sidebar_content().with_share(Share::percent(20));
4016 assert_eq!(narrow.share(), Share::percent(20));
4017 assert!(matches!(narrow, Arrangement::SidebarContent { .. }));
4018 }
4019
4020 #[test]
4021 fn a_measure_defaults_to_the_one_53_of_69_templates_asked_for() {
4022 // The default is meaningful: a screen nobody said anything about uses
4023 // the window it was given.
4024 assert_eq!(Measure::default(), Measure::Wide);
4025 assert_eq!(Measure::Reading.as_str(), "reading");
4026 }
4027
4028 #[test]
4029 fn readiness_names_the_state_and_not_the_shimmer() {
4030 // Two members and no third. If a skeleton ever appears in this enum,
4031 // the deferral rule has been broken.
4032 assert_ne!(Readiness::Ready, Readiness::Pending);
4033 }
4034}