use theme::{AppExt as _, Theme, appearance::{self, AppearanceMode}};
cx.set_palette(|appearance| { // optional: your own tokens
let mut theme = Theme::for_appearance(appearance);
theme.danger = my_red(appearance);
theme
});
appearance::init(saved_mode, cx); // once, before the first window
let theme = Theme::of(cx);
div().bg(theme.surface).text_color(theme.text_muted)appearance::initruns once at boot, before any window opens; later, the first frame paints the wrong palette.- Change tokens through
set_palette. A light/dark switch rebuilds from the registered builder, so a palette installed withTheme::install_customlasts only until then. Registered afterinit, follow it withappearance::apply(cx). - Under
AppearanceMode::System, each window needsappearance::observe_window(window, cx).detach()to follow the OS. AppearanceModeis serde-serializable; persisting it is the app's job.cx.set_appearance_mode(mode)changes it at runtime.