From 45657d715ba468688c695664dfbfed051c0122f0 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Fri, 6 Oct 2023 18:19:13 -0500 Subject: [PATCH] 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 --- app/os_android.go | 14 +-- app/os_ios.go | 12 +-- app/os_js.go | 10 +- app/os_macos.go | 4 +- app/os_wayland.go | 16 +-- app/os_windows.go | 14 +-- app/os_x11.go | 14 +-- gesture/gesture.go | 16 +-- gesture/gesture_test.go | 8 +- io/pointer/pointer.go | 22 ++-- io/pointer/pointer_test.go | 2 +- io/router/key_test.go | 4 +- io/router/pointer.go | 38 +++---- io/router/pointer_test.go | 200 ++++++++++++++++++------------------- io/router/router.go | 8 +- io/router/semantic_test.go | 2 +- layout/list_test.go | 18 ++-- widget/dnd.go | 2 +- widget/dnd_test.go | 6 +- widget/editor.go | 4 +- widget/editor_test.go | 10 +- widget/example_test.go | 10 +- widget/float.go | 2 +- widget/list.go | 2 +- widget/selectable.go | 4 +- widget/widget_test.go | 4 +- 26 files changed, 223 insertions(+), 223 deletions(-) diff --git a/app/os_android.go b/app/os_android.go index 23e1f6ba0..d10681934 100644 --- a/app/os_android.go +++ b/app/os_android.go @@ -953,18 +953,18 @@ func Java_org_gioui_GioView_onKeyEvent(env *C.JNIEnv, class C.jclass, handle C.j //export Java_org_gioui_GioView_onTouchEvent func Java_org_gioui_GioView_onTouchEvent(env *C.JNIEnv, class C.jclass, handle C.jlong, action, pointerID, tool C.jint, x, y, scrollX, scrollY C.jfloat, jbtns C.jint, t C.jlong) { w := cgo.Handle(handle).Value().(*window) - var typ pointer.Type + var kind pointer.Kind switch action { case C.AMOTION_EVENT_ACTION_DOWN, C.AMOTION_EVENT_ACTION_POINTER_DOWN: - typ = pointer.Press + kind = pointer.Press case C.AMOTION_EVENT_ACTION_UP, C.AMOTION_EVENT_ACTION_POINTER_UP: - typ = pointer.Release + kind = pointer.Release case C.AMOTION_EVENT_ACTION_CANCEL: - typ = pointer.Cancel + kind = pointer.Cancel case C.AMOTION_EVENT_ACTION_MOVE: - typ = pointer.Move + kind = pointer.Move case C.AMOTION_EVENT_ACTION_SCROLL: - typ = pointer.Scroll + kind = pointer.Scroll default: return } @@ -994,7 +994,7 @@ func Java_org_gioui_GioView_onTouchEvent(env *C.JNIEnv, class C.jclass, handle C return } w.callbacks.Event(pointer.Event{ - Type: typ, + Kind: kind, Source: src, Buttons: btns, PointerID: pointer.ID(pointerID), diff --git a/app/os_ios.go b/app/os_ios.go index 5cbabfe8f..85cbe7019 100644 --- a/app/os_ios.go +++ b/app/os_ios.go @@ -236,16 +236,16 @@ func onText(view, str C.CFTypeRef) { //export onTouch func onTouch(last C.int, view, touchRef C.CFTypeRef, phase C.NSInteger, x, y C.CGFloat, ti C.double) { - var typ pointer.Type + var kind pointer.Kind switch phase { case C.UITouchPhaseBegan: - typ = pointer.Press + kind = pointer.Press case C.UITouchPhaseMoved: - typ = pointer.Move + kind = pointer.Move case C.UITouchPhaseEnded: - typ = pointer.Release + kind = pointer.Release case C.UITouchPhaseCancelled: - typ = pointer.Cancel + kind = pointer.Cancel default: return } @@ -253,7 +253,7 @@ func onTouch(last C.int, view, touchRef C.CFTypeRef, phase C.NSInteger, x, y C.C t := time.Duration(float64(ti) * float64(time.Second)) p := f32.Point{X: float32(x), Y: float32(y)} w.w.Event(pointer.Event{ - Type: typ, + Kind: typ, Source: pointer.Touch, PointerID: w.lookupTouch(last != 0, touchRef), Position: p, diff --git a/app/os_js.go b/app/os_js.go index f7fece4cc..2752e8142 100644 --- a/app/os_js.go +++ b/app/os_js.go @@ -275,7 +275,7 @@ func (w *window) addEventListeners() { } w.touches = w.touches[:0] w.w.Event(pointer.Event{ - Type: pointer.Cancel, + Kind: pointer.Cancel, Source: pointer.Touch, }) return nil @@ -398,7 +398,7 @@ func modifiersFor(e js.Value) key.Modifiers { return mods } -func (w *window) touchEvent(typ pointer.Type, e js.Value) { +func (w *window) touchEvent(kind pointer.Kind, e js.Value) { e.Call("preventDefault") t := time.Duration(e.Get("timeStamp").Int()) * time.Millisecond changedTouches := e.Get("changedTouches") @@ -426,7 +426,7 @@ func (w *window) touchEvent(typ pointer.Type, e js.Value) { Y: float32(y) * scale, } w.w.Event(pointer.Event{ - Type: typ, + Kind: kind, Source: pointer.Touch, Position: pos, PointerID: pid, @@ -448,7 +448,7 @@ func (w *window) touchIDFor(touch js.Value) pointer.ID { return pid } -func (w *window) pointerEvent(typ pointer.Type, dx, dy float32, e js.Value) { +func (w *window) pointerEvent(kind pointer.Kind, dx, dy float32, e js.Value) { e.Call("preventDefault") x, y := e.Get("clientX").Float(), e.Get("clientY").Float() rect := w.cnv.Call("getBoundingClientRect") @@ -476,7 +476,7 @@ func (w *window) pointerEvent(typ pointer.Type, dx, dy float32, e js.Value) { btns |= pointer.ButtonTertiary } w.w.Event(pointer.Event{ - Type: typ, + Kind: kind, Source: pointer.Mouse, Buttons: btns, Position: pos, diff --git a/app/os_macos.go b/app/os_macos.go index 1b4ac557a..93b7a4e8d 100644 --- a/app/os_macos.go +++ b/app/os_macos.go @@ -526,7 +526,7 @@ func gio_onMouse(view, evt C.CFTypeRef, cdir C.int, cbtn C.NSInteger, x, y, dx, case 2: btn = pointer.ButtonTertiary } - var typ pointer.Type + var typ pointer.Kind switch cdir { case C.MOUSE_MOVE: typ = pointer.Move @@ -550,7 +550,7 @@ func gio_onMouse(view, evt C.CFTypeRef, cdir C.int, cbtn C.NSInteger, x, y, dx, panic("invalid direction") } w.w.Event(pointer.Event{ - Type: typ, + Kind: typ, Source: pointer.Mouse, Time: t, Buttons: w.pointerBtns, diff --git a/app/os_wayland.go b/app/os_wayland.go index 159861a6e..b53004b13 100644 --- a/app/os_wayland.go +++ b/app/os_wayland.go @@ -794,7 +794,7 @@ func gio_onTouchDown(data unsafe.Pointer, touch *C.struct_wl_touch, serial, t C. Y: fromFixed(y) * float32(w.scale), } w.w.Event(pointer.Event{ - Type: pointer.Press, + Kind: pointer.Press, Source: pointer.Touch, Position: w.lastTouch, PointerID: pointer.ID(id), @@ -810,7 +810,7 @@ func gio_onTouchUp(data unsafe.Pointer, touch *C.struct_wl_touch, serial, t C.ui w := s.touchFoci[id] delete(s.touchFoci, id) w.w.Event(pointer.Event{ - Type: pointer.Release, + Kind: pointer.Release, Source: pointer.Touch, Position: w.lastTouch, PointerID: pointer.ID(id), @@ -828,7 +828,7 @@ func gio_onTouchMotion(data unsafe.Pointer, touch *C.struct_wl_touch, t C.uint32 Y: fromFixed(y) * float32(w.scale), } w.w.Event(pointer.Event{ - Type: pointer.Move, + Kind: pointer.Move, Position: w.lastTouch, Source: pointer.Touch, PointerID: pointer.ID(id), @@ -847,7 +847,7 @@ func gio_onTouchCancel(data unsafe.Pointer, touch *C.struct_wl_touch) { for id, w := range s.touchFoci { delete(s.touchFoci, id) w.w.Event(pointer.Event{ - Type: pointer.Cancel, + Kind: pointer.Cancel, Source: pointer.Touch, }) } @@ -872,7 +872,7 @@ func gio_onPointerLeave(data unsafe.Pointer, p *C.struct_wl_pointer, serial C.ui s.serial = serial if w.inCompositor { w.inCompositor = false - w.w.Event(pointer.Event{Type: pointer.Cancel}) + w.w.Event(pointer.Event{Kind: pointer.Cancel}) } } @@ -934,7 +934,7 @@ func gio_onPointerButton(data unsafe.Pointer, p *C.struct_wl_pointer, serial, t, w.flushScroll() w.resetFling() w.w.Event(pointer.Event{ - Type: typ, + Kind: typ, Source: pointer.Mouse, Buttons: w.pointerBtns, Position: w.lastPos, @@ -1581,7 +1581,7 @@ func (w *window) flushScroll() { return } w.w.Event(pointer.Event{ - Type: pointer.Scroll, + Kind: pointer.Scroll, Source: pointer.Mouse, Buttons: w.pointerBtns, Position: w.lastPos, @@ -1604,7 +1604,7 @@ func (w *window) onPointerMotion(x, y C.wl_fixed_t, t C.uint32_t) { Y: fromFixed(y) * float32(w.scale), } w.w.Event(pointer.Event{ - Type: pointer.Move, + Kind: pointer.Move, Position: w.lastPos, Buttons: w.pointerBtns, Source: pointer.Mouse, diff --git a/app/os_windows.go b/app/os_windows.go index 4aa806f11..b6a08d3ca 100644 --- a/app/os_windows.go +++ b/app/os_windows.go @@ -259,7 +259,7 @@ func windowProc(hwnd syscall.Handle, msg uint32, wParam, lParam uintptr) uintptr w.pointerButton(pointer.ButtonTertiary, false, lParam, getModifiers()) case windows.WM_CANCELMODE: w.w.Event(pointer.Event{ - Type: pointer.Cancel, + Kind: pointer.Cancel, }) case windows.WM_SETFOCUS: w.focused = true @@ -288,7 +288,7 @@ func windowProc(hwnd syscall.Handle, msg uint32, wParam, lParam uintptr) uintptr x, y := coordsFromlParam(lParam) p := f32.Point{X: float32(x), Y: float32(y)} w.w.Event(pointer.Event{ - Type: pointer.Move, + Kind: pointer.Move, Source: pointer.Mouse, Position: p, Buttons: w.pointerBtns, @@ -501,15 +501,15 @@ func (w *window) pointerButton(btn pointer.Buttons, press bool, lParam uintptr, windows.SetFocus(w.hwnd) } - var typ pointer.Type + var kind pointer.Kind if press { - typ = pointer.Press + kind = pointer.Press if w.pointerBtns == 0 { windows.SetCapture(w.hwnd) } w.pointerBtns |= btn } else { - typ = pointer.Release + kind = pointer.Release w.pointerBtns &^= btn if w.pointerBtns == 0 { windows.ReleaseCapture() @@ -518,7 +518,7 @@ func (w *window) pointerButton(btn pointer.Buttons, press bool, lParam uintptr, x, y := coordsFromlParam(lParam) p := f32.Point{X: float32(x), Y: float32(y)} w.w.Event(pointer.Event{ - Type: typ, + Kind: kind, Source: pointer.Mouse, Position: p, Buttons: w.pointerBtns, @@ -553,7 +553,7 @@ func (w *window) scrollEvent(wParam, lParam uintptr, horizontal bool, kmods key. } } w.w.Event(pointer.Event{ - Type: pointer.Scroll, + Kind: pointer.Scroll, Source: pointer.Mouse, Position: p, Buttons: w.pointerBtns, diff --git a/app/os_x11.go b/app/os_x11.go index 144386115..a80c9c600 100644 --- a/app/os_x11.go +++ b/app/os_x11.go @@ -547,7 +547,7 @@ func (h *x11EventHandler) handleEvents() bool { case C.ButtonPress, C.ButtonRelease: bevt := (*C.XButtonEvent)(unsafe.Pointer(xev)) ev := pointer.Event{ - Type: pointer.Press, + Kind: pointer.Press, Source: pointer.Mouse, Position: f32.Point{ X: float32(bevt.x), @@ -557,7 +557,7 @@ func (h *x11EventHandler) handleEvents() bool { Modifiers: w.xkb.Modifiers(), } if bevt._type == C.ButtonRelease { - ev.Type = pointer.Release + ev.Kind = pointer.Release } var btn pointer.Buttons const scrollScale = 10 @@ -569,7 +569,7 @@ func (h *x11EventHandler) handleEvents() bool { case C.Button3: btn = pointer.ButtonSecondary case C.Button4: - ev.Type = pointer.Scroll + ev.Kind = pointer.Scroll // scroll up or left (if shift is pressed). if ev.Modifiers == key.ModShift { ev.Scroll.X = -scrollScale @@ -578,7 +578,7 @@ func (h *x11EventHandler) handleEvents() bool { } case C.Button5: // scroll down or right (if shift is pressed). - ev.Type = pointer.Scroll + ev.Kind = pointer.Scroll if ev.Modifiers == key.ModShift { ev.Scroll.X = +scrollScale } else { @@ -587,11 +587,11 @@ func (h *x11EventHandler) handleEvents() bool { case 6: // http://xahlee.info/linux/linux_x11_mouse_button_number.html // scroll left. - ev.Type = pointer.Scroll + ev.Kind = pointer.Scroll ev.Scroll.X = -scrollScale * 2 case 7: // scroll right - ev.Type = pointer.Scroll + ev.Kind = pointer.Scroll ev.Scroll.X = +scrollScale * 2 default: continue @@ -607,7 +607,7 @@ func (h *x11EventHandler) handleEvents() bool { case C.MotionNotify: mevt := (*C.XMotionEvent)(unsafe.Pointer(xev)) w.w.Event(pointer.Event{ - Type: pointer.Move, + Kind: pointer.Move, Source: pointer.Mouse, Buttons: w.pointerBtns, Position: f32.Point{ diff --git a/gesture/gesture.go b/gesture/gesture.go index f29386054..347db5567 100644 --- a/gesture/gesture.go +++ b/gesture/gesture.go @@ -39,7 +39,7 @@ type Hover struct { func (h *Hover) Add(ops *op.Ops) { pointer.InputOp{ Tag: h, - Types: pointer.Enter | pointer.Leave, + Kinds: pointer.Enter | pointer.Leave, }.Add(ops) } @@ -50,7 +50,7 @@ func (h *Hover) Hovered(q event.Queue) bool { if !ok { continue } - switch e.Type { + switch e.Kind { case pointer.Leave, pointer.Cancel: if h.entered && h.pid == e.PointerID { h.entered = false @@ -163,7 +163,7 @@ const touchSlop = unit.Dp(3) func (c *Click) Add(ops *op.Ops) { pointer.InputOp{ Tag: c, - Types: pointer.Press | pointer.Release | pointer.Enter | pointer.Leave, + Kinds: pointer.Press | pointer.Release | pointer.Enter | pointer.Leave, }.Add(ops) } @@ -185,7 +185,7 @@ func (c *Click) Events(q event.Queue) []ClickEvent { if !ok { continue } - switch e.Type { + switch e.Kind { case pointer.Release: if !c.pressed || c.pid != e.PointerID { break @@ -254,7 +254,7 @@ func (s *Scroll) Add(ops *op.Ops, bounds image.Rectangle) { oph := pointer.InputOp{ Tag: s, Grab: s.grab, - Types: pointer.Press | pointer.Drag | pointer.Release | pointer.Scroll, + Kinds: pointer.Press | pointer.Drag | pointer.Release | pointer.Scroll, ScrollBounds: bounds, } oph.Add(ops) @@ -281,7 +281,7 @@ func (s *Scroll) Scroll(cfg unit.Metric, q event.Queue, t time.Time, axis Axis) if !ok { continue } - switch e.Type { + switch e.Kind { case pointer.Press: if s.dragging { break @@ -368,7 +368,7 @@ func (d *Drag) Add(ops *op.Ops) { pointer.InputOp{ Tag: d, Grab: d.grab, - Types: pointer.Press | pointer.Drag | pointer.Release, + Kinds: pointer.Press | pointer.Drag | pointer.Release, }.Add(ops) } @@ -381,7 +381,7 @@ func (d *Drag) Events(cfg unit.Metric, q event.Queue, axis Axis) []pointer.Event continue } - switch e.Type { + switch e.Kind { case pointer.Press: if !(e.Buttons == pointer.ButtonPrimary || e.Source == pointer.Touch) { continue diff --git a/gesture/gesture_test.go b/gesture/gesture_test.go index 5574b6df2..8dc3f7aec 100644 --- a/gesture/gesture_test.go +++ b/gesture/gesture_test.go @@ -26,14 +26,14 @@ func TestHover(t *testing.T) { r.Frame(ops) r.Queue( - pointer.Event{Type: pointer.Move, Position: f32.Pt(30, 30)}, + pointer.Event{Kind: pointer.Move, Position: f32.Pt(30, 30)}, ) if !h.Hovered(r) { t.Fatal("expected hovered") } r.Queue( - pointer.Event{Type: pointer.Move, Position: f32.Pt(50, 50)}, + pointer.Event{Kind: pointer.Move, Position: f32.Pt(50, 50)}, ) if h.Hovered(r) { t.Fatal("expected not hovered") @@ -92,7 +92,7 @@ func TestMouseClicks(t *testing.T) { func mouseClickEvents(times ...time.Duration) []event.Event { press := pointer.Event{ - Type: pointer.Press, + Kind: pointer.Press, Source: pointer.Mouse, Buttons: pointer.ButtonPrimary, } @@ -101,7 +101,7 @@ func mouseClickEvents(times ...time.Duration) []event.Event { press := press press.Time = t release := press - release.Type = pointer.Release + release.Kind = pointer.Release events = append(events, press, release) } return events diff --git a/io/pointer/pointer.go b/io/pointer/pointer.go index a4d4fefc3..60619389e 100644 --- a/io/pointer/pointer.go +++ b/io/pointer/pointer.go @@ -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" diff --git a/io/pointer/pointer_test.go b/io/pointer/pointer_test.go index e0ee1d2fa..f0a4380b1 100644 --- a/io/pointer/pointer_test.go +++ b/io/pointer/pointer_test.go @@ -8,7 +8,7 @@ import ( func TestTypeString(t *testing.T) { for _, tc := range []struct { - typ Type + typ Kind res string }{ {Cancel, "Cancel"}, diff --git a/io/router/key_test.go b/io/router/key_test.go index 2e39a3dbb..dd15c29b1 100644 --- a/io/router/key_test.go +++ b/io/router/key_test.go @@ -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) diff --git a/io/router/pointer.go b/io/router/pointer.go index 7d2034bbb..2cc17ce33 100644 --- a/io/router/pointer.go +++ b/io/router/pointer.go @@ -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) diff --git a/io/router/pointer_test.go b/io/router/pointer_test.go index a8b0476c4..2c632152a 100644 --- a/io/router/pointer_test.go +++ b/io/router/pointer_test.go @@ -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), }, ) diff --git a/io/router/router.go b/io/router/router.go index 181e0ae99..6817c2c81 100644 --- a/io/router/router.go +++ b/io/router/router.go @@ -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:]))), diff --git a/io/router/semantic_test.go b/io/router/semantic_test.go index bb6abd8f4..46982fc08 100644 --- a/io/router/semantic_test.go +++ b/io/router/semantic_test.go @@ -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) diff --git a/layout/list_test.go b/layout/list_test.go index 0f3814bcc..b48f396fe 100644 --- a/layout/list_test.go +++ b/layout/list_test.go @@ -93,18 +93,18 @@ func TestListPosition(t *testing.T) { pointer.Event{ Source: pointer.Mouse, Buttons: pointer.ButtonPrimary, - Type: pointer.Press, + Kind: pointer.Press, Position: f32.Pt(0, 0), }, pointer.Event{ Source: pointer.Mouse, - Type: pointer.Scroll, + Kind: pointer.Scroll, Scroll: f32.Pt(5, 0), }, pointer.Event{ Source: pointer.Mouse, Buttons: pointer.ButtonPrimary, - Type: pointer.Release, + Kind: pointer.Release, Position: f32.Pt(5, 0), }, )}, @@ -113,18 +113,18 @@ func TestListPosition(t *testing.T) { pointer.Event{ Source: pointer.Mouse, Buttons: pointer.ButtonPrimary, - Type: pointer.Press, + Kind: pointer.Press, Position: f32.Pt(0, 0), }, pointer.Event{ Source: pointer.Mouse, - Type: pointer.Scroll, + Kind: pointer.Scroll, Scroll: f32.Pt(3, 0), }, pointer.Event{ Source: pointer.Mouse, Buttons: pointer.ButtonPrimary, - Type: pointer.Release, + Kind: pointer.Release, Position: f32.Pt(5, 0), }, )}, @@ -133,18 +133,18 @@ func TestListPosition(t *testing.T) { pointer.Event{ Source: pointer.Mouse, Buttons: pointer.ButtonPrimary, - Type: pointer.Press, + Kind: pointer.Press, Position: f32.Pt(0, 0), }, pointer.Event{ Source: pointer.Mouse, - Type: pointer.Scroll, + Kind: pointer.Scroll, Scroll: f32.Pt(10, 0), }, pointer.Event{ Source: pointer.Mouse, Buttons: pointer.ButtonPrimary, - Type: pointer.Release, + Kind: pointer.Release, Position: f32.Pt(15, 0), }, )}, diff --git a/widget/dnd.go b/widget/dnd.go index fbc47fd30..e336f659a 100644 --- a/widget/dnd.go +++ b/widget/dnd.go @@ -31,7 +31,7 @@ func (d *Draggable) Layout(gtx layout.Context, w, drag layout.Widget) layout.Dim } pos := d.pos for _, ev := range d.drag.Events(gtx.Metric, gtx.Queue, gesture.Both) { - switch ev.Type { + switch ev.Kind { case pointer.Press: d.click = ev.Position pos = f32.Point{} diff --git a/widget/dnd_test.go b/widget/dnd_test.go index fb3e80206..ea26de09e 100644 --- a/widget/dnd_test.go +++ b/widget/dnd_test.go @@ -39,15 +39,15 @@ func TestDraggable(t *testing.T) { r.Queue( pointer.Event{ Position: f32.Pt(10, 10), - Type: pointer.Press, + Kind: pointer.Press, }, pointer.Event{ Position: f32.Pt(20, 10), - Type: pointer.Move, + Kind: pointer.Move, }, pointer.Event{ Position: f32.Pt(20, 10), - Type: pointer.Release, + Kind: pointer.Release, }, ) ofr := &offer{data: "hello"} diff --git a/widget/editor.go b/widget/editor.go index 196010828..521a21de4 100644 --- a/widget/editor.go +++ b/widget/editor.go @@ -278,10 +278,10 @@ func (e *Editor) processPointer(gtx layout.Context) { case pointer.Event: release := false switch { - case evt.Type == pointer.Release && evt.Source == pointer.Mouse: + case evt.Kind == pointer.Release && evt.Source == pointer.Mouse: release = true fallthrough - case evt.Type == pointer.Drag && evt.Source == pointer.Mouse: + case evt.Kind == pointer.Drag && evt.Source == pointer.Mouse: if e.dragging { e.blinkStart = gtx.Now e.text.MoveCoord(image.Point{ diff --git a/widget/editor_test.go b/widget/editor_test.go index e09043a2f..e19828c8f 100644 --- a/widget/editor_test.go +++ b/widget/editor_test.go @@ -159,17 +159,17 @@ func TestEditorReadOnly(t *testing.T) { gtx.Ops.Reset() gtx.Queue = &testQueue{events: []event.Event{ pointer.Event{ - Type: pointer.Press, + Kind: pointer.Press, Buttons: pointer.ButtonPrimary, Position: f32.Pt(float32(dims.Size.X)*.5, 5), }, pointer.Event{ - Type: pointer.Drag, + Kind: pointer.Drag, Buttons: pointer.ButtonPrimary, Position: layout.FPt(dims.Size).Mul(.5), }, pointer.Event{ - Type: pointer.Release, + Kind: pointer.Release, Buttons: pointer.ButtonPrimary, Position: layout.FPt(dims.Size).Mul(.5), }, @@ -947,13 +947,13 @@ g 2 4 6 8 g events: []event.Event{ pointer.Event{ Buttons: pointer.ButtonPrimary, - Type: pointer.Press, + Kind: pointer.Press, Source: pointer.Mouse, Time: tim, Position: f32.Pt(textWidth(e, startPos.lineCol.line, 0, startPos.lineCol.col), textBaseline(e, startPos.lineCol.line)), }, pointer.Event{ - Type: pointer.Release, + Kind: pointer.Release, Source: pointer.Mouse, Time: tim, Position: f32.Pt(textWidth(e, endPos.lineCol.line, 0, endPos.lineCol.col), textBaseline(e, endPos.lineCol.line)), diff --git a/widget/example_test.go b/widget/example_test.go index b789c331d..131936f73 100644 --- a/widget/example_test.go +++ b/widget/example_test.go @@ -47,13 +47,13 @@ func ExampleClickable_passthrough() { pointer.Event{ Source: pointer.Mouse, Buttons: pointer.ButtonPrimary, - Type: pointer.Press, + Kind: pointer.Press, Position: f32.Pt(50, 50), }, pointer.Event{ Source: pointer.Mouse, Buttons: pointer.ButtonPrimary, - Type: pointer.Release, + Kind: pointer.Release, Position: f32.Pt(50, 50), }, ) @@ -125,15 +125,15 @@ func ExampleDraggable_Layout() { // Send drag and drop gesture events. r.Queue( pointer.Event{ - Type: pointer.Press, + Kind: pointer.Press, Position: f32.Pt(5, 5), // in the drag area }, pointer.Event{ - Type: pointer.Move, + Kind: pointer.Move, Position: f32.Pt(5, 5), // in the drop area }, pointer.Event{ - Type: pointer.Release, + Kind: pointer.Release, Position: f32.Pt(30, 30), // in the drop area }, ) diff --git a/widget/float.go b/widget/float.go index f9bb9d34c..640063387 100644 --- a/widget/float.go +++ b/widget/float.go @@ -33,7 +33,7 @@ func (f *Float) Layout(gtx layout.Context, axis layout.Axis, min, max float32, i var de *pointer.Event for _, e := range f.drag.Events(gtx.Metric, gtx, gesture.Axis(axis)) { - if e.Type == pointer.Press || e.Type == pointer.Drag { + if e.Kind == pointer.Press || e.Kind == pointer.Drag { de = &e } } diff --git a/widget/list.go b/widget/list.go index 8e351f8f5..1c45523fc 100644 --- a/widget/list.go +++ b/widget/list.go @@ -81,7 +81,7 @@ func (s *Scrollbar) Layout(gtx layout.Context, axis layout.Axis, viewportStart, // Offset to account for any drags. for _, event := range s.drag.Events(gtx.Metric, gtx, gesture.Axis(axis)) { - switch event.Type { + switch event.Kind { case pointer.Drag: case pointer.Release, pointer.Cancel: s.dragging = false diff --git a/widget/selectable.go b/widget/selectable.go index 90385dc7f..7c6fb6fee 100644 --- a/widget/selectable.go +++ b/widget/selectable.go @@ -271,10 +271,10 @@ func (e *Selectable) processPointer(gtx layout.Context) { case pointer.Event: release := false switch { - case evt.Type == pointer.Release && evt.Source == pointer.Mouse: + case evt.Kind == pointer.Release && evt.Source == pointer.Mouse: release = true fallthrough - case evt.Type == pointer.Drag && evt.Source == pointer.Mouse: + case evt.Kind == pointer.Drag && evt.Source == pointer.Mouse: if e.dragging { e.text.MoveCoord(image.Point{ X: int(math.Round(float64(evt.Position.X))), diff --git a/widget/widget_test.go b/widget/widget_test.go index 14b548be4..99a718ad7 100644 --- a/widget/widget_test.go +++ b/widget/widget_test.go @@ -35,12 +35,12 @@ func TestBool(t *testing.T) { r.Queue( pointer.Event{ Source: pointer.Touch, - Type: pointer.Press, + Kind: pointer.Press, Position: f32.Pt(50, 50), }, pointer.Event{ Source: pointer.Touch, - Type: pointer.Release, + Kind: pointer.Release, Position: f32.Pt(50, 50), }, )