theme
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
| Function | Does |
|---|---|
light() -> Theme | The default palette: light widgets (on a dark window where nothing covers it) |
dark() -> Theme | Dark widgets: light ink on dark surfaces, the same accent |
current() -> Theme | The 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() -> i64 | How 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:
var mine: theme.Theme = theme.light();
mine.accent = #CC3366;
mine.button = #FFF4F8;
theme.set(mine);The colors every widget is drawn in (through look):
| Field | Used for |
|---|---|
ink | Text, borders and washes, drawn at the look’s alphas over the surfaces |
surface, ground, soft, soft2, soft3, pressed | Panes and dialogs, what is behind them, fields and lists, badges, hovered rows and tracks, a pressed control |
button, button_hover, button_pressed | A default button’s fill per state |
accent, accent_border, accent_hover, accent_light | Accent buttons, checked boxes, the focus ring; their border; hovered |
accent_soft, accent_text, accent_ink, select_border | The selection wash and text on it; text on the accent; a selected tile’s border |
danger, danger_strong, danger_hover | Destructive buttons, an error ring, error badges |
warn, warn_text, ok, ok_text, info, info_text | Status dots, badges and bars |
term_bg, term_fg, term_err | A terminal’s ground and text |
viewer_bg | What 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:
| Field | Used for |
|---|---|
window | Behind the tree, in a window and in ui.headless (a window’s ui.Window.background wins) |
text, text_size | A styled TextInput’s text; the text size the older widgets used (the widgets’ text is on their type scale) |
placeholder, muted, selection | A TextInput’s placeholder, secondary text, selected text |
accent, accent_border, on_accent, check | A checked Checkbox, a pressed Button’s ring, text on a colored Button, the check mark |
focus | A focused TextInput’s border; ProgressBar and Slider fill |
button, button_hover, button_pressed | A Button’s fill per state |
button_border, button_hover_border, button_disabled_border, button_text | Its border and text |
field, field_border, field_hover_border | TextInput and Checkbox boxes, a Slider’s thumb |
track | ProgressBar and Slider tracks |
scroll_thumb, image_bg | An 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:
#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: