Expand description
Themes: tokens into egui’s style (from egui-pop-core).
Themes for egui: resolved design tokens turned into egui’s [Visuals]
and [Style], installed into a [Context], and kept there as a typed
Tokens set for custom widgets.
use egui_pop_core::theme::{self, Density, ThemeSpec, Tokens};
let ctx = egui::Context::default();
let tokens = theme::install(&ctx, &ThemeSpec::new("pop-light").density(Density::Compact));
assert!(tokens.resolved().problems().is_empty());
assert_eq!(ctx.global_style().visuals.panel_fill, tokens.surface.panel);
// Any widget reads the same set back from the context.
assert_eq!(Tokens::of(&ctx).accent.default, tokens.accent.default);§Where tokens go
egui’s own widgets (and other crates’ widgets) are drawn from the
generated style: surface.* become panel, window and field fills,
button.* the widget states (rest, hovered, pressed), text.* the
widget strokes, border.* outlines and separators, focus.ring the
stroke of a focused or pressed widget, selection the fill behind
selected text and items, space.* and size.* the spacing,
font.text-style.* (steps of the font.size.* scale) egui’s text
styles, shadow.window and shadow.popup egui’s window and popup
shadows, motion.duration the animation time, and the kit’s
scroll-bar every scroll area’s ScrollStyle (its width, margin,
placement and visibility).
egui uses one colour (selection.stroke) for both the text of a
selected label and the frame of a focused text field: egui-pop gives it
text.strong, which stays legible on the selection fill. egui’s slider
paints its rail with the resting widget fill and its optional trailing
fill with the selection fill; the slider.* tokens are for egui-pop’s
own slider.
Font families (font.family.*) become egui’s fonts at several weights
(fonts): faces the application registers, the system’s (feature
system-fonts), then egui’s bundled fonts.
§Never per widget
A theme is installed for the whole context, between frames. Never
change the global style in the middle of a frame to theme one widget:
read Tokens::of and paint with its values, or scope a style change
to a child Ui (ui.scope(|ui| { ui.style_mut()... })), which does
not leak to the rest of the frame.
Structs§
- Accent
- Axis
Palette - The axes’ colours (
palette.axis.*): X red, Y green and Z blue, as most 3D and image tools draw them. Each is seen at 3:1 on the viewport’s background. - Border
- Data
Palette - The data palettes (
palette.*): colours for charts and data views. - Font
- Font sizes in points and families, the first preferred.
small,body,button,headingandmonoare egui’s text styles (font.text-style.*), each a step of thescale(font.size.*). - Font
Scale - The size scale’s five steps, in points (
font.size.xstoxl). - LogPalette
- The log levels’ colours (
palette.log.*), from the least to the most severe: what a log view colours a line’s level with. Each reads as text on the canvas and the panel. - Motion
Tokens - Times of motion, in seconds (see
motion). - Radius
- Corner radii in points.
- Resolved
Tokens - A theme ready to use: every contract token has a value of its type.
- Scoped
Theme - A theme drawn in one part of a window without being installed: a
theme’s tokens, their kit and egui’s style for them, applied to a
child
Ui(ScopedTheme::show). While it draws,Tokens::ofandKit::ofgive its tokens and kit, so egui-pop’s widgets and custom painting follow it as egui’s do; the rest of the window keeps the installed theme. A theme editor’s preview, a themed island, a theme picker’s thumbnails. - Shadow
Tokens - Shadows under what lies over the interface (
shadow.*), as egui’s. - Size
- Sizes in points.
- Space
- Spacing in points: the scale’s steps (
space.xstospace.xl), and spacing by intent (space.inline,group,section,page), each an alias of a step, so densities scale it. - Status
- Status colours, legible as text on panels and overlays.
- Surface
- The surfaces, from the deepest to the topmost.
- Text
- Text
Role Style - How a text role is drawn.
- Text
Roles - Every text role’s style (
text-role.*). - 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.
- Tokens
- The system tokens of a resolved theme, typed for egui. Custom widgets
read it with
Tokens::ofinstead of hard-coding a colour or a size; a component’s look is in its kit (Kit::of(ctx).<component>), and any other token inTokens::resolved. - Variants
- The tokens installed, one set per egui theme: a theme and its counterpart, or the same theme twice when it is alone.
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.
- Scroll
Bars - What the user asks of the scroll bars, over what the theme’s
scroll-barsays (ThemeSpec::scroll_bars, theappearance.scroll_barssetting). - Text
Role - A text role: what a piece of text is (
text-role.*), each a size, a colour and a weight over the size scale and the text colours.
Constants§
- 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). - FALLBACK_
THEME - The theme everything falls back to.
- POP_
THEMES - egui-pop’s own base themes, in the order a switcher shows them.
Functions§
- color32
- A token colour as an egui colour.
- install
- Resolves a spec against the built-in themes and installs it.
- install_
tokens - Installs typed tokens into a context, alone: egui’s dark and light
styles both become the theme’s and egui’s mode is forced to the
theme’s (so the system’s light or dark preference does not swap it
out), and
Tokens::ofreturns them. Call it between frames (at start-up, or when the user picks another theme), not while drawing. - install_
variants - Installs a theme and, when given one of the other mode, its
counterpart: each is written into its own egui style (dark or light)
with its own kit, and
Tokens::ofandKit::ofgive the one of egui’s theme of the moment. egui’s mode is set to the theme’s (the first one), as when it is alone, and it is egui’s fallback when the system says nothing;set_preference(orctx.set_theme) then switches between the two, or follows the system, without installing anything again. A counterpart of the same mode is ignored (with a warning): the theme is installed alone. Fonts and icon sizes come from the first theme. Returns the first theme’s tokens. - install_
with - Resolves a spec against the given themes and installs it. Problems
(a broken user theme, a typo in an override) are in
tokens.resolved().problems(); the theme is installed anyway, with fallbacks. The spec’s counterpart, when it has one (ThemeSpec::counterpart, the token files’org.egui-pop.variant-of), is installed with it (install_variants). - is_
paired - Whether the theme installed has a counterpart: a light and a dark
variant installed together (
install_with). - set_
preference - Asks for egui’s light or dark mode, or the system’s
(
ThemePreference::System): with a pair installed, it switches between the two at once, nothing installed again. A theme alone keeps its own mode whatever is asked. - shadow
- The shadow a group of tokens gives (
<prefix>offset-x,offset-y,blur,spreadandcolor;shadow.window.or a component’sside-area.shadow-), as egui’s [Shadow], rounded to its whole points;Nonewhen the colour is missing. egui’s spread cannot be negative: below 0 it is 0. - snap_
strokes - Snaps a style’s stroke widths to whole physical pixels at
ppp(scale::snap), so 1 point borders stay one sharp pixel at 1.25 or 1.5.install_tokensdoes it for the scale of the window it runs in; egui-pop’s application installs the theme again when that scale changes. - style
- egui’s style for a theme, built over
base(whose settings the theme does not decide are kept). - style_
with stylewith a compiled kit (the one installed with the theme).- theme_
label - A theme’s name for people: a built-in theme’s label, else its id.
- variants
- The tokens installed in a context, per egui theme; the built-in
pop-darkones, alone (installed on first use), when no theme was. - visuals
- egui’s visuals for a theme.
- visuals_
with - egui’s visuals for a theme and its compiled kit: egui’s widget states
come from the kit’s
button(rest, hover, active, and selected for an open menu), text fields’ background from itsfield. What egui cannot draw is in the kit’s problems (Kit::compile).