Skip to content

SharedStyle: one style for every layout; Shadcn::apply and the fallback go (#497 stage 6) - #507

Merged
samitbasu merged 5 commits into
mainfrom
layout-style-497
Nov 25, 2026
Merged

samitbasu merged 5 commits into
mainfrom
layout-style-497

Conversation

@samitbasu

@samitbasu samitbasu commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Stage 6 of #497: one SharedStyle is the source of the look. #506 has merged, and main is merged in with no file changes, so the diff is stage 6 only.

What changes (decided on #497)

  • SharedStyle::new(themed) is a clonable handle, re-exported at the crate root.
    • Every layout is made from it: LayoutState::new(&shared) or LayoutState::named(name, &shared).
    • shared.set(..) switches every layout made from the handle, from their next build. shared.get() reads it.
  • The layout gives egui its visuals and fonts from the handle's style, only when that style changes. The contrast warning fires at the same point.
  • Deleted:
    • Shadcn::apply, apply_both, apply_both_with, applied and of;
    • the context's token store (theme::tokens);
    • with_style, LayoutState::set_style, LayoutState::style() and LayoutState's Default;
    • Style::fallback with its faces hack, FontSet::install and Problem::UnstyledLayout.
  • A style whose tokens carry no font declares egui's regular face for every weight. It draws the same, with no MissingFace.
  • A layout's root text is always its style's text. egui's Body style is no longer read.
  • Harnesses: Headless and Driver take .style(&SharedStyle) and default to shadcn's default style.
  • Examples: each example makes one handle for all its layouts, and the style and palette pickers call set.

Goldens (approved by the user)

The 8 layout-only goldens (kaolin_*, chrome_stacked_by_z) re-render in Geist instead of egui's sans, with the layout unchanged. Measurement matches paint: for example, "Fit me" is 45.47 pt in Geist against 44.53 pt in egui's sans, and both snap to the same pixel edge. The new PNGs are byte-identical to the reviewed images. No other golden moved.

Checks

  • cargo xtask integrate: all green (11/11), 229/229 goldens.
  • New tests:
    • set swaps the style from the next build;
    • every layout made from one handle follows its set.
  • Deleted tests:
    • the unstyled-layout reports;
    • the fallback;
    • egui-Body root text;
    • Shadcn::of;
    • the egui-defaults sidebar case;
    • "a layout without a style leaves egui alone";
    • "applying one theme leaves the other alone".

For the user

  • Try it: the examples' theme and palette pickers now drive the handle. Please try switching in an example before approving.
  • Prose: TODO(prose) on the theme module docs, the field/tokens/fonts docs that named Shadcn::apply, the README line about registering Geist, and the style, egui_look and layout_style test module docs.

🤖 Generated with Claude Code

https://claude.ai/code/session_01PWiKKfuwuKXZxdwsSBxd76

samitbasu and others added 5 commits November 24, 2026 20:25
A layout is given its style when it is made, LayoutState::new(style) or
LayoutState::named(name, style), and draws, builds and gives egui its
look from it alone; set_style still switches it, and style() reads it.
There is no look outside a layout any more.

- Deleted: Shadcn::apply, apply_both, apply_both_with, Shadcn::applied
  and Shadcn::of, theme::tokens (the context's token store),
  LayoutState::with_style and its Default, Style::fallback with its
  faces mapping every weight to egui's regular face, FontSet::install,
  Problem::UnstyledLayout (no layout is without a style).
- The contrast warning is given where a layout gives egui a new style
  (the first build after new or set_style), once for a light and dark
  pair that are one style.
- In a debug build, layouts on one context that give egui different
  looks in the same pass are reported, as Problem::EguiStyleClash. The
  looks compare as egui receives them, so one style built twice is no
  clash, and a style switched on every layout in one pass is none
  either.
- Text measured before any build has applied faces is drawn in its
  family's regular face, unreported; a Ui that is no node's has the
  default Style (NodeUi::node_style).
- The testing harnesses (Headless, Driver) lay out in shadcn's default
  style unless given one.

Behaviour changes:
- A layout's root text is its style's always; egui's Body is no longer
  read by a layout without a style.
- A fontless style (no `fonts` feature, or Shadcn::with_fonts(None))
  reports MissingFace for its weighted text, as the fallback's faces
  mapping is gone.
- Goldens: the 8 layout-only goldens (kaolin_*, chrome_stacked_by_z)
  draw in Geist instead of egui's font; they are not updated in this
  commit, pending the user's review.

Tests: the examples, tests and benches give each layout the style they
draw with (support::shadcn, the examples' chosen style, shadcn's
default); the rigs' bar follows its page's style. Deleted, as testing
what is gone: the unstyled-layout reports (replaced by clash tests),
the fallback, egui-Body root text, Shadcn::of, and egui-defaults sidebar
cases. style, egui_look and contrast give a layout the preset where
they applied it. The embedded pop-out screenshot scene is larger: the
shadcn window frame did not fit the old one and egui squeezed it.

Breaking: every LayoutState constructor, and the deleted items.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKfuwuKXZxdwsSBxd76
Part names a widget's sheet part enum; the enums that name the nodes a
widget draws (Part::Box and the like) are Node, as checkbox's, select's
and the rest already are. The last private ones: stepper, the number
readout, the text field, disclosure's section, markdown's build, and
mount.

Private names only. No behaviour change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKfuwuKXZxdwsSBxd76
The user's design: a style is shared by handle, not given to each
layout. SharedStyle::new(themed) is a cheap clonable handle; every
LayoutState::new(&shared) or LayoutState::named(name, &shared) builds
and draws with what it holds, and shared.set(themed) switches them all
from their next build. shared.get() reads it.

- Deleted: LayoutState::set_style and LayoutState::style (the handle
  switches and reads), Problem::EguiStyleClash and its detection (a
  second SharedStyle is a deliberate act), Kept's cached egui look.
- Fontless styles stay quiet: when the tokens carry no font,
  Style::new declares egui's regular face for every weight (Faces::
  egui_regular), so text draws as before with no MissingFace.
- Testing: Headless and Driver take a &SharedStyle (.style) and make
  shadcn's default when given none; Driver::set_style sets its handle.
- Examples: common::shared_style() makes an app's handle and
  common::adopt(ctx, &shared) registers it, so the style and palette
  pickers set it; ThemeBar::new takes the handle its layout shares.
- Test rigs: the bar and the page are made from one handle; Rig gets a
  set_style that sets it, as Driver's does.

Tests: the four clash tests are gone; layout_style switches through
the handle and gains a test that two layouts from one handle both
follow a set; font_weights' fontless case expects no report now, and
layout_style's undeclared-medium precondition uses a style with no
faces at all.

Breaking: LayoutState::new/named take &SharedStyle; set_style and
style() on LayoutState are gone; Headless/Driver::style take
&SharedStyle; ThemeBar::new (examples) takes the handle.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKfuwuKXZxdwsSBxd76
The layout is now the one source of the look, so the 8 goldens that
drew in egui's default sans because their layouts had no style of their
own (kaolin_embedded_layout, kaolin_hello_world, kaolin_multi_column,
kaolin_nested, kaolin_responsive, kaolin_sizing, kaolin_text_wrapping,
chrome_stacked_by_z) draw in their style's font, Geist.

Only the text face changed: every box, fill, border, radius and
position is the same, and wrapped text breaks at the same words. Text
is measured and painted in the same face: "Fit me" is laid out at
Geist's advance, 45.46875 pt (egui's sans: 44.53125), and its box edge
rounds to the same pixel either way; the wrapped rows end where
Geist's metrics put them. Reviewed and approved by the user.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKfuwuKXZxdwsSBxd76
@samitbasu

Copy link
Copy Markdown
Owner Author

Try it: controls_gallery, built at 199d759 (release wasm), is at https://sparkle-squid.pigeon-pride.ts.net/bullseye/controls_gallery-507/ for the user to try the style and palette pickers before approving.

@samitbasu
samitbasu merged commit 63930d4 into main Nov 25, 2026
4 checks passed
@samitbasu
samitbasu deleted the layout-style-497 branch November 25, 2026 05:48
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.

1 participant