uivars
import "github.com/tangoui/tango/sys/theme/uivars"本页由
site/tools/apigen从源码注释生成(按 darwin 构建标签选文件),请勿手改。
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.
The variables are those of (*ui/theme.Theme).CSSVars, whatever the theme exports, in one rule
:root { --tango-color-primary: #1677ff; ... }
held by <style id="tango-ui-vars"> placed first in the document, so the page's own stylesheets can still override them. Pages read them with var(--tango-color-primary) and may listen for the "tangouivars" event on window (detail: the name → value map); window.__tangoUIVarsState holds the current map. runtime-js exposes both as Theme.vars and Theme.onVarsChange.
This lives outside sys/theme so that WebView-only apps using sys/theme do not link package ui.
函数
func Default
func Default(sys systheme.Theme) *uitheme.ThemeDefault is the Gen used for a nil one: theme.AntDesign, dark when the system is.
func Refresh
func Refresh(a *tango.App)Refresh regenerates the variables with the generator given to SyncPage and pushes them to every page, for a generator whose answer depends on app state (the app switched its theme by hand). Safe from any goroutine; it does nothing before SyncPage or when the backend cannot read the system theme.
func SyncPage
func SyncPage(a *tango.App, gen Gen) errorSyncPage makes every page of a get the variables of gen's theme (Default when gen is nil) and updates them whenever the system theme changes. Call it once, before creating surfaces: it adds a bridge script that sets the variables at document start — the light or dark variant by prefers-color-scheme, built with gen at the time of the call — so pages do not flash unstyled; once a page has loaded it gets the exact variables for the current system theme (accent color included).
With an app that cannot read the system theme it returns systheme.ErrUnsupported; pages then keep the document-start variables, which still follow prefers-color-scheme. A second call for the same app only replaces gen.
To keep pages in step with a self-drawn window, pass the window's generator, e.g. uihost.Options.ThemeFor.
func Vars
func Vars(th *uitheme.Theme) map[string]stringVars returns the variables uivars injects for th: th.CSSVars(), or an empty map for nil.
类型
Gen
type Gen func(sys systheme.Theme) *uitheme.ThemeGen returns the theme to export while the system appearance is sys; nil removes the variables.