Documentation
¶
Overview ¶
Package theme reads the system's light/dark appearance and accent color and follows their changes.
System and OnChange report what the operating system uses; the WebView already applies prefers-color-scheme to pages. SyncPage additionally mirrors the theme into every page as data attributes and a CSS variable, for styles that need the accent color or a selector to hang on:
<html data-tango-theme="dark" style="--tango-accent: #0a84ffff">
Functions are safe from any goroutine once the app runs. System returns ErrUnsupported when the backend cannot read the theme and tango.ErrNotRunning after the app quit.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrUnsupported = platform.ErrUnsupported
ErrUnsupported is platform.ErrUnsupported, re-exported for callers outside the module.
Functions ¶
func OnChange ¶
OnChange calls fn on the main thread with the new theme whenever the user switches between light and dark or changes the accent color.
func SetAppearance ¶
func SetAppearance(a *tango.App, ap Appearance) error
SetAppearance forces the whole app light or dark — window title bars and traffic lights, menus, system controls and the pages' prefers-color-scheme — or, with AppearanceSystem, lets it follow the system again. While forced, System and OnChange (and so SyncPage and uivars) report the forced look, as if the system had switched.
Supported on macOS (NSApp.appearance); elsewhere it returns ErrUnsupported and the window keeps the system look. Safe from any goroutine; returns tango.ErrNotRunning after the app quit.
func SyncPage ¶
SyncPage keeps document.documentElement of every page in step with the system theme: the attribute data-tango-theme is "dark" or "light", and the CSS variable --tango-accent holds the accent color (#rrggbbaa) when known. Pages can also listen for the "tangotheme" event on window, whose detail is {dark, accent}.
Call it before creating surfaces (it adds a bridge script). Pages that exist are updated on every change; every page that loads later — in a new surface or after a navigation — gets the current theme, accent included, when it has loaded (until then light/dark follows prefers-color-scheme). It returns ErrUnsupported when the backend cannot read the theme; the attribute then still follows prefers-color-scheme.
Types ¶
type Appearance ¶
type Appearance string
Appearance is the look SetAppearance forces on the app.
const ( AppearanceSystem Appearance = "" // follow the system (the default) AppearanceLight Appearance = "light" // always light AppearanceDark Appearance = "dark" // always dark )
Directories
¶
| Path | Synopsis |
|---|---|
|
Package uivars injects the design tokens of Tango's self-drawn UI (ui/theme) into every WebView page as CSS custom properties, and keeps them in step with the system's light/dark appearance, so the pages of an app and its self-drawn windows look the same.
|
Package uivars injects the design tokens of Tango's self-drawn UI (ui/theme) into every WebView page as CSS custom properties, and keeps them in step with the system's light/dark appearance, so the pages of an app and its self-drawn windows look the same. |