From dd35a48a61ab51f0e55d2485798a3db3d7daa5e4 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Wed, 7 Aug 2019 20:11:53 +0200 Subject: [PATCH] ui/paint: rename the draw package The draw package name clashes with the standard library draw package. Signed-off-by: Elias Naur --- ui/app/internal/gpu/gpu.go | 20 ++++++++++---------- ui/go.sum | 1 + ui/internal/opconst/ops.go | 6 +++--- ui/layout/list.go | 4 ++-- ui/measure/measure.go | 4 ++-- ui/{draw/draw.go => paint/paint.go} | 10 +++++----- ui/{draw => paint}/path.go | 2 +- ui/text/editor.go | 12 ++++++------ ui/text/label.go | 6 +++--- ui/widget/image.go | 6 +++--- 10 files changed, 36 insertions(+), 35 deletions(-) rename ui/{draw/draw.go => paint/paint.go} (91%) rename ui/{draw => paint}/path.go (99%) diff --git a/ui/app/internal/gpu/gpu.go b/ui/app/internal/gpu/gpu.go index c2217b68..5766f886 100644 --- a/ui/app/internal/gpu/gpu.go +++ b/ui/app/internal/gpu/gpu.go @@ -14,10 +14,10 @@ import ( "gioui.org/ui" "gioui.org/ui/app/internal/gl" - gdraw "gioui.org/ui/draw" "gioui.org/ui/f32" "gioui.org/ui/internal/opconst" "gioui.org/ui/internal/ops" + "gioui.org/ui/paint" "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 if opconst.OpType(data[0]) != opconst.TypeImage { panic("invalid op") @@ -159,17 +159,17 @@ func decodeImageOp(data []byte, refs []interface{}) gdraw.ImageOp { Y: int(int32(bo.Uint32(data[13:]))), }, } - return gdraw.ImageOp{ + return paint.ImageOp{ Src: refs[0].(image.Image), 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 { panic("invalid op") } - return gdraw.ColorOp{ + return paint.ColorOp{ Color: color.RGBA{ R: data[1], 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 - if opconst.OpType(data[0]) != opconst.TypeDraw { + if opconst.OpType(data[0]) != opconst.TypePaint { panic("invalid op") } r := f32.Rectangle{ @@ -194,7 +194,7 @@ func decodeDrawOp(data []byte, refs []interface{}) gdraw.DrawOp { Y: math.Float32frombits(bo.Uint32(data[13:])), }, } - return gdraw.DrawOp{ + return paint.PaintOp{ Rect: r, } } @@ -740,8 +740,8 @@ loop: op := decodeImageOp(encOp.Data, encOp.Refs) state.img = op.Src state.imgRect = op.Rect - case opconst.TypeDraw: - op := decodeDrawOp(encOp.Data, encOp.Refs) + case opconst.TypePaint: + op := decodePaintOp(encOp.Data, encOp.Refs) off := state.t.Transform(f32.Point{}) clip := state.clip.Intersect(op.Rect.Add(off)) if clip.Empty() { diff --git a/ui/go.sum b/ui/go.sum index 95fbd5a0..40da998d 100644 --- a/ui/go.sum +++ b/ui/go.sum @@ -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/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb h1:fgwFCsaw9buMuxNd6+DQfAuSFqbNiQZpcgJQAgJsK6k= diff --git a/ui/internal/opconst/ops.go b/ui/internal/opconst/ops.go index 23b0f0e8..801d9df9 100644 --- a/ui/internal/opconst/ops.go +++ b/ui/internal/opconst/ops.go @@ -14,7 +14,7 @@ const ( TypeLayer TypeInvalidate TypeImage - TypeDraw + TypePaint TypeColor TypeArea TypePointerHandler @@ -35,7 +35,7 @@ const ( TypeLayerLen = 1 TypeRedrawLen = 1 + 8 TypeImageLen = 1 + 4*4 - TypeDrawLen = 1 + 4*4 + TypePaintLen = 1 + 4*4 TypeColorLen = 1 + 4 TypeAreaLen = 1 + 1 + 4*4 TypePointerHandlerLen = 1 + 1 @@ -57,7 +57,7 @@ func (t OpType) Size() int { TypeLayerLen, TypeRedrawLen, TypeImageLen, - TypeDrawLen, + TypePaintLen, TypeColorLen, TypeAreaLen, TypePointerHandlerLen, diff --git a/ui/layout/list.go b/ui/layout/list.go index 96c79558..a9145e02 100644 --- a/ui/layout/list.go +++ b/ui/layout/list.go @@ -6,10 +6,10 @@ import ( "image" "gioui.org/ui" - "gioui.org/ui/draw" "gioui.org/ui/gesture" "gioui.org/ui/input" "gioui.org/ui/pointer" + "gioui.org/ui/paint" ) type scrollChild struct { @@ -230,7 +230,7 @@ func (l *List) Layout() Dimens { } var stack ui.StackOp stack.Push(ops) - draw.RectClip(r).Add(ops) + paint.RectClip(r).Add(ops) ui.TransformOp{}.Offset(toPointF(axisPoint(l.Axis, transPos, cross))).Add(ops) child.macro.Add(ops) stack.Pop() diff --git a/ui/measure/measure.go b/ui/measure/measure.go index 5213c0ed..71605c97 100644 --- a/ui/measure/measure.go +++ b/ui/measure/measure.go @@ -8,9 +8,9 @@ import ( "unicode/utf8" "gioui.org/ui" - "gioui.org/ui/draw" "gioui.org/ui/f32" "gioui.org/ui/text" + "gioui.org/ui/paint" "golang.org/x/image/font" "golang.org/x/image/font/sfnt" "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 { var lastPos f32.Point - var builder draw.PathBuilder + var builder paint.PathBuilder ops := new(ui.Ops) builder.Init(ops) var x fixed.Int26_6 diff --git a/ui/draw/draw.go b/ui/paint/paint.go similarity index 91% rename from ui/draw/draw.go rename to ui/paint/paint.go index 943d28cb..1306466b 100644 --- a/ui/draw/draw.go +++ b/ui/paint/paint.go @@ -1,6 +1,6 @@ // SPDX-License-Identifier: Unlicense OR MIT -package draw +package paint import ( "encoding/binary" @@ -22,7 +22,7 @@ type ColorOp struct { Color color.RGBA } -type DrawOp struct { +type PaintOp struct { Rect f32.Rectangle } @@ -47,9 +47,9 @@ func (c ColorOp) Add(o *ui.Ops) { o.Write(data) } -func (d DrawOp) Add(o *ui.Ops) { - data := make([]byte, opconst.TypeDrawLen) - data[0] = byte(opconst.TypeDraw) +func (d PaintOp) Add(o *ui.Ops) { + data := make([]byte, opconst.TypePaintLen) + data[0] = byte(opconst.TypePaint) bo := binary.LittleEndian bo.PutUint32(data[1:], math.Float32bits(d.Rect.Min.X)) bo.PutUint32(data[5:], math.Float32bits(d.Rect.Min.Y)) diff --git a/ui/draw/path.go b/ui/paint/path.go similarity index 99% rename from ui/draw/path.go rename to ui/paint/path.go index d2fa7f40..877b97e1 100644 --- a/ui/draw/path.go +++ b/ui/paint/path.go @@ -1,6 +1,6 @@ // SPDX-License-Identifier: Unlicense OR MIT -package draw +package paint import ( "encoding/binary" diff --git a/ui/text/editor.go b/ui/text/editor.go index aadb1e8a..bb6fac79 100644 --- a/ui/text/editor.go +++ b/ui/text/editor.go @@ -10,12 +10,12 @@ import ( "unicode/utf8" "gioui.org/ui" - "gioui.org/ui/draw" "gioui.org/ui/gesture" "gioui.org/ui/input" "gioui.org/ui/key" "gioui.org/ui/layout" "gioui.org/ui/pointer" + "gioui.org/ui/paint" "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) // Apply material. Set a default color in case the material is empty. 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) } else { - draw.ColorOp{Color: color.RGBA{A: 0xaa}}.Add(ops) + paint.ColorOp{Color: color.RGBA{A: 0xaa}}.Add(ops) e.HintMaterial.Add(ops) } for { @@ -211,7 +211,7 @@ func (e *Editor) Layout(cfg ui.Config, queue input.Queue, ops *ui.Ops, cs layout stack.Push(ops) ui.TransformOp{}.Offset(lineOff).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() } 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) 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) - draw.DrawOp{Rect: toRectF(carRect)}.Add(ops) + paint.PaintOp{Rect: toRectF(carRect)}.Add(ops) } } if blinking { diff --git a/ui/text/label.go b/ui/text/label.go index 86b034fe..e32071d7 100644 --- a/ui/text/label.go +++ b/ui/text/label.go @@ -8,9 +8,9 @@ import ( "unicode/utf8" "gioui.org/ui" - "gioui.org/ui/draw" "gioui.org/ui/f32" "gioui.org/ui/layout" + "gioui.org/ui/paint" "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) l.Face.Path(str).Add(ops) // 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) - draw.DrawOp{Rect: lclip}.Add(ops) + paint.PaintOp{Rect: lclip}.Add(ops) stack.Pop() } return dims diff --git a/ui/widget/image.go b/ui/widget/image.go index 57ba2b4a..01e46b4b 100644 --- a/ui/widget/image.go +++ b/ui/widget/image.go @@ -6,9 +6,9 @@ import ( "image" "gioui.org/ui" - "gioui.org/ui/draw" "gioui.org/ui/f32" "gioui.org/ui/layout" + "gioui.org/ui/paint" ) 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{ Max: f32.Point{X: float32(d.X), Y: float32(d.Y)}, } - draw.ImageOp{Src: im.Src, Rect: im.Rect}.Add(ops) - draw.DrawOp{Rect: dr}.Add(ops) + paint.ImageOp{Src: im.Src, Rect: im.Rect}.Add(ops) + paint.PaintOp{Rect: dr}.Add(ops) return layout.Dimens{Size: d, Baseline: d.Y} }