theme

package
v0.0.0-...-57c1bf3 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2019 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package theme provides widget themes.

Index

Constants

View Source
const (
	// Light, Neutral and Dark are three color tones used to fill in widgets
	// such as buttons, menu bars and panels.
	Light   = PaletteIndex(0)
	Neutral = PaletteIndex(1)
	Dark    = PaletteIndex(2)

	// Accent is the color used to accentuate selections or suggestions.
	Accent = PaletteIndex(3)

	// Foreground is the color used for text, dividers and icons.
	Foreground = PaletteIndex(4)

	// Background is the color used behind large blocks of text. Short,
	// non-editable label text will typically be on the Neutral color.
	Background = PaletteIndex(5)

	PaletteLen = 6
)
View Source
const DefaultDPI = 72.0

DefaultDPI is the fallback value of a theme's DPI, if the underlying context does not provide a DPI value.

Variables

View Source
var (
	// DefaultFontFaceCatalog is a catalog for a basic font face.
	DefaultFontFaceCatalog FontFaceCatalog = defaultFontFaceCatalog{}

	// DefaultPalette is the default theme's palette.
	DefaultPalette = Palette{
		Light:      image.Uniform{C: color.RGBA{0xf5, 0xf5, 0xf5, 0xff}},
		Neutral:    image.Uniform{C: color.RGBA{0xee, 0xee, 0xee, 0xff}},
		Dark:       image.Uniform{C: color.RGBA{0xe0, 0xe0, 0xe0, 0xff}},
		Accent:     image.Uniform{C: color.RGBA{0x21, 0x96, 0xf3, 0xff}},
		Foreground: image.Uniform{C: color.RGBA{0x00, 0x00, 0x00, 0xff}},
		Background: image.Uniform{C: color.RGBA{0xff, 0xff, 0xff, 0xff}},
	}

	// Default uses the default DPI, FontFaceCatalog and Palette.
	//
	// The nil-valued pointer is a valid receiver for a Theme's methods.
	Default *Theme
)

Functions

This section is empty.

Types

type Color

type Color interface {
	Color(*Theme) color.Color
	Uniform(*Theme) *image.Uniform
}

Color is a theme-dependent color, such as "the foreground color". Combining a Color with a Theme results in a color.Color in the sense of the standard library's image/color package. It can also result in an *image.Uniform, suitable for passing as the src argument to image/draw functions.

func StaticColor

func StaticColor(c color.Color) Color

StaticColor adapts a color.Color to a theme Color.

type FontFaceCatalog

type FontFaceCatalog interface {
	AcquireFontFace(FontFaceOptions) font.Face
	ReleaseFontFace(FontFaceOptions, font.Face)
}

FontFaceCatalog provides a theme's font faces.

AcquireFontFace returns a font.Face. ReleaseFontFace should be called, with the same options, once a widget's measure, layout or paint is done with the font.Face returned.

A FontFaceCatalog is safe for use by multiple goroutines simultaneously, but in general, a font.Face is not safe for concurrent use, as its methods may re-use implementation-specific caches and mask image buffers.

type FontFaceOptions

type FontFaceOptions struct {
	Style  font.Style
	Weight font.Weight
}

FontFaceOptions allows asking for font face variants, such as style (e.g. italic) or weight (e.g. bold).

TODO: include font.Hinting and font.Stretch typed fields?

TODO: include font size? If so, directly as "12pt" or indirectly as an enum (Heading1, Heading2, Body, etc)?

type Palette

type Palette [PaletteLen]image.Uniform

Palette provides a theme's color palette. The array is indexed by PaletteIndex constants such as Accent and Foreground.

The colors are expressed as image.Uniform values so that they can be easily passed as the src argument to image/draw functions.

func (*Palette) Accent

func (p *Palette) Accent() *image.Uniform

func (*Palette) Background

func (p *Palette) Background() *image.Uniform

func (*Palette) Dark

func (p *Palette) Dark() *image.Uniform

func (*Palette) Foreground

func (p *Palette) Foreground() *image.Uniform

func (*Palette) Light

func (p *Palette) Light() *image.Uniform

func (*Palette) Neutral

func (p *Palette) Neutral() *image.Uniform

type PaletteIndex

type PaletteIndex int

PaletteIndex is both an integer index into a Palette array and a Color.

func (PaletteIndex) Color

func (i PaletteIndex) Color(t *Theme) color.Color

func (PaletteIndex) Uniform

func (i PaletteIndex) Uniform(t *Theme) *image.Uniform

type Theme

type Theme struct {
	// DPI is the screen resolution, in dots (i.e. pixels) per inch.
	//
	// A zero value means to use the DefaultDPI.
	DPI float64

	// FontFaceCatalog provides a theme's font faces.
	//
	// A zero value means to use the DefaultFontFaceCatalog.
	FontFaceCatalog FontFaceCatalog

	// Palette provides a theme's color palette.
	//
	// A zero value means to use the DefaultPalette.
	Palette *Palette
}

Theme is used for measuring, laying out and painting widgets. It consists of a screen DPI resolution, a set of font faces and colors.

func (*Theme) AcquireFontFace

func (t *Theme) AcquireFontFace(o FontFaceOptions) font.Face

AcquireFontFace calls the same method on the result of GetFontFaceCatalog.

func (*Theme) Convert

func (t *Theme) Convert(v unit.Value, to unit.Unit) unit.Value

Convert implements the unit.Converter interface.

func (*Theme) GetDPI

func (t *Theme) GetDPI() float64

GetDPI returns the theme's DPI, or the default DPI if the field value is zero.

func (*Theme) GetFontFaceCatalog

func (t *Theme) GetFontFaceCatalog() FontFaceCatalog

GetFontFaceCatalog returns the theme's font face catalog, or the default catalog if the field value is zero.

func (*Theme) GetPalette

func (t *Theme) GetPalette() *Palette

GetPalette returns the theme's palette, or the default palette if the field value is zero.

func (*Theme) Pixels

func (t *Theme) Pixels(v unit.Value) fixed.Int26_6

Pixels implements the unit.Converter interface.

func (*Theme) ReleaseFontFace

func (t *Theme) ReleaseFontFace(o FontFaceOptions, f font.Face)

ReleaseFontFace calls the same method on the result of GetFontFaceCatalog.

Jump to

Keyboard shortcuts

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