Expand description
The theme editor, as a plugin (ThemeEditorPlugin): a theme’s
tokens edited live, grouped by role, each colour with its picker and
the contrast of the pairs it takes part in, started from any built-in
theme, exported and imported as a token file, every change undoable.
show draws the editor in any Ui (a panel, a window, a settings
page); the state lives in the plugin’s service (THEME_EDITOR),
over the theme service: each change is written to the application’s
theme (its base and overrides) and installed before the next frame.
When the theme changes elsewhere (a theme switcher), the editor starts
again from it.
A theme with a light and a dark variant is edited as a pair: the
draft holds both, each with its own changes and history, and the
variant edited is the one shown. Switching between light and dark (the
editor’s own switch, ThemeEditor::switch_variant, the application’s
toggle, or the system’s mode when the preference follows it) edits the
other one. Both stay installed, and a pair is saved as a new pair, one
file carrying both. “Generate the other variant”
(ThemeEditor::propose_counterpart, ThemeEditor::apply_counterpart)
computes the other variant from the one edited, shown before it is
applied.
The model is ThemeDraft (no
egui): a base theme, the tokens changed over it and their history.
A file is an ordinary .tokens.json that $extends the base.
| Step | Arguments | Default |
|---|---|---|
theme.token | path, from, to (raw DTCG values, null for the base theme’s), cause (edit, reset, undo, redo, agent) | writes to |
theme.load | base, overrides, counterpart ({base, overrides}, or null for a theme alone), cause (start, import) | loads them (the history starts again) |
A before-hook vetoes a change (the token keeps from) or redirects
it (another to, checked again); a run-hook’s result is the value
written. A colour dragged in its picker is shown live and becomes one
change when the pointer is released; a value typed in becomes one
when its field loses the focus.
Commands, for agents (hidden from the palette): theme.read (the
draft, or one token with its contrast readouts), theme.set (path,
value, null for the base theme’s), theme.undo, theme.redo
(the draft’s history is also a local scope, SCOPE: while the
editor has the focus, Edit > Undo and Ctrl+Z undo its changes),
theme.start (base), theme.export (name), theme.import
(text), theme.generate (scale, seed: a colour scale
generated from a seed, ThemeEditor::generate), theme.switch
(the pair’s other variant edited) and theme.counterpart (the other
variant generated from the one edited; proposed, or written with
apply).
Owned: egui_thematic (MIT) edits egui’s Visuals, not tokens with
aliases and contrast pairs; egui’s colour picker (MIT OR Apache-2.0)
is adopted for colours; egui_colors (MIT) generates palettes, and its
approach is re-derived in egui_pop_tokens::palette (see
docs/theme-editor.md).
use egui_pop_api::theme_editor::{THEME_EDITOR, ThemeEditorPlugin, Cause};
use egui_pop_api::App;
let app = App::builder()
.plugin(ThemeEditorPlugin)
.build(&egui::Context::default())
.unwrap();
let handle = app.handle();
let editor = handle.service(&THEME_EDITOR).unwrap();
editor
.set(handle, "accent.default", Some(serde_json::json!("#2060c0")), Cause::Agent)
.unwrap();
assert_eq!(handle.theme().spec().overrides.len(), 1);
editor.undo(handle, Cause::Agent).unwrap();
assert!(handle.theme().spec().overrides.is_empty());Structs§
- Readout
- One contrast pair a token takes part in, measured.
- Theme
Editor - The theme editor’s state, shared by its view and its commands.
- Theme
Editor Plugin - Declares the editor’s service, steps and agent commands.
Enums§
- Cause
- Why a token changes, as the
theme.tokenstep says it. - Tab
- What the editor shows: the tokens, or the fonts.
Constants§
- CMD_
THEME_ COUNTERPART - CMD_
THEME_ EXPORT - CMD_
THEME_ GENERATE - CMD_
THEME_ IMPORT - CMD_
THEME_ READ - CMD_
THEME_ REDO - CMD_
THEME_ SET - CMD_
THEME_ START - CMD_
THEME_ SWITCH - CMD_
THEME_ UNDO - SCOPE
- The editor’s history, a local scope (ADR 0014).
- STEP_
THEME_ LOAD - The editor starts from a theme, or from a file.
- STEP_
THEME_ TOKEN - A token changes.
- SURFACE
- The focus surface the editor is drawn in (
themeEditorFocus): its keys listen there, and its draft is the local scope Ctrl+Z undoes in while it has the focus. - THEME_
EDITOR - The editor’s state, as a service.
- THEME_
EDITOR_ PLUGIN - The plugin’s id.
Functions§
- contrast_
of - The contrast pairs a token takes part in, itself or through the
tokens aliasing it, measured in
tokens. - dependents
- The tokens whose value comes from
path: itself, and every token aliasing it, directly or not. - font_
sample - A sample line per role, interface then monospace, at the body size,
in the fonts installed or, in
egui_pop_core::fonts::with_preview, in the preview families: the fonts tab’s sample, also the settings window’s Fonts page’s. - level_
of - The level a theme is checked at: AAA text (7:1) for a high-contrast theme, AA otherwise.
- sample
- The preview pane’s default content: text by role, the status
colours, buttons in their tones and states, a checkbox, options, a
slider, a field, a selected row and a progress bar, drawn in the
theme of the
Ui(aScopedTheme’s in the editor). - scale_
of - The colour scale a reference token is a step of (
blueforblue.3): a scale with a step 9. - show
- Draws the theme editor (it needs
ThemeEditorPlugin).
Type Aliases§
- File
Dialog - A file chooser the host gives the editor (
ThemeEditor::set_file_dialog): it starts a choice and answers later, asfiles::Files::choosedoes ({ "paths": [...] }, ornullwhen cancelled). - Sampler
- What the preview pane draws, in the draft’s theme
(
ThemeEditor::set_sampler).