theme

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: MIT Imports: 5 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 is Flatte's design system as data: the colors of a light and a dark palette, and the type, spacing, size, radius and stroke scales every component shares. Renderers resolve layout's roles through it — a window in points, a terminal in cells — so an app that names roles (layout.Fill, layout.TextStyle.Color) looks finished without choosing a color or a size.

Most apps use Default. An app with an identity turns the seeds — accent, density, roundness — with With; any single token can then be set on the Theme value directly. Check reports text and controls that no longer reach their contrast floor after such changes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contrast

func Contrast(fg, bg color.NRGBA) float64

Contrast is the WCAG 2 contrast ratio of two colors, 1 to 21; a translucent fg is first composited over bg.

func Hex

func Hex(s string) color.NRGBA

Hex is a color written #rgb, #rrggbb or #rrggbbaa (the # is optional). A malformed string is opaque magenta, so a typo shows instead of hiding.

func Mix

func Mix(a, b color.NRGBA, t float64) color.NRGBA

Mix is a and b mixed in OKLab, t of the way from a to b.

func Over

func Over(c, bg color.NRGBA) color.NRGBA

Over is c composited over an opaque bg: what a translucent wash looks like on that surface (a terminal paints only opaque cells).

Types

type Density

type Density int

Density scales the shared sizes and the middle spacing steps.

const (
	Regular Density = iota
	Compact
	Comfortable
)

type DiffColors

type DiffColors struct {
	Add, AddWord, Del, DelWord color.NRGBA
	Fold, Blank                color.NRGBA
}

DiffColors are a diff's line and word backgrounds.

type Pair

type Pair struct{ Light, Dark color.NRGBA }

Pair is one value per appearance.

type Palette

type Palette struct {
	// Canvas is the window ground behind the panes; it holds no text.
	Canvas color.NRGBA
	// Chrome is headers, sidebars, pane headers and the status bar — the
	// translucency material in a window.
	Chrome color.NRGBA
	// Content is where work is read: editors, terminals, diffs, lists,
	// pages.
	Content color.NRGBA
	// Field is text fields and segmented-control tracks.
	Field color.NRGBA
	// Raised is popovers, menus and alerts (always with Shadow).
	Raised color.NRGBA

	Text          color.NRGBA // body text, names, values
	TextSecondary color.NRGBA // paths, descriptions, metadata, inactive tabs
	TextMuted     color.NRGBA // gutters, captions, placeholders: on Chrome and Content only
	TextDisabled  color.NRGBA // disabled controls (no contrast floor)
	OnAccent      color.NRGBA // text and icons on an Accent fill

	Accent      color.NRGBA // the action color: primary buttons, active-tab edge, links
	AccentHover color.NRGBA // a primary button under the pointer
	Focus       color.NRGBA // the keyboard focus ring
	Hover       color.NRGBA // translucent wash under the pointer
	Pressed     color.NRGBA // translucent wash while pressed, or toggled on

	SelectionActive   color.NRGBA // the selected row in the focused pane
	SelectionInactive color.NRGBA // the selected row in a pane without focus
	TextSelection     color.NRGBA // selected text
	Match             color.NRGBA // a find or quick-open match, behind text
	CurrentLine       color.NRGBA // the caret's line in an editor

	Divider       color.NRGBA // pane separators and header rules
	ControlBorder color.NRGBA // field and toggle outlines

	Info, InfoTint       color.NRGBA // working, informational
	Success, SuccessTint color.NRGBA // ready, passed, added
	Warning, WarningTint color.NRGBA // needs the user
	Danger, DangerTint   color.NRGBA // errors, removed, destructive

	Diff   DiffColors
	Syntax SyntaxColors

	// Shadow is the one elevation (popovers): its color; the geometry is
	// the renderer's (a terminal draws a border instead).
	Shadow color.NRGBA

	// ANSI is the 16-color palette embedded terminals draw program output
	// in (0–7 normal, 8–15 bright).
	ANSI [16]color.NRGBA
}

Palette is one appearance's colors. Surfaces hold content; Text* read on every surface unless noted; washes (Hover, Pressed) are translucent and go over whatever surface is below.

type Problem

type Problem struct {
	Appearance string // "light" or "dark"
	Fg, Bg     string // the palette fields
	Ratio      float64
	Need       float64
}

Problem is a color pair below its contrast floor.

func (Problem) String

func (p Problem) String() string

type Radii

type Radii struct {
	Sm float64 // rows, tabs, badges
	Md float64 // buttons, fields, toggles, segmented controls
	Lg float64 // popovers, alerts
}

Radii are corner radii in points.

type Roundness

type Roundness int

Roundness sets the corner radii.

const (
	Subtle Roundness = iota
	Square
	Round
)

type Seeds

type Seeds struct {
	// Accent sets Accent and Focus per appearance, and derives
	// AccentHover, SelectionActive, TextSelection, Info and Syntax.Func
	// from it.
	Accent    *Pair
	Density   Density
	Roundness Roundness
}

Seeds are the few choices an app makes for an identity; zero values keep the theme's own (Regular, Subtle, its accent).

type Sizes

type Sizes struct {
	Row     float64 // list, tree, quick-open and tab rows
	Control float64 // buttons, fields, segmented controls
	Bar     float64 // pane headers, tab strips, toolbars
	Header  float64 // the window header strip
	Icon    float64 // icons in rows, tabs and buttons
	Popover float64 // the widest a centered popover gets
}

Sizes are the heights components share, in points.

type Strokes

type Strokes struct {
	Divider, Control, Focus float64
}

Strokes are line widths in points.

type SyntaxColors

type SyntaxColors struct {
	Keyword, String, Comment, Number, Type, Func color.NRGBA
}

SyntaxColors are code highlighting colors, checked against Content, CurrentLine and both diff line fills.

type TextSpec

type TextSpec struct {
	Size, Line float64
	Weight     int
	// Tracking is letter spacing in ems (captions).
	Tracking float64
}

TextSpec is one type style.

type Theme

type Theme struct {
	Light, Dark Palette

	// Type is the type scale.
	Type TypeScale
	// Space is the spacing scale, Space[0] … Space[5] in points (space-1 …
	// space-6 in the design docs): 4, 8, 12, 16, 24, 32 by default.
	Space [6]float64
	// Size holds the fixed heights every component shares.
	Size Sizes
	// Radius is the corner scale.
	Radius Radii
	// Stroke is the line widths.
	Stroke Strokes
	// Fonts are the UI and mono families ("": the system's).
	Font, MonoFont string
}

Theme is a light and a dark palette and the scales both share.

func Default

func Default() Theme

Default is Flatte's theme: warm stone-grey surfaces, a vivid blue accent, regular density and subtly rounded corners.

func (Theme) Check

func (t Theme) Check() []Problem

Check reports every text, status and control color that falls below WCAG 2's floor on the surfaces it is meant for: 4.5:1 for text, 3:1 for control outlines and the focus ring.

func (*Theme) Palette

func (t *Theme) Palette(dark bool) *Palette

Palette is the palette for an appearance.

func (Theme) With

func (t Theme) With(s Seeds) Theme

With is t with the seeds applied.

type TypeScale

type TypeScale struct {
	PageTitle, Title, Body, Meta, Caption, Code TextSpec
}

TypeScale is the text styles' size and line height in points and weight (400 regular, 600 semibold).

Jump to

Keyboard shortcuts

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