mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 01:45:36 +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:
+7
-7
@@ -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
|
//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) {
|
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)
|
w := cgo.Handle(handle).Value().(*window)
|
||||||
var typ pointer.Type
|
var kind pointer.Kind
|
||||||
switch action {
|
switch action {
|
||||||
case C.AMOTION_EVENT_ACTION_DOWN, C.AMOTION_EVENT_ACTION_POINTER_DOWN:
|
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:
|
case C.AMOTION_EVENT_ACTION_UP, C.AMOTION_EVENT_ACTION_POINTER_UP:
|
||||||
typ = pointer.Release
|
kind = pointer.Release
|
||||||
case C.AMOTION_EVENT_ACTION_CANCEL:
|
case C.AMOTION_EVENT_ACTION_CANCEL:
|
||||||
typ = pointer.Cancel
|
kind = pointer.Cancel
|
||||||
case C.AMOTION_EVENT_ACTION_MOVE:
|
case C.AMOTION_EVENT_ACTION_MOVE:
|
||||||
typ = pointer.Move
|
kind = pointer.Move
|
||||||
case C.AMOTION_EVENT_ACTION_SCROLL:
|
case C.AMOTION_EVENT_ACTION_SCROLL:
|
||||||
typ = pointer.Scroll
|
kind = pointer.Scroll
|
||||||
default:
|
default:
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -994,7 +994,7 @@ func Java_org_gioui_GioView_onTouchEvent(env *C.JNIEnv, class C.jclass, handle C
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.callbacks.Event(pointer.Event{
|
w.callbacks.Event(pointer.Event{
|
||||||
Type: typ,
|
Kind: kind,
|
||||||
Source: src,
|
Source: src,
|
||||||
Buttons: btns,
|
Buttons: btns,
|
||||||
PointerID: pointer.ID(pointerID),
|
PointerID: pointer.ID(pointerID),
|
||||||
|
|||||||
+6
-6
@@ -236,16 +236,16 @@ func onText(view, str C.CFTypeRef) {
|
|||||||
|
|
||||||
//export onTouch
|
//export onTouch
|
||||||
func onTouch(last C.int, view, touchRef C.CFTypeRef, phase C.NSInteger, x, y C.CGFloat, ti C.double) {
|
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 {
|
switch phase {
|
||||||
case C.UITouchPhaseBegan:
|
case C.UITouchPhaseBegan:
|
||||||
typ = pointer.Press
|
kind = pointer.Press
|
||||||
case C.UITouchPhaseMoved:
|
case C.UITouchPhaseMoved:
|
||||||
typ = pointer.Move
|
kind = pointer.Move
|
||||||
case C.UITouchPhaseEnded:
|
case C.UITouchPhaseEnded:
|
||||||
typ = pointer.Release
|
kind = pointer.Release
|
||||||
case C.UITouchPhaseCancelled:
|
case C.UITouchPhaseCancelled:
|
||||||
typ = pointer.Cancel
|
kind = pointer.Cancel
|
||||||
default:
|
default:
|
||||||
return
|
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))
|
t := time.Duration(float64(ti) * float64(time.Second))
|
||||||
p := f32.Point{X: float32(x), Y: float32(y)}
|
p := f32.Point{X: float32(x), Y: float32(y)}
|
||||||
w.w.Event(pointer.Event{
|
w.w.Event(pointer.Event{
|
||||||
Type: typ,
|
Kind: kind,
|
||||||
Source: pointer.Touch,
|
Source: pointer.Touch,
|
||||||
PointerID: w.lookupTouch(last != 0, touchRef),
|
PointerID: w.lookupTouch(last != 0, touchRef),
|
||||||
Position: p,
|
Position: p,
|
||||||
|
|||||||
+5
-5
@@ -275,7 +275,7 @@ func (w *window) addEventListeners() {
|
|||||||
}
|
}
|
||||||
w.touches = w.touches[:0]
|
w.touches = w.touches[:0]
|
||||||
w.w.Event(pointer.Event{
|
w.w.Event(pointer.Event{
|
||||||
Type: pointer.Cancel,
|
Kind: pointer.Cancel,
|
||||||
Source: pointer.Touch,
|
Source: pointer.Touch,
|
||||||
})
|
})
|
||||||
return nil
|
return nil
|
||||||
@@ -398,7 +398,7 @@ func modifiersFor(e js.Value) key.Modifiers {
|
|||||||
return mods
|
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")
|
e.Call("preventDefault")
|
||||||
t := time.Duration(e.Get("timeStamp").Int()) * time.Millisecond
|
t := time.Duration(e.Get("timeStamp").Int()) * time.Millisecond
|
||||||
changedTouches := e.Get("changedTouches")
|
changedTouches := e.Get("changedTouches")
|
||||||
@@ -426,7 +426,7 @@ func (w *window) touchEvent(typ pointer.Type, e js.Value) {
|
|||||||
Y: float32(y) * scale,
|
Y: float32(y) * scale,
|
||||||
}
|
}
|
||||||
w.w.Event(pointer.Event{
|
w.w.Event(pointer.Event{
|
||||||
Type: typ,
|
Kind: kind,
|
||||||
Source: pointer.Touch,
|
Source: pointer.Touch,
|
||||||
Position: pos,
|
Position: pos,
|
||||||
PointerID: pid,
|
PointerID: pid,
|
||||||
@@ -448,7 +448,7 @@ func (w *window) touchIDFor(touch js.Value) pointer.ID {
|
|||||||
return pid
|
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")
|
e.Call("preventDefault")
|
||||||
x, y := e.Get("clientX").Float(), e.Get("clientY").Float()
|
x, y := e.Get("clientX").Float(), e.Get("clientY").Float()
|
||||||
rect := w.cnv.Call("getBoundingClientRect")
|
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
|
btns |= pointer.ButtonTertiary
|
||||||
}
|
}
|
||||||
w.w.Event(pointer.Event{
|
w.w.Event(pointer.Event{
|
||||||
Type: typ,
|
Kind: kind,
|
||||||
Source: pointer.Mouse,
|
Source: pointer.Mouse,
|
||||||
Buttons: btns,
|
Buttons: btns,
|
||||||
Position: pos,
|
Position: pos,
|
||||||
|
|||||||
+2
-2
@@ -526,7 +526,7 @@ func gio_onMouse(view, evt C.CFTypeRef, cdir C.int, cbtn C.NSInteger, x, y, dx,
|
|||||||
case 2:
|
case 2:
|
||||||
btn = pointer.ButtonTertiary
|
btn = pointer.ButtonTertiary
|
||||||
}
|
}
|
||||||
var typ pointer.Type
|
var typ pointer.Kind
|
||||||
switch cdir {
|
switch cdir {
|
||||||
case C.MOUSE_MOVE:
|
case C.MOUSE_MOVE:
|
||||||
typ = pointer.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")
|
panic("invalid direction")
|
||||||
}
|
}
|
||||||
w.w.Event(pointer.Event{
|
w.w.Event(pointer.Event{
|
||||||
Type: typ,
|
Kind: typ,
|
||||||
Source: pointer.Mouse,
|
Source: pointer.Mouse,
|
||||||
Time: t,
|
Time: t,
|
||||||
Buttons: w.pointerBtns,
|
Buttons: w.pointerBtns,
|
||||||
|
|||||||
+11
-11
@@ -794,7 +794,7 @@ func gio_onTouchDown(data unsafe.Pointer, touch *C.struct_wl_touch, serial, t C.
|
|||||||
Y: fromFixed(y) * float32(w.scale),
|
Y: fromFixed(y) * float32(w.scale),
|
||||||
}
|
}
|
||||||
w.w.Event(pointer.Event{
|
w.w.Event(pointer.Event{
|
||||||
Type: pointer.Press,
|
Kind: pointer.Press,
|
||||||
Source: pointer.Touch,
|
Source: pointer.Touch,
|
||||||
Position: w.lastTouch,
|
Position: w.lastTouch,
|
||||||
PointerID: pointer.ID(id),
|
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]
|
w := s.touchFoci[id]
|
||||||
delete(s.touchFoci, id)
|
delete(s.touchFoci, id)
|
||||||
w.w.Event(pointer.Event{
|
w.w.Event(pointer.Event{
|
||||||
Type: pointer.Release,
|
Kind: pointer.Release,
|
||||||
Source: pointer.Touch,
|
Source: pointer.Touch,
|
||||||
Position: w.lastTouch,
|
Position: w.lastTouch,
|
||||||
PointerID: pointer.ID(id),
|
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),
|
Y: fromFixed(y) * float32(w.scale),
|
||||||
}
|
}
|
||||||
w.w.Event(pointer.Event{
|
w.w.Event(pointer.Event{
|
||||||
Type: pointer.Move,
|
Kind: pointer.Move,
|
||||||
Position: w.lastTouch,
|
Position: w.lastTouch,
|
||||||
Source: pointer.Touch,
|
Source: pointer.Touch,
|
||||||
PointerID: pointer.ID(id),
|
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 {
|
for id, w := range s.touchFoci {
|
||||||
delete(s.touchFoci, id)
|
delete(s.touchFoci, id)
|
||||||
w.w.Event(pointer.Event{
|
w.w.Event(pointer.Event{
|
||||||
Type: pointer.Cancel,
|
Kind: pointer.Cancel,
|
||||||
Source: pointer.Touch,
|
Source: pointer.Touch,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -872,7 +872,7 @@ func gio_onPointerLeave(data unsafe.Pointer, p *C.struct_wl_pointer, serial C.ui
|
|||||||
s.serial = serial
|
s.serial = serial
|
||||||
if w.inCompositor {
|
if w.inCompositor {
|
||||||
w.inCompositor = false
|
w.inCompositor = false
|
||||||
w.w.Event(pointer.Event{Type: pointer.Cancel})
|
w.w.Event(pointer.Event{Kind: pointer.Cancel})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -920,21 +920,21 @@ func gio_onPointerButton(data unsafe.Pointer, p *C.struct_wl_pointer, serial, t,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var typ pointer.Type
|
var kind pointer.Kind
|
||||||
switch state {
|
switch state {
|
||||||
case 0:
|
case 0:
|
||||||
w.pointerBtns &^= btn
|
w.pointerBtns &^= btn
|
||||||
typ = pointer.Release
|
kind = pointer.Release
|
||||||
// Move or resize gestures no longer applies.
|
// Move or resize gestures no longer applies.
|
||||||
w.inCompositor = false
|
w.inCompositor = false
|
||||||
case 1:
|
case 1:
|
||||||
w.pointerBtns |= btn
|
w.pointerBtns |= btn
|
||||||
typ = pointer.Press
|
kind = pointer.Press
|
||||||
}
|
}
|
||||||
w.flushScroll()
|
w.flushScroll()
|
||||||
w.resetFling()
|
w.resetFling()
|
||||||
w.w.Event(pointer.Event{
|
w.w.Event(pointer.Event{
|
||||||
Type: typ,
|
Kind: kind,
|
||||||
Source: pointer.Mouse,
|
Source: pointer.Mouse,
|
||||||
Buttons: w.pointerBtns,
|
Buttons: w.pointerBtns,
|
||||||
Position: w.lastPos,
|
Position: w.lastPos,
|
||||||
@@ -1581,7 +1581,7 @@ func (w *window) flushScroll() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.w.Event(pointer.Event{
|
w.w.Event(pointer.Event{
|
||||||
Type: pointer.Scroll,
|
Kind: pointer.Scroll,
|
||||||
Source: pointer.Mouse,
|
Source: pointer.Mouse,
|
||||||
Buttons: w.pointerBtns,
|
Buttons: w.pointerBtns,
|
||||||
Position: w.lastPos,
|
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),
|
Y: fromFixed(y) * float32(w.scale),
|
||||||
}
|
}
|
||||||
w.w.Event(pointer.Event{
|
w.w.Event(pointer.Event{
|
||||||
Type: pointer.Move,
|
Kind: pointer.Move,
|
||||||
Position: w.lastPos,
|
Position: w.lastPos,
|
||||||
Buttons: w.pointerBtns,
|
Buttons: w.pointerBtns,
|
||||||
Source: pointer.Mouse,
|
Source: pointer.Mouse,
|
||||||
|
|||||||
+7
-7
@@ -259,7 +259,7 @@ func windowProc(hwnd syscall.Handle, msg uint32, wParam, lParam uintptr) uintptr
|
|||||||
w.pointerButton(pointer.ButtonTertiary, false, lParam, getModifiers())
|
w.pointerButton(pointer.ButtonTertiary, false, lParam, getModifiers())
|
||||||
case windows.WM_CANCELMODE:
|
case windows.WM_CANCELMODE:
|
||||||
w.w.Event(pointer.Event{
|
w.w.Event(pointer.Event{
|
||||||
Type: pointer.Cancel,
|
Kind: pointer.Cancel,
|
||||||
})
|
})
|
||||||
case windows.WM_SETFOCUS:
|
case windows.WM_SETFOCUS:
|
||||||
w.focused = true
|
w.focused = true
|
||||||
@@ -288,7 +288,7 @@ func windowProc(hwnd syscall.Handle, msg uint32, wParam, lParam uintptr) uintptr
|
|||||||
x, y := coordsFromlParam(lParam)
|
x, y := coordsFromlParam(lParam)
|
||||||
p := f32.Point{X: float32(x), Y: float32(y)}
|
p := f32.Point{X: float32(x), Y: float32(y)}
|
||||||
w.w.Event(pointer.Event{
|
w.w.Event(pointer.Event{
|
||||||
Type: pointer.Move,
|
Kind: pointer.Move,
|
||||||
Source: pointer.Mouse,
|
Source: pointer.Mouse,
|
||||||
Position: p,
|
Position: p,
|
||||||
Buttons: w.pointerBtns,
|
Buttons: w.pointerBtns,
|
||||||
@@ -501,15 +501,15 @@ func (w *window) pointerButton(btn pointer.Buttons, press bool, lParam uintptr,
|
|||||||
windows.SetFocus(w.hwnd)
|
windows.SetFocus(w.hwnd)
|
||||||
}
|
}
|
||||||
|
|
||||||
var typ pointer.Type
|
var kind pointer.Kind
|
||||||
if press {
|
if press {
|
||||||
typ = pointer.Press
|
kind = pointer.Press
|
||||||
if w.pointerBtns == 0 {
|
if w.pointerBtns == 0 {
|
||||||
windows.SetCapture(w.hwnd)
|
windows.SetCapture(w.hwnd)
|
||||||
}
|
}
|
||||||
w.pointerBtns |= btn
|
w.pointerBtns |= btn
|
||||||
} else {
|
} else {
|
||||||
typ = pointer.Release
|
kind = pointer.Release
|
||||||
w.pointerBtns &^= btn
|
w.pointerBtns &^= btn
|
||||||
if w.pointerBtns == 0 {
|
if w.pointerBtns == 0 {
|
||||||
windows.ReleaseCapture()
|
windows.ReleaseCapture()
|
||||||
@@ -518,7 +518,7 @@ func (w *window) pointerButton(btn pointer.Buttons, press bool, lParam uintptr,
|
|||||||
x, y := coordsFromlParam(lParam)
|
x, y := coordsFromlParam(lParam)
|
||||||
p := f32.Point{X: float32(x), Y: float32(y)}
|
p := f32.Point{X: float32(x), Y: float32(y)}
|
||||||
w.w.Event(pointer.Event{
|
w.w.Event(pointer.Event{
|
||||||
Type: typ,
|
Kind: kind,
|
||||||
Source: pointer.Mouse,
|
Source: pointer.Mouse,
|
||||||
Position: p,
|
Position: p,
|
||||||
Buttons: w.pointerBtns,
|
Buttons: w.pointerBtns,
|
||||||
@@ -553,7 +553,7 @@ func (w *window) scrollEvent(wParam, lParam uintptr, horizontal bool, kmods key.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
w.w.Event(pointer.Event{
|
w.w.Event(pointer.Event{
|
||||||
Type: pointer.Scroll,
|
Kind: pointer.Scroll,
|
||||||
Source: pointer.Mouse,
|
Source: pointer.Mouse,
|
||||||
Position: p,
|
Position: p,
|
||||||
Buttons: w.pointerBtns,
|
Buttons: w.pointerBtns,
|
||||||
|
|||||||
+7
-7
@@ -547,7 +547,7 @@ func (h *x11EventHandler) handleEvents() bool {
|
|||||||
case C.ButtonPress, C.ButtonRelease:
|
case C.ButtonPress, C.ButtonRelease:
|
||||||
bevt := (*C.XButtonEvent)(unsafe.Pointer(xev))
|
bevt := (*C.XButtonEvent)(unsafe.Pointer(xev))
|
||||||
ev := pointer.Event{
|
ev := pointer.Event{
|
||||||
Type: pointer.Press,
|
Kind: pointer.Press,
|
||||||
Source: pointer.Mouse,
|
Source: pointer.Mouse,
|
||||||
Position: f32.Point{
|
Position: f32.Point{
|
||||||
X: float32(bevt.x),
|
X: float32(bevt.x),
|
||||||
@@ -557,7 +557,7 @@ func (h *x11EventHandler) handleEvents() bool {
|
|||||||
Modifiers: w.xkb.Modifiers(),
|
Modifiers: w.xkb.Modifiers(),
|
||||||
}
|
}
|
||||||
if bevt._type == C.ButtonRelease {
|
if bevt._type == C.ButtonRelease {
|
||||||
ev.Type = pointer.Release
|
ev.Kind = pointer.Release
|
||||||
}
|
}
|
||||||
var btn pointer.Buttons
|
var btn pointer.Buttons
|
||||||
const scrollScale = 10
|
const scrollScale = 10
|
||||||
@@ -569,7 +569,7 @@ func (h *x11EventHandler) handleEvents() bool {
|
|||||||
case C.Button3:
|
case C.Button3:
|
||||||
btn = pointer.ButtonSecondary
|
btn = pointer.ButtonSecondary
|
||||||
case C.Button4:
|
case C.Button4:
|
||||||
ev.Type = pointer.Scroll
|
ev.Kind = pointer.Scroll
|
||||||
// scroll up or left (if shift is pressed).
|
// scroll up or left (if shift is pressed).
|
||||||
if ev.Modifiers == key.ModShift {
|
if ev.Modifiers == key.ModShift {
|
||||||
ev.Scroll.X = -scrollScale
|
ev.Scroll.X = -scrollScale
|
||||||
@@ -578,7 +578,7 @@ func (h *x11EventHandler) handleEvents() bool {
|
|||||||
}
|
}
|
||||||
case C.Button5:
|
case C.Button5:
|
||||||
// scroll down or right (if shift is pressed).
|
// scroll down or right (if shift is pressed).
|
||||||
ev.Type = pointer.Scroll
|
ev.Kind = pointer.Scroll
|
||||||
if ev.Modifiers == key.ModShift {
|
if ev.Modifiers == key.ModShift {
|
||||||
ev.Scroll.X = +scrollScale
|
ev.Scroll.X = +scrollScale
|
||||||
} else {
|
} else {
|
||||||
@@ -587,11 +587,11 @@ func (h *x11EventHandler) handleEvents() bool {
|
|||||||
case 6:
|
case 6:
|
||||||
// http://xahlee.info/linux/linux_x11_mouse_button_number.html
|
// http://xahlee.info/linux/linux_x11_mouse_button_number.html
|
||||||
// scroll left.
|
// scroll left.
|
||||||
ev.Type = pointer.Scroll
|
ev.Kind = pointer.Scroll
|
||||||
ev.Scroll.X = -scrollScale * 2
|
ev.Scroll.X = -scrollScale * 2
|
||||||
case 7:
|
case 7:
|
||||||
// scroll right
|
// scroll right
|
||||||
ev.Type = pointer.Scroll
|
ev.Kind = pointer.Scroll
|
||||||
ev.Scroll.X = +scrollScale * 2
|
ev.Scroll.X = +scrollScale * 2
|
||||||
default:
|
default:
|
||||||
continue
|
continue
|
||||||
@@ -607,7 +607,7 @@ func (h *x11EventHandler) handleEvents() bool {
|
|||||||
case C.MotionNotify:
|
case C.MotionNotify:
|
||||||
mevt := (*C.XMotionEvent)(unsafe.Pointer(xev))
|
mevt := (*C.XMotionEvent)(unsafe.Pointer(xev))
|
||||||
w.w.Event(pointer.Event{
|
w.w.Event(pointer.Event{
|
||||||
Type: pointer.Move,
|
Kind: pointer.Move,
|
||||||
Source: pointer.Mouse,
|
Source: pointer.Mouse,
|
||||||
Buttons: w.pointerBtns,
|
Buttons: w.pointerBtns,
|
||||||
Position: f32.Point{
|
Position: f32.Point{
|
||||||
|
|||||||
+8
-8
@@ -39,7 +39,7 @@ type Hover struct {
|
|||||||
func (h *Hover) Add(ops *op.Ops) {
|
func (h *Hover) Add(ops *op.Ops) {
|
||||||
pointer.InputOp{
|
pointer.InputOp{
|
||||||
Tag: h,
|
Tag: h,
|
||||||
Types: pointer.Enter | pointer.Leave,
|
Kinds: pointer.Enter | pointer.Leave,
|
||||||
}.Add(ops)
|
}.Add(ops)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ func (h *Hover) Hovered(q event.Queue) bool {
|
|||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
switch e.Type {
|
switch e.Kind {
|
||||||
case pointer.Leave, pointer.Cancel:
|
case pointer.Leave, pointer.Cancel:
|
||||||
if h.entered && h.pid == e.PointerID {
|
if h.entered && h.pid == e.PointerID {
|
||||||
h.entered = false
|
h.entered = false
|
||||||
@@ -163,7 +163,7 @@ const touchSlop = unit.Dp(3)
|
|||||||
func (c *Click) Add(ops *op.Ops) {
|
func (c *Click) Add(ops *op.Ops) {
|
||||||
pointer.InputOp{
|
pointer.InputOp{
|
||||||
Tag: c,
|
Tag: c,
|
||||||
Types: pointer.Press | pointer.Release | pointer.Enter | pointer.Leave,
|
Kinds: pointer.Press | pointer.Release | pointer.Enter | pointer.Leave,
|
||||||
}.Add(ops)
|
}.Add(ops)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,7 +185,7 @@ func (c *Click) Events(q event.Queue) []ClickEvent {
|
|||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
switch e.Type {
|
switch e.Kind {
|
||||||
case pointer.Release:
|
case pointer.Release:
|
||||||
if !c.pressed || c.pid != e.PointerID {
|
if !c.pressed || c.pid != e.PointerID {
|
||||||
break
|
break
|
||||||
@@ -254,7 +254,7 @@ func (s *Scroll) Add(ops *op.Ops, bounds image.Rectangle) {
|
|||||||
oph := pointer.InputOp{
|
oph := pointer.InputOp{
|
||||||
Tag: s,
|
Tag: s,
|
||||||
Grab: s.grab,
|
Grab: s.grab,
|
||||||
Types: pointer.Press | pointer.Drag | pointer.Release | pointer.Scroll,
|
Kinds: pointer.Press | pointer.Drag | pointer.Release | pointer.Scroll,
|
||||||
ScrollBounds: bounds,
|
ScrollBounds: bounds,
|
||||||
}
|
}
|
||||||
oph.Add(ops)
|
oph.Add(ops)
|
||||||
@@ -281,7 +281,7 @@ func (s *Scroll) Scroll(cfg unit.Metric, q event.Queue, t time.Time, axis Axis)
|
|||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
switch e.Type {
|
switch e.Kind {
|
||||||
case pointer.Press:
|
case pointer.Press:
|
||||||
if s.dragging {
|
if s.dragging {
|
||||||
break
|
break
|
||||||
@@ -368,7 +368,7 @@ func (d *Drag) Add(ops *op.Ops) {
|
|||||||
pointer.InputOp{
|
pointer.InputOp{
|
||||||
Tag: d,
|
Tag: d,
|
||||||
Grab: d.grab,
|
Grab: d.grab,
|
||||||
Types: pointer.Press | pointer.Drag | pointer.Release,
|
Kinds: pointer.Press | pointer.Drag | pointer.Release,
|
||||||
}.Add(ops)
|
}.Add(ops)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -381,7 +381,7 @@ func (d *Drag) Events(cfg unit.Metric, q event.Queue, axis Axis) []pointer.Event
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
switch e.Type {
|
switch e.Kind {
|
||||||
case pointer.Press:
|
case pointer.Press:
|
||||||
if !(e.Buttons == pointer.ButtonPrimary || e.Source == pointer.Touch) {
|
if !(e.Buttons == pointer.ButtonPrimary || e.Source == pointer.Touch) {
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -26,14 +26,14 @@ func TestHover(t *testing.T) {
|
|||||||
r.Frame(ops)
|
r.Frame(ops)
|
||||||
|
|
||||||
r.Queue(
|
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) {
|
if !h.Hovered(r) {
|
||||||
t.Fatal("expected hovered")
|
t.Fatal("expected hovered")
|
||||||
}
|
}
|
||||||
|
|
||||||
r.Queue(
|
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) {
|
if h.Hovered(r) {
|
||||||
t.Fatal("expected not hovered")
|
t.Fatal("expected not hovered")
|
||||||
@@ -92,7 +92,7 @@ func TestMouseClicks(t *testing.T) {
|
|||||||
|
|
||||||
func mouseClickEvents(times ...time.Duration) []event.Event {
|
func mouseClickEvents(times ...time.Duration) []event.Event {
|
||||||
press := pointer.Event{
|
press := pointer.Event{
|
||||||
Type: pointer.Press,
|
Kind: pointer.Press,
|
||||||
Source: pointer.Mouse,
|
Source: pointer.Mouse,
|
||||||
Buttons: pointer.ButtonPrimary,
|
Buttons: pointer.ButtonPrimary,
|
||||||
}
|
}
|
||||||
@@ -101,7 +101,7 @@ func mouseClickEvents(times ...time.Duration) []event.Event {
|
|||||||
press := press
|
press := press
|
||||||
press.Time = t
|
press.Time = t
|
||||||
release := press
|
release := press
|
||||||
release.Type = pointer.Release
|
release.Kind = pointer.Release
|
||||||
events = append(events, press, release)
|
events = append(events, press, release)
|
||||||
}
|
}
|
||||||
return events
|
return events
|
||||||
|
|||||||
+11
-11
@@ -18,7 +18,7 @@ import (
|
|||||||
|
|
||||||
// Event is a pointer event.
|
// Event is a pointer event.
|
||||||
type Event struct {
|
type Event struct {
|
||||||
Type Type
|
Kind Kind
|
||||||
Source Source
|
Source Source
|
||||||
// PointerID is the id for the pointer and can be used
|
// PointerID is the id for the pointer and can be used
|
||||||
// to track a particular pointer from Press to
|
// to track a particular pointer from Press to
|
||||||
@@ -61,8 +61,8 @@ type InputOp struct {
|
|||||||
// Grab, if set, request that the handler get
|
// Grab, if set, request that the handler get
|
||||||
// Grabbed priority.
|
// Grabbed priority.
|
||||||
Grab bool
|
Grab bool
|
||||||
// Types is a bitwise-or of event types to receive.
|
// Kinds is a bitwise-or of event types to receive.
|
||||||
Types Type
|
Kinds Kind
|
||||||
// ScrollBounds describe the maximum scrollable distances in both
|
// ScrollBounds describe the maximum scrollable distances in both
|
||||||
// axes. Specifically, any Event e delivered to Tag will satisfy
|
// axes. Specifically, any Event e delivered to Tag will satisfy
|
||||||
//
|
//
|
||||||
@@ -73,8 +73,8 @@ type InputOp struct {
|
|||||||
|
|
||||||
type ID uint16
|
type ID uint16
|
||||||
|
|
||||||
// Type of an Event.
|
// Kind of an Event.
|
||||||
type Type uint
|
type Kind uint
|
||||||
|
|
||||||
// Priority of an Event.
|
// Priority of an Event.
|
||||||
type Priority uint8
|
type Priority uint8
|
||||||
@@ -169,7 +169,7 @@ const (
|
|||||||
const (
|
const (
|
||||||
// A Cancel event is generated when the current gesture is
|
// A Cancel event is generated when the current gesture is
|
||||||
// interrupted by other handlers or the system.
|
// interrupted by other handlers or the system.
|
||||||
Cancel Type = (1 << iota) >> 1
|
Cancel Kind = (1 << iota) >> 1
|
||||||
// Press of a pointer.
|
// Press of a pointer.
|
||||||
Press
|
Press
|
||||||
// Release of a pointer.
|
// 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 {
|
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))
|
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"))
|
panic(fmt.Errorf("value in Types overflows uint16"))
|
||||||
}
|
}
|
||||||
data := ops.Write1(&o.Internal, ops.TypePointerInputLen, op.Tag)
|
data := ops.Write1(&o.Internal, ops.TypePointerInputLen, op.Tag)
|
||||||
@@ -252,19 +252,19 @@ func (op InputOp) Add(o *op.Ops) {
|
|||||||
data[1] = 1
|
data[1] = 1
|
||||||
}
|
}
|
||||||
bo := binary.LittleEndian
|
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[4:], uint32(op.ScrollBounds.Min.X))
|
||||||
bo.PutUint32(data[8:], uint32(op.ScrollBounds.Min.Y))
|
bo.PutUint32(data[8:], uint32(op.ScrollBounds.Min.Y))
|
||||||
bo.PutUint32(data[12:], uint32(op.ScrollBounds.Max.X))
|
bo.PutUint32(data[12:], uint32(op.ScrollBounds.Max.X))
|
||||||
bo.PutUint32(data[16:], uint32(op.ScrollBounds.Max.Y))
|
bo.PutUint32(data[16:], uint32(op.ScrollBounds.Max.Y))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t Type) String() string {
|
func (t Kind) String() string {
|
||||||
if t == Cancel {
|
if t == Cancel {
|
||||||
return "Cancel"
|
return "Cancel"
|
||||||
}
|
}
|
||||||
var buf strings.Builder
|
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 t&tt > 0 {
|
||||||
if buf.Len() > 0 {
|
if buf.Len() > 0 {
|
||||||
buf.WriteByte('|')
|
buf.WriteByte('|')
|
||||||
@@ -275,7 +275,7 @@ func (t Type) String() string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t Type) string() string {
|
func (t Kind) string() string {
|
||||||
switch t {
|
switch t {
|
||||||
case Press:
|
case Press:
|
||||||
return "Press"
|
return "Press"
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
|
|
||||||
func TestTypeString(t *testing.T) {
|
func TestTypeString(t *testing.T) {
|
||||||
for _, tc := range []struct {
|
for _, tc := range []struct {
|
||||||
typ Type
|
typ Kind
|
||||||
res string
|
res string
|
||||||
}{
|
}{
|
||||||
{Cancel, "Cancel"},
|
{Cancel, "Cancel"},
|
||||||
|
|||||||
@@ -279,7 +279,7 @@ func TestFocusScroll(t *testing.T) {
|
|||||||
key.InputOp{Tag: h}.Add(ops)
|
key.InputOp{Tag: h}.Add(ops)
|
||||||
pointer.InputOp{
|
pointer.InputOp{
|
||||||
Tag: h,
|
Tag: h,
|
||||||
Types: pointer.Scroll,
|
Kinds: pointer.Scroll,
|
||||||
ScrollBounds: image.Rect(-100, -100, 100, 100),
|
ScrollBounds: image.Rect(-100, -100, 100, 100),
|
||||||
}.Add(ops)
|
}.Add(ops)
|
||||||
// Test that h is scrolled even if behind another handler.
|
// 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)
|
key.InputOp{Tag: h}.Add(ops)
|
||||||
pointer.InputOp{
|
pointer.InputOp{
|
||||||
Tag: h,
|
Tag: h,
|
||||||
Types: pointer.Press | pointer.Release,
|
Kinds: pointer.Press | pointer.Release,
|
||||||
}.Add(ops)
|
}.Add(ops)
|
||||||
cl.Pop()
|
cl.Pop()
|
||||||
r.Frame(ops)
|
r.Frame(ops)
|
||||||
|
|||||||
+19
-19
@@ -66,7 +66,7 @@ type pointerHandler struct {
|
|||||||
area int
|
area int
|
||||||
active bool
|
active bool
|
||||||
wantsGrab bool
|
wantsGrab bool
|
||||||
types pointer.Type
|
types pointer.Kind
|
||||||
// min and max horizontal/vertical scroll
|
// min and max horizontal/vertical scroll
|
||||||
scrollRange image.Rectangle
|
scrollRange image.Rectangle
|
||||||
|
|
||||||
@@ -242,7 +242,7 @@ func (c *pointerCollector) newHandler(tag event.Tag, events *handlerEvents) *poi
|
|||||||
c.q.handlers[tag] = h
|
c.q.handlers[tag] = h
|
||||||
// Cancel handlers on (each) first appearance, but don't
|
// Cancel handlers on (each) first appearance, but don't
|
||||||
// trigger redraw.
|
// trigger redraw.
|
||||||
events.AddNoRedraw(tag, pointer.Event{Type: pointer.Cancel})
|
events.AddNoRedraw(tag, pointer.Event{Kind: pointer.Cancel})
|
||||||
}
|
}
|
||||||
h.active = true
|
h.active = true
|
||||||
h.area = areaID
|
h.area = areaID
|
||||||
@@ -268,16 +268,16 @@ func (c *pointerCollector) inputOp(op pointer.InputOp, events *handlerEvents) {
|
|||||||
areaID := c.currentArea()
|
areaID := c.currentArea()
|
||||||
area := &c.q.areas[areaID]
|
area := &c.q.areas[areaID]
|
||||||
area.semantic.content.tag = op.Tag
|
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
|
area.semantic.content.gestures |= ClickGesture
|
||||||
}
|
}
|
||||||
if op.Types&pointer.Scroll != 0 {
|
if op.Kinds&pointer.Scroll != 0 {
|
||||||
area.semantic.content.gestures |= ScrollGesture
|
area.semantic.content.gestures |= ScrollGesture
|
||||||
}
|
}
|
||||||
area.semantic.valid = area.semantic.content.gestures != 0
|
area.semantic.valid = area.semantic.content.gestures != 0
|
||||||
h := c.newHandler(op.Tag, events)
|
h := c.newHandler(op.Tag, events)
|
||||||
h.wantsGrab = h.wantsGrab || op.Grab
|
h.wantsGrab = h.wantsGrab || op.Grab
|
||||||
h.types = h.types | op.Types
|
h.types = h.types | op.Kinds
|
||||||
h.scrollRange = op.ScrollBounds
|
h.scrollRange = op.ScrollBounds
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -602,7 +602,7 @@ func (q *pointerQueue) Frame(events *handlerEvents) {
|
|||||||
|
|
||||||
func (q *pointerQueue) dropHandler(events *handlerEvents, tag event.Tag) {
|
func (q *pointerQueue) dropHandler(events *handlerEvents, tag event.Tag) {
|
||||||
if events != nil {
|
if events != nil {
|
||||||
events.Add(tag, pointer.Event{Type: pointer.Cancel})
|
events.Add(tag, pointer.Event{Kind: pointer.Cancel})
|
||||||
}
|
}
|
||||||
for i := range q.pointers {
|
for i := range q.pointers {
|
||||||
p := &q.pointers[i]
|
p := &q.pointers[i]
|
||||||
@@ -649,11 +649,11 @@ func (q *pointerQueue) Deliver(areaIdx int, e pointer.Event, events *handlerEven
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
h := q.handlers[n.tag]
|
h := q.handlers[n.tag]
|
||||||
if e.Type&h.types == 0 {
|
if e.Kind&h.types == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
e := e
|
e := e
|
||||||
if e.Type == pointer.Scroll {
|
if e.Kind == pointer.Scroll {
|
||||||
if sx == 0 && sy == 0 {
|
if sx == 0 && sy == 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -663,7 +663,7 @@ func (q *pointerQueue) Deliver(areaIdx int, e pointer.Event, events *handlerEven
|
|||||||
}
|
}
|
||||||
e.Position = q.invTransform(h.area, e.Position)
|
e.Position = q.invTransform(h.area, e.Position)
|
||||||
events.Add(n.tag, e)
|
events.Add(n.tag, e)
|
||||||
if e.Type != pointer.Scroll {
|
if e.Kind != pointer.Scroll {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -683,7 +683,7 @@ func (q *pointerQueue) SemanticArea(areaIdx int) (semanticContent, int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (q *pointerQueue) Push(e pointer.Event, events *handlerEvents) {
|
func (q *pointerQueue) Push(e pointer.Event, events *handlerEvents) {
|
||||||
if e.Type == pointer.Cancel {
|
if e.Kind == pointer.Cancel {
|
||||||
q.pointers = q.pointers[:0]
|
q.pointers = q.pointers[:0]
|
||||||
for k := range q.handlers {
|
for k := range q.handlers {
|
||||||
q.dropHandler(events, k)
|
q.dropHandler(events, k)
|
||||||
@@ -694,14 +694,14 @@ func (q *pointerQueue) Push(e pointer.Event, events *handlerEvents) {
|
|||||||
p := &q.pointers[pidx]
|
p := &q.pointers[pidx]
|
||||||
p.last = e
|
p.last = e
|
||||||
|
|
||||||
switch e.Type {
|
switch e.Kind {
|
||||||
case pointer.Press:
|
case pointer.Press:
|
||||||
q.deliverEnterLeaveEvents(p, events, e)
|
q.deliverEnterLeaveEvents(p, events, e)
|
||||||
p.pressed = true
|
p.pressed = true
|
||||||
q.deliverEvent(p, events, e)
|
q.deliverEvent(p, events, e)
|
||||||
case pointer.Move:
|
case pointer.Move:
|
||||||
if p.pressed {
|
if p.pressed {
|
||||||
e.Type = pointer.Drag
|
e.Kind = pointer.Drag
|
||||||
}
|
}
|
||||||
q.deliverEnterLeaveEvents(p, events, e)
|
q.deliverEnterLeaveEvents(p, events, e)
|
||||||
q.deliverEvent(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
|
var sx, sy = e.Scroll.X, e.Scroll.Y
|
||||||
for _, k := range p.handlers {
|
for _, k := range p.handlers {
|
||||||
h := q.handlers[k]
|
h := q.handlers[k]
|
||||||
if e.Type == pointer.Scroll {
|
if e.Kind == pointer.Scroll {
|
||||||
if sx == 0 && sy == 0 {
|
if sx == 0 && sy == 0 {
|
||||||
return
|
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)
|
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)
|
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
|
continue
|
||||||
}
|
}
|
||||||
e := e
|
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) {
|
func (q *pointerQueue) deliverEnterLeaveEvents(p *pointerInfo, events *handlerEvents, e pointer.Event) {
|
||||||
var hits []event.Tag
|
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.
|
// Consider non-mouse pointers leaving when they're released.
|
||||||
} else {
|
} else {
|
||||||
hits, q.cursor = q.opHit(e.Position)
|
hits, q.cursor = q.opHit(e.Position)
|
||||||
@@ -790,9 +790,9 @@ func (q *pointerQueue) deliverEnterLeaveEvents(p *pointerInfo, events *handlerEv
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
h := q.handlers[k]
|
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 := e
|
||||||
e.Position = q.invTransform(h.area, e.Position)
|
e.Position = q.invTransform(h.area, e.Position)
|
||||||
events.Add(k, e)
|
events.Add(k, e)
|
||||||
@@ -804,9 +804,9 @@ func (q *pointerQueue) deliverEnterLeaveEvents(p *pointerInfo, events *handlerEv
|
|||||||
if _, found := searchTag(p.entered, k); found {
|
if _, found := searchTag(p.entered, k); found {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
e.Type = pointer.Enter
|
e.Kind = pointer.Enter
|
||||||
|
|
||||||
if e.Type&h.types != 0 {
|
if e.Kind&h.types != 0 {
|
||||||
e := e
|
e := e
|
||||||
e.Position = q.invTransform(h.area, e.Position)
|
e.Position = q.invTransform(h.area, e.Position)
|
||||||
events.Add(k, e)
|
events.Add(k, e)
|
||||||
|
|||||||
+100
-100
@@ -50,12 +50,12 @@ func TestPointerDrag(t *testing.T) {
|
|||||||
r.Queue(
|
r.Queue(
|
||||||
// Press.
|
// Press.
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Press,
|
Kind: pointer.Press,
|
||||||
Position: f32.Pt(50, 50),
|
Position: f32.Pt(50, 50),
|
||||||
},
|
},
|
||||||
// Move outside the area.
|
// Move outside the area.
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Move,
|
Kind: pointer.Move,
|
||||||
Position: f32.Pt(150, 150),
|
Position: f32.Pt(150, 150),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@@ -72,12 +72,12 @@ func TestPointerDragNegative(t *testing.T) {
|
|||||||
r.Queue(
|
r.Queue(
|
||||||
// Press.
|
// Press.
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Press,
|
Kind: pointer.Press,
|
||||||
Position: f32.Pt(-50, -50),
|
Position: f32.Pt(-50, -50),
|
||||||
},
|
},
|
||||||
// Move outside the area.
|
// Move outside the area.
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Move,
|
Kind: pointer.Move,
|
||||||
Position: f32.Pt(-150, -150),
|
Position: f32.Pt(-150, -150),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@@ -92,15 +92,15 @@ func TestPointerGrab(t *testing.T) {
|
|||||||
|
|
||||||
types := pointer.Press | pointer.Release
|
types := pointer.Press | pointer.Release
|
||||||
|
|
||||||
pointer.InputOp{Tag: handler1, Types: types, Grab: true}.Add(&ops)
|
pointer.InputOp{Tag: handler1, Kinds: types, Grab: true}.Add(&ops)
|
||||||
pointer.InputOp{Tag: handler2, Types: types}.Add(&ops)
|
pointer.InputOp{Tag: handler2, Kinds: types}.Add(&ops)
|
||||||
pointer.InputOp{Tag: handler3, Types: types}.Add(&ops)
|
pointer.InputOp{Tag: handler3, Kinds: types}.Add(&ops)
|
||||||
|
|
||||||
var r Router
|
var r Router
|
||||||
r.Frame(&ops)
|
r.Frame(&ops)
|
||||||
r.Queue(
|
r.Queue(
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Press,
|
Kind: pointer.Press,
|
||||||
Position: f32.Pt(50, 50),
|
Position: f32.Pt(50, 50),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@@ -110,7 +110,7 @@ func TestPointerGrab(t *testing.T) {
|
|||||||
r.Frame(&ops)
|
r.Frame(&ops)
|
||||||
r.Queue(
|
r.Queue(
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Release,
|
Kind: pointer.Release,
|
||||||
Position: f32.Pt(50, 50),
|
Position: f32.Pt(50, 50),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@@ -126,15 +126,15 @@ func TestPointerGrabSameHandlerTwice(t *testing.T) {
|
|||||||
|
|
||||||
types := pointer.Press | pointer.Release
|
types := pointer.Press | pointer.Release
|
||||||
|
|
||||||
pointer.InputOp{Tag: handler1, Types: types, Grab: true}.Add(&ops)
|
pointer.InputOp{Tag: handler1, Kinds: types, Grab: true}.Add(&ops)
|
||||||
pointer.InputOp{Tag: handler1, Types: types}.Add(&ops)
|
pointer.InputOp{Tag: handler1, Kinds: types}.Add(&ops)
|
||||||
pointer.InputOp{Tag: handler2, Types: types}.Add(&ops)
|
pointer.InputOp{Tag: handler2, Kinds: types}.Add(&ops)
|
||||||
|
|
||||||
var r Router
|
var r Router
|
||||||
r.Frame(&ops)
|
r.Frame(&ops)
|
||||||
r.Queue(
|
r.Queue(
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Press,
|
Kind: pointer.Press,
|
||||||
Position: f32.Pt(50, 50),
|
Position: f32.Pt(50, 50),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@@ -143,7 +143,7 @@ func TestPointerGrabSameHandlerTwice(t *testing.T) {
|
|||||||
r.Frame(&ops)
|
r.Frame(&ops)
|
||||||
r.Queue(
|
r.Queue(
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Release,
|
Kind: pointer.Release,
|
||||||
Position: f32.Pt(50, 50),
|
Position: f32.Pt(50, 50),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@@ -160,10 +160,10 @@ func TestPointerMove(t *testing.T) {
|
|||||||
|
|
||||||
// Handler 1 area: (0, 0) - (100, 100)
|
// Handler 1 area: (0, 0) - (100, 100)
|
||||||
r1 := clip.Rect(image.Rect(0, 0, 100, 100)).Push(&ops)
|
r1 := clip.Rect(image.Rect(0, 0, 100, 100)).Push(&ops)
|
||||||
pointer.InputOp{Tag: handler1, Types: types}.Add(&ops)
|
pointer.InputOp{Tag: handler1, Kinds: types}.Add(&ops)
|
||||||
// Handler 2 area: (50, 50) - (100, 100) (areas intersect).
|
// Handler 2 area: (50, 50) - (100, 100) (areas intersect).
|
||||||
r2 := clip.Rect(image.Rect(50, 50, 200, 200)).Push(&ops)
|
r2 := clip.Rect(image.Rect(50, 50, 200, 200)).Push(&ops)
|
||||||
pointer.InputOp{Tag: handler2, Types: types}.Add(&ops)
|
pointer.InputOp{Tag: handler2, Kinds: types}.Add(&ops)
|
||||||
r2.Pop()
|
r2.Pop()
|
||||||
r1.Pop()
|
r1.Pop()
|
||||||
|
|
||||||
@@ -172,21 +172,21 @@ func TestPointerMove(t *testing.T) {
|
|||||||
r.Queue(
|
r.Queue(
|
||||||
// Hit both handlers.
|
// Hit both handlers.
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Move,
|
Kind: pointer.Move,
|
||||||
Position: f32.Pt(50, 50),
|
Position: f32.Pt(50, 50),
|
||||||
},
|
},
|
||||||
// Hit handler 1.
|
// Hit handler 1.
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Move,
|
Kind: pointer.Move,
|
||||||
Position: f32.Pt(49, 50),
|
Position: f32.Pt(49, 50),
|
||||||
},
|
},
|
||||||
// Hit no handlers.
|
// Hit no handlers.
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Move,
|
Kind: pointer.Move,
|
||||||
Position: f32.Pt(100, 50),
|
Position: f32.Pt(100, 50),
|
||||||
},
|
},
|
||||||
pointer.Event{
|
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)
|
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)
|
r1 := clip.Rect(image.Rect(0, 0, 100, 100)).Push(&ops)
|
||||||
pointer.InputOp{
|
pointer.InputOp{
|
||||||
Tag: handler,
|
Tag: handler,
|
||||||
Types: pointer.Press | pointer.Release,
|
Kinds: pointer.Press | pointer.Release,
|
||||||
}.Add(&ops)
|
}.Add(&ops)
|
||||||
r1.Pop()
|
r1.Pop()
|
||||||
|
|
||||||
@@ -207,15 +207,15 @@ func TestPointerTypes(t *testing.T) {
|
|||||||
r.Frame(&ops)
|
r.Frame(&ops)
|
||||||
r.Queue(
|
r.Queue(
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Press,
|
Kind: pointer.Press,
|
||||||
Position: f32.Pt(50, 50),
|
Position: f32.Pt(50, 50),
|
||||||
},
|
},
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Move,
|
Kind: pointer.Move,
|
||||||
Position: f32.Pt(150, 150),
|
Position: f32.Pt(150, 150),
|
||||||
},
|
},
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Release,
|
Kind: pointer.Release,
|
||||||
Position: f32.Pt(150, 150),
|
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)
|
r1 := clip.Rect(image.Rect(0, 0, 100, 100)).Push(&ops)
|
||||||
pointer.InputOp{
|
pointer.InputOp{
|
||||||
Tag: handler1,
|
Tag: handler1,
|
||||||
Types: pointer.Scroll,
|
Kinds: pointer.Scroll,
|
||||||
ScrollBounds: image.Rectangle{Max: image.Point{X: 100}},
|
ScrollBounds: image.Rectangle{Max: image.Point{X: 100}},
|
||||||
}.Add(&ops)
|
}.Add(&ops)
|
||||||
|
|
||||||
r2 := clip.Rect(image.Rect(0, 0, 100, 50)).Push(&ops)
|
r2 := clip.Rect(image.Rect(0, 0, 100, 50)).Push(&ops)
|
||||||
pointer.InputOp{
|
pointer.InputOp{
|
||||||
Tag: handler2,
|
Tag: handler2,
|
||||||
Types: pointer.Scroll,
|
Kinds: pointer.Scroll,
|
||||||
ScrollBounds: image.Rectangle{Max: image.Point{X: 20}},
|
ScrollBounds: image.Rectangle{Max: image.Point{X: 20}},
|
||||||
}.Add(&ops)
|
}.Add(&ops)
|
||||||
r2.Pop()
|
r2.Pop()
|
||||||
@@ -284,7 +284,7 @@ func TestPointerPriority(t *testing.T) {
|
|||||||
r3 := clip.Rect(image.Rect(0, 100, 100, 200)).Push(&ops)
|
r3 := clip.Rect(image.Rect(0, 100, 100, 200)).Push(&ops)
|
||||||
pointer.InputOp{
|
pointer.InputOp{
|
||||||
Tag: handler3,
|
Tag: handler3,
|
||||||
Types: pointer.Scroll,
|
Kinds: pointer.Scroll,
|
||||||
ScrollBounds: image.Rectangle{Min: image.Point{X: -20, Y: -40}},
|
ScrollBounds: image.Rectangle{Min: image.Point{X: -20, Y: -40}},
|
||||||
}.Add(&ops)
|
}.Add(&ops)
|
||||||
r3.Pop()
|
r3.Pop()
|
||||||
@@ -294,25 +294,25 @@ func TestPointerPriority(t *testing.T) {
|
|||||||
r.Queue(
|
r.Queue(
|
||||||
// Hit handler 1 and 2.
|
// Hit handler 1 and 2.
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Scroll,
|
Kind: pointer.Scroll,
|
||||||
Position: f32.Pt(50, 25),
|
Position: f32.Pt(50, 25),
|
||||||
Scroll: f32.Pt(50, 0),
|
Scroll: f32.Pt(50, 0),
|
||||||
},
|
},
|
||||||
// Hit handler 1.
|
// Hit handler 1.
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Scroll,
|
Kind: pointer.Scroll,
|
||||||
Position: f32.Pt(50, 75),
|
Position: f32.Pt(50, 75),
|
||||||
Scroll: f32.Pt(50, 50),
|
Scroll: f32.Pt(50, 50),
|
||||||
},
|
},
|
||||||
// Hit handler 3.
|
// Hit handler 3.
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Scroll,
|
Kind: pointer.Scroll,
|
||||||
Position: f32.Pt(50, 150),
|
Position: f32.Pt(50, 150),
|
||||||
Scroll: f32.Pt(-30, -30),
|
Scroll: f32.Pt(-30, -30),
|
||||||
},
|
},
|
||||||
// Hit no handlers.
|
// Hit no handlers.
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Scroll,
|
Kind: pointer.Scroll,
|
||||||
Position: f32.Pt(50, 225),
|
Position: f32.Pt(50, 225),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@@ -348,7 +348,7 @@ func TestPointerEnterLeave(t *testing.T) {
|
|||||||
// Hit both handlers.
|
// Hit both handlers.
|
||||||
r.Queue(
|
r.Queue(
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Move,
|
Kind: pointer.Move,
|
||||||
Position: f32.Pt(50, 50),
|
Position: f32.Pt(50, 50),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@@ -361,7 +361,7 @@ func TestPointerEnterLeave(t *testing.T) {
|
|||||||
// Leave the second area by moving into the first.
|
// Leave the second area by moving into the first.
|
||||||
r.Queue(
|
r.Queue(
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Move,
|
Kind: pointer.Move,
|
||||||
Position: f32.Pt(45, 45),
|
Position: f32.Pt(45, 45),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@@ -372,7 +372,7 @@ func TestPointerEnterLeave(t *testing.T) {
|
|||||||
// Move, but stay within the same hit area.
|
// Move, but stay within the same hit area.
|
||||||
r.Queue(
|
r.Queue(
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Move,
|
Kind: pointer.Move,
|
||||||
Position: f32.Pt(40, 40),
|
Position: f32.Pt(40, 40),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@@ -382,7 +382,7 @@ func TestPointerEnterLeave(t *testing.T) {
|
|||||||
// Move outside of both inputs.
|
// Move outside of both inputs.
|
||||||
r.Queue(
|
r.Queue(
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Move,
|
Kind: pointer.Move,
|
||||||
Position: f32.Pt(300, 300),
|
Position: f32.Pt(300, 300),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@@ -392,7 +392,7 @@ func TestPointerEnterLeave(t *testing.T) {
|
|||||||
// Check that a Press event generates Enter Events.
|
// Check that a Press event generates Enter Events.
|
||||||
r.Queue(
|
r.Queue(
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Press,
|
Kind: pointer.Press,
|
||||||
Position: f32.Pt(125, 125),
|
Position: f32.Pt(125, 125),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@@ -403,12 +403,12 @@ func TestPointerEnterLeave(t *testing.T) {
|
|||||||
r.Queue(
|
r.Queue(
|
||||||
// Leave
|
// Leave
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Move,
|
Kind: pointer.Move,
|
||||||
Position: f32.Pt(25, 25),
|
Position: f32.Pt(25, 25),
|
||||||
},
|
},
|
||||||
// Enter
|
// Enter
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Move,
|
Kind: pointer.Move,
|
||||||
Position: f32.Pt(50, 50),
|
Position: f32.Pt(50, 50),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@@ -418,7 +418,7 @@ func TestPointerEnterLeave(t *testing.T) {
|
|||||||
// Check that a Release event generates Enter/Leave Events.
|
// Check that a Release event generates Enter/Leave Events.
|
||||||
r.Queue(
|
r.Queue(
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Release,
|
Kind: pointer.Release,
|
||||||
Position: f32.Pt(25,
|
Position: f32.Pt(25,
|
||||||
25),
|
25),
|
||||||
},
|
},
|
||||||
@@ -446,15 +446,15 @@ func TestMultipleAreas(t *testing.T) {
|
|||||||
// Hit first area, then second area, then both.
|
// Hit first area, then second area, then both.
|
||||||
r.Queue(
|
r.Queue(
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Move,
|
Kind: pointer.Move,
|
||||||
Position: f32.Pt(25, 25),
|
Position: f32.Pt(25, 25),
|
||||||
},
|
},
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Move,
|
Kind: pointer.Move,
|
||||||
Position: f32.Pt(150, 150),
|
Position: f32.Pt(150, 150),
|
||||||
},
|
},
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Move,
|
Kind: pointer.Move,
|
||||||
Position: f32.Pt(50, 50),
|
Position: f32.Pt(50, 50),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@@ -470,11 +470,11 @@ func TestPointerEnterLeaveNested(t *testing.T) {
|
|||||||
|
|
||||||
// Handler 1 area: (0, 0) - (100, 100)
|
// Handler 1 area: (0, 0) - (100, 100)
|
||||||
r1 := clip.Rect(image.Rect(0, 0, 100, 100)).Push(&ops)
|
r1 := clip.Rect(image.Rect(0, 0, 100, 100)).Push(&ops)
|
||||||
pointer.InputOp{Tag: handler1, Types: types}.Add(&ops)
|
pointer.InputOp{Tag: handler1, Kinds: types}.Add(&ops)
|
||||||
|
|
||||||
// Handler 2 area: (25, 25) - (75, 75) (nested within first).
|
// Handler 2 area: (25, 25) - (75, 75) (nested within first).
|
||||||
r2 := clip.Rect(image.Rect(25, 25, 75, 75)).Push(&ops)
|
r2 := clip.Rect(image.Rect(25, 25, 75, 75)).Push(&ops)
|
||||||
pointer.InputOp{Tag: handler2, Types: types}.Add(&ops)
|
pointer.InputOp{Tag: handler2, Kinds: types}.Add(&ops)
|
||||||
r2.Pop()
|
r2.Pop()
|
||||||
r1.Pop()
|
r1.Pop()
|
||||||
|
|
||||||
@@ -483,7 +483,7 @@ func TestPointerEnterLeaveNested(t *testing.T) {
|
|||||||
// Hit both handlers.
|
// Hit both handlers.
|
||||||
r.Queue(
|
r.Queue(
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Move,
|
Kind: pointer.Move,
|
||||||
Position: f32.Pt(50, 50),
|
Position: f32.Pt(50, 50),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@@ -495,7 +495,7 @@ func TestPointerEnterLeaveNested(t *testing.T) {
|
|||||||
// Leave the second area by moving into the first.
|
// Leave the second area by moving into the first.
|
||||||
r.Queue(
|
r.Queue(
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Move,
|
Kind: pointer.Move,
|
||||||
Position: f32.Pt(20, 20),
|
Position: f32.Pt(20, 20),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@@ -505,7 +505,7 @@ func TestPointerEnterLeaveNested(t *testing.T) {
|
|||||||
// Move, but stay within the same hit area.
|
// Move, but stay within the same hit area.
|
||||||
r.Queue(
|
r.Queue(
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Move,
|
Kind: pointer.Move,
|
||||||
Position: f32.Pt(10, 10),
|
Position: f32.Pt(10, 10),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@@ -515,7 +515,7 @@ func TestPointerEnterLeaveNested(t *testing.T) {
|
|||||||
// Move outside of both inputs.
|
// Move outside of both inputs.
|
||||||
r.Queue(
|
r.Queue(
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Move,
|
Kind: pointer.Move,
|
||||||
Position: f32.Pt(200, 200),
|
Position: f32.Pt(200, 200),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@@ -525,7 +525,7 @@ func TestPointerEnterLeaveNested(t *testing.T) {
|
|||||||
// Check that a Press event generates Enter Events.
|
// Check that a Press event generates Enter Events.
|
||||||
r.Queue(
|
r.Queue(
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Press,
|
Kind: pointer.Press,
|
||||||
Position: f32.Pt(50, 50),
|
Position: f32.Pt(50, 50),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@@ -535,7 +535,7 @@ func TestPointerEnterLeaveNested(t *testing.T) {
|
|||||||
// Check that a Release event generates Enter/Leave Events.
|
// Check that a Release event generates Enter/Leave Events.
|
||||||
r.Queue(
|
r.Queue(
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Release,
|
Kind: pointer.Release,
|
||||||
Position: f32.Pt(20, 20),
|
Position: f32.Pt(20, 20),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@@ -554,7 +554,7 @@ func TestPointerActiveInputDisappears(t *testing.T) {
|
|||||||
r.Frame(&ops)
|
r.Frame(&ops)
|
||||||
r.Queue(
|
r.Queue(
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Move,
|
Kind: pointer.Move,
|
||||||
Position: f32.Pt(25, 25),
|
Position: f32.Pt(25, 25),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@@ -565,7 +565,7 @@ func TestPointerActiveInputDisappears(t *testing.T) {
|
|||||||
r.Frame(&ops)
|
r.Frame(&ops)
|
||||||
r.Queue(
|
r.Queue(
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Move,
|
Kind: pointer.Move,
|
||||||
Position: f32.Pt(25, 25),
|
Position: f32.Pt(25, 25),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@@ -587,21 +587,21 @@ func TestMultitouch(t *testing.T) {
|
|||||||
r.Frame(&ops)
|
r.Frame(&ops)
|
||||||
r.Queue(
|
r.Queue(
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Press,
|
Kind: pointer.Press,
|
||||||
Position: h1pt,
|
Position: h1pt,
|
||||||
PointerID: p1,
|
PointerID: p1,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
r.Queue(
|
r.Queue(
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Press,
|
Kind: pointer.Press,
|
||||||
Position: h2pt,
|
Position: h2pt,
|
||||||
PointerID: p2,
|
PointerID: p2,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
r.Queue(
|
r.Queue(
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Release,
|
Kind: pointer.Release,
|
||||||
Position: h2pt,
|
Position: h2pt,
|
||||||
PointerID: p2,
|
PointerID: p2,
|
||||||
},
|
},
|
||||||
@@ -634,7 +634,7 @@ func TestCursor(t *testing.T) {
|
|||||||
|
|
||||||
_at := func(x, y float32) pointer.Event {
|
_at := func(x, y float32) pointer.Event {
|
||||||
return pointer.Event{
|
return pointer.Event{
|
||||||
Type: pointer.Move,
|
Kind: pointer.Move,
|
||||||
Source: pointer.Mouse,
|
Source: pointer.Mouse,
|
||||||
Buttons: pointer.ButtonPrimary,
|
Buttons: pointer.ButtonPrimary,
|
||||||
Position: f32.Pt(x, y),
|
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)
|
h1, h2, h3, h4 := new(int), new(int), new(int), new(int)
|
||||||
area := clip.Rect(image.Rect(0, 0, 100, 100))
|
area := clip.Rect(image.Rect(0, 0, 100, 100))
|
||||||
root := area.Push(&ops)
|
root := area.Push(&ops)
|
||||||
pointer.InputOp{Tag: h1, Types: pointer.Press}.Add(&ops)
|
pointer.InputOp{Tag: h1, Kinds: pointer.Press}.Add(&ops)
|
||||||
child1 := area.Push(&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()
|
child1.Pop()
|
||||||
child2 := area.Push(&ops)
|
child2 := area.Push(&ops)
|
||||||
pass := pointer.PassOp{}.Push(&ops)
|
pass := pointer.PassOp{}.Push(&ops)
|
||||||
pointer.InputOp{Tag: h3, Types: pointer.Press}.Add(&ops)
|
pointer.InputOp{Tag: h3, Kinds: pointer.Press}.Add(&ops)
|
||||||
pointer.InputOp{Tag: h4, Types: pointer.Press}.Add(&ops)
|
pointer.InputOp{Tag: h4, Kinds: pointer.Press}.Add(&ops)
|
||||||
pass.Pop()
|
pass.Pop()
|
||||||
child2.Pop()
|
child2.Pop()
|
||||||
root.Pop()
|
root.Pop()
|
||||||
@@ -750,7 +750,7 @@ func TestPassOp(t *testing.T) {
|
|||||||
r.Frame(&ops)
|
r.Frame(&ops)
|
||||||
r.Queue(
|
r.Queue(
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Press,
|
Kind: pointer.Press,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
assertEventPointerTypeSequence(t, r.Events(h1), pointer.Cancel, pointer.Press)
|
assertEventPointerTypeSequence(t, r.Events(h1), pointer.Cancel, pointer.Press)
|
||||||
@@ -763,13 +763,13 @@ func TestAreaPassthrough(t *testing.T) {
|
|||||||
var ops op.Ops
|
var ops op.Ops
|
||||||
|
|
||||||
h := new(int)
|
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()
|
clip.Rect(image.Rect(0, 0, 100, 100)).Push(&ops).Pop()
|
||||||
var r Router
|
var r Router
|
||||||
r.Frame(&ops)
|
r.Frame(&ops)
|
||||||
r.Queue(
|
r.Queue(
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Press,
|
Kind: pointer.Press,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
assertEventPointerTypeSequence(t, r.Events(h), pointer.Cancel, pointer.Press)
|
assertEventPointerTypeSequence(t, r.Events(h), pointer.Cancel, pointer.Press)
|
||||||
@@ -780,7 +780,7 @@ func TestEllipse(t *testing.T) {
|
|||||||
|
|
||||||
h := new(int)
|
h := new(int)
|
||||||
cl := clip.Ellipse(image.Rect(0, 0, 100, 100)).Push(&ops)
|
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()
|
cl.Pop()
|
||||||
var r Router
|
var r Router
|
||||||
r.Frame(&ops)
|
r.Frame(&ops)
|
||||||
@@ -788,15 +788,15 @@ func TestEllipse(t *testing.T) {
|
|||||||
// Outside ellipse.
|
// Outside ellipse.
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Position: f32.Pt(10, 10),
|
Position: f32.Pt(10, 10),
|
||||||
Type: pointer.Press,
|
Kind: pointer.Press,
|
||||||
},
|
},
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Release,
|
Kind: pointer.Release,
|
||||||
},
|
},
|
||||||
// Inside ellipse.
|
// Inside ellipse.
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Position: f32.Pt(50, 50),
|
Position: f32.Pt(50, 50),
|
||||||
Type: pointer.Press,
|
Kind: pointer.Press,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
assertEventPointerTypeSequence(t, r.Events(h), pointer.Cancel, pointer.Press)
|
assertEventPointerTypeSequence(t, r.Events(h), pointer.Cancel, pointer.Press)
|
||||||
@@ -825,7 +825,7 @@ func TestTransfer(t *testing.T) {
|
|||||||
return src, tgt
|
return src, tgt
|
||||||
}
|
}
|
||||||
// Cancel is received when the pointer is first seen.
|
// 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) {
|
t.Run("transfer.Offer should panic on nil Data", func(t *testing.T) {
|
||||||
defer func() {
|
defer func() {
|
||||||
@@ -845,11 +845,11 @@ func TestTransfer(t *testing.T) {
|
|||||||
r.Queue(
|
r.Queue(
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Position: f32.Pt(10, 10),
|
Position: f32.Pt(10, 10),
|
||||||
Type: pointer.Press,
|
Kind: pointer.Press,
|
||||||
},
|
},
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Position: f32.Pt(10, 10),
|
Position: f32.Pt(10, 10),
|
||||||
Type: pointer.Move,
|
Kind: pointer.Move,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
assertEventSequence(t, r.Events(src), cancel)
|
assertEventSequence(t, r.Events(src), cancel)
|
||||||
@@ -859,11 +859,11 @@ func TestTransfer(t *testing.T) {
|
|||||||
r.Queue(
|
r.Queue(
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Position: f32.Pt(30, 10),
|
Position: f32.Pt(30, 10),
|
||||||
Type: pointer.Move,
|
Kind: pointer.Move,
|
||||||
},
|
},
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Position: f32.Pt(30, 10),
|
Position: f32.Pt(30, 10),
|
||||||
Type: pointer.Release,
|
Kind: pointer.Release,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
assertEventSequence(t, r.Events(src), transfer.CancelEvent{})
|
assertEventSequence(t, r.Events(src), transfer.CancelEvent{})
|
||||||
@@ -886,11 +886,11 @@ func TestTransfer(t *testing.T) {
|
|||||||
r.Queue(
|
r.Queue(
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Position: f32.Pt(10, 10),
|
Position: f32.Pt(10, 10),
|
||||||
Type: pointer.Press,
|
Kind: pointer.Press,
|
||||||
},
|
},
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Position: f32.Pt(10, 10),
|
Position: f32.Pt(10, 10),
|
||||||
Type: pointer.Move,
|
Kind: pointer.Move,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
assertEventSequence(t, r.Events(src), cancel)
|
assertEventSequence(t, r.Events(src), cancel)
|
||||||
@@ -907,11 +907,11 @@ func TestTransfer(t *testing.T) {
|
|||||||
r.Queue(
|
r.Queue(
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Position: f32.Pt(10, 10),
|
Position: f32.Pt(10, 10),
|
||||||
Type: pointer.Press,
|
Kind: pointer.Press,
|
||||||
},
|
},
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Position: f32.Pt(10, 10),
|
Position: f32.Pt(10, 10),
|
||||||
Type: pointer.Move,
|
Kind: pointer.Move,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
assertEventSequence(t, r.Events(src), cancel)
|
assertEventSequence(t, r.Events(src), cancel)
|
||||||
@@ -921,7 +921,7 @@ func TestTransfer(t *testing.T) {
|
|||||||
r.Queue(
|
r.Queue(
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Position: f32.Pt(40, 10),
|
Position: f32.Pt(40, 10),
|
||||||
Type: pointer.Release,
|
Kind: pointer.Release,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
assertEventSequence(t, r.Events(src), transfer.CancelEvent{})
|
assertEventSequence(t, r.Events(src), transfer.CancelEvent{})
|
||||||
@@ -944,11 +944,11 @@ func TestTransfer(t *testing.T) {
|
|||||||
r.Queue(
|
r.Queue(
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Position: f32.Pt(10, 10),
|
Position: f32.Pt(10, 10),
|
||||||
Type: pointer.Press,
|
Kind: pointer.Press,
|
||||||
},
|
},
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Position: f32.Pt(10, 10),
|
Position: f32.Pt(10, 10),
|
||||||
Type: pointer.Move,
|
Kind: pointer.Move,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
assertEventSequence(t, r.Events(src), cancel)
|
assertEventSequence(t, r.Events(src), cancel)
|
||||||
@@ -958,7 +958,7 @@ func TestTransfer(t *testing.T) {
|
|||||||
r.Queue(
|
r.Queue(
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Position: f32.Pt(40, 10),
|
Position: f32.Pt(40, 10),
|
||||||
Type: pointer.Release,
|
Kind: pointer.Release,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
assertEventSequence(t, r.Events(src), transfer.RequestEvent{Type: "file"})
|
assertEventSequence(t, r.Events(src), transfer.RequestEvent{Type: "file"})
|
||||||
@@ -1011,15 +1011,15 @@ func TestTransfer(t *testing.T) {
|
|||||||
r.Queue(
|
r.Queue(
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Position: f32.Pt(10, 10),
|
Position: f32.Pt(10, 10),
|
||||||
Type: pointer.Press,
|
Kind: pointer.Press,
|
||||||
},
|
},
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Position: f32.Pt(10, 10),
|
Position: f32.Pt(10, 10),
|
||||||
Type: pointer.Move,
|
Kind: pointer.Move,
|
||||||
},
|
},
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Position: f32.Pt(40, 10),
|
Position: f32.Pt(40, 10),
|
||||||
Type: pointer.Release,
|
Kind: pointer.Release,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
ofr := &offer{data: "hello"}
|
ofr := &offer{data: "hello"}
|
||||||
@@ -1054,15 +1054,15 @@ func TestTransfer(t *testing.T) {
|
|||||||
r.Queue(
|
r.Queue(
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Position: f32.Pt(10, 10),
|
Position: f32.Pt(10, 10),
|
||||||
Type: pointer.Press,
|
Kind: pointer.Press,
|
||||||
},
|
},
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Position: f32.Pt(10, 10),
|
Position: f32.Pt(10, 10),
|
||||||
Type: pointer.Move,
|
Kind: pointer.Move,
|
||||||
},
|
},
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Position: f32.Pt(40, 10),
|
Position: f32.Pt(40, 10),
|
||||||
Type: pointer.Move,
|
Kind: pointer.Move,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
assertEventPointerTypeSequence(t, r.Events(&hover), pointer.Cancel, pointer.Enter)
|
assertEventPointerTypeSequence(t, r.Events(&hover), pointer.Cancel, pointer.Enter)
|
||||||
@@ -1071,7 +1071,7 @@ func TestTransfer(t *testing.T) {
|
|||||||
r.Queue(
|
r.Queue(
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Position: f32.Pt(40, 10),
|
Position: f32.Pt(40, 10),
|
||||||
Type: pointer.Release,
|
Kind: pointer.Release,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -1102,15 +1102,15 @@ func TestTransfer(t *testing.T) {
|
|||||||
r.Queue(
|
r.Queue(
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Position: f32.Pt(10, 10),
|
Position: f32.Pt(10, 10),
|
||||||
Type: pointer.Press,
|
Kind: pointer.Press,
|
||||||
},
|
},
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Position: f32.Pt(10, 10),
|
Position: f32.Pt(10, 10),
|
||||||
Type: pointer.Move,
|
Kind: pointer.Move,
|
||||||
},
|
},
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Position: f32.Pt(40, 10),
|
Position: f32.Pt(40, 10),
|
||||||
Type: pointer.Move,
|
Kind: pointer.Move,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
assertEventPointerTypeSequence(t, r.Events(&hover), pointer.Cancel)
|
assertEventPointerTypeSequence(t, r.Events(&hover), pointer.Cancel)
|
||||||
@@ -1119,7 +1119,7 @@ func TestTransfer(t *testing.T) {
|
|||||||
r.Queue(
|
r.Queue(
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Position: f32.Pt(40, 10),
|
Position: f32.Pt(40, 10),
|
||||||
Type: pointer.Release,
|
Kind: pointer.Release,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -1167,7 +1167,7 @@ func TestPassCursor(t *testing.T) {
|
|||||||
r.Frame(&ops)
|
r.Frame(&ops)
|
||||||
r.Queue(pointer.Event{
|
r.Queue(pointer.Event{
|
||||||
Position: f32.Pt(10, 10),
|
Position: f32.Pt(10, 10),
|
||||||
Type: pointer.Move,
|
Kind: pointer.Move,
|
||||||
})
|
})
|
||||||
if got := r.Cursor(); want != got {
|
if got := r.Cursor(); want != got {
|
||||||
t.Errorf("got cursor %v, want %v", got, want)
|
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()
|
defer clip.Rect(area).Push(ops).Pop()
|
||||||
pointer.InputOp{
|
pointer.InputOp{
|
||||||
Tag: tag,
|
Tag: tag,
|
||||||
Types: pointer.Press | pointer.Release | pointer.Move | pointer.Drag | pointer.Enter | pointer.Leave,
|
Kinds: pointer.Press | pointer.Release | pointer.Move | pointer.Drag | pointer.Enter | pointer.Leave,
|
||||||
}.Add(ops)
|
}.Add(ops)
|
||||||
}
|
}
|
||||||
|
|
||||||
// pointerTypes converts a sequence of event.Event to their pointer.Types. It assumes
|
// 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
|
// that all input events are of underlying type pointer.Event, and thus will
|
||||||
// panic if some are not.
|
// panic if some are not.
|
||||||
func pointerTypes(events []event.Event) []pointer.Type {
|
func pointerTypes(events []event.Event) []pointer.Kind {
|
||||||
var types []pointer.Type
|
var types []pointer.Kind
|
||||||
for _, e := range events {
|
for _, e := range events {
|
||||||
if e, ok := e.(pointer.Event); ok {
|
if e, ok := e.(pointer.Event); ok {
|
||||||
types = append(types, e.Type)
|
types = append(types, e.Kind)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return types
|
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
|
// assertEventPointerTypeSequence checks that the provided events match the expected pointer event types
|
||||||
// in the provided order.
|
// 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()
|
t.Helper()
|
||||||
got := pointerTypes(events)
|
got := pointerTypes(events)
|
||||||
if !reflect.DeepEqual(got, expected) {
|
if !reflect.DeepEqual(got, expected) {
|
||||||
@@ -1239,7 +1239,7 @@ func eventsToString(evs []event.Event) string {
|
|||||||
for _, ev := range evs {
|
for _, ev := range evs {
|
||||||
switch e := ev.(type) {
|
switch e := ev.(type) {
|
||||||
case pointer.Event:
|
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:
|
default:
|
||||||
s = append(s, fmt.Sprintf("{%T}", e))
|
s = append(s, fmt.Sprintf("{%T}", e))
|
||||||
}
|
}
|
||||||
@@ -1308,7 +1308,7 @@ func BenchmarkRouterAdd(b *testing.B) {
|
|||||||
Push(&ops)
|
Push(&ops)
|
||||||
pointer.InputOp{
|
pointer.InputOp{
|
||||||
Tag: handlers[i],
|
Tag: handlers[i],
|
||||||
Types: pointer.Move,
|
Kinds: pointer.Move,
|
||||||
}.Add(&ops)
|
}.Add(&ops)
|
||||||
}
|
}
|
||||||
var r Router
|
var r Router
|
||||||
@@ -1318,7 +1318,7 @@ func BenchmarkRouterAdd(b *testing.B) {
|
|||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
r.Queue(
|
r.Queue(
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Move,
|
Kind: pointer.Move,
|
||||||
Position: f32.Pt(50, 50),
|
Position: f32.Pt(50, 50),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
+4
-4
@@ -273,7 +273,7 @@ func (q *Router) ScrollFocus(dist image.Point) {
|
|||||||
}
|
}
|
||||||
area := q.key.queue.AreaFor(focus)
|
area := q.key.queue.AreaFor(focus)
|
||||||
q.pointer.queue.Deliver(area, pointer.Event{
|
q.pointer.queue.Deliver(area, pointer.Event{
|
||||||
Type: pointer.Scroll,
|
Kind: pointer.Scroll,
|
||||||
Source: pointer.Touch,
|
Source: pointer.Touch,
|
||||||
Scroll: f32internal.FPt(dist),
|
Scroll: f32internal.FPt(dist),
|
||||||
}, &q.handlers)
|
}, &q.handlers)
|
||||||
@@ -317,9 +317,9 @@ func (q *Router) ClickFocus() {
|
|||||||
Source: pointer.Touch,
|
Source: pointer.Touch,
|
||||||
}
|
}
|
||||||
area := q.key.queue.AreaFor(focus)
|
area := q.key.queue.AreaFor(focus)
|
||||||
e.Type = pointer.Press
|
e.Kind = pointer.Press
|
||||||
q.pointer.queue.Deliver(area, e, &q.handlers)
|
q.pointer.queue.Deliver(area, e, &q.handlers)
|
||||||
e.Type = pointer.Release
|
e.Kind = pointer.Release
|
||||||
q.pointer.queue.Deliver(area, e, &q.handlers)
|
q.pointer.queue.Deliver(area, e, &q.handlers)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -438,7 +438,7 @@ func (q *Router) collect() {
|
|||||||
op := pointer.InputOp{
|
op := pointer.InputOp{
|
||||||
Tag: encOp.Refs[0].(event.Tag),
|
Tag: encOp.Refs[0].(event.Tag),
|
||||||
Grab: encOp.Data[1] != 0,
|
Grab: encOp.Data[1] != 0,
|
||||||
Types: pointer.Type(bo.Uint16(encOp.Data[2:])),
|
Kinds: pointer.Kind(bo.Uint16(encOp.Data[2:])),
|
||||||
ScrollBounds: image.Rectangle{
|
ScrollBounds: image.Rectangle{
|
||||||
Min: image.Point{
|
Min: image.Point{
|
||||||
X: int(int32(bo.Uint32(encOp.Data[4:]))),
|
X: int(int32(bo.Uint32(encOp.Data[4:]))),
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ func TestSemanticTree(t *testing.T) {
|
|||||||
|
|
||||||
func TestSemanticDescription(t *testing.T) {
|
func TestSemanticDescription(t *testing.T) {
|
||||||
var ops op.Ops
|
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.DescriptionOp("description").Add(&ops)
|
||||||
semantic.LabelOp("label").Add(&ops)
|
semantic.LabelOp("label").Add(&ops)
|
||||||
semantic.Button.Add(&ops)
|
semantic.Button.Add(&ops)
|
||||||
|
|||||||
+9
-9
@@ -93,18 +93,18 @@ func TestListPosition(t *testing.T) {
|
|||||||
pointer.Event{
|
pointer.Event{
|
||||||
Source: pointer.Mouse,
|
Source: pointer.Mouse,
|
||||||
Buttons: pointer.ButtonPrimary,
|
Buttons: pointer.ButtonPrimary,
|
||||||
Type: pointer.Press,
|
Kind: pointer.Press,
|
||||||
Position: f32.Pt(0, 0),
|
Position: f32.Pt(0, 0),
|
||||||
},
|
},
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Source: pointer.Mouse,
|
Source: pointer.Mouse,
|
||||||
Type: pointer.Scroll,
|
Kind: pointer.Scroll,
|
||||||
Scroll: f32.Pt(5, 0),
|
Scroll: f32.Pt(5, 0),
|
||||||
},
|
},
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Source: pointer.Mouse,
|
Source: pointer.Mouse,
|
||||||
Buttons: pointer.ButtonPrimary,
|
Buttons: pointer.ButtonPrimary,
|
||||||
Type: pointer.Release,
|
Kind: pointer.Release,
|
||||||
Position: f32.Pt(5, 0),
|
Position: f32.Pt(5, 0),
|
||||||
},
|
},
|
||||||
)},
|
)},
|
||||||
@@ -113,18 +113,18 @@ func TestListPosition(t *testing.T) {
|
|||||||
pointer.Event{
|
pointer.Event{
|
||||||
Source: pointer.Mouse,
|
Source: pointer.Mouse,
|
||||||
Buttons: pointer.ButtonPrimary,
|
Buttons: pointer.ButtonPrimary,
|
||||||
Type: pointer.Press,
|
Kind: pointer.Press,
|
||||||
Position: f32.Pt(0, 0),
|
Position: f32.Pt(0, 0),
|
||||||
},
|
},
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Source: pointer.Mouse,
|
Source: pointer.Mouse,
|
||||||
Type: pointer.Scroll,
|
Kind: pointer.Scroll,
|
||||||
Scroll: f32.Pt(3, 0),
|
Scroll: f32.Pt(3, 0),
|
||||||
},
|
},
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Source: pointer.Mouse,
|
Source: pointer.Mouse,
|
||||||
Buttons: pointer.ButtonPrimary,
|
Buttons: pointer.ButtonPrimary,
|
||||||
Type: pointer.Release,
|
Kind: pointer.Release,
|
||||||
Position: f32.Pt(5, 0),
|
Position: f32.Pt(5, 0),
|
||||||
},
|
},
|
||||||
)},
|
)},
|
||||||
@@ -133,18 +133,18 @@ func TestListPosition(t *testing.T) {
|
|||||||
pointer.Event{
|
pointer.Event{
|
||||||
Source: pointer.Mouse,
|
Source: pointer.Mouse,
|
||||||
Buttons: pointer.ButtonPrimary,
|
Buttons: pointer.ButtonPrimary,
|
||||||
Type: pointer.Press,
|
Kind: pointer.Press,
|
||||||
Position: f32.Pt(0, 0),
|
Position: f32.Pt(0, 0),
|
||||||
},
|
},
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Source: pointer.Mouse,
|
Source: pointer.Mouse,
|
||||||
Type: pointer.Scroll,
|
Kind: pointer.Scroll,
|
||||||
Scroll: f32.Pt(10, 0),
|
Scroll: f32.Pt(10, 0),
|
||||||
},
|
},
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Source: pointer.Mouse,
|
Source: pointer.Mouse,
|
||||||
Buttons: pointer.ButtonPrimary,
|
Buttons: pointer.ButtonPrimary,
|
||||||
Type: pointer.Release,
|
Kind: pointer.Release,
|
||||||
Position: f32.Pt(15, 0),
|
Position: f32.Pt(15, 0),
|
||||||
},
|
},
|
||||||
)},
|
)},
|
||||||
|
|||||||
+1
-1
@@ -31,7 +31,7 @@ func (d *Draggable) Layout(gtx layout.Context, w, drag layout.Widget) layout.Dim
|
|||||||
}
|
}
|
||||||
pos := d.pos
|
pos := d.pos
|
||||||
for _, ev := range d.drag.Events(gtx.Metric, gtx.Queue, gesture.Both) {
|
for _, ev := range d.drag.Events(gtx.Metric, gtx.Queue, gesture.Both) {
|
||||||
switch ev.Type {
|
switch ev.Kind {
|
||||||
case pointer.Press:
|
case pointer.Press:
|
||||||
d.click = ev.Position
|
d.click = ev.Position
|
||||||
pos = f32.Point{}
|
pos = f32.Point{}
|
||||||
|
|||||||
+3
-3
@@ -39,15 +39,15 @@ func TestDraggable(t *testing.T) {
|
|||||||
r.Queue(
|
r.Queue(
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Position: f32.Pt(10, 10),
|
Position: f32.Pt(10, 10),
|
||||||
Type: pointer.Press,
|
Kind: pointer.Press,
|
||||||
},
|
},
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Position: f32.Pt(20, 10),
|
Position: f32.Pt(20, 10),
|
||||||
Type: pointer.Move,
|
Kind: pointer.Move,
|
||||||
},
|
},
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Position: f32.Pt(20, 10),
|
Position: f32.Pt(20, 10),
|
||||||
Type: pointer.Release,
|
Kind: pointer.Release,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
ofr := &offer{data: "hello"}
|
ofr := &offer{data: "hello"}
|
||||||
|
|||||||
+2
-2
@@ -278,10 +278,10 @@ func (e *Editor) processPointer(gtx layout.Context) {
|
|||||||
case pointer.Event:
|
case pointer.Event:
|
||||||
release := false
|
release := false
|
||||||
switch {
|
switch {
|
||||||
case evt.Type == pointer.Release && evt.Source == pointer.Mouse:
|
case evt.Kind == pointer.Release && evt.Source == pointer.Mouse:
|
||||||
release = true
|
release = true
|
||||||
fallthrough
|
fallthrough
|
||||||
case evt.Type == pointer.Drag && evt.Source == pointer.Mouse:
|
case evt.Kind == pointer.Drag && evt.Source == pointer.Mouse:
|
||||||
if e.dragging {
|
if e.dragging {
|
||||||
e.blinkStart = gtx.Now
|
e.blinkStart = gtx.Now
|
||||||
e.text.MoveCoord(image.Point{
|
e.text.MoveCoord(image.Point{
|
||||||
|
|||||||
@@ -159,17 +159,17 @@ func TestEditorReadOnly(t *testing.T) {
|
|||||||
gtx.Ops.Reset()
|
gtx.Ops.Reset()
|
||||||
gtx.Queue = &testQueue{events: []event.Event{
|
gtx.Queue = &testQueue{events: []event.Event{
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Press,
|
Kind: pointer.Press,
|
||||||
Buttons: pointer.ButtonPrimary,
|
Buttons: pointer.ButtonPrimary,
|
||||||
Position: f32.Pt(float32(dims.Size.X)*.5, 5),
|
Position: f32.Pt(float32(dims.Size.X)*.5, 5),
|
||||||
},
|
},
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Drag,
|
Kind: pointer.Drag,
|
||||||
Buttons: pointer.ButtonPrimary,
|
Buttons: pointer.ButtonPrimary,
|
||||||
Position: layout.FPt(dims.Size).Mul(.5),
|
Position: layout.FPt(dims.Size).Mul(.5),
|
||||||
},
|
},
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Release,
|
Kind: pointer.Release,
|
||||||
Buttons: pointer.ButtonPrimary,
|
Buttons: pointer.ButtonPrimary,
|
||||||
Position: layout.FPt(dims.Size).Mul(.5),
|
Position: layout.FPt(dims.Size).Mul(.5),
|
||||||
},
|
},
|
||||||
@@ -947,13 +947,13 @@ g 2 4 6 8 g
|
|||||||
events: []event.Event{
|
events: []event.Event{
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Buttons: pointer.ButtonPrimary,
|
Buttons: pointer.ButtonPrimary,
|
||||||
Type: pointer.Press,
|
Kind: pointer.Press,
|
||||||
Source: pointer.Mouse,
|
Source: pointer.Mouse,
|
||||||
Time: tim,
|
Time: tim,
|
||||||
Position: f32.Pt(textWidth(e, startPos.lineCol.line, 0, startPos.lineCol.col), textBaseline(e, startPos.lineCol.line)),
|
Position: f32.Pt(textWidth(e, startPos.lineCol.line, 0, startPos.lineCol.col), textBaseline(e, startPos.lineCol.line)),
|
||||||
},
|
},
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Release,
|
Kind: pointer.Release,
|
||||||
Source: pointer.Mouse,
|
Source: pointer.Mouse,
|
||||||
Time: tim,
|
Time: tim,
|
||||||
Position: f32.Pt(textWidth(e, endPos.lineCol.line, 0, endPos.lineCol.col), textBaseline(e, endPos.lineCol.line)),
|
Position: f32.Pt(textWidth(e, endPos.lineCol.line, 0, endPos.lineCol.col), textBaseline(e, endPos.lineCol.line)),
|
||||||
|
|||||||
@@ -47,13 +47,13 @@ func ExampleClickable_passthrough() {
|
|||||||
pointer.Event{
|
pointer.Event{
|
||||||
Source: pointer.Mouse,
|
Source: pointer.Mouse,
|
||||||
Buttons: pointer.ButtonPrimary,
|
Buttons: pointer.ButtonPrimary,
|
||||||
Type: pointer.Press,
|
Kind: pointer.Press,
|
||||||
Position: f32.Pt(50, 50),
|
Position: f32.Pt(50, 50),
|
||||||
},
|
},
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Source: pointer.Mouse,
|
Source: pointer.Mouse,
|
||||||
Buttons: pointer.ButtonPrimary,
|
Buttons: pointer.ButtonPrimary,
|
||||||
Type: pointer.Release,
|
Kind: pointer.Release,
|
||||||
Position: f32.Pt(50, 50),
|
Position: f32.Pt(50, 50),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@@ -125,15 +125,15 @@ func ExampleDraggable_Layout() {
|
|||||||
// Send drag and drop gesture events.
|
// Send drag and drop gesture events.
|
||||||
r.Queue(
|
r.Queue(
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Press,
|
Kind: pointer.Press,
|
||||||
Position: f32.Pt(5, 5), // in the drag area
|
Position: f32.Pt(5, 5), // in the drag area
|
||||||
},
|
},
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Move,
|
Kind: pointer.Move,
|
||||||
Position: f32.Pt(5, 5), // in the drop area
|
Position: f32.Pt(5, 5), // in the drop area
|
||||||
},
|
},
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Release,
|
Kind: pointer.Release,
|
||||||
Position: f32.Pt(30, 30), // in the drop area
|
Position: f32.Pt(30, 30), // in the drop area
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
+1
-1
@@ -33,7 +33,7 @@ func (f *Float) Layout(gtx layout.Context, axis layout.Axis, min, max float32, i
|
|||||||
|
|
||||||
var de *pointer.Event
|
var de *pointer.Event
|
||||||
for _, e := range f.drag.Events(gtx.Metric, gtx, gesture.Axis(axis)) {
|
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
|
de = &e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -81,7 +81,7 @@ func (s *Scrollbar) Layout(gtx layout.Context, axis layout.Axis, viewportStart,
|
|||||||
|
|
||||||
// Offset to account for any drags.
|
// Offset to account for any drags.
|
||||||
for _, event := range s.drag.Events(gtx.Metric, gtx, gesture.Axis(axis)) {
|
for _, event := range s.drag.Events(gtx.Metric, gtx, gesture.Axis(axis)) {
|
||||||
switch event.Type {
|
switch event.Kind {
|
||||||
case pointer.Drag:
|
case pointer.Drag:
|
||||||
case pointer.Release, pointer.Cancel:
|
case pointer.Release, pointer.Cancel:
|
||||||
s.dragging = false
|
s.dragging = false
|
||||||
|
|||||||
@@ -271,10 +271,10 @@ func (e *Selectable) processPointer(gtx layout.Context) {
|
|||||||
case pointer.Event:
|
case pointer.Event:
|
||||||
release := false
|
release := false
|
||||||
switch {
|
switch {
|
||||||
case evt.Type == pointer.Release && evt.Source == pointer.Mouse:
|
case evt.Kind == pointer.Release && evt.Source == pointer.Mouse:
|
||||||
release = true
|
release = true
|
||||||
fallthrough
|
fallthrough
|
||||||
case evt.Type == pointer.Drag && evt.Source == pointer.Mouse:
|
case evt.Kind == pointer.Drag && evt.Source == pointer.Mouse:
|
||||||
if e.dragging {
|
if e.dragging {
|
||||||
e.text.MoveCoord(image.Point{
|
e.text.MoveCoord(image.Point{
|
||||||
X: int(math.Round(float64(evt.Position.X))),
|
X: int(math.Round(float64(evt.Position.X))),
|
||||||
|
|||||||
@@ -35,12 +35,12 @@ func TestBool(t *testing.T) {
|
|||||||
r.Queue(
|
r.Queue(
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Source: pointer.Touch,
|
Source: pointer.Touch,
|
||||||
Type: pointer.Press,
|
Kind: pointer.Press,
|
||||||
Position: f32.Pt(50, 50),
|
Position: f32.Pt(50, 50),
|
||||||
},
|
},
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Source: pointer.Touch,
|
Source: pointer.Touch,
|
||||||
Type: pointer.Release,
|
Kind: pointer.Release,
|
||||||
Position: f32.Pt(50, 50),
|
Position: f32.Pt(50, 50),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user