Skip to content

themes: an app can contribute its own and name the default - #1216

Open
MichaelBelousov wants to merge 2 commits into
fizzyedit:mainfrom
MichaelBelousov:app-themes
Open

MichaelBelousov wants to merge 2 commits into
fizzyedit:mainfrom
MichaelBelousov:app-themes

Conversation

@MichaelBelousov

@MichaelBelousov MichaelBelousov commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

An app built on fizzy could not ship its own themes or choose which one a fresh install starts on: the theme set was fizzy's alone (Editor registering Fizzy Dark / Light / Strawberry), and Settings.default_theme was the literal "Fizzy Dark". Graphl's port ran into exactly this (fizzyedit/graphl's report item 11) — it carries its own Graphl Dark / Light.

Two ways for an app to contribute, following -Dapp-layout:

At runtime, from a plugin (before the first frame):

  • Host.registerTheme(theme) — the editor appends the theme beside the user's and the app's, replacing an entry of the same name in place (a reloaded plugin updates its theme instead of duplicating it). The host keeps its own copy of the name and tracks the registering plugin, the way demos do; the editor pulls them in postInit — the editor's own theme apply ran in init, before any plugin existed — then re-applies font sizes and the settings theme, so a registered theme lands shaped and sized like the built-ins. Plugin reloads and web-plugin loads pull again.
  • Host.setDefaultTheme(name) — what a fresh settings store starts on. The stored setting now seeds empty ("the app decides") instead of seeding the comptime default, so a runtime default actually takes effect: the stored name is only written when the user picks, and the fallback chain at apply time is the stored name, then the runtime default, then Settings.default_theme.

At build time, for an app without plugins:

  • -Dapp-theme — a LazyPath to a file with pub fn add(gpa, themes: *std.ArrayList(dvui.Theme)) !void; the editor appends its themes beside the user's. The module wires into the executable's root, the web build, and the test module, each only when the build was given it (the editor's has_app_theme branch is comptime-off otherwise, so the import is never analyzed).
  • -Dapp-default-theme — the comptime fallback Settings.default_theme uses when no runtime default was set.

Fizzy's own build passes neither and behaves exactly as before. Verified with a smoke-test themes file and -Dapp-default-theme on the native and web builds, the full suite (with a new Host.registerTheme test mirroring registerDemo's), fmt, and lint.

Two options an app built on fizzy passes in its dependency invocation,
following `-Dapp-layout`:

`-Dapp-theme` is a LazyPath to a file with
`pub fn add(gpa, themes: *std.ArrayList(dvui.Theme)) !void`; the editor
appends its themes beside the user's, before fizzy's own, so an app's
themes sit at the top of the picker. The module wires into the
executable's root, the web build's, and the test module, each only when
the build was given it (the editor's `has_app_theme` branch is
comptime-off otherwise, so the import is never analyzed).

`-Dapp-default-theme` names the theme a fresh settings store starts
with (`Settings.default_theme`). It is a name, checked against what
the editor registers; a name nothing registered logs and falls back to
the first entry, as a stored theme that no longer exists does.
@MichaelBelousov

MichaelBelousov commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor Author

hmmm I actually wanted to do this at runtime... will try again

EDIT: done

`Host.registerTheme(owner, theme)`, called while a plugin registers:
the editor appends the theme beside the user's and the app's, replacing
an entry of the same name in place (so a reloaded plugin updates its
theme instead of duplicating it). The Host keeps its own copy of the
name and tracks the plugin, the way demos do, so the themes go with the
plugin when it retires. The editor pulls them in `postInit` (its own
theme apply ran in `init`, before any plugin existed) and again after
a web plugin loads, then re-applies the settings theme, so a registered
theme lands shaped and sized like the built-ins.

This branch was successfully deployed

1 active deployment
bridge — 14d5dbf6 Deployed Nov 15, 2026 by MichaelBelousov via bridge #4911
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant