3.8 KiB
AGENTS.md — Theming repo guide for AI agents
This is a Makepad 2.0 demo of runtime theme swapping. Read this before editing the codebase.
What this repo is
A small desktop app that shows how to push Rust-side state (theme + i18n)
into a Makepad 2.0 ScriptVm and have the whole UI re-skin live. It is
not a Makepad Studio plugin — it's a standalone Cargo binary that
depends on makepad-widgets from git.
Key files
| File | Role |
|---|---|
src/main.rs |
App struct, MatchEvent, AppMain, and the script_mod! UI |
src/theme.rs |
ThemeState enum, system detection, JSON persistence |
src/i18n.rs |
LanguageState enum + apply_to_vm |
src/streem_theme/mod.rs |
The four theme palettes + s_themes slot |
src/streem_theme/{colors,shapes,typography}.rs |
Token vocabularies registered on the VM |
src/streem_i18n/mod.rs |
EN + SW string tables + s_i18n slot |
splash/theme_gallery.splash |
Standalone Splash script using the same palette |
The runtime swap pattern
The Rust side never touches widget properties directly. Instead:
ThemeState::apply_to_vm(vm)reassignsmod.streem_theme.s_themesviascript_eval!.App::reload_ui_from_rust_statere-runsscript_modand applies it withApply::Reload, which re-evaluates everydraw_bg.color: color_bgetc. in the tree.self.ui.redraw(cx)triggers a repaint.
The same pattern is used for LanguageState → mod.streem_i18n.s_i18n.
Common edits
Add a new theme
- Add a variant to
ThemeStateinsrc/theme.rs. - Add a palette to
mod.streem_themeinsrc/streem_theme/mod.rs. - Add a
themes.<name>alias in the same file. - Add a
Self::Variant => script_eval!(...)arm inThemeState::apply_to_vm. - Update
ThemeState::toggled()to include the new variant in the cycle. - Update the tests in
src/theme.rs.
Add a new i18n key
- Add the key to both
enandswblocks insrc/streem_i18n/mod.rs. - Use it in the UI via
text: <key>(withuse mod.streem_i18n.s_i18n.*at the top of thescript_mod!block). - If the key name collides with a widget
:=name, rename the i18n key (prefix withbtn_,section_, etc.).
Change a theme color
Edit the palette in src/streem_theme/mod.rs. If the same color appears in
splash/theme_gallery.splash, update it there too.
Gotchas
script_mod!blocks in submodule files must be registered. The v0.1 bug was thatcolors.rs,shapes.rs, andtypography.rsdeclaredscript_mod!blocks but were never called fromAppMain::script_mod. v0.2 fixes this by giving each apub fn script_mod(vm)that runsscript_eval!, called from the top-levelstreem_theme::script_mod.Systemmust be resolved beforeapply_to_vm. The Splash side never sees aSystemvalue — only the resolvedLightorDarkpalette.new_batch: trueis required on any View withshow_bg: truethat contains text children. Without it, text renders behind the background.- Default text color is white. For light themes, set
draw_text.colorto a dark color on every text widget. - Hex colors containing
eadjacent to digits need the#xprefix insidescript_mod!to avoid parse errors. E.g.#x1E293Bnot#1E293B.
Running
just run # or: cargo run
just test # runs the ThemeState and LanguageState unit tests
just ci # fmt-check + clippy + test (what CI runs)
The Makepad git dependency requires a recent Rust toolchain and, on Linux, the usual X11/ALSA/pkg-config dev packages (see README).
Splash reference
For the full Makepad 2.0 Splash scripting manual, see the splash.md
file in the Makepad monorepo at tools/splash.md or the Makepad docs.
The key rules: height: Fit on every container, width: Fill on the
root, := for named children, no commas between properties.