Skip to content

M4c: split the shadcn preset into its own crate behind a style contract #19

Closed

Description

@samitbasu

Decided with the user after reviewing M4b (#17). This is its own PR, after M4b merges and before M5.

Why

bullseye::style mixes design-system content into core. Core widgets read shadcn data back out:

  • the TextEdit / ComboBox size estimates use the preset's input_padding, stored in the context;
  • the switch reads the preset's colours;
  • button variants are styled by Shadcn::style_button.

The dependency should run the other way: core defines what its widgets need, and presets provide it.

Goals (from the user)

  1. The style can be truly customised. An app can replace or adjust every value core widgets draw with, without forking a preset.
  2. Other design systems can be added later without changing core. A future Fluent 2 or Material 3 preset would be a new crate that fills the contract; bullseye itself would not change.

No second preset now: only shadcn is implemented. But the contract is reviewed against the axes where Fluent 2 and Material 3 differ from shadcn, so it doesn't close the door on them. It doesn't have to implement them. For each axis, the contract either supports it or the PR explains how a future preset would express it without a core change:

  • Button variants: core must not own a closed, shadcn-named enum. The style decides which variants exist; for example, a variant key maps to a palette. shadcn's five become the preset's own names. (Material has filled/tonal/outlined/text/elevated; Fluent has primary/secondary/outline/subtle/transparent.)
  • Per-state colours: the palette holds explicit colours for each state (rest, hover, pressed, selected, disabled), not a base colour plus an alpha rule. shadcn's alpha steps are computed by the preset when it fills the contract.
  • Control sizes: metrics are per size (e.g. small/medium/large), not one global height, even if shadcn fills only one size at first.
  • Focus indicator: described by the style (rings or strokes, widths, colours, offsets), not hard-coded as one ring.
  • Input appearance: a border and focus treatment the style chooses, which can express an underline-only input.
  • Switch: separate off and on drawing parameters (fill or outline, thumb size per state), not just colours.

Anything here that needs speculative machinery today is left out and noted in the PR instead.

Design (decided with the user, 2026-11-08)

bullseye::Style enumerates every widget's look, and bullseye applies it per widget.

  • One struct in core named bullseye::Style (decided) lists, for each widget kind bullseye draws or hosts, all of its colours, strokes, radii and metrics, per state:

    • widget kinds: button (with style-defined variants), toggle/selectable, checkbox, radio, switch, slider (track, range, thumb), text input, select/combo, drag value, segmented, focus indicator;
    • states: rest, hover, pressed, focused, selected, disabled.

    It's plain data. Every field is public and has a neutral default, so an app can construct it, edit it, or take a preset's version and change parts of it.

  • Applied per widget, scoped to that widget's node Ui. Before egui draws a stock widget, bullseye writes that widget's entries into the node Ui's egui visuals and spacing: WidgetVisuals for inactive/hovered/active/open, selection, handle_shape, padding, interact_size and so on. egui's global Visuals no longer decide how bullseye widgets look, and two widgets that egui would colour from the same global slot (a selected button and a text selection, a slider thumb and a button fill) can differ.

    • The conversion from bullseye::Style to egui visuals for each widget kind is written once, in core.
    • bullseye's own primitives (switch, segmented) read the struct directly.
  • One source for size and look. Metrics live in the struct (button padding, input padding, control heights per size, thumb diameter, …), and the size estimates read the same values that are written into the widget's Ui. Estimate and drawing can't drift apart, and the drift guards test against the struct.

  • Stored in the egui context (with a Builder/ctx accessor), so it can change per frame (light and dark) and per subtree if ever needed.

  • Presets only construct it. bullseye-shadcn builds a bullseye::Style from shadcn's tokens and parameters (theme colour, light or dark, radius, …). A future Fluent or Material preset would build the same struct from its own parameters, with no change to core. Presets may also offer to write matching egui global visuals, for egui widgets an app draws outside bullseye trees; core doesn't require it.

  • Items 22 and 23 of M4b review follow-ups: preset gaps, accent colour, semantic tokens #18 (slider thumb, toggle look, both scoped to the widget's Ui) are the first instances of this pattern. M4c generalises them into the struct.

Owned versus wrapped widgets (decided: spike first)

Simple controls are mostly paint. bullseye's node system (sense, variants, focus, transitions, inert) already draws that well. Text input is mostly behaviour (IME, selection, clipboard, undo), which egui does well. Planned split:

  • Owned (built from bullseye nodes, styled straight from bullseye::Style, measured by taffy, so no size estimates): button (with variants), toggle/selectable, checkbox, radio, switch, slider, segmented, and the select trigger. After M6, the select's popup list as a bullseye overlay.
  • Wrapped egui, with the scoped Style mapping and size estimates: TextEdit only, plus the select popup until M6.
  • Dropped from the supported set: DragValue. It is an egui-ism with no web or shadcn equivalent, and it can still go in a leaf with the generic mapping. signup_form's Age moves to a text field or slider.
  • Owned widgets set their accessibility role and label themselves (widget_info on the node response) and keep kittest's accessibility check passing. Keyboard: Space/Enter through focus; arrow keys inside a radio group.

Spike before committing to it. Rebuild Button (all variants plus the toggle) and Checkbox as bullseye-owned widgets next to the wrapped versions, and compare:

  • styling fidelity against shadcn (disabled colours, focus ring);
  • accessibility (kittest's check);
  • keyboard behaviour;
  • lines of code.

The user is concerned about bullseye's size, so the spike reports LOC before and after for src/ (code only, without tests, docs or blank lines), per module. If the spike shows owning costs more code than it removes, the split gets revisited.

shadcn's eight styles (decided with the user, 2026-11-08)

shadcn ships eight styles (apps/v4/registry/styles/style-{vega,nova,maia,lyra,mira,luma,rhea,sera}.css). They share the same ~440 component rules and the same colour tokens; colour is a separate choice. They differ in a handful of parameters:

  • a radius scale (rounded-none to rounded-4xl);
  • control height and padding (button h-7 to h-10);
  • text size (xs or sm);
  • font weight (medium; sera uses semibold);
  • focus-ring width (1 to 3 px);
  • shadow level;
  • a few per-component quirks (sera's square switch, pill inputs in maia and luma).

The point, in the user's words: we must be able to handle style changes smoothly at the contract to the bullseye layer. A shadcn style is a parameter set that fills bullseye::Style; changing style is changing data, with no core change and no per-style widget code.

  • In M4c: our current preset is shadcn's vega, which matches what we built from new-york (h-9, rounded-md, 3 px ring, shadow-xs). Name it that. Add lyra (square, compact, xs text, 1 px ring), the most different, as the contract test. Both go through the same bullseye::Style constructor.
  • Every example should switch between vega and lyra with no layout code changes, and the size drift guards (for wrapped TextEdit) pass under both.
  • Post-0.1: the other six styles, by hand or generated by an xtask that reads the CSS (Tw speaks Tailwind; watch for selectors like has-data-[…]).
  • Known blockers for exact fidelity: font weights (Font weights (font-medium / font-semibold) have no faces; headings fall back to Regular #13), negative-spread shadows (Shadows with negative spread (Tailwind shadow-md/-lg/-xl) can't be expressed #12), and focus-ring width on wrapped TextEdit.

Press feedback (found by the user)

shadcn's current styles (vega, nova, maia, lyra, mira, luma, rhea, sera in apps/v4/registry/styles/style-*.css) give buttons active:not-aria-[haspopup]:translate-y-px with transition-all: while pressed, the button shifts down 1 px, easing in and out. Buttons that open a popup are excluded, and nothing scales. new-york-v4, which our tokens came from, doesn't have it. Plan:

  • Add a paint-only translate to Paint (e.g. p.translate_y(1.0)), usable in variants. Like CSS transforms, it moves the node's and its subtree's painting, not its layout or its hit rect, and it animates with transition. Implement it by offsetting the shapes the subtree emits.
  • Owned buttons use active(|p| p.translate_y(1.0)), except buttons marked as opening a popup (select trigger, menu buttons).
  • Tests: the pressed button's shapes are 1 pt lower, layout rects are unchanged, and the press eases in and out with a transition.
  • Also check which shadcn style the preset should track. The site has moved from new-york to these styles, so recheck the token values and radii against the style the user prefers when the preset moves crates.

Size (lines of code)

At M4b head, src/ is 7,660 lines in total, or about 4,700 lines of code without unit tests, comments or blanks. It was 6,252 total at v0.1.0-m4. The largest modules:

Module Lines Notes
style.rs 989 Moves to bullseye-shadcn in M4c
widget.rs + sizing.rs about 1,030 Stock-widget wrapping and size estimates; owning simple widgets should shrink these to TextEdit only
tw/layout.rs 766
draw.rs 757

M4c reports core's LOC before and after in its PR. A cargo xtask loc target (code lines per module, tests and docs excluded) makes this repeatable, and each milestone PR quotes it.

Risks to handle (reviewed with the user)

  1. Popups. ComboBox lists, tooltips and menus open in separate egui Areas and may take the context's global style rather than the opening widget's scoped style. Verify first. If so, either the preset also writes matching global egui visuals, or bullseye styles popup content itself (M6 overlays).
  2. Bounded by egui. Stock widgets are painted from egui's fixed WidgetVisuals slots (five states; fill, weak fill, border, foreground stroke, radius, expansion). Disabled is an opacity multiply, focus exists only on text edits, and checkmark and rail geometry are hard-coded. Each Style field documents whether it is exact or approximated on stock widgets. Where exact control is needed, bullseye draws the widget itself, as with the switch.
  3. egui widgets bullseye doesn't know. Every node Ui gets a generic mapping from Style, so ui.add(..) of an arbitrary egui widget inside a bullseye tree still matches. The preset may optionally write egui's global visuals for egui drawn outside bullseye.
  4. Struct growth. Style is nested per widget (style.button, style.slider.thumb, …) and #[non_exhaustive] with Default, so new fields don't break presets or apps.
  5. Costs. There is a copy-on-write Style clone per widget Ui (check it in the M8 virtual-list benchmark). One Style per context; a scoped per-subtree override can come later if needed.

Plan

  1. Style contract in core. A struct (working name WidgetStyle) kept in the egui context, holding exactly the knobs core widgets read today that egui's Visuals / Spacing don't already cover:

    • input padding, separate from button padding;
    • switch track and thumb colours per state;
    • a per-variant button palette (primary, secondary, destructive, outline, ghost: fill, text, border, hover, active, disabled).

    It must also include anything else found by searching core for preset reads. Core reads only this struct and egui's own style. It has a neutral default derived from egui's visuals, so core works with no preset at all.

  2. New workspace crate bullseye-shadcn. It takes Tokens, Shadcn, Accent, the semantic colours, SegmentedClasses, and the egui Visuals / Spacing mapping. It fills the contract. It depends on bullseye and egui; bullseye doesn't depend on it.

  3. Tests.

    • Core's size drift guards run against the contract, using the default style and a deliberately unusual test style.
    • bullseye-shadcn runs the same guards under light and dark, with an accent.
    • Preset tests move with the preset.
  4. Examples depend on both crates, unchanged in look: goldens must not change, and any that do get explained.

  5. Docs. Core's crate guide documents the contract as the way to theme widgets, and the preset crate documents shadcn usage. The reference shell can provide its own style.

Done when

  • core has no shadcn names or values;
  • every example looks the same as at the M4b tag;
  • cargo xtask ci covers both crates, including the publish-readiness checks the user wants before crates.io.

Activity

  1. samitbasu commented on Nov 8, 2026

    @samitbasu
    OwnerAuthor

    Decided by the user after the spike (#38): the full owned split.

    Delivery in two PRs:

    1. M4c-1, on the m4c-spike branch (M4c-1: bullseye::Style contract, owned widgets, paint translate, selectable text #38):

      • the core bullseye::Style contract, with open variant keys, per-state colours, per-size metrics, caching, and nothing panicking on an unknown key;
      • the paint translate and press feedback;
      • all owned widgets, plus label association / group focus;
      • selectable text;
      • removing the wrapped paths and the estimate engine, except for TextEdit;
      • examples migrated.

      The shadcn preset stays in core temporarily, filling the contract.

    2. M4c-2:

      • the bullseye-shadcn crate (preset, Accent renamed to ThemeColor, vega and lyra);
      • the TextEdit scoped mapping;
      • the popup-style check (risk 1);
      • the vega/lyra switch in the examples.
  2. samitbasu commented on Nov 14, 2026

    @samitbasu
    OwnerAuthor

    Done in #38 (Style contract, owned widgets, translate) and #45 (eggshell-ui-shadcn with Vega and Lyra). The other six styles are tracked in #26.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions