theme

tape
import theme from "theme";

theme.set(theme.dark());      // every widget paints with the dark palette from the next frame
theme.reset();                // back to the default, theme.light()

theme holds the palette the widgets, look and ui paint with: the ink, surfaces, accent and status colors every control is drawn in, the colors of widgets you style yourself, and the window behind them. A widget uses the active theme for every color prop you leave at its zero value (#00000000) and for a size of 0, each time it paints. So switching the theme changes every such widget on the next frame; a color you set yourself, at the instantiation or with a #style rule, stays.

Themes

FunctionDoes
light() -> ThemeThe default palette: light widgets (on a dark window where nothing covers it)
dark() -> ThemeDark widgets: light ink on dark surfaces, the same accent
current() -> ThemeThe active theme: light() until set
set(t: Theme)Make t the active theme; windows and headless screens paint their next frame with it
reset()Back to light()
version() -> i64How many times set/reset changed the theme (ui repaints everything when it changes)

Theme is a plain struct, so a theme of your own is a copy with some fields changed:

tape
var mine: theme.Theme = theme.light();
mine.accent = #CC3366;
mine.button = #FFF4F8;
theme.set(mine);

The colors every widget is drawn in (through look):

FieldUsed for
inkText, borders and washes, drawn at the look’s alphas over the surfaces
surface, ground, soft, soft2, soft3, pressedPanes and dialogs, what is behind them, fields and lists, badges, hovered rows and tracks, a pressed control
button, button_hover, button_pressedA default button’s fill per state
accent, accent_border, accent_hover, accent_lightAccent buttons, checked boxes, the focus ring; their border; hovered
accent_soft, accent_text, accent_ink, select_borderThe selection wash and text on it; text on the accent; a selected tile’s border
danger, danger_strong, danger_hoverDestructive buttons, an error ring, error badges
warn, warn_text, ok, ok_text, info, info_textStatus dots, badges and bars
term_bg, term_fg, term_errA terminal’s ground and text
viewer_bgWhat a photo is shown on

Every field has a default (the light palette), so a Theme literal names only what it changes: theme.Theme { accent: #CC3366; } is light() with another accent.

The colors of a widget you give a color of your own (a bg, a hovered_bg), for the parts you didn’t give, and of ui:

FieldUsed for
windowBehind the tree, in a window and in ui.headless (a window’s ui.Window.background wins)
text, text_sizeA styled TextInput’s text; the text size the older widgets used (the widgets’ text is on their type scale)
placeholder, muted, selectionA TextInput’s placeholder, secondary text, selected text
accent, accent_border, on_accent, checkA checked Checkbox, a pressed Button’s ring, text on a colored Button, the check mark
focusA focused TextInput’s border; ProgressBar and Slider fill
button, button_hover, button_pressedA Button’s fill per state
button_border, button_hover_border, button_disabled_border, button_textIts border and text
field, field_border, field_hover_borderTextInput and Checkbox boxes, a Slider’s thumb
trackProgressBar and Slider tracks
scroll_thumb, image_bgAn empty Image’s border; behind an Image’s src

A ui.ScrollArea’s scrollbars are drawn by look, in the palette’s soft, ink and accent, like every widget’s.

The palette in #style

The light palette is also a set of constants in theme’s #style region, for your own style rules:

tape
#style
import theme from "theme#style";

Toolbar {
    widgets.Button { bg: theme.accent; }
}

These are compile-time values: a rule with theme.accent keeps the light accent after theme.set(theme.dark()). Leave a prop unset to have it follow the active theme.

See the example stdlib/examples/theme.tape.

Last modified: