theme

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
var ErrUnsupported = platform.ErrUnsupported

ErrUnsupported is platform.ErrUnsupported, re-exported for callers outside the module.

Functions

func AccentCSS

func AccentCSS(c uint32) string

AccentCSS 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) 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

func SyncPage(a *tango.App) error

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
)

type Theme

type Theme = platform.Theme

Theme 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.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL