Skip to main content

Crate egui_pop_tokens

Crate egui_pop_tokens 

Source
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 file kit = "kit.json" names), and the token files, faces (under fonts/) and licence it is given. The path is relative to the file calling the macro, as include_str!’s. Nothing is checked when compiling: call kit::check from a test.

Structs§

Color
An sRGB colour with straight (not premultiplied) alpha, each channel from 0 to 1.
FormatStamp
A token file’s format stamp: the format and contract versions it was written for.
GeneratedVariant
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.
ResolvedTokens
A theme ready to use: every contract token has a value of its type.
ThemeDraft
A theme being edited: one theme, or a light and dark pair.
ThemeSpec
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.
TokenEdit
One change of one token: from a value to another. None is the value the base theme gives (no override).
TokenFile
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.
ScrollBars
What the user asks of the scroll bars, over what the theme’s scroll-bar says (ThemeSpec::scroll_bars, the appearance.scroll_bars setting).
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 $extensions key 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 $extensions key 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_EXTENSIONDeprecated
The $extensions key 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_VERSIONDeprecated
The version the theme editor wrote under its former stamp.
FALLBACK_THEME
The theme everything falls back to.
FORMAT_EXTENSION
The root $extensions key 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 in rem.
SEED_SCALE
The scale an accent generated from a seed colour is written to (ThemeSpec::accent_color): custom.1 to custom.12 and custom.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 $extensions key naming a theme’s counterpart: the other variant, light or dark, of the same theme ($extensions: {"org.egui-pop.variant-of": "pop-dark"} in pop-light). Saying it on one side is enough: the other is found by looking it up. Not inherited through $extends: a theme built on pop-light is a theme of its own.

Functions§

text_size_step
The step of TEXT_SIZES nearest to a factor.
theme_label
A theme’s name for people: a built-in theme’s label, else its id.