ui/paint: rename the draw package

The draw package name clashes with the standard library draw package.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-08-07 20:11:53 +02:00
parent 6e26c92c75
commit dd35a48a61
10 changed files with 36 additions and 35 deletions
+10 -10
View File
@@ -14,10 +14,10 @@ import (
"gioui.org/ui" "gioui.org/ui"
"gioui.org/ui/app/internal/gl" "gioui.org/ui/app/internal/gl"
gdraw "gioui.org/ui/draw"
"gioui.org/ui/f32" "gioui.org/ui/f32"
"gioui.org/ui/internal/opconst" "gioui.org/ui/internal/opconst"
"gioui.org/ui/internal/ops" "gioui.org/ui/internal/ops"
"gioui.org/ui/paint"
"golang.org/x/image/draw" "golang.org/x/image/draw"
) )
@@ -144,7 +144,7 @@ func (op *clipOp) decode(data []byte) {
} }
} }
func decodeImageOp(data []byte, refs []interface{}) gdraw.ImageOp { func decodeImageOp(data []byte, refs []interface{}) paint.ImageOp {
bo := binary.LittleEndian bo := binary.LittleEndian
if opconst.OpType(data[0]) != opconst.TypeImage { if opconst.OpType(data[0]) != opconst.TypeImage {
panic("invalid op") panic("invalid op")
@@ -159,17 +159,17 @@ func decodeImageOp(data []byte, refs []interface{}) gdraw.ImageOp {
Y: int(int32(bo.Uint32(data[13:]))), Y: int(int32(bo.Uint32(data[13:]))),
}, },
} }
return gdraw.ImageOp{ return paint.ImageOp{
Src: refs[0].(image.Image), Src: refs[0].(image.Image),
Rect: sr, Rect: sr,
} }
} }
func decodeColorOp(data []byte, refs []interface{}) gdraw.ColorOp { func decodeColorOp(data []byte, refs []interface{}) paint.ColorOp {
if opconst.OpType(data[0]) != opconst.TypeColor { if opconst.OpType(data[0]) != opconst.TypeColor {
panic("invalid op") panic("invalid op")
} }
return gdraw.ColorOp{ return paint.ColorOp{
Color: color.RGBA{ Color: color.RGBA{
R: data[1], R: data[1],
G: data[2], G: data[2],
@@ -179,9 +179,9 @@ func decodeColorOp(data []byte, refs []interface{}) gdraw.ColorOp {
} }
} }
func decodeDrawOp(data []byte, refs []interface{}) gdraw.DrawOp { func decodePaintOp(data []byte, refs []interface{}) paint.PaintOp {
bo := binary.LittleEndian bo := binary.LittleEndian
if opconst.OpType(data[0]) != opconst.TypeDraw { if opconst.OpType(data[0]) != opconst.TypePaint {
panic("invalid op") panic("invalid op")
} }
r := f32.Rectangle{ r := f32.Rectangle{
@@ -194,7 +194,7 @@ func decodeDrawOp(data []byte, refs []interface{}) gdraw.DrawOp {
Y: math.Float32frombits(bo.Uint32(data[13:])), Y: math.Float32frombits(bo.Uint32(data[13:])),
}, },
} }
return gdraw.DrawOp{ return paint.PaintOp{
Rect: r, Rect: r,
} }
} }
@@ -740,8 +740,8 @@ loop:
op := decodeImageOp(encOp.Data, encOp.Refs) op := decodeImageOp(encOp.Data, encOp.Refs)
state.img = op.Src state.img = op.Src
state.imgRect = op.Rect state.imgRect = op.Rect
case opconst.TypeDraw: case opconst.TypePaint:
op := decodeDrawOp(encOp.Data, encOp.Refs) op := decodePaintOp(encOp.Data, encOp.Refs)
off := state.t.Transform(f32.Point{}) off := state.t.Transform(f32.Point{})
clip := state.clip.Intersect(op.Rect.Add(off)) clip := state.clip.Intersect(op.Rect.Add(off))
if clip.Empty() { if clip.Empty() {
+1
View File
@@ -1,3 +1,4 @@
gioui.org v0.0.0-20190807152134-6e26c92c7553 h1:TEPtJ8ilc4uETV9T6vS69XifDObJqgNEKUBGrPi21Ak=
golang.org/x/image v0.0.0-20190703141733-d6a02ce849c9 h1:uc17S921SPw5F2gJo7slQ3aqvr2RwpL7eb3+DZncu3s= golang.org/x/image v0.0.0-20190703141733-d6a02ce849c9 h1:uc17S921SPw5F2gJo7slQ3aqvr2RwpL7eb3+DZncu3s=
golang.org/x/image v0.0.0-20190703141733-d6a02ce849c9/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/image v0.0.0-20190703141733-d6a02ce849c9/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb h1:fgwFCsaw9buMuxNd6+DQfAuSFqbNiQZpcgJQAgJsK6k= golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb h1:fgwFCsaw9buMuxNd6+DQfAuSFqbNiQZpcgJQAgJsK6k=
+3 -3
View File
@@ -14,7 +14,7 @@ const (
TypeLayer TypeLayer
TypeInvalidate TypeInvalidate
TypeImage TypeImage
TypeDraw TypePaint
TypeColor TypeColor
TypeArea TypeArea
TypePointerHandler TypePointerHandler
@@ -35,7 +35,7 @@ const (
TypeLayerLen = 1 TypeLayerLen = 1
TypeRedrawLen = 1 + 8 TypeRedrawLen = 1 + 8
TypeImageLen = 1 + 4*4 TypeImageLen = 1 + 4*4
TypeDrawLen = 1 + 4*4 TypePaintLen = 1 + 4*4
TypeColorLen = 1 + 4 TypeColorLen = 1 + 4
TypeAreaLen = 1 + 1 + 4*4 TypeAreaLen = 1 + 1 + 4*4
TypePointerHandlerLen = 1 + 1 TypePointerHandlerLen = 1 + 1
@@ -57,7 +57,7 @@ func (t OpType) Size() int {
TypeLayerLen, TypeLayerLen,
TypeRedrawLen, TypeRedrawLen,
TypeImageLen, TypeImageLen,
TypeDrawLen, TypePaintLen,
TypeColorLen, TypeColorLen,
TypeAreaLen, TypeAreaLen,
TypePointerHandlerLen, TypePointerHandlerLen,
+2 -2
View File
@@ -6,10 +6,10 @@ import (
"image" "image"
"gioui.org/ui" "gioui.org/ui"
"gioui.org/ui/draw"
"gioui.org/ui/gesture" "gioui.org/ui/gesture"
"gioui.org/ui/input" "gioui.org/ui/input"
"gioui.org/ui/pointer" "gioui.org/ui/pointer"
"gioui.org/ui/paint"
) )
type scrollChild struct { type scrollChild struct {
@@ -230,7 +230,7 @@ func (l *List) Layout() Dimens {
} }
var stack ui.StackOp var stack ui.StackOp
stack.Push(ops) stack.Push(ops)
draw.RectClip(r).Add(ops) paint.RectClip(r).Add(ops)
ui.TransformOp{}.Offset(toPointF(axisPoint(l.Axis, transPos, cross))).Add(ops) ui.TransformOp{}.Offset(toPointF(axisPoint(l.Axis, transPos, cross))).Add(ops)
child.macro.Add(ops) child.macro.Add(ops)
stack.Pop() stack.Pop()
+2 -2
View File
@@ -8,9 +8,9 @@ import (
"unicode/utf8" "unicode/utf8"
"gioui.org/ui" "gioui.org/ui"
"gioui.org/ui/draw"
"gioui.org/ui/f32" "gioui.org/ui/f32"
"gioui.org/ui/text" "gioui.org/ui/text"
"gioui.org/ui/paint"
"golang.org/x/image/font" "golang.org/x/image/font"
"golang.org/x/image/font/sfnt" "golang.org/x/image/font/sfnt"
"golang.org/x/image/math/fixed" "golang.org/x/image/math/fixed"
@@ -228,7 +228,7 @@ func layoutText(ppem fixed.Int26_6, str string, f *opentype, opts text.LayoutOpt
func textPath(ppem fixed.Int26_6, f *opentype, str text.String) ui.MacroOp { func textPath(ppem fixed.Int26_6, f *opentype, str text.String) ui.MacroOp {
var lastPos f32.Point var lastPos f32.Point
var builder draw.PathBuilder var builder paint.PathBuilder
ops := new(ui.Ops) ops := new(ui.Ops)
builder.Init(ops) builder.Init(ops)
var x fixed.Int26_6 var x fixed.Int26_6
+5 -5
View File
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: Unlicense OR MIT // SPDX-License-Identifier: Unlicense OR MIT
package draw package paint
import ( import (
"encoding/binary" "encoding/binary"
@@ -22,7 +22,7 @@ type ColorOp struct {
Color color.RGBA Color color.RGBA
} }
type DrawOp struct { type PaintOp struct {
Rect f32.Rectangle Rect f32.Rectangle
} }
@@ -47,9 +47,9 @@ func (c ColorOp) Add(o *ui.Ops) {
o.Write(data) o.Write(data)
} }
func (d DrawOp) Add(o *ui.Ops) { func (d PaintOp) Add(o *ui.Ops) {
data := make([]byte, opconst.TypeDrawLen) data := make([]byte, opconst.TypePaintLen)
data[0] = byte(opconst.TypeDraw) data[0] = byte(opconst.TypePaint)
bo := binary.LittleEndian bo := binary.LittleEndian
bo.PutUint32(data[1:], math.Float32bits(d.Rect.Min.X)) bo.PutUint32(data[1:], math.Float32bits(d.Rect.Min.X))
bo.PutUint32(data[5:], math.Float32bits(d.Rect.Min.Y)) bo.PutUint32(data[5:], math.Float32bits(d.Rect.Min.Y))
+1 -1
View File
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: Unlicense OR MIT // SPDX-License-Identifier: Unlicense OR MIT
package draw package paint
import ( import (
"encoding/binary" "encoding/binary"
+6 -6
View File
@@ -10,12 +10,12 @@ import (
"unicode/utf8" "unicode/utf8"
"gioui.org/ui" "gioui.org/ui"
"gioui.org/ui/draw"
"gioui.org/ui/gesture" "gioui.org/ui/gesture"
"gioui.org/ui/input" "gioui.org/ui/input"
"gioui.org/ui/key" "gioui.org/ui/key"
"gioui.org/ui/layout" "gioui.org/ui/layout"
"gioui.org/ui/pointer" "gioui.org/ui/pointer"
"gioui.org/ui/paint"
"golang.org/x/image/math/fixed" "golang.org/x/image/math/fixed"
) )
@@ -196,10 +196,10 @@ func (e *Editor) Layout(cfg ui.Config, queue input.Queue, ops *ui.Ops, cs layout
stack.Push(ops) stack.Push(ops)
// Apply material. Set a default color in case the material is empty. // Apply material. Set a default color in case the material is empty.
if e.rr.len() > 0 { if e.rr.len() > 0 {
draw.ColorOp{Color: color.RGBA{A: 0xff}}.Add(ops) paint.ColorOp{Color: color.RGBA{A: 0xff}}.Add(ops)
e.Material.Add(ops) e.Material.Add(ops)
} else { } else {
draw.ColorOp{Color: color.RGBA{A: 0xaa}}.Add(ops) paint.ColorOp{Color: color.RGBA{A: 0xaa}}.Add(ops)
e.HintMaterial.Add(ops) e.HintMaterial.Add(ops)
} }
for { for {
@@ -211,7 +211,7 @@ func (e *Editor) Layout(cfg ui.Config, queue input.Queue, ops *ui.Ops, cs layout
stack.Push(ops) stack.Push(ops)
ui.TransformOp{}.Offset(lineOff).Add(ops) ui.TransformOp{}.Offset(lineOff).Add(ops)
e.Face.Path(str).Add(ops) e.Face.Path(str).Add(ops)
draw.DrawOp{Rect: toRectF(clip).Sub(lineOff)}.Add(ops) paint.PaintOp{Rect: toRectF(clip).Sub(lineOff)}.Add(ops)
stack.Pop() stack.Pop()
} }
if e.focused { if e.focused {
@@ -235,9 +235,9 @@ func (e *Editor) Layout(cfg ui.Config, queue input.Queue, ops *ui.Ops, cs layout
}) })
carRect = clip.Intersect(carRect) carRect = clip.Intersect(carRect)
if !carRect.Empty() { if !carRect.Empty() {
draw.ColorOp{Color: color.RGBA{A: 0xff}}.Add(ops) paint.ColorOp{Color: color.RGBA{A: 0xff}}.Add(ops)
e.Material.Add(ops) e.Material.Add(ops)
draw.DrawOp{Rect: toRectF(carRect)}.Add(ops) paint.PaintOp{Rect: toRectF(carRect)}.Add(ops)
} }
} }
if blinking { if blinking {
+3 -3
View File
@@ -8,9 +8,9 @@ import (
"unicode/utf8" "unicode/utf8"
"gioui.org/ui" "gioui.org/ui"
"gioui.org/ui/draw"
"gioui.org/ui/f32" "gioui.org/ui/f32"
"gioui.org/ui/layout" "gioui.org/ui/layout"
"gioui.org/ui/paint"
"golang.org/x/image/math/fixed" "golang.org/x/image/math/fixed"
) )
@@ -113,9 +113,9 @@ func (l Label) Layout(ops *ui.Ops, cs layout.Constraints) layout.Dimens {
ui.TransformOp{}.Offset(off).Add(ops) ui.TransformOp{}.Offset(off).Add(ops)
l.Face.Path(str).Add(ops) l.Face.Path(str).Add(ops)
// Set a default color in case the material is empty. // Set a default color in case the material is empty.
draw.ColorOp{Color: color.RGBA{A: 0xff}}.Add(ops) paint.ColorOp{Color: color.RGBA{A: 0xff}}.Add(ops)
l.Material.Add(ops) l.Material.Add(ops)
draw.DrawOp{Rect: lclip}.Add(ops) paint.PaintOp{Rect: lclip}.Add(ops)
stack.Pop() stack.Pop()
} }
return dims return dims
+3 -3
View File
@@ -6,9 +6,9 @@ import (
"image" "image"
"gioui.org/ui" "gioui.org/ui"
"gioui.org/ui/draw"
"gioui.org/ui/f32" "gioui.org/ui/f32"
"gioui.org/ui/layout" "gioui.org/ui/layout"
"gioui.org/ui/paint"
) )
type Image struct { type Image struct {
@@ -45,7 +45,7 @@ func (im Image) Layout(c ui.Config, ops *ui.Ops, cs layout.Constraints) layout.D
dr := f32.Rectangle{ dr := f32.Rectangle{
Max: f32.Point{X: float32(d.X), Y: float32(d.Y)}, Max: f32.Point{X: float32(d.X), Y: float32(d.Y)},
} }
draw.ImageOp{Src: im.Src, Rect: im.Rect}.Add(ops) paint.ImageOp{Src: im.Src, Rect: im.Rect}.Add(ops)
draw.DrawOp{Rect: dr}.Add(ops) paint.PaintOp{Rect: dr}.Add(ops)
return layout.Dimens{Size: d, Baseline: d.Y} return layout.Dimens{Size: d, Baseline: d.Y}
} }