makeover_layout/component.rs
1use crate::{Depth, Fill, Intent, Priority};
2
3// Names this module's prose links to, resolved for rustdoc.
4#[allow(unused_imports)]
5use crate::{Awaiting, Region};
6
7/// What a region is saying, when it is saying something.
8///
9/// The one intent family shared by badges, notices and nothing else. Kept
10/// separate from [`Fill`] because a surface is where a thing sits and a tone is
11/// what it means, and the three apps agree on the four statuses:
12/// `info_banner` / `warning_banner` in audiofiles, `.toast-info` /
13/// `.toast-success` / `.toast-error` in goingson, `.toast.success` /
14/// `.toast.error` in Balanced Breakfast.
15///
16/// The per-tag palette (`category-one` through `category-six`) is deliberately
17/// not here. Which colour a *particular* tag takes is app domain, and both
18/// webview apps already carry it as a `data-color` attribute.
19#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
20#[non_exhaustive]
21pub enum Tone {
22 /// No status.
23 ///
24 /// Ordinary content, at full weight. It does not also mean muted: a
25 /// badge reads quiet because [`Token::Badge`] answers no click, which is
26 /// the renderer's knowledge and not this axis's. A renderer wanting a
27 /// muted badge reaches for [`Token::interactive`] itself rather than
28 /// expecting `Neutral` to have muted it.
29 Neutral,
30 /// Something worth knowing and nothing to do about it.
31 Info,
32 /// Something finished and it worked.
33 Success,
34 /// Something the user should look at before continuing.
35 Warning,
36 /// Something broken, or something about to be destroyed.
37 Danger,
38}
39
40impl Intent for Tone {
41 fn token(self) -> &'static str {
42 match self {
43 // Neutral has no status token of its own, so it takes the plain
44 // content intent. It used to answer `content-muted`, which read
45 // "no status" as "de-emphasised" and muted every figure value in
46 // the webview. Muting is a renderer's call about a particular
47 // token, not something the status axis knows.
48 Self::Neutral => "content",
49 Self::Info => "info",
50 Self::Success => "success",
51 Self::Warning => "warning",
52 Self::Danger => "danger",
53 }
54 }
55}
56
57/// A step of the measure ramp: how much of something there is, as a band.
58///
59/// Distinct from [`Tone`]: a tone says what a thing *means* (a warning, a
60/// success), a heat says how *much* (entropy, a value, a ratio). The bands
61/// are a neutral ramp the theme colours; the app decides where the cuts fall,
62/// since "how much" is app domain. A heat is never a status: the loudest band
63/// is not a warning and the quietest is not a success, any more than a long
64/// bar is.
65///
66/// Carried as a background on text and cells, the one emphasis a value earns
67/// without a claim about what to do about it.
68#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
69pub struct Heat(pub u8);
70
71/// The bands a heat resolves against. A higher band clamps to the last.
72pub const HEAT_BANDS: u8 = 5;
73
74impl Intent for Heat {
75 fn token(self) -> &'static str {
76 match self.0.min(HEAT_BANDS - 1) {
77 0 => "heat-0",
78 1 => "heat-1",
79 2 => "heat-2",
80 3 => "heat-3",
81 _ => "heat-4",
82 }
83 }
84}
85
86/// A small labelled thing that sits inside something else.
87///
88/// Two members, because the three apps drew three taxonomies and only one line
89/// runs through all of them: does it answer a click. audiofiles has
90/// `classification_badge` (a label) against `tag_chip`, `tag_chip_removable`
91/// and `selectable_tag` (all of which do). Balanced Breakfast has `.tag` and
92/// `.badge` against `.tag-chip`. goingson is the one that has to move: its
93/// `.tag` and `.badge` are a single CSS rule, so every call site has to be read
94/// to decide which of the two it always was.
95///
96/// The evidence that a chip is a real concept rather than a badge with a
97/// cursor: audiofiles inverts its bevel on press and Balanced Breakfast latches
98/// `.tag-chip.active` with the inset bevel. Two independent arrivals at "a chip
99/// holds itself down", which is exactly what [`Depth::pressed`] already says.
100#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
101#[non_exhaustive]
102pub enum Token {
103 /// Non-interactive status or count. Answers no click.
104 Badge,
105 /// An interactive or removable token. Answers a click, and latches if it
106 /// stands for a filter that is either on or off.
107 Chip {
108 /// Whether it carries its own remove affordance.
109 removable: bool,
110 },
111}
112
113impl Token {
114 /// Whether this answers a click.
115 ///
116 /// The whole difference between the two members, and the reason a renderer
117 /// with no hover (a touch surface, a terminal) can still tell them apart.
118 #[must_use]
119 pub const fn interactive(self) -> bool {
120 matches!(self, Self::Chip { .. })
121 }
122
123 /// How it sits, given whether it is currently latched down.
124 ///
125 /// A badge is flat: it is a label, and giving it an edge would say it can
126 /// be pressed. A chip is raised, and inset while latched.
127 #[must_use]
128 pub const fn depth(self, latched: bool) -> Depth {
129 match self {
130 Self::Badge => Depth::Flat,
131 Self::Chip { .. } if latched => Depth::Well,
132 Self::Chip { .. } => Depth::Raised,
133 }
134 }
135}
136
137/// Something the app is telling the user, unprompted.
138///
139/// Two concepts, not one with a placement. They differ in more than where they
140/// sit: a toast is transient, stacked and self-dismissing, and a banner is
141/// persistent, in flow, one per region, and dismissed by fixing the condition
142/// it reports. Folding them into one member with a placement parameter would
143/// make lifetime, stacking and dismissal all placement-dependent, which is the
144/// description leaking renderer policy.
145///
146/// All three apps have banners: `info_banner` and `warning_banner` in
147/// audiofiles, five of them in goingson (sync, sync-result, vacation-day,
148/// timer-active, past-review), `.update-banner` in Balanced Breakfast. The two
149/// webview apps also have toasts. So neither member is speculative, and no app
150/// gains a concept it lacks except audiofiles, whose renderer may legitimately
151/// decline to draw a toast at all.
152#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
153#[non_exhaustive]
154pub enum Notice {
155 /// Transient, stacked, dismisses itself.
156 Toast,
157 /// Persistent, in flow, one per region, dismissed by fixing the cause.
158 Banner,
159}
160
161impl Notice {
162 /// Whether it goes away on its own.
163 #[must_use]
164 pub const fn transient(self) -> bool {
165 matches!(self, Self::Toast)
166 }
167
168 /// How it sits.
169 ///
170 /// A toast floats above the page rather than resting on it, which is
171 /// [`Fill::Overlay`]'s whole reason to exist. A banner is a card in the
172 /// flow. Both are raised, and they are raised off different things.
173 #[must_use]
174 pub const fn fill(self) -> Fill {
175 match self {
176 Self::Toast => Fill::Overlay,
177 Self::Banner => Fill::Raised,
178 }
179 }
180}
181
182/// The parts of a list row.
183///
184/// `#[non_exhaustive]`: a renderer carries a wildcard arm, so a new part is not
185/// a lockstep event across three renderers.
186///
187/// # Meta against Tokens
188///
189/// The line is whether the thing has its own standing. `Meta` is one short
190/// trailing fact about the row, written as text: a count, a size, a date.
191/// `Tokens` is a set of small labelled things, each of which can be toned and
192/// can answer a click. "3 files" is meta. A status badge that is amber, and a
193/// tag you can click to filter by, are tokens.
194///
195/// Keeping them apart is what a single widened slot would have foreclosed. A
196/// renderer can right-align one string and cannot usefully do the same to a
197/// strip of chips, and a fact that is not clickable should not be drawn as
198/// though it were.
199/// How much vertical room a part's text may take.
200///
201/// A row is an inline run and every part in it is a leaf, so a part's text has
202/// always been drawn on one line and no description could say otherwise. Two
203/// apps say otherwise in their own stylesheets, both to the same number and
204/// both with a comment explaining it: Balanced Breakfast clamps a feed row's
205/// title to two lines (`.row--article .row-primary`, whose comment reads
206/// "overrides .row-primary's single flex line"), and goingson clamps a
207/// problem's body to two ("two lines is enough to recognize one, and the full
208/// text is in the task once promoted").
209///
210/// Two named tiers rather than a line count, and the count is what the measured
211/// demand argues against. Both sites want exactly one tier past the default,
212/// and a number invites a row whose primary is a paragraph, which is a block
213/// and has no business in a run. A third tier is a decision, made here, rather
214/// than something a call site can reach for.
215///
216/// What a renderer owes it: `Tight` is what a run already does and needs no
217/// answer. `Relaxed` is at most two lines and then truncation, however that
218/// renderer truncates, a webview clamps, a terminal wraps into two rows of
219/// cells, an immediate-mode renderer caps the galley. A renderer that cannot
220/// give two lines may draw one; what it may not do is grow without bound,
221/// because the run is a line and the row's neighbours are relying on that.
222#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
223#[non_exhaustive]
224pub enum Flow {
225 /// One line. What every part did before this type existed.
226 #[default]
227 Tight,
228 /// Up to two lines, then truncated.
229 Relaxed,
230}
231
232impl Flow {
233 /// How many lines the part may take.
234 ///
235 /// A number here rather than in the enum, because a renderer needs one and
236 /// a call site does not. That asymmetry is the whole argument for the
237 /// tiers: the description says how much room the thing deserves and this
238 /// says what that costs, so a third tier changes one line rather than every
239 /// consumer's arithmetic.
240 #[must_use]
241 pub const fn lines(self) -> u8 {
242 match self {
243 Self::Relaxed => 2,
244 // Including any tier added later: one line is the safe reading of
245 // an unknown flow, since it is what the run guaranteed before flows
246 // existed.
247 _ => 1,
248 }
249 }
250}
251
252/// How deep a row sits inside a set: a tree, an outline, a threaded list.
253///
254/// [`RowPart`] below already names what is *in* a row; nothing named where a
255/// row sits relative to its siblings, so every consumer that had a hierarchy
256/// carried a bare number and every renderer decided for itself what one was
257/// worth.
258///
259/// # Not `Depth`, and the collision is the reason
260///
261/// [`Depth`] is taken and means something else entirely: surface bevel --
262/// `Flat`, `Raised`, `Well`, `Sunken`, `Overlay`, a fact about a surface
263/// rather than a position in a hierarchy. Two meanings under one word in one
264/// crate is the collision that costs a reader an hour, and the word this
265/// concept wants is the one that would cause it.
266///
267/// # The magnitude is the renderer's, and that is the precedent
268///
269/// [`Awaiting`] is the shape: this crate names the fact and declines to name
270/// what it is worth. makeover-webview writes the rule as a custom property with
271/// a fallback, the way it writes `margin-inline-start: var(--awaiting-gap,
272/// 0.5ch)`, so a level has one answer per renderer and an app can override
273/// it. A terminal spends columns, a browser spends inline space, and neither
274/// number belongs in a description.
275///
276/// # Zero is a real answer
277///
278/// [`top`](Self::top) is the default and is what a flat list says: every row is
279/// at the top level, which is true and is the reading a renderer needs. An
280/// `Option` here would make "not nested" and "nested at zero" two spellings of
281/// one thing, the same argument `Discovery`'s `indexable` makes about defaults
282/// that are meaningful.
283#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default, PartialOrd, Ord)]
284#[non_exhaustive]
285pub struct Nesting {
286 /// How many levels in, counting from zero.
287 ///
288 /// `u8` because a hierarchy a reader can follow is not 256 deep, and a
289 /// renderer indenting by a level has to multiply it by something, a wider
290 /// integer here is a wider integer in every renderer's arithmetic for a
291 /// range nothing will use.
292 pub level: u8,
293}
294
295impl Nesting {
296 /// The top level: not nested. The default, and what a flat list says.
297 #[must_use]
298 pub const fn top() -> Self {
299 Self { level: 0 }
300 }
301
302 /// A row this many levels in.
303 #[must_use]
304 pub const fn at(level: u8) -> Self {
305 Self { level }
306 }
307
308 /// Whether this row sits under another.
309 ///
310 /// The question every renderer asks before it spends anything on indenting,
311 /// answered once here rather than by a `> 0` in each, which is
312 /// [`Awaiting::is_determinate`]'s reason too.
313 #[must_use]
314 pub const fn is_nested(self) -> bool {
315 self.level > 0
316 }
317}
318
319#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
320#[non_exhaustive]
321pub enum RowPart {
322 /// The thing itself. What the row is called.
323 Primary,
324 /// Supporting text under the primary.
325 Secondary,
326 /// A short trailing fact: a count, a size, a date.
327 Meta,
328 /// Controls that act on this row.
329 Actions,
330 /// Small labelled things belonging to the row: badges, chips, tags.
331 ///
332 /// Each carries its own [`Token`] kind and [`Tone`], so a renderer with no
333 /// colour still has the kind to work with, and one with no chips still has
334 /// the label. That is the constrained-consumer test this vocabulary exists
335 /// to pass, and it is why the tone lives on the token rather than on the
336 /// part.
337 Tokens,
338 /// How much of a set the row's thing has done: a meter in the row.
339 ///
340 /// A row holds no nodes, by the rule that a row part may not carry an
341 /// arbitrary node, which is the door through which a description becomes a
342 /// templating language. So the part carries the *description of a bar* rather than a node, exactly as
343 /// `Tokens` carries tags rather than nodes.
344 ///
345 /// Without it a row flattens the proportion into [`Meta`](Self::Meta) as
346 /// "3/7 subtasks", which keeps both numbers and loses the reading, the same
347 /// way a toned status badge read as prose before `Tokens`.
348 Proportion,
349}
350
351impl RowPart {
352 /// What the part is worth when the run does not fit.
353 ///
354 /// The default only. A part may say otherwise, and a renderer reads the
355 /// part rather than the role; this is what a description that has never
356 /// heard of [`Priority`] means, which is every description written before
357 /// the field existed.
358 ///
359 /// Deriving it from the role is the thing this vocabulary has otherwise
360 /// been moving away from, and it is right here for one reason: the roles
361 /// already encode this ranking and every consumer already assumes it.
362 /// [`Primary`](Self::Primary) is what the row is called, and
363 /// [`Priority::Essential`]'s own doc was written about exactly that --
364 /// "without it the row does not identify itself".
365 ///
366 /// [`Actions`](Self::Actions) is `Essential` and it is the interesting one.
367 /// A control is not a fact, so dropping it does not cost the reader a
368 /// detail; it costs them the only way to act on the row, and in a terminal
369 /// it silently removes something focus had already been claimed for. A
370 /// renderer that needs room takes it from what the row *says*, never from
371 /// what it *offers*.
372 ///
373 /// An unknown member reads as [`Priority::Secondary`]: droppable, but not
374 /// first, since guessing `Optional` for something this crate has not been
375 /// taught would make a new member the first thing to vanish.
376 #[must_use]
377 pub const fn priority(self) -> Priority {
378 match self {
379 Self::Primary | Self::Actions => Priority::Essential,
380 Self::Meta | Self::Proportion => Priority::Optional,
381 _ => Priority::Secondary,
382 }
383 }
384
385 /// The content intent the part takes.
386 #[must_use]
387 pub const fn intent(self) -> &'static str {
388 match self {
389 Self::Primary => "content",
390 Self::Secondary => "content-secondary",
391 Self::Meta => "content-muted",
392 // Actions carry controls rather than text, so they inherit.
393 Self::Actions => "content",
394 // So do tokens: each one carries its own tone, and a part-level
395 // intent underneath it would fight the token that sits on it.
396 Self::Tokens => "content",
397 // And so does a proportion, for the same reason: the meter carries
398 // the tone, and it is about the ratio rather than about the row.
399 Self::Proportion => "content",
400 }
401 }
402}
403
404/// How far down the heading tree a title sits.
405///
406/// Three, and only the three that are actually headings. The bands those used
407/// to be filed with (goingson's `.page-header`, Balanced Breakfast's `.header`
408/// and `.detail-header`) are arrangement, not type, and live at
409/// [`Region::Band`]. One of them contains no text at all.
410#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
411#[non_exhaustive]
412pub enum Heading {
413 /// Names the whole screen. One per screen.
414 Page,
415 /// Names a block within the screen.
416 Section,
417 /// Names a sub-block inside an already-named section.
418 Subsection,
419}
420
421/// A control that picks between things.
422///
423/// Three, because three distinct behaviours are in play and collapsing any two
424/// loses something. A segmented control picks a value; a tab picks a pane; a
425/// toggle picks nothing and simply holds itself on or off.
426#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
427#[non_exhaustive]
428pub enum Selector {
429 /// Exactly one of N, and the options abut.
430 Segmented,
431 /// Independent on or off, on its own.
432 Toggle,
433 /// Navigation between panes. The folder semantic.
434 Tabs,
435}
436
437impl Selector {
438 /// How the chosen option sits.
439 ///
440 /// Held in for a segmented control and a toggle, which is the same shape
441 /// pressing produces and the whole economy of the idiom: one appearance,
442 /// two reasons to wear it. A tab is the exception, because the selected
443 /// folder tab comes *forward* to join the pane it opens.
444 #[must_use]
445 pub const fn chosen(self) -> Depth {
446 match self {
447 Self::Segmented | Self::Toggle => Depth::Well,
448 Self::Tabs => Depth::Raised,
449 }
450 }
451
452 /// How the options that were *not* picked sit.
453 ///
454 /// Describing only [`Selector::chosen`] left the unchosen option falling
455 /// through to [`Depth::Flat`], which says it is level with the strip it
456 /// sits in, and no renderer emitted anything for it. That is wrong in both
457 /// directions and goingson proved it: its unchosen tabs are recessed by
458 /// hand, and being recessed is *why* the chosen one reads as coming
459 /// forward. Against a flat strip, a raised chosen tab is a bevel drawn on
460 /// the strip's own colour, which is a much weaker folder effect than the
461 /// contrast the idiom is named after.
462 ///
463 /// Each member is the inverse of its chosen state, which is the whole
464 /// content of "picked" once colour is deferred:
465 ///
466 /// - Tabs recede, so the chosen one comes forward.
467 /// - A segment and a toggle stand up, so the chosen one is held in.
468 #[must_use]
469 pub const fn unchosen(self) -> Depth {
470 match self {
471 Self::Tabs => Depth::Sunken,
472 Self::Segmented | Self::Toggle => Depth::Raised,
473 }
474 }
475
476 /// Whether the options touch.
477 ///
478 /// The gap is the entire difference between a segmented control and a row
479 /// of buttons that happen to sit near each other, which is what audiofiles'
480 /// `segmented_control` says in its own comment and why it zeroes the
481 /// spacing by hand.
482 #[must_use]
483 pub const fn abutting(self) -> bool {
484 matches!(self, Self::Segmented | Self::Tabs)
485 }
486
487 /// Whether the chosen option joins the surface it opens.
488 ///
489 /// True for [`Tabs`](Self::Tabs) alone, and it is the half of the folder
490 /// semantic [`chosen`](Self::chosen) cannot carry. A depth says how a
491 /// thing sits relative to what is behind it; this says that the chosen
492 /// option and its pane are one surface, so the run between them is not
493 /// drawn at all.
494 ///
495 /// Kept as its own question rather than folded into the depth because the
496 /// pairing rule holds: fill and bevel travel together off one [`Depth`],
497 /// and a renderer composes that depth's fill with
498 /// [`Bevel::RaisedOpen`](crate::Bevel::RaisedOpen) when this is true. A
499 /// segment or a toggle picks a value and opens nothing, so there is
500 /// nothing for either of them to join.
501 #[must_use]
502 pub const fn joins_its_pane(self) -> bool {
503 matches!(self, Self::Tabs)
504 }
505}