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 ¶
- func Contrast(fg, bg color.NRGBA) float64
- func Hex(s string) color.NRGBA
- func Mix(a, b color.NRGBA, t float64) color.NRGBA
- func Over(c, bg color.NRGBA) color.NRGBA
- type Density
- type DiffColors
- type Pair
- type Palette
- type Problem
- type Radii
- type Roundness
- type Seeds
- type Sizes
- type Strokes
- type SyntaxColors
- type TextSpec
- type Theme
- type TypeScale
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Contrast ¶
Contrast is the WCAG 2 contrast ratio of two colors, 1 to 21; a translucent fg is first composited over bg.
func Hex ¶
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.
Types ¶
type DiffColors ¶
DiffColors are a diff's line and word backgrounds.
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.
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 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 ¶
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 ¶
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.