Skip to content

Themes

API → Editor

The editor's look is data. A theme is a small JSON file of colour roles, chrome fills, fonts, and metrics. Six themes ship with the editor and every user can save their own, gradients included. The active theme is a per-user setting, never a project setting, so choosing one never changes a project's files.

conjure/editor/theme.h holds the data model, the file format, and the rules. conjure/editor/theme_library.h lists the themes and owns the active one, and conjure/editor/user_settings.h keeps the user's choice. Neither of the first two includes ImGui, so the commands, the headless editor, and tests use them as they are. The window shows a theme through conjure/editor/ui/theme_applier.h, and the Theme editor (conjure/editor/ui/panels/theme_editor_panel.h) edits them.

Syntax

A variant of a built-in theme, checked, saved as a user theme, and made active. Adapted from the test "theme - a user theme saved and loaded round trips" in tests/editor/test_theme.cpp.

#include "conjure/editor/theme.h"
#include "conjure/editor/theme_library.h"

#include <string>

using namespace conjure;
using namespace conjure::editor;

// 'library' has its themes folder set (theme_library::set_directory); save() needs one.
bool save_aurora_at_dusk(theme_library &library) {
    theme value = *find_builtin_theme("Aurora");
    value.name = "Aurora at Dusk";
    value.colours.prefab = *parse_theme_colour("#7fb2fe");
    value.chrome.grid = *parse_theme_colour("#ffffff0b");
    value.metrics.density = theme_density::COMPACT;
    if (!validate_theme(value).empty()) {
        return false;                                       // a rule is broken: save() would refuse it too
    }
    const core::result<std::string> saved = library.save(value);    // "aurora-at-dusk.conjure-theme.json"
    if (!saved.has_value()) {
        return false;
    }
    library.request(value.name);
    return library.active().name == value.name;
}

Important

This drives a library of its own. Inside the editor, choose a theme the way editor.theme.set does: set editor_context::user_settings().activeTheme and call editor_context::sync_themes(), which emits theme.changed and asks the window to apply the theme again. That lasts for the session: editor.theme.set also saves the choice with update_user_settings.

At a glance

If you want to... Then use...
read a theme file, with every problem reported by path parse_theme(text)
check the readability rules validate_theme(theme) (Validation rules)
write a theme file serialise_theme(theme), theme_to_json(theme)
reach the built-in themes builtin_themes(), find_builtin_theme(name)
list the themes the editor offers and the one it shows editor_context::themes(), a theme_library
choose, save, or delete a theme from a protocol client editor.theme.set, editor.theme.save, editor.theme.delete (Theme commands)
edit, preview, import, or export themes in the window Edit > Preferences > Themes... (The Theme editor)
fill the title bar, toolbar, status bar, or Scene backdrop with a gradient a linear or radial chrome fill (User-made gradient themes)
use another font family fonts.ui, fonts.mono, and the font files (Fonts and code ligatures)

Variables and Properties

Name Access Purpose
std::string theme::name public the theme's name, 1 to 64 bytes of UTF-8
std::string theme::base public what the members the file left out fell back to: "dark" (Midnight, the default) or a built-in theme's name
theme_colours theme::colours public the 30 colour roles
theme_chrome theme::chrome public the title, toolbar, status, and viewportBackdrop fills, the statusText, and the grid and gridMajor colours
theme_fonts theme::fonts public the ui and mono families and the size
theme_metrics theme::metrics public the corner rounding and the density
theme_rule theme_problem::rule, std::string theme_problem::path, std::string theme_problem::message public one thing wrong with a theme, and the member it concerns
std::string_view THEME_FILE_EXTENSION constant ".conjure-theme.json"
std::string_view DEFAULT_THEME_NAME constant "Midnight", the theme of a user who never chose one (conjure/editor/user_settings.h)
f64 MIN_TEXT_CONTRAST, f64 MIN_FAINT_CONTRAST constant 4.5 and 3, the contrast ratios the rules ask for
f64 MIN_STATE_COLOUR_DIFFERENCE, f64 MIN_STATE_LIGHTNESS_DIFFERENCE constant 20 and 8, how far accent, play, and persist lie apart

