Guinevere's Controls Are Now Styled by Stylesheets

2026-10-09 · 5 min read

Until now, Guinevere's Excalibur controls drew themselves by hand. Colors came from a 24-entry ControlPalette, and sizes, radii, focus rings and borders were literals inside each control. A stylesheet engine already existed, but the controls didn't read it. With issue #160 that changes: every control, from buttons to the file dialog, resolves its look from .pss stylesheets.

The design follows PanGui's immediate-mode styling. A look is a matter of taste, and taste has no stable ground truth, so instead of shipping colors in code, Guinevere ships a complete, themable set of controls and a documented style contract per control: anyone can restyle the built-ins, or compose their own from the same primitives and keep the last bit of drawing performance for themselves.

What you get in practice: a re-theme is a file, a light/dark switch is two sheets, and a panel can carry its own colors in a subtree without a single control having been written for it.

One default sheet, many themes

Excalibur embeds guinevere.default.pss and keeps it under every application sheet. Sheets layer; the winner is the layer closest to the node:

  1. the default sheet, as the floor;
  2. a theme, which is really just a token sheet;
  3. an application sheet;
  4. a token set on a subtree, for everything inside that node for that frame.

A color theme needs nothing but $token = value; declarations layered above the default:

ExcaliburStyles.SetTheme(gui, ExcaliburStyles.Light);  // also MonoLight, MonoDark, or any token sheet of your own
var ink  = ExcaliburStyles.TokenColor(gui, "text");    // theme colors for your own drawing

The default look is now dark. ExcaliburStyles.Light, MonoLight and MonoDark ship alongside it, and all four are plain files you can read, fork and hand-edit before committing to anything.

Classes instead of color parameters

Controls no longer take color or radius arguments. They take classes and id, and the sheet decides. The same control is a different button depending on where the rule that matches it lives:

gui.StyleSheets.Add(StyleSheet.Parse("""
    $accent = #88c0d0;
    button.danger { background-color = #dc3545; color = #ffffff; :hover { background-color = #c82131; } }
    """));

if (gui.Button("Delete", classes: ["danger"])) Delete();

using (gui.Node().Enter())
{
    gui.SetStyleToken("surface", Color.FromArgb(255, 40, 44, 52)); // this subtree only
    gui.Button("Dark");
}

Tokens inherit down the node tree, so the fourth layer above re-themes everything inside it, including child controls, without any control having a Color parameter to begin with. Layout geometry stays in code; styling is what moved into sheets.

Style contracts

Every control publishes a contract: its element name, the classes it adds, the states it sets (:hover, :focus, :disabled, :checked, :open, :selected, …) and the properties it reads. Themes are therefore authorable against a published list instead of by reading control source. Drawn parts are addressable through > selectors, so a slider's thumb or a checkbox's indicator has an element name like anything else:

slider.volume > thumb { width = 18; height = 18; border-radius = 50%; }
slider.volume:focus > thumb { outline = 2px solid $accent; outline-offset = 3; }
progress.download > fill { background = linear-gradient(to right, #5081d9, #88c0d0); }

The full table lives in the Excalibur README; the default sheet is the normative list, since it styles every control through that contract.

Borders follow CSS

A border used to be stroked on the box edge, so half of it fell outside the node and blurred across two pixels. Borders now lie inside the box, matching CSS, and per-side borders (border-top-width, …) are honored. Screens where a node's border was swallowed by an adjacent sibling look right without layout changes.

Cost

Styled controls stay within budget of hand-drawn ones. In the benchmark suite, the styled/hard-coded loop ratio is 1.00×, and resolving a cached style costs about 50 ns with no allocation. Retiring the palette also shrank per-node scope storage: a fixed-frame probe measures about 210 fewer bytes per node than before (2,304 → 2,094).

Two honest edges: those figures are from the benchmark fixtures, not a guarantee for an arbitrary screen, and uncached first resolves on a fresh sheet cost more than the cached steady state.

Migrating

This is a breaking release; every row has a mechanical replacement.

Before After
default (light) look ExcaliburStyles.SetTheme(gui, ExcaliburStyles.Light); the default is now dark
ControlPalette = ControlPalette.Dark nothing: dark is the default
a custom new ControlPalette { Surface = … } a sheet of $surface = …; tokens passed to SetTheme, or gui.StyleSheets.SetToken("surface", …)
gui.ControlPalette.Text, gui.ControlStyle.Text ExcaliburStyles.TokenColor(gui, "text")
a subtree color override through ControlStyles.Value<…> gui.SetStyleToken("accent", c)
gui.ApplyControlPalette() with a control-palette { … } rule top-level $token = value; declarations in a sheet
color or radius arguments on a control classes: or id: plus a sheet rule

Token names are the old palette property names in kebab case (SurfaceHover → surface-hover). Control dimensions (gui.ControlStyle sizes and spacing) are unchanged. Excalibur now depends on the MASS4.Guinevere.Styling package.

What's next

This is one step in a larger theming effort: animated state transitions, a font registry, a color picker built from composable parts, and following the operating system's light/dark preference. Together they let an application ship and switch complete themes as plain files, including our own studio.

#guinevere#dotnet#csharp