Hazel

Theming

How editor and game UI get their colours: the process-wide palette, the per-widget style resource, the theme files that feed both, and the game widget kit's own theme.

The layers

LayerWhere it livesRepaints
Palette and SyntaxPaletterenzora_ember::theme, process-wide staticsNo. Read when a widget spawns, so a switch re-spawns the chrome.
style::Themerenzora_ember::style, a ResourceYes. apply_theme repaints every Styled widget when it changes.
Theme files and the active themerenzora_theme::ThemeManager, editor onlyFeeds the two above through the shell's theme_bridge.
UiThemerenzora_ember::game_ui::components, a ResourceYes. ui_theme_system repaints UiThemed game widgets.

All colours are Bevy Color, or the hex-serialized Rgba (ember) and ThemeColor (renzora_theme) wrappers. Custom themes live in the project's themes/ folder.

The palette: renzora_ember::theme

Palette is one value per process, held in a LazyLock<RwLock<..>>. Builder functions only get &mut Commands, so they resolve colours through accessor functions instead of threading a resource through every signature:

use renzora_ember::theme::{panel_bg, rgb, text_primary};

commands.spawn((
    Text::new("Hello"),
    TextColor(rgb(text_primary())), // rgb((u8, u8, u8)) -> Color
    BackgroundColor(rgb(panel_bg())),
));

There is one accessor per field: window_bg, panel_bg, faint_bg, header_bg, tab_active, tab_hover, close_red, divider, text_primary, text_muted, placeholder, play_green, warn_amber, accent, on_accent, border, popup_bg, row_even, row_odd, value_text, selection, section_bg, hover_bg, card_bg and tree_line, plus menu_hover_bg() (a Color). rgba([u8; 4]) and mix(a, b, t) help with derived colours.

The built-in defaults, for orientation:

AccessorDefaultUsed for
window_bg()(11, 12, 17)Chrome: top bar, status bar, the gutters between panels
panel_bg()(19, 21, 28)Panel content
header_bg()(23, 26, 34)Tab bars
accent()(84, 124, 214)Primary buttons, active indicators
text_primary() / text_muted()(230, 233, 239) / (139, 147, 167)Body text / labels and hints
border()(38, 43, 56)Input and panel borders
selection()(36, 50, 84)Selected rows
play_green() / warn_amber()(89, 191, 115) / (242, 166, 64)Success / warning

Because the accessors are read at spawn, setting a new palette does not recolour widgets already on screen. The shell handles that on a theme switch by re-spawning its chrome (see the bridge below). Panel content is rebuilt on every activation anyway (see Editor Panels).

use renzora_ember::theme::{palette, set_palette, Palette};

// The bridge does this; you rarely need to.
set_palette(Palette { accent: (0, 255, 200), ..palette() });

renzora_ember::theme also holds a StyleSheet (per-widget geometry and typography, read with style(Role) and set with set_stylesheet) under its own theme::Role enum. It is a separate enum from style::Role below; do not mix them up when importing.

Syntax colours: SyntaxPalette

The code editor widget resolves token and chrome colours through a second process-wide palette, SyntaxPalette (set_syntax_palette, syntax_palette()). That keeps the widget independent of renzora_theme: the bridge pushes colours in. They come from a theme's [syntax] section:

GroupKeys
Tokensnormal, keyword, type, function, number, string, comment, operator, constant, punctuation
Chromeline_number, line_number_active, current_line, selection, cursor, indent_guide, bracket_match, find_match

