ui: build paths as ops

Instead of allocating and constructing a clip path, store path data
directly in op lists. Use separate op lists for cached text layout
paths.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-06-02 16:43:28 +02:00
parent 9f58ed0fea
commit 1e38eec0ab
15 changed files with 248 additions and 160 deletions
+1 -8
View File
@@ -10,7 +10,6 @@ import (
"gioui.org/ui"
"gioui.org/ui/draw"
"gioui.org/ui/f32"
"gioui.org/ui/gesture"
"gioui.org/ui/key"
"gioui.org/ui/layout"
@@ -49,11 +48,6 @@ type Editor struct {
clicker gesture.Click
}
type linePath struct {
path *draw.Path
off f32.Point
}
const (
blinksPerSecond = 1
maxBlinkDuration = 10 * time.Second
@@ -170,10 +164,9 @@ func (e *Editor) Layout(ops *ui.Ops, cs layout.Constraints) layout.Dimens {
if !ok {
break
}
path := e.Face.Path(str)
ui.OpPush{}.Add(ops)
ui.OpTransform{Transform: ui.Offset(lineOff)}.Add(ops)
draw.OpClip{Path: path}.Add(ops)
e.Face.Path(str).Add(ops)
draw.OpDraw{Rect: toRectF(clip).Sub(lineOff)}.Add(ops)
ui.OpPop{}.Add(ops)
}
+1 -2
View File
@@ -100,11 +100,10 @@ func (l Label) Layout(ops *ui.Ops, cs layout.Constraints) layout.Dimens {
if !ok {
break
}
path := l.Face.Path(str)
lclip := toRectF(clip).Sub(off)
ui.OpPush{}.Add(ops)
ui.OpTransform{Transform: ui.Offset(off)}.Add(ops)
draw.OpClip{Path: path}.Add(ops)
l.Face.Path(str).Add(ops)
draw.OpDraw{Rect: lclip}.Add(ops)
ui.OpPop{}.Add(ops)
}
+2 -2
View File
@@ -6,7 +6,7 @@ import (
"fmt"
"image"
"gioui.org/ui/draw"
"gioui.org/ui"
"gioui.org/ui/layout"
"golang.org/x/image/math/fixed"
)
@@ -35,7 +35,7 @@ type Layout struct {
type Face interface {
Layout(str string, singleLine bool, maxWidth int) *Layout
Path(str String) *draw.Path
Path(str String) ui.OpBlock
}
type Alignment uint8