S015: Material You foundation: M3 schemes, Outfit, icons, springs, widgets, gallery

Fixes R1-01 (icon glyphs) and R1-02 (clock contrast).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
astar76 2026-11-11 19:36:53 -06:00
commit 07b357deaf

View file

@ -140,6 +140,86 @@ picture-in-picture, extensions, password capture, printing.
- Hardware acceleration switch: Servo needs GL; "Off" selects software GL (LIBGL_ALWAYS_SOFTWARE) on next start.
- Printing: "Save page as PDF/PNG" through a full-page screenshot.
## UI system (S015)
Everything the interface draws takes its colours, radii, sizes and springs from `src/theme.rs`; widgets live in
`src/ui/widgets.rs`, Expressive shapes in `src/ui/paint.rs`, icons in `src/ui/icons.rs`. `nacre://gallery`
(`src/ui/pages/gallery.rs`, not linked from the UI) shows all of it; `SMOKE_SIZE=1400x2800 tools/smoke.sh
tests/smoke/gallery.txt` shoots it dark and light. Rules: the `app-taste` skill. No one-off colour, radius or duration.
**Tokens reach widgets through the egui context.** `theme::apply(ctx, &palette, &settings)` (called by
`App::style_window` whenever the theme, seed or settings change) stores `theme::Tokens { palette, roundness, motion }`
and sets egui visuals, text styles and spacing. From any `Ui`: `theme::palette(ui.ctx())`,
`theme::radius(ui.ctx(), theme::L)`, `theme::spring(...)`. Fonts are set once per window: `ui::fonts()` in
`window.rs`.
**Colour** (`theme::Palette`, from the `material-colors` crate, D-009). `Palette::new(seed, dark, variant, contrast)`
builds the M3 scheme; `variant` is a `theme::VARIANTS` key (tonal_spot default), `contrast` -1..1. Seeds:
`theme::seed` (website colour if chroma ≥ 12 and tone 8..95, else fallback; system accent; preset; custom).
- M3 roles: `primary`, `on_primary`, `primary_container`, `on_primary_container`, `inverse_primary`, `secondary*`,
`tertiary*` (same four each), `error`, `on_error`, `error_container`, `on_error_container`, `surface`,
`surface_dim`, `surface_bright`, `surface_container_lowest`, `surface_container_low`, `surface_container`, `surface_container_high`,
`surface_container_highest`, `on_surface`,
`on_surface_variant`, `outline`, `outline_variant`, `inverse_surface`, `inverse_on_surface`, `scrim`, `shadow`.
- Extra: `warning`, `success` (fixed hues at primary's tones).
- Old names kept as aliases for existing code: `accent` = primary, `on_accent` = on_primary, `accent_soft` =
secondary_container, `surface_high` = surface_container_high, `surface_low` = surface_container_lowest (the page
background), `text` = on_surface, `text_weak` = on_surface_variant. New code uses the M3 names.
- Usage: page background `surface_container_lowest`; cards `surface_container`; floating surfaces
`surface_container_high`; fields `surface_container_highest`; hairlines `outline_variant`; selection
`secondary_container` + `on_secondary_container`; main action `primary`.
- State layers: `theme::layer(base, over, amount)` mixes opaque; constants `HOVER` 0.08, `FOCUS` 0.10, `PRESS` 0.10,
`DRAG` 0.16, `DISABLED_CONTENT` 0.38, `DISABLED_CONTAINER` 0.12 (content colour over the container).
**Shape and space.** Radii `XS` 4, `S` 8, `M` 12, `L` 16, `XL` 28, `FULL` (pill); always read through
`theme::radius(ctx, token)` (Roundness setting: Subtle ×0.5, Default ×1, Round ×1.4) and convert with
`theme::corner_radius(f32)`. Spacing `GAP_XS` 4, `GAP_S` 8, `GAP_M` 12, `GAP_L` 16, `GAP_XL` 24. Heights
`CONTROL_SMALL` 32 (icon buttons), `CONTROL` 40 (buttons, segmented), `ROW` 56 (list rows). Cards use `L`, chrome
pills `FULL`, small egui widgets `S` (`theme::corner`).
**Type.** Outfit (OFL, `assets/fonts/Outfit[wght].ttf`, one variable font) at `theme::Weight` Thin 200, Light 300,
Regular 400 (egui's Proportional), Medium 500, SemiBold 600; `theme::font(size, weight)`. Sizes `SMALL` 12, `BODY` 14,
`TITLE` 18, `HEADLINE` 24, `DISPLAY` 64 (clock: Thin, primary). egui text styles: Small/Body/Button/Heading(24
Medium)/Monospace 13. Outfit is Latin only: every family falls back to Material Symbols, then egui's Ubuntu-Light
(Cyrillic, Greek). No CJK font is bundled.
**Icons.** Material Symbols Outlined (Apache 2.0), cut to `tools/icons.txt` by `tools/icons.py` into
`assets/fonts/MaterialSymbolsOutlined-Nacre.ttf` (FILL and wght axes kept). Use the constants `icons::HOME` etc.
(`icons::ALL` lists them). To add one: add its name (fonts.google.com/icons) to `tools/icons.txt`, run
`python tools/icons.py`. Draw with `widgets::icon(ui, center, glyph, size, filled, colour)` or
`theme::icon_font(size, filled)`; filled (FILL 1) is for selected states. Icons also work inside text (`format!("{}
Open folder", icons::FOLDER_OPEN)`) through the fallback. Sizes `ICON` 20, `ICON_LARGE` 32. Never emoji.
**Motion.** `theme::spring(ctx, id, target, spring) -> f32`: per-id state in egui memory, retargets keeping
velocity, starts at the target on first use, repaints only while moving, returns the target at once with Motion off.
`theme::effect(ctx, id, on) -> 0..1` is the colour/opacity spring. Presets (stiffness/damping ratio): `FAST`
1400/0.62 (press, small controls), `DEFAULT` 700/0.68 (panels, movement), `SLOW` 300/0.74 (big transitions),
`EFFECT` 900/1.0 (colour, opacity; never overshoots). Motion setting = time factor (Off 0, Fast 0.6, Normal 1,
Slow 1.8; stiffness ÷ factor²); `theme::animation_time` drives egui's own animations (0.1 s × factor).
**Widgets** (`ui::widgets`; all have hover state layer, press squeeze, focus ring in `secondary`, disabled 38 %):
- `button(ui, ButtonKind::{Filled, Tonal, Outlined, Text}, Option<icon>, label) -> Response`: 40 px pill, press
morphs to radius `S`.
- `icon_button(ui, icon, tooltip)`, `icon_toggle(ui, icon, tooltip, on)`: 32 px circle, press squashes to a squircle;
selected = `secondary_container` fill and filled icon.
- `switch(ui, &mut bool) -> changed`: M3 switch, handle travels (FAST) and grows with a check when on, hover halo.
- `segmented(ui, &mut T, &[(T, label)]) -> changed`: equal-width segments, selected = tonal fill + check that slides in.
- `card(ui, |ui| ...)`: `surface_container`, radius `L`; rows inside get hairlines between them (not above the first).
- `row(ui, title, description, |ui| control)`, `switch_row`, `link_row(ui, title, description) -> clicked` (whole
row is the button, chevron at the end), `section(ui, title)` (group title in `primary`, above a card).
- `text_field`, `number`, `page_column`, `glyph(toolbar key) -> icon`.
**Shapes** (`ui::paint`): `cookie(painter, center, radius, lobes, rotation, fill, stroke)`,
`cookie_image(painter, texture, center, radius, lobes, rotation)` (artwork in a cookie), `cookie_points`,
`wavy_line(painter, x0, x1, y, amplitude, wavelength, phase, stroke)`, `wavy_progress(painter, rect, fraction,
amplitude, phase, &palette)` (amplitude 0 = flat, animate it with a spring when playing/paused; advance `phase` only
while something plays), `shadow(painter, rect, radius, dark)` (one soft shadow for floating surfaces; egui's
`window_shadow`/`popup_shadow` are set to match).
**What egui can't do here:** no text blur or text shadows; no per-glyph variable axes inside one label (a weight is
a font family); shadows are tessellator-blurred rectangles only (not arbitrary shapes); `Ui::id`/`Id::new` are
deprecated in 0.37 but still used across the code.
## Feature checklist
See `docs/FEATURES.md`; every row names the file that implements it and its review state.