op/clip: split clip operations into its own package

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-11-09 19:05:03 +01:00
parent 560cf6054c
commit e864ac3fc3
14 changed files with 72 additions and 53 deletions
+5 -5
View File
@@ -3,7 +3,7 @@
package text
import (
"gioui.org/op/paint"
"gioui.org/op/clip"
"golang.org/x/image/math/fixed"
)
@@ -26,7 +26,7 @@ type layoutElem struct {
type path struct {
next, prev *path
key pathKey
val paint.ClipOp
val clip.Op
}
type layoutKey struct {
@@ -81,16 +81,16 @@ func (l *layoutCache) insert(lt *layoutElem) {
lt.next.prev = lt
}
func (c *pathCache) Get(k pathKey) (paint.ClipOp, bool) {
func (c *pathCache) Get(k pathKey) (clip.Op, bool) {
if v, ok := c.m[k]; ok {
c.remove(v)
c.insert(v)
return v.val, true
}
return paint.ClipOp{}, false
return clip.Op{}, false
}
func (c *pathCache) Put(k pathKey, v paint.ClipOp) {
func (c *pathCache) Put(k pathKey, v clip.Op) {
if c.m == nil {
c.m = make(map[pathKey]*path)
c.head = new(path)
+2 -2
View File
@@ -6,7 +6,7 @@ import (
"strconv"
"testing"
"gioui.org/op/paint"
"gioui.org/op/clip"
)
func TestLayoutLRU(t *testing.T) {
@@ -24,7 +24,7 @@ func TestLayoutLRU(t *testing.T) {
func TestPathLRU(t *testing.T) {
c := new(pathCache)
put := func(i int) {
c.Put(pathKey{str: strconv.Itoa(i)}, paint.ClipOp{})
c.Put(pathKey{str: strconv.Itoa(i)}, clip.Op{})
}
get := func(i int) bool {
_, ok := c.Get(pathKey{str: strconv.Itoa(i)})
+4 -4
View File
@@ -5,7 +5,7 @@ package text
import (
"unicode/utf8"
"gioui.org/op/paint"
"gioui.org/op/clip"
"gioui.org/unit"
"golang.org/x/image/math/fixed"
)
@@ -46,7 +46,7 @@ func (s *Shaper) Layout(c unit.Converter, font Font, str string, opts LayoutOpti
return tf.layout(fixed.I(c.Px(font.Size)), str, opts)
}
func (s *Shaper) Shape(c unit.Converter, font Font, str String) paint.ClipOp {
func (s *Shaper) Shape(c unit.Converter, font Font, str String) clip.Op {
tf := s.faceForFont(font)
return tf.shape(fixed.I(c.Px(font.Size)), str)
}
@@ -99,9 +99,9 @@ func (t *face) layout(ppem fixed.Int26_6, str string, opts LayoutOptions) *Layou
return l
}
func (t *face) shape(ppem fixed.Int26_6, str String) paint.ClipOp {
func (t *face) shape(ppem fixed.Int26_6, str String) clip.Op {
if t == nil {
return paint.ClipOp{}
return clip.Op{}
}
pk := pathKey{
ppem: ppem,
+2 -2
View File
@@ -3,7 +3,7 @@
package text
import (
"gioui.org/op/paint"
"gioui.org/op/clip"
"gioui.org/unit"
"golang.org/x/image/math/fixed"
)
@@ -61,7 +61,7 @@ type Font struct {
// Face implements text layout and shaping for a particular font.
type Face interface {
Layout(ppem fixed.Int26_6, str string, opts LayoutOptions) *Layout
Shape(ppem fixed.Int26_6, str String) paint.ClipOp
Shape(ppem fixed.Int26_6, str String) clip.Op
}
// Typeface identifies a particular typeface design. The empty