The theme file

A theme file is <name>.conjure-theme.json, in UTF-8. This is the built-in Midnight theme's file, which lists every member:

{
  "schema_version": 1,
  "name": "Midnight",
  "base": "dark",
  "colours": {
    "panel": "#1d2026", "head": "#262a31", "sunken": "#1a1c21", "tabbar": "#181a1f", "menu": "#181a1f",
    "line": "#2c3038", "line2": "#15171b", "control": "#2a2e36", "controlLine": "#363b45",
    "text": "#c9ced8", "strong": "#e8ebf0", "muted": "#9aa1ad", "faint": "#6f7682",
    "accent": "#4c8dff", "accentSoft": "#2f4b7f", "accentText": "#ffffff",
    "play": "#e8a23b", "playSoft": "#4a3714", "playText": "#ffc56b",
    "persist": "#4fddbc", "persistSoft": "#123b35",
    "prefab": "#5aa2ff", "prefabSoft": "#1f2a3d", "prefabLine": "#2b3f63",
    "script": "#a78bfa", "warning": "#ffb347", "error": "#ff6b6b",
    "overlay": "#121418d1", "statusDim": "#c4d5f5", "frame": "#9aa1ad"
  },
  "chrome": {
    "title": "#121418",
    "toolbar": "#22252b",
    "status": {"flat": "#2f4b7f", "text": "#eef3fd"},
    "viewportBackdrop": "#26292f",
    "grid": "#2e323a", "gridMajor": "#383d47"
  },
  "fonts": {"ui": "Inter", "mono": "Fira Code", "size": 13},
  "metrics": {"rounding": 5, "density": "comfortable"}
}
  • Colours are sRGB as the screen shows them, with straight alpha: "#rrggbb" or "#rrggbbaa", hex digits in either case (parse_theme_colour). Nothing else parses: no "#fff" shorthand, no spaces, no rgb().
  • Missing members fall back to the base. Only "name" is required. "base": "dark", the default, is Midnight; the name of a built-in theme, in any letter case, falls back to that theme. schema_version is 1.
  • Unknown members are refused, so a misspelt role is reported instead of falling back silently.
  • parse_theme(text) returns a theme_parse_result: the complete theme and every problem found, each by the path of its member (colours.text). A file with problems is never applied. serialise_theme writes every member, so a saved file never depends on its base.

Colour roles

The 30 colour roles name meanings, not widgets: the editor maps them onto every ImGui colour and, through the widget kit's tokens, onto its own drawing. A theme cannot restyle one widget, and every new widget is themed for free. theme_colour_roles() lists them in file order.

Roles Meaning
panel, head, sunken the panel and window background; headers and title rows; fields, lists, and the console
tabbar, menu dock tab bars; the menu bar and popups
line, line2 separators and borders; the darker line beside line
control, controlLine buttons and frames; their edge
text, strong, muted, faint body text; emphasised text; secondary text; hints and disabled text
accent, accentSoft, accentText selection, focus, and the active tool; the selection background; text on accentSoft
play, playSoft, playText play mode; its soft fill (the Pause button while paused); text on playSoft
persist, persistSoft values pinned to survive Stop; their soft fill
prefab, prefabSoft, prefabLine prefab instances; the prefab banner's fill and border
script, warning, error script components and their icons; warnings; errors
overlay, statusDim, frame the Scene view's chips and view-axes disc; secondary status-bar text; the camera frame in the Scene view

Five roles are optional: prefabSoft, prefabLine, overlay, statusDim, and frame. A file that leaves them out gets them derived from its own colours (derive_theme_roles), never from its base: prefabSoft is panel 10 % towards prefab, prefabLine 30 %, overlay is sunken at 85 % opacity, statusDim is the status text 16 % towards the mean of the status fill's colours, and frame is muted. A derived value that would break its rule is pulled back until it passes.

