ui/theme_app.rs#
Source: lib/ui/theme_app.rs
theme_app -- app themes: the active style's tokens overridden from a small text file
Theme::from_ini(text) -> Result<Theme, ThemeError> parse a theme (the format below)
Theme::load(path) -> Result<Theme, ThemeError> ... from a file (app://, config://, a
path); relative font files are taken from the theme's folder
theme.to_ini() -> String / theme.save(path) -> bool the text form of what the theme sets
token_index(name) -> Option<usize> the T_* index (token / 4) of a token name ("bg")
TOKEN_NAMES, TS_NAMES the names of the tokens and of the text styles
The format is INI (base::ini):
[theme] name = the theme's name
[colors] TOKEN = #RRGGBB | #AARRGGBB for light and dark; [light], [dark] for one of
them, [contrast] for high contrast (on top of the scheme's colours). TOKEN is
a T_* name in lower case (bg, card, ctrl_stroke, text2, accent_text, ...);
accent is the colour the style derives its accent ramp from (as accent_set;
high contrast: the accent fills)
[metrics] radius = DIP | PERCENT% rounded corners that are not pills (0: square)
spacing = PERCENT% padding and gaps of boxes and grid boxes
control_height = DIP buttons, text boxes, combo boxes, drop-down and split
buttons (not compact or large ones)
[text] family = FILE | installed family (family.semibold, family.bold: their faces;
else from the family: a file gets a synthetic bold, a variable one its wght);
family.axes = TAG=VALUE, ... axis values of a variable family (wdth=87.5,
opsz=12; weights still come from the faces' 400 / 600 / 700, opsz else 11 pt);
STYLE.size = DIP (24.8), STYLE.line = DIP, STYLE.weight = regular | semibold |
bold | 100..900 for STYLE in caption, body, body_strong, subtitle, title,
title_large, display
Errors name the line (in the UI language): an unknown section or key, a line without '=',
a key before the first section or twice in one section, a value out of range. A theme is
applied whole or not at all (Ui::set_theme).
/// Theme::colors / accent index: the light theme
THEME_LIGHT: usize = 0
/// ... the dark theme
THEME_DARK: usize = 1
/// ... high contrast
THEME_CONTRAST: usize = 2
/// the T_* tokens by name, in token order (index = token / 4); theme files write them in
/// lower case
TOKEN_NAMES: [&str; T_COUNT] = [ "BG", "BG_ALT", "LAYER", "LAYER_STROKE", "CARD", "CARD_ ...
/// the TS_* text styles by name (theme files: body.size, title.weight)
TS_NAMES: [&str; TS_COUNT as usize] = ["caption", "body", "body_strong", "subtitle", "title", " ...
fn token_index(name: &str) -> Option<usize>the T_* index of a token name (any case, "T_" in front allowed)enum Radiusrounded corners of a theme: every corner radius that is not a pill becomes this many DIP, or the style's radius scaled by this percentageDip(u16)Percent(u16)
struct TextStylea text style of a theme: size in DIP (24.8), line height in DIP, weight 100..900; None = the style's (a size alone scales the style's line height with it)size_fx: Option<u16>line: Option<u16>weight: Option<u16>
struct Themean app theme (see the module header); Default = nothing overriddenname: Stringcolors: [[Option<u32>; T_COUNT]; 3]-- colour tokens per THEME_LIGHT / _DARK / _CONTRAST (index token / 4), 0xAARRGGBBaccent: [Option<u32>; 3]-- the accent per mode, 0xRRGGBB: the style derives its accent ramp from itradius: Option<Radius>spacing: u16-- box padding and gaps in percent (100: the app's values)control_height: u16-- DIP; 0 = the style'stext: [TextStyle; TS_COUNT as usize]family: String-- "" = the style's faces; a font file (VFS path) or an installed familyfamily_semibold: Stringfamily_bold: Stringfamily_axes: Vec<([u8; 4], f32)>-- axis values of a variable family (tag, user units); empty: its defaults
struct ThemeErrorwhy a theme could not be read or applied: the line of the file (0: not a line) and the message in the UI language ("Zeile 4: ...")line: u32msg: String
impl Theme
fn from_ini(text: &str) -> Result<Theme, ThemeError>parse a theme file's text (module header); every error names its linefn load(path: &str) -> Result<Theme, ThemeError>read and parse a theme file; relative font files then name files in its folderfn to_ini(&self) -> Stringthe theme as the text of a theme file (only what it sets)fn save(&self, path: &str) -> boolwrite the theme file (missing folders are made) -> written