Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Design tokens

egui-pop’s look comes from design tokens: named, typed values in YAML files (JSON is read too) in the format of the W3C Design Tokens Community Group (DTCG 2025.10). No widget hard-codes a colour or a size; it reads a token.

The files live in crates/egui-pop-tokens/themes. egui-pop-tokens reads and resolves them (it has no egui dependency); egui_pop::theme turns the result into egui’s style.

The format, as read here

$description: "A theme"
$extends: "pop-dark"
gray:
  $type: "color"
  "2":
    $value: {colorSpace: "oklch", components: [0.215, 0.006, 75], hex: "#1b1916"}
surface:
  $type: "color"
  panel:
    $value: "{gray.2}"
    $description: "Panels and side bars."
radius:
  widget: {$type: "dimension", $value: {value: 4, unit: "px"}}
  • A token is an object with $value; anything else not starting with $ is a group. A token’s name is its dotted path (surface.panel).
  • $type is given on the token or inherited from an enclosing group, or taken from the token an alias points to.
  • An alias is a whole value of the form "{path}". Aliases chain; a cycle or a reference to nothing is reported, never followed forever.
  • $description and $extensions are kept (tools may store their own data under $extensions, keyed by a reverse domain name).
  • At the root, $extends names the theme a file builds on: every token not given comes from it, and chains of $extends are followed.
  • Types read: color (colour objects in srgb, srgb-linear, oklch or oklab, other colour spaces through their hex fallback, and #rrggbb/#rrggbbaa strings), dimension (px, or rem at 16 px), number, duration (ms or s) and fontFamily. Other types are kept as raw JSON.

Not read yet: references inside composite values, JSON Pointer $ref, $deprecated, group-level $extends.

A colour at another opacity

DTCG has no way to say “this colour, translucent”. egui-pop reads one modifier, in the spirit of Tokens Studio’s modify, kept under $extensions so the file stays plain DTCG (another tool reads the alias and ignores the modifier):

pill:
  rest:
    fill:
      $type: "color"
      $value: "{surface.overlay}"
      # the overlay at 85 %: its alpha multiplied by 0.85
      $extensions: {org.egui-pop.alpha: 0.85}

org.egui-pop.alpha (egui_pop_tokens::ALPHA_EXTENSION) is a number from 0 to 1 the colour’s alpha is multiplied by, once its alias is followed. A token aliasing a modified token gets the modified colour, and its own modifier multiplies again. A value outside 0 to 1, or a modifier on a token that is not a colour, is a reported problem, and the token is treated as broken. The modifier belongs to the value it is written with: a theme giving the token again, an override and the theme editor’s export replace both, and to_dtcg writes the resulting colour without it.

Three tiers

  1. Reference: the palette, named by what a value is. Each base theme has a warm neutral scale gray.0 to gray.12 and five hue scales, gold, amber, red, green and blue, steps 1 to 12 plus contrast (the text colour that reads on step 9). Scale steps mean the same in every mode:

    StepsUse
    gray 0 to 2the deepest backgrounds (in light mode, white paper)
    3 to 5subtle fills (hue scales: quiet accent backgrounds, selection)
    6 to 7borders
    8a solid fill being pressed
    9the solid fill (the accent)
    10the solid fill under the pointer
    11low-contrast text (status colours)
    12high-contrast text

    The light theme redefines the scales (light backgrounds, dark text) and keeps the same step meanings, so the system tier mostly aliases the same steps in both modes.

    A theme may add hue scales of its own with the same steps (1 to 12 and contrast): any such scale is offered as an accent (Themes::accents). The Catppuccin-inspired themes add purple (Catppuccin’s mauve) and use it as their accent.

  2. System: roles, what a value is for. These are the tokens widgets read, listed in contract(): surface.{canvas, panel, raised, hover, active, overlay, sunken}, text.{default, muted, strong, on-accent}, border.{default, strong}, accent.{default, hover, active, subtle}, danger, warning, success, info, focus.ring, selection, palette.category.0 to palette.category.9 (the categorical palette, below), palette.log.{trace, debug, info, warn, error, critical} (the log levels’ colours, below), palette.axis.{x, y, z} (the axes’ colours, below), radius.{widget, window}, shadow.{popup, window, side}.{offset-x, offset-y, blur, spread, color} (egui’s popup and window shadows, and a side area lying over the centre; their colours alias the shade.10 and shade.38 palette tokens, black at 10 % and 38 %), space.{xs, s, m, l, xl} (the spacing scale), space.{inline, group, section, page} (spacing by intent, below), text-role.{title, section, body, muted, meta}.{size, color, weight} (text by role, below), size.control.height, size.row.height (a row of a list, a tree or a property panel; an alias of the control height unless a theme gives it a value of its own), size.icon.{inline, toolbar, panel}, size.dialog.width, size.magnet, size.toast.width, font.size.{xs, s, m, l, xl} (the size scale) and font.text-style.{small, body, button, heading, monospace} (egui’s text styles, each an alias of a step), font.family.{ui, mono}, font.baseline-offset.{ui, mono} (where a family’s glyphs sit in their row, a share of the size; 0 by default, Fonts), font.numeric ("mono" or "ui": how values line their digits up, Fonts), motion.duration, motion.spinner.{delay, min, turn} (300 ms before a busy indicator shows, 500 ms at least once shown, a spinner’s turn), motion.progress.travel, motion.skeleton.shimmer, motion.toast.slide (a toast sliding in and out; none under reduced motion), motion.submenu.delay (200 ms of the pointer resting on a submenu item before its submenu opens), opacity.scrim.

  3. Component: one component’s tokens, each an alias of a system token (or, for a component based on another, of its base’s token under the same term: kit.md). The kit’s components are component.state.term (kit.md): button.* (with tones), card.* (an application’s card, by tone), the sliders’ (slider.*, slider-fill.*…), field.* (input fields, their states as tones: read-only and the placeholder muted, modified accent, required warning, invalid danger, pending info), the bars, rings, meters and spinners (progress-bar.*, progress-fill.*, progress-ring.*, spinner.*…), indicator-dot.*, indicator-badge.*, indicator-flag.*, indicator-swatch.*, indicator-outline.* and indicator-button.* (micro-indicators, see indicators), skeleton.* and skeleton-shimmer.*, dialog.*, palette-window.*, toast.*, scroll-bar.* (every scroll area’s bars: width, width-rest, opacity-rest, room, min-length, margin, margin-track, placement, visibility, track-fill, the thumb’s rest, hover and active fill and its radius; kit.md). Content drawn in code keeps flat names: editor.* and syntax.* (one colour per kind of code: keywords on the accent, strings on success, numbers on warning, comments muted…), terminal.* (its text, cursor, selection, links, and terminal.ansi.0 to terminal.ansi.15, the 16 colours programs ask for by number: 0 is the colour furthest from the text, 7 the text’s own, 1 to 6 the status roles and the accent, 8 to 15 their stronger forms). A theme may re-alias a component token (high contrast outlines every button and field: button.rest.border-color and field.rest.border-color are {border.strong}). A component’s text size aliases a step of the size scale ("{font.size.l}"), never a number of its own.

Spacing and text by intent

Layout code says why there is space, or what a piece of text is, rather than how many points: the tokens below are system roles over the scales, read through Tokens (t.space.group, t.text_role.section) or the UiPop helpers (Getting started).

TokenAlias ofUse
space.inline{space.s}between items on one line
space.group{space.m}between related groups of items
space.section{space.l}before a section of a panel or a page
space.page{space.xl}around a page’s content, between its main blocks

They are aliases, so a density overlay, which moves the steps, moves them too; a theme may re-alias one onto another step.

A text role is three tokens, text-role.<role>.size (a step of the size scale), .color (a text colour) and .weight (a number, 100 to 900; 400 is regular). The role names say what the text is; the colours stay text.*, which the roles alias, so text.muted is still the one muted colour:

RoleSizeColourWeightUse
title{font.size.xl}{text.strong}600a page’s or a dialog’s title
section{font.size.m}{text.strong}600a section’s title in a panel
body{font.size.m}{text.default}400ordinary text
muted{font.size.m}{text.muted}400hints, descriptions, an empty list’s message
meta{font.size.xs}{text.muted}400a date, a size, a count

A weight other than 400 is drawn with the theme’s interface font at that weight (fonts::family), once a theme has installed the fonts; egui’s bundled font has one weight, which draws them all. The role colours are in the contrast pairs, over panels and the raised surface.

Beside the roles, three helpers of UiPop (experimental) read the same tokens for what is not a role of its own:

  • ui.code_text(text): monospace text (a log or console line, a path) in egui’s monospace style (font.text-style.monospace, font.family.mono) and the body’s colour (text-role.body.color).
  • ui.text_tone(tone, text): the body role in a tone’s colour (egui_pop_core::ui::tone_color): danger, warning, success and info the status colours, accent the accent, muted the muted role’s colour, neutral the body’s. Colour is not the only signal: the words say it too (“Failed: …”).
  • ui.divider(): a rule across the layout between two sections, in border.default, one point wide on whole pixels, centred in a space of space.group; upright in a row.

The categorical palette

Charts and data views colour what they tell apart by identity (an entity, a sensor, a run) with palette.category.0 to palette.category.9, in that order: the first series takes slot 0, the second slot 1. A series keeps its slot whatever else is shown, so its colour follows it from one view to the next. Code reads them through Tokens::of(ctx).palette (DataPalette::series(i), which starts again from slot 0 past the last); the plot component uses them (Charts). More series than slots repeat colours: name them (a legend) or group the smallest.

The slots alias a reference group named by hue, chart.blue, chart.orange, chart.green, chart.pink, chart.olive, chart.periwinkle, chart.lime, chart.red, chart.teal and chart.purple, which each base theme gives for its surfaces; a theme changes a hue there, or re-aliases a slot.

Slotpop-darkpop-lightpop-high-contrast
0#0aa5f8#014d74#15b3fe
1#f69408#b66402#ff942f
2#0dbd86#026a52#01c996
3#ff9fea#a447a5#feb5f9
4#958801#564700#c1b007
5#a2b1ff#4157c3#a9bdff
6#a1df60#3f8304#bae962
7#dd556e#d34d6a#fe8b9e
8#0398a7#078997#17f9fe
9#a477eb#672b98#cc8ffe

Two checks hold them, in every built-in theme (the editor-inspired ones take their base’s hues):

  • Contrast. Each slot reads at 3:1 (WCAG 1.4.11, a graphical object) on surface.canvas, surface.panel and surface.raised: pairs of contrast::PAIRS, so contrast::check and the overview page show them. The high-contrast hues reach 4.5:1 on black.
  • Separation (contrast::check_category), measured as ΔE OK, the Euclidean distance in OKLab times 100 (contrast::delta_e): two neighbouring slots at 15 at least (CATEGORY_ADJACENT), any two at 10 (CATEGORY_ANY), and neighbours at 8 for people with protanopia or deuteranopia (CATEGORY_CVD_ADJACENT; Vision::simulate, Machado, Oliveira and Fernandes’ model at full severity). Each slot is a hue, not a grey (OKLCH chroma 0.08 at least).

Ten hues cannot all stay apart for colour-blind readers: any two slots are not checked for them, only neighbours, so the first series of a chart are the ones to tell apart, and a legend names them all. The built-in hues were searched for together under these checks (the same hue per slot in the three themes, the lightness moved for each theme’s surfaces) and reach 11.9 for any two, 20.9 for neighbours and 9.0 for neighbours with colour blindness.

Log levels

A log view colours a line’s level, or the whole line, with palette.log.trace, palette.log.debug, palette.log.info, palette.log.warn, palette.log.error and palette.log.critical: the five levels of the log facade and a sixth past error, the critical level some loggers add (Python’s logging, Rerun’s text log), from the least to the most severe (egui_pop_tokens::LOG_LEVELS, in that order). Code reads them through Tokens::of(ctx).palette.log (LogPalette, whose levels() gives them in the same order).

pop-dark aliases them to the status colours and the muted text, so the other built-in themes follow their own: trace is {text.muted}, debug {info}, info {success}, warn {warning}, error {danger} and critical {red.12}, danger’s red at its scale’s high-contrast text step (danger is step 11): lighter than danger in a dark theme, darker in a light one. Info is green and debug blue, as most log viewers draw them. A theme gives a level a value of its own where its status colour does not read on its canvas (gruvbox-light darkens info’s green).

Levelpop-darkpop-lightpop-high-contrast
trace#b3b1ad#5d5a57#e0ddda
debug#9ac7ff#2a5993#9ac7ff
info#9dd59e#2a672f#9dd59e
warn#f8b376#884300#f8b376
error#ffa696#953226#ffa696
critical#ffdfd7#4d1c16#ffdfd7

Each level is used as text: it reads at 4.5:1 (7:1 in high contrast) on surface.canvas and surface.panel, pairs of contrast::PAIRS checked like the status colours.

Axes

A view’s X, Y and Z axes (a gizmo, an axis line, a transform’s arrows) take palette.axis.x, palette.axis.y and palette.axis.z: red, green and blue, as most 3D and image tools draw them. Code reads them through Tokens::of(ctx).palette.axis (AxisPalette). pop-dark aliases them to the categorical palette’s hues, {chart.red}, {chart.green} and {chart.blue}, which each built-in theme fits to its surfaces. Each is a graphical object: it must be seen at 3:1 on viewport.background, pairs of contrast::PAIRS.

A scale from one colour

A hue scale (steps 1 to 12 and contrast) can be generated from a seed colour rather than written by hand: egui_pop_tokens::palette::ramp(seed, Scheme::Light) gives its twelve steps for a light theme, Scheme::Dark for a dark one, from the same seed; palette::Ramp adds contrast and writes the scale as tokens (Ramp::tokens("brick"): brick.1 to brick.12, brick.contrast).

use egui_pop_tokens::palette::{Ramp, Scheme};
use egui_pop_tokens::{Color, contrast};

let seed = Color::from_hex("#c0392b").unwrap();
let light = Ramp::new(seed, Scheme::Light);
// The text on the solid step reads, and so does the solid on the
// backgrounds (an accent is drawn as text on panels too).
assert!(contrast::contrast_ratio(light.contrast, light.steps[8]) >= 4.5);
assert!(contrast::contrast_ratio(light.steps[8], light.steps[0]) >= 4.5);

How it is made (in OkHsl, so no step leaves the sRGB gamut):

StepsLightnessSaturation (times the seed’s)
1 to 7fixed targets, from pop-light and pop-dark’s scales0.45 to 0.8 in light, 0.3 to 0.7 in dark
9the seed’s, moved away from the text until it readsthe seed’s
8, 10step 9’s, pressed and under the pointer0.9 to 1
11, 12low- and high-contrast text0.95 and 0.7 in light, 0.9 and 0.5 in dark
  • The solid step is the seed when the text on it reads: APCA’s Lc 60 at least (apca::lc, informative elsewhere: the contrast pairs stay on WCAG 2.x) and WCAG 5:1. Otherwise its lightness moves, darker in light (white text), lighter in dark (nearly black text), its hue and saturation kept. contrast is the text APCA ranks higher on it.
  • Saturation is limited per hue band in large areas: greens and cyans (OkHsl hue 125 to 200) turn neon, yellows (85 to 115) muddy.
  • Hue shifts a few degrees with lightness: lighter warm steps lean to yellow, lighter cool steps to cyan.
  • A seed nearly black or white has no hue to speak of: palette::clamp_seed brings its lightness within 0.25 to 0.92 (and its saturation within its band), and ramp applies it first. A grey seed gives a neutral ramp.

An accent from a seed. ThemeSpec::new("pop-light").accent_color(seed) (or .accent("#c0392b")) generates the accent’s scale when the theme is resolved, as the custom scale (SEED_SCALE), for the base theme’s scheme; a counterpart gets the other scheme’s ramp from the same seed. The ramp is then fitted to the theme (Ramp::fitted, a Backdrop): step 9 also reads as text on the theme’s surfaces and its editor (4.6:1) and is seen on the slider and progress tracks (3:1), and steps 3 to 5 keep the theme’s text readable on them (the selection). A test checks seeds round the hue circle in every built-in theme against the contrast pairs at AA.

A scale saved as its seed. A token file may give a scale by its seed rather than as twelve values, in its root $extensions (palette::SEEDS_EXTENSION):

{
  "$extends": "pop-light",
  "$extensions": { "org.egui-pop.seeds": {
    "blue": { "seed": "#8e44ad", "scheme": "light" }
  } }
}

When the theme is resolved, the scale is generated from the seed (Ramp::fitted), for the scheme given (light or dark; without one, the theme’s, from surface.panel), fitted to the theme’s surfaces and text as the file and the themes it extends give them (the scale’s own tokens left out, so a scale never fits itself). A scale its base already has gets the steps the base has (gray has no contrast); a new scale gets its twelve steps and contrast. Then the file’s own tokens are laid over it: a step the file also gives keeps the file’s value. A file with the twelve values written out, and no seed, works as before. An entry that cannot be read is a warning (Warning::Invalid), and the scale keeps the values under it. The theme editor’s “palette from a colour” writes the seed (The theme editor).

The approach follows egui_colors (MIT), which builds 12-step Radix-like scales in OkHsl with APCA; egui-pop’s generator is a re-derivation with the targets above, not its code, and its tests check every hue in both schemes against the contrast targets.

Naming rules

  • Name by role, never by hue, outside the reference tier: text.muted, not text.gray; danger, not red.
  • Path segments are lowercase, words joined by hyphens: background-hover, on-accent. Dots separate groups, so a segment never contains ., { or }.
  • States are suffixes of the thing they modify (button.hover.fill, the kit’s grid: docs/kit.md), sizes are xs, s, m, l, xl.
  • A component token points at a system token, a system token at the palette or another role, never the other way round (a test checks it).

The editor-inspired themes

Twelve built-in themes take their colours from popular, permissively licensed editor themes (their workbench colours, not syntax): five families with a light and a dark member, and GitHub’s high-contrast pair. Each extends pop-light, pop-dark or pop-high-contrast and gives its palette and the roles that differ; where an original colour missed a contrast pair, only its OKLCH lightness was moved. Ids keep the family names; the labels shown to people say “inspired” (theme_label). Sources and licences are in NOTICE.

idlabelextends
github-light, github-darkGitHub-inspired Light, Darkpop-light, pop-dark
github-light-high-contrast, github-dark-high-contrastGitHub-inspired Light, Dark High Contrastpop-light, pop-high-contrast (7:1 text)
catppuccin-latte, catppuccin-mochaCatppuccin-inspired Latte, Mochapop-light, pop-dark (+ purple)
one-light, one-dark-proOne Light-, One Dark Pro-inspiredpop-light, pop-dark
solarized-light, solarized-darkSolarized-inspired Light, Darkpop-light, pop-dark
gruvbox-light, gruvbox-darkGruvbox-inspired Light, Darkpop-light, pop-dark

the editor-inspired themes

Each one at full size: the built-in themes.

Composing a theme

The three base themes, pop-dark, pop-light and pop-high-contrast, are shown at full size with the others in the built-in themes (captured headless; see CONTRIBUTING.md to regenerate).

The compact density changes spacing and sizes only:

A theme is resolved from a ThemeSpec, in this order:

  1. the base theme (mode and contrast: pop-dark, pop-light, pop-high-contrast) with everything it $extends;
  2. a density overlay, density-comfortable or density-compact, which touches space.* and size.* only (a test checks it);
  3. an accent: a colour scale whose steps become accent.default (9), accent.hover (10), accent.active (8), accent.subtle (3), selection (5) and text.on-accent (contrast); anything aliasing the accent (focus.ring, slider-fill.rest.fill) follows. The accent may also be a seed colour ("#3a7bd5", ThemeSpec::accent_color): its scale is generated as custom.1 to custom.12 and custom.contrast (below), for the theme’s light or dark scheme;
  4. reduced motion: motion.duration becomes 0 (egui’s animation time, cursor blink and scroll animation follow);
  5. components based on another (<component>.based-on) receive each token of their base they do not give, as an alias of it (kit.md);
  6. the user’s overrides, raw values by path (aliases allowed); an override of a base reaches the components based on it;
  7. the user’s fonts, text size and scroll bars (ThemeSpec::font_ui, text_size, scroll_bars): the last writes scroll-bar.visibility and placement (kit.md).
use egui_pop::tokens::{Density, ThemeSpec, Themes};
use serde_json::json;

let spec = ThemeSpec::new("pop-light")
    .density(Density::Compact)
    .accent("blue")
    .reduced_motion(true)
    .override_token("radius.widget", json!({ "value": 2, "unit": "px" }));
let tokens = Themes::default().resolve(&spec);

Resolving never panics. Problems (an unknown theme, an $extends cycle, an alias cycle, an unknown alias, a wrong type, an unreadable value, a modifier that cannot apply, a missing contract token, an unknown override or accent, a component based on an unknown one or components based on each other in a circle) are listed in tokens.problems(), and every contract token with a problem takes the built-in pop-dark value.

Contrast

egui_pop_tokens::contrast lists, by hand, the token pairs that must stay legible (PAIRS): text over every surface it is drawn on, status colours used as text, labels on accent fills, component text, and the things that must be seen (strong borders, the focus ring, slider fill and thumb on the track). The tests check every built-in theme in every density against WCAG 2.x: 4.5:1 for text, 3:1 for interface parts, 7:1 for text in high contrast; and every accent in every theme at 4.5:1 and 3:1. Decorative borders (border.default) are not checked. A pair drawn over an image (OVER_IMAGES: a label’s text on its translucent fill) is checked with its background painted over black and over white, the poorer ratio counting. The gallery’s overview page shows the same table live.

YAML or JSON

A token file is the DTCG tree, written in YAML (.tokens.yaml, the shipped files) or in JSON (.tokens.json): TokenFile::parse reads JSON when the text starts with {, YAML otherwise, into the same tree. The shipped files are compiled to JSON when egui-pop is built (egui-pop-tokens/build.rs): reading YAML costs about seven times JSON’s, and the built-in themes load at every start (24 ms in YAML, 3 ms in JSON, release build). A trap below in a shipped file fails the build, with its file and line. Files known only at run time, a user’s kits and themes (KitData::load, Themes::add_path), are compiled into a cache folder instead, never next to their YAML: see the cache of compiled files. Themes::add_path runs the loading rule below on what it reads, so a theme’s warnings are the same on a hit. YAML is there for comments. JSON stays the exchange format: what egui-pop writes (the theme editor’s export, to_dtcg) is DTCG JSON, which other token tools read.

In YAML, every string is quoted, colours and aliases first. Left bare, YAML reads them as something else, and a parser would take them silently, so egui-pop refuses them, with the line:

WrittenYAML readsWrite
$value: #0a0a0aa comment: the value is lost$value: "#0a0a0a"
$value: {surface.panel}a map with one key$value: "{surface.panel}"

(The same rule as every YAML colour format, Asciidoctor’s themes or DESIGN.md’s tokens among them.) Numbers stay bare ($value: {value: 1, unit: "px"}), and DTCG’s colour objects need no quotes but their strings’:

accent:
  default:
    $type: "color"
    # gold, kept in OKLCH so the light theme can derive its shades
    $value: {colorSpace: "oklch", components: [0.832, 0.126, 83], hex: "#f0c060"}

A colour is "#rgb", "#rrggbb", "#rrggbbaa", or a DTCG object (colorSpace srgb, srgb-linear, oklch or oklab; another space is read from its hex fallback).

A file’s version

A token file may say which format and which contract it was written for, with a stamp in the root’s $extensions:

{
  "$extends": "pop-light",
  "$extensions": { "org.egui-pop.format": { "version": 1, "contract": 1 } }
}
  • version is the file format’s (FORMAT_VERSION): how a file is laid out, apart from which tokens it gives.
  • contract is the contract’s (CONTRACT_VERSION): which tokens exist, under which names. It is a number of its own, not a crate’s version: it starts at 1 and goes up by one in a release that renames or removes a token of the contract. Adding a token does not raise it, since an older file still loads.
  • A file without a stamp is read as current, so a file written by hand needs none. The theme editor’s export writes it (TokenFile::stamp, FormatStamp::CURRENT).
  • One stamp per file: each file a theme is made of says what it was written for, whoever wrote it, and a file keeps its meaning when it travels alone.

A file stamped with a newer format or contract than this egui-pop knows loads all the same, best-effort, with a warning saying so.

One loading rule. A theme file loads over its base theme (its $extends, else pop-dark) the same way wherever it comes from: Themes::add_text (an application’s own themes, a user’s), the theme editor’s import (ThemeDraft::import), and Themes::check_file for a file already parsed. Only a file that cannot be read at all (not JSON or YAML, not a tree of tokens) is an error. Past that, nothing fails: each of these is a Warning, with the token’s path and why.

  • A token whose value does not load (an unreadable value, an alias to nothing or in a cycle, another type than the base’s or the contract’s) is left out: the base theme’s value stays.
  • A token the base does not have is kept as the file’s own (a palette scale, an extension’s component); under a group of the contract (surface, button) with a term no token of the base uses, it is reported as a likely typo. The theme editor, which changes its base’s tokens only, leaves it out.
  • A token renamed since the file’s contract is read under its new name.
  • A file stamped newer than this egui-pop is read best-effort.
  • A base not known yet (themes added in another order) leaves the tokens unchecked; resolving the theme reports what is wrong.

Themes::add takes a parsed file as it is, past this rule.

Renames. A release renaming a token raises CONTRACT_VERSION and adds an entry to egui_pop_tokens::RENAMED: the former name, the new one, the contract that dropped the former name, and the release of egui-pop-tokens that renamed it (since: "0.3"). A file stamped with an older contract has each former name read under its new one (aliases naming it too), with a warning: “renamed, update your file” (TokenFile::upgrade). The table is empty while the contract is at its first version.

How long a rename is read. Two minor releases after the one renaming it (RENAME_WINDOW): a token renamed in 0.N is still read under its former name, with the warning, in 0.N, 0.N+1 and 0.N+2; its entry is dropped in 0.N+3, after which the former name loads as a token the base theme does not have (kept as the file’s own, or left out by the theme editor, with a warning). A major release counts as one more minor release. A test (no_rename_entry_outlives_its_window) compares each entry’s since with the crate’s version and fails once an entry is past its window, so the release raising the version drops it.

A light and dark pair in one file

A pair whose two variants were edited apart (the theme editor’s) is saved as one file: the token file of the theme named first, carrying its counterpart’s in its root $extensions under "org.egui-pop.counterpart" (COUNTERPART_EXTENSION), with the name it goes by. Each names the other (org.egui-pop.variant-of), and the counterpart is an ordinary token file with its own stamp (one stamp per file, see above): the format version stays 1, since a reader not knowing the key still loads the file’s own variant.

{
  "$extends": "pop-dark",
  "$extensions": {
    "org.egui-pop.format": { "version": 1, "contract": 1 },
    "org.egui-pop.variant-of": "ocean-light",
    "org.egui-pop.counterpart": {
      "name": "ocean-light",
      "file": {
        "$extends": "pop-light",
        "$extensions": {
          "org.egui-pop.format": { "version": 1, "contract": 1 },
          "org.egui-pop.variant-of": "ocean"
        },
        "accent": { "default": { "$type": "color", "$value": "#2060c0" } }
      }
    }
  },
  "accent": { "default": { "$type": "color", "$value": "#40a0ff" } }
}

Themes::add_text and Themes::add_path add both, the counterpart under its name through the same loading rule; one that cannot be read is a warning, and the file’s own variant is added alone. The file travels in a package like any other (below).

A theme with its fonts

A theme naming font files of its own (a user’s, added in the theme editor) travels as a package: a folder, or a .zip archive of the same files, holding the token file and the faces by relative path (egui_pop_tokens::package).

my-theme/
  my-theme.tokens.json
  fonts/Inter-Regular.ttf

The token file lists its faces in its root $extensions, with the family a theme names each by and its weight:

{
  "$extends": "pop-dark",
  "$extensions": { "org.egui-pop.fonts": [
    { "file": "fonts/Inter-Regular.ttf", "family": "Inter", "weight": 400 }
  ] },
  "font": { "family": { "ui": { "$type": "fontFamily", "$value": ["Inter", "sans-serif"] } } }
}
  • ThemePackage::read(path) takes the folder, the archive or the lone token file (its faces then looked for beside it by the same paths). In a folder or an archive, the token file is the one at the top ending in .tokens.json, .tokens.yaml or .tokens.yml (the first by name; another is a warning); an archive of the folder itself, its files under one top folder, reads too.
  • Only a package without a readable token file is an error. A face missing, not a TrueType or OpenType file, or with a path leaving the package is left out with a Warning::Font, and the families naming it fall back. An archive holding more than 256 MiB once unpacked is refused.
  • ThemePackage::write(path) writes what a user chose: a .zip path is an archive; otherwise a theme without faces is the lone token file, and one with faces a folder named after the theme beside the path. write_dir and to_zip write one or the other.
  • Archives need egui-pop-tokens’ zip feature (theme-zip in egui-pop, on by default): zip (MIT), deflate only, through the flate2 that egui’s image decoding already uses. Without it, a folder or a lone file still reads and writes, and an archive is an error.

The theme editor saves and opens themes this way (The theme editor).

Adding a theme

  1. Write my-theme.tokens.yaml. The shortest way is to extend a built-in theme and change what differs:

    $extends: "pop-dark"
    $description: "Cooler greys"
    gray:
      $type: "color"
      "2": {$value: "#171a1f"}   # a key that is a number is quoted too
    surface:
      $type: "color"
      canvas: {$value: "#000000"}
    

    A theme may also stand alone (no $extends): it must then give every contract token, or the missing ones fall back to pop-dark.

  2. Register it and resolve it:

    let mut themes = egui_pop::tokens::Themes::default();
    // What was read otherwise than written: a token left out, renamed...
    for warning in themes.add_text("my-theme", include_str!("my-theme.tokens.yaml"))? {
        eprintln!("my-theme: {warning}");
    }
    let tokens = egui_pop::theme::install_with(ctx, &themes, &ThemeSpec::new("my-theme"));
    assert!(tokens.resolved().problems().is_empty());
  3. Check its contrast: contrast::check(tokens.resolved(), Level::Normal) returns the failing pairs.

For a new built-in theme: add the file under themes/, list it in BUILT_IN_FILES and BUILT_IN_THEMES, and the contrast and contract tests cover it at once. The default kit’s component tokens are not in pop-dark.tokens.yaml: they live in themes/kit/<component>.tokens.yaml and are layered into pop-dark at load (docs/kit.md). Add its snapshots to the gallery tests (UPDATE_SNAPSHOTS=1 cargo test -p egui-pop-gallery).

Into egui

egui_pop::theme::install sets egui’s styles from the system and component tiers (see the module documentation for the mapping) and stores a typed Tokens set in the context, read with Tokens::of(ctx). A theme alone fills both of egui’s styles, dark and light; a theme with a counterpart (org.egui-pop.variant-of, Themes) fills each with its own variant, and Tokens::of gives the one of egui’s theme of the moment. Install between frames; never change the global style mid-frame to theme one widget. The kit’s scroll-bar becomes egui’s ScrollStyle there, so every scroll area follows the theme’s bars, or what the user chose over them (kit.md).