Chrome, fonts, and metrics

  • Chrome is the only place for gradients. title, toolbar, status, and viewportBackdrop each take a fill: a colour string, {"flat": colour}, {"linear": {...}}, or {"radial": {...}} (User-made gradient themes). The status fill's object may also carry its "text" colour; {"text": colour} alone changes only the text, and a colour string keeps the base's text. grid and gridMajor are the Scene view's grid lines and may be translucent.
  • The scene is never themed. viewportBackdrop shows only where the scene draws nothing.
  • Fonts name the UI family (ui), the code family (mono) and the base size in pixels at 100 % (size, 8 to 32). See Fonts and code ligatures.
  • Metrics are the corner rounding (0 to 12 pixels) and the density: "compact", "comfortable" or "spacious", which multiply the paddings and spacings of ImGui's style by 0.75, 1, and 1.5 (kit::density_factor). The widget kit's own sizes do not change with the density.

Validation rules

validate_theme(theme) returns every violation of the rules; an empty list means the theme may be applied. Each problem is a theme_problem { rule, path, message }, and to_string(problem) prints "path: message".

Rule What it asks for
DOCUMENT a theme document: JSON, known member names of the right types, colour spellings, schema_version 1, a known base (found by parse_theme)
NAME a name of 1 to 64 bytes of UTF-8, without control characters or surrounding spaces
FONTS non-empty font families and a size from 8 to 32 pixels
METRICS a rounding from 0 to 12 pixels
GRADIENT 2 to 4 stops for a linear fill and 2 to 3 for a radial one, positions from 0 to 1 in ascending order, a radial centre inside the area
ALPHA every role a contrast or distinction rule reads is opaque, since contrast between translucent colours depends on what lies beneath them
CONTRAST text, strong, and muted reach 4.5:1 on panel, head, and sunken, and faint reaches 3:1; accentText on accentSoft, playText on playSoft, strong on prefabSoft, and the status text on every colour of the status fill reach 4.5:1; statusDim reaches 3:1 on every colour of the status fill (WCAG 2 contrast ratios)
DISTINCTION accent, play, and persist differ pairwise by at least 20 in CIEDE2000 and by at least 8 in CIELAB lightness, so a state never rests on hue alone

Every colour role that no rule reads may be translucent: tabbar, menu, line, line2, control, controlLine, persistSoft, prefab, prefabLine, script, warning, error, overlay, and frame. So may the grid colours, chrome.grid and chrome.gridMajor, and the title, toolbar, and Scene backdrop fills; only the status fill and its text must be opaque. The Theme editor offers an alpha channel for these roles (theme_editor_panel::role_may_be_translucent), the two grid colours, and those three fills, and for no other colour.

Built-in themes

builtin_themes() returns the six built-in themes in a fixed order, and find_builtin_theme(name) finds one by name in any letter case. They are compiled into the editor from their theme files (builtin_theme_files()).

