theme
import "github.com/tangoui/tango/sys/theme"本页由
site/tools/apigen从源码注释生成(按 darwin 构建标签选文件),请勿手改。
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.
变量
var ErrUnsupported = platform.ErrUnsupportedErrUnsupported is platform.ErrUnsupported, re-exported for callers outside the module.
函数
func AccentCSS
func AccentCSS(c uint32) stringAccentCSS formats a 0xRRGGBBAA color as #rrggbbaa; "" for 0.
func OnChange
func OnChange(a *tango.App, fn func(Theme))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) errorSetAppearance 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
func SyncPage(a *tango.App) errorSyncPage 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.
类型
Appearance
type Appearance stringAppearance 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
)Theme
type Theme = platform.ThemeTheme is the system appearance. Accent is 0xRRGGBBAA, 0 when the platform has none or does not say.
func System
func System(a *tango.App) (Theme, error)System returns the current system theme.