Documentation ¶
Overview ¶
Package theme provides widget themes.
Index ¶
- Constants
- Variables
- type Color
- type FontFaceCatalog
- type FontFaceOptions
- type Palette
- type PaletteIndex
- type Theme
- func (t *Theme) AcquireFontFace(o FontFaceOptions) font.Face
- func (t *Theme) Convert(v unit.Value, to unit.Unit) unit.Value
- func (t *Theme) GetDPI() float64
- func (t *Theme) GetFontFaceCatalog() FontFaceCatalog
- func (t *Theme) GetPalette() *Palette
- func (t *Theme) Pixels(v unit.Value) fixed.Int26_6
- func (t *Theme) ReleaseFontFace(o FontFaceOptions, f font.Face)
Constants ¶
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 )
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 ¶
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 ¶
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 ¶
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 ¶
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) Background ¶
func (*Palette) Foreground ¶
type PaletteIndex ¶
type PaletteIndex int
PaletteIndex is both an integer index into a Palette array and a Color.
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) GetDPI ¶
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 ¶
GetPalette returns the theme's palette, or the default palette if the field value is zero.
func (*Theme) ReleaseFontFace ¶
func (t *Theme) ReleaseFontFace(o FontFaceOptions, f font.Face)
ReleaseFontFace calls the same method on the result of GetFontFaceCatalog.