mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-03 08:25:34 +00:00
op/paint: return ClipOp from Path.End
Instead of adding an implicit ClipOp, return a ClipOp ready to use, freeing the caller from recording a macro. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+5
-5
@@ -3,7 +3,7 @@
|
||||
package shape
|
||||
|
||||
import (
|
||||
"gioui.org/op"
|
||||
"gioui.org/op/paint"
|
||||
"gioui.org/text"
|
||||
"golang.org/x/image/font/sfnt"
|
||||
"golang.org/x/image/math/fixed"
|
||||
@@ -28,7 +28,7 @@ type layout struct {
|
||||
type path struct {
|
||||
next, prev *path
|
||||
key pathKey
|
||||
val op.MacroOp
|
||||
val paint.ClipOp
|
||||
}
|
||||
|
||||
type layoutKey struct {
|
||||
@@ -85,16 +85,16 @@ func (l *layoutCache) insert(lt *layout) {
|
||||
lt.next.prev = lt
|
||||
}
|
||||
|
||||
func (c *pathCache) Get(k pathKey) (op.MacroOp, bool) {
|
||||
func (c *pathCache) Get(k pathKey) (paint.ClipOp, bool) {
|
||||
if v, ok := c.m[k]; ok {
|
||||
c.remove(v)
|
||||
c.insert(v)
|
||||
return v.val, true
|
||||
}
|
||||
return op.MacroOp{}, false
|
||||
return paint.ClipOp{}, false
|
||||
}
|
||||
|
||||
func (c *pathCache) Put(k pathKey, v op.MacroOp) {
|
||||
func (c *pathCache) Put(k pathKey, v paint.ClipOp) {
|
||||
if c.m == nil {
|
||||
c.m = make(map[pathKey]*path)
|
||||
c.head = new(path)
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"gioui.org/op"
|
||||
"gioui.org/op/paint"
|
||||
)
|
||||
|
||||
func TestLayoutLRU(t *testing.T) {
|
||||
@@ -24,7 +24,7 @@ func TestLayoutLRU(t *testing.T) {
|
||||
func TestuPathLRU(t *testing.T) {
|
||||
c := new(pathCache)
|
||||
put := func(i int) {
|
||||
c.Put(pathKey{str: strconv.Itoa(i)}, op.MacroOp{})
|
||||
c.Put(pathKey{str: strconv.Itoa(i)}, paint.ClipOp{})
|
||||
}
|
||||
get := func(i int) bool {
|
||||
_, ok := c.Get(pathKey{str: strconv.Itoa(i)})
|
||||
|
||||
@@ -64,7 +64,7 @@ func (f *Family) Layout(face text.Face, size float32, str string, opts text.Layo
|
||||
return l
|
||||
}
|
||||
|
||||
func (f *Family) Shape(face text.Face, size float32, str text.String) op.MacroOp {
|
||||
func (f *Family) Shape(face text.Face, size float32, str text.String) paint.ClipOp {
|
||||
fnt := f.fontFor(face)
|
||||
ppem := fixed.Int26_6(size * 64)
|
||||
pk := pathKey{
|
||||
@@ -169,14 +169,12 @@ func layoutText(buf *sfnt.Buffer, ppem fixed.Int26_6, str string, f *opentype, o
|
||||
return &text.Layout{Lines: lines}
|
||||
}
|
||||
|
||||
func textPath(buf *sfnt.Buffer, ppem fixed.Int26_6, f *opentype, str text.String) op.MacroOp {
|
||||
func textPath(buf *sfnt.Buffer, ppem fixed.Int26_6, f *opentype, str text.String) paint.ClipOp {
|
||||
var lastPos f32.Point
|
||||
var builder paint.Path
|
||||
ops := new(op.Ops)
|
||||
var x fixed.Int26_6
|
||||
var advIdx int
|
||||
var m op.MacroOp
|
||||
m.Record(ops)
|
||||
builder.Begin(ops)
|
||||
for _, r := range str.String {
|
||||
if !unicode.IsSpace(r) {
|
||||
@@ -229,7 +227,5 @@ func textPath(buf *sfnt.Buffer, ppem fixed.Int26_6, f *opentype, str text.String
|
||||
x += str.Advances[advIdx]
|
||||
advIdx++
|
||||
}
|
||||
builder.End()
|
||||
m.Stop()
|
||||
return m
|
||||
return builder.End()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user