|
Portals0.7.0 · dev (544a5c68c72e · 2026-11-28 UTC)
|
A theme supplies presentation rules and a palette. An application can install one with ui::theme:
The short guide and package setup explain how to build a client. The compact runner attempts cleanup and reports failures; declarative UI describes checked construction. The fragments below assume an open, idle scene, ui::Scene, named scene, using namespace portals;, and <portals/ui_style.hpp>.
| Factory | Appearance |
|---|---|
| modernTheme() | Modern dark palette |
| turboTheme() | Turbo-like palette |
| nordTheme() | Nord dark palette |
| gruvboxTheme() | Gruvbox dark palette |
| tokyoNightTheme() | Tokyo Night dark palette |
| catppuccinLatteTheme() | Catppuccin Latte light palette |
Factories return a StyleSheet that owns its rules and may allocate. The ui::Scene facade collects installation errors for scene.checked() or the runner. Theme changes belong between frames on the UI thread.
ThemeTokens supplies six named palette values, or theme tokens, each stored as an RgbColor:
| Token | Role |
|---|---|
| foreground | Normal and selected text |
| background | Normal fill, focused text and caret fill |
| accent | Focused fill and caret text |
| muted | Disabled text |
| selection | Selected row or editor range fill |
| heading | Header text |
The built-in rules request bold for focus, selection and headers. The caret reverses the focused field colors. Additional control-specific choices can be expressed with PSS rules. Runtime PSS v0 cannot refer to these C++ tokens by name.
Theme replacement updates THEME. APPLICATION and USER layers stay installed above it. If an application layer sets a foreground color, that declaration continues to take priority over the theme's foreground. Style precedence and layer contracts describe the details.
The repository includes themes/modern.pss and themes/turbo.pss, matching their C++ factories. Their rules can be loaded as an application layer:
Style-source stages accept APPLICATION and USER. A palette installed there can override colors from ui::theme. Current theme factories and ui::theme(StyleSheet) replace the reserved THEME slot; direct PSS-file theme loading is TBD — M5. PSS v0 has no automatic reload or theme-variable substitution. File loading is described in the styling guide.
The experimental C++ descriptor supports named RgbColor, bool and std::int32_t parameters. This setup declares a live accent:
The UI stage is the configuration object returned by ui::liveTheme(THEME); in this example it is stored as stage. Applying scene | stage attaches the controller.
After successful attachment, an event handler on the UI thread can update it:
The result is true when the value changed and false when it was already equal. An error preserves previous values and styles. mix accepts a percentage from 0 to 100. Atomic batches, exact type checks and controller lifetime are described in compile-time styles. The scene owns the controller. colors observes it without extending its lifetime. Reads and updates require the UI thread. A closed scene or superseded theme controller returns a typed error; a fresh stage is required for a new controller.
True color preserves RGB values. ANSI16 maps them to a smaller palette and can merge nearby colors. Bold, italic and underline depend on terminal support.
Canonical PSS theme sources and expanded parameters are TBD — M5. Importing external theme formats is TBD, with a milestone still to be assigned. Planned features describes these changes.