Core provides convenience methods for easy theme access
This commit is contained in:
parent
8d90dbdc92
commit
f8ebe5b1e4
@ -2,9 +2,11 @@ package core
|
||||
|
||||
import "image"
|
||||
import "image/color"
|
||||
import "golang.org/x/image/font"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/theme"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/config"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/canvas"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/artist"
|
||||
|
||||
// Core is a struct that implements some core functionality common to most
|
||||
// widgets. It is meant to be embedded directly into a struct.
|
||||
@ -18,6 +20,7 @@ type Core struct {
|
||||
|
||||
config config.Config
|
||||
theme theme.Theme
|
||||
c theme.Case
|
||||
|
||||
drawSizeChange func ()
|
||||
onConfigChange func ()
|
||||
@ -31,11 +34,17 @@ func NewCore (
|
||||
drawSizeChange func (),
|
||||
onConfigChange func (),
|
||||
onThemeChange func (),
|
||||
c theme.Case,
|
||||
) (
|
||||
core *Core,
|
||||
control CoreControl,
|
||||
) {
|
||||
core = &Core { drawSizeChange: drawSizeChange }
|
||||
core = &Core {
|
||||
drawSizeChange: drawSizeChange,
|
||||
onConfigChange: onConfigChange,
|
||||
onThemeChange: onThemeChange,
|
||||
c: c,
|
||||
}
|
||||
control = CoreControl { core: core }
|
||||
return
|
||||
}
|
||||
@ -189,3 +198,39 @@ func (control CoreControl) Config () (config.Config) {
|
||||
func (control CoreControl) Theme () (theme.Theme) {
|
||||
return control.core.theme
|
||||
}
|
||||
|
||||
// FontFace is like Theme.FontFace, but it automatically applies the correct
|
||||
// case.
|
||||
func (control CoreControl) FontFace (
|
||||
style theme.FontStyle,
|
||||
size theme.FontSize,
|
||||
) (
|
||||
face font.Face,
|
||||
) {
|
||||
return control.core.theme.FontFace(style, size, control.core.c)
|
||||
}
|
||||
|
||||
// Icon is like Theme.Icon, but it automatically applies the correct case.
|
||||
func (control CoreControl) Icon (name string) (artist.Pattern) {
|
||||
return control.core.theme.Icon(name, control.core.c)
|
||||
}
|
||||
|
||||
// Pattern is like Theme.Pattern, but it automatically applies the correct case.
|
||||
func (control CoreControl) Pattern (
|
||||
id theme.Pattern,
|
||||
state theme.PatternState,
|
||||
) (
|
||||
pattern artist.Pattern,
|
||||
) {
|
||||
return control.core.theme.Pattern(id, control.core.c, state)
|
||||
}
|
||||
|
||||
// Inset is like Theme.Inset, but it automatically applies the correct case.
|
||||
func (control CoreControl) Inset (id theme.Pattern) (inset theme.Inset) {
|
||||
return control.core.theme.Inset(id, control.core.c)
|
||||
}
|
||||
|
||||
// Sink is like Theme.Sink, but it automatically applies the correct case.
|
||||
func (control CoreControl) Sink (id theme.Pattern) (offset image.Point) {
|
||||
return control.core.theme.Sink(id, control.core.c)
|
||||
}
|
||||
|
Reference in New Issue
Block a user