max / makeover-layout
| 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.** [`Bevel`], [`Edge`], [`Fill`], [`Depth`]: the bevel and the |
| 28 | //! surfaces it shapes. Fill and bevel are named together, so a raised bevel |
| 29 | //! over a recessed fill is unrepresentable. |
| 30 | //! - **Components.** [`Token`] (badge against chip), [`Notice`] (toast against |
| 31 | //! banner), [`RowPart`], [`CellPart`], [`Heading`], [`Selector`], |
| 32 | //! [`Readiness`], [`Awaiting`], [`Meter`], [`Figure`], [`Track`], |
| 33 | //! and [`Tone`], the one intent family they share. |
| 34 | //! - **Schemas.** [`Field`] for forms, [`Column`] for lists and tables, |
| 35 | //! [`Facet`] for the dimensions a set is narrowed by. |
| 36 | //! - **Structure.** [`Region`] for the parts of a screen, [`Arrangement`] for |
| 37 | //! how a screen is put together, [`Showing`] for how many of a region's |
| 38 | //! children are visible at once. |
| 39 | //! |
| 40 | //! # What a member is admitted on |
| 41 | //! |
| 42 | //! A member is added when an app needs a fact the vocabulary cannot state, and |
| 43 | //! refused when what it wants is presentation it should be asking a renderer |
| 44 | //! for. Three tests, all of which have to pass: |
| 45 | //! |
| 46 | //! - **Generic against bespoke.** Is this furniture any app would have, or is |
| 47 | //! it this app's own? A rule that withholds a word until a second app has |
| 48 | //! duplicated the code guarantees the duplication. Bespoke keeps |
| 49 | //! [`Region::Bespoke`]. |
| 50 | //! - **Every host has an honest answer.** A member no renderer can express |
| 51 | //! without borrowing one host's idiom is not a description. |
| 52 | //! - **It can be laid out before it is filled.** See *First paint is final |
| 53 | //! paint* below. |
| 54 | //! |
| 55 | //! Count the members a thing needs before refusing it. A refusal is only worth |
| 56 | //! as much as the measurement under it. |
| 57 | //! |
| 58 | //! # What this crate cannot say |
| 59 | //! |
| 60 | //! - **An address.** What a control calls, and where a button goes. [`Act`] |
| 61 | //! names the act and holds no destination. |
| 62 | //! - **A current value.** A webview reads it out of the DOM and an |
| 63 | //! immediate-mode renderer holds a `&mut` to the app's own field. A |
| 64 | //! description carrying it would be a form model. |
| 65 | //! - **What has focus.** See below. |
| 66 | //! - **A duration or a clock.** No estimate of time remaining, no autosave |
| 67 | //! interval, no animation length. |
| 68 | //! - **A colour, a size or a position.** The deferral rule. |
| 69 | //! |
| 70 | //! # Reach, focus and the focus ring |
| 71 | //! |
| 72 | //! Three terms, and no others, for what sits outside the description. |
| 73 | //! **Reach** is which things can take focus and in what order; a browser reads |
| 74 | //! it off the document, a TUI derives it from draw order, egui from its own id |
| 75 | //! stack. **Focus** is which reached thing has the keyboard right now: the |
| 76 | //! renderer's, live, never described and never round-tripped through a |
| 77 | //! description. The **focus ring** is the visible cue; the token (`focus-ring`, |
| 78 | //! derived by `makeover` from the action colour) is the one shared artifact and |
| 79 | //! the drawing is the renderer's. Retired as names for any of this: "focus |
| 80 | //! stroke", "focus cue", "wants focus". "Caret" is a different thing — the text |
| 81 | //! cursor inside a field — and keeps its name. |
| 82 | //! |
| 83 | //! # The three tones, and what a colour claims |
| 84 | //! |
| 85 | //! One rule for how colour says whether a thing can be |
| 86 | //! used. Every renderer answers to it, and it is stated here because the |
| 87 | //! description is what names the intents. |
| 88 | //! |
| 89 | //! | the thing | intent | |
| 90 | //! |-----------|--------| |
| 91 | //! | active, emphasised, the thing itself | `content` | |
| 92 | //! | inactive but usable: it still answers a press | `content-secondary` | |
| 93 | //! | inert: disabled, or not a control at all | `content-muted` | |
| 94 | //! |
| 95 | //! `content-muted` is the one with a claim in it. [`State::Disabled`] resolves |
| 96 | //! to it, so a live control wearing it is telling the user it will not answer, |
| 97 | //! and being wrong about that is worse than being quiet, because the user's |
| 98 | //! response is to stop trying. A sortable column heading that was never sorted, |
| 99 | //! and every unchosen option in a radio group, read as dead lists if they wear |
| 100 | //! it. What is legitimately muted is a caption, a hint, a placeholder, a meter's reading, an axis label: text that |
| 101 | //! was never going to answer anything. |
| 102 | //! |
| 103 | //! The three are one ramp and not three colours. `makeover`'s `Emphasis` derives |
| 104 | //! the quieter two from the ink, so "one step back" means the same distance in |
| 105 | //! every theme and a renderer cannot land between them by picking its own. |
| 106 | //! |
| 107 | //! # First paint is final paint |
| 108 | //! |
| 109 | //! Nothing may change size or position after it is |
| 110 | //! first drawn, and nothing may stand in for content that has not arrived yet. |
| 111 | //! Both halves are absolute. |
| 112 | //! |
| 113 | //! It is stated here, rather than left to each renderer, because a renderer can |
| 114 | //! only reserve space the description gave it enough to size. A member whose |
| 115 | //! size depends on its content therefore owes whatever makes it sizeable while |
| 116 | //! the content is still absent, and that is the second admission test for a new |
| 117 | //! member: not only does it compose something this crate already names, it can |
| 118 | //! be laid out before it is filled. |
| 119 | //! |
| 120 | //! The mechanism is a reservation, and [`Sort`]'s caret is the worked example. |
| 121 | //! The caret is drawn into a box its own width whether or not the column is |
| 122 | //! sorted, so pressing a heading cannot reflow the row it sits in. The box names |
| 123 | //! no magnitude, which is what keeps it out of `makeover-geometry`'s territory. |
| 124 | //! Reserve from what is known; never discover geometry from what has not |
| 125 | //! arrived. |
| 126 | //! |
| 127 | //! The trap is an `Option` that means "not yet". [`Readiness::Pending`] is the |
| 128 | //! honest way to say a region is still waiting. An optional *measurement* is |
| 129 | //! not: a count that shows up later widens the text that prints it and moves |
| 130 | //! everything beside it, which is the reflow this rule exists to forbid. So an |
| 131 | //! `Option` on a measurement means the host will never know it — a property of |
| 132 | //! the query, fixed for the life of the screen — and a renderer sizes for the |
| 133 | //! answer it was handed rather than for the one it hopes is coming. |
| 134 | //! |
| 135 | //! # Any width, one answer |
| 136 | //! |
| 137 | //! The sibling of the rule above. That one is |
| 138 | //! independence from *when*; this one is independence from *how you got here*. |
| 139 | //! |
| 140 | //! A rendering is a pure function of the description and the viewport. The same |
| 141 | //! description at the same width is the same output, whatever widths came |
| 142 | //! before it. No renderer may carry geometry across frames, and none may narrow |
| 143 | //! by counting. |
| 144 | //! |
| 145 | //! The failure this forbids is ordinary enough to be the default everywhere |
| 146 | //! else: a page that hides its sidebar below some width, remembers that it hid |
| 147 | //! it, and does not bring it back the same way. Layout there is a function of |
| 148 | //! `(width, history)`, so dragging a window to 900 wide is a different screen |
| 149 | //! depending on whether you came from 1400 or from 600. Nobody chose that; it |
| 150 | //! is what measuring and remembering produce. |
| 151 | //! |
| 152 | //! The mechanism is [`Width`] for what grows and [`Priority`] for what drops. |
| 153 | //! Both are declared, both are read off the description, and neither needs a |
| 154 | //! measurement. A renderer narrows by raising a cutoff over a total order, |
| 155 | //! never by counting what fits and stopping — `makeover-tui`'s table states |
| 156 | //! that as its own rule and tests it, and `makeover-webview` reaches the same |
| 157 | //! place with `@media` and `display: none`, which is path-independent by |
| 158 | //! construction because CSS has nowhere to keep the previous width. |
| 159 | //! |
| 160 | //! Two things follow for anything new. A member that would need last frame's |
| 161 | //! size to lay out this frame is refused, the same way a member that cannot be |
| 162 | //! sized before it is filled is refused. And a fact about what disappears |
| 163 | //! belongs in the description, because a host that has to infer it can only |
| 164 | //! infer it from a measurement. |
| 165 | //! |
| 166 | //! # Where the description stops |
| 167 | //! |
| 168 | //! A member is added when an app needs a fact the vocabulary cannot state, and |
| 169 | //! refused when what it wants is presentation it should be asking a renderer |
| 170 | //! for. It is not a quota, and the goal is every screen described. |
| 171 | //! |
| 172 | //! A timeline is describable. What it needs and could not previously get is two |
| 173 | //! integers, where a thing starts and how long it lasts, which is [`Track`]. |
| 174 | //! Slot heights, gridline colour, how overlapping things stack and which hour |
| 175 | //! scrolls into view stay the renderer's, and `Track` carries none of them. |
| 176 | //! |
| 177 | //! A kanban board is describable, and the member is [`Region::Columns`]. Every |
| 178 | //! card fact is already sayable through `Row`'s parts; what nothing else could |
| 179 | //! say is that the columns are *peers*, since [`Arrangement`] offers only |
| 180 | //! list-detail and sidebar-content and a board described as either is a lie |
| 181 | //! about the screen. Dragging a card between columns does not enter into it: a |
| 182 | //! drop's effect is "set status", a discrete action `Row`'s menu already |
| 183 | //! carries, and the drag itself is affordance. |
| 184 | //! |
| 185 | //! A calendar takes no members. The month grid's primacy in calendar apps is an |
| 186 | //! artifact of paper: paper cannot be queried, so it has to show every day at |
| 187 | //! once as a fallback index, and routes, search and ranking do that job better. |
| 188 | //! Three jobs survive that reasoning, and only one of them needs a grid: |
| 189 | //! |
| 190 | //! 1. **Spans across days**, a stretch of leave, a trip, a sprint. You cannot |
| 191 | //! see "away the 3rd to the 17th" in a list without diffing dates. This is |
| 192 | //! [`Track`] with [`Unit::Days`], and [`Track::days`] is it. |
| 193 | //! 2. **Density at a glance**, which weeks were heavy. That is a heatmap, and a |
| 194 | //! heatmap describes as a list. |
| 195 | //! 3. **Weekday periodicity**, "every other Tuesday", "the 15th is a Saturday". |
| 196 | //! This is the only job that needs the seven-column wrap, because alignment |
| 197 | //! is the whole of what makes it visible. |
| 198 | //! |
| 199 | //! Job 3 is the only open question, and nothing in the tree asks for it. A |
| 200 | //! month grid otherwise renders as a [`Table`](crate::Column): seven weekday |
| 201 | //! columns, weeks as rows, blanks for the offset. If a screen wants one, |
| 202 | //! measure the members it needs before adding any. |
| 203 | //! |
| 204 | //! [`Region::Bespoke`] remains for the genuinely app-owned. The description |
| 205 | //! names the *place* and the app owns the contents, so a screen containing a |
| 206 | //! timeline is still a whole screen and still routable. Without it, the screens |
| 207 | //! that make an app worth using would need a second, undescribed path beside |
| 208 | //! the router, and two paths is how a vocabulary drifts from its app. |
| 209 | //! |
| 210 | //! [`Region::Widget`] sits between that limit and the primitives, and it does |
| 211 | //! not move the limit. A widget is an assembly of members this crate *already* |
| 212 | //! has, under a name a renderer may or may not recognise. Anything that needs a |
| 213 | //! member the vocabulary does not have is still a finding about the vocabulary |
| 214 | //! or still bespoke; naming an assembly buys no new expressive power, which is |
| 215 | //! why it is safe to let the set grow outside this crate. |
| 216 | |
| 217 | |
| 218 | |
| 219 | /// A colour intent this crate refers to but never resolves. |
| 220 | /// |
| 221 | /// The string is the token name `makeover` publishes, so a renderer can look |
| 222 | /// it up without this crate knowing what colour came back. |
| 223 | |
| 224 | /// The `makeover` intent token this resolves against. |
| 225 | ; |
| 226 | |
| 227 | |
| 228 | /// Which way the light falls across a two-tone edge. |
| 229 | /// |
| 230 | /// The whole content of a bevel, once colour and thickness are deferred. The |
| 231 | /// light is always assumed to come from the top left: every consumer measured |
| 232 | /// agreed on that and none of them ever varied it, so it is an invariant here |
| 233 | /// rather than a parameter. |
| 234 | /// |
| 235 | /// # The two corners that belong to both edges |
| 236 | /// |
| 237 | /// Top-right and bottom-left are where the lit run meets the shaded one, and |
| 238 | /// the description's claim is that they belong to *both*. How a renderer says |
| 239 | /// that is its own business, because the answer is bounded by resolution and |
| 240 | /// not by taste: |
| 241 | /// |
| 242 | /// - A terminal cell is roughly 8x17 device pixels, so giving the whole corner |
| 243 | /// to one tone thickens that edge by a cell and reads as one run overrunning |
| 244 | /// the other. A half-cell glyph divides the cell already, so `makeover-tui` |
| 245 | /// splits it and recovers real information. Its box-drawing fallback cannot: |
| 246 | /// a single stroke has no half to give, so there both corners go to dark. |
| 247 | /// - A pixel bevel is a one-point stroke by default, which makes the corner a |
| 248 | /// one-point square. There is nothing to divide — a diagonal seam across one |
| 249 | /// point is sub-pixel, and antialiasing renders it as the blend a mitred join |
| 250 | /// already produces. So `makeover-immediate` mitres and is *not* diverging; |
| 251 | /// it is the same rule at a resolution where the split degenerates. |
| 252 | /// |
| 253 | /// Stated here so the difference reads as a decision rather than as drift. A |
| 254 | /// renderer with room to divide the corner should; one without should mitre or |
| 255 | /// pick the shaded tone, and neither is a bug. |
| 256 | |
| 257 | |
| 258 | /// Lit from the top left: light on top and left, dark on bottom and right. |
| 259 | Raised, |
| 260 | /// The same edge inverted, which is also the pressed state of anything |
| 261 | /// that draws itself [`Bevel::Raised`]. |
| 262 | Inset, |
| 263 | |
| 264 | |
| 265 | |
| 266 | /// The edge intents, as `(top_left, bottom_right)`. |
| 267 | /// |
| 268 | /// Split out from any painting because the inversion *is* the idea, and |
| 269 | /// it is the one part every renderer implements identically. |
| 270 | |
| 271 | pub const |
| 272 | match self |
| 273 | SelfRaised => , |
| 274 | SelfInset => , |
| 275 | |
| 276 | |
| 277 | |
| 278 | /// Pressing inverts. A raised control reads as inset while held. |
| 279 | /// |
| 280 | /// Stated here rather than left to each consumer because a cascade can |
| 281 | /// carry a pressed state and an immediate-mode renderer cannot: audiofiles |
| 282 | /// resolves this per call site, eighteen times. |
| 283 | |
| 284 | pub const |
| 285 | match self |
| 286 | SelfRaised => SelfInset, |
| 287 | SelfInset => SelfRaised, |
| 288 | |
| 289 | |
| 290 | |
| 291 | |
| 292 | /// One side of a bevel, named by the intent it takes. |
| 293 | |
| 294 | |
| 295 | /// The lit side. |
| 296 | Light, |
| 297 | /// The shadowed side. |
| 298 | Dark, |
| 299 | |
| 300 | |
| 301 | |
| 302 | |
| 303 | match self |
| 304 | SelfLight => "bevel-light", |
| 305 | SelfDark => "bevel-dark", |
| 306 | |
| 307 | |
| 308 | |
| 309 | |
| 310 | /// A surface intent a region is filled with. |
| 311 | /// |
| 312 | /// `#[non_exhaustive]`, so a renderer must carry a wildcard arm and a new |
| 313 | /// member is additive rather than breaking. The vocabulary exists to grow and |
| 314 | /// the renderers exist to disagree about how much of it they answer, so growth |
| 315 | /// must not be a lockstep event. The renderer's wildcard is not a hole: |
| 316 | /// [`Fill`] is resolved through a fallible lookup, and a missing intent is |
| 317 | /// answered with structure rather than with a substituted colour. |
| 318 | /// |
| 319 | /// [`Sunken`]: Fill::Sunken |
| 320 | |
| 321 | |
| 322 | |
| 323 | /// The page behind everything. |
| 324 | Page, |
| 325 | /// A surface lifted off the page: cards, controls, menus, toasts. |
| 326 | Raised, |
| 327 | /// A surface floating above the page rather than resting on it. |
| 328 | Overlay, |
| 329 | /// The inside of a well. |
| 330 | Well, |
| 331 | /// A surface set back from the one it sits on, by colour and nothing else. |
| 332 | /// |
| 333 | /// Not a well. A well is a hole with an edge, and the two are authored in |
| 334 | /// opposite directions: `makeover` derives `surface-well` by inverting |
| 335 | /// against the theme's own content colour, while `surface-sunken` is |
| 336 | /// authored and free to sit darker than raised (goingson's does). Naming |
| 337 | /// only the well left the recessed-with-no-edge surface unsayable, which is |
| 338 | /// what an unchosen tab is: it recedes so the chosen one can come forward, |
| 339 | /// and it carries no bevel of its own. |
| 340 | Sunken, |
| 341 | |
| 342 | |
| 343 | // No `fallback` here, deliberately. An earlier cut had `Fill::Well` fall back |
| 344 | // to `Fill::Page` so a consumer on makeover 2.2.0, which has no `surface-well`, |
| 345 | // had something to paint. makeover-tui found that wrong within a day: page is |
| 346 | // the surface a well is usually cut into, so on a terminal that substitution |
| 347 | // produces exactly the invisibility it was meant to prevent, and the right |
| 348 | // answer there is a drawn edge rather than a different colour. |
| 349 | // |
| 350 | // Substituting one intent for another is renderer policy. The description says |
| 351 | // what the region is and stops. |
| 352 | |
| 353 | |
| 354 | |
| 355 | match self |
| 356 | SelfPage => "surface-page", |
| 357 | SelfRaised => "surface-raised", |
| 358 | SelfOverlay => "surface-overlay", |
| 359 | SelfWell => "surface-well", |
| 360 | SelfSunken => "surface-sunken", |
| 361 | |
| 362 | |
| 363 | |
| 364 | |
| 365 | /// How a region sits relative to the surface behind it. |
| 366 | /// |
| 367 | /// Fill and bevel are named together because naming them apart is what let |
| 368 | /// them disagree. Every consumer measured had at least one region carrying a |
| 369 | /// raised bevel over a recessed fill: audiofiles fixed it in `raised_frame` |
| 370 | /// and recorded the bug in its doc comment, and Balanced Breakfast still had |
| 371 | /// twelve of them a year later. A single name for the pair makes that |
| 372 | /// unrepresentable. |
| 373 | /// `#[non_exhaustive]` for the same reason as [`Fill`], and in the same |
| 374 | /// release: a depth this renderer has no drawing for should cost it a |
| 375 | /// wildcard arm, not a compile error and a wait on someone else's publish. |
| 376 | |
| 377 | |
| 378 | |
| 379 | /// Level with its surroundings. No edge. |
| 380 | Flat, |
| 381 | /// A card laid on the panel it sits in. |
| 382 | Raised, |
| 383 | /// A hole in the panel, with content down inside it. For anything the |
| 384 | /// user looks *into*: a table body, a tag tree, a text field. |
| 385 | Well, |
| 386 | /// Set back from what it sits on, by colour alone. No edge. |
| 387 | /// |
| 388 | /// The one member carrying a fill without a bevel, so a renderer cannot |
| 389 | /// assume the two arrive together. That is deliberate and it is still the |
| 390 | /// pairing rule: both halves come off the same `Depth`, so they cannot |
| 391 | /// disagree, and here one half is legitimately absent. |
| 392 | /// |
| 393 | /// Distinct from [`Depth::Flat`], which has no fill either and inherits. |
| 394 | /// Recessed and level-with are different claims, and only one of them |
| 395 | /// needs a colour. |
| 396 | Sunken, |
| 397 | /// A surface sitting *over* the page rather than in it. A modal, a popover, |
| 398 | /// a menu. |
| 399 | /// |
| 400 | /// Takes elevation and no bevel: a surface overlaying the page is lifted |
| 401 | /// off it, and a surface in the page is cut into it. That is the same |
| 402 | /// pairing rule the rest of the enum holds, applied to the one case where |
| 403 | /// the separation is not an edge at all — the lift and the scrim behind it |
| 404 | /// are already saying where the surface is. |
| 405 | /// |
| 406 | /// Every renderer already has the surface: `makeover-tui` carries |
| 407 | /// `Palette::overlay`, `makeover-immediate` `Palette::elevation`, and |
| 408 | /// `makeover-webview` emits `--elevation-overlay`. This variant is the |
| 409 | /// route from a description to any of them, which is why it is one variant |
| 410 | /// rather than a feature. |
| 411 | Overlay, |
| 412 | |
| 413 | |
| 414 | |
| 415 | /// The edge this depth is drawn with, if it has one. |
| 416 | |
| 417 | pub const |
| 418 | match self |
| 419 | // Sunken joins Flat here, for the opposite reason: Flat has no edge |
| 420 | // because nothing separates it from its surroundings, and Sunken has |
| 421 | // none because its colour is already doing the separating. |
| 422 | SelfFlat | SelfSunken => None, |
| 423 | // A third reason to have no edge, which is why it gets its own arm |
| 424 | // rather than joining the two above: an overlay is separated by the |
| 425 | // lift and by the scrim behind it, so an edge would be a second |
| 426 | // answer to a question already answered. |
| 427 | SelfOverlay => None, |
| 428 | SelfRaised => Some, |
| 429 | SelfWell => Some, |
| 430 | |
| 431 | |
| 432 | |
| 433 | /// The surface this depth is filled with. |
| 434 | /// |
| 435 | /// [`Depth::Flat`] has no fill of its own: it inherits whatever it sits on, |
| 436 | /// which is the difference between level-with and painted-the-same-colour. |
| 437 | |
| 438 | pub const |
| 439 | match self |
| 440 | SelfFlat => None, |
| 441 | SelfRaised => Some, |
| 442 | SelfWell => Some, |
| 443 | SelfSunken => Some, |
| 444 | SelfOverlay => Some, |
| 445 | |
| 446 | |
| 447 | |
| 448 | /// Pressing a raised region reads as a well, and nothing else moves. |
| 449 | /// |
| 450 | /// [`Depth::Overlay`] is untouched along with the rest: an overlay is a |
| 451 | /// surface, not a control, so there is nothing there to press. |
| 452 | |
| 453 | pub const |
| 454 | match self |
| 455 | SelfRaised => SelfWell, |
| 456 | other => other, |
| 457 | |
| 458 | |
| 459 | |
| 460 | |
| 461 | /// An interaction state a region can be in, beside whatever [`Depth`] it is. |
| 462 | /// |
| 463 | /// Orthogonal to depth on purpose. A disabled button is still [`Depth::Raised`] |
| 464 | /// and a disabled field is still a [`Depth::Well`], so folding either member |
| 465 | /// into `Depth` would make [`Depth::bevel`] and [`Depth::fill`] answer for |
| 466 | /// something that is not a depth, and would leave disabled-button and |
| 467 | /// disabled-field sharing one variant that cannot tell them apart. |
| 468 | /// |
| 469 | /// # Why hover and pressed are not members |
| 470 | /// |
| 471 | /// The line is whether every renderer has the state to express, not whether CSS |
| 472 | /// does. Hover is renderer policy and `makeover-webview` says so in its own |
| 473 | /// header: a terminal and an immediate-mode painter have no pointer hovering |
| 474 | /// over anything, and pressed already arrives through [`Bevel::pressed`] and |
| 475 | /// [`Depth::pressed`], where it belongs, because pressing is a depth inversion |
| 476 | /// rather than a separate condition. |
| 477 | /// |
| 478 | /// Focus and disabled are different in kind. A TUI has a focused widget and a |
| 479 | /// greyed-out one; so does egui. Both were unsayable here, so all three webview |
| 480 | /// consumers supplied them from outside the primitive by out-specifying rules |
| 481 | /// they did not own: goingson alone carries 19 of them, and the MNW server |
| 482 | /// another 21. That is the divergence this crate exists to end, arriving one |
| 483 | /// layer down. |
| 484 | /// |
| 485 | /// # The principle this encodes |
| 486 | /// |
| 487 | /// A primitive owns every state it implies. A renderer that emits a hover rule |
| 488 | /// for a thing owes disabled and the capability answer for that same thing, |
| 489 | /// because anything less exports the completion work to N consumers who will |
| 490 | /// each do it differently. |
| 491 | /// |
| 492 | /// Focus is not on that list and is not on this axis. It is the renderer's, |
| 493 | /// decided after the description; see the crate header, "Reach, |
| 494 | /// focus and the focus ring", for the three terms and who owns each. |
| 495 | /// |
| 496 | /// `#[non_exhaustive]` for the reason [`Fill`] and [`Depth`] carry it: growth |
| 497 | /// must not be a lockstep event across the three renderers. |
| 498 | |
| 499 | |
| 500 | |
| 501 | /// Present, visible, and not answering. |
| 502 | /// |
| 503 | /// Not the same as absent, and deliberately not a [`Fill`]: a disabled |
| 504 | /// control keeps the surface it always had and stops responding, so what |
| 505 | /// changes is its content and its interactivity rather than what it is. |
| 506 | Disabled, |
| 507 | |
| 508 | |
| 509 | |
| 510 | /// Whether a region in this state stops answering the pointer. |
| 511 | /// |
| 512 | /// Stated in the description rather than left to each renderer, on the same |
| 513 | /// reasoning as [`Bevel::pressed`]: a cascade carries it for free and an |
| 514 | /// immediate-mode renderer resolves it per call site, so leaving it unsaid |
| 515 | /// means resolving it once per consumer and disagreeing. |
| 516 | |
| 517 | pub const |
| 518 | // A match rather than a bare `true`, so a member added to this |
| 519 | // `#[non_exhaustive]` axis has to answer the question rather than |
| 520 | // inheriting an answer. |
| 521 | match self |
| 522 | SelfDisabled => true, |
| 523 | |
| 524 | |
| 525 | |
| 526 | |
| 527 | |
| 528 | |
| 529 | match self |
| 530 | // Reusing the muted content intent rather than minting a |
| 531 | // `disabled` colour. Disabled is a reduction and not a status, and |
| 532 | // `makeover-webview`'s progress rules already record the reading |
| 533 | // that `content-muted` is what disabled looks like. |
| 534 | SelfDisabled => "content-muted", |
| 535 | |
| 536 | |
| 537 | |
| 538 | |
| 539 | /// What a region is saying, when it is saying something. |
| 540 | /// |
| 541 | /// The one intent family shared by badges, notices and nothing else. Kept |
| 542 | /// separate from [`Fill`] because a surface is where a thing sits and a tone is |
| 543 | /// what it means, and the three apps agree on the four statuses: |
| 544 | /// `info_banner` / `warning_banner` in audiofiles, `.toast-info` / |
| 545 | /// `.toast-success` / `.toast-error` in goingson, `.toast.success` / |
| 546 | /// `.toast.error` in Balanced Breakfast. |
| 547 | /// |
| 548 | /// The per-tag palette (`category-one` through `category-six`) is deliberately |
| 549 | /// not here. Which colour a *particular* tag takes is app domain, and both |
| 550 | /// webview apps already carry it as a `data-color` attribute. |
| 551 | |
| 552 | |
| 553 | /// No status. |
| 554 | /// |
| 555 | /// Ordinary content, at full weight. It does not also mean muted: a |
| 556 | /// badge reads quiet because [`Token::Badge`] answers no click, which is |
| 557 | /// the renderer's knowledge and not this axis's. A renderer wanting a |
| 558 | /// muted badge reaches for [`Token::interactive`] itself rather than |
| 559 | /// expecting `Neutral` to have muted it. |
| 560 | Neutral, |
| 561 | /// Something worth knowing and nothing to do about it. |
| 562 | Info, |
| 563 | /// Something finished and it worked. |
| 564 | Success, |
| 565 | /// Something the user should look at before continuing. |
| 566 | Warning, |
| 567 | /// Something broken, or something about to be destroyed. |
| 568 | Danger, |
| 569 | |
| 570 | |
| 571 | |
| 572 | |
| 573 | match self |
| 574 | // Neutral has no status token of its own, so it takes the plain |
| 575 | // content intent. It used to answer `content-muted`, which read |
| 576 | // "no status" as "de-emphasised" and muted every figure value in |
| 577 | // the webview. Muting is a renderer's call about a particular |
| 578 | // token, not something the status axis knows. |
| 579 | SelfNeutral => "content", |
| 580 | SelfInfo => "info", |
| 581 | SelfSuccess => "success", |
| 582 | SelfWarning => "warning", |
| 583 | SelfDanger => "danger", |
| 584 | |
| 585 | |
| 586 | |
| 587 | |
| 588 | /// A small labelled thing that sits inside something else. |
| 589 | /// |
| 590 | /// Two members, because the three apps drew three taxonomies and only one line |
| 591 | /// runs through all of them: does it answer a click. audiofiles has |
| 592 | /// `classification_badge` (a label) against `tag_chip`, `tag_chip_removable` |
| 593 | /// and `selectable_tag` (all of which do). Balanced Breakfast has `.tag` and |
| 594 | /// `.badge` against `.tag-chip`. goingson is the one that has to move: its |
| 595 | /// `.tag` and `.badge` are a single CSS rule, so every call site has to be read |
| 596 | /// to decide which of the two it always was. |
| 597 | /// |
| 598 | /// The evidence that a chip is a real concept rather than a badge with a |
| 599 | /// cursor: audiofiles inverts its bevel on press and Balanced Breakfast latches |
| 600 | /// `.tag-chip.active` with the inset bevel. Two independent arrivals at "a chip |
| 601 | /// holds itself down", which is exactly what [`Depth::pressed`] already says. |
| 602 | |
| 603 | |
| 604 | /// Non-interactive status or count. Answers no click. |
| 605 | Badge, |
| 606 | /// An interactive or removable token. Answers a click, and latches if it |
| 607 | /// stands for a filter that is either on or off. |
| 608 | Chip |
| 609 | /// Whether it carries its own remove affordance. |
| 610 | removable: bool, |
| 611 | , |
| 612 | |
| 613 | |
| 614 | |
| 615 | /// Whether this answers a click. |
| 616 | /// |
| 617 | /// The whole difference between the two members, and the reason a renderer |
| 618 | /// with no hover (a touch surface, a terminal) can still tell them apart. |
| 619 | |
| 620 | pub const |
| 621 | matches! |
| 622 | |
| 623 | |
| 624 | /// How it sits, given whether it is currently latched down. |
| 625 | /// |
| 626 | /// A badge is flat: it is a label, and giving it an edge would say it can |
| 627 | /// be pressed. A chip is raised, and inset while latched. |
| 628 | |
| 629 | pub const |
| 630 | match self |
| 631 | SelfBadge => Flat, |
| 632 | SelfChip if latched => Well, |
| 633 | SelfChip => Raised, |
| 634 | |
| 635 | |
| 636 | |
| 637 | |
| 638 | /// Something the app is telling the user, unprompted. |
| 639 | /// |
| 640 | /// Two concepts, not one with a placement. They differ in more than where they |
| 641 | /// sit: a toast is transient, stacked and self-dismissing, and a banner is |
| 642 | /// persistent, in flow, one per region, and dismissed by fixing the condition |
| 643 | /// it reports. Folding them into one member with a placement parameter would |
| 644 | /// make lifetime, stacking and dismissal all placement-dependent, which is the |
| 645 | /// description leaking renderer policy. |
| 646 | /// |
| 647 | /// All three apps have banners: `info_banner` and `warning_banner` in |
| 648 | /// audiofiles, five of them in goingson (sync, sync-result, vacation-day, |
| 649 | /// timer-active, past-review), `.update-banner` in Balanced Breakfast. The two |
| 650 | /// webview apps also have toasts. So neither member is speculative, and no app |
| 651 | /// gains a concept it lacks except audiofiles, whose renderer may legitimately |
| 652 | /// decline to draw a toast at all. |
| 653 | |
| 654 | |
| 655 | /// Transient, stacked, dismisses itself. |
| 656 | Toast, |
| 657 | /// Persistent, in flow, one per region, dismissed by fixing the cause. |
| 658 | Banner, |
| 659 | |
| 660 | |
| 661 | |
| 662 | /// Whether it goes away on its own. |
| 663 | |
| 664 | pub const |
| 665 | matches! |
| 666 | |
| 667 | |
| 668 | /// How it sits. |
| 669 | /// |
| 670 | /// A toast floats above the page rather than resting on it, which is |
| 671 | /// [`Fill::Overlay`]'s whole reason to exist. A banner is a card in the |
| 672 | /// flow. Both are raised, and they are raised off different things. |
| 673 | |
| 674 | pub const |
| 675 | match self |
| 676 | SelfToast => Overlay, |
| 677 | SelfBanner => Raised, |
| 678 | |
| 679 | |
| 680 | |
| 681 | |
| 682 | /// The parts of a list row. |
| 683 | /// |
| 684 | /// `#[non_exhaustive]`: a renderer carries a wildcard arm, so a new part is not |
| 685 | /// a lockstep event across three renderers. |
| 686 | /// |
| 687 | /// # Meta against Tokens |
| 688 | /// |
| 689 | /// The line is whether the thing has its own standing. `Meta` is one short |
| 690 | /// trailing fact about the row, written as text: a count, a size, a date. |
| 691 | /// `Tokens` is a set of small labelled things, each of which can be toned and |
| 692 | /// can answer a click. "3 files" is meta. A status badge that is amber, and a |
| 693 | /// tag you can click to filter by, are tokens. |
| 694 | /// |
| 695 | /// Keeping them apart is what a single widened slot would have foreclosed. A |
| 696 | /// renderer can right-align one string and cannot usefully do the same to a |
| 697 | /// strip of chips, and a fact that is not clickable should not be drawn as |
| 698 | /// though it were. |
| 699 | /// How much vertical room a part's text may take. |
| 700 | /// |
| 701 | /// A row is an inline run and every part in it is a leaf, so a part's text has |
| 702 | /// always been drawn on one line and no description could say otherwise. Two |
| 703 | /// apps say otherwise in their own stylesheets, both to the same number and |
| 704 | /// both with a comment explaining it: Balanced Breakfast clamps a feed row's |
| 705 | /// title to two lines (`.row--article .row-primary`, whose comment reads |
| 706 | /// "overrides .row-primary's single flex line"), and goingson clamps a |
| 707 | /// problem's body to two ("two lines is enough to recognize one, and the full |
| 708 | /// text is in the task once promoted"). |
| 709 | /// |
| 710 | /// Two named tiers rather than a line count, and the count is what the measured |
| 711 | /// demand argues against. Both sites want exactly one tier past the default, |
| 712 | /// and a number invites a row whose primary is a paragraph, which is a block |
| 713 | /// and has no business in a run. A third tier is a decision, made here, rather |
| 714 | /// than something a call site can reach for. |
| 715 | /// |
| 716 | /// What a renderer owes it: `Tight` is what a run already does and needs no |
| 717 | /// answer. `Relaxed` is at most two lines and then truncation, however that |
| 718 | /// renderer truncates -- a webview clamps, a terminal wraps into two rows of |
| 719 | /// cells, an immediate-mode renderer caps the galley. A renderer that cannot |
| 720 | /// give two lines may draw one; what it may not do is grow without bound, |
| 721 | /// because the run is a line and the row's neighbours are relying on that. |
| 722 | |
| 723 | |
| 724 | |
| 725 | /// One line. What every part did before this type existed. |
| 726 | |
| 727 | Tight, |
| 728 | /// Up to two lines, then truncated. |
| 729 | Relaxed, |
| 730 | |
| 731 | |
| 732 | |
| 733 | /// How many lines the part may take. |
| 734 | /// |
| 735 | /// A number here rather than in the enum, because a renderer needs one and |
| 736 | /// a call site does not. That asymmetry is the whole argument for the |
| 737 | /// tiers: the description says how much room the thing deserves and this |
| 738 | /// says what that costs, so a third tier changes one line rather than every |
| 739 | /// consumer's arithmetic. |
| 740 | |
| 741 | pub const |
| 742 | match self |
| 743 | SelfRelaxed => 2, |
| 744 | // Including any tier added later: one line is the safe reading of |
| 745 | // an unknown flow, since it is what the run guaranteed before flows |
| 746 | // existed. |
| 747 | _ => 1, |
| 748 | |
| 749 | |
| 750 | |
| 751 | |
| 752 | /// How deep a row sits inside a set: a tree, an outline, a threaded list. |
| 753 | /// |
| 754 | /// [`RowPart`] below already names what is *in* a row; nothing named where a |
| 755 | /// row sits relative to its siblings, so every consumer that had a hierarchy |
| 756 | /// carried a bare number and every renderer decided for itself what one was |
| 757 | /// worth. |
| 758 | /// |
| 759 | /// # Not `Depth`, and the collision is the reason |
| 760 | /// |
| 761 | /// [`Depth`] is taken and means something else entirely: surface bevel -- |
| 762 | /// `Flat`, `Raised`, `Well`, `Sunken`, `Overlay` -- a fact about a surface |
| 763 | /// rather than a position in a hierarchy. Two meanings under one word in one |
| 764 | /// crate is the collision that costs a reader an hour, and the word this |
| 765 | /// concept wants is the one that would cause it. |
| 766 | /// |
| 767 | /// # The magnitude is the renderer's, and that is the precedent |
| 768 | /// |
| 769 | /// [`Awaiting`] is the shape: this crate names the fact and declines to name |
| 770 | /// what it is worth. makeover-webview writes the rule as a custom property with |
| 771 | /// a fallback -- the way it writes `margin-inline-start: var(--awaiting-gap, |
| 772 | /// 0.5ch)` -- so a level has one answer per renderer and an app can override |
| 773 | /// it. A terminal spends columns, a browser spends inline space, and neither |
| 774 | /// number belongs in a description. |
| 775 | /// |
| 776 | /// # Zero is a real answer |
| 777 | /// |
| 778 | /// [`top`](Self::top) is the default and is what a flat list says: every row is |
| 779 | /// at the top level, which is true and is the reading a renderer needs. An |
| 780 | /// `Option` here would make "not nested" and "nested at zero" two spellings of |
| 781 | /// one thing, the same argument `Discovery`'s `indexable` makes about defaults |
| 782 | /// that are meaningful. |
| 783 | |
| 784 | |
| 785 | |
| 786 | /// How many levels in, counting from zero. |
| 787 | /// |
| 788 | /// `u8` because a hierarchy a reader can follow is not 256 deep, and a |
| 789 | /// renderer indenting by a level has to multiply it by something -- a wider |
| 790 | /// integer here is a wider integer in every renderer's arithmetic for a |
| 791 | /// range nothing will use. |
| 792 | pub level: u8, |
| 793 | |
| 794 | |
| 795 | |
| 796 | /// The top level: not nested. The default, and what a flat list says. |
| 797 | |
| 798 | pub const |
| 799 | Self |
| 800 | |
| 801 | |
| 802 | /// A row this many levels in. |
| 803 | |
| 804 | pub const |
| 805 | Self |
| 806 | |
| 807 | |
| 808 | /// Whether this row sits under another. |
| 809 | /// |
| 810 | /// The question every renderer asks before it spends anything on indenting, |
| 811 | /// answered once here rather than by a `> 0` in each -- which is |
| 812 | /// [`Awaiting::is_determinate`]'s reason too. |
| 813 | |
| 814 | pub const |
| 815 | self.level > 0 |
| 816 | |
| 817 | |
| 818 | |
| 819 | |
| 820 | |
| 821 | |
| 822 | /// The thing itself. What the row is called. |
| 823 | Primary, |
| 824 | /// Supporting text under the primary. |
| 825 | Secondary, |
| 826 | /// A short trailing fact: a count, a size, a date. |
| 827 | Meta, |
| 828 | /// Controls that act on this row. |
| 829 | Actions, |
| 830 | /// Small labelled things belonging to the row: badges, chips, tags. |
| 831 | /// |
| 832 | /// Each carries its own [`Token`] kind and [`Tone`], so a renderer with no |
| 833 | /// colour still has the kind to work with, and one with no chips still has |
| 834 | /// the label. That is the constrained-consumer test this vocabulary exists |
| 835 | /// to pass, and it is why the tone lives on the token rather than on the |
| 836 | /// part. |
| 837 | Tokens, |
| 838 | /// How much of a set the row's thing has done: a [`Meter`] in the row. |
| 839 | /// |
| 840 | /// A row holds no nodes, by the rule that a row part may not carry an |
| 841 | /// arbitrary node, which is the door through which a description becomes a |
| 842 | /// templating language. So the part carries the *description of a bar* rather than a node, exactly as |
| 843 | /// `Tokens` carries tags rather than nodes. |
| 844 | /// |
| 845 | /// Without it a row flattens the proportion into [`Meta`](Self::Meta) as |
| 846 | /// "3/7 subtasks", which keeps both numbers and loses the reading, the same |
| 847 | /// way a toned status badge read as prose before `Tokens`. |
| 848 | Proportion, |
| 849 | |
| 850 | |
| 851 | |
| 852 | /// What the part is worth when the run does not fit. |
| 853 | /// |
| 854 | /// The default only. A part may say otherwise, and a renderer reads the |
| 855 | /// part rather than the role; this is what a description that has never |
| 856 | /// heard of [`Priority`] means, which is every description written before |
| 857 | /// the field existed. |
| 858 | /// |
| 859 | /// Deriving it from the role is the thing this vocabulary has otherwise |
| 860 | /// been moving away from, and it is right here for one reason: the roles |
| 861 | /// already encode this ranking and every consumer already assumes it. |
| 862 | /// [`Primary`](Self::Primary) is what the row is called, and |
| 863 | /// [`Priority::Essential`]'s own doc was written about exactly that -- |
| 864 | /// "without it the row does not identify itself". |
| 865 | /// |
| 866 | /// [`Actions`](Self::Actions) is `Essential` and it is the interesting one. |
| 867 | /// A control is not a fact, so dropping it does not cost the reader a |
| 868 | /// detail; it costs them the only way to act on the row, and in a terminal |
| 869 | /// it silently removes something focus had already been claimed for. A |
| 870 | /// renderer that needs room takes it from what the row *says*, never from |
| 871 | /// what it *offers*. |
| 872 | /// |
| 873 | /// An unknown member reads as [`Priority::Secondary`]: droppable, but not |
| 874 | /// first, since guessing `Optional` for something this crate has not been |
| 875 | /// taught would make a new member the first thing to vanish. |
| 876 | |
| 877 | pub const |
| 878 | match self |
| 879 | SelfPrimary | SelfActions => Essential, |
| 880 | SelfMeta | SelfProportion => Optional, |
| 881 | _ => Secondary, |
| 882 | |
| 883 | |
| 884 | |
| 885 | /// The content intent the part takes. |
| 886 | |
| 887 | pub const |
| 888 | match self |
| 889 | SelfPrimary => "content", |
| 890 | SelfSecondary => "content-secondary", |
| 891 | SelfMeta => "content-muted", |
| 892 | // Actions carry controls rather than text, so they inherit. |
| 893 | SelfActions => "content", |
| 894 | // So do tokens: each one carries its own tone, and a part-level |
| 895 | // intent underneath it would fight the token that sits on it. |
| 896 | SelfTokens => "content", |
| 897 | // And so does a proportion, for the same reason: the meter carries |
| 898 | // the tone, and it is about the ratio rather than about the row. |
| 899 | SelfProportion => "content", |
| 900 | |
| 901 | |
| 902 | |
| 903 | |
| 904 | /// How far down the heading tree a title sits. |
| 905 | /// |
| 906 | /// Three, and only the three that are actually headings. The bands those used |
| 907 | /// to be filed with (goingson's `.page-header`, Balanced Breakfast's `.header` |
| 908 | /// and `.detail-header`) are arrangement, not type, and live at |
| 909 | /// [`Region::Band`]. One of them contains no text at all. |
| 910 | |
| 911 | |
| 912 | /// Names the whole screen. One per screen. |
| 913 | Page, |
| 914 | /// Names a block within the screen. |
| 915 | Section, |
| 916 | /// Names a sub-block inside an already-named section. |
| 917 | Subsection, |
| 918 | |
| 919 | |
| 920 | |
| 921 | /// Whether a rule follows the heading. |
| 922 | /// |
| 923 | /// audiofiles' `section_header` draws a separator and its |
| 924 | /// `subsection_label` deliberately does not, which is the only thing |
| 925 | /// distinguishing the two once weight and colour are deferred. |
| 926 | |
| 927 | pub const |
| 928 | matches! |
| 929 | |
| 930 | |
| 931 | |
| 932 | /// A control that picks between things. |
| 933 | /// |
| 934 | /// Three, because three distinct behaviours are in play and collapsing any two |
| 935 | /// loses something. A segmented control picks a value; a tab picks a pane; a |
| 936 | /// toggle picks nothing and simply holds itself on or off. |
| 937 | |
| 938 | |
| 939 | /// Exactly one of N, and the options abut. |
| 940 | Segmented, |
| 941 | /// Independent on or off, on its own. |
| 942 | Toggle, |
| 943 | /// Navigation between panes. The folder semantic. |
| 944 | Tabs, |
| 945 | |
| 946 | |
| 947 | |
| 948 | /// How the chosen option sits. |
| 949 | /// |
| 950 | /// Held in for a segmented control and a toggle, which is the same shape |
| 951 | /// pressing produces and the whole economy of the idiom: one appearance, |
| 952 | /// two reasons to wear it. A tab is the exception, because the selected |
| 953 | /// folder tab comes *forward* to join the pane it opens. |
| 954 | |
| 955 | pub const |
| 956 | match self |
| 957 | SelfSegmented | SelfToggle => Well, |
| 958 | SelfTabs => Raised, |
| 959 | |
| 960 | |
| 961 | |
| 962 | /// How the options that were *not* picked sit. |
| 963 | /// |
| 964 | /// Describing only [`Selector::chosen`] left the unchosen option falling |
| 965 | /// through to [`Depth::Flat`], which says it is level with the strip it |
| 966 | /// sits in, and no renderer emitted anything for it. That is wrong in both |
| 967 | /// directions and goingson proved it: its unchosen tabs are recessed by |
| 968 | /// hand, and being recessed is *why* the chosen one reads as coming |
| 969 | /// forward. Against a flat strip, a raised chosen tab is a bevel drawn on |
| 970 | /// the strip's own colour, which is a much weaker folder effect than the |
| 971 | /// contrast the idiom is named after. |
| 972 | /// |
| 973 | /// Each member is the inverse of its chosen state, which is the whole |
| 974 | /// content of "picked" once colour is deferred: |
| 975 | /// |
| 976 | /// - Tabs recede, so the chosen one comes forward. |
| 977 | /// - A segment and a toggle stand up, so the chosen one is held in. |
| 978 | |
| 979 | pub const |
| 980 | match self |
| 981 | SelfTabs => Sunken, |
| 982 | SelfSegmented | SelfToggle => Raised, |
| 983 | |
| 984 | |
| 985 | |
| 986 | /// Whether the options touch. |
| 987 | /// |
| 988 | /// The gap is the entire difference between a segmented control and a row |
| 989 | /// of buttons that happen to sit near each other, which is what audiofiles' |
| 990 | /// `segmented_control` says in its own comment and why it zeroes the |
| 991 | /// spacing by hand. |
| 992 | |
| 993 | pub const |
| 994 | matches! |
| 995 | |
| 996 | |
| 997 | |
| 998 | /// What is in a region right now. |
| 999 | /// |
| 1000 | /// The state, not the shimmer. Whether pending paints a skeleton, a spinner or |
| 1001 | /// nothing at all is renderer policy, the same class of decision that got |
| 1002 | /// `Fill::fallback` deleted from this crate. goingson and Balanced Breakfast |
| 1003 | /// each grew a skeleton with differently-named parts; both keep them, as the |
| 1004 | /// webview renderer's expression of [`Readiness::Pending`]. audiofiles has none |
| 1005 | /// and needs none, because an immediate-mode renderer simply repaints. |
| 1006 | /// |
| 1007 | /// # Four states and not two |
| 1008 | /// |
| 1009 | /// Naming only `Ready` and `Pending` leaves a screen whose list came back empty |
| 1010 | /// with nothing to say about it, so it renders an empty region or invents its |
| 1011 | /// own placeholder text and neither says what it is. Left to the apps, the |
| 1012 | /// class family drifts: `empty-state`, `empty-state--error`, `error-state` and |
| 1013 | /// six more. |
| 1014 | /// |
| 1015 | /// The four are one axis because they are mutually exclusive: a region shows its |
| 1016 | /// content, or a sign that it is coming, or a sign that there is none, or a sign |
| 1017 | /// that it broke. Never two. That is the test for one enum against several |
| 1018 | /// fields, and it is why this grew rather than a new member arriving beside it. |
| 1019 | /// |
| 1020 | /// # What is not here |
| 1021 | /// |
| 1022 | /// **The message.** "No projects yet" is content, and this names a state. It |
| 1023 | /// lives with whatever holds the region — in quasi's case a `Slot` — alongside |
| 1024 | /// the action that leads out of the emptiness, since an address is the one thing |
| 1025 | /// this crate never names. |
| 1026 | /// |
| 1027 | /// **How much room it gets.** goingson's `--compact`, `--dashboard` and |
| 1028 | /// `--padded` are the same state at three sizes, and a size is |
| 1029 | /// `makeover-geometry`'s question. Naming them here would be this crate stating |
| 1030 | /// values again. |
| 1031 | /// |
| 1032 | /// **The icon.** Presentation, and each host has its own answer or none. |
| 1033 | |
| 1034 | |
| 1035 | |
| 1036 | /// The content is here. |
| 1037 | Ready, |
| 1038 | /// The content is on its way. |
| 1039 | /// |
| 1040 | /// For a region that changes *after* the first paint, and never for the |
| 1041 | /// first paint itself: see "First paint is final paint" in the crate header. |
| 1042 | /// A host that renders once, with its data already in hand, has nothing to |
| 1043 | /// say this about, and a screen arriving in this state is describing a |
| 1044 | /// moment its host should not have been in. |
| 1045 | /// |
| 1046 | /// What stands in occupies the geometry the content will occupy. A stand-in |
| 1047 | /// sized to itself rather than to what replaces it is the reflow the rule |
| 1048 | /// forbids, arriving one repaint later. |
| 1049 | Pending, |
| 1050 | /// The content arrived and there is none of it. |
| 1051 | /// |
| 1052 | /// Not a failure. An empty list is the normal state of a new install, and a |
| 1053 | /// renderer that drew it in a danger tone would be reporting a fault where |
| 1054 | /// there is none. |
| 1055 | Empty, |
| 1056 | /// The content did not arrive. |
| 1057 | Failed, |
| 1058 | |
| 1059 | |
| 1060 | |
| 1061 | /// Whether the region draws its own content, or something standing in for |
| 1062 | /// it. |
| 1063 | /// |
| 1064 | /// The question every renderer asks first, so it is answered once here |
| 1065 | /// rather than by a `matches!` in each. A state added later is a stand-in |
| 1066 | /// until proven otherwise: falling back to drawing content that may not be |
| 1067 | /// there is the worse of the two mistakes. |
| 1068 | |
| 1069 | pub const |
| 1070 | matches! |
| 1071 | |
| 1072 | |
| 1073 | /// What the state means, for a renderer choosing a colour. |
| 1074 | /// |
| 1075 | /// Derived rather than carried, which is the opposite of [`Meter`] and |
| 1076 | /// [`Figure`], and the difference is worth stating: a proportion's meaning |
| 1077 | /// depends on what is being counted and only the app knows it, while |
| 1078 | /// "nothing here yet" and "this broke" mean the same thing in every app that |
| 1079 | /// will ever have them. |
| 1080 | |
| 1081 | pub const |
| 1082 | match self |
| 1083 | SelfFailed => Danger, |
| 1084 | _ => Neutral, |
| 1085 | |
| 1086 | |
| 1087 | |
| 1088 | |
| 1089 | /// An action is waiting on something that resolves once, in expected finite |
| 1090 | /// time. |
| 1091 | /// |
| 1092 | /// The control-side sibling of [`Readiness`]. That enum names four states for a |
| 1093 | /// region and named nothing at all for the button that is currently doing what |
| 1094 | /// it was clicked for, so the in-flight treatment is hand-written wherever it |
| 1095 | /// exists: the MNW server carries 57 in-flight indicators against 2 guards |
| 1096 | /// against a second press, which is the spinner mostly present and the guard |
| 1097 | /// mostly absent, on a codebase whose money path is a purchase button. |
| 1098 | /// |
| 1099 | /// # What is described here, and what is not |
| 1100 | /// |
| 1101 | /// The fact is that there is an outstanding thing which will complete. Not that |
| 1102 | /// the address is remote: a heavy local query waits too, and a server calling a |
| 1103 | /// payment provider is not the browser leaving the app. Not that the call is |
| 1104 | /// slow either, which is a judgement about a call rather than a property of one. |
| 1105 | /// |
| 1106 | /// Resolving **once** is the boundary, and it is what separates this from a |
| 1107 | /// screen that keeps changing. A live screen never resolves and has no name in |
| 1108 | /// this crate yet. |
| 1109 | /// |
| 1110 | /// # One mark, two renderings |
| 1111 | /// |
| 1112 | /// | what reads it | what it does | |
| 1113 | /// |---|---| |
| 1114 | /// | a control that was pressed | goes busy and refuses a second press until it resolves | |
| 1115 | /// | a region fed by it | stands in as [`Readiness::Pending`], then fills | |
| 1116 | /// |
| 1117 | /// The two were on the table separately and both were taken. Controls alone |
| 1118 | /// leaves a slow region hand-split into its own route, which is what MNW's user |
| 1119 | /// dashboard does with its payout summary; regions alone leaves the purchase |
| 1120 | /// button unguarded. |
| 1121 | /// |
| 1122 | /// # A quantity when it is measured, never a duration |
| 1123 | /// |
| 1124 | /// [`amount`](Self::amount) is stated only when it is a measured fact about the |
| 1125 | /// payload. An upload's file length, yes; a round trip to a payment provider, |
| 1126 | /// [`None`]. A duration is described nowhere, and a renderer may not manufacture |
| 1127 | /// one from the amount either: a determinate bar shows what is done over what |
| 1128 | /// there is, plus the time it has taken so far, and never a remaining time, an |
| 1129 | /// arrival time or a rate extrapolated forwards. A prediction is wrong the |
| 1130 | /// moment the transfer stalls, and being confidently wrong is worse than being |
| 1131 | /// honestly indeterminate. |
| 1132 | /// |
| 1133 | /// This is why the crate refuses to say how long an undo stays offered and |
| 1134 | /// accepts a byte count here. The refusal is about naming a decision that |
| 1135 | /// belongs to the renderer; a file's length is not a decision, nobody chose it. |
| 1136 | /// |
| 1137 | /// # Not [`Meter`] |
| 1138 | /// |
| 1139 | /// [`Meter`] is how much of a set is done, and its own docs refuse the progress |
| 1140 | /// of an operation on the grounds that a description is built once and dropped |
| 1141 | /// while an operation runs between renders. That refusal stands. This names the |
| 1142 | /// operation and its size, which is all that is known before it starts; how much |
| 1143 | /// of it has gone through is the renderer's to observe live, and nothing round |
| 1144 | /// trips through a description to say so. |
| 1145 | |
| 1146 | |
| 1147 | |
| 1148 | /// Total work to get through, when it is a measured fact about the payload. |
| 1149 | /// |
| 1150 | /// `None` when the wait has no countable size, which is the common case and |
| 1151 | /// the default. |
| 1152 | /// |
| 1153 | /// Unit-agnostic on purpose. Bytes for an upload, rows for an import; what |
| 1154 | /// is being counted is the app's business and a renderer draws a proportion |
| 1155 | /// either way. |
| 1156 | pub amount: , |
| 1157 | |
| 1158 | |
| 1159 | |
| 1160 | /// A wait with no countable size. |
| 1161 | |
| 1162 | pub const |
| 1163 | Self |
| 1164 | |
| 1165 | |
| 1166 | /// A wait whose size is known. |
| 1167 | /// |
| 1168 | /// Reach for it only with a measured figure. An estimate written in here is |
| 1169 | /// a prediction wearing a fact's clothes, and the renderer has no way to |
| 1170 | /// tell the two apart. |
| 1171 | |
| 1172 | pub const |
| 1173 | Self |
| 1174 | amount: Some, |
| 1175 | |
| 1176 | |
| 1177 | |
| 1178 | /// Whether there is a proportion to draw. |
| 1179 | /// |
| 1180 | /// The question every renderer asks first, answered once here rather than by |
| 1181 | /// a `matches!` in each. False means indeterminate, which is the honest |
| 1182 | /// drawing when nothing countable was measured. |
| 1183 | |
| 1184 | pub const |
| 1185 | self.amount.is_some |
| 1186 | |
| 1187 | |
| 1188 | |
| 1189 | /// How much of a set is done. |
| 1190 | /// |
| 1191 | /// Nine sites across the two webview apps drew a bar and nothing here named |
| 1192 | /// one, so every described screen concatenated the two numbers into its |
| 1193 | /// heading text instead: "Subtasks 3/7", "Time Tracking 45m tracked / 30m est, |
| 1194 | /// over". Every fact survives that and the reading does not, which is the same |
| 1195 | /// loss `RowPart::Tokens` closed when a toned status badge became prose. |
| 1196 | /// |
| 1197 | /// # Why a pair and not a percentage |
| 1198 | /// |
| 1199 | /// Both numbers, not the percentage the apps compute from them. The percentage |
| 1200 | /// was the obvious shape and it had already been tried: goingson's |
| 1201 | /// `Task::time_progress` divides, rounds, and then clamps to 100, which throws |
| 1202 | /// away the one case the bar exists to show — 45 minutes tracked against a |
| 1203 | /// 30-minute estimate. It carries a separate `is_over_estimate` boolean beside |
| 1204 | /// it to recover the fact the clamp dropped. A pair keeps the over-run without a |
| 1205 | /// companion flag, and [`percent`](Meter::percent) is still one call away for a |
| 1206 | /// renderer that wants it. |
| 1207 | /// |
| 1208 | /// The pair is also what the apps already have at every site. All seven |
| 1209 | /// determinate bars write the ratio into the accessible layer and never the |
| 1210 | /// percentage: `title="3/7 subtasks"`, `aria-label="3 of 7 subtasks completed"`, |
| 1211 | /// a milestone's own `3/7` span. Given 43 nothing can recover "3 of 7", so a |
| 1212 | /// percentage member would have made [`label`](Meter::label) mandatory at every |
| 1213 | /// call site, which is the concatenated text this member removes, moved one |
| 1214 | /// layer down. |
| 1215 | /// |
| 1216 | /// # What this is not |
| 1217 | /// |
| 1218 | /// The progress of an *operation*. Two of the nine sites are that — goingson's |
| 1219 | /// focus timer, Balanced Breakfast's feed fetch — and they get nothing here, on |
| 1220 | /// purpose. Both are imperative controllers over a live handle, driven by a tick |
| 1221 | /// or an event stream, and a description is built once and dropped. Holding one |
| 1222 | /// would mean growing a way to update a description between renders, which is a |
| 1223 | /// different feature. [`Readiness::Pending`] and a [`Notice::Toast`] carry the |
| 1224 | /// honest part. |
| 1225 | /// |
| 1226 | /// The two cases are distinguishable in the markup rather than by taste: every |
| 1227 | /// determinate bar in both apps carries a tone, and neither operation bar |
| 1228 | /// carries one. Two codebases drew that line the same way without coordinating. |
| 1229 | |
| 1230 | |
| 1231 | /// How much is done. May exceed [`total`](Self::total), and that is the |
| 1232 | /// case worth drawing. |
| 1233 | pub done: u32, |
| 1234 | /// How much there is to do. Zero means there is no set, not that the set is |
| 1235 | /// complete. |
| 1236 | pub total: u32, |
| 1237 | /// What the proportion means right now. |
| 1238 | /// |
| 1239 | /// Carried rather than derived, because no renderer can work it out. The |
| 1240 | /// same 90% is [`Tone::Success`] on a subtask rollup and [`Tone::Danger`] on |
| 1241 | /// a time estimate, and goingson picks between them from `is_over_estimate`, |
| 1242 | /// a fact about the data and not about the number. |
| 1243 | pub tone: Tone, |
| 1244 | /// What is being counted, if the bar says so: "subtasks", "tasks". |
| 1245 | /// |
| 1246 | /// The noun, not the ratio. A renderer builds "3 of 7 subtasks" from this |
| 1247 | /// and the two numbers; handing it the assembled string would put the |
| 1248 | /// sentence order in the description, where a terminal at one line and a |
| 1249 | /// tooltip want different ones. |
| 1250 | pub label: , |
| 1251 | |
| 1252 | |
| 1253 | |
| 1254 | /// A proportion with no tone and no label. |
| 1255 | |
| 1256 | pub const |
| 1257 | Self |
| 1258 | done, |
| 1259 | total, |
| 1260 | tone: Neutral, |
| 1261 | label: None, |
| 1262 | |
| 1263 | |
| 1264 | |
| 1265 | /// What the proportion means. |
| 1266 | |
| 1267 | pub const |
| 1268 | self.tone = tone; |
| 1269 | self |
| 1270 | |
| 1271 | |
| 1272 | /// What is being counted. |
| 1273 | |
| 1274 | pub const |
| 1275 | self.label = Some; |
| 1276 | self |
| 1277 | |
| 1278 | |
| 1279 | /// How full the bar is, 0 to 100, clamped. |
| 1280 | /// |
| 1281 | /// For drawing, which is the only thing a clamped number is good for. Ask |
| 1282 | /// [`overflowing`](Self::overflowing) before reporting it as a fact, or this |
| 1283 | /// is `time_progress`'s bug again with the clamp moved. |
| 1284 | /// |
| 1285 | /// An empty set reads as 0. Nothing is done, because there is nothing to do |
| 1286 | /// and no bar to fill; the apps guard on the count before drawing at all. |
| 1287 | |
| 1288 | pub const |
| 1289 | if self.total == 0 |
| 1290 | return 0; |
| 1291 | |
| 1292 | let scaled = / self.total as u64; |
| 1293 | if scaled > 100 else |
| 1294 | |
| 1295 | |
| 1296 | /// Whether more is done than there was to do. |
| 1297 | /// |
| 1298 | /// The fact [`percent`](Self::percent) destroys, kept reachable so a |
| 1299 | /// renderer can mark the over-run rather than drawing a full bar and |
| 1300 | /// implying it landed exactly. |
| 1301 | |
| 1302 | pub const |
| 1303 | self.done > self.total |
| 1304 | |
| 1305 | |
| 1306 | /// Whether there is a set at all. |
| 1307 | /// |
| 1308 | /// A meter over nothing is sayable on purpose, for the same reason a field |
| 1309 | /// with no options is: it is what an app with an unloaded count actually |
| 1310 | /// has, and a renderer that shows an empty bar says so on screen rather than |
| 1311 | /// dividing by zero. |
| 1312 | |
| 1313 | pub const |
| 1314 | self.total == 0 |
| 1315 | |
| 1316 | |
| 1317 | |
| 1318 | /// One figure with a caption: a number and what it counts. |
| 1319 | /// |
| 1320 | /// The dashboard shape. A large value over a small caption, several of them in |
| 1321 | /// a strip: a current streak, a completion rate, a total. Four put the value |
| 1322 | /// above the caption and one inverts it, which is drift inside the shape |
| 1323 | /// rather than a second shape. |
| 1324 | /// |
| 1325 | /// # Why the value is text |
| 1326 | /// |
| 1327 | /// "17", "84%", "12/30", "3d". A figure is whatever the app computed, already |
| 1328 | /// formatted, and the formatting is the app's because only it knows whether the |
| 1329 | /// number is a percentage, a duration or a ratio. This carries none of the |
| 1330 | /// arithmetic [`Meter`] carries, and that is the difference between them: a |
| 1331 | /// meter is a proportion a renderer draws, and a figure is a fact a renderer |
| 1332 | /// sets in type. |
| 1333 | /// |
| 1334 | /// # Tone is carried, for [`Meter`]'s reason |
| 1335 | /// |
| 1336 | /// Three of the five sites tone the figure by their own means — `red`/`blue` on |
| 1337 | /// the weekly review, a `${type}` class on the monthly one, `sync-stat-warn` on |
| 1338 | /// sync. So tone is carried at every site that needs it and derived at none, and |
| 1339 | /// no renderer can work out that a streak of zero is worth colouring. |
| 1340 | /// |
| 1341 | /// # What is not here |
| 1342 | /// |
| 1343 | /// Whether the figure answers a click. One of the five is a control — sync's |
| 1344 | /// "Not Applied: 3" opens the list — and an action is not something this crate |
| 1345 | /// can name: nothing here knows what a route is. That belongs beside the figure |
| 1346 | /// in whatever layer holds the actions, the same way a row's activation sits |
| 1347 | /// beside its parts rather than inside them. |
| 1348 | /// |
| 1349 | /// The arrangement is not here either. Several figures in a strip is a set, and |
| 1350 | /// a renderer given them one at a time cannot tell it is looking at one; the |
| 1351 | /// layer that holds the tree is where the set gets said. |
| 1352 | |
| 1353 | |
| 1354 | /// The number, formatted the way the app means it to read. |
| 1355 | pub value: &'a str, |
| 1356 | /// What it counts. The caption under the value. |
| 1357 | pub caption: &'a str, |
| 1358 | /// How the value has moved, if the app is tracking that. |
| 1359 | /// |
| 1360 | /// Text, for [`value`](Self::value)'s reason: only the app knows whether a |
| 1361 | /// move reads as `+12.5%`, `+3` or `2x`, and a renderer handed a number |
| 1362 | /// would have to guess. |
| 1363 | /// |
| 1364 | /// This is what [`tone`](Self::tone) was for and had no consumer of. The MNW |
| 1365 | /// server has four screens whose stat card is a label, a value and a delta, |
| 1366 | /// and the delta is the toned part: the figure itself is an ordinary fact |
| 1367 | /// and it is the movement that reads as good or bad. Without this the delta |
| 1368 | /// has to be folded into the caption, which loses the tone and reads as a |
| 1369 | /// longer caption rather than as a second, smaller line. |
| 1370 | pub change: , |
| 1371 | /// What the figure means right now. [`Tone::Neutral`] is an ordinary fact. |
| 1372 | /// |
| 1373 | /// Applies to [`change`](Self::change) where there is one, since that is the |
| 1374 | /// part that carries the judgement, and to the value where there is not. |
| 1375 | pub tone: Tone, |
| 1376 | |
| 1377 | |
| 1378 | |
| 1379 | /// A figure that is an ordinary fact. |
| 1380 | |
| 1381 | pub const |
| 1382 | Self |
| 1383 | value, |
| 1384 | caption, |
| 1385 | change: None, |
| 1386 | tone: Neutral, |
| 1387 | |
| 1388 | |
| 1389 | |
| 1390 | /// How the value has moved. |
| 1391 | |
| 1392 | pub const |
| 1393 | self.change = Some; |
| 1394 | self |
| 1395 | |
| 1396 | |
| 1397 | /// What the figure means. |
| 1398 | |
| 1399 | pub const |
| 1400 | self.tone = tone; |
| 1401 | self |
| 1402 | |
| 1403 | |
| 1404 | |
| 1405 | /// Something the user can do, and what it costs to say so. |
| 1406 | /// |
| 1407 | /// Beside [`Meter`] and [`Figure`] for the reason those are here: a renderer |
| 1408 | /// that is handed the parts has to decide how to say them, and a renderer that |
| 1409 | /// is handed a finished string has already had the decision made for it. |
| 1410 | /// |
| 1411 | /// No address. Where a control goes is the app's business and every host |
| 1412 | /// follows it differently — an `hx-get`, a protocol URL, a function call — so |
| 1413 | /// the description says what the control *is* and the caller keeps what it |
| 1414 | /// does. That is the same split [`Choice`] makes. |
| 1415 | /// |
| 1416 | /// No confirmation flag either, and that one is a finding rather than an |
| 1417 | /// omission: a question asked *after* a control is pressed belongs to whatever |
| 1418 | /// is holding the interaction, and a renderer that drew it would be asking |
| 1419 | /// before there was anything to answer. |
| 1420 | /// How a picture sits in the box it is given. |
| 1421 | /// |
| 1422 | /// An intent rather than a value, so a renderer picks the expression it has: |
| 1423 | /// `object-fit` in a webview, a texture's UV rect in egui, and in a terminal a |
| 1424 | /// choice about how many cells the blit gets. Named because MNW already makes |
| 1425 | /// the distinction deliberately at 17 sites and makes it three different ways, |
| 1426 | /// which is a policy the app decided rather than one a shared crate would be |
| 1427 | /// picking by accident. |
| 1428 | |
| 1429 | |
| 1430 | |
| 1431 | /// The picture's own proportions, and the box takes the height they imply. |
| 1432 | /// |
| 1433 | /// The default because it is the only one that shows the whole picture at |
| 1434 | /// its own shape, so a renderer that ignores this enum entirely is still |
| 1435 | /// right about the common case. A screenshot wants this; the shipped MNW |
| 1436 | /// carousel sets no `object-fit` at all, which is this. |
| 1437 | |
| 1438 | Natural, |
| 1439 | /// Fill the box and crop whatever does not fit. |
| 1440 | /// |
| 1441 | /// For a picture in a slot whose shape the layout fixed: a thumbnail, an |
| 1442 | /// avatar, cover art. 15 of MNW's 17 sites. |
| 1443 | Cover, |
| 1444 | /// Fit inside the box whole, leaving space on two sides. |
| 1445 | /// |
| 1446 | /// The letterbox. For when the whole picture matters more than filling the |
| 1447 | /// space, and the space is not the picture's shape. |
| 1448 | Contain, |
| 1449 | |
| 1450 | |
| 1451 | /// A picture's own pixel dimensions. |
| 1452 | /// |
| 1453 | /// Deliberately not [`makeover_geometry`]'s business. Geometry answers *how |
| 1454 | /// much space a thing should get*, which is a scale question with the same |
| 1455 | /// answer on every screen. This is the intrinsic size of one asset, which is a |
| 1456 | /// fact about that asset and varies per picture. |
| 1457 | /// |
| 1458 | /// [`makeover_geometry`]: https://docs.rs/makeover-geometry |
| 1459 | |
| 1460 | |
| 1461 | /// Width in the picture's own pixels. |
| 1462 | pub width: u32, |
| 1463 | /// Height in the picture's own pixels. |
| 1464 | pub height: u32, |
| 1465 | |
| 1466 | |
| 1467 | |
| 1468 | /// A picture's dimensions. |
| 1469 | |
| 1470 | pub const |
| 1471 | Self |
| 1472 | |
| 1473 | |
| 1474 | /// Width over height, or `None` if either side is zero. |
| 1475 | /// |
| 1476 | /// The form a renderer actually reserves space with: a box that knows its |
| 1477 | /// proportion holds the right height at any width, which is what a |
| 1478 | /// responsive picture needs and what a fixed pixel height cannot give. |
| 1479 | |
| 1480 | |
| 1481 | .then |
| 1482 | |
| 1483 | |
| 1484 | |
| 1485 | /// When a picture is needed. |
| 1486 | /// |
| 1487 | /// A claim about *importance and position* rather than a fetch mechanism, which |
| 1488 | /// is why it is the description's to make: only the app knows whether a picture |
| 1489 | /// is the first thing on the screen or the fortieth thing down a list. |
| 1490 | /// |
| 1491 | /// # Eager is the default, and that is a correctness choice |
| 1492 | /// |
| 1493 | /// Emitting the webview's `loading="lazy"` for every picture reads one |
| 1494 | /// consumer's habit as a rule. Deferring a picture that is on screen at first paint does not |
| 1495 | /// save anything -- it is needed immediately either way -- and it delays the |
| 1496 | /// arrival, so the space it eventually takes is claimed later and the shift is |
| 1497 | /// more visible, not less. |
| 1498 | /// |
| 1499 | /// So the safe answer is the default and the optimisation is opted into. A |
| 1500 | /// carousel is the case that proves the two cannot be one setting for the |
| 1501 | /// renderer to choose: its first frame is on screen and its other frames are |
| 1502 | /// not, in the same widget, at the same moment. |
| 1503 | |
| 1504 | |
| 1505 | |
| 1506 | /// Needed with the screen. Fetch it now. |
| 1507 | |
| 1508 | Eager, |
| 1509 | /// Not on screen yet. It can wait until it is near. |
| 1510 | Lazy, |
| 1511 | |
| 1512 | |
| 1513 | /// What a [`Track`]'s integers count. |
| 1514 | /// |
| 1515 | /// `Track::fraction` never needed this -- the arithmetic is the same whatever |
| 1516 | /// the numbers mean -- which is exactly how the ruler came to assume minutes |
| 1517 | /// and print `00:00` over a month. A renderer drawing an axis has to write a |
| 1518 | /// label, and it cannot derive the unit from the numbers. |
| 1519 | |
| 1520 | |
| 1521 | |
| 1522 | /// Minutes from the start of a day. A day view. |
| 1523 | |
| 1524 | Minutes, |
| 1525 | /// Whole days. A month strip, a sprint, a stretch of leave. |
| 1526 | /// |
| 1527 | /// A day-granularity axis is a *strip*, not a calendar: one line with |
| 1528 | /// spans laid along it. What it deliberately does not do is wrap into |
| 1529 | /// weeks, which is the shape that makes weekday periodicity visible and |
| 1530 | /// the one job of a month grid that a strip cannot take over. See the |
| 1531 | /// crate header. |
| 1532 | Days, |
| 1533 | |
| 1534 | |
| 1535 | /// A window on an axis, in whatever [`Unit`] its [`Track`] counts. |
| 1536 | /// |
| 1537 | /// The axis a [`Track`] draws. Offsets rather than instants, because a |
| 1538 | /// description carrying a `DateTime` would carry a timezone with it and the |
| 1539 | /// vocabulary has no business holding one. The app knows which day or month |
| 1540 | /// this is; the description says how far along it a thing sits. |
| 1541 | /// |
| 1542 | /// `to` is exclusive and may exceed the natural period, which is how a span |
| 1543 | /// running past the end is said without a second date: under |
| 1544 | /// [`Unit::Minutes`], `Span::new(1320, 1560)` is 22:00 to 02:00. |
| 1545 | |
| 1546 | |
| 1547 | from: u16, |
| 1548 | to: u16, |
| 1549 | |
| 1550 | |
| 1551 | |
| 1552 | /// Midnight to midnight, the ordinary day. |
| 1553 | pub const DAY: Self = Self ; |
| 1554 | |
| 1555 | /// A span, clamped to a sane one. |
| 1556 | /// |
| 1557 | /// An empty or backwards span is a caller bug that should not cost a |
| 1558 | /// renderer a division by zero, so `to` is forced at least one minute past |
| 1559 | /// `from` rather than returning an error nobody can act on. Same reasoning |
| 1560 | /// as [`Share::percent`], which clamps rather than refuses. |
| 1561 | |
| 1562 | pub const |
| 1563 | Self |
| 1564 | from, |
| 1565 | to: if to > from else , |
| 1566 | |
| 1567 | |
| 1568 | |
| 1569 | /// The first minute on the axis. |
| 1570 | |
| 1571 | pub const |
| 1572 | self.from |
| 1573 | |
| 1574 | |
| 1575 | /// One past the last minute on the axis. |
| 1576 | |
| 1577 | pub const |
| 1578 | self.to |
| 1579 | |
| 1580 | |
| 1581 | /// How much the axis covers, in its track's unit. Never zero. |
| 1582 | |
| 1583 | pub const |
| 1584 | self.to - self.from |
| 1585 | |
| 1586 | |
| 1587 | /// Whether an offset falls on this axis. |
| 1588 | |
| 1589 | pub const |
| 1590 | minute >= self.from && minute < self.to |
| 1591 | |
| 1592 | |
| 1593 | |
| 1594 | |
| 1595 | |
| 1596 | SelfDAY |
| 1597 | |
| 1598 | |
| 1599 | |
| 1600 | /// Where a thing sits on a [`Track`], and for how long. |
| 1601 | /// |
| 1602 | /// The one fact a list cannot carry and the whole reason this primitive exists. |
| 1603 | /// A list says what order things come in; a track says a thing starts 135 |
| 1604 | /// minutes along and lasts 45, which is a different claim and not derivable |
| 1605 | /// from the first. |
| 1606 | |
| 1607 | |
| 1608 | at: u16, |
| 1609 | length: u16, |
| 1610 | |
| 1611 | |
| 1612 | |
| 1613 | /// A placement, clamped to a drawable one. |
| 1614 | /// |
| 1615 | /// Zero length becomes one for the same reason [`Span::new`] clamps: a |
| 1616 | /// zero-height thing is invisible rather than expressive, and every |
| 1617 | /// renderer would need its own guard. |
| 1618 | |
| 1619 | pub const |
| 1620 | Self |
| 1621 | at, |
| 1622 | length: if length == 0 else , |
| 1623 | |
| 1624 | |
| 1625 | |
| 1626 | /// Offset from the axis origin, matching [`Span`]'s. |
| 1627 | |
| 1628 | pub const |
| 1629 | self.at |
| 1630 | |
| 1631 | |
| 1632 | /// How long it lasts, in its track's unit. Never zero. |
| 1633 | |
| 1634 | pub const |
| 1635 | self.length |
| 1636 | |
| 1637 | |
| 1638 | /// One past its last minute. |
| 1639 | |
| 1640 | pub const |
| 1641 | self.at + self.length |
| 1642 | |
| 1643 | |
| 1644 | /// Whether two placements cover any of the same time. |
| 1645 | /// |
| 1646 | /// Geometry, and deliberately not a described field. Whether an overlap is |
| 1647 | /// a *conflict* is the app's judgment -- a meeting inside a block of free |
| 1648 | /// time overlaps and is fine -- and that judgment travels the way every |
| 1649 | /// other judgment does, as a [`Tone`] on the thing itself. What a renderer |
| 1650 | /// needs in order to lay two things side by side instead of on top of each |
| 1651 | /// other is this, and it can compute it. |
| 1652 | /// |
| 1653 | /// The alternative was a `conflicts: bool` on each entry, which is state |
| 1654 | /// that can disagree with the times beside it. Two sources for one fact is |
| 1655 | /// how a screen starts rendering a conflict badge on a thing that no longer |
| 1656 | /// conflicts. |
| 1657 | |
| 1658 | pub const |
| 1659 | self.at < other.end && other.at < self.end |
| 1660 | |
| 1661 | |
| 1662 | |
| 1663 | /// A time axis: things placed by when they happen, rather than flowed. |
| 1664 | /// |
| 1665 | /// # Why this is a primitive |
| 1666 | /// |
| 1667 | /// The argument against naming a timeline is that a description expressive |
| 1668 | /// enough to draw one is a component library wearing a description's name. It |
| 1669 | /// does not hold here, and being precise about why matters, because the |
| 1670 | /// reasoning applies to real cases. |
| 1671 | /// |
| 1672 | /// What a timeline needs that a [`List`](Region::Pane) does not is **one** |
| 1673 | /// thing: placement. Where a thing sits is a fact about the thing, the way a |
| 1674 | /// row's primary text is, and it is not derivable from order. Everything else a |
| 1675 | /// day view draws -- the labels, the gridlines, the item bodies, the tones -- |
| 1676 | /// is furniture this vocabulary already names. Measured against goingson's |
| 1677 | /// `day-planning-render.js`, the only members it needed and could not get were |
| 1678 | /// `at` and `minutes`. |
| 1679 | /// |
| 1680 | /// So the timeline was never a component library's worth of vocabulary. It was |
| 1681 | /// two integers, and the refusal was priced as though it were the whole widget. |
| 1682 | /// The test that matters is not "does this shape look complicated" but "how |
| 1683 | /// many members does it actually add, and are they facts or presentation". |
| 1684 | /// Slot heights, gridline colour, how overlaps stack and which hour scrolls |
| 1685 | /// into view on open are all presentation and all stay the renderer's, which is |
| 1686 | /// why they are absent here. |
| 1687 | /// |
| 1688 | /// # What it does not carry |
| 1689 | /// |
| 1690 | /// No pixel measure, no scroll offset, no drag affordance. A renderer draws the |
| 1691 | /// span at whatever density its host uses; `makeover-geometry` owns that the |
| 1692 | /// way it owns everything else measured in pixels. |
| 1693 | |
| 1694 | |
| 1695 | /// The window the axis covers. |
| 1696 | pub span: Span, |
| 1697 | /// The granularity a thing can be placed on, in minutes. |
| 1698 | /// |
| 1699 | /// goingson's day view is 15, giving 96 slots across a day. A renderer uses |
| 1700 | /// it to decide where gridlines fall and what a drop lands on; it does not |
| 1701 | /// constrain [`Placement`], because data arriving from a calendar does not |
| 1702 | /// respect anyone's grid. |
| 1703 | pub slot: u16, |
| 1704 | /// How often the axis labels itself, in its own unit. |
| 1705 | /// |
| 1706 | /// 60 gives an hourly ruler over a 15-minute grid, which is the common |
| 1707 | /// shape and the reason this is separate from `slot`. Zero means an |
| 1708 | /// unlabelled axis. |
| 1709 | pub tick: u16, |
| 1710 | /// What `span`, `slot`, `tick` and every [`Placement`] on it count. |
| 1711 | /// |
| 1712 | /// The one field here a renderer cannot derive, and the reason it exists: |
| 1713 | /// [`fraction`](Self::fraction) is unit-agnostic, so a day-granularity |
| 1714 | /// track produced correct geometry under an hours-and-minutes ruler until |
| 1715 | /// this was added. Geometry never needed it; a label always did. |
| 1716 | pub unit: Unit, |
| 1717 | |
| 1718 | |
| 1719 | |
| 1720 | /// An ordinary day: midnight to midnight, quarter-hour slots, hourly ticks. |
| 1721 | pub const DAY: Self = Self |
| 1722 | span: DAY, |
| 1723 | slot: 15, |
| 1724 | tick: 60, |
| 1725 | unit: Minutes, |
| 1726 | ; |
| 1727 | |
| 1728 | /// A track over `span`, with the day's usual granularity. |
| 1729 | |
| 1730 | pub const |
| 1731 | Self |
| 1732 | span, |
| 1733 | slot: 15, |
| 1734 | tick: 60, |
| 1735 | unit: Minutes, |
| 1736 | |
| 1737 | |
| 1738 | |
| 1739 | /// A strip of whole days: one slot a day, a label a week. |
| 1740 | /// |
| 1741 | /// The shape a stretch of leave or a sprint is drawn on. Not a calendar -- |
| 1742 | /// it does not wrap into weeks, and the crate header says why that |
| 1743 | /// distinction is the whole of what a month grid still has over this. |
| 1744 | |
| 1745 | pub const |
| 1746 | Self |
| 1747 | span, |
| 1748 | slot: 1, |
| 1749 | tick: 7, |
| 1750 | unit: Days, |
| 1751 | |
| 1752 | |
| 1753 | |
| 1754 | /// How many slots the axis holds. |
| 1755 | /// |
| 1756 | /// Rounded up, so a span that does not divide evenly by `slot` still has a |
| 1757 | /// slot covering its tail rather than dropping it. Never zero: `slot` of 0 |
| 1758 | /// reads as one slot spanning the whole axis rather than a division by |
| 1759 | /// zero, since a renderer asking this question has already committed to |
| 1760 | /// drawing something. |
| 1761 | |
| 1762 | pub const |
| 1763 | if self.slot == 0 |
| 1764 | 1 |
| 1765 | else |
| 1766 | self.span.length.div_ceil |
| 1767 | |
| 1768 | |
| 1769 | |
| 1770 | /// Where a placement sits on the axis, as a fraction from 0.0 to 1.0. |
| 1771 | /// |
| 1772 | /// The one calculation every renderer would otherwise write itself, and the |
| 1773 | /// place the three would drift apart. Clamped, so a placement outside the |
| 1774 | /// span draws at the edge rather than off it -- an event running past |
| 1775 | /// midnight is a real thing and truncating it is better than either |
| 1776 | /// panicking or drawing it somewhere impossible. |
| 1777 | |
| 1778 | |
| 1779 | let span = f32from; |
| 1780 | let offset = f32from; |
| 1781 | .clamp |
| 1782 | |
| 1783 | |
| 1784 | |
| 1785 | |
| 1786 | |
| 1787 | SelfDAY |
| 1788 | |
| 1789 | |
| 1790 | |
| 1791 | |
| 1792 | |
| 1793 | /// What the control says. |
| 1794 | pub label: &'a str, |
| 1795 | /// The key that reaches it where a host has keys. |
| 1796 | /// |
| 1797 | /// The one member written for a terminal before there was one. A webview |
| 1798 | /// hangs it off `accesskey` or ignores it; a terminal has nothing else to |
| 1799 | /// offer, so this is the whole of how a control is reached there. |
| 1800 | pub key: , |
| 1801 | /// What pressing it means. [`Tone::Danger`] is the destructive one. |
| 1802 | pub tone: Tone, |
| 1803 | /// Disabled, or nothing said. |
| 1804 | /// |
| 1805 | /// [`State::Disabled`] is what changes what a renderer may do: see |
| 1806 | /// [`State::suppresses_interaction`], which is what says a disabled control |
| 1807 | /// is drawn and not reachable. A control's focus is not sayable here at |
| 1808 | /// all: see the crate header, "Reach, focus and the focus ring". |
| 1809 | pub state: , |
| 1810 | /// A sentence that is always true of this control, shown rather than hunted |
| 1811 | /// for. |
| 1812 | /// |
| 1813 | /// Standing help, not a message and not a tooltip. Half the hosts that read |
| 1814 | /// this have no pointer: a hover is one spelling of it, and the shipped |
| 1815 | /// apps reached for that spelling only because egui and a browser both had |
| 1816 | /// one. What is being said is that the sentence is true, never that it is |
| 1817 | /// hidden until a pointer arrives. |
| 1818 | /// |
| 1819 | /// # Why it is here rather than a layer up |
| 1820 | /// |
| 1821 | /// A hint left to `quasi_router::Act` alone means each renderer draws it |
| 1822 | /// for itself: `makeover_tui` had no hint to read, so quasi-tui built |
| 1823 | /// the muted line, and quasi-immediate called `on_hover_text` outside |
| 1824 | /// [`crate::Act`] rather than inside it. `Field::hint` was here the whole |
| 1825 | /// time, so the same idea sat at two layers depending on which thing |
| 1826 | /// carried it, and a host that was not quasi could say it of a field and |
| 1827 | /// not of a control. |
| 1828 | /// |
| 1829 | /// What kept it out was price rather than doubt: this crate declares |
| 1830 | /// `links`, so a member here moves 25 manifests across 12 repos. That is a |
| 1831 | /// release's forward-fix pass, which is a cost and was being read as a |
| 1832 | /// barrier. |
| 1833 | /// |
| 1834 | /// # What a renderer owes it |
| 1835 | /// |
| 1836 | /// Somewhere to put it, or nothing. Dropping it is legitimate; drawing it |
| 1837 | /// *instead of* the label is not, and neither is drawing it in a way that |
| 1838 | /// takes it out of the accessible tree, which is the failure `title` alone |
| 1839 | /// has on a browser. Nothing may live only in a hint. |
| 1840 | /// |
| 1841 | /// `None` is a control whose label is the whole of it, which is nearly all |
| 1842 | /// of them. |
| 1843 | pub hint: , |
| 1844 | |
| 1845 | |
| 1846 | |
| 1847 | /// An ordinary control, reachable, with no key. |
| 1848 | |
| 1849 | pub const |
| 1850 | Self |
| 1851 | label, |
| 1852 | key: None, |
| 1853 | tone: Neutral, |
| 1854 | state: None, |
| 1855 | hint: None, |
| 1856 | |
| 1857 | |
| 1858 | |
| 1859 | /// The sentence that is always true of it; see [`hint`](Self::hint). |
| 1860 | /// |
| 1861 | /// A renderer with nowhere to put it drops it, so this must never be the |
| 1862 | /// only place a fact appears. |
| 1863 | |
| 1864 | pub const |
| 1865 | self.hint = Some; |
| 1866 | self |
| 1867 | |
| 1868 | |
| 1869 | /// The key that reaches it. |
| 1870 | |
| 1871 | pub const |
| 1872 | self.key = Some; |
| 1873 | self |
| 1874 | |
| 1875 | |
| 1876 | /// What pressing it means. |
| 1877 | |
| 1878 | pub const |
| 1879 | self.tone = tone; |
| 1880 | self |
| 1881 | |
| 1882 | |
| 1883 | /// Focus, or disabled. |
| 1884 | |
| 1885 | pub const |
| 1886 | self.state = Some; |
| 1887 | self |
| 1888 | |
| 1889 | |
| 1890 | /// Whether the control is drawn and does not answer. |
| 1891 | |
| 1892 | |
| 1893 | self.state.is_some_and |
| 1894 | |
| 1895 | |
| 1896 | |
| 1897 | /// A named part of a screen. |
| 1898 | /// |
| 1899 | /// The thing `makeover-geometry` deliberately does not name: it names the space |
| 1900 | /// *between* things by relationship, and nothing named the things. Six named |
| 1901 | /// members, taken from what the two webview apps actually use, plus |
| 1902 | /// [`Region::Bespoke`] for the parts no description should reach. Both apps' |
| 1903 | /// `layout.css` currently names exactly two things, `.raised` and `.well`, so |
| 1904 | /// this layer is absent rather than divergent, which makes it the cheapest of |
| 1905 | /// the schemas to add and the easiest to over-build. |
| 1906 | /// |
| 1907 | /// `#[non_exhaustive]`, for [`RowPart`]'s and [`Readiness`]' reason: the member |
| 1908 | /// after this one should not be a lockstep event across three renderers. |
| 1909 | |
| 1910 | |
| 1911 | |
| 1912 | /// A full-width strip with a title slot and an actions cluster, either of |
| 1913 | /// which may be empty. goingson's `.page-header`, Balanced Breakfast's |
| 1914 | /// `.header` and `.detail-header` are all this, differing only in which |
| 1915 | /// slots they fill. |
| 1916 | Band, |
| 1917 | /// A persistent column beside the content, holding navigation. |
| 1918 | Sidebar, |
| 1919 | /// A region of content with its own scroll. |
| 1920 | Pane, |
| 1921 | /// Things that belong together, and nothing else. |
| 1922 | /// |
| 1923 | /// The block [`Heading::Section`] names, which the vocabulary otherwise |
| 1924 | /// cannot contain. A section heading is a leaf sitting |
| 1925 | /// *beside* the things it names, so nothing said where a section started or |
| 1926 | /// ended and a renderer learned one had ended only because the next heading |
| 1927 | /// arrived. |
| 1928 | /// |
| 1929 | /// # The measurement |
| 1930 | /// |
| 1931 | /// 41 [`Heading::Section`] sites across the ten screens described through |
| 1932 | /// the router, not one of them contained. audiofiles' settings screen is the |
| 1933 | /// clearest: one pane holding a heading, a field, a heading, two toggles, a |
| 1934 | /// heading, a toggle and a heading, which is four sections and no |
| 1935 | /// containers. Under the hand-written CSS the ports are replacing the same |
| 1936 | /// block is spelled `.settings-section` in goingson, `.form-section` and |
| 1937 | /// `.content-section` in the MNW server, `.help-section` in Balanced |
| 1938 | /// Breakfast: three apps, four names, one shape. |
| 1939 | /// |
| 1940 | /// # Why the existing members were the wrong answer |
| 1941 | /// |
| 1942 | /// [`Pane`](Self::Pane) is what apps reached for, and it is 28 of the 45 |
| 1943 | /// regions in the described screens. It claims a scroll of its own and |
| 1944 | /// [`Depth::Well`], so four settings groups inside a pane are four wells |
| 1945 | /// inside a well and four scroll contexts. Neither claim is true of a group. |
| 1946 | /// |
| 1947 | /// [`Widget`](Self::Widget) is wrong from the other side. Its own docs say a |
| 1948 | /// widget is never how a primitive gets added by the back door, and a run of |
| 1949 | /// related controls under a heading is furniture any app would have, which |
| 1950 | /// is the generic-against-bespoke bar a primitive has to clear. |
| 1951 | /// |
| 1952 | /// # What it does not carry |
| 1953 | /// |
| 1954 | /// **A heading.** A group usually has one and it is an ordinary node in the |
| 1955 | /// body, the way it already was. A group of related toggles with no heading |
| 1956 | /// is a real thing and a mandatory slot would forbid it. |
| 1957 | /// |
| 1958 | /// **A depth.** [`Depth::Flat`], on [`Bespoke`](Self::Bespoke)'s reasoning: |
| 1959 | /// it inherits, and an app that wants its group in a well puts it in a |
| 1960 | /// [`Pane`](Self::Pane), which composes rather than adding a knob here. |
| 1961 | /// |
| 1962 | /// **A colour.** Distinguishing sibling groups by colour is the thing this |
| 1963 | /// member was asked for and it is deliberately not stated here. The |
| 1964 | /// description says these things belong together; which of the theme's |
| 1965 | /// categorical colours a renderer reaches for, and whether it reaches for |
| 1966 | /// one at all, is derived from sibling order at the renderer. A terminal |
| 1967 | /// that tints nothing and separates with a rule is honouring this. |
| 1968 | Group, |
| 1969 | /// Two panes side by side, where the left chooses what the right shows. |
| 1970 | Split, |
| 1971 | /// Peer regions across, all of them equals. |
| 1972 | /// |
| 1973 | /// A kanban board's columns, and the shape [`Split`](Self::Split) is not: |
| 1974 | /// a split's two panes stand in a master-detail relationship, where the |
| 1975 | /// left chooses what the right shows. These choose nothing about each |
| 1976 | /// other. Each is a whole region and the set is the arrangement. |
| 1977 | /// |
| 1978 | /// # What it does not carry |
| 1979 | /// |
| 1980 | /// **How many.** The children say, and a count here would be a second |
| 1981 | /// source for something the description already states by containing them. |
| 1982 | /// |
| 1983 | /// **How wide.** Peers are equal by definition, so there is no [`Share`] to |
| 1984 | /// state. A board whose columns wanted different widths would be a |
| 1985 | /// different member, and no app has one. |
| 1986 | /// |
| 1987 | /// **What happens when there is no room.** Scroll across, wrap, or collapse |
| 1988 | /// to one column at a time: all three are right on some host, none is |
| 1989 | /// derivable from the description, and every one of them is presentation. |
| 1990 | /// A terminal that stacks them vertically is honouring this, not degrading |
| 1991 | /// it. |
| 1992 | /// |
| 1993 | /// # Why it is not an `Arrangement` |
| 1994 | /// |
| 1995 | /// [`Arrangement`] is the page's shape, and a board is usually a region |
| 1996 | /// *inside* a page that also has a band over it. Naming it here composes; |
| 1997 | /// naming it there would make a screen either a board or a list-detail and |
| 1998 | /// never a band above a board. It also keeps [`Arrangement::share`] |
| 1999 | /// meaningful, which a peer arrangement has no answer for. |
| 2000 | Columns, |
| 2001 | /// A set of panes, one visible at a time, and a [`Selector::Tabs`] that |
| 2002 | /// chooses between them. |
| 2003 | /// |
| 2004 | /// Says nothing about where the strip sits. A row over the panes, a column |
| 2005 | /// beside them, a wrapped run of links under them: all three are the same |
| 2006 | /// member drawn by a renderer that knows its host, the way the strip's |
| 2007 | /// overflow is. |
| 2008 | TabGroup, |
| 2009 | /// Content over a scrim, taking input until dismissed. |
| 2010 | Modal, |
| 2011 | /// A region this crate names the *place* of and nothing else. The app owns |
| 2012 | /// what goes in it. |
| 2013 | /// |
| 2014 | /// The escape hatch, and the thing that keeps the description honest about |
| 2015 | /// its own limits. A day-plan timeline, a kanban board, a calendar and the |
| 2016 | /// paint interaction over the timeline are not describable here and are not |
| 2017 | /// going to become describable: a description expressive enough to produce |
| 2018 | /// a timeline is a widget library wearing a description's name. |
| 2019 | /// |
| 2020 | /// But a screen containing one still has to be a screen. Without this |
| 2021 | /// member the description covers only the boring screens, and the four that |
| 2022 | /// make goingson worth using would need a second, undescribed path beside |
| 2023 | /// the router. Two paths is how the vocabulary starts drifting from the app |
| 2024 | /// again, which is the exact failure this crate exists to end. |
| 2025 | /// |
| 2026 | /// So the description says "a thing called `day-plan` goes here" and stops. |
| 2027 | /// The name is opaque: this crate never interprets it, and no renderer is |
| 2028 | /// expected to know what it means beyond handing the space over. |
| 2029 | Bespoke |
| 2030 | /// What the app calls it. Never interpreted here. |
| 2031 | name: &'a str, |
| 2032 | , |
| 2033 | /// A named assembly of things the vocabulary already says. |
| 2034 | /// |
| 2035 | /// The third tier, between a primitive and [`Bespoke`](Self::Bespoke). |
| 2036 | /// |
| 2037 | /// # What separates it from the two members either side |
| 2038 | /// |
| 2039 | /// A primitive is a thing every renderer draws from scratch, and the test |
| 2040 | /// it has to pass is that every host has an honest answer. A carousel fails |
| 2041 | /// that test — a terminal has no carousel — which is the same refusal |
| 2042 | /// `Node::Html` got and is why the carousel sat unsayable for months. |
| 2043 | /// |
| 2044 | /// [`Bespoke`](Self::Bespoke) fails it from the other side. Bespoke is for |
| 2045 | /// what one app owns and nobody will build twice, and it carries *no* |
| 2046 | /// contents: the description names the place and stops. A carousel is |
| 2047 | /// furniture any app would have, and every part of it — an ordered set of |
| 2048 | /// frames, a position, prev and next, a strip of position indicators — is |
| 2049 | /// already sayable. Only the assembly had no name. |
| 2050 | /// |
| 2051 | /// So this member is the pair the other two are not: a name **and** |
| 2052 | /// contents. The contents are the assembly, in the region's own body, said |
| 2053 | /// in members that already exist. |
| 2054 | /// |
| 2055 | /// # Why the name does not have to be understood |
| 2056 | /// |
| 2057 | /// A renderer that recognises the name draws it the way its host does it: a |
| 2058 | /// carousel in a webview, a pager with a count in a terminal, a selector in |
| 2059 | /// egui. A renderer that does not recognise it walks the body, which is |
| 2060 | /// primitives all the way down and which it can already draw. |
| 2061 | /// |
| 2062 | /// That is what lets the widget set be **open** without every renderer |
| 2063 | /// knowing every widget. An unrecognised widget degrades to its assembly |
| 2064 | /// instead of failing, so a second or third party can name one without |
| 2065 | /// three renderers releasing in lockstep to accept it. Contrast |
| 2066 | /// [`Bespoke`](Self::Bespoke), which no renderer can degrade: there is |
| 2067 | /// nothing under it to fall back to. |
| 2068 | /// |
| 2069 | /// # What it does not do |
| 2070 | /// |
| 2071 | /// A widget is an assembly of things the vocabulary *already* says, so it |
| 2072 | /// buys no expressive power. Anything needing a member the vocabulary does |
| 2073 | /// not have is a finding about the vocabulary, and the answer to a finding |
| 2074 | /// is to add the member. A widget is never the way a primitive gets added |
| 2075 | /// by the back door. A timeline is describable because [`Track`] was added |
| 2076 | /// to say it, not because a screen was dressed up as an assembly. |
| 2077 | Widget |
| 2078 | /// What the assembly is called. This crate never interprets it, and a |
| 2079 | /// renderer is free not to know it. |
| 2080 | name: &'a str, |
| 2081 | , |
| 2082 | |
| 2083 | |
| 2084 | |
| 2085 | /// How the region sits on what is behind it. |
| 2086 | |
| 2087 | pub const |
| 2088 | match self |
| 2089 | SelfBand | SelfSidebar | SelfSplit | SelfTabGroup => Flat, |
| 2090 | // Flat, and it inherits. A group says its contents belong together |
| 2091 | // and says nothing about the surface they sit on, so a group in a |
| 2092 | // pane is in a well and a group on the page is on the page. An app |
| 2093 | // wanting one lifted puts it in a `Pane`. |
| 2094 | SelfGroup => Flat, |
| 2095 | // Flat, and it is the container rather than the columns. Each |
| 2096 | // column is its own region and brings its own depth; a well here |
| 2097 | // would put a second edge around a row of wells. |
| 2098 | SelfColumns => Flat, |
| 2099 | // A pane is looked into, the same as a table body or a tag tree. |
| 2100 | SelfPane => Well, |
| 2101 | SelfModal => Raised, |
| 2102 | // Flat because it inherits: a bespoke region takes the depth of |
| 2103 | // whatever frames it. An app that wants its timeline in a well puts |
| 2104 | // it in a `Pane`, which composes rather than adding a knob here. |
| 2105 | // |
| 2106 | // A widget inherits for the same reason and it matters more here, |
| 2107 | // because a widget is drawn by whichever renderer recognises it. A |
| 2108 | // depth set here would be this crate deciding that a carousel is |
| 2109 | // raised on every host, which is the kind of value the deferral |
| 2110 | // rule exists to refuse. |
| 2111 | SelfBespoke | SelfWidget => Flat, |
| 2112 | |
| 2113 | |
| 2114 | |
| 2115 | /// Whether this crate can say anything about the region's contents. |
| 2116 | /// |
| 2117 | /// A renderer walks the description and hands every region it understands |
| 2118 | /// to the right drawing code. This is how it tells the two apart, and the |
| 2119 | /// reason it is a method rather than a `matches!` at each renderer: there |
| 2120 | /// is exactly one opaque member and there should stay exactly one. |
| 2121 | /// |
| 2122 | /// [`Widget`](Self::Widget) is described, and that is the whole of what |
| 2123 | /// separates it from [`Bespoke`](Self::Bespoke) here. Both carry a name |
| 2124 | /// this crate never interprets; only one of them carries contents under it. |
| 2125 | /// A renderer that does not recognise a widget's name still walks its body, |
| 2126 | /// so there is nothing for it to hand over and nothing it cannot draw. |
| 2127 | |
| 2128 | pub const |
| 2129 | !matches! |
| 2130 | |
| 2131 | |
| 2132 | /// The name an app gave this region, if it gave one. |
| 2133 | /// |
| 2134 | /// [`Bespoke`](Self::Bespoke) and [`Widget`](Self::Widget) are the two |
| 2135 | /// members that carry a name, for two different purposes: one says what the |
| 2136 | /// app will fill the space with, the other says what the assembly under it |
| 2137 | /// is called. A renderer dispatching on either wants the string without |
| 2138 | /// caring which member it came from, and writing that `matches!` at each |
| 2139 | /// renderer is how the two drift apart. |
| 2140 | |
| 2141 | pub const |
| 2142 | match self |
| 2143 | SelfBespoke | SelfWidget => Some, |
| 2144 | // Spelled out rather than a wildcard, so a member added later has |
| 2145 | // to answer whether it carries a name instead of inheriting `None` |
| 2146 | // by sitting under a `_`. |
| 2147 | SelfBand |
| 2148 | | SelfSidebar |
| 2149 | | SelfPane |
| 2150 | | SelfGroup |
| 2151 | | SelfSplit |
| 2152 | | SelfColumns |
| 2153 | | SelfTabGroup |
| 2154 | | SelfModal => None, |
| 2155 | |
| 2156 | |
| 2157 | |
| 2158 | |
| 2159 | /// How many of a region's children are visible at once. |
| 2160 | /// |
| 2161 | /// One sentence covering three shapes: *this region holds several children and |
| 2162 | /// shows some of them, and the reader can change which.* A tab group, a |
| 2163 | /// carousel and a disclosure all need it, and without it a renderer has two |
| 2164 | /// moves: hardcode a widget name, or draw every child. That is what puts |
| 2165 | /// per-widget code in renderers. |
| 2166 | /// |
| 2167 | /// # What is here and what is not |
| 2168 | /// |
| 2169 | /// The *kind*, and only the kind. Which child is currently up is the current |
| 2170 | /// answer, and a layer that defers every address does not hold the current |
| 2171 | /// answer either — the split [`Selector`] already makes, where this crate says |
| 2172 | /// what kind of chooser a thing is and the router says which option is picked. |
| 2173 | /// So a holder of regions carries the index and the per-child label beside this. |
| 2174 | /// |
| 2175 | /// # What a renderer does with it |
| 2176 | /// |
| 2177 | /// Derives its chrome, once, for every widget rather than per name: |
| 2178 | /// |
| 2179 | /// - Children carrying labels get a strip of the labels, the current one marked. |
| 2180 | /// - Children carrying none get previous, position, next. |
| 2181 | /// - [`AtMostOne`](Self::AtMostOne) over one child gets a summary line that |
| 2182 | /// opens. |
| 2183 | /// |
| 2184 | /// The name on [`Region::Widget`] survives as app vocabulary, for a renderer |
| 2185 | /// that wants to do something *special* with one, which is what it should have |
| 2186 | /// been from the start. |
| 2187 | /// |
| 2188 | /// Degradation runs the way it already did: a renderer ignoring this draws every |
| 2189 | /// child, which is more content rather than less. |
| 2190 | |
| 2191 | |
| 2192 | |
| 2193 | /// Every child, in order. What every region did before this existed. |
| 2194 | |
| 2195 | All, |
| 2196 | /// Exactly one. A carousel, a tab group. |
| 2197 | One, |
| 2198 | /// One, or none. A disclosure, which is closed until it is opened. |
| 2199 | AtMostOne, |
| 2200 | |
| 2201 | |
| 2202 | |
| 2203 | /// Whether the reader can change which child is up. |
| 2204 | /// |
| 2205 | /// The question every renderer's region arm asks before deriving any |
| 2206 | /// chrome, and a method rather than a `matches!` at each renderer for |
| 2207 | /// [`Region::name`]'s reason: three renderers writing the same comparison is |
| 2208 | /// how they come to disagree about a member added later. |
| 2209 | |
| 2210 | pub const |
| 2211 | !matches! |
| 2212 | |
| 2213 | |
| 2214 | /// Whether showing nothing is a legal state. |
| 2215 | /// |
| 2216 | /// True only for [`AtMostOne`](Self::AtMostOne). A renderer needs this to |
| 2217 | /// know whether its control closes as well as moves: a carousel's row moves |
| 2218 | /// between frames and never reaches empty, and a disclosure's summary line |
| 2219 | /// is the same control wearing its closed state. |
| 2220 | |
| 2221 | pub const |
| 2222 | matches! |
| 2223 | |
| 2224 | |
| 2225 | |
| 2226 | /// A window onto a sequence: where it starts, how much it covers, and how long |
| 2227 | /// the sequence is when that is known. |
| 2228 | /// |
| 2229 | /// The mechanism under two things the vocabulary deliberately keeps apart. A |
| 2230 | /// carousel is a window of one frame over children that are all present; a |
| 2231 | /// paged list is a window of a page over rows most of which were never fetched. |
| 2232 | /// Those are different facts and they stay different types — [`Showing`] says |
| 2233 | /// which child is up, [`Paging`] says where a reader is in a query — but the |
| 2234 | /// arithmetic underneath is one piece of code, so a terminal and a browser |
| 2235 | /// cannot come to disagree about which frame is last. |
| 2236 | /// |
| 2237 | /// # Why `of` is optional and `count` is not |
| 2238 | /// |
| 2239 | /// `count` is what is on screen and is therefore always known. `of` is the |
| 2240 | /// length of the thing being windowed, and a host that cannot count says so by |
| 2241 | /// leaving it empty **for the life of the screen**. It is never "not counted |
| 2242 | /// yet": see "First paint is final paint" in the crate header. A total that |
| 2243 | /// turns up on a later pass widens the text that prints it. |
| 2244 | /// |
| 2245 | /// # Clamping |
| 2246 | /// |
| 2247 | /// Every derivation clamps rather than refusing, and a zero `count` answers |
| 2248 | /// `None` rather than dividing. A window past the end is a bug in the host, and |
| 2249 | /// a renderer that answered it by drawing nothing would report a region that |
| 2250 | /// vanished, which is the hardest kind of bug to find from what is on screen. |
| 2251 | /// [`Share::percent`] clamps for the same reason. |
| 2252 | |
| 2253 | |
| 2254 | /// The index into the sequence where the window starts. |
| 2255 | pub from: usize, |
| 2256 | /// How many the window covers. One, for a carousel. |
| 2257 | pub count: usize, |
| 2258 | /// How long the sequence is, when the host can say. |
| 2259 | pub of: , |
| 2260 | |
| 2261 | |
| 2262 | |
| 2263 | /// A window of `count`, starting at `from`, over a sequence of unknown |
| 2264 | /// length. |
| 2265 | |
| 2266 | pub const |
| 2267 | Self |
| 2268 | from, |
| 2269 | count, |
| 2270 | of: None, |
| 2271 | |
| 2272 | |
| 2273 | |
| 2274 | /// How long the sequence is. |
| 2275 | |
| 2276 | pub const |
| 2277 | self.of = Some; |
| 2278 | self |
| 2279 | |
| 2280 | |
| 2281 | /// One item of a sequence whose length is known. A carousel frame. |
| 2282 | |
| 2283 | pub const |
| 2284 | Self |
| 2285 | from: at, |
| 2286 | count: 1, |
| 2287 | of: Some, |
| 2288 | |
| 2289 | |
| 2290 | |
| 2291 | /// Which window this is, counting from zero. |
| 2292 | /// |
| 2293 | /// `None` when `count` is zero, which is the only input with no answer |
| 2294 | /// rather than a clamped one. |
| 2295 | |
| 2296 | pub const |
| 2297 | if self.count == 0 |
| 2298 | return None; |
| 2299 | |
| 2300 | Some |
| 2301 | |
| 2302 | |
| 2303 | /// How many windows the sequence holds. |
| 2304 | /// |
| 2305 | /// `None` unless both the length and a non-zero `count` are known. A |
| 2306 | /// partial answer here would be a renderer drawing "of 0". |
| 2307 | |
| 2308 | pub const |
| 2309 | match self.of |
| 2310 | Some if self.count > 0 => Some, |
| 2311 | _ => None, |
| 2312 | |
| 2313 | |
| 2314 | |
| 2315 | /// Whether anything sits before this window. |
| 2316 | |
| 2317 | pub const |
| 2318 | self.from > 0 |
| 2319 | |
| 2320 | |
| 2321 | /// How many sit after this window, when the length is known. |
| 2322 | /// |
| 2323 | /// Here rather than in each renderer for [`Showing::selective`]'s reason: |
| 2324 | /// three of them writing the same subtraction is how they come to disagree, |
| 2325 | /// and this one has an underflow in it for whoever writes it fourth. |
| 2326 | |
| 2327 | pub const |
| 2328 | match self.of |
| 2329 | Some => Some, |
| 2330 | None => None, |
| 2331 | |
| 2332 | |
| 2333 | |
| 2334 | /// Whether anything sits after it. |
| 2335 | /// |
| 2336 | /// `true` when the length is unknown: a host that cannot count cannot rule |
| 2337 | /// out more, and offering a way forward that turns out to be empty is the |
| 2338 | /// cheaper of the two mistakes. |
| 2339 | |
| 2340 | pub const |
| 2341 | match self.of |
| 2342 | Some => self.from.saturating_add < of, |
| 2343 | None => true, |
| 2344 | |
| 2345 | |
| 2346 | |
| 2347 | /// The window with `from` brought inside the sequence. |
| 2348 | /// |
| 2349 | /// A no-op when the length is unknown, since there is nothing to clamp |
| 2350 | /// against. |
| 2351 | |
| 2352 | pub const |
| 2353 | if let Some = self.of |
| 2354 | && self.from >= of |
| 2355 | |
| 2356 | // `max(1)` by hand: `Ord::max` is not const yet, and a zero-count |
| 2357 | // window would otherwise clamp onto the end rather than inside it. |
| 2358 | let step = if self.count == 0 else ; |
| 2359 | self.from = of.saturating_sub; |
| 2360 | |
| 2361 | self |
| 2362 | |
| 2363 | |
| 2364 | |
| 2365 | /// Where a reader is in a set that arrived in parts. |
| 2366 | /// |
| 2367 | /// A [`Window`] wearing the paged reading of itself. Distinct from a carousel's |
| 2368 | /// window at the top level on purpose, because the intent differs and a call |
| 2369 | /// site should say which one it means, while the arithmetic below is shared so |
| 2370 | /// the two cannot drift apart. |
| 2371 | /// |
| 2372 | /// # The two idioms, and which one a renderer may draw |
| 2373 | /// |
| 2374 | /// Load-more and numbered pages are both this type. Which is honest is |
| 2375 | /// [`paged`](Self::paged): a set whose page size is known can be drawn as |
| 2376 | /// "Page 3 of 8", and one without can only be drawn as "150 of 400" and a way |
| 2377 | /// forward. Saying it here rather than letting each renderer guess is the point |
| 2378 | /// — three renderers inferring it from the numbers is how they come to disagree. |
| 2379 | /// |
| 2380 | /// # What it does not carry |
| 2381 | /// |
| 2382 | /// No addresses. `makeover-layout` cannot name an action, and the way to ask for |
| 2383 | /// the next part is the host's: `quasi_router` pairs this with the addresses the |
| 2384 | /// same way `Row` pairs its parts with `Row::activate`. That split is the reason |
| 2385 | /// this type is reusable by a carousel, which has nothing to ask. |
| 2386 | |
| 2387 | |
| 2388 | /// The window onto the set. |
| 2389 | pub window: Window, |
| 2390 | /// Whether the parts are a fixed size, and so whether pages are countable. |
| 2391 | /// |
| 2392 | /// `false` for load-more, where the window simply grew and "page 2" would |
| 2393 | /// name nothing. |
| 2394 | pub paged: bool, |
| 2395 | |
| 2396 | |
| 2397 | |
| 2398 | /// A page of `per`, starting at `from`. |
| 2399 | |
| 2400 | pub const |
| 2401 | Self |
| 2402 | window: new, |
| 2403 | paged: true, |
| 2404 | |
| 2405 | |
| 2406 | |
| 2407 | /// The first `shown`, with more behind them. |
| 2408 | /// |
| 2409 | /// The load-more shape: the window starts at the beginning and grows, so |
| 2410 | /// there is no page to number. |
| 2411 | |
| 2412 | pub const |
| 2413 | Self |
| 2414 | window: new, |
| 2415 | paged: false, |
| 2416 | |
| 2417 | |
| 2418 | |
| 2419 | /// How many there are altogether. |
| 2420 | /// |
| 2421 | /// Left unsaid by a host that cannot count, and left unsaid **for good**: |
| 2422 | /// a total arriving later widens whatever prints it. See "First paint is |
| 2423 | /// final paint" in the crate header. |
| 2424 | |
| 2425 | pub const |
| 2426 | self.window = self.window.of; |
| 2427 | self |
| 2428 | |
| 2429 | |
| 2430 | /// Which page this is, counting from one, when pages are countable. |
| 2431 | /// |
| 2432 | /// One-based because it is read aloud. [`Window::index`] is the zero-based |
| 2433 | /// form for anyone indexing with it. |
| 2434 | |
| 2435 | pub const |
| 2436 | if !self.paged |
| 2437 | return None; |
| 2438 | |
| 2439 | match self.window.index |
| 2440 | Some => Some, |
| 2441 | None => None, |
| 2442 | |
| 2443 | |
| 2444 | |
| 2445 | /// How many pages there are, when that is countable. |
| 2446 | |
| 2447 | pub const |
| 2448 | if !self.paged |
| 2449 | return None; |
| 2450 | |
| 2451 | self.window.windows |
| 2452 | |
| 2453 | |
| 2454 | /// How many are on screen. |
| 2455 | |
| 2456 | pub const |
| 2457 | self.window.count |
| 2458 | |
| 2459 | |
| 2460 | /// How many there are, when the host counted. |
| 2461 | |
| 2462 | pub const |
| 2463 | self.window.of |
| 2464 | |
| 2465 | |
| 2466 | /// How many are not shown yet, when the host counted. |
| 2467 | /// |
| 2468 | /// The figure a load-more control puts in its label. `None` is the honest |
| 2469 | /// and common case: a set that cannot say how many more there are still has |
| 2470 | /// a way to ask for them. |
| 2471 | |
| 2472 | pub const |
| 2473 | self.window.after |
| 2474 | |
| 2475 | |
| 2476 | /// Whether there is anything further on. |
| 2477 | |
| 2478 | pub const |
| 2479 | self.window.has_after |
| 2480 | |
| 2481 | |
| 2482 | /// Whether there is anything back the other way. |
| 2483 | |
| 2484 | pub const |
| 2485 | self.window.has_before |
| 2486 | |
| 2487 | |
| 2488 | |
| 2489 | /// How much of the width an arrangement's first region takes. |
| 2490 | /// |
| 2491 | /// Nothing said how much room a region got, so every renderer invented its own |
| 2492 | /// number and two hosts showing one screen disagreed about its proportions. A |
| 2493 | /// webview never noticed, because the stylesheet answered once for every |
| 2494 | /// consumer; a terminal has no stylesheet to inherit from, so `quasi-tui` |
| 2495 | /// picked 24 columns for a sidebar and 40% for a list pane and neither had |
| 2496 | /// anything behind it. |
| 2497 | /// |
| 2498 | /// # A proportion, never a unit |
| 2499 | /// |
| 2500 | /// Held as a percentage, and that is the only form it comes in. A description |
| 2501 | /// carrying columns would be describing a terminal and one carrying pixels a |
| 2502 | /// webview, and the whole point is that both honour the same fact: a terminal |
| 2503 | /// resolves it against a column count, a webview writes it into a grid, and |
| 2504 | /// neither has to know what the other did. |
| 2505 | /// |
| 2506 | /// It is not [`makeover_geometry::Ratio`]'s job either, which was the first |
| 2507 | /// guess. Geometry is scales that answer the same for every screen and takes |
| 2508 | /// no input that would let a sidebar screen differ from a list-detail one. |
| 2509 | /// |
| 2510 | /// [`makeover_geometry::Ratio`]: https://docs.rs/makeover-geometry |
| 2511 | |
| 2512 | ; |
| 2513 | |
| 2514 | |
| 2515 | /// What a sidebar takes, when nobody says otherwise. |
| 2516 | /// |
| 2517 | /// A quarter. `quasi-tui` drew 24 columns, which is a quarter of a |
| 2518 | /// 96-column terminal and about a fifth of a wide one; a quarter is that |
| 2519 | /// number said in the form a webview can honour too. |
| 2520 | pub const SIDEBAR: Self = Self; |
| 2521 | |
| 2522 | /// What the list side of a list-detail takes, when nobody says otherwise. |
| 2523 | /// |
| 2524 | /// `quasi-tui`'s 40%, which was already a proportion and is the one number |
| 2525 | /// this member did not have to invent. |
| 2526 | pub const LIST: Self = Self; |
| 2527 | |
| 2528 | /// A share of the width, as a percentage. |
| 2529 | /// |
| 2530 | /// Clamped to 5..=95 rather than refused. A description that asked for a |
| 2531 | /// region of nothing is a bug in the app, and a renderer drawing a region |
| 2532 | /// zero cells wide reports it as a region that vanished, which is the |
| 2533 | /// hardest kind of bug to find from what is on the screen. |
| 2534 | |
| 2535 | pub const |
| 2536 | Self |
| 2537 | 5 |
| 2538 | else if percent > 95 |
| 2539 | 95 |
| 2540 | else |
| 2541 | percent |
| 2542 | |
| 2543 | |
| 2544 | |
| 2545 | /// The share as a percentage. |
| 2546 | |
| 2547 | pub const |
| 2548 | self.0 |
| 2549 | |
| 2550 | |
| 2551 | /// This share of a width, rounded to the nearest whole unit. |
| 2552 | /// |
| 2553 | /// What a terminal calls to turn the proportion into columns. At least one, |
| 2554 | /// because a region the description named should be visible: a screen |
| 2555 | /// 3 columns wide is unusable either way, and a sidebar that is there is a |
| 2556 | /// truer picture of the description than a sidebar that is not. |
| 2557 | |
| 2558 | pub const |
| 2559 | let taken = .div_ceil; |
| 2560 | if taken == 0 else |
| 2561 | |
| 2562 | |
| 2563 | |
| 2564 | /// How a screen is laid out. |
| 2565 | /// |
| 2566 | /// Three, and no one of them is a variant of another. goingson is list-detail, |
| 2567 | /// Balanced Breakfast is sidebar plus content, and MNW's embeds are one region |
| 2568 | /// filling the document. The tab group is a modifier rather than a member, |
| 2569 | /// because goingson uses it *inside* the same content region rather than |
| 2570 | /// instead of one. |
| 2571 | /// |
| 2572 | /// This exists at all because the router has to be able to express a screen |
| 2573 | /// rather than only a control. Discovering the arrangement layer missing after |
| 2574 | /// the renderers exist is a redesign; naming two now is a morning. |
| 2575 | /// |
| 2576 | /// # Why the share rides here |
| 2577 | /// |
| 2578 | /// A share is per-arrangement: how much a sidebar takes and how much a list |
| 2579 | /// side takes are different questions, and this enum is the only thing that |
| 2580 | /// knows which one is being asked. Geometry would have had to invent a channel |
| 2581 | /// to be told. |
| 2582 | /// |
| 2583 | /// [`list_detail`](Self::list_detail) and |
| 2584 | /// [`sidebar_content`](Self::sidebar_content) build these with the default |
| 2585 | /// shares, so a screen that has no opinion does not have to have one. |
| 2586 | |
| 2587 | |
| 2588 | /// A list that chooses what the detail beside it shows. |
| 2589 | ListDetail |
| 2590 | /// Whether the detail side is a [`Region::TabGroup`]. |
| 2591 | tabbed: bool, |
| 2592 | /// How much of the width the list side takes. |
| 2593 | share: Share, |
| 2594 | , |
| 2595 | /// Navigation down the side, content filling the rest. |
| 2596 | SidebarContent |
| 2597 | /// How much of the width the sidebar takes. |
| 2598 | share: Share, |
| 2599 | , |
| 2600 | /// One region, filling the document. |
| 2601 | /// |
| 2602 | /// The other two are both about dividing a width between two regions, so a |
| 2603 | /// screen that is one region had to borrow one of them and then undo it: |
| 2604 | /// MNW's five embeds said `list_detail(title, false)` and the host spent a |
| 2605 | /// `display: block` cancelling the grid that produced. A host writing CSS |
| 2606 | /// to contradict the description rather than to add to it is the thing |
| 2607 | /// this member ends. |
| 2608 | /// |
| 2609 | /// Carries no [`Share`], because there is no division to describe. That is |
| 2610 | /// why [`share`](Self::share) answers `None` here. |
| 2611 | Single, |
| 2612 | |
| 2613 | |
| 2614 | |
| 2615 | /// A list and a detail beside it, at the default share. |
| 2616 | |
| 2617 | pub const |
| 2618 | SelfListDetail |
| 2619 | tabbed, |
| 2620 | share: LIST, |
| 2621 | |
| 2622 | |
| 2623 | |
| 2624 | /// A sidebar and content beside it, at the default share. |
| 2625 | |
| 2626 | pub const |
| 2627 | SelfSidebarContent |
| 2628 | share: SIDEBAR, |
| 2629 | |
| 2630 | |
| 2631 | |
| 2632 | /// How much of the width the first region takes, when two regions divide it. |
| 2633 | /// |
| 2634 | /// `None` for [`Single`](Self::Single): one region takes the width, and a |
| 2635 | /// renderer that asked how to divide it was asking the wrong question. It |
| 2636 | /// answers `Option` rather than a full-width `Share` so that a host cannot |
| 2637 | /// quietly draw a one-region screen as a grid with an empty second column. |
| 2638 | |
| 2639 | pub const |
| 2640 | match self |
| 2641 | SelfListDetail | SelfSidebarContent => Some, |
| 2642 | SelfSingle => None, |
| 2643 | |
| 2644 | |
| 2645 | |
| 2646 | /// The same arrangement, at this share. |
| 2647 | /// |
| 2648 | /// [`Single`](Self::Single) is returned unchanged: it has no division to |
| 2649 | /// set, so a share named for it is a statement about nothing rather than an |
| 2650 | /// error worth refusing a screen over. |
| 2651 | |
| 2652 | pub const |
| 2653 | match self |
| 2654 | SelfListDetail => SelfListDetail , |
| 2655 | SelfSidebarContent => SelfSidebarContent , |
| 2656 | SelfSingle => SelfSingle, |
| 2657 | |
| 2658 | |
| 2659 | |
| 2660 | |
| 2661 | /// How wide the content of a whole screen runs. |
| 2662 | /// |
| 2663 | /// Both are the description's, which is what answering the two together |
| 2664 | /// settled. |
| 2665 | /// |
| 2666 | /// Measured in the MNW server, where 69 of 72 templates carry exactly one of |
| 2667 | /// three mutually exclusive classes and the choice is per screen. GoingsOn |
| 2668 | /// reaches for `max-width` 56 times and Balanced Breakfast 12, neither with a |
| 2669 | /// token for it, so three apps were solving one thing by hand. |
| 2670 | /// |
| 2671 | /// # Named for the measure, not for MNW's classes |
| 2672 | /// |
| 2673 | /// A renderer that is not a browser has to answer this too, and `padded-page` |
| 2674 | /// tells a terminal nothing. The three say how wide the text runs, which is a |
| 2675 | /// question every renderer can answer: a webview with a `max-width`, a terminal |
| 2676 | /// with gutters, an immediate-mode frame with its own width. |
| 2677 | /// |
| 2678 | /// `#[non_exhaustive]` for [`Fill`]'s reason. The set is closed today because |
| 2679 | /// the measurement found three, and a fourth arriving should not be a lockstep |
| 2680 | /// release across nine repos. |
| 2681 | |
| 2682 | |
| 2683 | |
| 2684 | /// The whole width, with gutters. The default, and 53 of the 69. |
| 2685 | /// |
| 2686 | /// What a dashboard, a table and a settings screen want: the content is |
| 2687 | /// wide because the content *is* wide, and constraining it would waste the |
| 2688 | /// window. |
| 2689 | |
| 2690 | Wide, |
| 2691 | /// Capped at a comfortable page width, centred. 13 of the 69. |
| 2692 | /// |
| 2693 | /// A form, a sign-in, a purchase. Content that does not get better by |
| 2694 | /// getting wider, but is not prose either. |
| 2695 | Contained, |
| 2696 | /// Capped at a line length that reads well. 3 of the 69. |
| 2697 | /// |
| 2698 | /// Prose. The narrowest of the three, and the one with a reason outside |
| 2699 | /// taste: a line of text past roughly 75 characters costs the reader the |
| 2700 | /// return sweep. |
| 2701 | Reading, |
| 2702 | |
| 2703 | |
| 2704 | |
| 2705 | /// A stable name, for a renderer that needs to spell it. |
| 2706 | /// |
| 2707 | /// Here rather than in each renderer for [`Sort::as_str`]'s reason: three |
| 2708 | /// renderers spelling one enum is three chances to spell it differently. |
| 2709 | |
| 2710 | pub const |
| 2711 | match self |
| 2712 | SelfWide => "wide", |
| 2713 | SelfContained => "contained", |
| 2714 | SelfReading => "reading", |
| 2715 | |
| 2716 | |
| 2717 | |
| 2718 | |
| 2719 | /// What kind of value a form field takes. |
| 2720 | /// |
| 2721 | /// The union of the two vocabularies that diverged, which is what triggered |
| 2722 | /// this crate. They have since converged on their own: both apps now have a |
| 2723 | /// `renderFormField` emitting the same anatomy, and what is left differing is |
| 2724 | /// the kind set, the error shape, and whether the return is a string or a node. |
| 2725 | /// |
| 2726 | /// Validation is deliberately absent. Neither app has a shared story (goingson |
| 2727 | /// validates after collecting the form data, with per-field transform hooks; |
| 2728 | /// Balanced Breakfast has `required` and nothing else), and a schema that |
| 2729 | /// describes fields but not constraints acquires a constraint layer per app, |
| 2730 | /// which is exactly how the current divergence started. Naming it absent is a |
| 2731 | /// decision; leaving it unmentioned would not be. |
| 2732 | /// `#[non_exhaustive]` for the reason [`Fill`] is: renderers match on this and |
| 2733 | /// the set keeps growing, so growth must not be a lockstep event. |
| 2734 | |
| 2735 | |
| 2736 | |
| 2737 | /// A single line of text. |
| 2738 | Text, |
| 2739 | /// A single line of text that must never be echoed, logged or round-tripped |
| 2740 | /// through anything that might persist it. |
| 2741 | Secret, |
| 2742 | /// A number. |
| 2743 | Number, |
| 2744 | /// A number inside bounds the user drags across, where the range being |
| 2745 | /// visible is the point. |
| 2746 | /// |
| 2747 | /// Not [`Number`](Self::Number) with [`min`](Field::min) and |
| 2748 | /// [`max`](Field::max), which is the reading to resist and is the same |
| 2749 | /// resistance [`Radio`](Self::Radio) needed against `Select`. A bounded |
| 2750 | /// number and a validated number are different *questions*. A validated |
| 2751 | /// number is typed and can be wrong: the bounds are a rule the answer is |
| 2752 | /// checked against, and being told "must be at least 1" afterwards is the |
| 2753 | /// normal course of it. A range cannot be out of range at all, because the |
| 2754 | /// bounds are the control's extent rather than a rule, and the two ends are |
| 2755 | /// what the question means — audiofiles asks for a classifier threshold |
| 2756 | /// between 0 and 1, where 0 is never and 1 is only-on-certainty, and a typed |
| 2757 | /// 0.72 says nothing without both ends on screen beside it. |
| 2758 | /// |
| 2759 | /// A renderer cannot infer which one is meant from `min`/`max` alone, which |
| 2760 | /// is why this is a kind and not an inference: goingson's `min="1"` duration |
| 2761 | /// is a validated number and would become a slider. |
| 2762 | /// |
| 2763 | /// The membership test passes without stretching: a webview emits |
| 2764 | /// `<input type="range">`, egui has `Slider`, a terminal draws a bar and |
| 2765 | /// takes arrow keys, a CLI takes a bounded argument. |
| 2766 | /// |
| 2767 | /// # It owes its bounds |
| 2768 | /// |
| 2769 | /// [`min`](Field::min) and [`max`](Field::max) are `Option` for every other |
| 2770 | /// kind and are **required** here, in the sense the description can require |
| 2771 | /// anything: [`Field::bounded`] is the check, and a range missing one has no |
| 2772 | /// extent for a renderer to draw. What a renderer does with an unbounded |
| 2773 | /// range is its own call and both answers are honest — fall back to a typed |
| 2774 | /// number, or pick a host default — so this is stated rather than enforced, |
| 2775 | /// the way every other constraint here is. |
| 2776 | /// |
| 2777 | /// [`Field::step`] is the third fact and is genuinely optional: absent, the |
| 2778 | /// host's own granularity stands. |
| 2779 | Range, |
| 2780 | /// One question with two ends: a lower value and an upper one, submitted |
| 2781 | /// under two names. |
| 2782 | /// |
| 2783 | /// "Show me samples between 90 and 130 BPM" has a single answer with two |
| 2784 | /// ends, and the ends constrain each other: a minimum above the maximum is |
| 2785 | /// not a wrong value, it is an empty result nobody asked for. Described as |
| 2786 | /// two [`Number`](Self::Number) fields that is unsayable — nothing says they |
| 2787 | /// are one question, so a renderer draws two controls with two labels and no |
| 2788 | /// relationship, and [`Field::error`] can only be attached to one side of a |
| 2789 | /// fault that belongs to both. |
| 2790 | /// |
| 2791 | /// Not [`Range`](Self::Range), which was the reading to resist and the |
| 2792 | /// resistance is the same one `Range` itself needed against `Number`. A |
| 2793 | /// range describes *one* value inside an extent; this describes two, and the |
| 2794 | /// extent is a bound on each rather than the question's meaning. The two |
| 2795 | /// come apart in the answer: a range has a value, an interval has a pair, |
| 2796 | /// and either end may be absent while the other stands. |
| 2797 | /// |
| 2798 | /// # It states both names |
| 2799 | /// |
| 2800 | /// [`Field::name`] is the lower end and [`Field::upper_name`] is the upper |
| 2801 | /// one, stated rather than derived. One member instead of a naming |
| 2802 | /// convention this crate would then own forever. |
| 2803 | /// |
| 2804 | /// Direction is carried by which member the name sits in, so nothing |
| 2805 | /// separate says which end is which. |
| 2806 | /// |
| 2807 | /// # What it does not enforce |
| 2808 | /// |
| 2809 | /// The crossing rule. A lower end above the upper one is describable here |
| 2810 | /// and always was, exactly as an out-of-[`min`](Field::min) number is: this |
| 2811 | /// crate carries constraints and never checks them, and deciding a value is |
| 2812 | /// wrong stays with whoever validated. What the description buys is that the |
| 2813 | /// fault now has one place to be reported rather than two. |
| 2814 | /// |
| 2815 | /// # Both ends take the same facts |
| 2816 | /// |
| 2817 | /// [`min`](Field::min), [`max`](Field::max), [`step`](Field::step) and |
| 2818 | /// [`unit`](Field::unit) describe the axis rather than one end of it, so |
| 2819 | /// they are read once and applied to both. Six of audiofiles' filter axes |
| 2820 | /// are exactly this: one extent, one unit, one granularity, two ends. |
| 2821 | /// |
| 2822 | /// The bounds are optional here, unlike `Range`. They are a rule the answer |
| 2823 | /// is checked against rather than the control's extent, which is |
| 2824 | /// [`Number`](Self::Number)'s arrangement and not a slider's. |
| 2825 | Interval, |
| 2826 | /// An email address. |
| 2827 | /// |
| 2828 | /// Distinct from [`Text`](Self::Text) because the distinction is not |
| 2829 | /// decoration: a webview renderer emits `type="email"`, which on a touch |
| 2830 | /// device changes the keyboard that appears and turns on the platform's own |
| 2831 | /// validation. goingson ships to iOS, so collapsing this into text costs a |
| 2832 | /// keyboard with no `@` on it. |
| 2833 | Email, |
| 2834 | /// A URL. Same reasoning as [`Email`](Self::Email). |
| 2835 | Url, |
| 2836 | /// A telephone number. Same reasoning as [`Email`](Self::Email), and the |
| 2837 | /// clearest case of it: the keyboard is a numeric pad rather than letters. |
| 2838 | Tel, |
| 2839 | /// A calendar day, with no time of day in it. |
| 2840 | /// |
| 2841 | /// [`Email`](Self::Email)'s argument, and it carries further: a webview |
| 2842 | /// emits `type="date"`, which is a native picker, the platform's own |
| 2843 | /// validation, and on a touch device the date keyboard. Described as |
| 2844 | /// [`Text`](Self::Text) with a hint reading "YYYY-MM-DD", all three are |
| 2845 | /// lost and the hint is doing the platform's job in prose. |
| 2846 | /// |
| 2847 | /// The membership test passes on every host without stretching: a webview |
| 2848 | /// and a Tauri app emit the input, egui has a date picker, a terminal |
| 2849 | /// prompts for a day and can validate it, a CLI takes an argument. |
| 2850 | /// |
| 2851 | /// # The value is ISO 8601, `YYYY-MM-DD` |
| 2852 | /// |
| 2853 | /// Named here rather than left to each host, because a host that picks |
| 2854 | /// differently sends a server something it parses differently, and the |
| 2855 | /// failure is silent and per-host. It is `<input type="date">`'s own wire |
| 2856 | /// format, so the webview renderer owes nothing to honour it and the other |
| 2857 | /// hosts have one spelling to meet. [`DATE_FORMAT`] is the constant, and a |
| 2858 | /// test asserts this doc and that constant agree. |
| 2859 | Date, |
| 2860 | /// A calendar day and a time of day together. |
| 2861 | /// |
| 2862 | /// Apart from [`Date`](Self::Date) because the question is different rather |
| 2863 | /// than more precise: "which day does this expire" and "at what moment does |
| 2864 | /// this publish" are asked by different screens and answered by different |
| 2865 | /// controls. A webview emits `type="datetime-local"` for one and |
| 2866 | /// `type="date"` for the other, and a host that collapsed them would ask |
| 2867 | /// half the tree for a precision it does not want. |
| 2868 | /// |
| 2869 | /// Both arrived together on measurement rather than on symmetry: 13 sites |
| 2870 | /// of each across the MNW server and goingson, and **zero** of `time`, |
| 2871 | /// `month` or `week`, which is why those are not here. A member added for a |
| 2872 | /// case nobody has is a member designed against nothing, which is |
| 2873 | /// [`File`](Self::File)'s reasoning about `accept` applied to a whole |
| 2874 | /// member. |
| 2875 | /// |
| 2876 | /// # The value is `YYYY-MM-DDTHH:MM`, local, with no zone |
| 2877 | /// |
| 2878 | /// `<input type="datetime-local">`'s own format, and the "local" is the |
| 2879 | /// load-bearing half: the value carries no offset and no `Z`, so the moment |
| 2880 | /// it names is only fixed once something supplies a zone. That is the app's |
| 2881 | /// business and not the description's. Seconds are absent, which is the |
| 2882 | /// browser's own default and is left as the rule rather than restated as a |
| 2883 | /// constraint. [`DATETIME_FORMAT`] is the constant. |
| 2884 | /// |
| 2885 | /// [`Field::min`] and [`Field::max`] already take "the host's own spelling |
| 2886 | /// of a bound", so a floor of *not in the past* needs nothing new here: it |
| 2887 | /// is a string in this same format. |
| 2888 | DateTime, |
| 2889 | /// Several lines of text. |
| 2890 | Textarea, |
| 2891 | /// Several lines of text the user writes markdown in. |
| 2892 | /// |
| 2893 | /// The editing counterpart of prose a description carries as markdown |
| 2894 | /// source, and the reason it can exist at all is the same one that lets the |
| 2895 | /// source be carried: editing markdown is editing text, so a terminal, an |
| 2896 | /// immediate-mode host and a webview all have an honest answer, and none of |
| 2897 | /// them has to refuse. A kind that meant "rich text" in the WYSIWYG sense |
| 2898 | /// would have been a document model, and two of the three hosts would have |
| 2899 | /// had to draw something they cannot. |
| 2900 | /// |
| 2901 | /// What the mark buys over [`Textarea`](Self::Textarea) is that a renderer |
| 2902 | /// may offer the affordances markdown has and plain text does not — a |
| 2903 | /// preview, a syntax pass, a monospaced face for the source — and that a |
| 2904 | /// host reading the value back knows what it is holding. A renderer with |
| 2905 | /// none of that draws a textarea, which is why this is additive rather than |
| 2906 | /// a second control. |
| 2907 | /// |
| 2908 | /// It says nothing about **when** the value is saved. Autosave is a clock, |
| 2909 | /// clocks are not described here, and the four MNW editors this was measured |
| 2910 | /// against each keep their own. |
| 2911 | /// |
| 2912 | /// Sanitising stays where it already is for markdown that is only displayed: |
| 2913 | /// with the renderer, at the point markup is produced. Being described is |
| 2914 | /// not a safety property, and a host with its own sanitiser and its own |
| 2915 | /// content-security posture still owns both. |
| 2916 | Rich, |
| 2917 | /// One of a fixed set, offered behind a control that shows one at a time. |
| 2918 | Select, |
| 2919 | /// One of a fixed set, with every option on screen at once. |
| 2920 | /// |
| 2921 | /// Not a presentation of [`Select`](Self::Select), which is the reading to |
| 2922 | /// resist: what differs is a property of the *question*. A choice that is |
| 2923 | /// consequential or irreversible has to be readable without opening |
| 2924 | /// anything, because a closed control shows one option and hides the rest, |
| 2925 | /// and the one it shows is whichever was current before the user had read |
| 2926 | /// the alternatives. audiofiles asks whether a library copies samples into |
| 2927 | /// its store or references them where they lie — which cannot be changed |
| 2928 | /// afterwards — and had already promoted that out of a checkbox by hand, |
| 2929 | /// with a comment giving this reason, before the description could say it. |
| 2930 | /// |
| 2931 | /// Everything here is an `<input type=...>`, a `<select>` or a |
| 2932 | /// `<textarea>`, and the way this enum grows is by a site being measured |
| 2933 | /// rather than by a list being completed. No member is ever "the last one". |
| 2934 | Radio, |
| 2935 | /// On or off. |
| 2936 | Checkbox, |
| 2937 | /// A file the user picks from wherever the host keeps files. |
| 2938 | /// |
| 2939 | /// It was filed as a router finding — a control whose destination is a |
| 2940 | /// host capability rather than an address — and splitting it is what made |
| 2941 | /// it two answers instead of one member satisfying neither. *Opening* a |
| 2942 | /// file is a one-way handoff and needs no new API. *Picking* one returns a |
| 2943 | /// value into a write, which is a form concern, which is this. |
| 2944 | /// |
| 2945 | /// The membership test passes on every host and not by a stretch: a Tauri |
| 2946 | /// app opens a native picker, a server renders `<input type="file">`, a |
| 2947 | /// terminal prompts for a path, a CLI takes an argument. That is closer to |
| 2948 | /// [`Email`](Self::Email), which exists because it changes the keyboard, |
| 2949 | /// than to anything bespoke. |
| 2950 | /// |
| 2951 | /// # The four things an upload says, and where each of them lives |
| 2952 | /// |
| 2953 | /// | axis | where | |
| 2954 | /// |---|---| |
| 2955 | /// | what it accepts | [`Field::accept`] | |
| 2956 | /// | one file or several | [`Field::multiple`] | |
| 2957 | /// | where the bytes go | the router's action, not here | |
| 2958 | /// | how far along it is | [`Awaiting`] on that action | |
| 2959 | /// |
| 2960 | /// Only the first two are this crate's, and that split is the answer to |
| 2961 | /// "describe an upload in full" rather than a gap in it. A destination is an |
| 2962 | /// address and this crate holds no addresses; progress is a live number and |
| 2963 | /// a description is built once, so the number is the renderer's to observe |
| 2964 | /// against the size [`Awaiting::amount`] carried before the transfer began. |
| 2965 | /// |
| 2966 | /// # How the file is handed over is the host's |
| 2967 | /// |
| 2968 | /// A drop area, a button opening a native picker, a path typed at a prompt: |
| 2969 | /// all three are the same field, and every measured site has the first. It |
| 2970 | /// is not described for the reason no gesture is — this crate owns no |
| 2971 | /// coordinates and no pointer, and a terminal that cannot be dropped on |
| 2972 | /// would be refusing a description it can otherwise honour completely. |
| 2973 | /// |
| 2974 | /// [`Field::accept`] and [`Field::multiple`] are measured rather than |
| 2975 | /// deferred. A member designed against nothing is the rule to keep: count |
| 2976 | /// the sites before adding one. |
| 2977 | File, |
| 2978 | /// Which theme the app wears. |
| 2979 | /// |
| 2980 | /// The one member here that names a *subject* rather than a shape of |
| 2981 | /// answer, and it is worth saying why that is not the door it looks like. |
| 2982 | /// Every other kind is a question a screen might ask about anything; this |
| 2983 | /// one is a specific question every app in the family asks, once, on its |
| 2984 | /// settings screen, and three of them wrote the same control by hand. |
| 2985 | /// |
| 2986 | /// # It is furniture, and the measurement is what says so |
| 2987 | /// |
| 2988 | /// The reading to resist is that this is [`Select`](Self::Select) with a |
| 2989 | /// grouped option list. Max rejected that: `optgroup` appears at one live |
| 2990 | /// site in the tree and the non-theme grouping count is zero, so the thing |
| 2991 | /// that recurs is this picker rather than option lists that group. |
| 2992 | /// |
| 2993 | /// # What it carries that a select cannot |
| 2994 | /// |
| 2995 | /// [`Field::themes`] rather than [`Field::options`], because a theme is |
| 2996 | /// four facts and an option is two. The two extra facts are the ones no |
| 2997 | /// app can supply without redoing work the theme layer has already done: |
| 2998 | /// which [`ThemeVariant`] group a theme is in, and how legible its muted |
| 2999 | /// text measured. `Choice::new(id, format!("{name} ({variant})"))` is what |
| 3000 | /// the three apps had, and it flattens the group into prose and loses the |
| 3001 | /// tier entirely. |
| 3002 | /// |
| 3003 | /// [`Field::follows`] carries the entry that is not a theme. |
| 3004 | /// |
| 3005 | /// # The cost, stated rather than discovered later |
| 3006 | /// |
| 3007 | /// This puts one screen's shape into a vocabulary that otherwise holds |
| 3008 | /// none, which was the objection raised against it and accepted going in. |
| 3009 | /// The mitigation is narrowness: this describes a theme picker, not a |
| 3010 | /// general "list the host resolved" mechanism. A second host-resolved list |
| 3011 | /// is when that generalisation gets measured, and not before. |
| 3012 | /// |
| 3013 | /// A renderer that has not heard of it draws a select over |
| 3014 | /// [`Field::themes`]' names and loses the grouping, which is the state |
| 3015 | /// every app was in before this member. Degrading to the status quo ante |
| 3016 | /// is the floor the member is designed against. |
| 3017 | Theme, |
| 3018 | /// Carried through the form and never shown. |
| 3019 | Hidden, |
| 3020 | |
| 3021 | |
| 3022 | /// The wire format a [`FieldKind::Date`] value takes: ISO 8601, `YYYY-MM-DD`. |
| 3023 | /// |
| 3024 | /// A constant rather than a sentence in a doc comment, because the reason to |
| 3025 | /// name the format at all is that a host picking its own would fail silently |
| 3026 | /// against a server parsing another. A host that cannot emit the native control |
| 3027 | /// still has one spelling to meet, and can say which one it meant. |
| 3028 | pub const DATE_FORMAT: &str = "%Y-%m-%d"; |
| 3029 | |
| 3030 | /// The wire format a [`FieldKind::DateTime`] value takes: `YYYY-MM-DDTHH:MM`, |
| 3031 | /// local, carrying no zone and no seconds. |
| 3032 | /// |
| 3033 | /// [`DATE_FORMAT`]'s sibling and there for its reason. The absent zone is a |
| 3034 | /// property of the value rather than an omission: the moment is not fixed until |
| 3035 | /// something outside the description supplies one. |
| 3036 | pub const DATETIME_FORMAT: &str = "%Y-%m-%dT%H:%M"; |
| 3037 | |
| 3038 | |
| 3039 | /// Whether the value the kind takes is a moment rather than a string. |
| 3040 | /// |
| 3041 | /// Named once here for the reason [`offers_options`](Self::offers_options) |
| 3042 | /// is: two kinds answer yes, and a host that has to parse or format a value |
| 3043 | /// needs to ask without spelling the pair out at each renderer. A third |
| 3044 | /// temporal kind should land here and nowhere else. |
| 3045 | /// |
| 3046 | /// The format each one takes is [`DATE_FORMAT`] and [`DATETIME_FORMAT`]. |
| 3047 | |
| 3048 | pub const |
| 3049 | matches! |
| 3050 | |
| 3051 | |
| 3052 | /// Whether the field is drawn at all. |
| 3053 | |
| 3054 | pub const |
| 3055 | !matches! |
| 3056 | |
| 3057 | |
| 3058 | /// Whether the value must be kept out of logs and diagnostics. |
| 3059 | |
| 3060 | pub const |
| 3061 | matches! |
| 3062 | |
| 3063 | |
| 3064 | /// Where the field's own label sits. |
| 3065 | /// |
| 3066 | /// A checkbox labels itself on the right of the box; everything else takes |
| 3067 | /// a label above. Both webview apps already do this and both special-case |
| 3068 | /// it inline, which is the tell that it belongs in the description. |
| 3069 | /// |
| 3070 | /// A [`Radio`](Self::Radio) is not one of them, and the near-miss is worth |
| 3071 | /// naming: its *options* each label themselves, but the field still asks a |
| 3072 | /// question above them, so the group takes a label like everything else. |
| 3073 | |
| 3074 | pub const |
| 3075 | matches! |
| 3076 | |
| 3077 | |
| 3078 | /// Whether the kind reads [`Field::options`]. |
| 3079 | /// |
| 3080 | /// Two kinds do, so the pair is named once here rather than spelled out at |
| 3081 | /// each renderer and again in [`Field::options`]' own doc, where "every |
| 3082 | /// kind but `Select`" was true for exactly one release. A third |
| 3083 | /// option-taking kind should land here and nowhere else. |
| 3084 | |
| 3085 | pub const |
| 3086 | matches! |
| 3087 | |
| 3088 | |
| 3089 | /// Whether the kind reads [`Field::themes`] and [`Field::follows`]. |
| 3090 | /// |
| 3091 | /// One member answers yes, and it gets a name for |
| 3092 | /// [`takes_files`](Self::takes_files)'s reason rather than in spite of |
| 3093 | /// being alone: four renderers ask it before they read either member, and |
| 3094 | /// a `matches!` per renderer is where the next one goes missing. |
| 3095 | /// |
| 3096 | /// Deliberately not folded into |
| 3097 | /// [`offers_options`](Self::offers_options). A theme picker offers no |
| 3098 | /// [`Choice`]es at all, so a renderer walking `options` for it walks an |
| 3099 | /// empty slice and draws an empty control. |
| 3100 | |
| 3101 | pub const |
| 3102 | matches! |
| 3103 | |
| 3104 | |
| 3105 | /// Whether the value runs to more than one line. |
| 3106 | /// |
| 3107 | /// Named once here for [`temporal`](Self::temporal)'s reason: two kinds |
| 3108 | /// answer yes, every renderer has to ask it before it can size anything, |
| 3109 | /// and a `matches!` per renderer is the pair drifting apart one member at a |
| 3110 | /// time. What a host does with the markdown, if anything, it reads from the |
| 3111 | /// kind itself; this is only whether one line is enough. |
| 3112 | |
| 3113 | pub const |
| 3114 | matches! |
| 3115 | |
| 3116 | |
| 3117 | /// Whether the value is a file the host picks rather than a string typed |
| 3118 | /// into a box. |
| 3119 | /// |
| 3120 | /// One member answers yes, which is [`visible`](Self::visible)'s and |
| 3121 | /// [`confidential`](Self::confidential)'s footing rather than a departure |
| 3122 | /// from it: the question gets a name because three renderers ask it before |
| 3123 | /// they can read [`Field::accept`] or [`Field::multiple`], and a `matches!` |
| 3124 | /// per renderer is where a second file-taking kind would go missing. |
| 3125 | |
| 3126 | pub const |
| 3127 | matches! |
| 3128 | |
| 3129 | |
| 3130 | /// Whether the value is a quantity, so [`Field::unit`] means something. |
| 3131 | /// |
| 3132 | /// The numeric kinds and nothing else. A date is a quantity in the sense |
| 3133 | /// that it is ordered, and it is not one in the sense that matters here: |
| 3134 | /// its unit is fixed by the kind, so `Date` carrying `days` would be the |
| 3135 | /// description restating what [`kind`](Field::kind) already said. |
| 3136 | /// |
| 3137 | /// [`takes_files`](Self::takes_files)'s footing, and for its reason: the |
| 3138 | /// renderers ask this before they decide where a unit goes, and a |
| 3139 | /// `matches!` per renderer is where the next measurable kind goes missing. |
| 3140 | /// |
| 3141 | /// [`Interval`](Self::Interval) is measurable too: an axis is measured in |
| 3142 | /// something and both its ends are in it. |
| 3143 | |
| 3144 | pub const |
| 3145 | matches! |
| 3146 | |
| 3147 | |
| 3148 | |
| 3149 | /// A family of media a file can belong to. |
| 3150 | /// |
| 3151 | /// Three members, because three is what a media type's own first segment offers |
| 3152 | /// that a renderer can do anything with. `text` and `application` are families |
| 3153 | /// too and neither buys a disclosure — there is no preview of an |
| 3154 | /// `application/octet-stream` — so naming them would be a member added for a |
| 3155 | /// case nobody has. |
| 3156 | /// |
| 3157 | /// It is the answer to "which disclosure", not a validation rule. |
| 3158 | /// [`Field::accept`] is what a host filters on. |
| 3159 | |
| 3160 | |
| 3161 | |
| 3162 | /// A still picture. |
| 3163 | Image, |
| 3164 | /// Sound. |
| 3165 | Audio, |
| 3166 | /// Moving pictures, with or without sound. |
| 3167 | Video, |
| 3168 | |
| 3169 | |
| 3170 | |
| 3171 | /// The wildcard media type that means the whole family. |
| 3172 | /// |
| 3173 | /// `image/*` and its two siblings, which is what the measured sites write |
| 3174 | /// and what a webview puts in an `accept` attribute. Named here so the three |
| 3175 | /// renderers do not each spell the star. |
| 3176 | |
| 3177 | pub const |
| 3178 | match self |
| 3179 | SelfImage => "image/*", |
| 3180 | SelfAudio => "audio/*", |
| 3181 | SelfVideo => "video/*", |
| 3182 | |
| 3183 | |
| 3184 | |
| 3185 | /// The family a media type's first segment names, if it is one of these. |
| 3186 | /// |
| 3187 | /// Case-insensitive on the segment, because a media type is |
| 3188 | /// case-insensitive and half the tree writes them lowercase by habit rather |
| 3189 | /// than by rule. |
| 3190 | |
| 3191 | |
| 3192 | let = media_type.split_once?; |
| 3193 | if top.eq_ignore_ascii_case |
| 3194 | Some |
| 3195 | else if top.eq_ignore_ascii_case |
| 3196 | Some |
| 3197 | else if top.eq_ignore_ascii_case |
| 3198 | Some |
| 3199 | else |
| 3200 | None |
| 3201 | |
| 3202 | |
| 3203 | |
| 3204 | |
| 3205 | /// One entry in a file field's accept list. |
| 3206 | /// |
| 3207 | /// Three shapes rather than a string, and all three are in the measured sites: |
| 3208 | /// the MNW server writes `image/*`, `image/jpeg,image/png,image/webp`, |
| 3209 | /// `.zip,.dmg,.exe,.appimage,.deb,.tar.gz,.clap,.vst3` and, in one place, |
| 3210 | /// `.csv,text/csv`. A single string would carry all of them and answer nothing |
| 3211 | /// about any of them. |
| 3212 | /// |
| 3213 | /// # Why the list is not just a filter |
| 3214 | /// |
| 3215 | /// It is read twice. Once to decide what the picker offers, which any of the |
| 3216 | /// three shapes serves, and once to decide **which disclosure** the field gets: |
| 3217 | /// a preview for a picture, a duration or a waveform for a sound. There is one |
| 3218 | /// upload shape and a media upload is that shape with more of it shown, so the |
| 3219 | /// accept list is what says which more. [`family`](Self::family) is that |
| 3220 | /// question answered once here instead of a media-type parser in each renderer. |
| 3221 | /// |
| 3222 | /// # A suffix names no family, on purpose |
| 3223 | /// |
| 3224 | /// `.mp3` is audio in fact, and nothing here says so. A suffix-to-family table |
| 3225 | /// in a published crate is a mapping that goes stale, disagrees with the host's |
| 3226 | /// own idea of what a file is, and is wrong the first time somebody hands it a |
| 3227 | /// container. A call site that wants a picture's preview writes |
| 3228 | /// [`Family::Image`] or `image/jpeg`; a call site listing installer suffixes |
| 3229 | /// wants no disclosure anyway, which is the measured case. |
| 3230 | |
| 3231 | |
| 3232 | |
| 3233 | /// Every file of a family: `image/*` and its siblings. |
| 3234 | Family, |
| 3235 | /// One media type, written the way a media type is written: |
| 3236 | /// `image/jpeg`, `text/csv`. |
| 3237 | Type, |
| 3238 | /// One file-name suffix, written with its leading dot: `.zip`, `.tar.gz`. |
| 3239 | /// |
| 3240 | /// A suffix and not an extension, because `.tar.gz` is a measured site and |
| 3241 | /// is two dots. |
| 3242 | Suffix, |
| 3243 | |
| 3244 | |
| 3245 | |
| 3246 | /// The family this entry belongs to, when it names one. |
| 3247 | /// |
| 3248 | /// [`None`] for a [`Suffix`](Self::Suffix) and for any media type outside |
| 3249 | /// the three families, which is the honest answer rather than a missing |
| 3250 | /// one: the description did not say. |
| 3251 | |
| 3252 | |
| 3253 | match self |
| 3254 | SelfFamily => Some, |
| 3255 | SelfType => of_type, |
| 3256 | SelfSuffix => None, |
| 3257 | |
| 3258 | |
| 3259 | |
| 3260 | /// How a host that wants one string writes this entry. |
| 3261 | /// |
| 3262 | /// A webview's `accept` attribute takes exactly these spellings, and a |
| 3263 | /// terminal listing what it will take reads the same words. |
| 3264 | |
| 3265 | pub const |
| 3266 | match self |
| 3267 | SelfFamily => family.wildcard, |
| 3268 | SelfType | SelfSuffix => text, |
| 3269 | |
| 3270 | |
| 3271 | |
| 3272 | |
| 3273 | /// One option offered by a field [`FieldKind::offers_options`] accepts. |
| 3274 | /// |
| 3275 | /// Two strings, because the submitted value and the read label are different |
| 3276 | /// facts and every renderer that has tried to collapse them has had to |
| 3277 | /// un-collapse them later. `makeover-webview` invented this shape writing its |
| 3278 | /// form emitter and it is taken here unchanged; moving it down rather than |
| 3279 | /// re-deriving it is the point, since the second and third renderers were each |
| 3280 | /// going to arrive at a near-miss of it. |
| 3281 | /// `#[non_exhaustive]`, which every type here that a renderer matches or builds |
| 3282 | /// carries. Without it a new member is a breaking change at every literal site |
| 3283 | /// in the tree. |
| 3284 | |
| 3285 | |
| 3286 | |
| 3287 | /// What is submitted. |
| 3288 | pub value: &'a str, |
| 3289 | /// What is read. |
| 3290 | pub label: &'a str, |
| 3291 | /// Why it cannot be picked right now, when it cannot. |
| 3292 | /// |
| 3293 | /// One member rather than an `available: bool` beside a reason, and the |
| 3294 | /// conflation is the point: an option greyed out with no explanation is a |
| 3295 | /// dead end the user cannot act on, and it is exactly the state the app |
| 3296 | /// that found this gap had to patch by hand with a line of prose under the |
| 3297 | /// control. Making the reason mandatory means the description cannot say |
| 3298 | /// the useless half. |
| 3299 | /// |
| 3300 | /// The option stays in the list. Dropping it is what an app does today, and |
| 3301 | /// it costs the user the knowledge that the thing exists at all — |
| 3302 | /// audiofiles' multi-sample mode appears on its own once a second sample is |
| 3303 | /// dropped, so a user who never sees it never learns what to drop. |
| 3304 | /// |
| 3305 | /// **Not [`Field::error`], and not [`Field::hint`].** An error is about the |
| 3306 | /// answer and a hint is standing help for the whole question; this is about |
| 3307 | /// one option among several, which is the level neither of those reaches. |
| 3308 | /// |
| 3309 | /// **Not disabled-the-state.** `State::Disabled` is about a whole field |
| 3310 | /// refusing to answer. This says the field is live and one of its answers |
| 3311 | /// is not available yet, which is a different sentence and the reason the |
| 3312 | /// tone rule matters here: the *other* options are still usable. |
| 3313 | pub unavailable: , |
| 3314 | /// The line under the label that says what picking this means. |
| 3315 | /// |
| 3316 | /// A choice between three plans is a choice nobody can make from three |
| 3317 | /// names, and until this existed the description had nowhere to put the |
| 3318 | /// sentence that made it makeable. What the corpus did instead is the |
| 3319 | /// tell: four of the six measured sites fold it into the label — |
| 3320 | /// `<strong>Public</strong>: Anyone can see this repository` in MNW's git |
| 3321 | /// settings, the same shape in its project-basics AI tier and its cart's |
| 3322 | /// currency conversion, and `Mislabeled (wrong AI tier or category)` in |
| 3323 | /// its report modal. The described screens do it too, in miniature: `Every |
| 3324 | /// 15 minutes (recommended)`, `Reference samples in place (loose-files |
| 3325 | /// mode)`. One fact, six spellings, no member. |
| 3326 | /// |
| 3327 | /// # Where it goes is the host's, and the rule already exists |
| 3328 | /// |
| 3329 | /// This is [`unavailable`](Self::unavailable)'s question met a third time |
| 3330 | /// and it takes the same answer, which is the strongest evidence one member |
| 3331 | /// is right rather than two. A radio group has room and gives the line its |
| 3332 | /// own element beside the label. A `<select>`'s option takes no elements, |
| 3333 | /// no second line and no title a keyboard reaches, so the line runs into |
| 3334 | /// the option's own text — exactly as a precondition does, and as a theme's |
| 3335 | /// contrast badge does in brackets. A terminal has rows and puts it on one |
| 3336 | /// under the option. |
| 3337 | /// |
| 3338 | /// # Not a price, and that is a measurement rather than a preference |
| 3339 | /// |
| 3340 | /// The site that asked for this is MNW's fee calculator, whose tier cards |
| 3341 | /// carry a name, a price *and* a description, so a second member for the |
| 3342 | /// price was on the table. It loses on the count: the tree's other three |
| 3343 | /// priced tier lists — `project.html`, `project_paywall.html`, |
| 3344 | /// `index.html` — are not option lists at all. Each card carries its own |
| 3345 | /// submit, which makes it a region with a heading, a fact and an act, and |
| 3346 | /// it is sayable already. So a price member would have exactly one |
| 3347 | /// consumer, and it would mean this crate growing a money type it does not |
| 3348 | /// have: [`Unit`] is a time axis, and every amount in the described tree is |
| 3349 | /// text. |
| 3350 | /// |
| 3351 | /// The price therefore leads the line: `$24/mo. 2GB/file, 100GB total. |
| 3352 | /// Fits audio, plugins, binaries.` What would reopen it is a **second** |
| 3353 | /// priced option list, not a judgement about how that reads. |
| 3354 | /// |
| 3355 | /// # What it is not |
| 3356 | /// |
| 3357 | /// Not [`unavailable`](Self::unavailable), which says the option cannot be |
| 3358 | /// picked. This says what it means to pick it, and the two are drawn |
| 3359 | /// together on an option that carries both: the description that says a |
| 3360 | /// tier is out of stock *and* what the tier is has said two things. |
| 3361 | /// |
| 3362 | /// Not [`Field::hint`], which is standing help for the whole question, and |
| 3363 | /// not markup. One line of plain text, for [`Candidate::detail`]'s reason: |
| 3364 | /// an option list is a place a renderer lays out, and a description that |
| 3365 | /// put a block in one would be handing every host a layout problem for the |
| 3366 | /// benefit of one. |
| 3367 | pub detail: , |
| 3368 | |
| 3369 | |
| 3370 | |
| 3371 | /// An option whose submitted value is also its label. |
| 3372 | |
| 3373 | pub const |
| 3374 | Selfnew |
| 3375 | |
| 3376 | |
| 3377 | /// An option that submits one string and reads as another. |
| 3378 | /// |
| 3379 | /// A constructor rather than a literal, which is what `#[non_exhaustive]` |
| 3380 | /// costs and buys: outside this crate the struct cannot be built by naming |
| 3381 | /// its members, so every call site goes through here and the next member |
| 3382 | /// added breaks none of them. |
| 3383 | |
| 3384 | pub const |
| 3385 | Self |
| 3386 | value, |
| 3387 | label, |
| 3388 | unavailable: None, |
| 3389 | detail: None, |
| 3390 | |
| 3391 | |
| 3392 | |
| 3393 | /// The same option, not pickable yet, and why. |
| 3394 | /// |
| 3395 | /// Builder-shaped because the reason is the rare case: 39 of the 40 option |
| 3396 | /// sites measured across the tree do not have one. |
| 3397 | |
| 3398 | pub const |
| 3399 | self.unavailable = Some; |
| 3400 | self |
| 3401 | |
| 3402 | |
| 3403 | /// The same option, with the line that says what picking it means. |
| 3404 | /// |
| 3405 | /// Builder-shaped for [`unless`](Self::unless)'s reason, and it is the |
| 3406 | /// commoner of the two: six measured sites want this and one wants a |
| 3407 | /// precondition. See [`detail`](Self::detail). |
| 3408 | |
| 3409 | pub const |
| 3410 | self.detail = Some; |
| 3411 | self |
| 3412 | |
| 3413 | |
| 3414 | /// Whether the option can be picked right now. |
| 3415 | /// |
| 3416 | /// The predicate a renderer branches on, so that "unavailable" is read as |
| 3417 | /// one condition in one place rather than as `unavailable.is_some()` at |
| 3418 | /// three renderers, one of which will invert it. |
| 3419 | |
| 3420 | pub const |
| 3421 | self.unavailable.is_none |
| 3422 | |
| 3423 | |
| 3424 | |
| 3425 | /// One entry in a field's suggestion list. |
| 3426 | /// |
| 3427 | /// A suggestion-only type rather than a fourth member on [`Choice`], ruled by |
| 3428 | /// Max. The two are near-identical and that is the accepted drift risk, so the |
| 3429 | /// mitigation is written here: **an |
| 3430 | /// option and a candidate are submitted the same way and read differently.** |
| 3431 | /// An option is a thing you pick from a known set, and the set is the whole of |
| 3432 | /// what there is. A candidate is a thing you are being *oriented* toward out of |
| 3433 | /// a set nobody can see, which is why it carries [`detail`](Self::detail) and |
| 3434 | /// an option does not. |
| 3435 | /// |
| 3436 | /// This reverses a position quasi-router stated in its own doc, that a |
| 3437 | /// candidate is [`Choice`] "because a candidate is submitted under one string |
| 3438 | /// and read under another, which is what an option is". True and not |
| 3439 | /// sufficient: how a thing is submitted was never the half that differed. |
| 3440 | /// |
| 3441 | /// # Why the second string is not folded into the label |
| 3442 | /// |
| 3443 | /// Because every renderer wants it separately, and the two measured sites both |
| 3444 | /// draw it by hand today. The MNW server's tag box computes its context as the |
| 3445 | /// parent path -- "the parent path orients an otherwise ambiguous leaf: |
| 3446 | /// 'Format' appears under audio, software, writing, and video" -- and a list of |
| 3447 | /// four identical rows reading "Format" is not a usable list. In a webview the |
| 3448 | /// second string is styled differently, in a terminal it wants the remaining |
| 3449 | /// columns rather than a dash, and in neither is it part of what the typed |
| 3450 | /// value matches against. `Choice::new(slug, format!("{label} - {context}"))` |
| 3451 | /// loses all three of those facts, which is the condition this type exists to |
| 3452 | /// end. |
| 3453 | /// |
| 3454 | /// # No `unavailable` |
| 3455 | /// |
| 3456 | /// [`Choice::unavailable`] has no counterpart here, and the omission is the |
| 3457 | /// implementer's call recorded rather than an oversight. A suggestion that |
| 3458 | /// cannot be picked is arguably not a suggestion: an option list is a fixed set |
| 3459 | /// a user is owed an explanation about, and a candidate list is whatever a |
| 3460 | /// route decided to offer, so a route with nothing to say simply does not offer |
| 3461 | /// the row. Add it if a measured site ever wants it. |
| 3462 | /// |
| 3463 | /// # What it does not carry, and where that lives |
| 3464 | /// |
| 3465 | /// What *happens* when a candidate is picked. Picking is local by default -- it |
| 3466 | /// writes [`value`](Self::value) into the field that owns the list -- and a |
| 3467 | /// candidate that does something else says so with an action. An action is not |
| 3468 | /// a word this crate has, exactly as [`Field`] here has no `suggests` member, |
| 3469 | /// so both live on the router's owned mirror of this type. |
| 3470 | /// |
| 3471 | /// `#[non_exhaustive]` from birth. Non-negotiable: adding it later means a |
| 3472 | /// breaking change at every literal site in the tree. |
| 3473 | |
| 3474 | |
| 3475 | |
| 3476 | /// What is submitted, and what picking writes into the field. |
| 3477 | pub value: &'a str, |
| 3478 | /// What is read. |
| 3479 | pub label: &'a str, |
| 3480 | /// The second line: what orients this candidate among rows that read alike. |
| 3481 | /// |
| 3482 | /// Optional because a candidate list whose labels are already distinct |
| 3483 | /// wants nothing here, and a renderer given [`None`] draws one line rather |
| 3484 | /// than an empty second one. |
| 3485 | pub detail: , |
| 3486 | |
| 3487 | |
| 3488 | |
| 3489 | /// A candidate whose submitted value is also its label. |
| 3490 | |
| 3491 | pub const |
| 3492 | Selfnew |
| 3493 | |
| 3494 | |
| 3495 | /// A candidate that submits one string and reads as another. |
| 3496 | /// |
| 3497 | /// A constructor rather than a literal, which is what `#[non_exhaustive]` |
| 3498 | /// costs and buys: outside this crate the struct cannot be built by naming |
| 3499 | /// its members, so every call site goes through here and the next member |
| 3500 | /// added breaks none of them. |
| 3501 | |
| 3502 | pub const |
| 3503 | Self |
| 3504 | value, |
| 3505 | label, |
| 3506 | detail: None, |
| 3507 | |
| 3508 | |
| 3509 | |
| 3510 | /// The same candidate, with the line that tells it from its neighbours. |
| 3511 | |
| 3512 | pub const |
| 3513 | self.detail = Some; |
| 3514 | self |
| 3515 | |
| 3516 | |
| 3517 | |
| 3518 | /// Which ambient mode a theme is written for. |
| 3519 | /// |
| 3520 | /// The vocabulary's own spelling of what `makeover` calls a theme's variant, |
| 3521 | /// and the duplication is deliberate rather than an oversight. This crate has |
| 3522 | /// no dependencies by charter — it emits nothing, reads nothing and resolves |
| 3523 | /// nothing — so it cannot take the crate that owns the file format, and a |
| 3524 | /// renderer that must group a picker needs the three groups as values. |
| 3525 | /// |
| 3526 | /// The two are kept in step by the app that converts between them, which is a |
| 3527 | /// three-arm `match` at each adopter and the price of the layering. If a fourth |
| 3528 | /// mode is ever authored, this enum and `makeover::Variant` move together. |
| 3529 | /// |
| 3530 | /// Three, not two: one shipped theme is high contrast, and an app matching on |
| 3531 | /// light-or-dark alone files it under the wrong one. |
| 3532 | |
| 3533 | |
| 3534 | |
| 3535 | /// Written for a light ambient mode. |
| 3536 | Light, |
| 3537 | /// Written for a dark ambient mode. |
| 3538 | Dark, |
| 3539 | /// Written to be legible before it is pretty. |
| 3540 | HighContrast, |
| 3541 | |
| 3542 | |
| 3543 | |
| 3544 | /// The machine spelling, matching the theme file's own `meta.variant`. |
| 3545 | /// |
| 3546 | /// A data attribute, a stored value, a test assertion. Not a heading: what |
| 3547 | /// a group is *called* on screen is [`heading`](Self::heading). |
| 3548 | |
| 3549 | pub const |
| 3550 | match self |
| 3551 | Light => "light", |
| 3552 | Dark => "dark", |
| 3553 | HighContrast => "high-contrast", |
| 3554 | |
| 3555 | |
| 3556 | |
| 3557 | /// What the group of themes in this variant is called on screen. |
| 3558 | /// |
| 3559 | /// Here rather than at each renderer, which is the whole argument for the |
| 3560 | /// member existing: three renderers picking their own headings is one |
| 3561 | /// picker reading three ways, and the spellings below are the ones |
| 3562 | /// goingson's shipped picker used before it was described. |
| 3563 | |
| 3564 | pub const |
| 3565 | match self |
| 3566 | Light => "Light", |
| 3567 | Dark => "Dark", |
| 3568 | HighContrast => "High Contrast", |
| 3569 | |
| 3570 | |
| 3571 | |
| 3572 | |
| 3573 | |
| 3574 | |
| 3575 | f.write_str |
| 3576 | |
| 3577 | |
| 3578 | |
| 3579 | /// How legible a theme measured, as a picker reports it. |
| 3580 | /// |
| 3581 | /// A measurement carried into the description, which is unusual here and is the |
| 3582 | /// one case that earns it: the number comes off the theme's resolved colours, |
| 3583 | /// so the layer that loaded the theme is the only party that has it, and an app |
| 3584 | /// re-deriving it would be parsing every theme file a second time to learn what |
| 3585 | /// was already known. What a renderer does with it is a badge beside the name. |
| 3586 | /// |
| 3587 | /// Ordered worst-first, matching `makeover::ContrastTier`, so the two sort the |
| 3588 | /// same way and an adopter's `match` cannot invert an ordering by accident. |
| 3589 | |
| 3590 | |
| 3591 | |
| 3592 | /// Muted text below the 3:1 floor for large text and UI parts. |
| 3593 | Low, |
| 3594 | /// Muted text clears 3:1 but not the 4.5:1 bar for normal text. |
| 3595 | Standard, |
| 3596 | /// Muted text meets WCAG AA on every panel ground. |
| 3597 | High, |
| 3598 | |
| 3599 | |
| 3600 | |
| 3601 | /// The machine spelling, for a data attribute or a test. |
| 3602 | |
| 3603 | pub const |
| 3604 | match self |
| 3605 | Low => "low", |
| 3606 | Standard => "standard", |
| 3607 | High => "high", |
| 3608 | |
| 3609 | |
| 3610 | |
| 3611 | /// The short mark shown beside a theme's name. |
| 3612 | /// |
| 3613 | /// One spelling for the tree, for [`ThemeVariant::heading`]'s reason. These |
| 3614 | /// are the marks audiofiles shipped before its picker was described, which |
| 3615 | /// is the only implementation that ever drew them. |
| 3616 | /// |
| 3617 | /// [`Standard`](Self::Standard) is not the absence of a mark: a reader |
| 3618 | /// scanning a column of badges learns more from three marks than from two |
| 3619 | /// and a gap, and "OK" is the honest reading of a theme that clears the UI |
| 3620 | /// floor and misses the text one. |
| 3621 | |
| 3622 | pub const |
| 3623 | match self |
| 3624 | Low => "low", |
| 3625 | Standard => "OK", |
| 3626 | High => "AA", |
| 3627 | |
| 3628 | |
| 3629 | |
| 3630 | |
| 3631 | |
| 3632 | |
| 3633 | f.write_str |
| 3634 | |
| 3635 | |
| 3636 | |
| 3637 | /// One theme, as a picker offers it. |
| 3638 | /// |
| 3639 | /// Four facts where a [`Choice`] has two, and the two extra ones are why this |
| 3640 | /// is its own type rather than options with the variant folded into the label. |
| 3641 | /// Both are facts the theme layer resolved and neither survives being written |
| 3642 | /// into a string: a group is structure and a badge is a second column. |
| 3643 | /// |
| 3644 | /// # No `unavailable` |
| 3645 | /// |
| 3646 | /// [`Choice::unavailable`]'s counterpart is absent for its own sibling's |
| 3647 | /// reason. A theme that is installed can be picked, and a theme that is not |
| 3648 | /// installed is not in the list. There is no third state for a reason to |
| 3649 | /// explain. |
| 3650 | /// |
| 3651 | /// `#[non_exhaustive]` from birth, so a new member costs no call site. |
| 3652 | |
| 3653 | |
| 3654 | |
| 3655 | /// What is submitted, and what the app stores. |
| 3656 | pub id: &'a str, |
| 3657 | /// What is read. |
| 3658 | pub name: &'a str, |
| 3659 | /// Which group it belongs to. |
| 3660 | pub variant: ThemeVariant, |
| 3661 | /// How legible its muted text measured. |
| 3662 | pub contrast: Contrast, |
| 3663 | |
| 3664 | |
| 3665 | |
| 3666 | /// A theme, with everything a picker needs to place and mark it. |
| 3667 | /// |
| 3668 | /// Every fact is an argument and none is a builder, which is the opposite |
| 3669 | /// of [`Choice`]'s arrangement and is deliberate: a theme missing its |
| 3670 | /// variant has no group to sit in and a theme missing its tier has no badge |
| 3671 | /// to draw, so both are the control rather than embellishments on it. The |
| 3672 | /// same reasoning [`Field::range`] applies to its bounds. |
| 3673 | |
| 3674 | pub const |
| 3675 | id: &'a str, |
| 3676 | name: &'a str, |
| 3677 | variant: ThemeVariant, |
| 3678 | contrast: Contrast, |
| 3679 | |
| 3680 | Self |
| 3681 | id, |
| 3682 | name, |
| 3683 | variant, |
| 3684 | contrast, |
| 3685 | |
| 3686 | |
| 3687 | |
| 3688 | |
| 3689 | /// One field of a form. |
| 3690 | /// |
| 3691 | /// Borrowed rather than owned: a description is built, read once by a renderer, |
| 3692 | /// and dropped. Nothing here outlives the screen it describes. |
| 3693 | /// |
| 3694 | /// # What it carries, and what it does not |
| 3695 | /// |
| 3696 | /// Stated here so the next renderer does not re-ask, which is what the first |
| 3697 | /// two both did. It carries everything a renderer needs to *draw* the field: |
| 3698 | /// its kind, what it is called, what it is asked for, its standing help, what |
| 3699 | /// is wrong with it now, whether it is compulsory, whether it hides behind a |
| 3700 | /// disclosure, its ghost text, and the options it offers. |
| 3701 | /// |
| 3702 | /// It does not carry the **current value**, and it is not going to. That is the |
| 3703 | /// one thing here that is genuinely renderer state: a webview reads it back out |
| 3704 | /// of the DOM, an immediate-mode renderer holds a `&mut` to the app's own field |
| 3705 | /// and writes through it, and a terminal keeps an edit buffer. A description |
| 3706 | /// that carried the value would have to carry a way to write it back, at which |
| 3707 | /// point it is a form model and no longer a description. |
| 3708 | /// |
| 3709 | /// **Constraints** are here and enforcement is not, which is one line rather |
| 3710 | /// than two. [`required`], [`max_length`], [`min`] and [`max`] are facts about |
| 3711 | /// the *question*, so a renderer can emit its host's idiom for each — an HTML |
| 3712 | /// attribute, a marked label, a clamped spinner — and the platform helps the |
| 3713 | /// user before anything is submitted. Deciding that a value is wrong stays with |
| 3714 | /// whoever validated, and [`error`] is that decision arriving back. |
| 3715 | /// |
| 3716 | /// The set stops before `pattern`, and stops there on both tests at once. A |
| 3717 | /// regex has an honest answer in a webview and none anywhere else: egui would |
| 3718 | /// have to run it per keystroke and decide what a half-typed value means, |
| 3719 | /// which is enforcement wearing description's clothes. And it is one site in |
| 3720 | /// goingson and none in Balanced Breakfast, against 8 and 1 for `maxlength`. |
| 3721 | /// |
| 3722 | /// [`error`]: Field::error |
| 3723 | /// [`required`]: Field::required |
| 3724 | /// [`max_length`]: Field::max_length |
| 3725 | /// [`min`]: Field::min |
| 3726 | /// [`max`]: Field::max |
| 3727 | /// How a slider's position becomes its value, and how finely it moves. |
| 3728 | /// |
| 3729 | /// **The data of a slider is a fraction and a function taking numbers to |
| 3730 | /// numbers.** Stated by Max, and it is what [`min`](Field::min) and |
| 3731 | /// [`max`](Field::max) are not: they were never the control's extent. |
| 3732 | /// A slider's extent is always 0 to 1 — a thumb at 40% of a track — and the |
| 3733 | /// bounds are `f(0)` and `f(1)`. Linear is the constant-slope case, which is |
| 3734 | /// exactly why nobody noticed the function was there: when `f` is |
| 3735 | /// `min + t * (max - min)` the extent and the bounds coincide numerically and |
| 3736 | /// the mapping is invisible. |
| 3737 | /// |
| 3738 | /// So this is not a scale flag bolted onto a range. Every range described |
| 3739 | /// before it had a mapping, and four renderers each hard-coded the same one. |
| 3740 | /// |
| 3741 | /// # Why a closed family and not a function |
| 3742 | /// |
| 3743 | /// `fn(f64) -> f64` is the literal reading and it does not survive the |
| 3744 | /// description boundary. A fn pointer cannot be emitted into a browser, and it |
| 3745 | /// cannot be compared or hashed in a way that means anything, which this struct |
| 3746 | /// needs. A named family is the same semantics with arbitrary closures given |
| 3747 | /// up, and nothing measured wants one: the tree has a single non-linear shape |
| 3748 | /// across five controls and no second shape at all. |
| 3749 | /// |
| 3750 | /// # Why the step is here |
| 3751 | /// |
| 3752 | /// Max, in the same breath: if the family is prescriptive anyway, the step |
| 3753 | /// spacing belongs in it. On a slider the granularity and the mapping are one |
| 3754 | /// decision — a curve chosen without saying how finely it moves is half an |
| 3755 | /// answer — and holding them apart is what let a 0-to-1 threshold ship as a |
| 3756 | /// two-position control, since the host default of 1 was applied to a mapping |
| 3757 | /// nobody had named. It also un-overloads [`Field::step`], which stays as it |
| 3758 | /// was for a *typed* value, where there is no mapping and the granularity is a |
| 3759 | /// plain fact about the number. |
| 3760 | /// |
| 3761 | /// A future curve carrying a fact of its own — an exponent, an inflection — |
| 3762 | /// puts it in its own variant rather than on the struct, which is the second |
| 3763 | /// reason this shape is right. |
| 3764 | /// |
| 3765 | /// **The step is in the value's own units under every curve.** What a curve |
| 3766 | /// changes is the mapping, not the units the granularity is measured in: a step |
| 3767 | /// of `0.001` on an envelope time is three decimals whether the track is |
| 3768 | /// logarithmic or not, and a renderer that reads the step for display precision |
| 3769 | /// keeps reading it the same way. |
| 3770 | |
| 3771 | |
| 3772 | |
| 3773 | /// Constant slope: `f(t) = min + t * (max - min)`. |
| 3774 | /// |
| 3775 | /// What every described range meant before this enum existed, and the |
| 3776 | /// default, so a site that says nothing is correct unchanged. |
| 3777 | Linear |
| 3778 | /// The granularity, in the value's own units. `None` is the host's own. |
| 3779 | step: , |
| 3780 | , |
| 3781 | /// Constant ratio: `f(t) = min * (max / min).powf(t)`. |
| 3782 | /// |
| 3783 | /// The mapping for a question whose extent spans orders of magnitude and |
| 3784 | /// whose interesting half is the small end. audiofiles' envelope times run |
| 3785 | /// 0.001 to 5 seconds, where a 5 ms attack and a 50 ms attack are audibly |
| 3786 | /// different instruments and a linear track puts both inside its first one |
| 3787 | /// percent. |
| 3788 | /// |
| 3789 | /// # It needs positive bounds |
| 3790 | /// |
| 3791 | /// A constant ratio is undefined across zero, so this asks for `min > 0`. |
| 3792 | /// A range that does not have that is mapped [`Linear`](Self::Linear)ly |
| 3793 | /// instead — see [`value_at`](Self::value_at). Stated rather than enforced, |
| 3794 | /// the way every other constraint in this crate is, and it is not a |
| 3795 | /// hypothetical: an envelope's sustain is a 0-to-1 level and is linear for |
| 3796 | /// this reason rather than by oversight. |
| 3797 | Logarithmic |
| 3798 | /// The granularity, in the value's own units. `None` is the host's own. |
| 3799 | step: , |
| 3800 | , |
| 3801 | |
| 3802 | |
| 3803 | |
| 3804 | |
| 3805 | SelfLinear |
| 3806 | |
| 3807 | |
| 3808 | |
| 3809 | |
| 3810 | /// The granularity this curve moves in, whichever curve it is. |
| 3811 | /// |
| 3812 | /// Every variant carries one, so reading it does not need a match at each |
| 3813 | /// of the four renderers. |
| 3814 | |
| 3815 | pub const |
| 3816 | // No wildcard: `#[non_exhaustive]` binds downstream, not here, so a |
| 3817 | // curve added later has to answer this rather than fall through to a |
| 3818 | // granularity nobody chose. |
| 3819 | match self |
| 3820 | SelfLinear | SelfLogarithmic => step, |
| 3821 | |
| 3822 | |
| 3823 | |
| 3824 | /// Whether this curve maps as a constant ratio *given these bounds*. |
| 3825 | /// |
| 3826 | /// The bounds are the argument because [`Logarithmic`](Self::Logarithmic) |
| 3827 | /// is a request rather than a guarantee: it needs `0 < min < max`, and a |
| 3828 | /// range that does not have that is drawn linearly. A renderer asks this |
| 3829 | /// instead of matching on the variant, so the fallback is decided in one |
| 3830 | /// place rather than four. |
| 3831 | |
| 3832 | |
| 3833 | matches! && min > 0.0 && max > min |
| 3834 | |
| 3835 | |
| 3836 | /// The value at a position along the track, where `position` is 0 to 1. |
| 3837 | /// |
| 3838 | /// `f`. The whole point of the type, and it lives here rather than in each |
| 3839 | /// renderer so that a terminal's bar, an egui slider and a browser's input |
| 3840 | /// cannot disagree about where a value sits. |
| 3841 | /// |
| 3842 | /// A position outside 0 to 1 is clamped, and bounds that are equal or |
| 3843 | /// inverted give `min` back: a track with no extent has one value on it. |
| 3844 | |
| 3845 | |
| 3846 | let position = position.clamp; |
| 3847 | // NaN named rather than fallen through: `max <= min` is false for a NaN |
| 3848 | // bound, so without it a track with no numbers on it would be mapped as |
| 3849 | // if it had two. |
| 3850 | if max <= min || min.is_nan || max.is_nan |
| 3851 | return min; |
| 3852 | |
| 3853 | if self.is_ratio |
| 3854 | min * .powf |
| 3855 | else |
| 3856 | position.mul_add |
| 3857 | |
| 3858 | |
| 3859 | |
| 3860 | /// The position a value sits at, where the answer is 0 to 1. |
| 3861 | /// |
| 3862 | /// `f` inverted, which is what a renderer needs to *draw* a value it was |
| 3863 | /// handed. Same clamping and the same degenerate answer as |
| 3864 | /// [`value_at`](Self::value_at). |
| 3865 | |
| 3866 | |
| 3867 | if max <= min || min.is_nan || max.is_nan |
| 3868 | return 0.0; |
| 3869 | |
| 3870 | let value = value.clamp; |
| 3871 | let position = if self.is_ratio |
| 3872 | .ln / .ln |
| 3873 | else |
| 3874 | / |
| 3875 | ; |
| 3876 | position.clamp |
| 3877 | |
| 3878 | |
| 3879 | |
| 3880 | |
| 3881 | |
| 3882 | /// What kind of value it takes. |
| 3883 | pub kind: FieldKind, |
| 3884 | /// The name the value is submitted under. |
| 3885 | /// |
| 3886 | /// The *lower* end's name for a [`FieldKind::Interval`], whose upper end is |
| 3887 | /// [`upper_name`](Self::upper_name). Every other kind submits one value and |
| 3888 | /// this is the whole of it. |
| 3889 | pub name: &'a str, |
| 3890 | /// The name a [`FieldKind::Interval`]'s upper end is submitted under. |
| 3891 | /// |
| 3892 | /// [`None`] for every other kind, and sayable-and-ignored there the way |
| 3893 | /// [`options`](Self::options) is on a kind that offers none. |
| 3894 | /// |
| 3895 | /// Stated rather than derived from [`name`](Self::name), and |
| 3896 | /// [`FieldKind::Interval`] carries the measurement that decided it: the two |
| 3897 | /// sites in this tree disagree about affix order, so a derived rule would |
| 3898 | /// rename one of them. Which member a name sits in is also what says which |
| 3899 | /// end it is, so nothing separate carries the direction. |
| 3900 | /// |
| 3901 | /// An interval missing it is an interval with one end that can be submitted, |
| 3902 | /// which is a description a renderer may draw honestly and no better than |
| 3903 | /// that. [`Field::interval`] is what makes forgetting it unsayable, on the |
| 3904 | /// same footing as [`Field::range`] and its bounds. |
| 3905 | pub upper_name: , |
| 3906 | /// What the user is asked for. |
| 3907 | pub label: &'a str, |
| 3908 | /// Standing help, shown whether or not anything is wrong. |
| 3909 | pub hint: , |
| 3910 | /// What is currently wrong with the value. |
| 3911 | pub error: , |
| 3912 | /// A consequence of the answer the user has given, carrying its own tone. |
| 3913 | /// |
| 3914 | /// The third message channel, between [`hint`](Self::hint) and |
| 3915 | /// [`error`](Self::error) and overlapping neither. A hint is standing help |
| 3916 | /// that does not depend on the value; an error says the value is not |
| 3917 | /// acceptable. A note is the case in the middle: the value is perfectly |
| 3918 | /// acceptable and choosing it costs something the user should know about. |
| 3919 | /// |
| 3920 | /// The first consumer is audiofiles' export Format field, where choosing |
| 3921 | /// WAV or AIFF over Original re-encodes and silently drops embedded BWF, |
| 3922 | /// iXML, loop points, cue markers and ID3. That is not a validation |
| 3923 | /// failure and it is not standing help — it is true of one answer to one |
| 3924 | /// question — and it was hand-drawn in the app's own draw callback for |
| 3925 | /// want of anywhere to say it. |
| 3926 | /// |
| 3927 | /// The tone is carried rather than fixed at [`Tone::Warning`] because the |
| 3928 | /// channel is not only for warnings: the same slot says "this is the |
| 3929 | /// recommended one" ([`Tone::Success`]) and "this is what that setting |
| 3930 | /// implies" ([`Tone::Info`]). A renderer gets the announcement behaviour |
| 3931 | /// off the tone for free — makeover-webview emits `data-tone` and treats |
| 3932 | /// Warning and Danger as assertive for `aria-live`. |
| 3933 | /// |
| 3934 | /// It does **not** make the field invalid. [`invalid`](Self::invalid) stays |
| 3935 | /// `error.is_some()`, so a note never marks the group as a problem. |
| 3936 | /// |
| 3937 | /// # Precedence, for a renderer with room for one |
| 3938 | /// |
| 3939 | /// Error, then note, then hint. A renderer that shows every message shows |
| 3940 | /// them in that order too. makeover-tui is the one with room for exactly |
| 3941 | /// one line, and it is why the order is decided here rather than three |
| 3942 | /// times: what is wrong outranks what it costs, which outranks how it |
| 3943 | /// works. |
| 3944 | pub note: , |
| 3945 | /// Ghost text shown while the field is empty. |
| 3946 | /// |
| 3947 | /// User-facing text, and it sits with `label` and `hint` rather than with |
| 3948 | /// the value because it is a property of the *question* and not of the |
| 3949 | /// answer. |
| 3950 | /// |
| 3951 | /// Not a substitute for a label. A field labelled only by its placeholder |
| 3952 | /// loses its label the moment anything is typed, and no renderer here can |
| 3953 | /// make that not happen, so the description keeps both. |
| 3954 | pub placeholder: , |
| 3955 | /// The options offered, in the order they are offered. |
| 3956 | /// |
| 3957 | /// Empty for every kind [`FieldKind::offers_options`] rejects. A field |
| 3958 | /// described with no options is sayable on purpose: it is what an app with |
| 3959 | /// an unfinished-loading option list actually has, and a renderer showing |
| 3960 | /// an empty control says so on screen rather than in a log. |
| 3961 | /// |
| 3962 | /// Which option is *current* is not here. That is the value, and the value |
| 3963 | /// is renderer state. |
| 3964 | pub options: &'a [], |
| 3965 | /// The themes offered, in the order they are offered. |
| 3966 | /// |
| 3967 | /// Empty for every kind [`FieldKind::offers_themes`] rejects, and sayable |
| 3968 | /// as empty for the one that accepts it: an app whose theme directories |
| 3969 | /// hold nothing has a picker offering only [`follows`](Self::follows), |
| 3970 | /// which is a true description of that machine. |
| 3971 | /// |
| 3972 | /// **The order is the grouping.** Entries arrive sorted by |
| 3973 | /// [`ThemeVariant`] and then by [`Contrast`] within each variant, so a |
| 3974 | /// renderer that draws headings walks the run of one variant and a renderer |
| 3975 | /// that cannot still gets the useful order. Handing back groups would force |
| 3976 | /// the second renderer to flatten what the first wanted. |
| 3977 | /// |
| 3978 | /// Nothing here sorts. The description carries the order it was given, and |
| 3979 | /// the sort belongs with whoever measured the tiers — `makeover::theme_options` |
| 3980 | /// is what produces it, and re-sorting here would be this crate deciding a |
| 3981 | /// question it cannot see the inputs to. |
| 3982 | /// |
| 3983 | /// Which theme is *current* is not here. That is the value, and the value |
| 3984 | /// is renderer state, exactly as it is for [`options`](Self::options). |
| 3985 | pub themes: &'a [], |
| 3986 | /// The entry that follows the ambient mode instead of naming a theme. |
| 3987 | /// |
| 3988 | /// [`None`] for a picker that does not offer one, which is a real answer: |
| 3989 | /// an app whose host has no ambient mode to follow should not offer a row |
| 3990 | /// that does nothing. |
| 3991 | /// |
| 3992 | /// A [`Choice`] rather than a bare label, because the *value* is the app's. |
| 3993 | /// Every store in the family spells it `system` today and none of them is |
| 3994 | /// obliged to; a description that hardcoded the spelling would be this |
| 3995 | /// crate holding a fact about somebody else's config table. |
| 3996 | /// |
| 3997 | /// It is not a [`ThemeChoice`] with an absent variant. Following is a |
| 3998 | /// standing instruction that resolves differently as the desktop flips, and |
| 3999 | /// a theme id is an answer that does not — which is the distinction |
| 4000 | /// `makeover::ThemeSelection` exists to hold, carried here rather than |
| 4001 | /// blurred. |
| 4002 | pub follows: , |
| 4003 | /// What a file field takes, in the order a host offering the list shows it. |
| 4004 | /// |
| 4005 | /// Empty for every kind [`FieldKind::takes_files`] rejects, and empty is |
| 4006 | /// also a real answer for one that accepts it: a field that takes any file |
| 4007 | /// says so by listing nothing, which is what an `<input type="file">` with |
| 4008 | /// no `accept` does and what most of the measured sites are. |
| 4009 | /// |
| 4010 | /// It is a filter and it is the disclosure cue, and [`Accepted`]'s doc |
| 4011 | /// carries which reading is which. Nothing here validates: a host may hand |
| 4012 | /// back a file the list does not cover, exactly as a browser does when the |
| 4013 | /// user switches the picker to "All Files", and deciding a value is wrong |
| 4014 | /// stays with whoever validated. |
| 4015 | pub accept: &'a [], |
| 4016 | /// Whether more than one file may be picked at once. |
| 4017 | /// |
| 4018 | /// Only [`FieldKind::takes_files`] reads it. A multi-valued answer to any |
| 4019 | /// other question is a different shape — a set of options, a repeated |
| 4020 | /// group — and neither is this flag with a different kind beside it. |
| 4021 | /// |
| 4022 | /// False is the common case: 4 of the MNW server's 16 file inputs carry it. |
| 4023 | pub multiple: bool, |
| 4024 | /// Whether the form refuses to submit without it. |
| 4025 | pub required: bool, |
| 4026 | /// The longest the value may be, in characters. |
| 4027 | pub max_length: , |
| 4028 | /// The lowest value accepted, as the host would write it. |
| 4029 | /// |
| 4030 | /// Text rather than a number, because the bound is only a number for some |
| 4031 | /// of the kinds that take one. goingson's own sites are `min="1"` on a |
| 4032 | /// duration and `min="2026-08-09T14:30"` on a datetime, and a numeric member |
| 4033 | /// could say the first and not the second. The [`kind`](Self::kind) already |
| 4034 | /// says how to read it, the same way it does for the value. |
| 4035 | pub min: , |
| 4036 | /// The highest value accepted, as the host would write it. See |
| 4037 | /// [`min`](Self::min). |
| 4038 | pub max: , |
| 4039 | /// The granularity the value moves in, as the host would write it. |
| 4040 | /// |
| 4041 | /// Text for [`min`](Self::min)'s reason, and it earns it twice over: the |
| 4042 | /// step of a date is a day and the step of a threshold is 0.01, and a |
| 4043 | /// numeric member could say one of them. |
| 4044 | /// |
| 4045 | /// Absent means the host's own granularity, which is the honest default |
| 4046 | /// rather than a missing value: a webview's `<input>` steps by 1 unless told |
| 4047 | /// otherwise, and that is the browser's rule and not this crate's to |
| 4048 | /// restate. |
| 4049 | /// |
| 4050 | /// # It is the granularity of a *typed* value |
| 4051 | /// |
| 4052 | /// [`FieldKind::Range`] reads its own from [`curve`](Self::curve) and |
| 4053 | /// ignores this. On a slider the granularity and the mapping are one |
| 4054 | /// decision, and on a typed number there is no mapping to decide with. See |
| 4055 | /// [`Curve`], "Why the step is here". |
| 4056 | pub step: , |
| 4057 | /// How a slider's position becomes its value, and how finely it moves. |
| 4058 | /// |
| 4059 | /// [`FieldKind::Range`]'s, and nothing else reads it: a typed number has a |
| 4060 | /// granularity but no mapping, and takes [`step`](Self::step) instead. |
| 4061 | /// |
| 4062 | /// Defaults to [`Curve::Linear`] with no step, which is what an |
| 4063 | /// undescribed range means. |
| 4064 | pub curve: , |
| 4065 | /// What the number is measured in: `s`, `ms`, `dB`, `GiB`. |
| 4066 | /// |
| 4067 | /// A fact about the value, not part of the question's name, and that |
| 4068 | /// distinction is the whole reason it is a member. The two readings come |
| 4069 | /// apart the moment anything reads a field back rather than drawing it: a |
| 4070 | /// [`max`](Self::max) of `-96` and a bound of `-96 dBFS` are the same number |
| 4071 | /// and not the same answer, and under the convention this replaces the unit |
| 4072 | /// could only be recovered by parsing it back out of a label. |
| 4073 | /// |
| 4074 | /// # Where a renderer draws it |
| 4075 | /// |
| 4076 | /// Beside the value, wherever that host puts a value. Not in the label: a |
| 4077 | /// label is the sentence above the control, so unit-in-label reads the same |
| 4078 | /// on every host and is wrong on any host with somewhere better. egui puts |
| 4079 | /// it inside |
| 4080 | /// the slider where the readout already is, a terminal appends it to the |
| 4081 | /// value in the edit line, a webview sets it adjacent to the input. |
| 4082 | /// |
| 4083 | /// # Which kinds read it |
| 4084 | /// |
| 4085 | /// [`FieldKind::measurable`] answers, and it is |
| 4086 | /// [`takes_files`](FieldKind::takes_files)'s footing: three renderers ask |
| 4087 | /// before they can decide whether to draw this, and a `matches!` per |
| 4088 | /// renderer is where the next measurable kind goes missing. A unit on a kind |
| 4089 | /// that rejects it is sayable and ignored, the same way |
| 4090 | /// [`options`](Self::options) is on a kind that offers none. |
| 4091 | /// |
| 4092 | /// # Why a string |
| 4093 | /// |
| 4094 | /// The measured sites are `GiB`, `dBFS`, `s` and `ms`. An enum would have to |
| 4095 | /// grow a member for every unit any consumer ever wants, and this crate does |
| 4096 | /// not know them; it knows that a number has one. |
| 4097 | /// |
| 4098 | /// Written as the symbol alone, with no brackets and no leading space. The |
| 4099 | /// spacing is the renderer's, because a slider's readout and a sentence want |
| 4100 | /// different answers. |
| 4101 | pub unit: , |
| 4102 | /// Whether the field lives behind a "more options" disclosure. |
| 4103 | pub extended: bool, |
| 4104 | /// Whether this local wall-clock value is submitted as an absolute instant. |
| 4105 | /// |
| 4106 | /// [`FieldKind::DateTime`] asks for a time the way a person says one -- |
| 4107 | /// "the 14th at half past two" -- and that names a different moment in |
| 4108 | /// Denver than it does in Berlin. A route that stores an instant needs the |
| 4109 | /// moment, so somebody has to convert. This member says the description |
| 4110 | /// wants that conversion; it does not say how. |
| 4111 | /// |
| 4112 | /// # The conversion belongs to the renderer |
| 4113 | /// |
| 4114 | /// Because the renderer is the only party that knows what "your computer's |
| 4115 | /// time zone" means for its host. A browser has one and the user is sitting |
| 4116 | /// in it; a TUI reads the host clock; an egui app reads the same clock a |
| 4117 | /// different way. Nothing above the renderer can answer it, and the |
| 4118 | /// alternatives all try: a hidden IANA-zone field needs a host capability |
| 4119 | /// for reading the zone that three hosts answer differently, plus a kind |
| 4120 | /// that does not exist, plus a wire-contract change; a timezone on the |
| 4121 | /// user's profile is a product decision wearing a bug's clothes. Say it |
| 4122 | /// here, and the next reader does not propose them again. |
| 4123 | /// |
| 4124 | /// # What a renderer does |
| 4125 | /// |
| 4126 | /// Draws the same control it always did -- the flag changes what is |
| 4127 | /// *submitted*, not what is shown -- and converts the local value to an |
| 4128 | /// absolute instant on the way out. A renderer that cannot convert submits |
| 4129 | /// the local value unchanged, which is what every renderer did before this |
| 4130 | /// existed. |
| 4131 | /// |
| 4132 | /// No wire contract moves when a site adopts it: the route was already |
| 4133 | /// receiving an instant. What changes is who computed it. |
| 4134 | /// |
| 4135 | /// # Which kinds read it |
| 4136 | /// |
| 4137 | /// [`FieldKind::DateTime`]'s. `Date` and `Time` are each half a moment and |
| 4138 | /// cannot name one on their own, so the flag is sayable and ignored there, |
| 4139 | /// the way [`options`](Self::options) is on a kind that offers none. |
| 4140 | pub as_instant: bool, |
| 4141 | |
| 4142 | |
| 4143 | |
| 4144 | /// A plain required-nothing field of the given kind. |
| 4145 | |
| 4146 | pub const |
| 4147 | Self |
| 4148 | kind, |
| 4149 | name, |
| 4150 | upper_name: None, |
| 4151 | label, |
| 4152 | hint: None, |
| 4153 | error: None, |
| 4154 | note: None, |
| 4155 | placeholder: None, |
| 4156 | options: &, |
| 4157 | themes: &, |
| 4158 | follows: None, |
| 4159 | accept: &, |
| 4160 | multiple: false, |
| 4161 | required: false, |
| 4162 | max_length: None, |
| 4163 | min: None, |
| 4164 | max: None, |
| 4165 | step: None, |
| 4166 | curve: Linear , |
| 4167 | unit: None, |
| 4168 | extended: false, |
| 4169 | as_instant: false, |
| 4170 | |
| 4171 | |
| 4172 | |
| 4173 | /// A bounded number the user drags across its whole extent. |
| 4174 | /// |
| 4175 | /// The third under-described kind, and it gets a constructor for |
| 4176 | /// [`select`](Self::select)'s reason: a range is the one kind whose bounds |
| 4177 | /// are not a rule but the control itself, so a call site that forgot them |
| 4178 | /// has a slider with nothing to slide across. Taking them as arguments is |
| 4179 | /// what makes that unsayable. |
| 4180 | /// |
| 4181 | /// The granularity stays a field rather than a fourth argument, and it is |
| 4182 | /// [`curve`](Self::curve)'s: it is genuinely optional, since the host's own |
| 4183 | /// is a real answer, and the two bounds are not. |
| 4184 | |
| 4185 | pub const |
| 4186 | Self |
| 4187 | min: Some, |
| 4188 | max: Some, |
| 4189 | ..Selfnew |
| 4190 | |
| 4191 | |
| 4192 | |
| 4193 | /// One question with two ends, taking the name each end submits under. |
| 4194 | /// |
| 4195 | /// A constructor for [`range`](Self::range)'s reason inverted: a range's |
| 4196 | /// bounds are what a call site cannot forget, and an interval's second name |
| 4197 | /// is. An interval built through [`new`](Self::new) has an upper end with |
| 4198 | /// nowhere to be submitted, and nothing downstream can invent one, so taking |
| 4199 | /// it as an argument is what makes that unsayable. |
| 4200 | /// |
| 4201 | /// The extent, the granularity and the unit stay members. They describe the |
| 4202 | /// axis rather than either end and they are genuinely optional, which is |
| 4203 | /// [`FieldKind::Number`]'s arrangement and the one an interval takes. |
| 4204 | |
| 4205 | pub const |
| 4206 | Self |
| 4207 | upper_name: Some, |
| 4208 | ..Selfnew |
| 4209 | |
| 4210 | |
| 4211 | |
| 4212 | /// A file field, taking the given accept list. |
| 4213 | /// |
| 4214 | /// The fourth under-described kind and it gets a constructor for |
| 4215 | /// [`range`](Self::range)'s reason rather than [`select`](Self::select)'s: |
| 4216 | /// a file field with no accept list is not broken, it is a field that takes |
| 4217 | /// anything, and the hazard is the opposite one. A call site that meant to |
| 4218 | /// restrict and forgot has a picker offering every file on the machine and |
| 4219 | /// a server refusing the upload afterwards, which is the failure the list |
| 4220 | /// exists to move forward. Taking it as an argument is what makes an |
| 4221 | /// accidental omission a deliberate `&[]`. |
| 4222 | /// |
| 4223 | /// [`multiple`](Self::multiple) stays a field. One file is the common case |
| 4224 | /// and the honest default; several is the thing worth saying. |
| 4225 | |
| 4226 | pub const |
| 4227 | Self |
| 4228 | accept, |
| 4229 | ..Selfnew |
| 4230 | |
| 4231 | |
| 4232 | |
| 4233 | /// A select offering the given options. |
| 4234 | /// |
| 4235 | /// One of the two kinds under-described by [`Field::new`], so it gets a |
| 4236 | /// constructor rather than leaving every call site to remember that a |
| 4237 | /// select with an empty `options` renders as an empty select. |
| 4238 | |
| 4239 | pub const |
| 4240 | Selfoffering |
| 4241 | |
| 4242 | |
| 4243 | /// A radio group offering the given options. |
| 4244 | /// |
| 4245 | /// The other. Same hazard as [`select`](Self::select) and a worse one: a |
| 4246 | /// radio group with no options draws nothing at all, so a call site that |
| 4247 | /// forgot them has an empty rectangle rather than a visibly empty control. |
| 4248 | |
| 4249 | pub const |
| 4250 | Selfoffering |
| 4251 | |
| 4252 | |
| 4253 | /// A theme picker over the themes the host resolved. |
| 4254 | /// |
| 4255 | /// A constructor for [`select`](Self::select)'s reason and one of its own. |
| 4256 | /// The shared reason: a theme picker built through [`new`](Self::new) has |
| 4257 | /// an empty [`themes`](Self::themes) list and draws an empty control. Its |
| 4258 | /// own: the list is the *only* thing this kind takes that a call site |
| 4259 | /// cannot get wrong by omission and can get wrong by substitution, since |
| 4260 | /// [`options`](Self::options) is right there and reads as if it would work. |
| 4261 | /// |
| 4262 | /// [`following`](Self::following) is the builder rather than a fourth |
| 4263 | /// argument, because a picker with no follow-the-system row is a real |
| 4264 | /// picker and every renderer draws it honestly. |
| 4265 | |
| 4266 | pub const |
| 4267 | Self |
| 4268 | themes, |
| 4269 | ..Selfnew |
| 4270 | |
| 4271 | |
| 4272 | |
| 4273 | /// The same picker, offering a row that tracks the ambient mode. |
| 4274 | /// |
| 4275 | /// The [`Choice`] carries the value the app's own store spells it with. |
| 4276 | |
| 4277 | pub const |
| 4278 | self.follows = Some; |
| 4279 | self |
| 4280 | |
| 4281 | |
| 4282 | /// The shared body of the two constructors that take options. |
| 4283 | /// |
| 4284 | /// Private, and keyed on the kind rather than exposed, because the two |
| 4285 | /// public names are the point: a call site says which question it is |
| 4286 | /// asking, not which flag it is setting. |
| 4287 | const |
| 4288 | kind: FieldKind, |
| 4289 | name: &'a str, |
| 4290 | label: &'a str, |
| 4291 | options: &'a [], |
| 4292 | |
| 4293 | Self |
| 4294 | options, |
| 4295 | ..Selfnew |
| 4296 | |
| 4297 | |
| 4298 | |
| 4299 | /// Whether the field is currently reporting a problem. |
| 4300 | /// |
| 4301 | /// Read this rather than testing `error.is_some()` at each renderer: the |
| 4302 | /// error state has to mark the field's whole group and not only the |
| 4303 | /// message, because a renderer with no descendant selectors (egui, a |
| 4304 | /// terminal) cannot find the group from the message. goingson already marks |
| 4305 | /// the group and Balanced Breakfast does not, so goingson's shape is the |
| 4306 | /// one taken here. |
| 4307 | /// |
| 4308 | /// [`note`](Self::note) is deliberately not consulted. A note says the |
| 4309 | /// answer costs something, not that it is unacceptable, and a field the |
| 4310 | /// user may submit as it stands is not invalid. |
| 4311 | |
| 4312 | pub const |
| 4313 | self.error.is_some |
| 4314 | |
| 4315 | |
| 4316 | /// Whether the field carries both ends of its extent. |
| 4317 | /// |
| 4318 | /// Only [`FieldKind::Range`] owes them, and it owes them absolutely: a |
| 4319 | /// slider with one end missing has no extent to draw. Named here rather |
| 4320 | /// than left to each renderer to test `min.is_some() && max.is_some()`, |
| 4321 | /// which is three renderers arriving at the same condition and one of them |
| 4322 | /// getting it wrong, and named as a question about the *field* rather than |
| 4323 | /// about the kind because the kind cannot see the bounds. |
| 4324 | /// |
| 4325 | /// It is a check and not a guarantee. Nothing here refuses to build an |
| 4326 | /// unbounded range — [`Field::range`] is what makes the bounded one easy — |
| 4327 | /// so a renderer asks this and falls back to whatever its host does |
| 4328 | /// honestly with a number. |
| 4329 | |
| 4330 | pub const |
| 4331 | self.min.is_some && self.max.is_some |
| 4332 | |
| 4333 | |
| 4334 | /// Whether anything in [`accept`](Self::accept) names a media family. |
| 4335 | /// |
| 4336 | /// The question a renderer asks before it decides to keep room for a |
| 4337 | /// preview, and it is deliberately the *whole list* rather than one entry: |
| 4338 | /// the media dropzone this was measured against takes `image/*,video/*`, so |
| 4339 | /// there is no single family to return and there is still a disclosure to |
| 4340 | /// offer. Which one it turns out to be is known once a file is picked, which |
| 4341 | /// is renderer-side and after the description is gone. |
| 4342 | /// |
| 4343 | /// False for an empty list, for a list of suffixes, and for `text/csv`. A |
| 4344 | /// renderer that wants the family of a particular entry reads |
| 4345 | /// [`Accepted::family`]. |
| 4346 | |
| 4347 | |
| 4348 | self.accept.iter.any |
| 4349 | |
| 4350 | |
| 4351 | |
| 4352 | /// How much room a placement asks for. |
| 4353 | /// |
| 4354 | /// A column says it, and so does a [`Field`]. An intent, so the actual floor |
| 4355 | /// stays with `makeover-geometry`. goingson's task table spells these as |
| 4356 | /// `minmax(200px, 1fr)`, `140px` and content-sized; only the first three words |
| 4357 | /// of that survive deferral. |
| 4358 | /// `#[non_exhaustive]`, for the reason [`Fill`] and [`FieldKind`] are: a |
| 4359 | /// renderer matches on this and a vocabulary that grows must not break every |
| 4360 | /// renderer when it does. |
| 4361 | |
| 4362 | |
| 4363 | |
| 4364 | /// Takes what it needs and no more. |
| 4365 | Content, |
| 4366 | /// A fixed share, the same at every width. |
| 4367 | Fixed, |
| 4368 | /// Absorbs whatever is left over. |
| 4369 | /// |
| 4370 | /// **Several fills divide what is left equally.** Stated because it would |
| 4371 | /// otherwise be undefined and each renderer would invent something, and |
| 4372 | /// stated this way because equal division is the only sharing rule that |
| 4373 | /// answers to "Any width, one answer" without a tiebreak: allocating in |
| 4374 | /// declaration order makes the result depend on the order the description |
| 4375 | /// was written in, which is a fact about the source file and not about the |
| 4376 | /// screen. It documents what both renderers already do — CSS grid gives |
| 4377 | /// `1fr 1fr`, ratatui gives each a `Constraint::Fill(1)` — rather than |
| 4378 | /// changing anything. |
| 4379 | /// |
| 4380 | /// So a row of fills is a legal thing to describe, and there is no rule |
| 4381 | /// against it. |
| 4382 | Fill, |
| 4383 | |
| 4384 | |
| 4385 | /// What a member is worth when there is not room for all of them. |
| 4386 | /// |
| 4387 | /// Written for table columns and no longer only theirs. Three shapes ask the |
| 4388 | /// same question and this answers all three: a table too narrow for its |
| 4389 | /// columns, a row too narrow for its parts (see [`RowPart::priority`]), and a |
| 4390 | /// group of regions sharing one run of room -- goingson's tab strip and the |
| 4391 | /// [`Region::Band`] beside it, which is the case wiki `layout-room-and-fallback` |
| 4392 | /// was ruled on. It is what any member of a group is worth, not a table |
| 4393 | /// concept, and [`Fallback::Shed`] is what reads it. |
| 4394 | /// |
| 4395 | /// The doc below is the column argument, which is where the type was measured; |
| 4396 | /// the sentence that gave it away is [`Priority::Essential`]'s, which was |
| 4397 | /// already written about a row. |
| 4398 | /// |
| 4399 | /// Ordered: [`Priority::Optional`] drops first, [`Priority::Essential`] never |
| 4400 | /// drops. This replaces addressing columns by position, which is what both |
| 4401 | /// webview apps do today and is a live bug rather than only verbosity. goingson |
| 4402 | /// hides mobile columns with `nth-child(n+5)` against a seven-column table, so |
| 4403 | /// inserting a column silently hides the wrong one. |
| 4404 | /// `#[non_exhaustive]`, same reasoning as [`Width`]. Note the ordering is the |
| 4405 | /// whole point of the type, so a new tier has to be declared in its place in |
| 4406 | /// the sequence rather than appended. |
| 4407 | |
| 4408 | |
| 4409 | |
| 4410 | /// Dropped first. |
| 4411 | Optional, |
| 4412 | /// Dropped once the optional members are gone. |
| 4413 | Secondary, |
| 4414 | /// Never dropped. Without it the group does not identify itself. |
| 4415 | Essential, |
| 4416 | |
| 4417 | |
| 4418 | /// What a group does when it runs out of room. |
| 4419 | /// |
| 4420 | /// Authored, and required: the field carrying this has no `Default` and a group |
| 4421 | /// cannot be described without saying what it does when it runs out of room. |
| 4422 | /// Max ruled on that: more intentionality from layout designers is |
| 4423 | /// acceptable so long as the constraints are solvable, because the goal is |
| 4424 | /// enabling good layouts rather than rescuing bad ones. A default here would be |
| 4425 | /// the crate guessing, and the guess would be silently wrong on the screens |
| 4426 | /// that matter. |
| 4427 | /// |
| 4428 | /// Relief resolves inside-out. A group asks its children to fall back before |
| 4429 | /// falling back itself, or an outer group collapses while an inner one still |
| 4430 | /// had slack. |
| 4431 | /// |
| 4432 | /// # No `Swap` |
| 4433 | /// |
| 4434 | /// An authored alternate group for the tight case is deliberately out of the |
| 4435 | /// first cut. It doubles the description for that group and the two halves can |
| 4436 | /// drift, which is the failure this vocabulary exists to end. Add it when a |
| 4437 | /// site proves it needs one. |
| 4438 | /// |
| 4439 | /// `#[non_exhaustive]`, [`Width`]'s reasoning. Unlike [`Priority`] there is no |
| 4440 | /// order to preserve, so a member can be appended. |
| 4441 | |
| 4442 | |
| 4443 | |
| 4444 | /// One row becomes two. Every member stays, in the order described. |
| 4445 | Wrap, |
| 4446 | /// A row becomes a column. Every member stays, full width. |
| 4447 | Stack, |
| 4448 | /// Members drop by [`Priority`], down to [`Priority::Essential`]. |
| 4449 | /// |
| 4450 | /// What a narrow table already does with its columns, applied to a group. |
| 4451 | /// What drops is gone from the screen, so this is right when the dropped |
| 4452 | /// members are facts the reader can do without and wrong when they are the |
| 4453 | /// only way to act. |
| 4454 | Shed, |
| 4455 | /// The members [`Shed`](Self::Shed) would drop move into one overflow |
| 4456 | /// control instead. |
| 4457 | /// |
| 4458 | /// The answer when a group holds actions. A control is not a fact: dropping |
| 4459 | /// it does not cost the reader a detail, it costs them the only way to act, |
| 4460 | /// which is [`RowPart::priority`]'s argument one level up. |
| 4461 | Menu, |
| 4462 | |
| 4463 | |
| 4464 | /// One column of a table. |
| 4465 | /// |
| 4466 | /// Described once. The grid track, the cell order and the drop behaviour are |
| 4467 | /// all derived from this, rather than being three hand-written encodings that |
| 4468 | /// must agree and are never checked against each other. |
| 4469 | |
| 4470 | |
| 4471 | /// The heading, and the name the cell is addressed by. |
| 4472 | pub name: &'a str, |
| 4473 | /// How much room it asks for. |
| 4474 | pub width: Width, |
| 4475 | /// What it is worth when room runs out. |
| 4476 | pub priority: Priority, |
| 4477 | /// Whether the user can reorder the table by this column. |
| 4478 | /// |
| 4479 | /// What reordering *calls* is not here — that is an address, and this |
| 4480 | /// crate names none — so a host pairs this with the route the way it pairs |
| 4481 | /// a row's parts with the row's activation. This says the affordance |
| 4482 | /// exists, which is what a renderer needs to draw a header a user can |
| 4483 | /// press rather than a heading they cannot. |
| 4484 | pub sortable: bool, |
| 4485 | /// Which way the table is ordered by this column, if it is. |
| 4486 | /// |
| 4487 | /// `None` on every column but the one in force. A renderer draws the caret |
| 4488 | /// from this and a webview sets `aria-sort`, which is why it is per column |
| 4489 | /// rather than a single fact on the table: the host idiom is a property of |
| 4490 | /// the header cell. |
| 4491 | /// |
| 4492 | /// Independent of [`sortable`](Self::sortable) rather than implied by it, |
| 4493 | /// because both combinations mean something. A column sorted and not |
| 4494 | /// sortable is a list ordered by a key the user cannot change, which is a |
| 4495 | /// real thing to describe and a caret worth drawing. |
| 4496 | pub sorted: , |
| 4497 | |
| 4498 | |
| 4499 | /// Which way a column is ordered. |
| 4500 | /// |
| 4501 | /// Two, because there is no third. "Unsorted" is [`Column::sorted`] being |
| 4502 | /// `None`, and folding it in here would be the same absence said twice. |
| 4503 | |
| 4504 | |
| 4505 | /// Smallest, earliest or first alphabetically at the top. |
| 4506 | Ascending, |
| 4507 | /// The other way. |
| 4508 | Descending, |
| 4509 | |
| 4510 | |
| 4511 | |
| 4512 | /// The other direction, for a header that flips when pressed. |
| 4513 | |
| 4514 | pub const |
| 4515 | match self |
| 4516 | SelfAscending => SelfDescending, |
| 4517 | SelfDescending => SelfAscending, |
| 4518 | |
| 4519 | |
| 4520 | |
| 4521 | /// What a webview writes into `aria-sort`. |
| 4522 | /// |
| 4523 | /// Named here rather than in the webview renderer because a terminal and an |
| 4524 | /// immediate-mode painter both want the same two words for a caret's label, |
| 4525 | /// and three renderers picking their own is the drift this crate ends. |
| 4526 | |
| 4527 | pub const |
| 4528 | match self |
| 4529 | SelfAscending => "ascending", |
| 4530 | SelfDescending => "descending", |
| 4531 | |
| 4532 | |
| 4533 | |
| 4534 | /// The caret a renderer draws for this direction. |
| 4535 | /// |
| 4536 | /// Here for [`as_str`](Self::as_str)'s reason, said about a glyph rather |
| 4537 | /// than a word: three renderers picking their own is the drift this crate |
| 4538 | /// ends. They had picked their own — two on the solid triangles and |
| 4539 | /// `makeover-webview` on the arrows U+2191/U+2193 — and agreeing by |
| 4540 | /// coincidence in three files is not agreement. |
| 4541 | /// |
| 4542 | /// The reason generalizes past this pair and is the house rule now — |
| 4543 | /// prefer the bolder, simpler glyph over the thinner or more complicated |
| 4544 | /// one. A third spelling is not open for re-argument. |
| 4545 | /// |
| 4546 | /// **Bare, with no spacing.** Where the gap goes is each renderer's |
| 4547 | /// business: `makeover-tui` and `makeover-immediate` carry a leading space |
| 4548 | /// inside their `TableStyle` string and a webview emits its own in |
| 4549 | /// `content`, so folding a space in here would make one of the two wrong. |
| 4550 | /// |
| 4551 | /// Neither face the web apps self-host carries these — IBM Plex Mono has one |
| 4552 | /// glyph in the whole geometric-shapes block and Lato has none — so a |
| 4553 | /// browser falls back per glyph until the in-house face ships with them |
| 4554 | /// drawn in (wiki `typography-standard`). Cosmetic |
| 4555 | /// drift in one renderer, not a reason to spell it three ways. |
| 4556 | |
| 4557 | pub const |
| 4558 | match self |
| 4559 | SelfAscending => "\u{25B2}", |
| 4560 | SelfDescending => "\u{25BC}", |
| 4561 | |
| 4562 | |
| 4563 | |
| 4564 | |
| 4565 | |
| 4566 | /// A column that absorbs slack and drops after the optional ones. |
| 4567 | |
| 4568 | pub const |
| 4569 | Self |
| 4570 | name, |
| 4571 | width: Fill, |
| 4572 | priority: Secondary, |
| 4573 | sortable: false, |
| 4574 | sorted: None, |
| 4575 | |
| 4576 | |
| 4577 | |
| 4578 | /// Whether this column survives at the given cutoff. |
| 4579 | /// |
| 4580 | /// A renderer narrows by raising the cutoff, and never by counting |
| 4581 | /// positions. |
| 4582 | |
| 4583 | pub const |
| 4584 | >= |
| 4585 | |
| 4586 | |
| 4587 | |
| 4588 | /// What a table cell holds. |
| 4589 | /// |
| 4590 | /// [`RowPart`] for tables, and it exists for the same reason: a part that |
| 4591 | /// carries a control is not text, and a renderer with one class for the whole |
| 4592 | /// cell paints it as though it were: a button in a cell inherits the cell's |
| 4593 | /// content colour, which is the drift [`RowPart::intent`] prevents for rows. |
| 4594 | /// |
| 4595 | /// Four members, and the count is what quasi's `Cell` was measured to carry: a |
| 4596 | /// value, tokens, actions and a link. Nothing was added past what something |
| 4597 | /// holds. |
| 4598 | /// |
| 4599 | /// `#[non_exhaustive]` for [`RowPart`]'s reason: growth here must not be a |
| 4600 | /// lockstep event across three renderers. |
| 4601 | /// |
| 4602 | /// # No hover-reveal |
| 4603 | /// |
| 4604 | /// This enum never gets one. A cell's actions are shown at rest in every |
| 4605 | /// consumer measured, and a member nothing uses is one three renderers owe an |
| 4606 | /// answer for. |
| 4607 | |
| 4608 | |
| 4609 | |
| 4610 | /// The cell's own text. |
| 4611 | Value, |
| 4612 | /// Small labelled things in the cell: a status badge, a chip. |
| 4613 | Tokens, |
| 4614 | /// Controls that act on what the row is about. |
| 4615 | Actions, |
| 4616 | /// The cell's value, where the value is itself a link. |
| 4617 | Link, |
| 4618 | |
| 4619 | |
| 4620 | |
| 4621 | /// The content intent the part takes. |
| 4622 | /// |
| 4623 | /// One part is text and three are not, so three answer with the intent |
| 4624 | /// inheriting already gives. That is [`RowPart::intent`]'s shape with the |
| 4625 | /// text side narrower: a cell's secondary and muted readings are the |
| 4626 | /// column's business, not the cell's. |
| 4627 | |
| 4628 | pub const |
| 4629 | match self |
| 4630 | SelfValue => "content", |
| 4631 | // A token carries its own tone, and a part-level intent underneath |
| 4632 | // it would fight the token sitting on it. |
| 4633 | SelfTokens => "content", |
| 4634 | // Actions carry controls rather than text. |
| 4635 | SelfActions => "content", |
| 4636 | // A link takes the action colour from the control it is, rather |
| 4637 | // than the cell's text colour from the cell it sits in. |
| 4638 | SelfLink => "content", |
| 4639 | |
| 4640 | |
| 4641 | |
| 4642 | |
| 4643 | /// A named dimension a set can be narrowed by. |
| 4644 | /// |
| 4645 | /// One word for six things that were six mechanisms. MNW's discover page filters |
| 4646 | /// by free text, a flat any-of over item types, a tree of tags, a numeric range |
| 4647 | /// over price, a nested one-of over AI tier, and a browse position in the tag |
| 4648 | /// tree held separately from the tag selection — and the last two being separate |
| 4649 | /// is the whole reason a filter row there needs a tick box *and* a chevron. The |
| 4650 | /// panel is a mixed bag of hand-written controls because nothing named the thing |
| 4651 | /// they all are. |
| 4652 | /// |
| 4653 | /// Deliberately wider than that one page. audiofiles' library browser and |
| 4654 | /// goingson's filters are the same shape, and a word that only fitted discover |
| 4655 | /// would be discover's markup with a neutral name on it. |
| 4656 | /// |
| 4657 | /// # What it does not say |
| 4658 | /// |
| 4659 | /// **What picking a value calls.** This crate names no address, so a facet is |
| 4660 | /// paired with routes the way a column's [`sortable`](Column::sortable) flag is |
| 4661 | /// paired with what reordering calls. |
| 4662 | /// |
| 4663 | /// **How a tree is drawn.** Indented rows, a column of panes, a breadcrumb and a |
| 4664 | /// list: all four are honest renderings of the same described facet, and a |
| 4665 | /// terminal will not pick the same one a browser does. [`FacetValue::depth`] is |
| 4666 | /// what a renderer needs to draw any of them; the choice is not described. |
| 4667 | /// |
| 4668 | /// **Which values to show.** A tag tree has thousands of nodes and a panel shows |
| 4669 | /// a handful. Deciding which handful is the app's — it is the same question as |
| 4670 | /// which rows go in a table, and no table member answers it either. |
| 4671 | |
| 4672 | |
| 4673 | |
| 4674 | /// What the dimension is called, as the user reads it. |
| 4675 | pub name: &'a str, |
| 4676 | /// How many of its values may be in force, and in what shape. |
| 4677 | pub mode: Selecting, |
| 4678 | /// The values on offer, in the order they are drawn. |
| 4679 | /// |
| 4680 | /// A [`Selecting::Text`] facet has none: the value is whatever was typed, |
| 4681 | /// and a description that listed the possible strings would be listing the |
| 4682 | /// corpus. A [`Selecting::Range`] facet has none either, for the reason |
| 4683 | /// [`FieldKind::Range`] takes bounds rather than options — the ends are the |
| 4684 | /// question and the values between them are not enumerable. |
| 4685 | pub values: &'a [], |
| 4686 | |
| 4687 | |
| 4688 | |
| 4689 | /// A dimension with values to pick from. |
| 4690 | |
| 4691 | pub const |
| 4692 | Self |
| 4693 | |
| 4694 | |
| 4695 | /// Whether the facet is narrowing the set right now. |
| 4696 | /// |
| 4697 | /// The question a renderer asks to decide whether to offer a way out of it, |
| 4698 | /// and the reason it is derived rather than carried: a facet with nothing |
| 4699 | /// standing is unengaged by construction, so a member saying so could |
| 4700 | /// disagree with the values beside it. [`Standing::Inherited`] does not |
| 4701 | /// count — something further up is what is doing the narrowing, and clearing |
| 4702 | /// a child that was never picked clears nothing. |
| 4703 | /// |
| 4704 | /// Always false for [`Selecting::Text`] and [`Selecting::Range`], which |
| 4705 | /// carry no values. A host that wants a clear affordance on those knows |
| 4706 | /// whether its own box is empty; the description does not hold the typed |
| 4707 | /// string. |
| 4708 | |
| 4709 | |
| 4710 | self.values.iter.any |
| 4711 | |
| 4712 | |
| 4713 | /// The deepest value in the facet, or zero when it is flat. |
| 4714 | /// |
| 4715 | /// What an indenting renderer needs to reserve a gutter before it draws the |
| 4716 | /// first row, which is "First paint is final paint" applied to a tree: a |
| 4717 | /// gutter widened as deeper values arrive is the reflow that rule forbids. |
| 4718 | |
| 4719 | |
| 4720 | self.values |
| 4721 | .iter |
| 4722 | .map |
| 4723 | .max |
| 4724 | .unwrap_or |
| 4725 | |
| 4726 | |
| 4727 | |
| 4728 | /// How many of a [`Facet`]'s values may be in force, and in what shape. |
| 4729 | /// |
| 4730 | /// Five, and the fifth is what made this an enum rather than a bool. `one-of`, |
| 4731 | /// `any-of`, a range and free text are the four a form vocabulary already has in |
| 4732 | /// [`FieldKind`]; a tree's selection is none of them, and describing tags as |
| 4733 | /// any-of was what forced browsing to be a second mechanism beside filtering. |
| 4734 | |
| 4735 | |
| 4736 | |
| 4737 | /// Exactly one value, and picking another replaces it. |
| 4738 | /// |
| 4739 | /// MNW's AI tier, whose three options are nested ranges rather than |
| 4740 | /// independent values, so two of them at once means nothing. |
| 4741 | OneOf, |
| 4742 | /// Any number of values, each independent of the others. |
| 4743 | AnyOf, |
| 4744 | /// A low end, a high end, or both. |
| 4745 | /// |
| 4746 | /// Carries no values for [`FieldKind::Range`]'s reason: the ends are the |
| 4747 | /// question. |
| 4748 | Range, |
| 4749 | /// Whatever the user types. |
| 4750 | Text, |
| 4751 | /// A position in a tree, edited by taking branches in and pruning branches |
| 4752 | /// out. |
| 4753 | /// |
| 4754 | /// The one mode that is not reducible to the others, and the one gesture |
| 4755 | /// that replaced two. Picking a value narrows the set to it *and* reveals |
| 4756 | /// its children, so browsing a tree and filtering by it stop being separate |
| 4757 | /// mechanisms with separate state. What a selection then is: a set of |
| 4758 | /// branches taken and a set pruned, resolved nearest-ancestor-first, so |
| 4759 | /// `music` in and `music/synths` out is sayable and no flat mode can say it. |
| 4760 | /// |
| 4761 | /// Resolution happens in the app, and what reaches a renderer is the |
| 4762 | /// [`Standing`] each drawn value ended up with. A renderer walking ancestors |
| 4763 | /// itself would be a renderer that can disagree with the results beside it. |
| 4764 | Subtree, |
| 4765 | |
| 4766 | |
| 4767 | |
| 4768 | /// Whether the mode picks from values the description lists. |
| 4769 | /// |
| 4770 | /// False for [`Text`](Self::Text) and [`Range`](Self::Range), which are the |
| 4771 | /// two whose answer is not one of a set. A renderer asks this before it |
| 4772 | /// looks at [`Facet::values`], the way it asks |
| 4773 | /// [`FieldKind::offers_options`] before it looks at [`Field::options`]. |
| 4774 | |
| 4775 | pub const |
| 4776 | matches! |
| 4777 | |
| 4778 | |
| 4779 | /// Whether a value can be pruned as well as picked. |
| 4780 | /// |
| 4781 | /// [`Subtree`](Self::Subtree) alone. Excluding a value from a flat facet is |
| 4782 | /// the same fact as not picking it, so an exclude affordance there would be |
| 4783 | /// a second control for a state the first one already holds. |
| 4784 | |
| 4785 | pub const |
| 4786 | matches! |
| 4787 | |
| 4788 | |
| 4789 | /// Whether picking a second value keeps the first. |
| 4790 | |
| 4791 | pub const |
| 4792 | matches! |
| 4793 | |
| 4794 | |
| 4795 | |
| 4796 | /// One value a [`Facet`] offers, as it currently stands. |
| 4797 | |
| 4798 | |
| 4799 | |
| 4800 | /// What identifies it, and what a host keys its route on. |
| 4801 | /// |
| 4802 | /// [`Choice::value`]'s split, and a tree is why it is not optional: two |
| 4803 | /// leaves under different parents are legitimately both called "Ambient", |
| 4804 | /// and the path is the only thing telling them apart. It is also what |
| 4805 | /// nearest-ancestor-wins resolves over, so an app that carried only labels |
| 4806 | /// could not compute the [`standing`](Self::standing) it hands back here. |
| 4807 | pub value: &'a str, |
| 4808 | /// What it is called, as the user reads it. |
| 4809 | /// |
| 4810 | /// The leaf's own name rather than its path: a facet drawn as an indented |
| 4811 | /// tree repeats every ancestor on every line otherwise, and one drawn as a |
| 4812 | /// breadcrumb has the ancestors already. |
| 4813 | pub label: &'a str, |
| 4814 | /// How many members of the set carry it. |
| 4815 | /// |
| 4816 | /// Optional, and settled that way rather than made mandatory: a count is a |
| 4817 | /// measured fact the app may not have. Counting a tag subtree under an |
| 4818 | /// active text search is a second query, and an app that will not pay for it |
| 4819 | /// should be able to describe the facet anyway rather than write a zero that |
| 4820 | /// reads as "none of them". That is [`Awaiting::amount`]'s rule in a second |
| 4821 | /// place — state a number when it was measured, and nothing when it was not. |
| 4822 | pub count: , |
| 4823 | /// Whether it is narrowing the set, and how it came to be. |
| 4824 | pub standing: Standing, |
| 4825 | /// How far down the tree it sits, counting from zero at the root. |
| 4826 | /// |
| 4827 | /// Always zero for a flat facet, which is what makes an indenting renderer |
| 4828 | /// one code path rather than two. A renderer that draws no tree at all still |
| 4829 | /// reads this, since a value's depth is what distinguishes two same-named |
| 4830 | /// leaves under different parents. |
| 4831 | pub depth: Nesting, |
| 4832 | /// Whether taking it reveals values under it. |
| 4833 | /// |
| 4834 | /// Distinct from having a nonzero [`depth`](Self::depth): a leaf deep in the |
| 4835 | /// tree branches no further, and a root with children does. Both facts are |
| 4836 | /// needed and neither implies the other, which is why the pair is two |
| 4837 | /// members rather than one count. |
| 4838 | pub branching: bool, |
| 4839 | |
| 4840 | |
| 4841 | |
| 4842 | /// An unpicked value at the root of the facet. |
| 4843 | |
| 4844 | pub const |
| 4845 | Self |
| 4846 | value, |
| 4847 | label, |
| 4848 | count: None, |
| 4849 | standing: Open, |
| 4850 | depth: top, |
| 4851 | branching: false, |
| 4852 | |
| 4853 | |
| 4854 | |
| 4855 | /// A value whose identifier is also what the user reads. |
| 4856 | /// |
| 4857 | /// [`Choice::of`]'s convenience, and it is the flat case: a type or a tier |
| 4858 | /// is its own name, and only a tree needs a path that is not one. |
| 4859 | |
| 4860 | pub const |
| 4861 | Selfnew |
| 4862 | |
| 4863 | |
| 4864 | /// How many members carry it, when that was measured. |
| 4865 | |
| 4866 | pub const |
| 4867 | self.count = Some; |
| 4868 | self |
| 4869 | |
| 4870 | |
| 4871 | /// How it stands in the current selection. |
| 4872 | |
| 4873 | pub const |
| 4874 | self.standing = standing; |
| 4875 | self |
| 4876 | |
| 4877 | |
| 4878 | /// Where it sits in the tree, and whether anything hangs off it. |
| 4879 | |
| 4880 | pub const |
| 4881 | self.depth = depth; |
| 4882 | self.branching = branching; |
| 4883 | self |
| 4884 | |
| 4885 | |
| 4886 | |
| 4887 | /// Whether a [`FacetValue`] is narrowing the set, and how it came to be. |
| 4888 | /// |
| 4889 | /// Four rather than a bool, and the two extra members are what a tree costs. A |
| 4890 | /// pruned branch and an untaken one are not the same state — one was decided |
| 4891 | /// against and the other was never reached — and a child under a taken parent is |
| 4892 | /// in force without anybody having picked it. A renderer given a bool either |
| 4893 | /// marks every descendant of a taken branch, which reads as forty deliberate |
| 4894 | /// choices, or marks none of them, which reads as unfiltered. |
| 4895 | |
| 4896 | |
| 4897 | |
| 4898 | /// Not picked, and nothing above it is either. |
| 4899 | |
| 4900 | Open, |
| 4901 | /// Picked here. The set is narrowed to it and whatever hangs off it. |
| 4902 | Taken, |
| 4903 | /// In force because something above it was taken. |
| 4904 | Inherited, |
| 4905 | /// Pruned out, though something above it was taken. |
| 4906 | /// |
| 4907 | /// The state that only [`Selecting::Subtree`] can reach, and the reason |
| 4908 | /// exclusion is drawn as a visible affordance beside each label rather than |
| 4909 | /// as a modifier on the ordinary one: a gesture a terminal cannot express is |
| 4910 | /// a gesture half the renderers would have to leave out, and an affordance |
| 4911 | /// nothing teaches is one users do not find. |
| 4912 | Pruned, |
| 4913 | |
| 4914 | |
| 4915 | |
| 4916 | /// Whether the user decided this value, either way. |
| 4917 | /// |
| 4918 | /// True for [`Taken`](Self::Taken) and [`Pruned`](Self::Pruned) — both are |
| 4919 | /// choices, and both are things a "clear this" affordance has to clear. |
| 4920 | /// [`Inherited`](Self::Inherited) is not: clearing it clears nothing, |
| 4921 | /// because the decision is further up. |
| 4922 | |
| 4923 | pub const |
| 4924 | matches! |
| 4925 | |
| 4926 | |
| 4927 | /// Whether the value narrows the set in. |
| 4928 | /// |
| 4929 | /// [`Taken`](Self::Taken) and [`Inherited`](Self::Inherited): one was picked |
| 4930 | /// and one came down from above, and to the set they mean the same thing. |
| 4931 | /// The pair is named here so a renderer colouring in-force values does not |
| 4932 | /// have to know which is which. |
| 4933 | |
| 4934 | pub const |
| 4935 | matches! |
| 4936 | |
| 4937 | |
| 4938 | /// The content intent the value takes. |
| 4939 | /// |
| 4940 | /// [`Pruned`](Self::Pruned) reads back a step, which is the three-tone rule |
| 4941 | /// above rather than a new decision: a pruned branch is still a live control |
| 4942 | /// — pressing it takes the prune off — so it may not wear `content-muted`, |
| 4943 | /// and it is not the thing itself either. |
| 4944 | |
| 4945 | pub const |
| 4946 | match self |
| 4947 | SelfTaken | SelfInherited | SelfOpen => "content", |
| 4948 | SelfPruned => "content-secondary", |
| 4949 | |
| 4950 | |
| 4951 | |
| 4952 | |
| 4953 | |
| 4954 | |
| 4955 | /// The concept is named here and its magnitude is not, which is |
| 4956 | /// `Awaiting`'s split and is why a renderer can disagree with another |
| 4957 | /// about what a level is worth without either of them being wrong. |
| 4958 | |
| 4959 | |
| 4960 | assert_eq!; |
| 4961 | assert_eq!; |
| 4962 | assert!; |
| 4963 | |
| 4964 | let under = at; |
| 4965 | assert_eq!; |
| 4966 | assert!; |
| 4967 | |
| 4968 | // Ordered, so a renderer walking a flat list of rows can compare two |
| 4969 | // levels rather than reaching into the field. |
| 4970 | assert!; |
| 4971 | |
| 4972 | |
| 4973 | use *; |
| 4974 | |
| 4975 | |
| 4976 | |
| 4977 | // The editing counterpart of markdown prose is still text: every host |
| 4978 | // can draw it, which is the whole reason the kind was addable. |
| 4979 | assert!; |
| 4980 | assert!; |
| 4981 | assert!; |
| 4982 | // It is not a chooser and not a moment. |
| 4983 | assert!; |
| 4984 | assert!; |
| 4985 | assert!; |
| 4986 | |
| 4987 | |
| 4988 | |
| 4989 | |
| 4990 | assert!; |
| 4991 | assert!; |
| 4992 | // An axis is measured in something and both its ends are in it, so the |
| 4993 | // unit is read once for the pair rather than per end. |
| 4994 | assert!; |
| 4995 | // A date is ordered and is not a quantity with a unit to choose: its |
| 4996 | // unit is fixed by the kind, so saying one would restate `kind`. |
| 4997 | for kind in |
| 4998 | Text, |
| 4999 | Date, |
| 5000 | DateTime, |
| 5001 | Select, |
| 5002 | Checkbox, |
| 5003 | File, |
| 5004 | ] |
| 5005 | assert!; |
| 5006 | |
| 5007 | |
| 5008 | |
| 5009 | |
| 5010 | |
| 5011 | // Additive: absent is what every field described before 0.33.0 meant. |
| 5012 | let plain = new; |
| 5013 | assert_eq!; |
| 5014 | let measured = Field |
| 5015 | unit: Some, |
| 5016 | ..range |
| 5017 | ; |
| 5018 | assert_eq!; |
| 5019 | assert!; |
| 5020 | |
| 5021 | |
| 5022 | |
| 5023 | |
| 5024 | // Stated rather than derived: the two measured sites disagree about |
| 5025 | // affix order, so a rule here would rename one of them. |
| 5026 | let suffixed = interval; |
| 5027 | assert_eq!; |
| 5028 | assert_eq!; |
| 5029 | let prefixed = interval; |
| 5030 | assert_eq!; |
| 5031 | assert_eq!; |
| 5032 | assert_eq!; |
| 5033 | |
| 5034 | |
| 5035 | |
| 5036 | |
| 5037 | // Additive: absent is what every field described before 0.34.0 meant. |
| 5038 | for kind in |
| 5039 | assert_eq!; |
| 5040 | |
| 5041 | assert_eq!; |
| 5042 | |
| 5043 | |
| 5044 | |
| 5045 | |
| 5046 | // A range's bounds are the control's extent and are owed; an interval's |
| 5047 | // are a rule on each end, which is Number's arrangement. |
| 5048 | let plain = interval; |
| 5049 | assert!; |
| 5050 | let axis = Field |
| 5051 | min: Some, |
| 5052 | max: Some, |
| 5053 | step: Some, |
| 5054 | unit: Some, |
| 5055 | ..interval |
| 5056 | ; |
| 5057 | assert!; |
| 5058 | assert_eq!; |
| 5059 | // Nothing here checks the crossing rule, exactly as nothing checks |
| 5060 | // `min` for a number: the description carries constraints and whoever |
| 5061 | // validated decides a value is wrong. |
| 5062 | assert!; |
| 5063 | |
| 5064 | |
| 5065 | |
| 5066 | |
| 5067 | // Excluding a value from a flat facet is the same fact as not picking |
| 5068 | // it, so the affordance exists in exactly one mode. |
| 5069 | assert!; |
| 5070 | for mode in |
| 5071 | OneOf, |
| 5072 | AnyOf, |
| 5073 | Range, |
| 5074 | Text, |
| 5075 | ] |
| 5076 | assert!; |
| 5077 | |
| 5078 | // Text and Range answer with something that is not one of a set. |
| 5079 | assert!; |
| 5080 | assert!; |
| 5081 | assert!; |
| 5082 | assert!; |
| 5083 | assert!; |
| 5084 | |
| 5085 | |
| 5086 | |
| 5087 | |
| 5088 | // The distinction a bool cannot hold, and the reason Standing has four |
| 5089 | // members: a child under a taken parent narrows the set, and clearing |
| 5090 | // it clears nothing. |
| 5091 | assert!; |
| 5092 | assert!; |
| 5093 | assert!; |
| 5094 | assert!; |
| 5095 | // A prune is a decision that takes the value out. |
| 5096 | assert!; |
| 5097 | assert!; |
| 5098 | assert!; |
| 5099 | assert!; |
| 5100 | // A pruned branch still answers a press, so it may not read as inert. |
| 5101 | assert_ne!; |
| 5102 | |
| 5103 | |
| 5104 | |
| 5105 | |
| 5106 | let inherited = |
| 5107 | of |
| 5108 | .standing |
| 5109 | .at, |
| 5110 | new |
| 5111 | .standing |
| 5112 | .at, |
| 5113 | ]; |
| 5114 | let facet = new; |
| 5115 | assert!; |
| 5116 | // The gutter an indenting renderer reserves before its first paint. |
| 5117 | assert_eq!; |
| 5118 | |
| 5119 | let untouched = |
| 5120 | of.at, |
| 5121 | new |
| 5122 | .standing |
| 5123 | .at, |
| 5124 | ]; |
| 5125 | // Inherited alone is something further up doing the narrowing, and |
| 5126 | // there is nothing further up here. |
| 5127 | assert!; |
| 5128 | |
| 5129 | // A text facet lists nothing, so it is flat and never reads as engaged |
| 5130 | // from its values: the typed string is not held here. |
| 5131 | let typed = new; |
| 5132 | assert!; |
| 5133 | assert_eq!; |
| 5134 | |
| 5135 | |
| 5136 | |
| 5137 | |
| 5138 | // Awaiting::amount's rule in a second place: a written zero reads as |
| 5139 | // "none of them", which is a different claim from "not counted". |
| 5140 | assert_eq!; |
| 5141 | assert_eq!; |
| 5142 | |
| 5143 | |
| 5144 | |
| 5145 | |
| 5146 | assert!; |
| 5147 | for kind in |
| 5148 | Text, |
| 5149 | Textarea, |
| 5150 | Rich, |
| 5151 | Select, |
| 5152 | Checkbox, |
| 5153 | Hidden, |
| 5154 | ] |
| 5155 | assert!; |
| 5156 | |
| 5157 | // The default is a field that takes any one file, which is what an |
| 5158 | // input with no accept and no multiple already is. |
| 5159 | let plain = new; |
| 5160 | assert!; |
| 5161 | assert!; |
| 5162 | |
| 5163 | |
| 5164 | |
| 5165 | |
| 5166 | // The three shapes are the MNW server's own three, and the family is |
| 5167 | // the question a renderer asks before it keeps room for a preview. |
| 5168 | assert_eq! |
| 5169 | Family.family, |
| 5170 | Some |
| 5171 | ; |
| 5172 | assert_eq!; |
| 5173 | assert_eq!; |
| 5174 | assert_eq! |
| 5175 | Type.family, |
| 5176 | Some |
| 5177 | ; |
| 5178 | // A media type outside the three families names none, and neither does |
| 5179 | // a suffix. `.mp3` is audio in fact and this crate will not infer it: |
| 5180 | // the table that said so would rot. |
| 5181 | assert_eq!; |
| 5182 | assert_eq!; |
| 5183 | assert_eq!; |
| 5184 | // Media types are case-insensitive and half the tree writes them |
| 5185 | // lowercase by habit rather than by rule. |
| 5186 | assert_eq!; |
| 5187 | |
| 5188 | |
| 5189 | |
| 5190 | |
| 5191 | assert_eq!; |
| 5192 | assert_eq!; |
| 5193 | assert_eq!; |
| 5194 | assert_eq!; |
| 5195 | assert_eq!; |
| 5196 | |
| 5197 | |
| 5198 | |
| 5199 | |
| 5200 | // The measured dropzone: `accept="image/*,video/*"`. There is no single |
| 5201 | // family to return and there is still a preview to keep room for, which |
| 5202 | // is why the question is asked of the list rather than of one entry. |
| 5203 | const MEDIA: & = & |
| 5204 | Family, |
| 5205 | Family, |
| 5206 | ]; |
| 5207 | assert!; |
| 5208 | // An installer's suffix list wants no disclosure, which is the measured |
| 5209 | // case rather than a hypothetical one. |
| 5210 | const BUILDS: & = &; |
| 5211 | assert!; |
| 5212 | // And a field that takes anything says so by listing nothing. |
| 5213 | assert!; |
| 5214 | |
| 5215 | |
| 5216 | |
| 5217 | |
| 5218 | const IMAGES: & = & |
| 5219 | Type, |
| 5220 | Type, |
| 5221 | Type, |
| 5222 | ]; |
| 5223 | let avatar = upload; |
| 5224 | assert_eq!; |
| 5225 | assert_eq!; |
| 5226 | assert!; |
| 5227 | let several = Field |
| 5228 | multiple: true, |
| 5229 | ..avatar |
| 5230 | ; |
| 5231 | assert!; |
| 5232 | |
| 5233 | |
| 5234 | |
| 5235 | |
| 5236 | // Mutually exclusive is the test for one enum against several fields: a |
| 5237 | // region shows its content, or that it is coming, or that there is none, |
| 5238 | // or that it broke. Never two. |
| 5239 | assert!; |
| 5240 | for state in |
| 5241 | assert!; |
| 5242 | |
| 5243 | |
| 5244 | |
| 5245 | |
| 5246 | |
| 5247 | // The default is the behaviour every region had before this member |
| 5248 | // existed, which is what keeps it additive: a description written |
| 5249 | // against 0.22.0 says the same thing under 0.23.0. |
| 5250 | assert_eq!; |
| 5251 | assert!; |
| 5252 | |
| 5253 | |
| 5254 | |
| 5255 | |
| 5256 | // The two derived idioms differ in one respect and this is it. A |
| 5257 | // carousel's row moves between frames and never reaches empty; a |
| 5258 | // disclosure's summary line is the same control wearing its closed |
| 5259 | // state, so a renderer has to know which it is drawing. |
| 5260 | assert!; |
| 5261 | assert!; |
| 5262 | assert!; |
| 5263 | |
| 5264 | // Both are selective, though. Deriving chrome is one question and |
| 5265 | // whether that chrome closes is another. |
| 5266 | assert!; |
| 5267 | assert!; |
| 5268 | |
| 5269 | |
| 5270 | |
| 5271 | |
| 5272 | // An empty list is the normal state of a new install. Drawing it in a |
| 5273 | // danger tone reports a fault where there is none, and this is the one |
| 5274 | // place the distinction is carried. |
| 5275 | assert_eq!; |
| 5276 | assert_eq!; |
| 5277 | assert_eq!; |
| 5278 | |
| 5279 | |
| 5280 | |
| 5281 | |
| 5282 | // Both combinations mean something, which is why the two fields are |
| 5283 | // independent rather than one implying the other. A list ordered by a |
| 5284 | // key the user cannot change is a real thing with a caret worth drawing. |
| 5285 | let fixed = Column |
| 5286 | sorted: Some, |
| 5287 | ..new |
| 5288 | ; |
| 5289 | |
| 5290 | assert!; |
| 5291 | assert_eq!; |
| 5292 | |
| 5293 | let offered = Column |
| 5294 | sortable: true, |
| 5295 | ..new |
| 5296 | ; |
| 5297 | assert_eq!; |
| 5298 | |
| 5299 | |
| 5300 | |
| 5301 | |
| 5302 | assert_eq!; |
| 5303 | assert_eq!; |
| 5304 | assert_eq!; |
| 5305 | |
| 5306 | |
| 5307 | |
| 5308 | |
| 5309 | // The spelling every renderer reads, so that agreeing is composition |
| 5310 | // rather than three files happening to hold the same literal. |
| 5311 | assert_eq!; |
| 5312 | assert_eq!; |
| 5313 | assert_ne!; |
| 5314 | // Bare. The gap is the renderer's, and a space here would be a second |
| 5315 | // one wherever a renderer already carries its own. |
| 5316 | for d in |
| 5317 | assert_eq!; |
| 5318 | |
| 5319 | |
| 5320 | |
| 5321 | |
| 5322 | |
| 5323 | // Three of goingson's five sites tone the figure by their own means, so |
| 5324 | // tone is carried at every site that needs it and derived at none. The |
| 5325 | // same reasoning `Meter` reached, from a different direction. |
| 5326 | let streak = new.tone; |
| 5327 | assert_eq!; |
| 5328 | assert_eq!; |
| 5329 | |
| 5330 | |
| 5331 | |
| 5332 | |
| 5333 | // 0.13.0. The MNW server's stat card is a label, a value and a delta, |
| 5334 | // across four screens, and the delta is what reads as good or bad. Tone |
| 5335 | // had no consumer before this: the figure itself is an ordinary fact. |
| 5336 | let views = new |
| 5337 | .change |
| 5338 | .tone; |
| 5339 | assert_eq!; |
| 5340 | assert_eq!; |
| 5341 | |
| 5342 | // A figure with nothing to compare against says so by having no change, |
| 5343 | // rather than by carrying an empty string a renderer has to test for. |
| 5344 | assert_eq!; |
| 5345 | |
| 5346 | |
| 5347 | |
| 5348 | |
| 5349 | // "84%", "12/30", "3d". A figure is whatever the app computed, already |
| 5350 | // formatted, and that is the line between this and `Meter`: a meter is |
| 5351 | // a proportion a renderer draws, a figure is a fact it sets in type. |
| 5352 | for value in |
| 5353 | assert_eq!; |
| 5354 | |
| 5355 | |
| 5356 | |
| 5357 | |
| 5358 | |
| 5359 | // The meter carries the tone, so a part-level intent underneath would |
| 5360 | // fight it. Same answer `Tokens` needed, for the same reason. |
| 5361 | assert_eq!; |
| 5362 | |
| 5363 | |
| 5364 | |
| 5365 | |
| 5366 | // It is a control the user operates, unlike `Hidden`, and it does not |
| 5367 | // pick from a list the description carries, unlike `Select`. |
| 5368 | assert!; |
| 5369 | assert!; |
| 5370 | assert!; |
| 5371 | |
| 5372 | |
| 5373 | |
| 5374 | |
| 5375 | // The whole model: the description carries the rule, the renderer emits |
| 5376 | // its host's idiom, and `error` is what arrives back when someone |
| 5377 | // validated. Nothing here decides a value is wrong. |
| 5378 | let field = Field |
| 5379 | max_length: Some, |
| 5380 | min: Some, |
| 5381 | max: Some, |
| 5382 | required: true, |
| 5383 | ..new |
| 5384 | ; |
| 5385 | assert!; |
| 5386 | |
| 5387 | // A bound is text because it is only a number for some of the kinds |
| 5388 | // that take one. goingson has both shapes live. |
| 5389 | let when = Field |
| 5390 | min: Some, |
| 5391 | ..new |
| 5392 | ; |
| 5393 | assert_eq!; |
| 5394 | |
| 5395 | |
| 5396 | |
| 5397 | |
| 5398 | // The whole reason this is a pair. goingson's `Task::time_progress` |
| 5399 | // clamps to 100 and then carries `is_over_estimate` beside it to say |
| 5400 | // what the clamp dropped; a meter says both from one fact. |
| 5401 | let over = new; |
| 5402 | assert_eq!; |
| 5403 | assert!; |
| 5404 | |
| 5405 | let exact = new; |
| 5406 | assert_eq!; |
| 5407 | assert!; |
| 5408 | |
| 5409 | |
| 5410 | |
| 5411 | |
| 5412 | // Sayable on purpose, so it has to be answerable. A meter over an |
| 5413 | // unloaded count is what an app actually has for a frame. |
| 5414 | let none = new; |
| 5415 | assert_eq!; |
| 5416 | assert!; |
| 5417 | assert!; |
| 5418 | |
| 5419 | |
| 5420 | |
| 5421 | |
| 5422 | // Given 43 nothing can recover "3 of 7", which is why the numbers are |
| 5423 | // carried and the label names only the noun. |
| 5424 | let m = new.label; |
| 5425 | assert_eq!; |
| 5426 | assert_eq!; |
| 5427 | assert_eq!; |
| 5428 | |
| 5429 | |
| 5430 | |
| 5431 | |
| 5432 | // The same fullness means opposite things on two of goingson's bars, |
| 5433 | // and only the app knows which. |
| 5434 | let subtasks = new.tone; |
| 5435 | let estimate = new.tone; |
| 5436 | assert_eq!; |
| 5437 | assert_ne!; |
| 5438 | // Untoned by default: a bar says nothing about status until something |
| 5439 | // says so, the same way a row is not selectable until told. |
| 5440 | assert_eq!; |
| 5441 | |
| 5442 | |
| 5443 | |
| 5444 | |
| 5445 | // The one member a renderer must branch on, and since 0.19.0 the only |
| 5446 | // member there is. A stated state is not by itself a reason to stop |
| 5447 | // answering, which is the distinction `State` makes and every |
| 5448 | // hand-rolled button in the tree had to remember. |
| 5449 | assert!; |
| 5450 | assert!; |
| 5451 | |
| 5452 | |
| 5453 | |
| 5454 | |
| 5455 | // No key is the ordinary case, and the webview hosts that ignore it |
| 5456 | // are why it stayed optional. |
| 5457 | assert_eq!; |
| 5458 | let quit = new.key.tone; |
| 5459 | assert_eq!; |
| 5460 | assert_eq!; |
| 5461 | |
| 5462 | |
| 5463 | |
| 5464 | |
| 5465 | // done * 100 in u32 would wrap somewhere past 42 million. Counts that |
| 5466 | // size are not tasks, but a description layer that silently reports 3% |
| 5467 | // for a full bar is worse than one that is slow. |
| 5468 | let big = new; |
| 5469 | assert_eq!; |
| 5470 | assert!; |
| 5471 | |
| 5472 | |
| 5473 | |
| 5474 | |
| 5475 | let = Raised.edges; |
| 5476 | let = Inset.edges; |
| 5477 | assert_eq!; |
| 5478 | assert_eq!; |
| 5479 | |
| 5480 | |
| 5481 | |
| 5482 | |
| 5483 | for b in |
| 5484 | assert_eq!; |
| 5485 | |
| 5486 | |
| 5487 | |
| 5488 | |
| 5489 | |
| 5490 | // The bug this vocabulary exists to make unrepresentable. |
| 5491 | assert_eq!; |
| 5492 | assert_eq!; |
| 5493 | assert_eq!; |
| 5494 | assert_ne!; |
| 5495 | |
| 5496 | |
| 5497 | |
| 5498 | |
| 5499 | // The reason State is its own axis and not a Depth member: a disabled |
| 5500 | // button and a disabled field are both disabled and are not the same |
| 5501 | // shape, which one shared variant could not have said. |
| 5502 | assert_eq!; |
| 5503 | assert_eq!; |
| 5504 | assert!; |
| 5505 | |
| 5506 | |
| 5507 | |
| 5508 | |
| 5509 | // Kept in spirit from the version where `Focus` was the counter-example: |
| 5510 | // suppressing interaction is `Disabled`'s alone, so a member added here |
| 5511 | // later does not get to inherit it by being a state. |
| 5512 | assert!; |
| 5513 | |
| 5514 | |
| 5515 | |
| 5516 | |
| 5517 | // No new token, so this costs no `makeover` release. |
| 5518 | assert_eq!; |
| 5519 | |
| 5520 | |
| 5521 | |
| 5522 | |
| 5523 | assert_eq!; |
| 5524 | assert_eq!; |
| 5525 | |
| 5526 | |
| 5527 | |
| 5528 | |
| 5529 | // The one member carrying a fill without a bevel. A renderer that |
| 5530 | // assumes the two arrive together drops the fill silently, which is |
| 5531 | // exactly what makeover-webview did before 0.3.0. |
| 5532 | assert_eq!; |
| 5533 | assert_eq!; |
| 5534 | |
| 5535 | |
| 5536 | |
| 5537 | |
| 5538 | // Both edgeless, and only one of them needs a colour. Collapsing them |
| 5539 | // is what left an unchosen tab unsayable. |
| 5540 | assert_eq!; |
| 5541 | assert_ne!; |
| 5542 | |
| 5543 | |
| 5544 | |
| 5545 | |
| 5546 | // Authored in opposite directions: makeover derives surface-well by |
| 5547 | // inverting against the theme's content colour, while surface-sunken is |
| 5548 | // authored and may sit darker than raised. |
| 5549 | assert_ne!; |
| 5550 | assert_eq!; |
| 5551 | assert_eq!; |
| 5552 | |
| 5553 | |
| 5554 | |
| 5555 | |
| 5556 | // The gap 0.3.0 closed. Before it, only `chosen` existed and the |
| 5557 | // unchosen option fell through to Flat at every renderer. |
| 5558 | for s in |
| 5559 | assert_ne! |
| 5560 | s.chosen, |
| 5561 | s.unchosen, |
| 5562 | "{s:?} cannot tell picked from unpicked" |
| 5563 | ; |
| 5564 | |
| 5565 | |
| 5566 | |
| 5567 | |
| 5568 | |
| 5569 | // Tabs recede so the chosen one comes forward; a segment and a toggle |
| 5570 | // stand up so the chosen one is held in. That inversion is the whole |
| 5571 | // content of "picked" once colour is deferred, and it is why the three |
| 5572 | // are not one member with a flag. |
| 5573 | assert_eq!; |
| 5574 | assert_eq!; |
| 5575 | |
| 5576 | for s in |
| 5577 | assert_eq!; |
| 5578 | assert_eq!; |
| 5579 | // Held in is what pressing produces: one appearance, two reasons. |
| 5580 | assert_eq!; |
| 5581 | |
| 5582 | |
| 5583 | |
| 5584 | |
| 5585 | |
| 5586 | assert_eq!; |
| 5587 | assert_eq! |
| 5588 | Raised.pressed.bevel, |
| 5589 | Raised.bevel.map |
| 5590 | ; |
| 5591 | // Only raised regions respond to being pressed. |
| 5592 | assert_eq!; |
| 5593 | assert_eq!; |
| 5594 | // An overlay is a surface, not a control. |
| 5595 | assert_eq!; |
| 5596 | |
| 5597 | |
| 5598 | |
| 5599 | |
| 5600 | // The wave-2 rule: a surface over the page takes elevation, a surface |
| 5601 | // in the page takes a bevel. Both halves come off the one Depth, so |
| 5602 | // they cannot disagree. |
| 5603 | assert_eq!; |
| 5604 | assert_eq!; |
| 5605 | |
| 5606 | // Three depths have no bevel and they are not the same claim. Flat has |
| 5607 | // nothing to separate from, Sunken's colour is doing the separating, |
| 5608 | // and an overlay is separated by the lift. |
| 5609 | assert_ne!; |
| 5610 | assert_ne!; |
| 5611 | |
| 5612 | |
| 5613 | |
| 5614 | |
| 5615 | // audiofiles' export Format field: choosing WAV over Original |
| 5616 | // re-encodes and drops the embedded metadata. Perfectly valid, and it |
| 5617 | // costs something. |
| 5618 | let format = Field |
| 5619 | note: Some, |
| 5620 | ..select |
| 5621 | ; |
| 5622 | assert!; |
| 5623 | assert!; |
| 5624 | assert!; |
| 5625 | assert_eq!; |
| 5626 | |
| 5627 | // The default is no note, so the 15 in-tree `..Field::new(..)` |
| 5628 | // literals absorb the member with no call-site edit. |
| 5629 | assert!; |
| 5630 | |
| 5631 | |
| 5632 | |
| 5633 | |
| 5634 | // Neutral means "no status", and that is all it means. It answered |
| 5635 | // `content-muted` until 2026-08-27, which muted a figure's headline |
| 5636 | // number to the colour of its own caption. What makes a badge quiet |
| 5637 | // is `Token::Badge` answering no click, which lives on the renderer. |
| 5638 | assert_eq!; |
| 5639 | assert!; |
| 5640 | assert_eq!; |
| 5641 | |
| 5642 | |
| 5643 | |
| 5644 | |
| 5645 | assert_eq!; |
| 5646 | assert_eq!; |
| 5647 | assert_eq!; |
| 5648 | assert_eq!; |
| 5649 | // No value ever leaves this crate. |
| 5650 | for t in |
| 5651 | Light.token, |
| 5652 | Dark.token, |
| 5653 | Danger.token, |
| 5654 | Neutral.token, |
| 5655 | Disabled.token, |
| 5656 | ] |
| 5657 | assert!; |
| 5658 | assert! |
| 5659 | !t.chars.next.unwrap.is_ascii_digit, |
| 5660 | "{t} is a value" |
| 5661 | ; |
| 5662 | |
| 5663 | |
| 5664 | |
| 5665 | |
| 5666 | |
| 5667 | // The one line that runs through all three apps' taxonomies. |
| 5668 | assert!; |
| 5669 | assert!; |
| 5670 | assert!; |
| 5671 | |
| 5672 | // A badge is a label, so giving it an edge would lie about it. |
| 5673 | assert_eq!; |
| 5674 | assert_eq!; |
| 5675 | |
| 5676 | // A latched chip wears the same shape a pressed one does. |
| 5677 | let chip = Chip ; |
| 5678 | assert_eq!; |
| 5679 | assert_eq!; |
| 5680 | |
| 5681 | |
| 5682 | |
| 5683 | |
| 5684 | assert!; |
| 5685 | assert!; |
| 5686 | // A toast floats above the page; a banner rests in the flow. |
| 5687 | assert_eq!; |
| 5688 | assert_eq!; |
| 5689 | |
| 5690 | |
| 5691 | |
| 5692 | |
| 5693 | // `revealed_on_hover` was asserted here until 0.13.0 retired it. It said |
| 5694 | // a row's actions stay hidden until hover, which stopped being true when |
| 5695 | // makeover-webview 0.23.0 showed them at rest, and nothing had consumed |
| 5696 | // it for a release either way. |
| 5697 | assert_eq!; |
| 5698 | assert_eq!; |
| 5699 | assert_eq!; |
| 5700 | |
| 5701 | |
| 5702 | |
| 5703 | |
| 5704 | // Each token carries its own tone, so a part-level intent underneath |
| 5705 | // would fight the thing sitting on it. Same reasoning as actions, which |
| 5706 | // is why they answer alike. |
| 5707 | assert_eq!; |
| 5708 | assert_eq!; |
| 5709 | |
| 5710 | |
| 5711 | |
| 5712 | |
| 5713 | // The pair is named once so a host with parsing to do asks here rather |
| 5714 | // than spelling it out, which is `offers_options`' reason. |
| 5715 | assert!; |
| 5716 | assert!; |
| 5717 | |
| 5718 | for kind in |
| 5719 | Text, |
| 5720 | Secret, |
| 5721 | Number, |
| 5722 | Email, |
| 5723 | Url, |
| 5724 | Tel, |
| 5725 | Range, |
| 5726 | Textarea, |
| 5727 | Rich, |
| 5728 | Select, |
| 5729 | Radio, |
| 5730 | Checkbox, |
| 5731 | File, |
| 5732 | Hidden, |
| 5733 | ] |
| 5734 | assert!; |
| 5735 | |
| 5736 | |
| 5737 | |
| 5738 | |
| 5739 | |
| 5740 | // The formats are the whole reason the members are worth naming apart |
| 5741 | // from text, so the doc comments and the constants have to agree. A |
| 5742 | // host reading one and meeting the other is the silent failure. |
| 5743 | assert_eq!; |
| 5744 | assert!; |
| 5745 | |
| 5746 | assert_eq!; |
| 5747 | assert! |
| 5748 | DATETIME_FORMAT.starts_with, |
| 5749 | "a moment starts with the day it is on" |
| 5750 | ; |
| 5751 | // Local, and that is a property of the value rather than an omission. |
| 5752 | assert!; |
| 5753 | assert!; |
| 5754 | assert!; |
| 5755 | |
| 5756 | |
| 5757 | |
| 5758 | |
| 5759 | // Neither is a checkbox and neither is a fixed set, so both fall where |
| 5760 | // text does. Asserted because a new kind lands in three predicates and |
| 5761 | // only one of them is the interesting one. |
| 5762 | for kind in |
| 5763 | assert!; |
| 5764 | assert!; |
| 5765 | assert!; |
| 5766 | assert!; |
| 5767 | |
| 5768 | |
| 5769 | |
| 5770 | |
| 5771 | |
| 5772 | // The table half of what RowPart::intent does for rows. A cell holding |
| 5773 | // a control and a cell holding text answered alike until 0.14.0, and a |
| 5774 | // control in a cell took the cell's text colour. |
| 5775 | assert_eq!; |
| 5776 | |
| 5777 | for part in |
| 5778 | // Each for its own reason -- a token carries its tone, an action is |
| 5779 | // a control, a link takes the action colour -- and all three reach |
| 5780 | // the intent inheriting already gives. |
| 5781 | assert_eq!; |
| 5782 | |
| 5783 | |
| 5784 | |
| 5785 | |
| 5786 | |
| 5787 | for part in |
| 5788 | Value, |
| 5789 | Tokens, |
| 5790 | Actions, |
| 5791 | Link, |
| 5792 | ] |
| 5793 | let intent = part.intent; |
| 5794 | assert!; |
| 5795 | assert!; |
| 5796 | |
| 5797 | |
| 5798 | |
| 5799 | |
| 5800 | |
| 5801 | assert!; |
| 5802 | assert!; |
| 5803 | assert!; |
| 5804 | |
| 5805 | |
| 5806 | |
| 5807 | |
| 5808 | assert_eq!; |
| 5809 | assert_eq!; |
| 5810 | // The exception, and the whole folder semantic: the open tab joins its |
| 5811 | // pane rather than sinking away from it. |
| 5812 | assert_eq!; |
| 5813 | |
| 5814 | // A held-in segment is indistinguishable from a pressed raised one, |
| 5815 | // which is the economy the light model buys over a colour swap. |
| 5816 | assert_eq!; |
| 5817 | |
| 5818 | // A toggle stands alone; the other two are built out of parts that |
| 5819 | // touch. |
| 5820 | assert!; |
| 5821 | assert!; |
| 5822 | assert!; |
| 5823 | |
| 5824 | |
| 5825 | |
| 5826 | |
| 5827 | // The distinction the member exists for. A split's two panes stand in a |
| 5828 | // master-detail relationship; columns choose nothing about each other. |
| 5829 | // Both are flat, so depth cannot tell them apart and the doc has to. |
| 5830 | assert_eq!; |
| 5831 | assert_eq!; |
| 5832 | assert_ne!; |
| 5833 | |
| 5834 | |
| 5835 | |
| 5836 | |
| 5837 | // The two things a board is always asked to carry and must not. How |
| 5838 | // many is what the children say; how wide is settled by "peers are |
| 5839 | // equal". |
| 5840 | // |
| 5841 | // The guard is the binding itself and it is a compile-time one: adding |
| 5842 | // a field to `Columns` stops this line compiling, which is a better |
| 5843 | // failure than any assertion about it. Written out rather than inlined |
| 5844 | // for exactly that reason. |
| 5845 | let columns: = Columns; |
| 5846 | assert_eq!; |
| 5847 | |
| 5848 | |
| 5849 | |
| 5850 | |
| 5851 | // A board's contents are ordinary description all the way down, so a |
| 5852 | // renderer that does not lay them across still draws every column. |
| 5853 | // Stacking them vertically is honouring this member, not degrading it. |
| 5854 | assert!; |
| 5855 | assert!; |
| 5856 | |
| 5857 | |
| 5858 | |
| 5859 | |
| 5860 | // Every renderer divides by this. A caller passing a backwards or empty |
| 5861 | // span is a bug, but it is not a bug worth a panic three renderers deep. |
| 5862 | assert_eq!; |
| 5863 | assert_eq!; |
| 5864 | assert_eq!; |
| 5865 | |
| 5866 | |
| 5867 | |
| 5868 | |
| 5869 | // 22:00 to 02:00. The alternative was carrying a date, which drags a |
| 5870 | // timezone into the vocabulary for the sake of one night shift. |
| 5871 | let overnight = new; |
| 5872 | assert_eq!; |
| 5873 | assert!; |
| 5874 | assert!; |
| 5875 | |
| 5876 | |
| 5877 | |
| 5878 | |
| 5879 | // The reason Placement carries no `conflicts` flag: the times already |
| 5880 | // say it, and a second source for one fact is how a stale conflict |
| 5881 | // badge outlives the conflict. |
| 5882 | let morning = new; // 09:00-10:00 |
| 5883 | let overlapping = new; // 09:30-10:30 |
| 5884 | let after = new; // 10:00-11:00 |
| 5885 | |
| 5886 | assert!; |
| 5887 | assert!; |
| 5888 | // Touching end to end is not overlapping: `to` is exclusive, so a |
| 5889 | // 10:00 start does not collide with a 10:00 end. |
| 5890 | assert!; |
| 5891 | assert!; |
| 5892 | |
| 5893 | |
| 5894 | |
| 5895 | |
| 5896 | assert_eq!; |
| 5897 | assert_eq!; |
| 5898 | |
| 5899 | |
| 5900 | |
| 5901 | |
| 5902 | let day = DAY; |
| 5903 | assert!; |
| 5904 | assert!; |
| 5905 | // Clamped rather than off the end: an event running past the span's |
| 5906 | // close draws at the edge, which beats panicking or drawing nowhere. |
| 5907 | assert!; |
| 5908 | |
| 5909 | |
| 5910 | |
| 5911 | |
| 5912 | assert_eq!; |
| 5913 | assert_eq!; |
| 5914 | // A span that does not divide evenly keeps a slot for its tail. |
| 5915 | assert_eq!; |
| 5916 | // slot: 0 is a caller bug that reads as one slot, not a panic. |
| 5917 | let degenerate = Track |
| 5918 | span: DAY, |
| 5919 | slot: 0, |
| 5920 | tick: 60, |
| 5921 | unit: Minutes, |
| 5922 | ; |
| 5923 | assert_eq!; |
| 5924 | |
| 5925 | |
| 5926 | |
| 5927 | |
| 5928 | // The guard on the thing the withdrawn refusal was right about. If a |
| 5929 | // pixel measure, a scroll offset or a colour ever lands on Track, the |
| 5930 | // member has stopped being a fact about the data and the timeline |
| 5931 | // really has become a component library wearing a description's name. |
| 5932 | let day = DAY; |
| 5933 | assert_eq!; |
| 5934 | assert_eq!; |
| 5935 | assert_eq!; |
| 5936 | assert_eq!; |
| 5937 | |
| 5938 | // Three fields when this was written, and the fourth came here to say |
| 5939 | // why, which is the whole point of the assertion. `unit` is what the |
| 5940 | // integers COUNT -- a fact about the data, unavailable from the numbers |
| 5941 | // themselves, and the absence of it is what let a month strip render |
| 5942 | // under a wall clock. A fifth field still has to argue, and "the |
| 5943 | // renderer would find it handy" is still not the argument. |
| 5944 | // Destructured rather than rebuilt: this is the form that names every |
| 5945 | // field and stops compiling when a fifth arrives, without binding |
| 5946 | // anything a lint has to forgive. |
| 5947 | let Track |
| 5948 | span: _, |
| 5949 | slot: _, |
| 5950 | tick: _, |
| 5951 | unit: _, |
| 5952 | = day; |
| 5953 | |
| 5954 | |
| 5955 | |
| 5956 | |
| 5957 | // The probe that found the defect, kept as a test. Fifteen days from |
| 5958 | // day three, on a thirty-one day month: the geometry was always right |
| 5959 | // and only the label was wrong, which is why `unit` is a fact and not |
| 5960 | // presentation. |
| 5961 | let march = days; |
| 5962 | assert_eq!; |
| 5963 | assert_eq!; |
| 5964 | |
| 5965 | let leave = new; |
| 5966 | assert!; |
| 5967 | assert!; |
| 5968 | |
| 5969 | |
| 5970 | |
| 5971 | |
| 5972 | assert_eq!; |
| 5973 | assert_eq!; |
| 5974 | for r in |
| 5975 | Band, |
| 5976 | Sidebar, |
| 5977 | Group, |
| 5978 | Split, |
| 5979 | TabGroup, |
| 5980 | ] |
| 5981 | assert_eq!; |
| 5982 | |
| 5983 | |
| 5984 | |
| 5985 | |
| 5986 | |
| 5987 | // The escape hatch is one member and stays one member. If a second |
| 5988 | // undescribed region ever appears, the description has started |
| 5989 | // conceding rather than deferring. |
| 5990 | for r in |
| 5991 | Band, |
| 5992 | Sidebar, |
| 5993 | Pane, |
| 5994 | Group, |
| 5995 | Split, |
| 5996 | TabGroup, |
| 5997 | Modal, |
| 5998 | // A widget is described, and that is the whole of what separates it |
| 5999 | // from a bespoke here. Both carry a name this crate never reads; |
| 6000 | // only one of them has contents under it that a renderer which does |
| 6001 | // not know the name can still walk. |
| 6002 | Widget , |
| 6003 | ] |
| 6004 | assert!; |
| 6005 | |
| 6006 | assert!; |
| 6007 | |
| 6008 | |
| 6009 | |
| 6010 | |
| 6011 | // The whole of why this is a member rather than a `Pane`. A pane is |
| 6012 | // looked into and scrolls; a group is neither, and four groups inside a |
| 6013 | // settings pane described as panes are four wells inside a well. |
| 6014 | assert_eq!; |
| 6015 | assert_eq!; |
| 6016 | assert_ne!; |
| 6017 | |
| 6018 | // Described, and it carries no name: a group is a primitive every |
| 6019 | // renderer draws from scratch, which is what separates it from the two |
| 6020 | // members that do carry one. |
| 6021 | assert!; |
| 6022 | assert_eq!; |
| 6023 | |
| 6024 | |
| 6025 | |
| 6026 | |
| 6027 | // `Heading::Section` has said "names a block within the screen" since |
| 6028 | // 0.2.0 and there was no block. The pairing is the point, and it is the |
| 6029 | // reason a group carries no heading of its own: the heading is an |
| 6030 | // ordinary node in the body, and a group without one is legal. |
| 6031 | assert!; |
| 6032 | assert_eq!; |
| 6033 | |
| 6034 | |
| 6035 | |
| 6036 | |
| 6037 | // Stronger than the bespoke case: a widget is drawn by whichever |
| 6038 | // renderer recognises the name, so a depth chosen here would be this |
| 6039 | // crate deciding a carousel is raised on every host. |
| 6040 | assert_eq!; |
| 6041 | assert_eq!; |
| 6042 | |
| 6043 | |
| 6044 | |
| 6045 | |
| 6046 | // A renderer dispatching on a name wants the string, not the member. |
| 6047 | // Writing that `matches!` at each renderer is how the two drift apart. |
| 6048 | assert_eq!; |
| 6049 | assert_eq! |
| 6050 | Bespoke .name, |
| 6051 | Some |
| 6052 | ; |
| 6053 | |
| 6054 | for r in |
| 6055 | Band, |
| 6056 | Sidebar, |
| 6057 | Pane, |
| 6058 | Group, |
| 6059 | Split, |
| 6060 | TabGroup, |
| 6061 | Modal, |
| 6062 | ] |
| 6063 | assert_eq!; |
| 6064 | |
| 6065 | |
| 6066 | |
| 6067 | |
| 6068 | |
| 6069 | // The app owns the contents, not the placement. An app that wants its |
| 6070 | // timeline in a well frames it in a Pane. |
| 6071 | assert_eq!; |
| 6072 | assert_eq!; |
| 6073 | |
| 6074 | |
| 6075 | |
| 6076 | |
| 6077 | // The argument the member exists for: goingson's day-plan has to be |
| 6078 | // routable, or the description covers only the boring screens and the |
| 6079 | // interesting four need a second path beside the router. |
| 6080 | let day_plan = |
| 6081 | Band, |
| 6082 | Bespoke , |
| 6083 | Sidebar, |
| 6084 | ]; |
| 6085 | assert_eq!; |
| 6086 | assert_eq!; |
| 6087 | |
| 6088 | |
| 6089 | |
| 6090 | |
| 6091 | let secret = new; |
| 6092 | assert!; |
| 6093 | assert!; |
| 6094 | |
| 6095 | assert!; |
| 6096 | // Nothing else is confidential, or the marker means nothing. |
| 6097 | for k in |
| 6098 | Text, |
| 6099 | Number, |
| 6100 | Textarea, |
| 6101 | Rich, |
| 6102 | Select, |
| 6103 | Checkbox, |
| 6104 | Hidden, |
| 6105 | ] |
| 6106 | assert!; |
| 6107 | |
| 6108 | |
| 6109 | // Only a checkbox carries its own label. |
| 6110 | assert!; |
| 6111 | assert!; |
| 6112 | |
| 6113 | |
| 6114 | |
| 6115 | |
| 6116 | let text = new; |
| 6117 | assert!; |
| 6118 | assert_eq!; |
| 6119 | |
| 6120 | let sizes = ; |
| 6121 | let select = select; |
| 6122 | assert_eq!; |
| 6123 | assert_eq!; |
| 6124 | |
| 6125 | |
| 6126 | |
| 6127 | |
| 6128 | // The whole reason it is two strings. `plain` is the case where they |
| 6129 | // coincide, and it is a shorthand rather than the general shape. |
| 6130 | let plain = plain; |
| 6131 | assert_eq!; |
| 6132 | |
| 6133 | let spelled = new; |
| 6134 | assert_ne!; |
| 6135 | assert! |
| 6136 | spelled.available, |
| 6137 | "an option is pickable until it says not" |
| 6138 | ; |
| 6139 | |
| 6140 | |
| 6141 | |
| 6142 | |
| 6143 | // The gap this type was born for: two candidates whose labels read |
| 6144 | // alike, told apart by the second string and by nothing else. The |
| 6145 | // measured site is the MNW tag box, where "Format" is a leaf under |
| 6146 | // audio, software, writing and video. |
| 6147 | let audio = new.detailed; |
| 6148 | let writing = new.detailed; |
| 6149 | |
| 6150 | assert_eq!; |
| 6151 | assert_ne!; |
| 6152 | assert_ne! |
| 6153 | audio, writing, |
| 6154 | "two rows a user cannot tell apart are two rows the type can" |
| 6155 | ; |
| 6156 | |
| 6157 | |
| 6158 | |
| 6159 | |
| 6160 | // The ruling's own distinction, held as a test so the two types do not |
| 6161 | // drift back together. Submitting is identical; the second line is the |
| 6162 | // whole of what differs, and it is absent by default because a list of |
| 6163 | // distinct labels wants nothing there. |
| 6164 | let candidate = plain; |
| 6165 | assert_eq!; |
| 6166 | assert_eq! |
| 6167 | candidate.detail, None, |
| 6168 | "one line unless the route says otherwise" |
| 6169 | ; |
| 6170 | |
| 6171 | let option = plain; |
| 6172 | assert_eq! |
| 6173 | , |
| 6174 | |
| 6175 | ; |
| 6176 | |
| 6177 | |
| 6178 | |
| 6179 | |
| 6180 | // Both offer a fixed set and both read `options`, so the two |
| 6181 | // constructors differ in exactly one thing. That one thing is the |
| 6182 | // point: a renderer decides whether the alternatives are readable |
| 6183 | // without opening anything, and it can only decide that if the |
| 6184 | // description said which question was asked. |
| 6185 | let styles = |
| 6186 | new, |
| 6187 | new, |
| 6188 | ]; |
| 6189 | let radio = radio; |
| 6190 | let select = select; |
| 6191 | |
| 6192 | assert_eq!; |
| 6193 | assert_ne!; |
| 6194 | assert_eq!; |
| 6195 | assert_eq! |
| 6196 | Field |
| 6197 | kind: select.kind, |
| 6198 | ..radio |
| 6199 | , |
| 6200 | select |
| 6201 | ; |
| 6202 | |
| 6203 | |
| 6204 | |
| 6205 | |
| 6206 | // The whole content of the one-member shape: saying an option is not |
| 6207 | // pickable and saying why are the same act, so the greyed-out-with-no- |
| 6208 | // reason state is unsayable rather than merely discouraged. |
| 6209 | let multi = |
| 6210 | new.unless; |
| 6211 | assert!; |
| 6212 | assert_eq! |
| 6213 | multi.unavailable, |
| 6214 | Some |
| 6215 | ; |
| 6216 | |
| 6217 | // And the option is still in the list, carrying what it submits, so a |
| 6218 | // renderer draws it rather than the app dropping it. |
| 6219 | assert_eq!; |
| 6220 | assert_eq!; |
| 6221 | |
| 6222 | |
| 6223 | |
| 6224 | |
| 6225 | // `5e21dcfc`. Two different sentences about one option, and an option |
| 6226 | // that has both has said two things: what the tier is, and that it is |
| 6227 | // not available yet. Folding them would be the label-folding this |
| 6228 | // member exists to end. |
| 6229 | let tier = new |
| 6230 | .detailing |
| 6231 | .unless; |
| 6232 | |
| 6233 | assert_eq! |
| 6234 | tier.detail, |
| 6235 | Some |
| 6236 | ; |
| 6237 | assert_eq! |
| 6238 | tier.unavailable, |
| 6239 | Some |
| 6240 | ; |
| 6241 | assert!; |
| 6242 | |
| 6243 | // Neither is implied by the other, which is what keeps a renderer from |
| 6244 | // reading a detail as a reason: an ordinary option with a second line |
| 6245 | // is still pickable. |
| 6246 | let plain = new.detailing; |
| 6247 | assert!; |
| 6248 | assert_eq!; |
| 6249 | assert_eq!; |
| 6250 | |
| 6251 | |
| 6252 | |
| 6253 | |
| 6254 | // The distinction the kind exists for, asserted rather than only |
| 6255 | // written down: bounds are a rule for one and the control itself for |
| 6256 | // the other. |
| 6257 | let threshold = range; |
| 6258 | assert_eq!; |
| 6259 | assert!; |
| 6260 | assert_eq!; |
| 6261 | assert_eq!; |
| 6262 | // Granularity is the host's until an app says otherwise. |
| 6263 | assert_eq!; |
| 6264 | |
| 6265 | // goingson's duration: a typed number with a floor, and it must not |
| 6266 | // read as a slider. |
| 6267 | let minutes = Field |
| 6268 | min: Some, |
| 6269 | ..new |
| 6270 | ; |
| 6271 | assert_ne!; |
| 6272 | assert!; |
| 6273 | |
| 6274 | |
| 6275 | |
| 6276 | |
| 6277 | // Nothing here enforces the pair, for the reason nothing here enforces |
| 6278 | // `required`: the description states the constraint and the renderer |
| 6279 | // asks. What it must not do is look bounded. |
| 6280 | let half = Field |
| 6281 | max: Some, |
| 6282 | ..new |
| 6283 | ; |
| 6284 | assert!; |
| 6285 | |
| 6286 | |
| 6287 | |
| 6288 | |
| 6289 | // The renderers branch on this rather than on a list of their own, so |
| 6290 | // a kind added without a decision here renders its options nowhere. |
| 6291 | assert!; |
| 6292 | assert!; |
| 6293 | for kind in |
| 6294 | Text, |
| 6295 | Secret, |
| 6296 | Number, |
| 6297 | Email, |
| 6298 | Url, |
| 6299 | Tel, |
| 6300 | Range, |
| 6301 | Textarea, |
| 6302 | Rich, |
| 6303 | Checkbox, |
| 6304 | Hidden, |
| 6305 | ] |
| 6306 | assert!; |
| 6307 | |
| 6308 | |
| 6309 | |
| 6310 | |
| 6311 | |
| 6312 | // The near-miss: each option is labelled beside its own button, so a |
| 6313 | // renderer could plausibly read the group as self-labelling and drop |
| 6314 | // the question. Checkbox is the only kind that does that. |
| 6315 | assert!; |
| 6316 | assert!; |
| 6317 | |
| 6318 | |
| 6319 | |
| 6320 | |
| 6321 | // An app whose option list has not loaded has exactly this. Making it |
| 6322 | // unrepresentable would push the state somewhere less visible, and a |
| 6323 | // renderer drawing an empty select reports it on screen. |
| 6324 | let loading = select; |
| 6325 | assert!; |
| 6326 | |
| 6327 | |
| 6328 | |
| 6329 | |
| 6330 | // The line 0.8.0 drew. Placeholder and options are properties of what |
| 6331 | // is being asked; the current value is what came back, and no field |
| 6332 | // here holds one. |
| 6333 | let f = Field |
| 6334 | placeholder: Some, |
| 6335 | ..new |
| 6336 | ; |
| 6337 | assert_eq!; |
| 6338 | // A placeholder is not a label, and having one does not excuse the |
| 6339 | // field from carrying the other. |
| 6340 | assert_eq!; |
| 6341 | |
| 6342 | |
| 6343 | |
| 6344 | |
| 6345 | let mut f = new; |
| 6346 | assert!; |
| 6347 | f.error = Some; |
| 6348 | assert!; |
| 6349 | |
| 6350 | |
| 6351 | |
| 6352 | |
| 6353 | let cols = |
| 6354 | Column |
| 6355 | width: Fill, |
| 6356 | priority: Essential, |
| 6357 | ..new |
| 6358 | , |
| 6359 | Column |
| 6360 | width: Fixed, |
| 6361 | priority: Secondary, |
| 6362 | ..new |
| 6363 | , |
| 6364 | Column |
| 6365 | width: Fixed, |
| 6366 | priority: Optional, |
| 6367 | ..new |
| 6368 | , |
| 6369 | ]; |
| 6370 | |
| 6371 | // Widest: everything survives. |
| 6372 | assert_eq! |
| 6373 | cols.iter |
| 6374 | .filter |
| 6375 | .count, |
| 6376 | 3 |
| 6377 | ; |
| 6378 | // Narrower: the optional column goes first. |
| 6379 | let kept: = cols |
| 6380 | .iter |
| 6381 | .filter |
| 6382 | .map |
| 6383 | .collect; |
| 6384 | assert_eq!; |
| 6385 | // Narrowest: only what identifies the row. |
| 6386 | let kept: = cols |
| 6387 | .iter |
| 6388 | .filter |
| 6389 | .map |
| 6390 | .collect; |
| 6391 | assert_eq!; |
| 6392 | |
| 6393 | |
| 6394 | |
| 6395 | |
| 6396 | // The bug the ordinal form has and this form cannot: goingson hides |
| 6397 | // `nth-child(n+5)` against a seven-column table, so a column inserted |
| 6398 | // anywhere to the left silently hides a different one. |
| 6399 | let before = |
| 6400 | new, |
| 6401 | Column |
| 6402 | width: Fixed, |
| 6403 | priority: Optional, |
| 6404 | ..new |
| 6405 | , |
| 6406 | ]; |
| 6407 | let after = |
| 6408 | new, |
| 6409 | new, // inserted |
| 6410 | Column |
| 6411 | width: Fixed, |
| 6412 | priority: Optional, |
| 6413 | ..new |
| 6414 | , |
| 6415 | ]; |
| 6416 | |
| 6417 | |
| 6418 | cols.iter |
| 6419 | .filter |
| 6420 | .map |
| 6421 | .collect |
| 6422 | |
| 6423 | assert_eq!; |
| 6424 | assert_eq!; |
| 6425 | |
| 6426 | |
| 6427 | |
| 6428 | |
| 6429 | // goingson uses the tab group inside the content region rather than |
| 6430 | // instead of one, so it is not a third arrangement. |
| 6431 | let go = list_detail; |
| 6432 | let plain = list_detail; |
| 6433 | assert_ne!; |
| 6434 | assert_ne!; |
| 6435 | |
| 6436 | |
| 6437 | |
| 6438 | |
| 6439 | // The point of the member: a terminal reading columns and a webview |
| 6440 | // reading a grid honour one fact, so two hosts showing one screen agree |
| 6441 | // about its proportions. |
| 6442 | assert_eq!; |
| 6443 | assert_eq!; |
| 6444 | assert_eq! |
| 6445 | SIDEBAR.of, |
| 6446 | 24, |
| 6447 | "quasi-tui's 24 columns, said as a quarter" |
| 6448 | ; |
| 6449 | |
| 6450 | |
| 6451 | |
| 6452 | |
| 6453 | // A region the description named should be visible. A zero-width one |
| 6454 | // reads on screen as a region that vanished, which is the hardest kind |
| 6455 | // of bug to find from what is drawn. |
| 6456 | assert_eq!; |
| 6457 | assert_eq!; |
| 6458 | |
| 6459 | |
| 6460 | |
| 6461 | |
| 6462 | assert_eq!; |
| 6463 | assert_eq!; |
| 6464 | |
| 6465 | |
| 6466 | |
| 6467 | |
| 6468 | // How much a sidebar takes and how much a list side takes are different |
| 6469 | // questions, and this enum is the only thing that knows which is being |
| 6470 | // asked. |
| 6471 | assert_eq!; |
| 6472 | assert_eq!; |
| 6473 | // One region divides nothing, so there is no share to answer with. |
| 6474 | assert_eq!; |
| 6475 | assert_eq! |
| 6476 | Single.with_share, |
| 6477 | Single |
| 6478 | ; |
| 6479 | |
| 6480 | let narrow = sidebar_content.with_share; |
| 6481 | assert_eq!; |
| 6482 | assert!; |
| 6483 | |
| 6484 | |
| 6485 | |
| 6486 | |
| 6487 | // The default is meaningful: a screen nobody said anything about uses |
| 6488 | // the window it was given. |
| 6489 | assert_eq!; |
| 6490 | assert_eq!; |
| 6491 | |
| 6492 | |
| 6493 | |
| 6494 | |
| 6495 | // Two members and no third. If a skeleton ever appears in this enum, |
| 6496 | // the deferral rule has been broken. |
| 6497 | assert_ne!; |
| 6498 | |
| 6499 | |
| 6500 | |
| 6501 | |
| 6502 | // The uncounted case is the common one, not the degenerate one: a query |
| 6503 | // that asked for 51 to learn there were more than 50 knows there are, |
| 6504 | // and not how many. |
| 6505 | let uncounted = new; |
| 6506 | assert_eq!; |
| 6507 | assert_eq!; |
| 6508 | assert!; |
| 6509 | // Unknown length cannot rule out more, and offering a way forward that |
| 6510 | // turns out empty is the cheaper mistake. |
| 6511 | assert!; |
| 6512 | |
| 6513 | |
| 6514 | |
| 6515 | |
| 6516 | let last = new.of; |
| 6517 | assert_eq!; |
| 6518 | assert_eq!; |
| 6519 | assert!; |
| 6520 | assert!; |
| 6521 | |
| 6522 | let first = new.of; |
| 6523 | assert!; |
| 6524 | assert!; |
| 6525 | |
| 6526 | |
| 6527 | |
| 6528 | |
| 6529 | // 401 rows in pages of 50 is eight pages and a straggler, which is nine |
| 6530 | // pages. Rounding down would make the last one unreachable. |
| 6531 | assert_eq!; |
| 6532 | |
| 6533 | |
| 6534 | |
| 6535 | |
| 6536 | let empty = new.of; |
| 6537 | assert_eq!; |
| 6538 | assert_eq!; |
| 6539 | // And it still clamps rather than panicking. |
| 6540 | assert_eq!; |
| 6541 | |
| 6542 | |
| 6543 | |
| 6544 | |
| 6545 | // `Slot::current`'s reasoning, one layer down: a description pointing |
| 6546 | // past the end is a host bug, and answering it by drawing nothing |
| 6547 | // reports a region that vanished. |
| 6548 | assert_eq!; |
| 6549 | // Nothing to clamp against when the length is unknown. |
| 6550 | assert_eq!; |
| 6551 | |
| 6552 | |
| 6553 | |
| 6554 | |
| 6555 | // The shape a carousel instantiates. Same code as a paged list, which is |
| 6556 | // the whole reason `Window` exists rather than two copies of it. |
| 6557 | let third = frame; |
| 6558 | assert_eq!; |
| 6559 | assert_eq!; |
| 6560 | assert!; |
| 6561 | assert!; |
| 6562 | |
| 6563 | let last = frame; |
| 6564 | assert!; |
| 6565 | |
| 6566 | |
| 6567 | |
| 6568 | |
| 6569 | // The page number is read aloud, so it is one-based; `Window::index` is |
| 6570 | // the zero-based form for indexing. |
| 6571 | let third = pages.of; |
| 6572 | assert_eq!; |
| 6573 | assert_eq!; |
| 6574 | assert_eq!; |
| 6575 | assert!; |
| 6576 | assert!; |
| 6577 | |
| 6578 | // Load-more grew a window from the start, so "page 2" would name |
| 6579 | // nothing and the type says so rather than inventing one. |
| 6580 | let grown = more.of; |
| 6581 | assert_eq!; |
| 6582 | assert_eq!; |
| 6583 | assert_eq!; |
| 6584 | assert!; |
| 6585 | assert!; |
| 6586 | |
| 6587 | |
| 6588 | |
| 6589 | |
| 6590 | // What a host that will not pay for a COUNT describes. `None` here is |
| 6591 | // permanent: a total arriving later would widen the text that prints it, |
| 6592 | // which is the reflow "first paint is final paint" forbids. |
| 6593 | let feed = more; |
| 6594 | assert_eq!; |
| 6595 | assert_eq!; |
| 6596 | assert_eq!; |
| 6597 | assert!; |
| 6598 | |
| 6599 | |
| 6600 | |
| 6601 | |
| 6602 | assert_eq!; |
| 6603 | assert_eq!; |
| 6604 | // A host that overshot its own total gets zero rather than a wrapped |
| 6605 | // usize, which would print as "18446744073709551516 remaining". |
| 6606 | assert_eq!; |
| 6607 | |
| 6608 | |
| 6609 | |
| 6610 | |
| 6611 | // No `Default`. The compiler is what enforces rule 2, so the assertion |
| 6612 | // that matters is one this file cannot write; what it can say is that |
| 6613 | // the four authored answers are distinct and none is privileged. |
| 6614 | let all = |
| 6615 | Wrap, |
| 6616 | Stack, |
| 6617 | Shed, |
| 6618 | Menu, |
| 6619 | ]; |
| 6620 | for in all.iter.enumerate |
| 6621 | for b in &all |
| 6622 | assert_ne!; |
| 6623 | |
| 6624 | |
| 6625 | |
| 6626 | |
| 6627 | |
| 6628 | |
| 6629 | // Priority is read the same way for a group member as for a column, |
| 6630 | // which is the whole claim of generalising it off `Column`. |
| 6631 | let members = |
| 6632 | , |
| 6633 | , |
| 6634 | , |
| 6635 | ]; |
| 6636 | let kept: = members |
| 6637 | .iter |
| 6638 | .filter |
| 6639 | .map |
| 6640 | .collect; |
| 6641 | assert_eq!; |
| 6642 | |
| 6643 | |
| 6644 | |
| 6645 | |
| 6646 | // The row still identifies itself after everything droppable has gone, |
| 6647 | // which is the property the ladder exists for. |
| 6648 | assert_eq!; |
| 6649 | // A control is not a fact. Room comes out of what the row says, never |
| 6650 | // out of what it offers. |
| 6651 | assert_eq!; |
| 6652 | assert_eq!; |
| 6653 | assert_eq!; |
| 6654 | assert_eq!; |
| 6655 | // Tokens sit in the middle deliberately: a toned badge is often the |
| 6656 | // most scannable thing in a row, so it does not go first. |
| 6657 | assert_eq!; |
| 6658 | |
| 6659 | |
| 6660 | |
| 6661 | |
| 6662 | // The default is what every part did before flows existed, so a |
| 6663 | // description written against the old vocabulary keeps its rendering. |
| 6664 | assert_eq!; |
| 6665 | assert_eq!; |
| 6666 | assert_eq!; |
| 6667 | |
| 6668 | |
| 6669 | |
| 6670 | |
| 6671 | // `#[non_exhaustive]`'s cost, taken deliberately. A tier added upstream |
| 6672 | // reaches an old renderer as one line rather than as a build break, and |
| 6673 | // one line is the reading that cannot break a neighbour's layout. The |
| 6674 | // match in `lines` is what this holds; it fails if a new tier is given |
| 6675 | // an arm that returns something unbounded. |
| 6676 | for flow in |
| 6677 | assert!; |
| 6678 | |
| 6679 | |
| 6680 | |
| 6681 | |
| 6682 | |
| 6683 | // The default is the common case: a call waits, and nothing about it is |
| 6684 | // countable. A determinate bar is the exception and says so. |
| 6685 | assert_eq!; |
| 6686 | assert!; |
| 6687 | assert!; |
| 6688 | assert_eq!; |
| 6689 | |
| 6690 | |
| 6691 | // A slider is a fraction and a mapping |
| 6692 | // |
| 6693 | // `Curve` is the one thing in this crate that computes rather than |
| 6694 | // describes, and it does so because four renderers would otherwise each |
| 6695 | // write these two formulas and drift. So the formulas are pinned here. |
| 6696 | |
| 6697 | /// The bounds of audiofiles' envelope attack, the curve's first consumer. |
| 6698 | const ATTACK: = ; |
| 6699 | |
| 6700 | |
| 6701 | |
| 6702 | assert_eq!; |
| 6703 | let plain = range; |
| 6704 | assert_eq!; |
| 6705 | assert_eq!; |
| 6706 | |
| 6707 | |
| 6708 | |
| 6709 | |
| 6710 | assert_eq!; |
| 6711 | assert_eq! |
| 6712 | Logarithmic |
| 6713 | step: Some |
| 6714 | |
| 6715 | .step, |
| 6716 | Some |
| 6717 | ; |
| 6718 | |
| 6719 | |
| 6720 | |
| 6721 | |
| 6722 | // `min` and `max` are `f(0)` and `f(1)`. That is the whole reframe, and |
| 6723 | // it has to hold for a mapping that is not the identity or the bounds |
| 6724 | // have stopped meaning what the field says they mean. |
| 6725 | let = ATTACK; |
| 6726 | for curve in |
| 6727 | Linear , |
| 6728 | Logarithmic , |
| 6729 | ] |
| 6730 | assert!; |
| 6731 | assert!; |
| 6732 | |
| 6733 | |
| 6734 | |
| 6735 | |
| 6736 | |
| 6737 | let = ATTACK; |
| 6738 | let linear = Linear .value_at; |
| 6739 | assert!; |
| 6740 | |
| 6741 | // The reason the envelope is not linear: half way along a log track is |
| 6742 | // 70 ms, and half way along a linear one is 2.5 seconds. Every attack a |
| 6743 | // sampler is actually played with lives below the first. |
| 6744 | let ratio = Logarithmic .value_at; |
| 6745 | assert!; |
| 6746 | assert!; |
| 6747 | |
| 6748 | |
| 6749 | |
| 6750 | |
| 6751 | let = ATTACK; |
| 6752 | for curve in |
| 6753 | Linear , |
| 6754 | Logarithmic , |
| 6755 | ] |
| 6756 | for position in |
| 6757 | let back = curve.position_of; |
| 6758 | assert! |
| 6759 | .abs < 1e-9, |
| 6760 | "{curve:?} lost {position} (got {back})" |
| 6761 | ; |
| 6762 | |
| 6763 | |
| 6764 | |
| 6765 | |
| 6766 | |
| 6767 | |
| 6768 | // An envelope's sustain is a 0-to-1 level. A constant ratio is |
| 6769 | // undefined there, and the answer is the linear mapping rather than a |
| 6770 | // NaN reaching a renderer that would paint it. |
| 6771 | let curve = Logarithmic ; |
| 6772 | assert!; |
| 6773 | assert!; |
| 6774 | assert!; |
| 6775 | assert!; |
| 6776 | |
| 6777 | |
| 6778 | |
| 6779 | |
| 6780 | for curve in |
| 6781 | Linear , |
| 6782 | Logarithmic , |
| 6783 | ] |
| 6784 | assert!; |
| 6785 | assert!; |
| 6786 | // Inverted bounds are the same degenerate answer, not a negative |
| 6787 | // extent a renderer would draw backwards. |
| 6788 | assert!; |
| 6789 | |
| 6790 | |
| 6791 | |
| 6792 | |
| 6793 | |
| 6794 | let = ATTACK; |
| 6795 | let curve = Logarithmic ; |
| 6796 | assert!; |
| 6797 | assert!; |
| 6798 | assert!; |
| 6799 | assert!; |
| 6800 | |
| 6801 | |
| 6802 | |
| 6803 | |
| 6804 | // The split the 0.32.0 narrowing is: two granularities that were one |
| 6805 | // member, and the kinds that take them do not overlap. |
| 6806 | let typed = Field |
| 6807 | step: Some, |
| 6808 | ..new |
| 6809 | ; |
| 6810 | assert_eq!; |
| 6811 | |
| 6812 | let slid = Field |
| 6813 | curve: Logarithmic |
| 6814 | step: Some, |
| 6815 | , |
| 6816 | ..range |
| 6817 | ; |
| 6818 | assert_eq!; |
| 6819 | assert_eq!; |
| 6820 | |
| 6821 | |
| 6822 | |
| 6823 | |
| 6824 | // The substitution hazard the constructor exists against: `options` is |
| 6825 | // right there and reads as if it would work, and a renderer walking it |
| 6826 | // for a theme picker draws an empty control. |
| 6827 | let themes = |
| 6828 | new, |
| 6829 | new, |
| 6830 | ]; |
| 6831 | let field = theme; |
| 6832 | |
| 6833 | assert_eq!; |
| 6834 | assert!; |
| 6835 | assert!; |
| 6836 | assert_eq!; |
| 6837 | assert!; |
| 6838 | assert_eq!; |
| 6839 | |
| 6840 | |
| 6841 | |
| 6842 | |
| 6843 | // Not hardcoded here: the value belongs to the app's config table, and |
| 6844 | // this crate holds no facts about somebody else's store. |
| 6845 | let field = |
| 6846 | theme.following; |
| 6847 | let follow = field.follows.expect; |
| 6848 | assert_eq!; |
| 6849 | assert_eq!; |
| 6850 | |
| 6851 | |
| 6852 | |
| 6853 | |
| 6854 | // A machine whose theme directories hold nothing. The description is |
| 6855 | // true and a renderer says so on screen rather than in a log, which is |
| 6856 | // `Field::options`' own arrangement. |
| 6857 | let field = theme; |
| 6858 | assert!; |
| 6859 | |
| 6860 | |
| 6861 | |
| 6862 | |
| 6863 | for kind in |
| 6864 | Text, |
| 6865 | Select, |
| 6866 | Radio, |
| 6867 | Checkbox, |
| 6868 | File, |
| 6869 | Hidden, |
| 6870 | ] |
| 6871 | assert! |
| 6872 | !kind.offers_themes, |
| 6873 | "{kind:?} does not read Field::themes" |
| 6874 | ; |
| 6875 | |
| 6876 | |
| 6877 | |
| 6878 | |
| 6879 | |
| 6880 | // Matches `makeover::ContrastTier`, so an adopter's conversion cannot |
| 6881 | // invert an ordering by accident and a sort agrees across the seam. |
| 6882 | assert!; |
| 6883 | assert!; |
| 6884 | |
| 6885 | |
| 6886 | |
| 6887 | |
| 6888 | // The whole argument for these living here: three renderers picking |
| 6889 | // their own is one picker reading three ways. |
| 6890 | assert_eq!; |
| 6891 | assert_eq!; |
| 6892 | assert_eq!; |
| 6893 | |
| 6894 | assert_eq!; |
| 6895 | |
| 6896 | assert_eq!; |
| 6897 | assert_eq!; |
| 6898 | assert_eq!; |
| 6899 | |
| 6900 | |
| 6901 | |
| 6902 | |
| 6903 | // The seam this enum is duplicated across. `makeover::parse_meta` reads |
| 6904 | // `meta.variant` as one of these three strings; a rename on either side |
| 6905 | // that does not move together silently regroups every picker. |
| 6906 | for in |
| 6907 | , |
| 6908 | , |
| 6909 | , |
| 6910 | ] |
| 6911 | assert_eq!; |
| 6912 | assert_eq!; |
| 6913 | |
| 6914 | |
| 6915 | |
| 6916 |