io/pointer: [API] rename PointerEvent.Type to Kind

Kind is the idiomatic field name for distinguishing a struct without
using separate types.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2023-10-06 18:19:13 -05:00
parent e1b3928819
commit 650ccea28d
26 changed files with 226 additions and 226 deletions
+100 -100
View File
@@ -50,12 +50,12 @@ func TestPointerDrag(t *testing.T) {
r.Queue(
// Press.
pointer.Event{
Type: pointer.Press,
Kind: pointer.Press,
Position: f32.Pt(50, 50),
},
// Move outside the area.
pointer.Event{
Type: pointer.Move,
Kind: pointer.Move,
Position: f32.Pt(150, 150),
},
)
@@ -72,12 +72,12 @@ func TestPointerDragNegative(t *testing.T) {
r.Queue(
// Press.
pointer.Event{
Type: pointer.Press,
Kind: pointer.Press,
Position: f32.Pt(-50, -50),
},
// Move outside the area.
pointer.Event{
Type: pointer.Move,
Kind: pointer.Move,
Position: f32.Pt(-150, -150),
},
)
@@ -92,15 +92,15 @@ func TestPointerGrab(t *testing.T) {
types := pointer.Press | pointer.Release
pointer.InputOp{Tag: handler1, Types: types, Grab: true}.Add(&ops)
pointer.InputOp{Tag: handler2, Types: types}.Add(&ops)
pointer.InputOp{Tag: handler3, Types: types}.Add(&ops)
pointer.InputOp{Tag: handler1, Kinds: types, Grab: true}.Add(&ops)
pointer.InputOp{Tag: handler2, Kinds: types}.Add(&ops)
pointer.InputOp{Tag: handler3, Kinds: types}.Add(&ops)
var r Router
r.Frame(&ops)
r.Queue(
pointer.Event{
Type: pointer.Press,
Kind: pointer.Press,
Position: f32.Pt(50, 50),
},
)
@@ -110,7 +110,7 @@ func TestPointerGrab(t *testing.T) {
r.Frame(&ops)
r.Queue(
pointer.Event{
Type: pointer.Release,
Kind: pointer.Release,
Position: f32.Pt(50, 50),
},
)
@@ -126,15 +126,15 @@ func TestPointerGrabSameHandlerTwice(t *testing.T) {
types := pointer.Press | pointer.Release
pointer.InputOp{Tag: handler1, Types: types, Grab: true}.Add(&ops)
pointer.InputOp{Tag: handler1, Types: types}.Add(&ops)
pointer.InputOp{Tag: handler2, Types: types}.Add(&ops)
pointer.InputOp{Tag: handler1, Kinds: types, Grab: true}.Add(&ops)
pointer.InputOp{Tag: handler1, Kinds: types}.Add(&ops)
pointer.InputOp{Tag: handler2, Kinds: types}.Add(&ops)
var r Router
r.Frame(&ops)
r.Queue(
pointer.Event{
Type: pointer.Press,
Kind: pointer.Press,
Position: f32.Pt(50, 50),
},
)
@@ -143,7 +143,7 @@ func TestPointerGrabSameHandlerTwice(t *testing.T) {
r.Frame(&ops)
r.Queue(
pointer.Event{
Type: pointer.Release,
Kind: pointer.Release,
Position: f32.Pt(50, 50),
},
)
@@ -160,10 +160,10 @@ func TestPointerMove(t *testing.T) {
// Handler 1 area: (0, 0) - (100, 100)
r1 := clip.Rect(image.Rect(0, 0, 100, 100)).Push(&ops)
pointer.InputOp{Tag: handler1, Types: types}.Add(&ops)
pointer.InputOp{Tag: handler1, Kinds: types}.Add(&ops)
// Handler 2 area: (50, 50) - (100, 100) (areas intersect).
r2 := clip.Rect(image.Rect(50, 50, 200, 200)).Push(&ops)
pointer.InputOp{Tag: handler2, Types: types}.Add(&ops)
pointer.InputOp{Tag: handler2, Kinds: types}.Add(&ops)
r2.Pop()
r1.Pop()
@@ -172,21 +172,21 @@ func TestPointerMove(t *testing.T) {
r.Queue(
// Hit both handlers.
pointer.Event{
Type: pointer.Move,
Kind: pointer.Move,
Position: f32.Pt(50, 50),
},
// Hit handler 1.
pointer.Event{
Type: pointer.Move,
Kind: pointer.Move,
Position: f32.Pt(49, 50),
},
// Hit no handlers.
pointer.Event{
Type: pointer.Move,
Kind: pointer.Move,
Position: f32.Pt(100, 50),
},
pointer.Event{
Type: pointer.Cancel,
Kind: pointer.Cancel,
},
)
assertEventPointerTypeSequence(t, r.Events(handler1), pointer.Cancel, pointer.Enter, pointer.Move, pointer.Move, pointer.Leave, pointer.Cancel)
@@ -199,7 +199,7 @@ func TestPointerTypes(t *testing.T) {
r1 := clip.Rect(image.Rect(0, 0, 100, 100)).Push(&ops)
pointer.InputOp{
Tag: handler,
Types: pointer.Press | pointer.Release,
Kinds: pointer.Press | pointer.Release,
}.Add(&ops)
r1.Pop()
@@ -207,15 +207,15 @@ func TestPointerTypes(t *testing.T) {
r.Frame(&ops)
r.Queue(
pointer.Event{
Type: pointer.Press,
Kind: pointer.Press,
Position: f32.Pt(50, 50),
},
pointer.Event{
Type: pointer.Move,
Kind: pointer.Move,
Position: f32.Pt(150, 150),
},
pointer.Event{
Type: pointer.Release,
Kind: pointer.Release,
Position: f32.Pt(150, 150),
},
)
@@ -268,14 +268,14 @@ func TestPointerPriority(t *testing.T) {
r1 := clip.Rect(image.Rect(0, 0, 100, 100)).Push(&ops)
pointer.InputOp{
Tag: handler1,
Types: pointer.Scroll,
Kinds: pointer.Scroll,
ScrollBounds: image.Rectangle{Max: image.Point{X: 100}},
}.Add(&ops)
r2 := clip.Rect(image.Rect(0, 0, 100, 50)).Push(&ops)
pointer.InputOp{
Tag: handler2,
Types: pointer.Scroll,
Kinds: pointer.Scroll,
ScrollBounds: image.Rectangle{Max: image.Point{X: 20}},
}.Add(&ops)
r2.Pop()
@@ -284,7 +284,7 @@ func TestPointerPriority(t *testing.T) {
r3 := clip.Rect(image.Rect(0, 100, 100, 200)).Push(&ops)
pointer.InputOp{
Tag: handler3,
Types: pointer.Scroll,
Kinds: pointer.Scroll,
ScrollBounds: image.Rectangle{Min: image.Point{X: -20, Y: -40}},
}.Add(&ops)
r3.Pop()
@@ -294,25 +294,25 @@ func TestPointerPriority(t *testing.T) {
r.Queue(
// Hit handler 1 and 2.
pointer.Event{
Type: pointer.Scroll,
Kind: pointer.Scroll,
Position: f32.Pt(50, 25),
Scroll: f32.Pt(50, 0),
},
// Hit handler 1.
pointer.Event{
Type: pointer.Scroll,
Kind: pointer.Scroll,
Position: f32.Pt(50, 75),
Scroll: f32.Pt(50, 50),
},
// Hit handler 3.
pointer.Event{
Type: pointer.Scroll,
Kind: pointer.Scroll,
Position: f32.Pt(50, 150),
Scroll: f32.Pt(-30, -30),
},
// Hit no handlers.
pointer.Event{
Type: pointer.Scroll,
Kind: pointer.Scroll,
Position: f32.Pt(50, 225),
},
)
@@ -348,7 +348,7 @@ func TestPointerEnterLeave(t *testing.T) {
// Hit both handlers.
r.Queue(
pointer.Event{
Type: pointer.Move,
Kind: pointer.Move,
Position: f32.Pt(50, 50),
},
)
@@ -361,7 +361,7 @@ func TestPointerEnterLeave(t *testing.T) {
// Leave the second area by moving into the first.
r.Queue(
pointer.Event{
Type: pointer.Move,
Kind: pointer.Move,
Position: f32.Pt(45, 45),
},
)
@@ -372,7 +372,7 @@ func TestPointerEnterLeave(t *testing.T) {
// Move, but stay within the same hit area.
r.Queue(
pointer.Event{
Type: pointer.Move,
Kind: pointer.Move,
Position: f32.Pt(40, 40),
},
)
@@ -382,7 +382,7 @@ func TestPointerEnterLeave(t *testing.T) {
// Move outside of both inputs.
r.Queue(
pointer.Event{
Type: pointer.Move,
Kind: pointer.Move,
Position: f32.Pt(300, 300),
},
)
@@ -392,7 +392,7 @@ func TestPointerEnterLeave(t *testing.T) {
// Check that a Press event generates Enter Events.
r.Queue(
pointer.Event{
Type: pointer.Press,
Kind: pointer.Press,
Position: f32.Pt(125, 125),
},
)
@@ -403,12 +403,12 @@ func TestPointerEnterLeave(t *testing.T) {
r.Queue(
// Leave
pointer.Event{
Type: pointer.Move,
Kind: pointer.Move,
Position: f32.Pt(25, 25),
},
// Enter
pointer.Event{
Type: pointer.Move,
Kind: pointer.Move,
Position: f32.Pt(50, 50),
},
)
@@ -418,7 +418,7 @@ func TestPointerEnterLeave(t *testing.T) {
// Check that a Release event generates Enter/Leave Events.
r.Queue(
pointer.Event{
Type: pointer.Release,
Kind: pointer.Release,
Position: f32.Pt(25,
25),
},
@@ -446,15 +446,15 @@ func TestMultipleAreas(t *testing.T) {
// Hit first area, then second area, then both.
r.Queue(
pointer.Event{
Type: pointer.Move,
Kind: pointer.Move,
Position: f32.Pt(25, 25),
},
pointer.Event{
Type: pointer.Move,
Kind: pointer.Move,
Position: f32.Pt(150, 150),
},
pointer.Event{
Type: pointer.Move,
Kind: pointer.Move,
Position: f32.Pt(50, 50),
},
)
@@ -470,11 +470,11 @@ func TestPointerEnterLeaveNested(t *testing.T) {
// Handler 1 area: (0, 0) - (100, 100)
r1 := clip.Rect(image.Rect(0, 0, 100, 100)).Push(&ops)
pointer.InputOp{Tag: handler1, Types: types}.Add(&ops)
pointer.InputOp{Tag: handler1, Kinds: types}.Add(&ops)
// Handler 2 area: (25, 25) - (75, 75) (nested within first).
r2 := clip.Rect(image.Rect(25, 25, 75, 75)).Push(&ops)
pointer.InputOp{Tag: handler2, Types: types}.Add(&ops)
pointer.InputOp{Tag: handler2, Kinds: types}.Add(&ops)
r2.Pop()
r1.Pop()
@@ -483,7 +483,7 @@ func TestPointerEnterLeaveNested(t *testing.T) {
// Hit both handlers.
r.Queue(
pointer.Event{
Type: pointer.Move,
Kind: pointer.Move,
Position: f32.Pt(50, 50),
},
)
@@ -495,7 +495,7 @@ func TestPointerEnterLeaveNested(t *testing.T) {
// Leave the second area by moving into the first.
r.Queue(
pointer.Event{
Type: pointer.Move,
Kind: pointer.Move,
Position: f32.Pt(20, 20),
},
)
@@ -505,7 +505,7 @@ func TestPointerEnterLeaveNested(t *testing.T) {
// Move, but stay within the same hit area.
r.Queue(
pointer.Event{
Type: pointer.Move,
Kind: pointer.Move,
Position: f32.Pt(10, 10),
},
)
@@ -515,7 +515,7 @@ func TestPointerEnterLeaveNested(t *testing.T) {
// Move outside of both inputs.
r.Queue(
pointer.Event{
Type: pointer.Move,
Kind: pointer.Move,
Position: f32.Pt(200, 200),
},
)
@@ -525,7 +525,7 @@ func TestPointerEnterLeaveNested(t *testing.T) {
// Check that a Press event generates Enter Events.
r.Queue(
pointer.Event{
Type: pointer.Press,
Kind: pointer.Press,
Position: f32.Pt(50, 50),
},
)
@@ -535,7 +535,7 @@ func TestPointerEnterLeaveNested(t *testing.T) {
// Check that a Release event generates Enter/Leave Events.
r.Queue(
pointer.Event{
Type: pointer.Release,
Kind: pointer.Release,
Position: f32.Pt(20, 20),
},
)
@@ -554,7 +554,7 @@ func TestPointerActiveInputDisappears(t *testing.T) {
r.Frame(&ops)
r.Queue(
pointer.Event{
Type: pointer.Move,
Kind: pointer.Move,
Position: f32.Pt(25, 25),
},
)
@@ -565,7 +565,7 @@ func TestPointerActiveInputDisappears(t *testing.T) {
r.Frame(&ops)
r.Queue(
pointer.Event{
Type: pointer.Move,
Kind: pointer.Move,
Position: f32.Pt(25, 25),
},
)
@@ -587,21 +587,21 @@ func TestMultitouch(t *testing.T) {
r.Frame(&ops)
r.Queue(
pointer.Event{
Type: pointer.Press,
Kind: pointer.Press,
Position: h1pt,
PointerID: p1,
},
)
r.Queue(
pointer.Event{
Type: pointer.Press,
Kind: pointer.Press,
Position: h2pt,
PointerID: p2,
},
)
r.Queue(
pointer.Event{
Type: pointer.Release,
Kind: pointer.Release,
Position: h2pt,
PointerID: p2,
},
@@ -634,7 +634,7 @@ func TestCursor(t *testing.T) {
_at := func(x, y float32) pointer.Event {
return pointer.Event{
Type: pointer.Move,
Kind: pointer.Move,
Source: pointer.Mouse,
Buttons: pointer.ButtonPrimary,
Position: f32.Pt(x, y),
@@ -734,14 +734,14 @@ func TestPassOp(t *testing.T) {
h1, h2, h3, h4 := new(int), new(int), new(int), new(int)
area := clip.Rect(image.Rect(0, 0, 100, 100))
root := area.Push(&ops)
pointer.InputOp{Tag: h1, Types: pointer.Press}.Add(&ops)
pointer.InputOp{Tag: h1, Kinds: pointer.Press}.Add(&ops)
child1 := area.Push(&ops)
pointer.InputOp{Tag: h2, Types: pointer.Press}.Add(&ops)
pointer.InputOp{Tag: h2, Kinds: pointer.Press}.Add(&ops)
child1.Pop()
child2 := area.Push(&ops)
pass := pointer.PassOp{}.Push(&ops)
pointer.InputOp{Tag: h3, Types: pointer.Press}.Add(&ops)
pointer.InputOp{Tag: h4, Types: pointer.Press}.Add(&ops)
pointer.InputOp{Tag: h3, Kinds: pointer.Press}.Add(&ops)
pointer.InputOp{Tag: h4, Kinds: pointer.Press}.Add(&ops)
pass.Pop()
child2.Pop()
root.Pop()
@@ -750,7 +750,7 @@ func TestPassOp(t *testing.T) {
r.Frame(&ops)
r.Queue(
pointer.Event{
Type: pointer.Press,
Kind: pointer.Press,
},
)
assertEventPointerTypeSequence(t, r.Events(h1), pointer.Cancel, pointer.Press)
@@ -763,13 +763,13 @@ func TestAreaPassthrough(t *testing.T) {
var ops op.Ops
h := new(int)
pointer.InputOp{Tag: h, Types: pointer.Press}.Add(&ops)
pointer.InputOp{Tag: h, Kinds: pointer.Press}.Add(&ops)
clip.Rect(image.Rect(0, 0, 100, 100)).Push(&ops).Pop()
var r Router
r.Frame(&ops)
r.Queue(
pointer.Event{
Type: pointer.Press,
Kind: pointer.Press,
},
)
assertEventPointerTypeSequence(t, r.Events(h), pointer.Cancel, pointer.Press)
@@ -780,7 +780,7 @@ func TestEllipse(t *testing.T) {
h := new(int)
cl := clip.Ellipse(image.Rect(0, 0, 100, 100)).Push(&ops)
pointer.InputOp{Tag: h, Types: pointer.Press}.Add(&ops)
pointer.InputOp{Tag: h, Kinds: pointer.Press}.Add(&ops)
cl.Pop()
var r Router
r.Frame(&ops)
@@ -788,15 +788,15 @@ func TestEllipse(t *testing.T) {
// Outside ellipse.
pointer.Event{
Position: f32.Pt(10, 10),
Type: pointer.Press,
Kind: pointer.Press,
},
pointer.Event{
Type: pointer.Release,
Kind: pointer.Release,
},
// Inside ellipse.
pointer.Event{
Position: f32.Pt(50, 50),
Type: pointer.Press,
Kind: pointer.Press,
},
)
assertEventPointerTypeSequence(t, r.Events(h), pointer.Cancel, pointer.Press)
@@ -825,7 +825,7 @@ func TestTransfer(t *testing.T) {
return src, tgt
}
// Cancel is received when the pointer is first seen.
cancel := pointer.Event{Type: pointer.Cancel}
cancel := pointer.Event{Kind: pointer.Cancel}
t.Run("transfer.Offer should panic on nil Data", func(t *testing.T) {
defer func() {
@@ -845,11 +845,11 @@ func TestTransfer(t *testing.T) {
r.Queue(
pointer.Event{
Position: f32.Pt(10, 10),
Type: pointer.Press,
Kind: pointer.Press,
},
pointer.Event{
Position: f32.Pt(10, 10),
Type: pointer.Move,
Kind: pointer.Move,
},
)
assertEventSequence(t, r.Events(src), cancel)
@@ -859,11 +859,11 @@ func TestTransfer(t *testing.T) {
r.Queue(
pointer.Event{
Position: f32.Pt(30, 10),
Type: pointer.Move,
Kind: pointer.Move,
},
pointer.Event{
Position: f32.Pt(30, 10),
Type: pointer.Release,
Kind: pointer.Release,
},
)
assertEventSequence(t, r.Events(src), transfer.CancelEvent{})
@@ -886,11 +886,11 @@ func TestTransfer(t *testing.T) {
r.Queue(
pointer.Event{
Position: f32.Pt(10, 10),
Type: pointer.Press,
Kind: pointer.Press,
},
pointer.Event{
Position: f32.Pt(10, 10),
Type: pointer.Move,
Kind: pointer.Move,
},
)
assertEventSequence(t, r.Events(src), cancel)
@@ -907,11 +907,11 @@ func TestTransfer(t *testing.T) {
r.Queue(
pointer.Event{
Position: f32.Pt(10, 10),
Type: pointer.Press,
Kind: pointer.Press,
},
pointer.Event{
Position: f32.Pt(10, 10),
Type: pointer.Move,
Kind: pointer.Move,
},
)
assertEventSequence(t, r.Events(src), cancel)
@@ -921,7 +921,7 @@ func TestTransfer(t *testing.T) {
r.Queue(
pointer.Event{
Position: f32.Pt(40, 10),
Type: pointer.Release,
Kind: pointer.Release,
},
)
assertEventSequence(t, r.Events(src), transfer.CancelEvent{})
@@ -944,11 +944,11 @@ func TestTransfer(t *testing.T) {
r.Queue(
pointer.Event{
Position: f32.Pt(10, 10),
Type: pointer.Press,
Kind: pointer.Press,
},
pointer.Event{
Position: f32.Pt(10, 10),
Type: pointer.Move,
Kind: pointer.Move,
},
)
assertEventSequence(t, r.Events(src), cancel)
@@ -958,7 +958,7 @@ func TestTransfer(t *testing.T) {
r.Queue(
pointer.Event{
Position: f32.Pt(40, 10),
Type: pointer.Release,
Kind: pointer.Release,
},
)
assertEventSequence(t, r.Events(src), transfer.RequestEvent{Type: "file"})
@@ -1011,15 +1011,15 @@ func TestTransfer(t *testing.T) {
r.Queue(
pointer.Event{
Position: f32.Pt(10, 10),
Type: pointer.Press,
Kind: pointer.Press,
},
pointer.Event{
Position: f32.Pt(10, 10),
Type: pointer.Move,
Kind: pointer.Move,
},
pointer.Event{
Position: f32.Pt(40, 10),
Type: pointer.Release,
Kind: pointer.Release,
},
)
ofr := &offer{data: "hello"}
@@ -1054,15 +1054,15 @@ func TestTransfer(t *testing.T) {
r.Queue(
pointer.Event{
Position: f32.Pt(10, 10),
Type: pointer.Press,
Kind: pointer.Press,
},
pointer.Event{
Position: f32.Pt(10, 10),
Type: pointer.Move,
Kind: pointer.Move,
},
pointer.Event{
Position: f32.Pt(40, 10),
Type: pointer.Move,
Kind: pointer.Move,
},
)
assertEventPointerTypeSequence(t, r.Events(&hover), pointer.Cancel, pointer.Enter)
@@ -1071,7 +1071,7 @@ func TestTransfer(t *testing.T) {
r.Queue(
pointer.Event{
Position: f32.Pt(40, 10),
Type: pointer.Release,
Kind: pointer.Release,
},
)
@@ -1102,15 +1102,15 @@ func TestTransfer(t *testing.T) {
r.Queue(
pointer.Event{
Position: f32.Pt(10, 10),
Type: pointer.Press,
Kind: pointer.Press,
},
pointer.Event{
Position: f32.Pt(10, 10),
Type: pointer.Move,
Kind: pointer.Move,
},
pointer.Event{
Position: f32.Pt(40, 10),
Type: pointer.Move,
Kind: pointer.Move,
},
)
assertEventPointerTypeSequence(t, r.Events(&hover), pointer.Cancel)
@@ -1119,7 +1119,7 @@ func TestTransfer(t *testing.T) {
r.Queue(
pointer.Event{
Position: f32.Pt(40, 10),
Type: pointer.Release,
Kind: pointer.Release,
},
)
@@ -1167,7 +1167,7 @@ func TestPassCursor(t *testing.T) {
r.Frame(&ops)
r.Queue(pointer.Event{
Position: f32.Pt(10, 10),
Type: pointer.Move,
Kind: pointer.Move,
})
if got := r.Cursor(); want != got {
t.Errorf("got cursor %v, want %v", got, want)
@@ -1192,18 +1192,18 @@ func addPointerHandler(ops *op.Ops, tag event.Tag, area image.Rectangle) {
defer clip.Rect(area).Push(ops).Pop()
pointer.InputOp{
Tag: tag,
Types: pointer.Press | pointer.Release | pointer.Move | pointer.Drag | pointer.Enter | pointer.Leave,
Kinds: pointer.Press | pointer.Release | pointer.Move | pointer.Drag | pointer.Enter | pointer.Leave,
}.Add(ops)
}
// pointerTypes converts a sequence of event.Event to their pointer.Types. It assumes
// that all input events are of underlying type pointer.Event, and thus will
// panic if some are not.
func pointerTypes(events []event.Event) []pointer.Type {
var types []pointer.Type
func pointerTypes(events []event.Event) []pointer.Kind {
var types []pointer.Kind
for _, e := range events {
if e, ok := e.(pointer.Event); ok {
types = append(types, e.Type)
types = append(types, e.Kind)
}
}
return types
@@ -1211,7 +1211,7 @@ func pointerTypes(events []event.Event) []pointer.Type {
// assertEventPointerTypeSequence checks that the provided events match the expected pointer event types
// in the provided order.
func assertEventPointerTypeSequence(t *testing.T, events []event.Event, expected ...pointer.Type) {
func assertEventPointerTypeSequence(t *testing.T, events []event.Event, expected ...pointer.Kind) {
t.Helper()
got := pointerTypes(events)
if !reflect.DeepEqual(got, expected) {
@@ -1239,7 +1239,7 @@ func eventsToString(evs []event.Event) string {
for _, ev := range evs {
switch e := ev.(type) {
case pointer.Event:
s = append(s, fmt.Sprintf("%T{%s}", e, e.Type.String()))
s = append(s, fmt.Sprintf("%T{%s}", e, e.Kind.String()))
default:
s = append(s, fmt.Sprintf("{%T}", e))
}
@@ -1308,7 +1308,7 @@ func BenchmarkRouterAdd(b *testing.B) {
Push(&ops)
pointer.InputOp{
Tag: handlers[i],
Types: pointer.Move,
Kinds: pointer.Move,
}.Add(&ops)
}
var r Router
@@ -1318,7 +1318,7 @@ func BenchmarkRouterAdd(b *testing.B) {
for i := 0; i < b.N; i++ {
r.Queue(
pointer.Event{
Type: pointer.Move,
Kind: pointer.Move,
Position: f32.Pt(50, 50),
},
)