~eliasnaur/gio

dd35a48a61ab51f0e55d2485798a3db3d7daa5e4 — Elias Naur 11 months ago 6e26c92
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>
10 files changed, 36 insertions(+), 35 deletions(-)

M ui/app/internal/gpu/gpu.go
M ui/go.sum
M ui/internal/opconst/ops.go
M ui/layout/list.go
M ui/measure/measure.go
R ui/draw/{draw.go => /paint.go}
R ui/draw/{path.go => /path.go}
M ui/text/editor.go
M ui/text/label.go
M ui/widget/image.go
M ui/app/internal/gpu/gpu.go => ui/app/internal/gpu/gpu.go +10 -10
@@ 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() {

M ui/go.sum => ui/go.sum +1 -0
@@ 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=

M ui/internal/opconst/ops.go => ui/internal/opconst/ops.go +3 -3
@@ 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,

M ui/layout/list.go => ui/layout/list.go +2 -2
@@ 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()

M ui/measure/measure.go => ui/measure/measure.go +2 -2
@@ 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

R ui/draw/draw.go => ui/paint/paint.go +5 -5
@@ 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))

R ui/draw/path.go => ui/paint/path.go +1 -1
@@ 1,6 1,6 @@
// SPDX-License-Identifier: Unlicense OR MIT

package draw
package paint

import (
	"encoding/binary"

M ui/text/editor.go => ui/text/editor.go +6 -6
@@ 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 {

M ui/text/label.go => ui/text/label.go +3 -3
@@ 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

M ui/widget/image.go => ui/widget/image.go +3 -3
@@ 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}
}