Theme Character
Midnight the default and the "dark" base: graphite panels, a blue accent (#4c8dff), a flat blue status bar, a flat Scene backdrop
Autumn warm brown panels, an orange accent, an ember gradient status bar, a radial Scene backdrop
Deep Ocean blue-green panels, a cyan accent, a teal gradient status bar, a radial Scene backdrop
Aurora near-black panels, a violet accent, a green to magenta status bar, a radial Scene backdrop
Synthwave purple panels, a pink accent, a purple to orange status bar, a linear Scene backdrop
High contrast black panels, white text, a yellow accent, a rounding of 2, a flat black Scene backdrop

Midnight comes first. Every other built-in file names "base": "dark", so Midnight is what any member it left out would fall back to, though each lists every member. Built-in themes are read-only: saving or deleting one is refused. Every built-in passes validate_theme.

User themes and the active theme

User themes are files in <user config>/themes/, named <slug>.conjure-theme.json. The user configuration folder is per user and per platform, or the folder --user-config <dir> names (User settings and the UI host). theme_file_name(name) gives the slug: the name in lower-case ASCII letters and digits, every other run of characters one -, cut to 48 characters ("Deep Ocean" becomes deep-ocean.conjure-theme.json). A second theme whose slug is taken gets a number (-2, -3).

  • The library lists every *.conjure-theme.json file of the folder. A file that cannot be read, parsed, or validated, or that takes the name of a built-in or of another user theme, is listed with its problems and never applied. Names compare without letter case.
  • The active theme is the user's choice, activeTheme in editor_settings.json (editor_user_settings, default "Midnight"), when it is valid; otherwise Midnight, with one warning. A theme that was showing and whose file turns invalid (a half-typed edit in a text editor) keeps its last valid version until the file is fixed. A file that no longer parses is listed under its file stem.
  • The folder is watched. Every editor_context::THEME_WATCH_INTERVAL_TICKS (30) frames, about twice a second at 60 frames per second, the editor lists the folder. A file that appeared, vanished, or changed is read again, and a change to the shown theme is applied at once.
  • Changes are announced. theme_library::revision() counts the changes of the active theme: another theme, or new values of the same one. Each change emits the event theme.changed {active} to protocol clients, and the window applies the theme again.

Note

The library is per user, not per project: it survives project.open, and Edit > Preferences > Themes... works on the start screen too.

User-made gradient themes

Any of the four chrome fills can be a gradient. This user theme, from tests/editor/test_theme.cpp, uses every fill form and passes validate_theme:

{"schema_version": 1, "name": "Fills", "chrome": {
  "title": "#101010",
  "toolbar": {"flat": "#202020"},
  "status": {"radial": {"centre": [0.25, 0.75], "stops": [["#2f4b7f", 0], ["#203050", 1]]}, "text": "#ffffff"},
  "viewportBackdrop": {"linear": {"stops": [["#000000", 0], ["#111111", 1]]}}}}
  • A stop is [colour, position], its position from 0 to 1. Positions ascend; equal neighbours are allowed. Before the first stop the first colour holds, after the last stop the last. Gradients mix in sRGB, as CSS does.
  • A linear fill takes 2 to 4 stops and an angle in CSS degrees: 0 runs upwards, 90 to the right, and 180, the default, downwards. The two corners the gradient line meets first and last take exactly the end stops.
  • A radial fill takes 2 to 3 stops and a centre [x, y] in fractions of the area, [0, 0] at the top left. The gradient is an ellipse at the centre through the farthest corner of the area, as CSS's farthest-corner ellipse, clipped to the area.

In the Theme editor, the Chrome section edits each fill: its kind, a flat colour, or a gradient's angle or centre and its stops in the gradient stop editor. Changing a fill's kind keeps its colours (theme_editor_panel::change_fill_kind): a flat colour becomes two equal stops at 0 and 1, a gradient made radial drops stops past three from the middle, and a gradient made flat keeps its first colour.

Theme commands

Theme commands are per-user UI state: they are not undoable, they move no revision, and nothing in the scene or project changes. The user's other preferences are read with editor.preferences.get and the code ligatures are set with editor.preferences.set (Code ligatures).

Command Does
editor.theme.list {} {active, requested, themes: [{name, builtIn, valid, file?, problems?}]}; requested is the user's choice, which differs from active while it cannot be applied
editor.theme.get {name?} {name, builtIn, valid, file?, theme, problems}: the theme document, null for a user file that is no theme document. Without a name, the active theme; the Theme editor's preview is never reported
editor.theme.set {name} chooses the active theme and saves the choice: {active, persisted}. persisted is false without a user configuration folder, or when the settings file cannot be written (one warning; the choice lasts for the session). An unknown or invalid theme is INVALID_ARGS; without the windowed UI (headless) it is NOT_AVAILABLE
editor.theme.save {theme, name?} validates a theme document and writes it as a user theme: {name, file, active}. A theme of the same name keeps its file. Problems are INVALID_ARGS with error.details.problems, each path naming its argument (args.theme.colours.text, args.name); a built-in's name is INVALID_ARGS; no user configuration folder is NOT_AVAILABLE; a file that cannot be written is IO_ERROR
editor.theme.delete {name} deletes a user theme's file: {name, file, active}. Deleting the chosen theme chooses Midnight. A built-in or an unknown user theme is INVALID_ARGS; a file that cannot be removed is IO_ERROR
-> {"id":7,"cmd":"editor.theme.save","args":{"theme":{"name":"Ocean Night","base":"Deep Ocean"}}}
<- {"id":7,"ok":true,"result":{"name":"Ocean Night","file":"ocean-night.conjure-theme.json","active":"Midnight"}}
-> {"id":8,"cmd":"editor.theme.set","args":{"name":"ocean night"}}
<- {"id":8,"ok":true,"result":{"active":"Ocean Night","persisted":true}}
<- {"event":"theme.changed","seq":120,"frame":3311,"data":{"active":"Ocean Night"}}

How the window shows a theme

editor_layer owns a theme_applier (editor_layer::themes()) next to its kit context. The applier keeps the ImGui context showing the shown theme (shown(context)): the active theme, or the Theme editor's working copy while it previews one (set_preview, clear_preview). The preview belongs to the window alone; the commands and theme.changed always report the active theme.

  • When. The layer applies the theme when it attaches. Then, every frame before the workspace draws, apply_style() applies the colours and metrics again when a refresh was requested, the library's revision() moved, the preview changed, the ImGui or kit context is another one, or the UI scale (ui::editor_ui_scale()) changed; otherwise it does nothing. Fonts change the font atlas, which ImGui locks inside a frame, so load_fonts() runs at the end of the frame, and only when the fonts are due (Fonts and code ligatures).
  • Each application goes through the widget kit: kit::kit_context::apply_theme resolves the kit's tokens at the UI scale and writes ImGui's global style. The applier also colours ImGuizmo (apply_gizmo_style) and sets the renderer's back-buffer clear to the theme's panel colour (back_buffer_colour), so empty areas show the theme. Without a kit context it calls apply_theme_style.
  • Metrics. The style starts from a fresh ImGuiStyle every time, so nothing compounds: ImGui's sizes scaled by fonts.size over 13, paddings and spacings multiplied by the density, metrics.rounding on windows, popups, frames and grabs, square tabs, a 6 px scrollbar, and 1 px dock splitters.

The Theme editor

Edit > Preferences > Themes... opens the Theme editor, theme_editor_panel (registry name theme_editor, titled Themes, closed by default). It lists every theme, the built-ins and the active theme marked, and user themes that cannot be applied in the error colour with their problems. A property grid under the list shows the selected theme, or the working copy, in the sections Theme, Files, Colours, Chrome, Fonts, and Metrics. A field that a problem concerns takes the invalid mark.

  • Set active sends editor.theme.set. Delete (user themes only, after a dialog naming the file) sends editor.theme.delete.
  • The working copy. Duplicate makes one under a free name (copy_name: "Deep Ocean copy", then "copy 2"). Changing a value makes one too: of a user theme under its own name, so Save replaces its file; of a built-in, a duplicate. While the copy has unsaved changes, Edit and Duplicate are refused with INVALID_STATE until it is saved or discarded.
  • Live preview. While the panel is open with a working copy, the whole editor shows the copy's last version that passes the rules, so a half-typed value never makes the editor unreadable. Discard, or closing the panel, shows the active theme again.
  • Save sends editor.theme.save with the copy under the name it has. Renamed, the copy is saved as a new theme and the original stays; a name another user theme has is refused with ALREADY_EXISTS.
  • Import reads a theme file from an absolute path typed into the panel and saves it through editor.theme.save. Export writes the selected theme's file to an absolute path, atomically: a folder takes the theme's file name, anything else is the file.
  • Two files that name one theme. The library lists the later one with a NAME problem. It can be selected, but it offers no action, since the commands act by name; rename its theme or remove its file.

The operations are public, so a test or a tool can drive the panel without its widgets: select, set_active, duplicate, start_editing, edit, save, discard, remove, import_file, and export_file, and the fill editor's change_fill_kind, add_fill_stop, and remove_fill_stop.

Functions

Signature Purpose
std::optional<theme_colour> parse_theme_colour(std::string_view text) reads "#rrggbb" or "#rrggbbaa"; nullopt for anything else
std::string to_string(const theme_colour &colour) the lower-case spelling, "#rrggbb" when opaque
theme_parse_result parse_theme(std::string_view text) reads a theme file, with every problem by path
theme_parse_result parse_theme(const core::json::value &root) reads a theme document a protocol client sent
core::json::document theme_to_json(const theme &value) writes every member as a document
std::string serialise_theme(const theme &value) writes every member as a file's text
std::vector<theme_problem> validate_theme(const theme &value) every violation of the rules
std::span<const theme> builtin_themes() the six built-in themes, in their fixed order
const theme *find_builtin_theme(std::string_view name) a built-in by name, in any letter case; nullptr when there is none
std::span<const builtin_theme_file> builtin_theme_files() the built-in theme files as the build embedded them
std::span<const theme_colour_role> theme_colour_roles() every colour role, in file order
theme_derived_roles derive_theme_roles(const theme &value) the five optional roles, derived from the theme's own colours
std::string theme_file_name(std::string_view themeName) "Deep Ocean" to "deep-ocean.conjure-theme.json"
theme_fonts resolve_theme_fonts(const theme &value, std::span<const std::string_view> available) the font families the window loads, with fallbacks
theme_colour mix_theme_colours(const theme_colour &from, const theme_colour &to, f32 amount) moves one colour towards another in sRGB
theme_colour readable_mix(const theme_colour &from, const theme_colour &to, f32 amount, const theme_colour &text, f64 minimumContrast = MIN_TEXT_CONTRAST) the same mix, pulled back until text stays readable on it
f64 theme_contrast_ratio(const theme_colour &first, const theme_colour &second) the WCAG 2 contrast ratio, 1 to 21
f64 theme_colour_difference(const theme_colour &first, const theme_colour &second) the CIEDE2000 difference
void theme_library::set_directory(std::filesystem::path directory) points the library at a themes folder and reads it
bool theme_library::rescan() the watch: reads the user themes again when a file appeared, vanished, or changed; true when it did
void theme_library::request(std::string_view name) chooses the active theme by name
const theme &theme_library::active() const the theme the editor shows
u64 theme_library::revision() const counts the changes of the active theme
core::result<std::string> theme_library::save(const theme &value) writes a user theme file and returns its name
core::result<std::string> theme_library::remove(std::string_view name) deletes a user theme file
theme_library &editor_context::themes() the editor's library, which survives project.open
void editor_context::sync_themes() applies user_settings().activeTheme and emits theme.changed when the theme changed
user_settings_load load_user_settings(const std::filesystem::path &configDirectory) reads the user settings that hold activeTheme
core::result<editor_user_settings> update_user_settings(const std::filesystem::path &configDirectory, const user_settings_change &change) changes and saves the user settings
const theme &ui::theme_applier::shown(const editor_context &context) const the theme the window shows: the preview or the active theme
void ui::theme_applier::set_preview(theme value), void clear_preview() shows a working copy, then the active theme again
bool ui::theme_applier::apply_style(editor_context &context) applies the colours and metrics when something changed
bool ui::theme_applier::load_fonts(editor_context &context) bakes the fonts again, outside a frame
void ui::apply_theme_style(const theme &value, ImGuiStyle &style, kit::stock_style stockStyle) writes a theme into an ImGui style
void ui::apply_gizmo_style(const theme_colours &roles, gizmo_highlight highlight) colours ImGuizmo
math::vec4 ui::back_buffer_colour(const theme &value) the renderer's back-buffer clear for a theme
core::result<void> ui::theme_editor_panel::set_active(editor_context &context, std::string_view name) the Theme editor's Set active
core::result<void> ui::theme_editor_panel::edit(editor_context &context, theme value) changes the working copy
core::result<std::string> ui::theme_editor_panel::save(editor_context &context) saves the working copy
core::result<std::string> ui::theme_editor_panel::import_file(editor_context &context, std::string_view path) reads a theme file and saves it as a user theme
core::result<std::filesystem::path> ui::theme_editor_panel::export_file(editor_context &context, std::string_view name, std::string_view path) writes a theme's file to a path
static bool ui::theme_editor_panel::role_may_be_translucent(std::string_view role) whether a role may have alpha

See also: