Skip to content

Style structs keep only metrics and behaviour; the looks live in the sheet (#482) - #495

Merged
samitbasu merged 11 commits into
mainfrom
struct-looks-482
Nov 24, 2026
Merged

samitbasu merged 11 commits into
mainfrom
struct-looks-482

Conversation

@samitbasu

Copy link
Copy Markdown
Owner

The core style sections no longer hold how a widget looks. Each keeps the
metrics and behaviour its widget, its recorded exceptions or the extras
read: sizes, delays, offsets, gaps. The look a style without a preset
draws is written once, in Style::from_egui, as a crate-private
XDefaults on the Defaults layer, the pattern ButtonDefaults set. The
shadcn preset's writes to the removed fields are deleted: its generated
sheets replace those parts, so they were dead. Where a write was live
(a part no generated sheet covers), it became a Preset-layer rule.

One commit per family: tooltip, table, choices, tabs, the text roles,
input (look, then height/padding/radius), select, menu, and the shadcn
token cleanup.

Closes #482

Breaking changes

  • Removed look fields. Restyle with rules on the family's parts.
    • TooltipStyle: popup, radius, padding, text, max_width.
    • TableStyle: header_fill, header_weight, header_height,
      cell_padding, cell_padding_y, header_padding_y, group_fill,
      group_text, hover, selected, footer_fill, footer_weight,
      transition.
    • CheckboxStyle, RadioStyle, SwitchStyle: border_width, off,
      on, transition.
    • SegmentedStyle: text, selected_weight, cell_border_width,
      selected, unselected, transition.
    • InputStyle: look. InputMetrics: radius, padding, height;
      a field reads them from the resolved InputPart::Root.
    • SelectStyle: trigger, text, transition.
    • MenuStyle: popup, radius, min_width, item, item_radius,
      destructive, separator, separator_margin, heading,
      heading_weight, shortcut, shortcut_tracking. It keeps
      padding, offset, item_padding, item_gap, text,
      shortcut_text and indicator.
  • MenuStyle::box_classes is removed (it was public). row_height
    stays.
  • Style::at_current_layer is removed; its one user, markdown's
    typeset tables, writes its own scope rules.
  • The setters stay where a struct still holds behaviour or metrics,
    and write only those rules. set_tooltip writes no rules.
  • shadcn Tokens:
    • control_height: f32 → control_units: f32 (Vega 9, Lyra 8);
      Tokens::control_height() gives the points at the tokens' spacing.
    • In spacing units now: button_padding, input_padding,
      control_gap, icon_size, toggle_padding_x, cell_padding,
      popup_padding, item_padding, slider_track, slider_thumb,
      switch_thumb. Tokens::points / points_vec turn them into points.
    • Points by design, unchanged: list_padding (p-[3px]),
      slider_halo (a ring width), switch_track (h-[1.15rem], a rem),
      ring_width.

New API

  • TablePart::first_column() -> When: the head and cells of a table's
    first column.
  • shadcn Tokens::control_height(), Tokens::points(units),
    Tokens::points_vec(units).

What moves visibly

At the default tokens, with the preset: nothing. No golden moves in
any commit. For the menu step, a dump of every extras style and the
resolved menu and select parts, in Vega and Lyra, light and dark, is
identical before and after.

At a non-default spacing (the intended fix for #487's gap): a text
field is h-9 (h-8 in Lyra) at that spacing, 31.5 at 3.5 points a unit, not
a fixed 36. Everything fed by the converted tokens scales too:

  • the select trigger's, toggle's, segmented's and stepper's heights;
  • toggle and icon-button least widths, and a form row's least height;
  • menu and popup padding, and menu rows;
  • segmented cells and icons;
  • the slider's track and thumb, and the switch thumb;
  • the stepper's inline padding;
  • egui's interact_size.y, button padding and icon width.

Without a preset (looks of the extras only; core's own widgets look as
before):

  • The command palette's highlighted row, and the highlighted option of a
    combobox's and an autosuggest's list, take tokens.accent /
    accent_foreground, not egui's selection colours.
  • A combobox's border while its field has focus is tokens.ring, not
    egui's selection stroke.
  • An extra's popup border is 1 pt, where it was egui's window stroke
    width. That is 1 pt in egui's own styles.

Core's menus and the select list still highlight in egui's selection
colours, as decided.

Behaviour notes

  • With no preset, an app that changes style.text and calls
    rewrite_rules re-roles its buttons, tooltips, tab triggers and select
    triggers again (write_text_roles). This had regressed for buttons
    since the ButtonStyle deletion.

Exceptions: eggshell's own Preset-layer rules

shadcn does not draw these, so the preset writes them itself:

  • a table's group rows: TablePart::Group muted/50,
    TablePart::GroupCell muted-foreground;
  • the sm and xs text fields: a unit and three under control_units,
    own_input_padding_x inline, py-0.5 at xs, on InputPart::Root,
    InputGroupPart::Root, Input and the inline addons.

Not in this PR

Docs

docs/overlays.md and the InputStyle doc table are marked TODO(prose)
where they list removed fields.

Tests

Every commit:

  • rewrites the tests that read removed fields to read the resolved part;
  • runs cargo xtask integrate green;
  • has a mutation check caught by a test.

New tests where none covered a look:

  • the neutral tabs' chosen cell;
  • a new text role reaching the widgets' own looks;
  • a dense sm field, 28 tall, with its icon in units;
  • the no-preset combobox highlight and its box radius from the sheet;
  • the no-preset menu highlight;
  • the unit tokens scaling.

cargo xtask ci: exit 0 on 5b9bca7.

🤖 Generated with Claude Code

https://claude.ai/code/session_01PWiKKfuwuKXZxdwsSBxd76

samitbasu and others added 11 commits November 23, 2026 08:27
`TooltipStyle` keeps what the tooltip machinery reads: the arrow, the
offset, the delay and the grace. The box's look, popup, radius, padding,
text and max_width, goes:

- a style without a preset writes it once from egui's visuals, as
  `TooltipDefaults`, on the Defaults layer (the `ButtonDefaults` pattern);
- the shadcn preset's writes to those fields are removed: its generated
  `cn-tooltip-content` replaced them;
- `set_tooltip` sets the behaviour only and writes no rules.

Breaking: `TooltipStyle::{popup, radius, padding, text, max_width}` are
removed. To restyle the box, write a rule on `TooltipPart::Content`, as
the gallery's scoped tooltip now does.

Tests that read the removed fields now read the resolved
`TooltipPart::Content`: its fill, ink and max width, through two new
support helpers (`support::part`, `support::ink`). The styled-scope test
reads the scope's offset at draw time, and the box's growth comes from
the scope's rule. No golden moves. Mutation: widening the default
max_width fails the neutral-style test.

docs/overlays.md is marked TODO(prose) where it lists the old fields.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKf74MNWrhkW1CvKVUP
`TableStyle` keeps the rules between rows (rule, rule_width,
rule_below_last), stripes, the first column's inset, and a group row's
title size, weight and end: what the recorded exceptions, the table
builder and the extras read. The rest of the look goes:

- a style without a preset writes it once from egui's visuals, as
  `TableDefaults`: the bands' fills, the cells' padding and weights, the
  header's height, the rows' hover, selection and transition;
- `set_table` writes only the rules its fields give, under a preset's
  look, and the exceptions again over it;
- the shadcn preset's writes to the removed fields are gone.

Not every preset write was dead. shadcn has no table groups, so a group
row's muted/50 fill and muted-foreground title came only from the preset's
struct writes. The preset now writes them as rules on `TablePart::Group`
and `TablePart::GroupCell`, next to its other rules of its own, and
table_example's goldens are unchanged.

`Style::at_current_layer` is removed, with the crate-private `Writes` mode
it switched. Its one user, markdown's typeset tables, now writes its own
scope rules: a rule under the header and every row, the cells' padding,
the head's weight and the first column's inset. For that,
`TablePart::first_column() -> When` is new public API: the head and cells
of a table's first column.

Breaking:
- `TableStyle::{header_fill, header_weight, header_height, cell_padding,
  cell_padding_y, header_padding_y, group_fill, group_text, hover,
  selected, footer_fill, footer_weight, transition}` are removed. To
  restyle a table, write rules on its `TablePart`s.
- `Style::at_current_layer` is removed.

Tests: the scope and extension tests that used `cell_padding` as a marker
use `rule_width`. The styled-table tests write scope rules, and the nested
one pads only the bottom, so the top proves it kept the outer scope's
rule. The table tests read the resolved parts, and hover and selection
from the theme's tokens. The two tests for the removed `cell_padding_y`
and `header_padding_y` are deleted (markdown's typeset tests cover what
they did). The at_current_layer test is deleted. No golden moves.
Mutation: a wrong first-column inset in markdown's rules fails the
typeset test and golden.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKf74MNWrhkW1CvKVUP
…eet (#482)

`CheckboxStyle`, `RadioStyle` and `SwitchStyle` keep their sizes and
label text role, and the switch its gap and slide: what the widgets read
when they build and what the size exceptions write. Their look, off and on
paints, border width and transition, goes:

- a style without a preset writes it once from egui's visuals, as
  `ChoiceDefaults`: each control's look, checked or not, enabled or not;
- `set_checkbox`, `set_radio` and `set_switch` write only the rules their
  sizes give (the box, circle, dot, track and thumb sizes, and a
  checkbox's corners per size);
- the shadcn preset's writes to the removed fields are gone. Its generated
  checkbox, radio-group and switch sheets replace every part those rules
  styled, so the writes were dead; no golden moves.

The label's colours stay on the style (`Style::label`): the extras' form
and markdown read them.

Breaking: `CheckboxStyle`, `RadioStyle` and `SwitchStyle` lose
`border_width`, `off`, `on` and `transition`.

Tests that read the removed paints now read the resolved sheet under the
part's keys: the switch's track and thumb fills, its track on a form
section, and the disabled-colours test. That test now runs on the
egui-derived style, whose look still comes from paints in the
Disabled::Colors form. The ring test does the same. The test that set a red
hover on the preset's thumb is reduced to what it proved: the thumb keeps
its rest colour. The red was a dead write under the generated sheet. The
disabled-colour walk loses the six choice paints, since they're no longer
on the style.

Mutation: drawing a disabled checkbox in its enabled look fails the
disabled-colours test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKf74MNWrhkW1CvKVUP
`SegmentedStyle` keeps the track's fill and each size's metrics: what the
recorded exceptions read (the track keeps its fill on a muted panel, #346;
the sizes other than the default keep their metrics). The cells' look,
chosen and unchosen paints, border width, transition, text role and the
chosen cell's weight, goes:

- a style without a preset writes it once from egui's visuals, as
  `TabsDefaults`;
- `set_segmented` writes the tabs' layout and the rules its fill and
  sizes give;
- the shadcn preset's writes to the removed fields are gone. Its generated
  tabs sheet replaces every part, so they were dead; no golden moves.

Breaking: `SegmentedStyle::{text, selected_weight, cell_border_width,
selected, unselected, transition}` are removed. A chosen cell's own
weight is a rule on `TabsPart::Trigger` while it is `aria-selected`.

Tests:
- Those that set the removed fields write the equivalent rules: a hover
  colour, a text role, a chosen weight.
- Those that read the paints read the resolved trigger.
- The icon-tint test compares the icon against its label drawn in the
  same cell.
- The inert segmented tests run on the egui-derived style, where the
  widget's own look lives now. The disabled-colour walk loses the two
  segmented paints.
- New: the neutral style draws the chosen cell in egui's active fill and
  no other cell filled. Before this, no test covered the no-preset look:
  swapping the chosen cell's paint passed the whole suite, and it now
  fails this test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKf74MNWrhkW1CvKVUP
The looks a style without a preset writes once from egui's visuals
(`ButtonDefaults`, and this PR's `TooltipDefaults` and `TabsDefaults`)
took their text role from egui at that moment. With no preset, an app that
changed `style.text` and called `rewrite_rules` no longer re-roled its
buttons (since the ButtonStyle deletion), tooltips or tab triggers.

The role now comes out of those defaults into `write_text_roles`, which
`rewrite_rules` runs with the style's text role: an enabled button, as
before; a tooltip's box; a tab's trigger. A change to `style.text` reaches
all three again once the rules are written, as it did when the sections
wrote them. A preset's generated looks replace these parts as before.

Test: a new text role reaches a button, a tooltip and a tab trigger after
`rewrite_rules`, and not before. Mutation: a wrong size on the trigger's
role fails it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKf74MNWrhkW1CvKVUP
`InputStyle` keeps its sizes, hint colour and icon colour: what the field,
the size exceptions, the menus, the stepper, the command palette and
markdown read. Its look goes:

- a style without a preset writes it once from egui's visuals, as
  `InputDefaults`: a field's and an input group's colours per state,
  border, ring and shadow;
- `set_input` writes an input group's layout and the rules its icon colour
  and sizes give;
- the shadcn preset's write of the look is gone. Its generated input and
  input-group sheets replace those parts, so it was dead; no golden moves.

The look's other readers now read the resolved `InputPart::Root`: the
stepper's and readout's inset (its border width), and markdown's and the
command palette's border colour, through one `styles::input_border` helper
in extras.

Breaking: `InputStyle::look` is removed. To restyle a field, write rules
on `InputPart::Root` and `InputGroupPart::Root`.

Tests: the mapping test writes its unusual look as a rule on the field's
part. Those that read the border width or colour read the resolved part
(`support::input_border`). The stepper's red group is a rule. The ring
test runs on the egui-derived style, whose input has no ring of its own,
and claims the report its small box raises there: that style has one
size. Mutation: a wider default border fails the neutral-input mapping
test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKf74MNWrhkW1CvKVUP
`SelectStyle` keeps each size's metrics and the chevron's size and
opacity: what the size exception, the menus, the disclosure and the
command palette read. The trigger's look, text role and transition go:

- a style without a preset writes the look once from egui's visuals, as
  `SelectDefaults`;
- the trigger's text role follows `Style::text` through
  `write_text_roles`, as the button's, tooltip's and tabs' do;
- `set_select` writes the trigger's layout, the disabled fade, the rules
  its sizes and chevron give, and the list drawn from the menu section,
  which moves with the menu commit;
- the shadcn preset's writes of the look are gone. Its generated select
  sheet replaces the trigger, so they were dead; no golden moves.

The command palette's combobox box, its look without a preset, read the
trigger's look from the section. It now resolves the trigger from the
sheet and keeps its own layout: auto width, content at the start, the
field's padding at the left. Its border while the field has focus is the
tokens' ring colour, where it was egui's selection stroke. That's a
no-preset look only, untouched by any golden.

Breaking: `SelectStyle::{trigger, text, transition}` are removed.

Tests: the sections that set the trigger's fill or text role write those
as rules on `SelectPart::Trigger`. The disabled-colour walk loses the
trigger. Mutation: drawing the default trigger disabled fails the
combobox defaults test and the overlay fuzzers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKf74MNWrhkW1CvKVUP
A text field's frame, egui's TextEdit margin and interact height, a
readout's outset and a slider header's row now read the resolved
InputPart::Root at the theme's spacing (`owned::input_frame`), the same
place the field's colours and border already came from. So a field
follows the generated `h-9 px-2.5 py-1` and the spacing token.

Without a preset the field keeps egui's radius, button padding and
interact height: InputDefaults writes them on the Defaults layer, beside
the rest of the no-preset look.

eggshell's sm and xs fields are the shadcn preset's own rules now, in
spacing units over the generated look: a unit (sm) and three (xs) under
`control_units`, with `own_input_padding_x` inline and `py-0.5` at xs.
Core's size exception keeps only what core still holds per size: the
control's text, the addon icon size and the icon gap.

Breaking changes

- `InputMetrics` loses `radius`, `padding` and `height`. Set them with
  sheet rules on `InputPart::Root` / `InputGroupPart::Root`.
- shadcn `Tokens.control_height: f32` becomes `control_units: f32` (Vega
  9, Lyra 8); `Tokens::control_height()` gives the points at the tokens'
  spacing.

Behaviour changes

- At a non-default spacing a field is h-9 (or h-8) at that spacing: 31.5
  at 3.5 points a unit, not 36. The density test's pin moves from 36 to
  31.5, closing the gap #487 left.
- Everything that read the preset's `control_height` now scales with the
  spacing too: the select trigger's and toggle's heights, the toggle's and
  icon buttons' least width, the segmented and stepper heights, a form
  row's least height, and egui's `interact_size.y`.
- No golden moves at the default tokens, with or without a preset.

Tests

- density: a dense sm field is 28 tall and its leading icon sits
  border + 3 units in.
- The input mapping test sets the radius, height and padding by a sheet
  rule, one of them in units.
- Tests that read the struct's metrics read the resolved part
  (`support::field_box`, the shadcn tests' `field_of`).

Mutation checks, each caught: dropping the preset's size rules, a wrong
sm height, and a zeroed height read in `Frame::of`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKf74MNWrhkW1CvKVUP
`MenuStyle` keeps the metrics that lay a menu out and size its rows:
padding, offset, item_padding, item_gap, text, shortcut_text and
indicator. Its look moves to a crate-private `MenuDefaults`, built in
`Style::from_egui` from egui's visuals and written once on the Defaults
layer, as the other families' are: the box's colours, border, shadow,
radius and least width, the items' colours and radius, the destructive
item, the separator, the heading and the shortcut. The same writer paints
the select's list (`SelectPart::Content` and `Item`), which is drawn with
the menu's look. The layout writer appends rules over it rather than
replacing them.

Under the preset every menu part and the select list's are replaced by
the generated sheets, so the preset's writes to the moved fields were
dead; they are removed.

The extras that drew a box or rows as a menu does read no menu field
now. A shared `styles::Popover` gives the box: the popover's colours and
`shadow_md` from the tokens, a 1 pt border, and the radius of the
resolved `MenuPart::Content`. The command list's rows take the item's
radius and the heading's weight from the resolved `MenuPart::Item` and
`Label`, the separator from the resolved `MenuPart::Separator`, and their
colours from the tokens. Under the preset every value is the one it was:
a dump of the extras' styles and the resolved menu and select parts,
both styles in both themes, is identical before and after.

Breaking changes

- `MenuStyle` loses popup, radius, min_width, item, item_radius,
  destructive, separator, separator_margin, heading, heading_weight,
  shortcut and shortcut_tracking. Restyle a menu with rules on its
  `MenuPart`s.
- `MenuStyle::box_classes` is removed (it was public). `row_height`
  stays.

Behaviour changes, without a preset only (the user's pick: token
colours, no new public API)

- The command palette's highlighted row, and the highlighted option of a
  combobox's and an autosuggest's list, take `tokens.accent` and
  `accent_foreground`, not egui's selection colours.
- The combobox's focus border is `tokens.ring` (from the select step).
- An extra's popup border is 1 pt, where it was egui's window stroke
  width (1 pt in egui's own styles).
- Core's menus and the select list are unchanged: they still highlight
  in egui's selection colours.

No golden moves.

Tests

- combobox_sheet: without a preset the highlighted option is the accent
  token; an App rule on `MenuPart::Content` sets the list box's radius.
- menu_sheet: without a preset a highlighted menu item takes egui's
  selection fill (no test covered it before).
- The disabled-colours walk reads a disabled menu item from the sheet;
  shadcn fades it with `opacity-50` and gives it no colours, so it is
  counted only where the sheet gives one.
- Tests that read the highlight from the struct read the accent token
  (they run under the preset).

Mutation checks, each caught: a zero popup radius, the palette highlight
on another token, and the core menu's highlight fill.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKf74MNWrhkW1CvKVUP
Every shadcn `Tokens` length the preset still reads as a struct metric
is now held in spacing units and turned into points where it is read, at
the tokens' spacing, so it follows the `spacing` token as the generated
sheets do. None could be deleted: each still feeds a metric that stays
on a section (select, segmented, stepper, slider, switch, menu rows, the
toggle, and egui's own spacing).

`Tokens::points(units)` and `points_vec(units)` give the points;
`control_height()` reads through them.

Breaking changes

- In spacing units now (Vega / Lyra): `button_padding` (4, 2 / 2.5,
  1.5), `input_padding` (2.5, 1), `control_gap` (2 / 1.5), `icon_size`
  (4 / 3.5), `toggle_padding_x` (2 / 2.5), `cell_padding` (2, 1 / 1.5,
  0.5), `popup_padding` (1), `item_padding` (2, 1.5 / 2, 2),
  `slider_track` (1.5 / 1), `slider_thumb` (4 / 3), `switch_thumb` (4).
- Points by design, unchanged: `list_padding` (`p-[3px]`), `slider_halo`
  (a ring width), `switch_track` (its height is `h-[1.15rem]`, a rem),
  `ring_width`, borders and shadows.
- Preset literals in units: the default input's icon and gap (4, 2), the
  segmented control's icon gap (1.5), the badge's icon padding (1.5).

Behaviour changes

- At a non-default spacing these metrics scale: menu and popup padding,
  menu rows, segmented cells and icons, slider track and thumb, the
  switch thumb, toggle padding, the stepper's inline padding, egui's
  button padding and icon width, and the three literals above.
- No golden moves at the default tokens.

Closes the "doesn't scale yet" list #487 left, apart from the points
kept by design above.

Tests

- density: at 3.5 points a unit, the menu's padding and item padding,
  the slider's track and thumb, and egui's button padding are the units
  times 3.5.
- The Lyra token test reads the units.

Mutation checks, each caught: the item padding fixed at 4 points a
unit, and `switch_thumb_for` mixing units with the track's points.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKf74MNWrhkW1CvKVUP
@samitbasu
samitbasu merged commit afe1883 into main Nov 24, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Style structs: move the no-preset looks into Defaults-layer sheets, and delete the look fields

1 participant