Skip to content
  1. Docs
  2. enzUI framework
  3. Developers

Colored controls

How a coloured fill chooses readable text and icon ink, and which controls use that rule.

An opaque coloured control, such as an accent button or a selected checkbox, needs a foreground that reads on its fill. enzUI resolves the two together with Palette::filled_color. The returned pair holds the background in color and the foreground in text, and the fill is made opaque (its alpha replaced with 1.0).

Which ink, and why never black on blue

The polarity comes from APCA, the perceptual contrast model planned for WCAG 3, not from the WCAG 2 ratio. WCAG 2 overrates black on saturated mid tones: on the #3584e4 accent it scores black 5.4:1 and white 3.9:1, so "highest ratio wins" would put black labels on blue buttons, which reads worse and looks broken. APCA and the major design systems (GNOME, Apple, Material, Fluent) put white on those blues.

The resolver then does one of two things:

  • White, on a deepened fill. When white reads better, the label is white and the fill is deepened until white reaches 4.5:1 (4.8:1 on a dark palette, as headroom against channel rounding). Deepening lowers OkLab lightness and keeps the hue, so a blue stays blue instead of greying the way mixing toward black does.
  • A tinted dark ink, on the kept fill. A fill too light for white (yellow, amber, a pale custom colour) keeps its colour and takes a near-black in its own hue at 4.5:1 or better, never pure black.

Palette::ink_on applies the same rule to a fill that cannot change (raw roles, authored colours): white where it reads best and reaches at least 3:1, otherwise the tinted dark ink. The on_* helpers use it on the raw roles, and enzui_widgets::tokens::ink_for uses it for everything drawn on a filled surface, keeping the palette's own text colour on neutral surfaces.

The raw accent and status roles stay unchanged for links, outlines, indicators and charts.

Custom filled controls

Paint both members of the returned pair together:

rust
let pair = palette.filled_color(palette.accent);
// draw the fill with pair.color and the label and icon with pair.text

If you change the fill afterwards, including its opacity, check contrast again against the background actually painted.

Default consumers

These apply to enabled controls on opaque surfaces. Explicit token overrides stay under the caller's control, and disabled controls can dim their colours.

ConsumersResolution
Accent, Success and Destructive buttons, with their iconsPaired fills and foregrounds at rest, hover and pressed
Pill tabs and view switchers with TabSelectionStyle::FilledAccentPaired accent selection; dark pills add an accent edge
Inline segmented switchers with filled accent selectionSelection adjusted for contrast against the track, ink resolved from that selection
Strong accent badges and avatar initialsPaired opaque accent
User chat bubblesPaired opaque accent
Checked checkboxes and selected radio buttonsPaired accent and tick or dot
Calendar selected dates, including a selected todayPaired accent and pressed accent
Schedule today marker, timed events and all-day chipsPaired danger or event colour
Active text-search highlightsResolved accent fill with separately resolved glyph ink

Segmented controls use the page background for their dark track and surface_alt for their light track. Their selected accent fill targets 3:1 against the track, then chooses readable ink for the result, so the 4.8:1 white-ink rule of filled_color does not apply to them.

Other treatments

  • Switches and toggles use a light thumb in both modes, and their track adjusts the accent to 3:1 against the thumb (the non-text contrast floor) instead of using filled_color.
  • Glass accent buttons use translucent fills, and tab selections using TranslucentAccent or NeutralMaterial follow their own material policies.
  • Soft status badges, neutral controls, translucent annotations and colour-picker samples keep their own semantics. A colour sample represents authored content and is never converted into a control fill.

Under the desktop's high-contrast setting every palette becomes Palette::high_contrast(), where the accent, state colours and focus ring reach 7:1 against the page. See Styling and tokens.