ui/text,ui/layout: move ui.Config and input.Queue to parameters

I too often forget to initialize widgets' config and queue. Moving
them from fields to parameters fix that. The change results in a
little more verbosity but cleaner code.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-07-21 11:44:48 +02:00
parent 6c0850ce60
commit b6290990ad
3 changed files with 31 additions and 30 deletions
+5 -4
View File
@@ -17,7 +17,7 @@ import (
)
type Faces struct {
Config ui.Config
config ui.Config
faceCache map[faceKey]*textFace
layoutCache map[layoutKey]cachedLayout
pathCache map[pathKey]cachedPath
@@ -57,7 +57,8 @@ type textFace struct {
font *opentype
}
func (f *Faces) Frame() {
func (f *Faces) Reset(c ui.Config) {
f.config = c
f.init()
for pk, p := range f.pathCache {
if !p.active {
@@ -102,7 +103,7 @@ func (f *Faces) init() {
}
func (f *textFace) Layout(str string, opts text.LayoutOptions) *text.Layout {
ppem := fixed.Int26_6(f.faces.Config.Px(f.size) * 64)
ppem := fixed.Int26_6(f.faces.config.Px(f.size) * 64)
lk := layoutKey{
f: f.font.Font,
ppem: ppem,
@@ -120,7 +121,7 @@ func (f *textFace) Layout(str string, opts text.LayoutOptions) *text.Layout {
}
func (f *textFace) Path(str text.String) ui.MacroOp {
ppem := fixed.Int26_6(f.faces.Config.Px(f.size) * 64)
ppem := fixed.Int26_6(f.faces.config.Px(f.size) * 64)
pk := pathKey{
f: f.font.Font,
ppem: ppem,