all: replace deprecated pointer.Rect with clip.Rect

Converted with

gofmt -w -r 'pointer.Rect(r) -> clip.Rect(r)' .
gofmt -w -r 'pointer.Ellipse(r) -> clip.Ellipse(layout.FRect(r))' .

combined with 'goimports -w .' to clean up imports.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2021-10-26 12:53:54 +02:00
parent 29cea1db49
commit 3e0b72304a
13 changed files with 41 additions and 39 deletions
+3 -2
View File
@@ -123,9 +123,10 @@ func (w *quarterWidget) Layout(gtx layout.Context) layout.Dimensions {
r := image.Rectangle{Max: gtx.Constraints.Max} r := image.Rectangle{Max: gtx.Constraints.Max}
paint.FillShape(gtx.Ops, color, clip.Rect(r).Op()) paint.FillShape(gtx.Ops, color, clip.Rect(r).Op())
pointer.Rect(image.Rectangle{ clip.Rect(image.Rectangle{
Max: image.Pt(gtx.Constraints.Max.X, gtx.Constraints.Max.Y), Max: image.Pt(gtx.Constraints.Max.X, gtx.Constraints.Max.Y),
}).Add(gtx.Ops) }).
Add(gtx.Ops)
pointer.InputOp{ pointer.InputOp{
Tag: w, Tag: w,
Types: pointer.Press, Types: pointer.Press,
+2 -1
View File
@@ -12,13 +12,14 @@ import (
"gioui.org/io/pointer" "gioui.org/io/pointer"
"gioui.org/io/router" "gioui.org/io/router"
"gioui.org/op" "gioui.org/op"
"gioui.org/op/clip"
) )
func TestHover(t *testing.T) { func TestHover(t *testing.T) {
ops := new(op.Ops) ops := new(op.Ops)
var h Hover var h Hover
rect := image.Rect(20, 20, 40, 40) rect := image.Rect(20, 20, 40, 40)
stack := pointer.Rect(rect).Push(ops) stack := clip.Rect(rect).Push(ops)
h.Add(ops) h.Add(ops)
stack.Pop() stack.Pop()
r := new(router.Router) r := new(router.Router)
+16 -15
View File
@@ -155,10 +155,10 @@ func TestPointerMove(t *testing.T) {
types := pointer.Move | pointer.Enter | pointer.Leave types := pointer.Move | pointer.Enter | pointer.Leave
// Handler 1 area: (0, 0) - (100, 100) // Handler 1 area: (0, 0) - (100, 100)
r1 := pointer.Rect(image.Rect(0, 0, 100, 100)).Push(&ops) r1 := clip.Rect(image.Rect(0, 0, 100, 100)).Push(&ops)
pointer.InputOp{Tag: handler1, Types: types}.Add(&ops) pointer.InputOp{Tag: handler1, Types: types}.Add(&ops)
// Handler 2 area: (50, 50) - (100, 100) (areas intersect). // Handler 2 area: (50, 50) - (100, 100) (areas intersect).
r2 := pointer.Rect(image.Rect(50, 50, 200, 200)).Push(&ops) r2 := clip.Rect(image.Rect(50, 50, 200, 200)).Push(&ops)
pointer.InputOp{Tag: handler2, Types: types}.Add(&ops) pointer.InputOp{Tag: handler2, Types: types}.Add(&ops)
r2.Pop() r2.Pop()
r1.Pop() r1.Pop()
@@ -192,7 +192,7 @@ func TestPointerMove(t *testing.T) {
func TestPointerTypes(t *testing.T) { func TestPointerTypes(t *testing.T) {
handler := new(int) handler := new(int)
var ops op.Ops var ops op.Ops
r1 := pointer.Rect(image.Rect(0, 0, 100, 100)).Push(&ops) r1 := clip.Rect(image.Rect(0, 0, 100, 100)).Push(&ops)
pointer.InputOp{ pointer.InputOp{
Tag: handler, Tag: handler,
Types: pointer.Press | pointer.Release, Types: pointer.Press | pointer.Release,
@@ -224,14 +224,14 @@ func TestPointerPriority(t *testing.T) {
handler3 := new(int) handler3 := new(int)
var ops op.Ops var ops op.Ops
r1 := pointer.Rect(image.Rect(0, 0, 100, 100)).Push(&ops) r1 := clip.Rect(image.Rect(0, 0, 100, 100)).Push(&ops)
pointer.InputOp{ pointer.InputOp{
Tag: handler1, Tag: handler1,
Types: pointer.Scroll, Types: pointer.Scroll,
ScrollBounds: image.Rectangle{Max: image.Point{X: 100}}, ScrollBounds: image.Rectangle{Max: image.Point{X: 100}},
}.Add(&ops) }.Add(&ops)
r2 := pointer.Rect(image.Rect(0, 0, 100, 50)).Push(&ops) r2 := clip.Rect(image.Rect(0, 0, 100, 50)).Push(&ops)
pointer.InputOp{ pointer.InputOp{
Tag: handler2, Tag: handler2,
Types: pointer.Scroll, Types: pointer.Scroll,
@@ -240,7 +240,7 @@ func TestPointerPriority(t *testing.T) {
r2.Pop() r2.Pop()
r1.Pop() r1.Pop()
r3 := pointer.Rect(image.Rect(0, 100, 100, 200)).Push(&ops) r3 := clip.Rect(image.Rect(0, 100, 100, 200)).Push(&ops)
pointer.InputOp{ pointer.InputOp{
Tag: handler3, Tag: handler3,
Types: pointer.Scroll, Types: pointer.Scroll,
@@ -394,7 +394,7 @@ func TestMultipleAreas(t *testing.T) {
var ops op.Ops var ops op.Ops
addPointerHandler(&ops, handler, image.Rect(0, 0, 100, 100)) addPointerHandler(&ops, handler, image.Rect(0, 0, 100, 100))
r1 := pointer.Rect(image.Rect(50, 50, 200, 200)).Push(&ops) r1 := clip.Rect(image.Rect(50, 50, 200, 200)).Push(&ops)
// Second area has no Types set, yet should receive events because // Second area has no Types set, yet should receive events because
// Types for the same handles are or-ed together. // Types for the same handles are or-ed together.
pointer.InputOp{Tag: handler}.Add(&ops) pointer.InputOp{Tag: handler}.Add(&ops)
@@ -428,11 +428,11 @@ func TestPointerEnterLeaveNested(t *testing.T) {
types := pointer.Press | pointer.Move | pointer.Release | pointer.Enter | pointer.Leave types := pointer.Press | pointer.Move | pointer.Release | pointer.Enter | pointer.Leave
// Handler 1 area: (0, 0) - (100, 100) // Handler 1 area: (0, 0) - (100, 100)
r1 := pointer.Rect(image.Rect(0, 0, 100, 100)).Push(&ops) r1 := clip.Rect(image.Rect(0, 0, 100, 100)).Push(&ops)
pointer.InputOp{Tag: handler1, Types: types}.Add(&ops) pointer.InputOp{Tag: handler1, Types: types}.Add(&ops)
// Handler 2 area: (25, 25) - (75, 75) (nested within first). // Handler 2 area: (25, 25) - (75, 75) (nested within first).
r2 := pointer.Rect(image.Rect(25, 25, 75, 75)).Push(&ops) r2 := clip.Rect(image.Rect(25, 25, 75, 75)).Push(&ops)
pointer.InputOp{Tag: handler2, Types: types}.Add(&ops) pointer.InputOp{Tag: handler2, Types: types}.Add(&ops)
r2.Pop() r2.Pop()
r1.Pop() r1.Pop()
@@ -576,7 +576,7 @@ func TestCursorNameOp(t *testing.T) {
var widget2 func() var widget2 func()
widget := func() { widget := func() {
// This is the area where the cursor is changed to CursorPointer. // This is the area where the cursor is changed to CursorPointer.
defer pointer.Rect(image.Rectangle{Max: image.Pt(100, 100)}).Push(ops).Pop() defer clip.Rect(image.Rectangle{Max: image.Pt(100, 100)}).Push(ops).Pop()
// The cursor is checked and changed upon cursor movement. // The cursor is checked and changed upon cursor movement.
pointer.InputOp{Tag: &h}.Add(ops) pointer.InputOp{Tag: &h}.Add(ops)
pointer.CursorNameOp{Name: pointer.CursorPointer}.Add(ops) pointer.CursorNameOp{Name: pointer.CursorPointer}.Add(ops)
@@ -691,7 +691,7 @@ func TestPassOp(t *testing.T) {
var ops op.Ops var ops op.Ops
h1, h2, h3, h4 := new(int), new(int), new(int), new(int) h1, h2, h3, h4 := new(int), new(int), new(int), new(int)
area := pointer.Rect(image.Rect(0, 0, 100, 100)) area := clip.Rect(image.Rect(0, 0, 100, 100))
root := area.Push(&ops) root := area.Push(&ops)
pointer.InputOp{Tag: h1, Types: pointer.Press}.Add(&ops) pointer.InputOp{Tag: h1, Types: pointer.Press}.Add(&ops)
child1 := area.Push(&ops) child1 := area.Push(&ops)
@@ -723,7 +723,7 @@ func TestAreaPassthrough(t *testing.T) {
h := new(int) h := new(int)
pointer.InputOp{Tag: h, Types: pointer.Press}.Add(&ops) pointer.InputOp{Tag: h, Types: pointer.Press}.Add(&ops)
pointer.Rect(image.Rect(0, 0, 100, 100)).Push(&ops).Pop() clip.Rect(image.Rect(0, 0, 100, 100)).Push(&ops).Pop()
var r Router var r Router
r.Frame(&ops) r.Frame(&ops)
r.Queue( r.Queue(
@@ -764,7 +764,7 @@ func TestEllipse(t *testing.T) {
// addPointerHandler adds a pointer.InputOp for the tag in a // addPointerHandler adds a pointer.InputOp for the tag in a
// rectangular area. // rectangular area.
func addPointerHandler(ops *op.Ops, tag event.Tag, area image.Rectangle) { func addPointerHandler(ops *op.Ops, tag event.Tag, area image.Rectangle) {
defer pointer.Rect(area).Push(ops).Pop() defer clip.Rect(area).Push(ops).Pop()
pointer.InputOp{ pointer.InputOp{
Tag: tag, Tag: tag,
Types: pointer.Press | pointer.Release | pointer.Move | pointer.Drag | pointer.Enter | pointer.Leave, Types: pointer.Press | pointer.Release | pointer.Move | pointer.Drag | pointer.Enter | pointer.Leave,
@@ -835,12 +835,13 @@ func BenchmarkRouterAdd(b *testing.B) {
var ops op.Ops var ops op.Ops
for i := range handlers { for i := range handlers {
pointer.Rect(image.Rectangle{ clip.Rect(image.Rectangle{
Max: image.Point{ Max: image.Point{
X: 100, X: 100,
Y: 100, Y: 100,
}, },
}).Push(&ops) }).
Push(&ops)
pointer.InputOp{ pointer.InputOp{
Tag: handlers[i], Tag: handlers[i],
Types: pointer.Move, Types: pointer.Move,
+1 -2
View File
@@ -6,7 +6,6 @@ import (
"image" "image"
"gioui.org/gesture" "gioui.org/gesture"
"gioui.org/io/pointer"
"gioui.org/op" "gioui.org/op"
"gioui.org/op/clip" "gioui.org/op/clip"
) )
@@ -296,7 +295,7 @@ func (l *List) layout(ops *op.Ops, macro op.MacroOp) Dimensions {
} }
dims := l.Axis.Convert(image.Pt(pos, maxCross)) dims := l.Axis.Convert(image.Pt(pos, maxCross))
call := macro.Stop() call := macro.Stop()
defer pointer.Rect(image.Rectangle{Max: dims}).Push(ops).Pop() defer clip.Rect(image.Rectangle{Max: dims}).Push(ops).Pop()
var min, max int var min, max int
if o := l.Position.Offset; o > 0 { if o := l.Position.Offset; o > 0 {
+2 -2
View File
@@ -9,8 +9,8 @@ import (
"gioui.org/f32" "gioui.org/f32"
"gioui.org/gesture" "gioui.org/gesture"
"gioui.org/io/key" "gioui.org/io/key"
"gioui.org/io/pointer"
"gioui.org/layout" "gioui.org/layout"
"gioui.org/op/clip"
) )
// Clickable represents a clickable area. // Clickable represents a clickable area.
@@ -92,7 +92,7 @@ func (b *Clickable) History() []Press {
// Layout and update the button state // Layout and update the button state
func (b *Clickable) Layout(gtx layout.Context) layout.Dimensions { func (b *Clickable) Layout(gtx layout.Context) layout.Dimensions {
b.update(gtx) b.update(gtx)
defer pointer.Rect(image.Rectangle{Max: gtx.Constraints.Min}).Push(gtx.Ops).Pop() defer clip.Rect(image.Rectangle{Max: gtx.Constraints.Min}).Push(gtx.Ops).Pop()
b.click.Add(gtx.Ops) b.click.Add(gtx.Ops)
for len(b.history) > 0 { for len(b.history) > 0 {
c := b.history[0] c := b.history[0]
+4 -4
View File
@@ -513,14 +513,14 @@ func (e *Editor) layout(gtx layout.Context) layout.Dimensions {
X: -e.scrollOff.X, X: -e.scrollOff.X,
Y: -e.scrollOff.Y, Y: -e.scrollOff.Y,
} }
clip := textPadding(e.lines) cl := textPadding(e.lines)
clip.Max = clip.Max.Add(e.viewSize) cl.Max = cl.Max.Add(e.viewSize)
startSel, endSel := sortPoints(e.caret.start.lineCol, e.caret.end.lineCol) startSel, endSel := sortPoints(e.caret.start.lineCol, e.caret.end.lineCol)
it := segmentIterator{ it := segmentIterator{
startSel: startSel, startSel: startSel,
endSel: endSel, endSel: endSel,
Lines: e.lines, Lines: e.lines,
Clip: clip, Clip: cl,
Alignment: e.Alignment, Alignment: e.Alignment,
Width: e.viewSize.X, Width: e.viewSize.X,
Offset: off, Offset: off,
@@ -547,7 +547,7 @@ func (e *Editor) layout(gtx layout.Context) layout.Dimensions {
r.Min.Y -= pointerPadding r.Min.Y -= pointerPadding
r.Max.X += pointerPadding r.Max.X += pointerPadding
r.Max.X += pointerPadding r.Max.X += pointerPadding
defer pointer.Rect(r).Push(gtx.Ops).Pop() defer clip.Rect(r).Push(gtx.Ops).Pop()
pointer.CursorNameOp{Name: pointer.CursorText}.Add(gtx.Ops) pointer.CursorNameOp{Name: pointer.CursorText}.Add(gtx.Ops)
var scrollRange image.Rectangle var scrollRange image.Rectangle
+2 -2
View File
@@ -4,8 +4,8 @@ import (
"image" "image"
"gioui.org/gesture" "gioui.org/gesture"
"gioui.org/io/pointer"
"gioui.org/layout" "gioui.org/layout"
"gioui.org/op/clip"
) )
type Enum struct { type Enum struct {
@@ -43,7 +43,7 @@ func (e *Enum) Hovered() (string, bool) {
// Layout adds the event handler for key. // Layout adds the event handler for key.
func (e *Enum) Layout(gtx layout.Context, key string) layout.Dimensions { func (e *Enum) Layout(gtx layout.Context, key string) layout.Dimensions {
defer pointer.Rect(image.Rectangle{Max: gtx.Constraints.Min}).Push(gtx.Ops).Pop() defer clip.Rect(image.Rectangle{Max: gtx.Constraints.Min}).Push(gtx.Ops).Pop()
if index(e.values, key) == -1 { if index(e.values, key) == -1 {
e.values = append(e.values, key) e.values = append(e.values, key)
+2 -1
View File
@@ -8,6 +8,7 @@ import (
"gioui.org/gesture" "gioui.org/gesture"
"gioui.org/io/pointer" "gioui.org/io/pointer"
"gioui.org/layout" "gioui.org/layout"
"gioui.org/op/clip"
) )
// Float is for selecting a value in a range. // Float is for selecting a value in a range.
@@ -63,7 +64,7 @@ func (f *Float) Layout(gtx layout.Context, pointerMargin int, min, max float32)
Min: margin.Mul(-1), Min: margin.Mul(-1),
Max: size.Add(margin), Max: size.Add(margin),
} }
defer pointer.Rect(rect).Push(gtx.Ops).Pop() defer clip.Rect(rect).Push(gtx.Ops).Pop()
f.drag.Add(gtx.Ops) f.drag.Add(gtx.Ops)
return layout.Dimensions{Size: size} return layout.Dimensions{Size: size}
+2 -2
View File
@@ -9,7 +9,6 @@ import (
"gioui.org/f32" "gioui.org/f32"
"gioui.org/internal/f32color" "gioui.org/internal/f32color"
"gioui.org/io/pointer"
"gioui.org/layout" "gioui.org/layout"
"gioui.org/op" "gioui.org/op"
"gioui.org/op/clip" "gioui.org/op/clip"
@@ -178,7 +177,8 @@ func (b IconButtonStyle) Layout(gtx layout.Context) layout.Dimensions {
}) })
}), }),
layout.Expanded(func(gtx layout.Context) layout.Dimensions { layout.Expanded(func(gtx layout.Context) layout.Dimensions {
defer pointer.Ellipse(image.Rectangle{Max: gtx.Constraints.Min}).Push(gtx.Ops).Pop() bounds := f32.Rectangle{Max: layout.FPt(gtx.Constraints.Min)}
defer clip.Ellipse(bounds).Push(gtx.Ops).Pop()
return b.Button.Layout(gtx) return b.Button.Layout(gtx)
}), }),
) )
+2 -2
View File
@@ -5,8 +5,8 @@ package material
import ( import (
"image" "image"
"gioui.org/io/pointer"
"gioui.org/layout" "gioui.org/layout"
"gioui.org/op/clip"
"gioui.org/unit" "gioui.org/unit"
"gioui.org/widget" "gioui.org/widget"
) )
@@ -35,7 +35,7 @@ func CheckBox(th *Theme, checkBox *widget.Bool, label string) CheckBoxStyle {
// Layout updates the checkBox and displays it. // Layout updates the checkBox and displays it.
func (c CheckBoxStyle) Layout(gtx layout.Context) layout.Dimensions { func (c CheckBoxStyle) Layout(gtx layout.Context) layout.Dimensions {
dims := c.layout(gtx, c.CheckBox.Value, c.CheckBox.Hovered()) dims := c.layout(gtx, c.CheckBox.Value, c.CheckBox.Hovered())
defer pointer.Rect(image.Rectangle{Max: dims.Size}).Push(gtx.Ops).Pop() defer clip.Rect(image.Rectangle{Max: dims.Size}).Push(gtx.Ops).Pop()
gtx.Constraints.Min = dims.Size gtx.Constraints.Min = dims.Size
c.CheckBox.Layout(gtx) c.CheckBox.Layout(gtx)
return dims return dims
+2 -2
View File
@@ -155,7 +155,7 @@ func (s ScrollbarStyle) layout(gtx layout.Context, axis layout.Axis, viewportSta
area := image.Rectangle{ area := image.Rectangle{
Max: gtx.Constraints.Min, Max: gtx.Constraints.Min,
} }
pointerArea := pointer.Rect(area) pointerArea := clip.Rect(area)
defer pointerArea.Push(gtx.Ops).Pop() defer pointerArea.Push(gtx.Ops).Pop()
s.Scrollbar.AddDrag(gtx.Ops) s.Scrollbar.AddDrag(gtx.Ops)
@@ -205,7 +205,7 @@ func (s ScrollbarStyle) layout(gtx layout.Context, axis layout.Axis, viewportSta
}.Op(gtx.Ops)) }.Op(gtx.Ops))
// Add the indicator pointer hit area. // Add the indicator pointer hit area.
area := pointer.Rect(image.Rectangle{Max: indicatorDims}) area := clip.Rect(image.Rectangle{Max: indicatorDims})
defer pointer.PassOp{}.Push(gtx.Ops).Pop() defer pointer.PassOp{}.Push(gtx.Ops).Pop()
defer area.Push(gtx.Ops).Pop() defer area.Push(gtx.Ops).Pop()
s.Scrollbar.AddIndicator(gtx.Ops) s.Scrollbar.AddIndicator(gtx.Ops)
+2 -2
View File
@@ -5,8 +5,8 @@ package material
import ( import (
"image" "image"
"gioui.org/io/pointer"
"gioui.org/layout" "gioui.org/layout"
"gioui.org/op/clip"
"gioui.org/unit" "gioui.org/unit"
"gioui.org/widget" "gioui.org/widget"
) )
@@ -41,7 +41,7 @@ func RadioButton(th *Theme, group *widget.Enum, key, label string) RadioButtonSt
func (r RadioButtonStyle) Layout(gtx layout.Context) layout.Dimensions { func (r RadioButtonStyle) Layout(gtx layout.Context) layout.Dimensions {
hovered, hovering := r.Group.Hovered() hovered, hovering := r.Group.Hovered()
dims := r.layout(gtx, r.Group.Value == r.Key, hovering && hovered == r.Key) dims := r.layout(gtx, r.Group.Value == r.Key, hovering && hovered == r.Key)
defer pointer.Rect(image.Rectangle{Max: dims.Size}).Push(gtx.Ops).Pop() defer clip.Rect(image.Rectangle{Max: dims.Size}).Push(gtx.Ops).Pop()
gtx.Constraints.Min = dims.Size gtx.Constraints.Min = dims.Size
r.Group.Layout(gtx, r.Key) r.Group.Layout(gtx, r.Key)
return dims return dims
+1 -2
View File
@@ -8,7 +8,6 @@ import (
"gioui.org/f32" "gioui.org/f32"
"gioui.org/internal/f32color" "gioui.org/internal/f32color"
"gioui.org/io/pointer"
"gioui.org/layout" "gioui.org/layout"
"gioui.org/op" "gioui.org/op"
"gioui.org/op/clip" "gioui.org/op/clip"
@@ -124,7 +123,7 @@ func (s SwitchStyle) Layout(gtx layout.Context) layout.Dimensions {
} }
defer op.Offset(clickOff).Push(gtx.Ops).Pop() defer op.Offset(clickOff).Push(gtx.Ops).Pop()
sz := image.Pt(clickSize, clickSize) sz := image.Pt(clickSize, clickSize)
defer pointer.Ellipse(image.Rectangle{Max: sz}).Push(gtx.Ops).Pop() defer clip.Ellipse(f32.Rectangle{Max: layout.FPt(sz)}).Push(gtx.Ops).Pop()
gtx.Constraints.Min = sz gtx.Constraints.Min = sz
s.Switch.Layout(gtx) s.Switch.Layout(gtx)