mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
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:
+11
-11
@@ -18,7 +18,7 @@ import (
|
||||
|
||||
// Event is a pointer event.
|
||||
type Event struct {
|
||||
Type Type
|
||||
Kind Kind
|
||||
Source Source
|
||||
// PointerID is the id for the pointer and can be used
|
||||
// to track a particular pointer from Press to
|
||||
@@ -61,8 +61,8 @@ type InputOp struct {
|
||||
// Grab, if set, request that the handler get
|
||||
// Grabbed priority.
|
||||
Grab bool
|
||||
// Types is a bitwise-or of event types to receive.
|
||||
Types Type
|
||||
// Kinds is a bitwise-or of event types to receive.
|
||||
Kinds Kind
|
||||
// ScrollBounds describe the maximum scrollable distances in both
|
||||
// axes. Specifically, any Event e delivered to Tag will satisfy
|
||||
//
|
||||
@@ -73,8 +73,8 @@ type InputOp struct {
|
||||
|
||||
type ID uint16
|
||||
|
||||
// Type of an Event.
|
||||
type Type uint
|
||||
// Kind of an Event.
|
||||
type Kind uint
|
||||
|
||||
// Priority of an Event.
|
||||
type Priority uint8
|
||||
@@ -169,7 +169,7 @@ const (
|
||||
const (
|
||||
// A Cancel event is generated when the current gesture is
|
||||
// interrupted by other handlers or the system.
|
||||
Cancel Type = (1 << iota) >> 1
|
||||
Cancel Kind = (1 << iota) >> 1
|
||||
// Press of a pointer.
|
||||
Press
|
||||
// Release of a pointer.
|
||||
@@ -243,7 +243,7 @@ func (op InputOp) Add(o *op.Ops) {
|
||||
if b := op.ScrollBounds; b.Min.X > 0 || b.Max.X < 0 || b.Min.Y > 0 || b.Max.Y < 0 {
|
||||
panic(fmt.Errorf("invalid scroll range value %v", b))
|
||||
}
|
||||
if op.Types>>16 > 0 {
|
||||
if op.Kinds>>16 > 0 {
|
||||
panic(fmt.Errorf("value in Types overflows uint16"))
|
||||
}
|
||||
data := ops.Write1(&o.Internal, ops.TypePointerInputLen, op.Tag)
|
||||
@@ -252,19 +252,19 @@ func (op InputOp) Add(o *op.Ops) {
|
||||
data[1] = 1
|
||||
}
|
||||
bo := binary.LittleEndian
|
||||
bo.PutUint16(data[2:], uint16(op.Types))
|
||||
bo.PutUint16(data[2:], uint16(op.Kinds))
|
||||
bo.PutUint32(data[4:], uint32(op.ScrollBounds.Min.X))
|
||||
bo.PutUint32(data[8:], uint32(op.ScrollBounds.Min.Y))
|
||||
bo.PutUint32(data[12:], uint32(op.ScrollBounds.Max.X))
|
||||
bo.PutUint32(data[16:], uint32(op.ScrollBounds.Max.Y))
|
||||
}
|
||||
|
||||
func (t Type) String() string {
|
||||
func (t Kind) String() string {
|
||||
if t == Cancel {
|
||||
return "Cancel"
|
||||
}
|
||||
var buf strings.Builder
|
||||
for tt := Type(1); tt > 0; tt <<= 1 {
|
||||
for tt := Kind(1); tt > 0; tt <<= 1 {
|
||||
if t&tt > 0 {
|
||||
if buf.Len() > 0 {
|
||||
buf.WriteByte('|')
|
||||
@@ -275,7 +275,7 @@ func (t Type) String() string {
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
func (t Type) string() string {
|
||||
func (t Kind) string() string {
|
||||
switch t {
|
||||
case Press:
|
||||
return "Press"
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
func TestTypeString(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
typ Type
|
||||
typ Kind
|
||||
res string
|
||||
}{
|
||||
{Cancel, "Cancel"},
|
||||
|
||||
@@ -279,7 +279,7 @@ func TestFocusScroll(t *testing.T) {
|
||||
key.InputOp{Tag: h}.Add(ops)
|
||||
pointer.InputOp{
|
||||
Tag: h,
|
||||
Types: pointer.Scroll,
|
||||
Kinds: pointer.Scroll,
|
||||
ScrollBounds: image.Rect(-100, -100, 100, 100),
|
||||
}.Add(ops)
|
||||
// Test that h is scrolled even if behind another handler.
|
||||
@@ -305,7 +305,7 @@ func TestFocusClick(t *testing.T) {
|
||||
key.InputOp{Tag: h}.Add(ops)
|
||||
pointer.InputOp{
|
||||
Tag: h,
|
||||
Types: pointer.Press | pointer.Release,
|
||||
Kinds: pointer.Press | pointer.Release,
|
||||
}.Add(ops)
|
||||
cl.Pop()
|
||||
r.Frame(ops)
|
||||
|
||||
+19
-19
@@ -66,7 +66,7 @@ type pointerHandler struct {
|
||||
area int
|
||||
active bool
|
||||
wantsGrab bool
|
||||
types pointer.Type
|
||||
types pointer.Kind
|
||||
// min and max horizontal/vertical scroll
|
||||
scrollRange image.Rectangle
|
||||
|
||||
@@ -242,7 +242,7 @@ func (c *pointerCollector) newHandler(tag event.Tag, events *handlerEvents) *poi
|
||||
c.q.handlers[tag] = h
|
||||
// Cancel handlers on (each) first appearance, but don't
|
||||
// trigger redraw.
|
||||
events.AddNoRedraw(tag, pointer.Event{Type: pointer.Cancel})
|
||||
events.AddNoRedraw(tag, pointer.Event{Kind: pointer.Cancel})
|
||||
}
|
||||
h.active = true
|
||||
h.area = areaID
|
||||
@@ -268,16 +268,16 @@ func (c *pointerCollector) inputOp(op pointer.InputOp, events *handlerEvents) {
|
||||
areaID := c.currentArea()
|
||||
area := &c.q.areas[areaID]
|
||||
area.semantic.content.tag = op.Tag
|
||||
if op.Types&(pointer.Press|pointer.Release) != 0 {
|
||||
if op.Kinds&(pointer.Press|pointer.Release) != 0 {
|
||||
area.semantic.content.gestures |= ClickGesture
|
||||
}
|
||||
if op.Types&pointer.Scroll != 0 {
|
||||
if op.Kinds&pointer.Scroll != 0 {
|
||||
area.semantic.content.gestures |= ScrollGesture
|
||||
}
|
||||
area.semantic.valid = area.semantic.content.gestures != 0
|
||||
h := c.newHandler(op.Tag, events)
|
||||
h.wantsGrab = h.wantsGrab || op.Grab
|
||||
h.types = h.types | op.Types
|
||||
h.types = h.types | op.Kinds
|
||||
h.scrollRange = op.ScrollBounds
|
||||
}
|
||||
|
||||
@@ -602,7 +602,7 @@ func (q *pointerQueue) Frame(events *handlerEvents) {
|
||||
|
||||
func (q *pointerQueue) dropHandler(events *handlerEvents, tag event.Tag) {
|
||||
if events != nil {
|
||||
events.Add(tag, pointer.Event{Type: pointer.Cancel})
|
||||
events.Add(tag, pointer.Event{Kind: pointer.Cancel})
|
||||
}
|
||||
for i := range q.pointers {
|
||||
p := &q.pointers[i]
|
||||
@@ -649,11 +649,11 @@ func (q *pointerQueue) Deliver(areaIdx int, e pointer.Event, events *handlerEven
|
||||
continue
|
||||
}
|
||||
h := q.handlers[n.tag]
|
||||
if e.Type&h.types == 0 {
|
||||
if e.Kind&h.types == 0 {
|
||||
continue
|
||||
}
|
||||
e := e
|
||||
if e.Type == pointer.Scroll {
|
||||
if e.Kind == pointer.Scroll {
|
||||
if sx == 0 && sy == 0 {
|
||||
break
|
||||
}
|
||||
@@ -663,7 +663,7 @@ func (q *pointerQueue) Deliver(areaIdx int, e pointer.Event, events *handlerEven
|
||||
}
|
||||
e.Position = q.invTransform(h.area, e.Position)
|
||||
events.Add(n.tag, e)
|
||||
if e.Type != pointer.Scroll {
|
||||
if e.Kind != pointer.Scroll {
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -683,7 +683,7 @@ func (q *pointerQueue) SemanticArea(areaIdx int) (semanticContent, int) {
|
||||
}
|
||||
|
||||
func (q *pointerQueue) Push(e pointer.Event, events *handlerEvents) {
|
||||
if e.Type == pointer.Cancel {
|
||||
if e.Kind == pointer.Cancel {
|
||||
q.pointers = q.pointers[:0]
|
||||
for k := range q.handlers {
|
||||
q.dropHandler(events, k)
|
||||
@@ -694,14 +694,14 @@ func (q *pointerQueue) Push(e pointer.Event, events *handlerEvents) {
|
||||
p := &q.pointers[pidx]
|
||||
p.last = e
|
||||
|
||||
switch e.Type {
|
||||
switch e.Kind {
|
||||
case pointer.Press:
|
||||
q.deliverEnterLeaveEvents(p, events, e)
|
||||
p.pressed = true
|
||||
q.deliverEvent(p, events, e)
|
||||
case pointer.Move:
|
||||
if p.pressed {
|
||||
e.Type = pointer.Drag
|
||||
e.Kind = pointer.Drag
|
||||
}
|
||||
q.deliverEnterLeaveEvents(p, events, e)
|
||||
q.deliverEvent(p, events, e)
|
||||
@@ -735,7 +735,7 @@ func (q *pointerQueue) deliverEvent(p *pointerInfo, events *handlerEvents, e poi
|
||||
var sx, sy = e.Scroll.X, e.Scroll.Y
|
||||
for _, k := range p.handlers {
|
||||
h := q.handlers[k]
|
||||
if e.Type == pointer.Scroll {
|
||||
if e.Kind == pointer.Scroll {
|
||||
if sx == 0 && sy == 0 {
|
||||
return
|
||||
}
|
||||
@@ -743,7 +743,7 @@ func (q *pointerQueue) deliverEvent(p *pointerInfo, events *handlerEvents, e poi
|
||||
sx, e.Scroll.X = setScrollEvent(sx, h.scrollRange.Min.X, h.scrollRange.Max.X)
|
||||
sy, e.Scroll.Y = setScrollEvent(sy, h.scrollRange.Min.Y, h.scrollRange.Max.Y)
|
||||
}
|
||||
if e.Type&h.types == 0 {
|
||||
if e.Kind&h.types == 0 {
|
||||
continue
|
||||
}
|
||||
e := e
|
||||
@@ -758,7 +758,7 @@ func (q *pointerQueue) deliverEvent(p *pointerInfo, events *handlerEvents, e poi
|
||||
|
||||
func (q *pointerQueue) deliverEnterLeaveEvents(p *pointerInfo, events *handlerEvents, e pointer.Event) {
|
||||
var hits []event.Tag
|
||||
if e.Source != pointer.Mouse && !p.pressed && e.Type != pointer.Press {
|
||||
if e.Source != pointer.Mouse && !p.pressed && e.Kind != pointer.Press {
|
||||
// Consider non-mouse pointers leaving when they're released.
|
||||
} else {
|
||||
hits, q.cursor = q.opHit(e.Position)
|
||||
@@ -790,9 +790,9 @@ func (q *pointerQueue) deliverEnterLeaveEvents(p *pointerInfo, events *handlerEv
|
||||
continue
|
||||
}
|
||||
h := q.handlers[k]
|
||||
e.Type = pointer.Leave
|
||||
e.Kind = pointer.Leave
|
||||
|
||||
if e.Type&h.types != 0 {
|
||||
if e.Kind&h.types != 0 {
|
||||
e := e
|
||||
e.Position = q.invTransform(h.area, e.Position)
|
||||
events.Add(k, e)
|
||||
@@ -804,9 +804,9 @@ func (q *pointerQueue) deliverEnterLeaveEvents(p *pointerInfo, events *handlerEv
|
||||
if _, found := searchTag(p.entered, k); found {
|
||||
continue
|
||||
}
|
||||
e.Type = pointer.Enter
|
||||
e.Kind = pointer.Enter
|
||||
|
||||
if e.Type&h.types != 0 {
|
||||
if e.Kind&h.types != 0 {
|
||||
e := e
|
||||
e.Position = q.invTransform(h.area, e.Position)
|
||||
events.Add(k, e)
|
||||
|
||||
+100
-100
@@ -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),
|
||||
},
|
||||
)
|
||||
|
||||
+4
-4
@@ -273,7 +273,7 @@ func (q *Router) ScrollFocus(dist image.Point) {
|
||||
}
|
||||
area := q.key.queue.AreaFor(focus)
|
||||
q.pointer.queue.Deliver(area, pointer.Event{
|
||||
Type: pointer.Scroll,
|
||||
Kind: pointer.Scroll,
|
||||
Source: pointer.Touch,
|
||||
Scroll: f32internal.FPt(dist),
|
||||
}, &q.handlers)
|
||||
@@ -317,9 +317,9 @@ func (q *Router) ClickFocus() {
|
||||
Source: pointer.Touch,
|
||||
}
|
||||
area := q.key.queue.AreaFor(focus)
|
||||
e.Type = pointer.Press
|
||||
e.Kind = pointer.Press
|
||||
q.pointer.queue.Deliver(area, e, &q.handlers)
|
||||
e.Type = pointer.Release
|
||||
e.Kind = pointer.Release
|
||||
q.pointer.queue.Deliver(area, e, &q.handlers)
|
||||
}
|
||||
|
||||
@@ -438,7 +438,7 @@ func (q *Router) collect() {
|
||||
op := pointer.InputOp{
|
||||
Tag: encOp.Refs[0].(event.Tag),
|
||||
Grab: encOp.Data[1] != 0,
|
||||
Types: pointer.Type(bo.Uint16(encOp.Data[2:])),
|
||||
Kinds: pointer.Kind(bo.Uint16(encOp.Data[2:])),
|
||||
ScrollBounds: image.Rectangle{
|
||||
Min: image.Point{
|
||||
X: int(int32(bo.Uint32(encOp.Data[4:]))),
|
||||
|
||||
@@ -74,7 +74,7 @@ func TestSemanticTree(t *testing.T) {
|
||||
|
||||
func TestSemanticDescription(t *testing.T) {
|
||||
var ops op.Ops
|
||||
pointer.InputOp{Tag: new(int), Types: pointer.Press | pointer.Release}.Add(&ops)
|
||||
pointer.InputOp{Tag: new(int), Kinds: pointer.Press | pointer.Release}.Add(&ops)
|
||||
semantic.DescriptionOp("description").Add(&ops)
|
||||
semantic.LabelOp("label").Add(&ops)
|
||||
semantic.Button.Add(&ops)
|
||||
|
||||
Reference in New Issue
Block a user