text: make Shaper an interface

And rename out the caching implementation to FontRegistry.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2020-01-13 14:48:31 +01:00
parent 3f6a1c34d3
commit e25b1639b9
9 changed files with 27 additions and 20 deletions
+3 -3
View File
@@ -213,7 +213,7 @@ func (e *Editor) Focus() {
}
// Layout lays out the editor.
func (e *Editor) Layout(gtx *layout.Context, sh *text.Shaper, font text.Font) {
func (e *Editor) Layout(gtx *layout.Context, sh text.Shaper, font text.Font) {
// Flush events from before the previous frame.
copy(e.events, e.events[e.prevEvents:])
e.events = e.events[:len(e.events)-e.prevEvents]
@@ -226,7 +226,7 @@ func (e *Editor) Layout(gtx *layout.Context, sh *text.Shaper, font text.Font) {
e.layout(gtx, sh)
}
func (e *Editor) layout(gtx *layout.Context, sh *text.Shaper) {
func (e *Editor) layout(gtx *layout.Context, sh text.Shaper) {
// Crude configuration change detection.
if scale := gtx.Px(unit.Sp(100)); scale != e.scale {
e.invalidate()
@@ -430,7 +430,7 @@ func (e *Editor) moveCoord(c unit.Converter, pos image.Point) {
e.moveToLine(x, carLine)
}
func (e *Editor) layoutText(c unit.Converter, s *text.Shaper, font text.Font) ([]text.Line, layout.Dimensions) {
func (e *Editor) layoutText(c unit.Converter, s text.Shaper, font text.Font) ([]text.Line, layout.Dimensions) {
txt := e.rr.String()
opts := text.LayoutOptions{MaxWidth: e.maxWidth}
textLayout := s.Layout(c, font, txt, opts)
+1 -1
View File
@@ -82,7 +82,7 @@ func (l *lineIterator) Next() (text.String, f32.Point, bool) {
return text.String{}, f32.Point{}, false
}
func (l Label) Layout(gtx *layout.Context, s *text.Shaper, font text.Font, txt string) {
func (l Label) Layout(gtx *layout.Context, s text.Shaper, font text.Font, txt string) {
cs := gtx.Constraints
textLayout := s.Layout(gtx, font, txt, text.LayoutOptions{MaxWidth: cs.Width.Max})
lines := textLayout.Lines
+1 -1
View File
@@ -24,7 +24,7 @@ type Button struct {
Font text.Font
Background color.RGBA
CornerRadius unit.Value
shaper *text.Shaper
shaper text.Shaper
}
type IconButton struct {
+1 -1
View File
@@ -20,7 +20,7 @@ type checkable struct {
Font text.Font
IconColor color.RGBA
Size unit.Value
shaper *text.Shaper
shaper text.Shaper
checkedStateIcon *Icon
uncheckedStateIcon *Icon
}
+1 -1
View File
@@ -21,7 +21,7 @@ type Editor struct {
// HintColor is the color of hint text.
HintColor color.RGBA
shaper *text.Shaper
shaper text.Shaper
}
func (t *Theme) Editor(hint string) Editor {
+1 -1
View File
@@ -23,7 +23,7 @@ type Label struct {
MaxLines int
Text string
shaper *text.Shaper
shaper text.Shaper
}
func (t *Theme) H1(txt string) Label {
+1 -1
View File
@@ -16,7 +16,7 @@ import (
)
type Theme struct {
Shaper *text.Shaper
Shaper text.Shaper
Color struct {
Primary color.RGBA
Text color.RGBA