Chrome colours that overlay text should carry alpha (#RRGGBBAA). Editing them in the Settings Theme tab recolours the open code editor live.

The style resource: renzora_ember::style

style::Theme is a Reflect and Serde resource holding one StyleToken per widget Role. Unlike the palette it repaints live: style::ThemePlugin (part of EmberRuntimePlugin) runs apply_theme and apply_themed_text whenever the resource changes or a widget's Styled changes.

use renzora_ember::style::{Role, Styled};

commands.spawn((
    Node { padding: UiRect::all(Val::Px(8.0)), ..default() },
    BackgroundColor::default(),    // apply_theme fills this
    BorderColor::all(Color::NONE), // and this
    Styled::new(Role::Button),
));

apply_theme writes the token's bg_for(state) into BackgroundColor, border_for(state) into BorderColor if present, and the border width, radius and padding into Node. A node that sets its own padding should carry StyleOwnsPadding, so the theme leaves its padding alone.

  • WidgetState: Normal, Hover, Pressed, Active (selected, on or focused), Disabled. Set it from your interaction system; see Widgets.
  • Role: Button, ButtonAccent, IconButton, Input, Checkbox, Segment, Toggle, Card, Badge, Alert, Toast, Tab, Panel, Menu. Theme::token(role) returns the token.
StyleToken fieldTypeMeaning
bg, bg_hover, bg_pressed, bg_active, bg_disabledRgbaFill per state
border, border_activeRgbaBorder, and the focus border
border_width, radiusf32Logical px
pad_x, pad_yf32Inner padding, logical px
text, text_mutedRgbaForeground colours
weightf32Variable-font weight of the widget's text (400 is normal)
letter_spacingf32Logical px; 0 is the font's default
line_heightf32Multiple of the font size

apply_themed_text applies the three typography fields to the text directly under each themed widget. Font size is deliberately not in the token: it stays with each ui_font(.., size) call and the user's UI scale, so theme typography never fights existing sizing.

Beside the per-role tokens, Theme has styles for elements made of several parts: node_graph, asset_tile, dock (DockStyle), top_bar, doc_tabs and status_bar (BarStyle), and timeline (TimelineStyle). These let a theme restyle, say, a node-graph cable without touching every other widget.

Rgba serializes to and from #RRGGBB or #RRGGBBAA; Rgba::rgb((r, g, b)) builds an opaque one and .color() converts it to a Bevy Color.

Dock panels are cards

DockStyle's defaults draw each panel as a rounded card on the window background: leaf_margin 0.5, leaf_radius 4.0, leaf_border_width 1.0, header_radius 4.0. Three things depend on each other here, so a theme that changes one should check the others:

  • leaf_margin is the separator, so divider defaults to transparent. The gutter already shows the window background, and a line down its middle reads as a seam. The divider stays draggable (its grab strip is unaffected). A theme that sets leaf_margin to 0.0 must give divider a colour, or flush panels have no visible boundary.
  • leaf_padding is a different thing. It insets a panel's content from its own edge, which would stop the viewport filling its card.
  • A rounded leaf does not round its children. bevy_ui clips to a plain rectangle, so each node must round itself. That is why header_radius exists beside leaf_radius, and why the viewport rounds its own bottom corners. A panel whose content colour differs from leaf_bg has to do the same.

shadow = true adds a drop shadow under each card. It is off by default because it costs a pass.

Theme files

Custom themes live in the project's themes/ folder, as a flat themes/<Name>.toml or a folder themes/<Name>/theme.toml. A folder wins over a flat file of the same name, and is the form that can ship assets beside the colours: chrome shaders ([effects]), images ([images]) and a UI font ([fonts] ui), each path relative to the folder.

One TOML holds two kinds of section, and each loader reads only its own:

  1. Colour sections ([meta], [semantic], [surfaces], [text], [widgets], [panels], [categories], [material], [viewport], [syntax], [effects], [images], [fonts]), parsed into renzora_theme::Theme by ThemeManager. The bridge maps them into the palettes.
  2. Per-widget sections ([button], [input], [dock], [node_graph], ...), parsed into renzora_ember::style::Theme by Theme::from_toml.

Theme::from_toml deep-merges the file over the defaults, so a theme only names what it overrides: a whole [button] table, or a single button.bg.

# themes/Cyberpunk.toml
[meta]
name = "Cyberpunk"

[semantic]
accent  = "#00FFC8"
success = "#00FF64"
warning = "#FFC800"
error   = "#FF3250"

[surfaces]
window = "#0A0514"
panel  = "#140A23"
popup  = "#1E1432"

[text]
primary = "#DCDCFF"
muted   = "#9696C8"

[syntax]
keyword   = "#FF3250"
selection = "#4F8CFF4D"

[button]
bg         = "#1E1432"
bg_hover   = "#2A1E46"
bg_pressed = "#00FFC8"
radius     = 6.0

[dock]
leaf_radius = 8.0
shadow      = true

Colours are hex strings (#RRGGBB, or #RRGGBBAA for alpha); sizes are floats in logical px. A section you leave out keeps its default.

ThemeManager

renzora_theme::ThemeManager is an editor resource, initialized by renzora_editor_framework. It owns discovery, the active theme and saving. The Settings Theme tab edits active_theme live; the status bar's theme switcher (renzora_theme_status) calls load_theme.

Field or methodPurpose
active_theme: ThemeThe live colour sections
active_theme_name: StringIts name
available_themes: Vec<String>"Dark", "Light", then custom themes
has_unsaved_changes: bool, mark_modified()Dirty tracking
set_project_path(&Path), scan_themes()Point at a project and list themes/
load_theme(name) -> boolActivate a built-in or custom theme
active_theme_dir() -> Option<&Path>The folder of a folder theme, for resolving its assets
save_theme(name), duplicate_theme(new_name), delete_theme(name)File management; built-ins cannot be deleted
is_builtin(name)true for Dark and Light

The only built-in editor themes are Dark and Light. On wasm there is no themes/ folder to scan, so only those two are listed.

The bridge

renzora_shell::theme_bridge::theme_bridge connects the layers. It runs only on a frame where ThemeManager changed or a file inside the active theme's folder changed (ThemeFilesRevision, bumped from the project watcher), and each step is gated on a fingerprint of its own inputs:

  • It maps active_theme into a Palette with palette_from_theme (for example surfaces.window to window_bg, surfaces.panel to panel_bg, surfaces.extreme to header_bg, semantic.accent to accent) and pushes it with set_palette. Translucent theme colours are blended over the panel colour, since the palette holds opaque RGB.
  • It maps [syntax] with syntax_from_theme into set_syntax_palette, separately, so a syntax-only edit does not touch the main palette.
  • It applies the theme's chrome shaders, images and UI font when they change.
  • On a switch, it inserts a freshly built style::Theme, despawns ShellRoot so the chrome re-spawns in the new colours, and cancels any pending DockDirty. The order matters: a dock rebuild requested in the same frame would run against a despawned tree.

Individual colour edits update the palette without re-spawning, which would close the colour picker being dragged.

The per-widget style::Theme built on a switch is read from themes/<Name>.toml only. A folder theme's theme.toml supplies colours, effects and fonts, but its per-widget sections are not applied in the editor today.

A game's theme

A game is drawn in the theme its project's ui_theme setting names: Dark, Light, or a theme in the project's themes/ folder (flat or folder form). renzora_ember::game_theme applies it, in a game only:

  • it maps the file through palette_from_theme and syntax_from_theme, inserts the style::Theme parsed from the same file, and sets the game widget kit's UiTheme from it, so every widget kit a game uses agrees;
  • then it rebuilds every markup screen (markup::template::rebuild_all), since widgets take their colours when spawned. Widgets a script built itself keep their colours until the script builds them again.

It skips the editor because the palette is one value per process and the editor's chrome is drawn from it; templates shown in the editor use the editor's theme. GameThemes (the list of names) is kept in both, so a <dropdown setting="ui_theme" /> offers the same list in the editor as in the game.

A packed game has no folder to list, so the runtime copies every themes/**.toml from the archive into ProjectThemeSources (renzora_project_api) at startup, and the exporter packs them all (project_theme_keys in renzora_rpak). Only the TOML ships; a folder theme's shaders and images paint editor chrome.

The game widget kit: UiTheme

The game widget kit (renzora_ember::game_ui, installed by GameUiPlugin) has its own flat theme of semantic tokens, the UiTheme resource. Widgets opt in with the UiThemed marker and must also carry a UiWidget, because ui_theme_system styles each one by its UiWidget::widget_type.

use bevy::prelude::*;
use renzora_ember::game_ui::components::UiTheme;

fn use_custom_ui(mut commands: Commands) {
    commands.insert_resource(UiTheme {
        accent: Color::srgb(0.0, 0.85, 0.6),
        health_fill: Color::srgb(0.2, 0.8, 0.2),
        ..UiTheme::dark()
    });
}

UiTheme::dark() is the default; UiTheme::light() and UiTheme::high_contrast() are the other built-ins. The tokens cover surfaces, text, interactive and semantic colours, widget colours (track, thumb, progress and health fills, toggles, tooltip, modal backdrop, title bar), font sizes and geometry; see the struct in game_ui/components/theme.rs for the full set.

When UiTheme changes, ui_theme_system re-derives each themed widget's style components (UiFill, UiStroke, UiTextStyle and the rest) and its per-widget colours. UiTheme follows the project's ui_theme whenever that is set; a resource inserted from code holds until ui_theme next changes. Authoring game UI is covered in Game UI.