From f8ebe5b1e4c1ae9542bb3040ec6ceba55b89f91e Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Fri, 3 Feb 2023 18:28:01 -0500 Subject: [PATCH] Core provides convenience methods for easy theme access --- elements/core/core.go | 47 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/elements/core/core.go b/elements/core/core.go index 827b87c..85999e0 100644 --- a/elements/core/core.go +++ b/elements/core/core.go @@ -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) +}