max / makeover-immediate
| 1 | //! The immediate-mode renderer for [`makeover_layout`]. |
| 2 | //! |
| 3 | //! <!-- wiki: makeover-immediate --> |
| 4 | //! |
| 5 | //! Named for the mode, not the library, the way `makeover-tui` is named for |
| 6 | //! the target and not for ratatui. Immediate mode is the constraint that |
| 7 | //! actually separates this renderer from the other two, and egui is the |
| 8 | //! backend it is written against. |
| 9 | //! |
| 10 | //! It is the harshest renderer the description has to survive: no |
| 11 | //! `box-shadow`, no `inset`, no cascade, no retained tree to mutate, and |
| 12 | //! `Visuals.widgets.*.bg_stroke` is a single stroke with no per-side control. |
| 13 | //! A two-tone lit edge is not something egui can be configured into producing, |
| 14 | //! so it gets painted by hand here, once, instead of in every consuming app. |
| 15 | //! |
| 16 | //! # What this crate does and does not own |
| 17 | //! |
| 18 | //! It owns the *expression*: two mitred polylines for a bevel and a `Frame` |
| 19 | //! for a filled region. It owns no colours and no sizes, and no longer owns a |
| 20 | //! substitution: it briefly supplied the page for a well, which was a stand-in |
| 21 | //! for `surface-well` before makeover derived it, and every consumer reads the |
| 22 | //! real token now. [`Palette`] is supplied by the caller, |
| 23 | //! already resolved, and every radius, margin and stroke width arrives in |
| 24 | //! [`FrameStyle`]. |
| 25 | //! |
| 26 | //! That split is why the crate has no dependency on `makeover` itself: the app |
| 27 | //! already resolves a theme, and coupling a renderer to a colour crate's |
| 28 | //! version would buy nothing. |
| 29 | //! |
| 30 | //! # The cascade is the real difference |
| 31 | //! |
| 32 | //! A stylesheet can say "a pressed button inverts its bevel" once and let the |
| 33 | //! cascade carry it. An immediate-mode renderer has nowhere to put that, so |
| 34 | //! every call site decides. [`makeover_layout::Depth::pressed`] is what keeps |
| 35 | //! the decision from being re-derived per widget. |
| 36 | //! |
| 37 | //! # 0.11.0: the overlay becomes reachable |
| 38 | //! |
| 39 | //! 0.10.0 answered what overlaying means in immediate mode with |
| 40 | //! [`Palette::cast`], and nothing could ask: the description had no |
| 41 | //! `Depth::Overlay` until `makeover-layout` 0.14.0, so the answer sat beside a |
| 42 | //! question that could not be posed. [`frame`] now hands the cast shadow to the |
| 43 | //! `egui::Frame` for any depth whose fill is [`Fill::Overlay`], keyed off the |
| 44 | //! fill rather than the variant. |
| 45 | //! |
| 46 | //! The same release brings `makeover_layout::CellPart`, which 0.11.0 carried |
| 47 | //! and did not draw. [`table`] draws it, below. |
| 48 | //! |
| 49 | //! # 0.12.0: the table |
| 50 | //! |
| 51 | //! [`table`] is the vocabulary 0.11.0 took without using. The consumer is |
| 52 | //! audiofiles, whose file list is the only table in the tree exercising all four |
| 53 | //! of what the description says about one at once: sortable headings with |
| 54 | //! carets, fixed and remainder tracks, and buttons inside cells. |
| 55 | //! |
| 56 | //! Two things it forces, both named where they land: |
| 57 | //! |
| 58 | //! - **`egui_extras`**, this crate's first dependency past egui. egui has no |
| 59 | //! table, and `Grid` gives no per-column sizing, no sticky header and no |
| 60 | //! scroll sync, which is why audiofiles reached for `egui_extras` rather than |
| 61 | //! building on `Grid`. A third answer here would reimplement that crate worse. |
| 62 | //! - **[`Palette::action`]**, on the footing [`Palette::content`] arrived on: a |
| 63 | //! link in a cell is the first thing here needing the action intent. |
| 64 | //! |
| 65 | //! Narrowing works differently from the terminal's and the module header says |
| 66 | //! why: a content column cannot be measured before the app's closure has drawn |
| 67 | //! it, so `egui_extras` sizes it and the declared floor budgets it. |
| 68 | //! |
| 69 | //! # 0.13.0: what the adoption found missing |
| 70 | //! |
| 71 | //! 0.12.0 shipped [`table`] before audiofiles had taken it, and taking it found |
| 72 | //! three things the file list already did that the function could not say. All |
| 73 | //! three are host idiom rather than description, which is why they land here and |
| 74 | //! not in `makeover-layout`, and all three are answered on a handle the app |
| 75 | //! never sees: the `egui_extras` row and builder this crate owns. That is |
| 76 | //! [`table::cell`]'s reasoning again: what the app cannot reach, the renderer |
| 77 | //! owes it. |
| 78 | //! |
| 79 | //! - **A selected row.** [`table::Body::selected`], a predicate asked per row, |
| 80 | //! because `set_selected` is a method on the row. Without it a file list has |
| 81 | //! no way to show what is selected, which is most of what a file list does. |
| 82 | //! - **Scrolling a row into view.** [`table::Body::scroll_to`], because |
| 83 | //! `scroll_to_row` is a method on the builder. A keyboard cursor that moves |
| 84 | //! off-screen and stays there is the bug this prevents. |
| 85 | //! - **Dragging a divider.** [`table::TableStyle::resizable`], which passes the |
| 86 | //! test `sticky_header` failed in 0.12.0: egui_extras offers two settings here |
| 87 | //! and a renderer can honestly make either choice. |
| 88 | //! |
| 89 | //! A fourth was found and is not a knob. Cells are centred on the row's centre |
| 90 | //! line, always, because there is no second honest answer and egui's own default |
| 91 | //! (top-aligned) is the one thing it cannot be. |
| 92 | //! |
| 93 | //! [`table::Body`] is also what splits a table's per-frame facts from its |
| 94 | //! description and from its style. A row count, a selection and a scroll request |
| 95 | //! are none of them style, and none of them survive the frame. |
| 96 | //! |
| 97 | //! # 0.18.0: the nodes that were not fields, tables or frames |
| 98 | //! |
| 99 | //! [`widget`] draws a meter, a token, a control and a figure. `makeover-tui` has |
| 100 | //! had all four for releases and this crate had none of them, which stayed |
| 101 | //! invisible while the only consumer was an app calling [`field`] and [`table`] |
| 102 | //! directly. It stopped being invisible the moment anything tried to draw a |
| 103 | //! whole `quasi_router::Screen` in egui: the four are ordinary nodes, so a |
| 104 | //! screen walk would have had to draw them itself, one copy per consumer. |
| 105 | //! |
| 106 | //! [`Palette`] grows the three status intents with it. They arrive together |
| 107 | //! rather than one per widget for the reason [`Palette::fill`] is an `Option`: |
| 108 | //! `Tone` is five members wide, and a resolver missing one has to invent a |
| 109 | //! colour, which is the substitution 0.2.0 spent a release removing. |
| 110 | //! |
| 111 | //! # Forms |
| 112 | //! |
| 113 | //! 0.5.0 adds the field vocabulary on top of the depth vocabulary: |
| 114 | //! [`makeover_layout::Field`] rendered to egui widgets, in [`field`], and a set |
| 115 | //! of them laid down a column in [`group`]. Before it, a description saying |
| 116 | //! "text field, labelled, required, with this hint" had no way to become a |
| 117 | //! widget here, and audiofiles' forms stayed hand-rolled. |
| 118 | //! |
| 119 | //! `makeover-webview` got there first and its form emitter is the precedent |
| 120 | //! followed rather than re-derived, including the parts that are bug fixes: a |
| 121 | //! select handed a value none of its options carries keeps that value visible |
| 122 | //! instead of silently reading as the first option, which is a save-the-wrong- |
| 123 | //! thing bug goingson hit for real. |
| 124 | //! |
| 125 | //! What differs is forced by the mode and not chosen: |
| 126 | //! |
| 127 | //! - **The value arrives as a `&mut`.** [`Filling`] borrows the app's own field |
| 128 | //! and the widget writes through it. There is no DOM to read back out of, |
| 129 | //! which is also why the description deliberately does not carry the value. |
| 130 | //! - **A text control is drawn as a well and a select is not.** The description |
| 131 | //! holds that a well is for anything the user looks *into*, and a text field |
| 132 | //! is its own example; a select and a checkbox are pressed rather than looked |
| 133 | //! into, so they keep egui's own control painting. |
| 134 | //! - **Focus is not describable, and egui owns all of it here.** **Reach**, |
| 135 | //! **focus** and the **focus ring** are this renderer's three answers and |
| 136 | //! egui already has all three: its own id stack decides what is reachable, |
| 137 | //! its own state decides what holds the keyboard, and it paints exactly one |
| 138 | //! ring. A description states none of them — `makeover_layout` removed the |
| 139 | //! member that used to try in 0.19.0 — and drawing a second ring on top of |
| 140 | //! egui's would break the one-ring rule it would have come from. The terms |
| 141 | //! are defined once in `makeover_layout`'s crate header, "Reach, focus and |
| 142 | //! the focus ring". [`makeover_layout::State::Disabled`] *is* drawn, because |
| 143 | //! egui has no opinion about it until told. |
| 144 | //! - **App-level chrome is not drawn here, and it is not this crate's to |
| 145 | //! draw.** `quasi-router` names the affordances that outlive one screen: a |
| 146 | //! `Chrome` of key bindings, and an `Outcome::Over` for a screen drawn over |
| 147 | //! another. Both are answered by `quasi-webview` and `quasi-tui`, and neither |
| 148 | //! is answerable here, because this crate depends on `makeover-layout` and |
| 149 | //! not on `quasi-router` — it is the peer of `makeover-webview` and |
| 150 | //! `makeover-tui`, one layer below the renderers that consume a `Screen`. |
| 151 | //! What is missing is the egui crate at *that* layer, which does not exist: |
| 152 | //! nothing renders a quasi `Screen` in egui at all, and chrome is one item on |
| 153 | //! the list such a crate would owe. Said here because this is where a reader |
| 154 | //! looks for it, and because the silent version reads as "egui does not need |
| 155 | //! a palette" rather than "nobody has built the renderer yet". |
| 156 | |
| 157 | //! # 0.33.0: an interval is a sixth control shape |
| 158 | //! |
| 159 | //! `makeover-layout` 0.34.0's [`FieldKind::Interval`], drawn as `Control::Spanned`: |
| 160 | //! two drag boxes on one row with the word `to` between them. |
| 161 | //! |
| 162 | //! - **Dragged rather than typed**, because that is what these controls already |
| 163 | //! were. audiofiles' six filter axes are `DragValue` pairs sharing an extent, |
| 164 | //! a speed and a suffix, and describing them into two text boxes would be a |
| 165 | //! port that cost the app a control. |
| 166 | //! - **One row, not two wells stacked.** Two wells are two questions on screen |
| 167 | //! whatever the description says, and the arrangement is the whole content of |
| 168 | //! the kind. |
| 169 | //! - **An empty end reads as the bound it stands for.** An unset minimum sits |
| 170 | //! on the low edge and stores no filter, which is what the shipped control |
| 171 | //! did; egui's `DragValue` has no empty state, and a text box in its place |
| 172 | //! would be the regression above. With no extent to fall back on it reads |
| 173 | //! zero -- the one number this renderer invents, invented where the |
| 174 | //! description declined to say anything. |
| 175 | //! - **The word rather than a dash**, which on a signed axis is a minus sign. |
| 176 | //! audiofiles filters loudness in dBFS. |
| 177 | //! |
| 178 | //! `Axis` holds the four facts both boxes share, because they are one axis: |
| 179 | //! reading `min`, `max`, `step` and `unit` once is what stops the two ends |
| 180 | //! drifting apart. |
| 181 | //! |
| 182 | //! # 0.32.0: a number draws its unit |
| 183 | //! |
| 184 | //! `makeover-layout` 0.33.0's [`Field::unit`], and this host is the one the |
| 185 | //! member was argued from: egui's `Slider` already draws a suffix beside its |
| 186 | //! readout, which is where these controls put the unit before they were |
| 187 | //! described and is somewhere a label cannot reach. |
| 188 | //! |
| 189 | //! So a slider takes it as a suffix, inside the control. A typed number has no |
| 190 | //! readout of its own and takes it as a muted label after the box. Every other |
| 191 | //! kind ignores it, and the description says which those are -- |
| 192 | //! `FieldKind::measurable`, rather than a `matches!` kept here. |
| 193 | //! |
| 194 | //! # 0.31.0: the slider's track is a curve |
| 195 | //! |
| 196 | //! `makeover-layout` 0.32.0 says what a slider is: a fraction and a function |
| 197 | //! taking numbers to numbers, with `min` and `max` being `f(0)` and `f(1)` |
| 198 | //! rather than the control's extent. This host has the easiest job of the |
| 199 | //! three, because egui already has the control -- `Slider::logarithmic` is a |
| 200 | //! constant-ratio track, so the mapping is a builder call rather than an |
| 201 | //! arithmetic of its own. |
| 202 | //! |
| 203 | //! Two things worth knowing. The granularity moved onto the curve, so a range |
| 204 | //! reads `Field::curve.step()` and every other kind still reads `Field::step`; |
| 205 | //! the step is in the value's own units under either curve, so the display |
| 206 | //! precision is derived exactly as before. And the fallback for a ratio curve |
| 207 | //! across zero is asked of `Curve::is_ratio` rather than matched on the |
| 208 | //! variant, so this renderer and a terminal cannot disagree about when a |
| 209 | //! logarithmic request is honoured. |
| 210 | //! |
| 211 | //! # 0.28.0: the slider, the unanswered chooser, and the option that is not |
| 212 | //! offered yet |
| 213 | //! |
| 214 | //! Three things `makeover-layout` 0.28.0 lets a description say, all three |
| 215 | //! found by audiofiles' forms port hitting a wall it could not describe its way |
| 216 | //! past. |
| 217 | //! |
| 218 | //! - **[`FieldKind::Range`] is a fifth control shape**, `Control::Slid`, and |
| 219 | //! the first one added since 0.5.0. egui has `Slider` and this crate had no |
| 220 | //! way to be asked for one, so four sliders in the only consuming app stayed |
| 221 | //! hand-rolled against a vocabulary that could not name them. A range missing |
| 222 | //! an end falls back to a well rather than to invented bounds, which is what |
| 223 | //! `makeover_layout::Field::bounded` is for. |
| 224 | //! - **`Field::placeholder` finally reads on a chooser.** It was sayable and |
| 225 | //! this renderer ignored it, so a select with nothing chosen showed an empty |
| 226 | //! box. Nothing new is described; the renderer caught up. |
| 227 | //! - **`Choice::unavailable` is drawn rather than dropped.** The option stays |
| 228 | //! in the list, inert, with its precondition beside it instead of behind a |
| 229 | //! hover — a greyed row with no reason reads as a dead end, which is the |
| 230 | //! whole finding. |
| 231 | //! |
| 232 | //! The value still arrives as a `&mut String` and a slider is a number, so the |
| 233 | //! parse and the write-back are this renderer's, and the write happens only on |
| 234 | //! a real drag: a value the app put there that this host cannot read survives |
| 235 | //! being looked at. |
| 236 | |
| 237 | |
| 238 | |
| 239 | use |
| 240 | Color32, ComboBox, CornerRadius, DragValue, Margin, Painter, Rect, Response, RichText, Shape, |
| 241 | Slider, Stroke, TextEdit, Ui, |
| 242 | ; |
| 243 | use ; |
| 244 | use RangeInclusive; |
| 245 | |
| 246 | /// Columns, narrowing, cell parts and the sort caret, over `egui_extras`. |
| 247 | |
| 248 | |
| 249 | |
| 250 | /// The resolved colours this renderer needs, as flat values. |
| 251 | /// |
| 252 | /// Built by the app from whatever it already uses to resolve a theme, then |
| 253 | /// held and reused. Deliberately not a trait and not string-keyed: a bevel is |
| 254 | /// painted per widget per frame, and a map lookup per edge is a cost with |
| 255 | /// nothing to show for it. |
| 256 | |
| 257 | |
| 258 | /// `surface-page`. |
| 259 | pub page: Color32, |
| 260 | /// `surface-raised`. |
| 261 | pub raised: Color32, |
| 262 | /// `surface-overlay`. |
| 263 | pub overlay: Color32, |
| 264 | /// `surface-well`. |
| 265 | /// |
| 266 | /// Required, not optional. makeover derives it for every theme from 2.3.0, |
| 267 | /// so a resolved palette without a well is not a thing that exists here. |
| 268 | /// It was an `Option` while that was untrue, and this renderer substituted |
| 269 | /// the page; `makeover-tui` keeps its own `Option` for a different reason, |
| 270 | /// since a terminal can have the colour and still be unable to show it. |
| 271 | pub well: Color32, |
| 272 | /// `surface-sunken`. |
| 273 | /// |
| 274 | /// A surface set back from the one it sits on, by colour and nothing else. |
| 275 | /// Not a well: a well is a hole with an edge, and this has no edge. An |
| 276 | /// immediate-mode renderer paints an arbitrary rect, so unlike |
| 277 | /// `makeover-tui` it has no excuse for declining this one. |
| 278 | /// |
| 279 | /// Required rather than optional, on the same footing as `well`: all 31 |
| 280 | /// themes makeover embeds author it. |
| 281 | pub sunken: Color32, |
| 282 | /// `bevel-light`. |
| 283 | pub bevel_light: Color32, |
| 284 | /// `bevel-dark`. |
| 285 | pub bevel_dark: Color32, |
| 286 | /// `elevation`. |
| 287 | /// |
| 288 | /// What a surface that floats OVER the page is cast onto it with. The one |
| 289 | /// intent here that is about a surface's relationship to the page rather |
| 290 | /// than about the surface, which is why it is a translucent near-black on |
| 291 | /// every theme rather than something read off the palette's own ramp. |
| 292 | /// |
| 293 | /// **Only for a surface that overlays.** A menu, a tooltip, a modal. A |
| 294 | /// surface *in* the layout takes a bevel, and reaching for this on a panel |
| 295 | /// or a card is how a pre-Platinum look survives a conversion under a new |
| 296 | /// name. |
| 297 | /// |
| 298 | /// egui has a real answer for this where a terminal does not: see |
| 299 | /// [`Palette::cast`], which is the shadow to hand an |
| 300 | /// [`egui::Frame`](egui::Frame). |
| 301 | pub elevation: Color32, |
| 302 | /// `content`. |
| 303 | /// |
| 304 | /// Ordinary text. Added 0.5.0 with the field renderer, which is the first |
| 305 | /// thing here that draws any: until then this crate painted surfaces and |
| 306 | /// edges and let the caller's own egui visuals answer for text. |
| 307 | pub content: Color32, |
| 308 | /// `content-secondary`. |
| 309 | /// |
| 310 | /// Inactive but usable: it still answers a press. The middle tone of the |
| 311 | /// three (wiki `three-tone-convention`), and the one an unchosen option in |
| 312 | /// a choice field takes. Added 0.26.0 for that widget, which drew every |
| 313 | /// option at full `content` and so said nothing about which one was |
| 314 | /// chosen beyond the dot egui paints. |
| 315 | /// |
| 316 | /// Not [`content_muted`](Self::content_muted), which carries a claim: |
| 317 | /// `State::Disabled` resolves to it, so a live control wearing it tells the |
| 318 | /// user it will not answer. `makeover-tui` draws the same widget the same |
| 319 | /// way from `makeover-tui@230bf63`. |
| 320 | /// |
| 321 | /// A step of `content` toward the page, derived at load by `makeover` |
| 322 | /// rather than authored, so it is read off the resolved theme here like |
| 323 | /// any other token and never re-derived. |
| 324 | pub content_secondary: Color32, |
| 325 | /// `content-muted`. |
| 326 | /// |
| 327 | /// A field's hint, and what |
| 328 | /// [`makeover_layout::State::Disabled`](makeover_layout::State::Disabled) |
| 329 | /// resolves to. Both readings come from the description rather than from |
| 330 | /// here: `State::Disabled` names this intent by token. |
| 331 | pub content_muted: Color32, |
| 332 | /// `action-primary`. |
| 333 | /// |
| 334 | /// What a control is drawn in. Added 0.12.0 with the table renderer, for the |
| 335 | /// reason `content` was added 0.5.0 with the field renderer: a link in a |
| 336 | /// cell is the first thing here that needs the action intent, and a palette |
| 337 | /// should carry what is used. |
| 338 | /// |
| 339 | /// This is the intent [`CellPart`](makeover_layout::CellPart) exists to |
| 340 | /// separate. A cell holding a control took the cell's text colour until the |
| 341 | /// description could say otherwise, which is the drift `makeover-layout` |
| 342 | /// 0.14.0 named and `makeover-webview` 0.25.0 fixed on its own side. |
| 343 | pub action: Color32, |
| 344 | /// `danger`. |
| 345 | /// |
| 346 | /// A field's error message, a destructive control, a bar that has run over. |
| 347 | pub danger: Color32, |
| 348 | /// `success`. |
| 349 | /// |
| 350 | /// Added 0.18.0 with [`widget`], which is the first thing here that draws a |
| 351 | /// [`Tone`]. The three status intents arrive together and not one at a |
| 352 | /// time: [`Tone`] is five members wide and a resolver missing one has to |
| 353 | /// invent a colour for it, which is the substitution this crate spent |
| 354 | /// 0.2.0 removing from [`Palette::fill`]. |
| 355 | pub success: Color32, |
| 356 | /// `warning`. |
| 357 | pub warning: Color32, |
| 358 | /// `info`. |
| 359 | pub info: Color32, |
| 360 | |
| 361 | |
| 362 | |
| 363 | /// Resolve a surface intent, or `None` for one this renderer does not know. |
| 364 | /// |
| 365 | /// A plain lookup. There is still no substitution: the old one existed only |
| 366 | /// while `surface-well` was underived, and every consumer reads the real |
| 367 | /// token now. |
| 368 | /// |
| 369 | /// `Option` since 0.3.0, because [`Fill`] became `#[non_exhaustive]` in |
| 370 | /// `makeover-layout` 0.4.0 and a total function over an open enum can only |
| 371 | /// stay total by inventing a colour for a member it has never heard of. |
| 372 | /// That is the substitution this crate spent 0.2.0 removing, so the return |
| 373 | /// type moved instead. Every member the description has today is answered |
| 374 | /// with `Some`. |
| 375 | |
| 376 | pub const |
| 377 | match fill |
| 378 | Page => Some, |
| 379 | Raised => Some, |
| 380 | Overlay => Some, |
| 381 | Well => Some, |
| 382 | Sunken => Some, |
| 383 | _ => None, |
| 384 | |
| 385 | |
| 386 | |
| 387 | /// The colour a [`Tone`] reads as. |
| 388 | /// |
| 389 | /// Total, unlike [`fill`](Self::fill), and the difference is not an |
| 390 | /// inconsistency. `Fill` is `#[non_exhaustive]` and `Tone` is not: the |
| 391 | /// description layer settled tone at five members and grows surfaces, so a |
| 392 | /// total function here cannot be made to invent a colour by an upstream |
| 393 | /// release the way a total `fill` could. |
| 394 | /// |
| 395 | /// [`Tone::Neutral`] is [`content`](Self::content) rather than a colour of |
| 396 | /// its own, which is what "an ordinary fact" means: a neutral badge is text |
| 397 | /// in a box, not a fifth status. |
| 398 | |
| 399 | pub const |
| 400 | match tone |
| 401 | Neutral => self.content, |
| 402 | Info => self.info, |
| 403 | Success => self.success, |
| 404 | Warning => self.warning, |
| 405 | Danger => self.danger, |
| 406 | |
| 407 | |
| 408 | |
| 409 | /// The cast shadow for a surface that overlays the page. |
| 410 | /// |
| 411 | /// What "overlaying" means in immediate mode, answered rather than skipped. |
| 412 | /// egui already paints shadows for its menus and windows through |
| 413 | /// [`egui::Frame::shadow`], so the honest port is to hand that machinery the |
| 414 | /// theme's tone instead of egui's own default, not to invent a painter here |
| 415 | /// the way [`paint_bevel`] had to. |
| 416 | /// |
| 417 | /// The geometry matches what `makeover-webview` composes, in points rather |
| 418 | /// than pixels: a small downward offset and a wide soft blur. A Platinum-era |
| 419 | /// menu sits just off the page rather than hovering above it. |
| 420 | /// |
| 421 | /// ```no_run |
| 422 | /// # let palette: makeover_immediate::Palette = unimplemented!(); |
| 423 | /// # let ui: &mut egui::Ui = unimplemented!(); |
| 424 | /// egui::Frame::popup(ui.style()) |
| 425 | /// .shadow(palette.cast()) |
| 426 | /// .show(ui, |ui| { ui.label("over the page"); }); |
| 427 | /// ``` |
| 428 | |
| 429 | pub const |
| 430 | Shadow |
| 431 | offset: , |
| 432 | blur: 24, |
| 433 | spread: 0, |
| 434 | color: self.elevation, |
| 435 | |
| 436 | |
| 437 | |
| 438 | /// Resolve a bevel edge intent. |
| 439 | |
| 440 | pub const |
| 441 | match edge |
| 442 | Light => self.bevel_light, |
| 443 | Dark => self.bevel_dark, |
| 444 | |
| 445 | |
| 446 | |
| 447 | |
| 448 | /// The geometry a framed region is drawn with. |
| 449 | /// |
| 450 | /// Every field is a value, which is why they all arrive from the caller: |
| 451 | /// radius and border width belong to `makeover-geometry`, and margins come |
| 452 | /// from its relational gaps. |
| 453 | |
| 454 | |
| 455 | /// Corner radius. Square under the Platinum default. |
| 456 | pub radius: CornerRadius, |
| 457 | /// Inner margin between the frame and its contents. |
| 458 | pub margin: Margin, |
| 459 | /// Bevel stroke width, in points. |
| 460 | pub stroke: f32, |
| 461 | |
| 462 | |
| 463 | |
| 464 | /// A one-point square frame with no inner margin. |
| 465 | |
| 466 | Self |
| 467 | radius: ZERO, |
| 468 | margin: ZERO, |
| 469 | stroke: 1.0, |
| 470 | |
| 471 | |
| 472 | |
| 473 | |
| 474 | /// Paint a two-tone edge just inside `rect`. |
| 475 | /// |
| 476 | /// Fill first, bevel after: this adds two polylines and nothing else, so it |
| 477 | /// composes over whatever is already there. That is what lets it go over an |
| 478 | /// [`egui::TextEdit`] after `ui.add`, where the widget's own fill has landed. |
| 479 | /// |
| 480 | /// Two three-point polylines meeting at opposite corners, rather than four |
| 481 | /// segments, so egui mitres the corner joins instead of leaving a notch. |
| 482 | /// |
| 483 | /// The dark polyline is drawn second, so the two corners where the runs meet |
| 484 | /// take its tone. That is the right answer here rather than a concession. |
| 485 | /// [`makeover_layout::Bevel`] holds those corners to belong to both edges, and |
| 486 | /// a renderer with room to divide one should; at the default one-point stroke |
| 487 | /// the corner is a one-point square, so the division is sub-pixel and |
| 488 | /// antialiasing resolves it to the same blend the mitre already gives. Splitting |
| 489 | /// it would add a seam and no information. `makeover-tui` does split, because a |
| 490 | /// terminal cell is large enough that not splitting costs a visible cell of edge |
| 491 | /// weight — the same rule, at a resolution where it has something to say. |
| 492 | |
| 493 | let = bevel.edges; |
| 494 | |
| 495 | // Inset by half a stroke so the line lands inside `rect` rather than |
| 496 | // straddling its edge, which on a fractional-scale display is the |
| 497 | // difference between one crisp pixel and two dim ones. |
| 498 | let r = rect.shrink; |
| 499 | |
| 500 | painter.add |
| 501 | vec!, |
| 502 | new, |
| 503 | ; |
| 504 | painter.add |
| 505 | vec!, |
| 506 | new, |
| 507 | ; |
| 508 | |
| 509 | |
| 510 | /// Draw a region at a given [`Depth`]: its fill and its edge, together. |
| 511 | /// |
| 512 | /// [`Depth::Flat`] gets neither, and inherits whatever it sits on. That is the |
| 513 | /// difference between level-with and painted-the-same-colour, and it is the |
| 514 | /// reason `Depth::fill` returns an [`Option`] rather than defaulting to the |
| 515 | /// page. |
| 516 | |
| 517 | ui: &mut Ui, |
| 518 | depth: Depth, |
| 519 | palette: &Palette, |
| 520 | style: FrameStyle, |
| 521 | add_contents: impl FnOnce -> R, |
| 522 | |
| 523 | let mut f = new |
| 524 | .corner_radius |
| 525 | .inner_margin; |
| 526 | // Two ways there is no fill to paint, and they collapse to the same |
| 527 | // outcome: the depth names none (Depth::Flat), or it names one this |
| 528 | // renderer cannot resolve. Either way the frame goes unfilled and the |
| 529 | // bevel below carries the depth on its own, which is the rule this |
| 530 | // module already documents for Flat. |
| 531 | if let Some = depth.fill.and_then |
| 532 | f = f.fill; |
| 533 | |
| 534 | // A surface that overlays the page is cast onto it. [`Palette::cast`] has |
| 535 | // answered what that means here since 0.10.0 and nothing could reach it: a |
| 536 | // description had no way to say Overlay until makeover-layout 0.14.0, so |
| 537 | // the answer sat beside the question. Keyed off the fill rather than the |
| 538 | // variant, so it stays right for whatever else the description calls an |
| 539 | // overlay later. |
| 540 | if depth.fill == Some |
| 541 | f = f.shadow; |
| 542 | |
| 543 | let framed = f.show; |
| 544 | if let Some = depth.bevel |
| 545 | paint_bevel |
| 546 | ui.painter, |
| 547 | framed.response.rect, |
| 548 | bevel, |
| 549 | palette, |
| 550 | style.stroke, |
| 551 | ; |
| 552 | |
| 553 | framed.inner |
| 554 | |
| 555 | |
| 556 | /// The geometry a field group is drawn with. |
| 557 | /// |
| 558 | /// Values again, for the reason [`FrameStyle`] is: every number here belongs to |
| 559 | /// `makeover-geometry` and arrives already resolved. |
| 560 | |
| 561 | |
| 562 | /// The well a text control sits in. |
| 563 | pub frame: FrameStyle, |
| 564 | /// Between a field's own parts: its label, its control, its hint and its |
| 565 | /// error. |
| 566 | pub gap: f32, |
| 567 | /// Between one field and the next. |
| 568 | pub group_gap: f32, |
| 569 | /// What marks a required field, appended to its label. |
| 570 | /// |
| 571 | /// A knob rather than a constant, because it is the one piece of *copy* in |
| 572 | /// this crate and copy is not a renderer's call. A webview does not need it |
| 573 | /// at all — it emits the `required` attribute and the browser answers — so |
| 574 | /// this renderer is the first place where a compulsory field either shows |
| 575 | /// that it is or silently does not. |
| 576 | pub required_marker: &'static str, |
| 577 | |
| 578 | |
| 579 | |
| 580 | /// The default frame, no gaps, and an asterisk. |
| 581 | |
| 582 | Self |
| 583 | frame: default, |
| 584 | gap: 0.0, |
| 585 | group_gap: 0.0, |
| 586 | required_marker: "*", |
| 587 | |
| 588 | |
| 589 | |
| 590 | |
| 591 | /// What the field currently holds, borrowed from wherever the app keeps it. |
| 592 | /// |
| 593 | /// The immediate-mode counterpart of `makeover_webview::form::Value`, and the |
| 594 | /// place the two renderers are forced apart: there the value is read back out |
| 595 | /// of the DOM after the fact, and here the widget writes through this borrow as |
| 596 | /// it is edited. Same reason the description carries neither. |
| 597 | /// |
| 598 | /// An enum rather than a bag of options, on the reasoning |
| 599 | /// `makeover_webview::form::Value` records: a checkbox holding a string is |
| 600 | /// unsayable here, where a struct would let it be said and then have to cope. |
| 601 | |
| 602 | |
| 603 | /// Nothing to edit. The control is drawn and does not answer. |
| 604 | |
| 605 | Absent, |
| 606 | /// The buffer behind anything that takes typed text, a select included: |
| 607 | /// what a select holds is the `value` of one of its [`Choice`]s. |
| 608 | /// |
| 609 | /// [`Choice`]: makeover_layout::Choice |
| 610 | Text, |
| 611 | /// A checkbox, on or off. |
| 612 | On, |
| 613 | /// The two buffers behind a [`FieldKind::Interval`], lower first. |
| 614 | /// |
| 615 | /// Two buffers rather than one string with a separator, which is |
| 616 | /// [`makeover_layout::Field::upper_name`]'s reason one level down: an |
| 617 | /// interval is submitted under two names, so it is edited as two values, |
| 618 | /// and a delimiter this crate owned could appear inside either of them. |
| 619 | /// |
| 620 | /// Either end may be empty while the other stands. An open end is an |
| 621 | /// answer -- "over 120 BPM" -- rather than a half-filled box. |
| 622 | /// |
| 623 | /// Added 0.33.0 with makeover-layout 0.34.0. |
| 624 | Between |
| 625 | /// The lower end's buffer. |
| 626 | lower: &'a mut String, |
| 627 | /// The upper end's buffer. |
| 628 | upper: &'a mut String, |
| 629 | , |
| 630 | |
| 631 | |
| 632 | /// The label, marked if the field is compulsory. |
| 633 | |
| 634 | if field.required |
| 635 | format! |
| 636 | else |
| 637 | field.label.to_owned |
| 638 | |
| 639 | |
| 640 | |
| 641 | /// The four shapes a control comes in here, which is fewer than there are |
| 642 | /// kinds. |
| 643 | /// |
| 644 | /// [`FieldKind`] is `#[non_exhaustive]` and grows; this does not, because the |
| 645 | /// ways egui has of asking for a value do not. Reducing the open set to this |
| 646 | /// closed one in one total function is what keeps a new kind from needing a new |
| 647 | /// arm at every match below. |
| 648 | |
| 649 | |
| 650 | /// Typed into, so it is drawn as a well: the user looks into it. |
| 651 | Typed, |
| 652 | /// Picked from a control that shows one option at a time. Pressed rather |
| 653 | /// than looked into, so egui's own control painting stands. |
| 654 | Chosen, |
| 655 | /// Picked from options that are all on screen at once. |
| 656 | /// |
| 657 | /// Apart from [`Chosen`](Self::Chosen) because the description holds them |
| 658 | /// apart, and holding them apart is the whole content of |
| 659 | /// [`FieldKind::Radio`]: same question, and an answer the user can read |
| 660 | /// without opening anything. |
| 661 | Listed, |
| 662 | /// Held on or off. |
| 663 | Toggled, |
| 664 | /// Dragged across an extent that is on screen the whole time. |
| 665 | /// |
| 666 | /// Apart from [`Typed`](Self::Typed) for the reason |
| 667 | /// [`FieldKind::Range`] is apart from `Number`: the two ends are what the |
| 668 | /// question means, so a well with a figure in it is not a quieter version |
| 669 | /// of this control, it is a different one. |
| 670 | Slid, |
| 671 | /// Two values dragged across one axis, drawn as one question. |
| 672 | /// |
| 673 | /// Apart from [`Typed`](Self::Typed) for the reason |
| 674 | /// [`FieldKind::Interval`] is apart from `Number`: two wells one under the |
| 675 | /// other are two questions on screen, whatever the description says, and |
| 676 | /// the arrangement is the whole content of the kind. |
| 677 | Spanned, |
| 678 | |
| 679 | |
| 680 | /// Which shape a kind takes. |
| 681 | /// |
| 682 | /// The wildcard falls to [`Control::Typed`] on purpose: a kind added to the |
| 683 | /// description since this renderer was built degrades to a text box, which |
| 684 | /// accepts any value the others would, rather than to nothing drawn at all. |
| 685 | /// |
| 686 | /// `FieldKind::File` lands there as of makeover-layout 0.11.0, and it is left |
| 687 | /// there rather than grown a shape of its own. egui's honest answer is a button |
| 688 | /// that opens a native picker, which is a fifth control and a file-dialog |
| 689 | /// dependency; no consumer of this crate asks for a file field yet. Same |
| 690 | /// position this crate took on `Meter` at 0.10.0: the membership test is that |
| 691 | /// every renderer *could* answer honestly, not that each one does on the day. |
| 692 | /// A path in a text box is not nothing, and it is what an app that needs this |
| 693 | /// tomorrow gets today. |
| 694 | /// |
| 695 | /// makeover-layout 0.31.0 added `Field::accept` and `Field::multiple`, and this |
| 696 | /// position is what they land on: both are the picker's arguments, and this |
| 697 | /// renderer has no picker to give them to. They are not lost — the description |
| 698 | /// still carries them, and the day the native dialog arrives here it is opened |
| 699 | /// with them rather than with a filter written twice. |
| 700 | /// |
| 701 | /// `FieldKind::Date` and `FieldKind::DateTime` land there too, as of |
| 702 | /// makeover-layout 0.15.0, on the same footing and with one thing owed. A |
| 703 | /// calendar is a sixth control and bare `egui` has none, so a typed value is |
| 704 | /// the honest answer here; what the app gets is the format the description |
| 705 | /// names, `makeover_layout::DATE_FORMAT` and `DATETIME_FORMAT`, which is why |
| 706 | /// those are constants rather than a sentence. audiofiles is the only consumer |
| 707 | /// of this crate and asks for neither today. A calendar popup is the upgrade |
| 708 | /// whenever one does. |
| 709 | const |
| 710 | match kind |
| 711 | Select => Chosen, |
| 712 | Radio => Listed, |
| 713 | Checkbox => Toggled, |
| 714 | Range => Slid, |
| 715 | Interval => Spanned, |
| 716 | _ => Typed, |
| 717 | |
| 718 | |
| 719 | |
| 720 | /// The shape the field actually gets, which is the kind's unless the field is |
| 721 | /// missing what that shape needs. |
| 722 | /// |
| 723 | /// One case, and `makeover-layout` names it: a [`FieldKind::Range`] carries its |
| 724 | /// extent in [`Field::min`] and [`Field::max`], and a range missing an end has |
| 725 | /// nothing to slide across. egui's `Slider` demands a `RangeInclusive`, so |
| 726 | /// inventing one would be this renderer picking bounds the app never stated and |
| 727 | /// the user then dragging against them. |
| 728 | /// |
| 729 | /// It falls back to [`Control::Typed`], which is where every kind this renderer |
| 730 | /// cannot draw natively already lands: a number in a well is a true report of |
| 731 | /// the value and takes any answer the slider would. |
| 732 | |
| 733 | match control_shape |
| 734 | Slid if !field.bounded => Typed, |
| 735 | shape => shape, |
| 736 | |
| 737 | |
| 738 | |
| 739 | /// The unit to draw beside this field's value, if there is one to draw. |
| 740 | /// |
| 741 | /// Two conditions rather than one: the field has to carry a unit and its kind |
| 742 | /// has to be one that means anything by it. `FieldKind::measurable` is the |
| 743 | /// description answering the second, so this renderer does not keep its own |
| 744 | /// list of which kinds are quantities -- which is the drift that predicate |
| 745 | /// exists to stop. |
| 746 | |
| 747 | field.unit.filter |
| 748 | |
| 749 | |
| 750 | /// The two ends of a range, as egui wants them. |
| 751 | /// |
| 752 | /// `None` when either end is missing or is not a number this host can read. |
| 753 | /// The description carries the bounds as text on purpose — the bound of a date |
| 754 | /// is a date — so parsing them is the renderer's job and failing to is a real |
| 755 | /// outcome rather than an assertion. |
| 756 | |
| 757 | let min = field.min?..ok?; |
| 758 | let max = field.max?..ok?; |
| 759 | Some |
| 760 | |
| 761 | |
| 762 | /// How many decimals to write a dragged value back with. |
| 763 | /// |
| 764 | /// Read off [`Field::step`], which is the only thing that says what |
| 765 | /// granularity the question has: a step of `0.01` is a two-decimal question and |
| 766 | /// a step of `1` is a whole-number one. Without a step the host's own |
| 767 | /// granularity stands, and egui's is continuous, so the value is written back |
| 768 | /// at whatever precision it round-trips at. |
| 769 | |
| 770 | let step = step?; |
| 771 | Some |
| 772 | Some => fraction.trim_end_matches.len, |
| 773 | None => 0, |
| 774 | |
| 775 | |
| 776 | |
| 777 | /// What a select shows for the value it currently holds. |
| 778 | /// |
| 779 | /// A value no option carries stays on screen as itself rather than reading as |
| 780 | /// whichever option happens to be first. goingson saved a backup retention of |
| 781 | /// 10 against a 1/3/7/14/0 list and the browser silently showed it as 1, so the |
| 782 | /// next save wrote a value nobody chose; `makeover-webview` grew the fix as a |
| 783 | /// stray `<option>` and this is the same fix in the shape egui allows. |
| 784 | /// |
| 785 | /// The empty value is the one case that reads as unanswered rather than as an |
| 786 | /// answer, and [`chosen_text`] is what puts the field's ghost text there. |
| 787 | |
| 788 | options |
| 789 | .iter |
| 790 | .find |
| 791 | .map_or |
| 792 | |
| 793 | |
| 794 | /// What a select's closed control reads, and in which tone. |
| 795 | /// |
| 796 | /// A chooser with nothing chosen showed an empty box: `shown_label` falls back |
| 797 | /// to the value, and the unanswered value is the empty string. So an app with |
| 798 | /// an instruction to give — audiofiles' "Select device..." — had nowhere to put |
| 799 | /// it but a disabled button elsewhere on the screen, which is the affordance |
| 800 | /// this vocabulary keeps moving messages *off*. |
| 801 | /// |
| 802 | /// [`Field::placeholder`] is already the description's word for "what the field |
| 803 | /// reads while it is empty" and was honoured by the typed kinds alone, so |
| 804 | /// nothing new is said here; the renderer is what had not caught up. Muted |
| 805 | /// because it is not an answer, the same tone the typed kinds' ghost text takes |
| 806 | /// three lines up. |
| 807 | /// |
| 808 | /// A value no option carries but that is *not* empty stays as itself, in |
| 809 | /// `content`: that is the goingson retention bug and it is a wrong answer |
| 810 | /// rather than an absent one. |
| 811 | /// |
| 812 | /// Returns the words and the tone rather than a built [`RichText`], because |
| 813 | /// what it decides is both of them and only one of them is readable back off a |
| 814 | /// `RichText`. |
| 815 | /// |
| 816 | /// [`Field::placeholder`]: makeover_layout::Field::placeholder |
| 817 | |
| 818 | match field.placeholder |
| 819 | Some if value.is_empty => , |
| 820 | _ => , |
| 821 | |
| 822 | |
| 823 | |
| 824 | /// What one option in a choice field is drawn in. |
| 825 | /// |
| 826 | /// The chosen one is the emphasised thing and takes `content`; the rest take |
| 827 | /// [`content_secondary`](Palette::content_secondary), because an option that is |
| 828 | /// not chosen is still an option and pressing it chooses it. Muted would be the |
| 829 | /// lie: [`State::Disabled`] resolves to it, so a five-option field read as one |
| 830 | /// live row and four dead ones. `makeover-tui` draws it the same way |
| 831 | /// (`makeover-tui@230bf63`); wiki `three-tone-convention` is the table. |
| 832 | |
| 833 | if value == option |
| 834 | palette.content |
| 835 | else |
| 836 | palette.content_secondary |
| 837 | |
| 838 | |
| 839 | |
| 840 | /// Which end of an interval a box is. |
| 841 | /// |
| 842 | /// Named rather than a bool, because what it selects is not a side but a |
| 843 | /// fallback: an empty end reads as the bound it stands for, and which bound |
| 844 | /// that is depends on the end. |
| 845 | |
| 846 | |
| 847 | /// The lower end, falling back to the start of the extent. |
| 848 | Low, |
| 849 | /// The upper end, falling back to its end. |
| 850 | High, |
| 851 | |
| 852 | |
| 853 | /// The facts an interval's two boxes share. |
| 854 | /// |
| 855 | /// One struct because they are one axis: [`Field::min`], [`Field::max`], |
| 856 | /// [`Field::step`] and [`Field::unit`] describe the question rather than either |
| 857 | /// end of it, so reading them once is what stops the two boxes drifting apart. |
| 858 | |
| 859 | /// The extent both ends are dragged inside, when it is one this host can |
| 860 | /// read. |
| 861 | extent: , |
| 862 | /// The granularity, as the description writes it. |
| 863 | step: , |
| 864 | /// What the axis is measured in. |
| 865 | unit: , |
| 866 | |
| 867 | |
| 868 | |
| 869 | /// What an empty end reads as: the bound it stands for. |
| 870 | /// |
| 871 | /// Zero with no extent to fall back on. That is the one number this |
| 872 | /// renderer invents, and it invents it where the description declined to |
| 873 | /// say anything: an unbounded interval has no edge for the end to sit on, |
| 874 | /// and a drag box has to start somewhere. |
| 875 | |
| 876 | self.extent.as_ref.map_or |
| 877 | Low => *extent.start, |
| 878 | High => *extent.end, |
| 879 | |
| 880 | |
| 881 | |
| 882 | /// One end of the interval, as a drag box. |
| 883 | /// |
| 884 | /// # An empty end reads as its bound |
| 885 | /// |
| 886 | /// Which is what the shipped control did before it was described: an unset |
| 887 | /// minimum sits on the low edge and stores no filter. egui's `DragValue` |
| 888 | /// holds a number and has no empty state to offer, so the alternative was a |
| 889 | /// text box, and that would cost the app a control on the way into being |
| 890 | /// described. |
| 891 | /// |
| 892 | /// With no extent to fall back on, an empty end reads zero. That is the one |
| 893 | /// number this renderer invents, and it invents it where the description |
| 894 | /// declined to say anything: an unbounded interval has no edge for the end |
| 895 | /// to sit on, and a drag box has to start somewhere. |
| 896 | /// |
| 897 | /// Nothing is written back until the user drags, so a value the app put |
| 898 | /// there survives being looked at -- the same guarantee the slider makes. |
| 899 | |
| 900 | let mut number = value..unwrap_or; |
| 901 | let mut drag = new; |
| 902 | if let Some = self.extent.clone |
| 903 | drag = drag.range; |
| 904 | |
| 905 | if let Some = decimals |
| 906 | drag = drag.max_decimals; |
| 907 | |
| 908 | if let Some = self.step.and_then |
| 909 | drag = drag.speed; |
| 910 | |
| 911 | // Inside the control, beside the readout, which is where `Field::unit` |
| 912 | // was decided to belong and where these boxes already put it. |
| 913 | if let Some = self.unit |
| 914 | drag = drag.suffix; |
| 915 | |
| 916 | let response = ui.add; |
| 917 | if response.changed |
| 918 | *value = match decimals |
| 919 | Some => format!, |
| 920 | None => number.to_string, |
| 921 | ; |
| 922 | |
| 923 | response |
| 924 | |
| 925 | |
| 926 | |
| 927 | /// The control alone, without its label, hint or error. |
| 928 | |
| 929 | ui: &mut Ui, |
| 930 | field: &, |
| 931 | filling: , |
| 932 | palette: &Palette, |
| 933 | style: &FieldStyle, |
| 934 | |
| 935 | // The mismatch path: described as one thing and filled as another. Nothing |
| 936 | // here can fix it, so it is drawn as the empty, inert version of what was |
| 937 | // described — visible on screen, in the way an empty select is at the |
| 938 | // webview renderer, rather than reported in a log nobody reads. |
| 939 | let mut discard = Stringnew; |
| 940 | // The interval's second scratch buffer. Two ends means the mismatch path |
| 941 | // needs two places to write nothing to. |
| 942 | let mut spare = Stringnew; |
| 943 | let mut off = false; |
| 944 | |
| 945 | match shape_of |
| 946 | Slid => |
| 947 | let value = match filling |
| 948 | Text => text, |
| 949 | _ => &mut discard, |
| 950 | ; |
| 951 | // `shape_of` has already refused an unbounded range, so the extent |
| 952 | // is only missing here if a bound is not a number — a date range, |
| 953 | // say, which this control cannot draw either. |
| 954 | let Some = extent else |
| 955 | return ui.label; |
| 956 | ; |
| 957 | |
| 958 | // A value the host cannot read starts at the low end rather than at |
| 959 | // zero, which may be outside the extent entirely. Nothing is |
| 960 | // written back until the user drags, so an unreadable value the app |
| 961 | // put there survives being looked at. |
| 962 | let mut number = value..unwrap_or; |
| 963 | // The granularity is the curve's as of makeover-layout 0.32.0. It |
| 964 | // is still in the value's own units, so the display precision is |
| 965 | // read off it exactly as before. |
| 966 | let step = field.curve.step; |
| 967 | let mut slider = new.text; |
| 968 | if let Some = decimals |
| 969 | slider = slider.max_decimals; |
| 970 | |
| 971 | if let Some = step.and_then |
| 972 | slider = slider.step_by; |
| 973 | |
| 974 | // egui's own constant-ratio track, which is this host's answer to |
| 975 | // `Curve::Logarithmic`. `is_ratio` rather than a match on the |
| 976 | // variant, because a ratio across zero is not one: makeover-layout |
| 977 | // decides the fallback so that four renderers cannot disagree about |
| 978 | // when it applies. |
| 979 | if field.curve.is_ratio |
| 980 | slider = slider.logarithmic; |
| 981 | |
| 982 | // The unit goes inside the control, beside the readout egui already |
| 983 | // draws. That placement is the argument `Field::unit` was decided |
| 984 | // on: it is where these controls put it before they were described, |
| 985 | // and it is the one a label could never reach. |
| 986 | if let Some = unit_of |
| 987 | slider = slider.suffix; |
| 988 | |
| 989 | let response = ui.add; |
| 990 | if response.changed |
| 991 | *value = match decimals |
| 992 | Some => format!, |
| 993 | None => number.to_string, |
| 994 | ; |
| 995 | |
| 996 | response |
| 997 | |
| 998 | // One question, so one row. Two wells stacked would be two questions on |
| 999 | // screen whatever the description said, which is the reading |
| 1000 | // `FieldKind::Interval` exists to prevent. |
| 1001 | // |
| 1002 | // Dragged rather than typed, because that is what these controls |
| 1003 | // already were: audiofiles' six filter axes are `DragValue` pairs with |
| 1004 | // a shared extent, a speed and a suffix, and a port that turned them |
| 1005 | // into text boxes would be a description costing the app a control. |
| 1006 | Spanned => |
| 1007 | let = match filling |
| 1008 | Between => , |
| 1009 | _ => , |
| 1010 | ; |
| 1011 | let axis = Axis |
| 1012 | extent: extent, |
| 1013 | step: field.step, |
| 1014 | unit: unit_of, |
| 1015 | ; |
| 1016 | ui.horizontal |
| 1017 | let low = axis.end; |
| 1018 | // The word rather than a dash. A dash between two numbers is a |
| 1019 | // minus sign on a signed axis, and audiofiles filters loudness |
| 1020 | // in dBFS. |
| 1021 | ui.label; |
| 1022 | let high = axis.end; |
| 1023 | low | high |
| 1024 | |
| 1025 | .inner |
| 1026 | |
| 1027 | Typed => |
| 1028 | let text = match filling |
| 1029 | Text => text, |
| 1030 | _ => &mut discard, |
| 1031 | ; |
| 1032 | // An empty frame and no margin: the well is this crate's, and egui's |
| 1033 | // own control background and padding would sit underneath it saying |
| 1034 | // something different about both. |
| 1035 | // Keyed on the description's own `multiline` and not on the |
| 1036 | // member: a markdown field is several lines by definition, and a |
| 1037 | // single-line edit would be a control the value cannot fit in. egui |
| 1038 | // does nothing else with the markdown, which is the honest answer |
| 1039 | // rather than a gap -- the source is text, and editing it as text |
| 1040 | // loses none of it. |
| 1041 | let mut edit = if field.kind.multiline |
| 1042 | multiline |
| 1043 | else |
| 1044 | singleline |
| 1045 | |
| 1046 | .frame |
| 1047 | .margin |
| 1048 | .text_color |
| 1049 | .password; |
| 1050 | if let Some = field.placeholder |
| 1051 | edit = edit.hint_text; |
| 1052 | |
| 1053 | let response = frame; |
| 1054 | // A typed number has no readout of its own to sit beside, so the |
| 1055 | // unit follows the box. Muted, because it is a fact about the value |
| 1056 | // rather than a second thing to read. |
| 1057 | match unit_of |
| 1058 | Some => |
| 1059 | ui.label; |
| 1060 | response |
| 1061 | |
| 1062 | None => response, |
| 1063 | |
| 1064 | |
| 1065 | Toggled => |
| 1066 | let on = match filling |
| 1067 | On => on, |
| 1068 | _ => &mut off, |
| 1069 | ; |
| 1070 | ui.checkbox |
| 1071 | |
| 1072 | Listed => |
| 1073 | let value = match filling |
| 1074 | Text => text, |
| 1075 | _ => &mut discard, |
| 1076 | ; |
| 1077 | // No `shown_label` counterpart, and none is needed: a value no |
| 1078 | // option carries leaves every button unfilled, which is already |
| 1079 | // the honest report on screen. The select needs the fix because it |
| 1080 | // has one slot and must put *something* in it. |
| 1081 | let group = ui.vertical |
| 1082 | let mut answered: = None; |
| 1083 | for opt in field.options |
| 1084 | // An option that cannot be picked yet is drawn and does not |
| 1085 | // answer, with the precondition beside it rather than |
| 1086 | // behind a hover: a greyed row with no reason reads as a |
| 1087 | // dead end, which is the state `Choice::unavailable` exists |
| 1088 | // to stop being sayable. |
| 1089 | let picked = if let Some = opt.unavailable |
| 1090 | ui.horizontal |
| 1091 | let picked = ui |
| 1092 | .add_enabled_ui |
| 1093 | ui.radio_value |
| 1094 | value, |
| 1095 | opt.value.to_owned, |
| 1096 | new.color, |
| 1097 | |
| 1098 | |
| 1099 | .inner; |
| 1100 | ui.label; |
| 1101 | picked |
| 1102 | |
| 1103 | .inner |
| 1104 | else |
| 1105 | ui.radio_value |
| 1106 | value, |
| 1107 | opt.value.to_owned, |
| 1108 | new.color, |
| 1109 | |
| 1110 | ; |
| 1111 | answered = Some |
| 1112 | Some => prev.union, |
| 1113 | None => picked, |
| 1114 | ; |
| 1115 | |
| 1116 | answered |
| 1117 | ; |
| 1118 | // A group described with no options answers as its own empty area |
| 1119 | // rather than as no response at all, which keeps the caller's |
| 1120 | // `.changed()` chain working on a field whose option list has not |
| 1121 | // loaded yet. |
| 1122 | group.inner.unwrap_or |
| 1123 | |
| 1124 | Chosen => |
| 1125 | let value = match filling |
| 1126 | Text => text, |
| 1127 | _ => &mut discard, |
| 1128 | ; |
| 1129 | let = chosen_text; |
| 1130 | from_id_salt |
| 1131 | .selected_text |
| 1132 | .show_ui |
| 1133 | for opt in field.options |
| 1134 | // Same rule as the radio group: shown, inert, and |
| 1135 | // saying why. A closed control hides its list, so the |
| 1136 | // reason has to travel with the row it belongs to. |
| 1137 | if let Some = opt.unavailable |
| 1138 | ui.add_enabled_ui |
| 1139 | ui.selectable_value |
| 1140 | value, |
| 1141 | opt.value.to_owned, |
| 1142 | new |
| 1143 | .color, |
| 1144 | ; |
| 1145 | ; |
| 1146 | continue; |
| 1147 | |
| 1148 | ui.selectable_value |
| 1149 | value, |
| 1150 | opt.value.to_owned, |
| 1151 | new.color, |
| 1152 | ; |
| 1153 | |
| 1154 | |
| 1155 | .response |
| 1156 | |
| 1157 | |
| 1158 | |
| 1159 | |
| 1160 | /// One field, as the column the app drops into its form. |
| 1161 | /// |
| 1162 | /// The anatomy is `makeover-webview`'s, so the two renderers put a form |
| 1163 | /// together the same way: label, control, hint, error, top to bottom, with a |
| 1164 | /// checkbox labelling itself instead of taking a label above. |
| 1165 | /// |
| 1166 | /// Returns [`None`] for a [`FieldKind::Hidden`] field, which is what |
| 1167 | /// [`FieldKind::visible`] means and is the honest answer here: a webview still |
| 1168 | /// emits an input for it because the form submits, and an immediate-mode |
| 1169 | /// renderer has no form and no submission, so a hidden field is a value the app |
| 1170 | /// already holds and there is nothing to draw or to respond to. |
| 1171 | /// |
| 1172 | /// `state` is the description's interaction axis. |
| 1173 | /// [`State::Disabled`] greys the field and stops it answering, through |
| 1174 | /// [`State::suppresses_interaction`] rather than through a second reading of |
| 1175 | /// what disabled means. Focus is not on that axis and never reaches here: egui |
| 1176 | /// owns reach, focus and the ring for this renderer, and one ring means not a |
| 1177 | /// second one per renderer that happens to have opinions. |
| 1178 | |
| 1179 | ui: &mut Ui, |
| 1180 | field: &, |
| 1181 | filling: , |
| 1182 | state: , |
| 1183 | palette: &Palette, |
| 1184 | style: &FieldStyle, |
| 1185 | |
| 1186 | if !field.kind.visible |
| 1187 | return None; |
| 1188 | |
| 1189 | let enabled = !state.is_some_and; |
| 1190 | let text = if enabled |
| 1191 | palette.content |
| 1192 | else |
| 1193 | palette.content_muted |
| 1194 | ; |
| 1195 | |
| 1196 | let response = ui |
| 1197 | .vertical |
| 1198 | ui.spacing_mut.item_spacing.y = style.gap; |
| 1199 | |
| 1200 | // A checkbox labels itself, on the right of the box. |
| 1201 | // `FieldKind::labels_itself` is the description saying so, and both |
| 1202 | // webview apps special-cased it inline before it did. |
| 1203 | if !field.kind.labels_itself |
| 1204 | ui.label; |
| 1205 | |
| 1206 | |
| 1207 | let response = ui |
| 1208 | .add_enabled_ui |
| 1209 | .inner; |
| 1210 | |
| 1211 | // Standing help first, then what is wrong now. Both, in that order, |
| 1212 | // for the reason the webview renderer names both in |
| 1213 | // `aria-describedby`: an error appearing must not take the hint |
| 1214 | // away with it. |
| 1215 | if let Some = field.hint |
| 1216 | ui.label; |
| 1217 | |
| 1218 | if let Some = field.error |
| 1219 | ui.label; |
| 1220 | |
| 1221 | response |
| 1222 | |
| 1223 | .inner; |
| 1224 | |
| 1225 | Some |
| 1226 | |
| 1227 | |
| 1228 | /// A set of fields, laid down a column. |
| 1229 | /// |
| 1230 | /// `show_extended` is the disclosure, and it is a parameter rather than state |
| 1231 | /// held here because the disclosure belongs to the *form* and not to any field: |
| 1232 | /// [`Field::extended`] marks which fields are behind one, and the app owns |
| 1233 | /// whether it is open. That is the same division `makeover-webview` draws when |
| 1234 | /// it marks the group `data-extended` and emits no control to toggle it. |
| 1235 | /// |
| 1236 | /// `draw` is called once per field that should be visible, in order. Taking a |
| 1237 | /// callback rather than a slice of [`Filling`]s is what keeps the app's own |
| 1238 | /// values borrowed one at a time: a form's fields usually live in different |
| 1239 | /// structs, and a parallel array would have to be built each frame and kept in |
| 1240 | /// step with the description by hand. |
| 1241 | |
| 1242 | ui: &mut Ui, |
| 1243 | fields: &'a [], |
| 1244 | show_extended: bool, |
| 1245 | style: &FieldStyle, |
| 1246 | mut draw: impl FnMut, |
| 1247 | |
| 1248 | ui.vertical |
| 1249 | ui.spacing_mut.item_spacing.y = style.group_gap; |
| 1250 | for f in fields |
| 1251 | if f.extended && !show_extended |
| 1252 | continue; |
| 1253 | |
| 1254 | draw; |
| 1255 | |
| 1256 | ; |
| 1257 | |
| 1258 | |
| 1259 | |
| 1260 | |
| 1261 | use *; |
| 1262 | |
| 1263 | |
| 1264 | Palette |
| 1265 | page: from_rgb, |
| 1266 | raised: from_rgb, |
| 1267 | overlay: from_rgb, |
| 1268 | well, |
| 1269 | sunken: from_rgb, |
| 1270 | bevel_light: WHITE, |
| 1271 | bevel_dark: BLACK, |
| 1272 | elevation: from_black_alpha, |
| 1273 | content: from_rgb, |
| 1274 | content_secondary: from_rgb, |
| 1275 | content_muted: from_rgb, |
| 1276 | action: from_rgb, |
| 1277 | danger: from_rgb, |
| 1278 | success: from_rgb, |
| 1279 | warning: from_rgb, |
| 1280 | info: from_rgb, |
| 1281 | |
| 1282 | |
| 1283 | |
| 1284 | /// The cast is egui's own shadow type carrying the theme's tone, which is |
| 1285 | /// the whole of what this crate had to decide for it: unlike a bevel, egui |
| 1286 | /// already knows how to paint one. |
| 1287 | |
| 1288 | |
| 1289 | // egui-drawing has no harness here, so what is tested is the decision |
| 1290 | // that precedes it: which fields have a unit to draw at all. The kind |
| 1291 | // half comes from the description rather than from a `matches!` in this |
| 1292 | // crate, which is the drift `FieldKind::measurable` exists to stop. |
| 1293 | let ranged = Field |
| 1294 | unit: Some, |
| 1295 | ..range |
| 1296 | ; |
| 1297 | assert_eq!; |
| 1298 | |
| 1299 | let typed = Field |
| 1300 | unit: Some, |
| 1301 | ..new |
| 1302 | ; |
| 1303 | assert_eq!; |
| 1304 | |
| 1305 | let worded = Field |
| 1306 | unit: Some, |
| 1307 | ..new |
| 1308 | ; |
| 1309 | assert_eq!; |
| 1310 | |
| 1311 | let bare = range; |
| 1312 | assert_eq!; |
| 1313 | |
| 1314 | |
| 1315 | |
| 1316 | |
| 1317 | let p = palette; |
| 1318 | let cast = p.cast; |
| 1319 | assert_eq!; |
| 1320 | assert!; |
| 1321 | assert_eq!; |
| 1322 | |
| 1323 | |
| 1324 | |
| 1325 | |
| 1326 | // No substitution left. The page-filled well was a stand-in for a |
| 1327 | // token that did not exist yet; it exists now. |
| 1328 | let w = from_rgb; |
| 1329 | let p = palette; |
| 1330 | assert_eq!; |
| 1331 | assert_ne!; |
| 1332 | |
| 1333 | |
| 1334 | |
| 1335 | |
| 1336 | let p = palette; |
| 1337 | assert_eq!; |
| 1338 | assert_eq!; |
| 1339 | assert_eq!; |
| 1340 | |
| 1341 | |
| 1342 | /// Sunken is its own colour, not the well's and not the page's. The two |
| 1343 | /// are authored in opposite directions and an earlier cut of the |
| 1344 | /// description conflated them. |
| 1345 | |
| 1346 | |
| 1347 | let p = palette; |
| 1348 | assert_eq!; |
| 1349 | assert_ne!; |
| 1350 | assert_ne!; |
| 1351 | |
| 1352 | |
| 1353 | |
| 1354 | |
| 1355 | // The cross-app bug, asserted at the renderer boundary this time. |
| 1356 | let p = palette; |
| 1357 | let raised = Raised.fill.and_then; |
| 1358 | let well = Well.fill.and_then; |
| 1359 | assert_eq!; |
| 1360 | assert_ne!; |
| 1361 | |
| 1362 | |
| 1363 | |
| 1364 | |
| 1365 | // makeover-layout 0.14.0 is what made this reachable. The answer was |
| 1366 | // already here at 0.10.0 and the question could not be asked. |
| 1367 | let p = palette; |
| 1368 | assert_eq! |
| 1369 | Overlay.fill.and_then, |
| 1370 | Some |
| 1371 | ; |
| 1372 | assert_eq!; |
| 1373 | // The shadow `frame` reaches for is the theme's tone rather than |
| 1374 | // egui's default, which is the whole reason `cast` exists. |
| 1375 | assert_eq!; |
| 1376 | |
| 1377 | |
| 1378 | |
| 1379 | |
| 1380 | let p = palette; |
| 1381 | let = Raised.bevel.unwrap.edges; |
| 1382 | let = Raised.pressed.bevel.unwrap.edges; |
| 1383 | assert_eq!; |
| 1384 | assert_eq!; |
| 1385 | |
| 1386 | |
| 1387 | |
| 1388 | |
| 1389 | assert!; |
| 1390 | assert!; |
| 1391 | |
| 1392 | |
| 1393 | |
| 1394 | |
| 1395 | // The save-the-wrong-thing bug, asserted at the second renderer so it |
| 1396 | // is not re-found there. goingson's own numbers. |
| 1397 | let options = |
| 1398 | plain, |
| 1399 | plain, |
| 1400 | plain, |
| 1401 | plain, |
| 1402 | ]; |
| 1403 | assert_eq!; |
| 1404 | // And a value that does match reads as its label, not as itself. |
| 1405 | let spelled = ; |
| 1406 | assert_eq!; |
| 1407 | |
| 1408 | |
| 1409 | |
| 1410 | |
| 1411 | let p = palette; |
| 1412 | let options = ; |
| 1413 | let field = Field |
| 1414 | placeholder: Some, |
| 1415 | ..select |
| 1416 | ; |
| 1417 | |
| 1418 | assert_eq! |
| 1419 | chosen_text, |
| 1420 | , |
| 1421 | "ghost text is not an answer, so it takes the tone the typed kinds' ghost text does" |
| 1422 | ; |
| 1423 | |
| 1424 | // Answered, and it is the label that reads rather than the value. |
| 1425 | assert_eq!; |
| 1426 | |
| 1427 | |
| 1428 | |
| 1429 | |
| 1430 | // The retention-10 bug and the ghost text meet here: a value no option |
| 1431 | // carries still reads as itself, because the field IS answered and the |
| 1432 | // answer is wrong. Only the empty value is unanswered. |
| 1433 | let p = palette; |
| 1434 | let options = ; |
| 1435 | let field = Field |
| 1436 | placeholder: Some, |
| 1437 | ..select |
| 1438 | ; |
| 1439 | |
| 1440 | assert_eq!; |
| 1441 | |
| 1442 | |
| 1443 | |
| 1444 | |
| 1445 | // The whole change is opt-in from the description. A field that says |
| 1446 | // nothing about its empty state still shows an empty box. |
| 1447 | let p = palette; |
| 1448 | let options = ; |
| 1449 | let field = select; |
| 1450 | assert_eq!; |
| 1451 | |
| 1452 | |
| 1453 | |
| 1454 | |
| 1455 | // The distinction the kind was added for, at the renderer that has to |
| 1456 | // act on it. A well with a figure in it is not a quiet slider. |
| 1457 | assert_eq!; |
| 1458 | assert_eq!; |
| 1459 | |
| 1460 | |
| 1461 | |
| 1462 | |
| 1463 | // egui's `Slider` demands both ends, so inventing one would be this |
| 1464 | // renderer picking bounds the app never stated and the user then |
| 1465 | // dragging against them. A typed number takes every answer the slider |
| 1466 | // would. |
| 1467 | let whole = range; |
| 1468 | assert_eq!; |
| 1469 | |
| 1470 | let half = Field |
| 1471 | max: Some, |
| 1472 | ..new |
| 1473 | ; |
| 1474 | assert_eq!; |
| 1475 | assert_eq!; |
| 1476 | |
| 1477 | // A bound this host cannot read is the same outcome by a different |
| 1478 | // route: the description carries bounds as text because the bound of a |
| 1479 | // date is a date. |
| 1480 | let dated = range; |
| 1481 | assert_eq!; |
| 1482 | |
| 1483 | |
| 1484 | |
| 1485 | |
| 1486 | // The distinction the kind was added for, at the renderer that has to |
| 1487 | // arrange it: two wells stacked are two questions on screen, whatever |
| 1488 | // the description says. |
| 1489 | assert_eq!; |
| 1490 | assert_eq!; |
| 1491 | |
| 1492 | // Unlike a range, it owes no extent: its bounds are a rule on each end |
| 1493 | // rather than the control, so a missing one is an open end. |
| 1494 | let axis = Field |
| 1495 | min: Some, |
| 1496 | max: Some, |
| 1497 | ..interval |
| 1498 | ; |
| 1499 | assert_eq!; |
| 1500 | |
| 1501 | |
| 1502 | |
| 1503 | |
| 1504 | // Which is what the shipped control did before it was described: an |
| 1505 | // unset minimum sits on the low edge and stores no filter. `DragValue` |
| 1506 | // has no empty state, and a text box instead would cost the app a |
| 1507 | // control on the way into being described. |
| 1508 | let axis = Axis |
| 1509 | extent: Some, |
| 1510 | step: Some, |
| 1511 | unit: Some, |
| 1512 | ; |
| 1513 | assert!; |
| 1514 | assert!; |
| 1515 | |
| 1516 | // With no extent there is no edge to sit on, and a drag box has to |
| 1517 | // start somewhere. The one number this renderer invents, invented where |
| 1518 | // the description declined to say anything. |
| 1519 | let open = Axis |
| 1520 | extent: None, |
| 1521 | step: None, |
| 1522 | unit: None, |
| 1523 | ; |
| 1524 | assert!; |
| 1525 | assert!; |
| 1526 | |
| 1527 | |
| 1528 | |
| 1529 | |
| 1530 | // Without it a 0-to-1 threshold writes back whatever float the drag |
| 1531 | // landed on, which is the host's granularity and is what the |
| 1532 | // description says an absent step means. |
| 1533 | assert_eq!; |
| 1534 | assert_eq!; |
| 1535 | assert_eq!; |
| 1536 | // Trailing zeros are not precision: 0.10 is a one-decimal question. |
| 1537 | assert_eq!; |
| 1538 | |
| 1539 | |
| 1540 | |
| 1541 | |
| 1542 | // The tone rule, at the one place it is a claim rather than a |
| 1543 | // preference: this option genuinely will not answer, so muted is the |
| 1544 | // truth. The available ones beside it keep the secondary intent. |
| 1545 | let p = palette; |
| 1546 | let options = |
| 1547 | new, |
| 1548 | new.unless, |
| 1549 | ]; |
| 1550 | assert!; |
| 1551 | assert!; |
| 1552 | assert_eq! |
| 1553 | option_color, |
| 1554 | p.content, |
| 1555 | "the chosen option is the emphasised thing" |
| 1556 | ; |
| 1557 | assert_eq! |
| 1558 | option_color, |
| 1559 | p.content_secondary, |
| 1560 | "and `option_color` never mutes: the unavailable path is what does" |
| 1561 | ; |
| 1562 | |
| 1563 | |
| 1564 | |
| 1565 | |
| 1566 | let style = default; |
| 1567 | let plain = new; |
| 1568 | assert_eq!; |
| 1569 | |
| 1570 | let required = Field |
| 1571 | required: true, |
| 1572 | ..plain |
| 1573 | ; |
| 1574 | assert_eq!; |
| 1575 | |
| 1576 | // The marker is copy and the app owns it, which is why it is a knob. |
| 1577 | let house = FieldStyle |
| 1578 | required_marker: "(required)", |
| 1579 | ..style |
| 1580 | ; |
| 1581 | assert_eq!; |
| 1582 | |
| 1583 | |
| 1584 | |
| 1585 | |
| 1586 | // What decides whether the control gets a well. A well is for what the |
| 1587 | // user looks into, and only one of these is. |
| 1588 | assert_eq!; |
| 1589 | assert_eq!; |
| 1590 | assert_eq!; |
| 1591 | for k in |
| 1592 | Text, |
| 1593 | Secret, |
| 1594 | Number, |
| 1595 | Email, |
| 1596 | Url, |
| 1597 | Tel, |
| 1598 | Textarea, |
| 1599 | Rich, |
| 1600 | ] |
| 1601 | assert_eq!; |
| 1602 | |
| 1603 | // And the two multi-line ones get a multi-line edit, which is the half |
| 1604 | // `control_shape` alone does not say: both are typed into, and only one |
| 1605 | // of the two edit shapes can hold a markdown document. |
| 1606 | assert!; |
| 1607 | assert!; |
| 1608 | assert!; |
| 1609 | |
| 1610 | |
| 1611 | |
| 1612 | |
| 1613 | // The description holds Select and Radio apart, and a renderer that |
| 1614 | // collapsed them would silently answer a question the app did not ask: |
| 1615 | // audiofiles' storage style is irreversible and its alternatives have |
| 1616 | // to be readable without opening anything. Asserting the two shapes |
| 1617 | // differ is asserting that distinction survives the trip. |
| 1618 | assert!; |
| 1619 | assert!; |
| 1620 | assert_ne! |
| 1621 | control_shape, |
| 1622 | control_shape |
| 1623 | ; |
| 1624 | |
| 1625 | |
| 1626 | |
| 1627 | |
| 1628 | let p = palette; |
| 1629 | assert_eq!; |
| 1630 | assert_eq!; |
| 1631 | // The whole point of the distinction: muted is what Disabled resolves |
| 1632 | // to, so an option wearing it would claim it does not answer a press. |
| 1633 | assert_ne!; |
| 1634 | |
| 1635 | |
| 1636 | |
| 1637 | |
| 1638 | // Where the two renderers legitimately part: a webview still emits an |
| 1639 | // input because the form submits, and there is no form here. |
| 1640 | let f = new; |
| 1641 | let p = palette; |
| 1642 | __run_test_ui |
| 1643 | let drawn = field; |
| 1644 | assert!; |
| 1645 | ; |
| 1646 | |
| 1647 | |
| 1648 | |
| 1649 | |
| 1650 | let f = new; |
| 1651 | let p = palette; |
| 1652 | let style = default; |
| 1653 | __run_test_ui |
| 1654 | let mut text = Stringfrom; |
| 1655 | let disabled = field |
| 1656 | ui, |
| 1657 | &f, |
| 1658 | Text, |
| 1659 | Some, |
| 1660 | &p, |
| 1661 | &style, |
| 1662 | |
| 1663 | .unwrap; |
| 1664 | assert!; |
| 1665 | |
| 1666 | // Stating no state is the ordinary case and answers. Focus used to |
| 1667 | // be the counter-example here; it is egui's now and a description |
| 1668 | // cannot state it at all. |
| 1669 | let mut text = Stringfrom; |
| 1670 | let plain = field.unwrap; |
| 1671 | assert!; |
| 1672 | ; |
| 1673 | |
| 1674 | |
| 1675 | |
| 1676 | |
| 1677 | // No panic and no write-through. A checkbox handed a string cannot be |
| 1678 | // filled, so it is drawn off and left alone. |
| 1679 | let f = new; |
| 1680 | let p = palette; |
| 1681 | let mut text = Stringfrom; |
| 1682 | __run_test_ui |
| 1683 | let drawn = field |
| 1684 | ui, |
| 1685 | &f, |
| 1686 | Text, |
| 1687 | None, |
| 1688 | &p, |
| 1689 | &default, |
| 1690 | ; |
| 1691 | assert!; |
| 1692 | ; |
| 1693 | assert_eq!; |
| 1694 | |
| 1695 | |
| 1696 | |
| 1697 | |
| 1698 | let fields = |
| 1699 | new, |
| 1700 | Field |
| 1701 | extended: true, |
| 1702 | ..new |
| 1703 | , |
| 1704 | ]; |
| 1705 | let style = default; |
| 1706 | |
| 1707 | let mut closed = Vecnew; |
| 1708 | __run_test_ui |
| 1709 | group; |
| 1710 | ; |
| 1711 | assert_eq!; |
| 1712 | |
| 1713 | let mut open = Vecnew; |
| 1714 | __run_test_ui |
| 1715 | group; |
| 1716 | ; |
| 1717 | assert_eq!; |
| 1718 | |
| 1719 | |
| 1720 | |
| 1721 | |
| 1722 | let d = default; |
| 1723 | assert_eq!; |
| 1724 | assert_eq!; |
| 1725 | assert!; |
| 1726 | |
| 1727 | |
| 1728 |