Expand description
Design tokens for egui-pop, in the DTCG format, with no egui dependency.
A token file is a tree of groups and tokens in the format of the W3C
Design Tokens Community Group (DTCG 2025.10). A token is an object with
a $value and a $type given on the token or inherited from its group;
its name is its dotted path (surface.panel). A value can be a
whole-value alias of another token, "{gray.2}". $description and
$extensions are kept. At the root, $extends names the theme a file
builds on: every token not given comes from it.
Tokens come in three tiers (Tier): the reference palette (colour
scales such as gray.0..gray.12), the system roles widgets read
(surface.panel, text.muted) and component tokens
(slider-fill.rest.fill), each tier aliasing the one below. Every theme answers
the same contract(); a theme missing a token, or giving it the wrong
type, gets the built-in pop-dark value for it and a reported problem.
Resolving never panics.
A theme is composed from a ThemeSpec: a base theme (mode and
contrast), a Density overlay (space and size tokens only), an accent
(a colour scale whose steps become the accent roles), reduced motion and
the user’s overrides.
use egui_pop_tokens::{ThemeSpec, Themes, contrast};
let themes = Themes::default();
let tokens = themes.resolve(&ThemeSpec::new("pop-dark").accent("blue"));
assert!(tokens.problems().is_empty());
let text = tokens.color("text.default").unwrap();
let panel = tokens.color("surface.panel").unwrap();
assert!(contrast::contrast_ratio(text, panel) >= 4.5);A theme being edited is a ThemeDraft: a base theme, the tokens
changed over it and their history, saved as a token file that
$extends the base.
A file may carry a format stamp (FormatStamp): the format and
contract versions it was written for. Loading a theme over its base
never fails on a token: what is read otherwise than written comes
back as Warnings.
A colour scale can be generated from one seed colour
(palette::ramp): twelve steps for a light or a dark theme, the
text on its solid step chosen with APCA (apca).
A kit’s tokens, fonts and licence come as a folder or embedded in the
binary (kit, kit!). A theme using font files travels
as a folder or a .zip archive holding them (package).
Types read: color (DTCG colour objects in srgb, srgb-linear,
oklch or oklab, any other space through its hex fallback, and
#rrggbb[aa] strings), dimension (px or rem), number,
duration (ms or s) and fontFamily. Other types are kept as raw
JSON (Value::Other).
Re-exports§
pub use contract::CATEGORY;pub use contract::CONTRACT_VERSION;pub use contract::LOG_LEVELS;pub use contract::RENAME_WINDOW;pub use contract::RENAMED;pub use contract::Renamed;pub use contract::Required;pub use contract::Tier;pub use contract::contract;
Modules§
- apca
- APCA lightness contrast (Lc), informative only.
- cache
- A cache of compiled files: what is read from a file at run time and costly to compile (a YAML token file, say) is compiled once and kept, never next to its source.
- contract
- The contract: the system and component tokens every theme provides.
- contrast
- Contrast checks: the token pairs that must stay legible, and the WCAG 2.x ratios they must reach.
- kit
- Kits as packages (
docs/kit-packages.md): a folder holding a kit’s tokens, its fonts and its licence, read at run time or embedded in the binary. - package
- Theme packages: a token file with the font files it uses, so that a theme naming its own faces travels whole.
- palette
- Palette ramps generated from one seed colour.
Macros§
- kit
- Embeds a kit folder in the binary:
kit.yaml(or the kit filekit = "kit.json"names), and the token files, faces (underfonts/) and licence it is given. The path is relative to the file calling the macro, asinclude_str!’s. Nothing is checked when compiling: callkit::checkfrom a test.
Structs§
- Color
- An sRGB colour with straight (not premultiplied) alpha, each channel from 0 to 1.
- Format
Stamp - A token file’s format stamp: the format and contract versions it was written for.
- Generated
Variant - A pair’s other variant generated from the one edited
(
ThemeDraft::generate_counterpart): a proposal, for a preview, that changes nothing until recorded. - RawToken
- A token as written in a file: its value may still be an alias.
- Resolved
Tokens - A theme ready to use: every contract token has a value of its type.
- Theme
Draft - A theme being edited: one theme, or a light and dark pair.
- Theme
Spec - What to resolve: a base theme (mode and contrast), a density, an accent,
reduced motion and the user’s own overrides, composed in that order.
The base theme’s counterpart (
Counterpart), when it has one, is resolved with the same density, accent, reduced motion and overrides (Themes::resolve_counterpart), or with overrides of its own (ThemeSpec::counterpart_overrides). - Themes
- The themes known: the built-in ones and any added.
- Token
- A resolved token.
- Token
Edit - One change of one token: from a value to another.
Noneis the value the base theme gives (no override). - Token
File - A token file: a theme, a density overlay or any other layer.
Enums§
- Counterpart
- Which theme, if any, is the other variant (light or dark) of a spec’s base theme: installed with it, so that egui’s light or dark mode (the system’s, or the user’s choice) switches between them without installing anything again.
- Density
- How much room the interface takes: an overlay of space and size tokens only.
- Error
- A problem in a token file or met while resolving a theme.
- Scroll
Bars - What the user asks of the scroll bars, over what the theme’s
scroll-barsays (ThemeSpec::scroll_bars, theappearance.scroll_barssetting). - Value
- A token’s value, resolved and typed.
- Warning
- Something a token file loaded with, short of failing: the file still loads, and the warning says what was read otherwise than written.
Constants§
- ALPHA_
EXTENSION - The
$extensionskey of the alpha modifier: on a colour token, a number from 0 to 1 the colour’s alpha is multiplied by, after its alias is followed ({"$value": "{surface.overlay}", "$extensions": {"org.egui-pop.alpha": 0.85}}, the overlay at 85 %). Every modifier met along a chain of aliases applies. - BASED_
ON - The component term naming the component another is based on
(
command-button.based-on: "button",docs/kit.md). - BUILT_
IN_ ACCENTS - The built-in colour scales usable as an accent.
- BUILT_
IN_ THEMES - Every built-in theme, in the order a switcher shows them: egui-pop’s
own, then the editor-inspired ones by family, light before dark (their
sources and licences are in
NOTICE). - COUNTERPART_
EXTENSION - The root
$extensionskey carrying a theme’s counterpart inside its file: a light and dark pair saved as one file (the theme editor’s). Its value names the counterpart and gives its token file, an ordinary one with its own stamp: - DRAFT_
EXTENSION Deprecated - The
$extensionskey the theme editor stamped its files with before the format stamp; still read. - DRAFT_
HISTORY_ CAP - How many edits a draft’s history keeps by default, the oldest
dropped first (
ThemeDraft::set_history_cap). - DRAFT_
VERSION Deprecated - The version the theme editor wrote under its former stamp.
- FALLBACK_
THEME - The theme everything falls back to.
- FORMAT_
EXTENSION - The root
$extensionskey of a token file’s format stamp. - FORMAT_
VERSION - The version of the file format egui-pop writes: how a token file is
laid out (DTCG,
$extends, egui-pop’s$extensions), apart from which tokens it gives (CONTRACT_VERSION). - POP_
THEMES - egui-pop’s own base themes, in the order a switcher shows them.
- PX_
PER_ REM - Pixels in one
rem, for dimensions given inrem. - SEED_
SCALE - The scale an accent generated from a seed colour is written to
(
ThemeSpec::accent_color):custom.1tocustom.12andcustom.contrast, replacing a scale of that name. - TEXT_
SIZES - The text sizes a user chooses from, as factors of a theme’s size scale: few steps, so the font atlas holds few sizes.
- TOKENS_
COMPILER - What compiles a YAML token file into the JSON tree the cache keeps: its version is this crate’s with a revision (raised when the tree a file compiles to changes), so a new egui-pop ignores the entries of the one before.
- VARIANT_
OF_ EXTENSION - The root
$extensionskey naming a theme’s counterpart: the other variant, light or dark, of the same theme ($extensions: {"org.egui-pop.variant-of": "pop-dark"}inpop-light). Saying it on one side is enough: the other is found by looking it up. Not inherited through$extends: a theme built onpop-lightis a theme of its own.
Functions§
- text_
size_ step - The step of
TEXT_SIZESnearest to a factor. - theme_
label - A theme’s name for people: a built-in theme’s label, else its id.