80 lines
1.3 KiB
Go
80 lines
1.3 KiB
Go
package gui
|
|
|
|
import (
|
|
"image/color"
|
|
|
|
"golang.org/x/image/font"
|
|
)
|
|
|
|
type Style interface {
|
|
SetForeground(c color.Color)
|
|
Foreground(ctx AppContext) color.Color
|
|
|
|
SetBackground(c color.Color)
|
|
Background(ctx AppContext) color.Color
|
|
|
|
SetFont(f *Font)
|
|
Font(ctx AppContext) *Font
|
|
|
|
SetFontSize(fontSize int)
|
|
FontSize(ctx AppContext) int
|
|
|
|
FontFace(ctx AppContext) font.Face
|
|
}
|
|
|
|
type StyleTmpl struct {
|
|
foreground color.Color
|
|
background color.Color
|
|
|
|
font *Font
|
|
fontSize *int
|
|
}
|
|
|
|
func (s *StyleTmpl) SetForeground(c color.Color) {
|
|
s.foreground = c
|
|
}
|
|
|
|
func (s *StyleTmpl) Foreground(ctx AppContext) color.Color {
|
|
if s.foreground == nil {
|
|
return ctx.Foreground()
|
|
}
|
|
return s.foreground
|
|
}
|
|
|
|
func (s *StyleTmpl) SetBackground(c color.Color) {
|
|
s.background = c
|
|
}
|
|
|
|
func (s *StyleTmpl) Background(ctx AppContext) color.Color {
|
|
if s.background == nil {
|
|
return ctx.Background()
|
|
}
|
|
return s.background
|
|
}
|
|
|
|
func (s *StyleTmpl) SetFont(f *Font) {
|
|
s.font = f
|
|
}
|
|
|
|
func (s *StyleTmpl) Font(ctx AppContext) *Font {
|
|
if s.font == nil {
|
|
return ctx.Font()
|
|
}
|
|
return s.font
|
|
}
|
|
|
|
func (s *StyleTmpl) SetFontSize(fontSize int) {
|
|
s.fontSize = &fontSize
|
|
}
|
|
|
|
func (s *StyleTmpl) FontSize(ctx AppContext) int {
|
|
if s.fontSize == nil {
|
|
return ctx.FontSize()
|
|
}
|
|
return *s.fontSize
|
|
}
|
|
|
|
func (s *StyleTmpl) FontFace(ctx AppContext) font.Face {
|
|
return s.Font(ctx).Face(s.FontSize(ctx))
|
|
}
|