Skip to content

Commit 9cb0cc5

Browse files
committed
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 <[email protected]>
1 parent e1b3928 commit 9cb0cc5

26 files changed

+218
-218
lines changed

app/os_android.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -953,18 +953,18 @@ func Java_org_gioui_GioView_onKeyEvent(env *C.JNIEnv, class C.jclass, handle C.j
953953
//export Java_org_gioui_GioView_onTouchEvent
954954
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) {
955955
w := cgo.Handle(handle).Value().(*window)
956-
var typ pointer.Type
956+
var kind pointer.Kind
957957
switch action {
958958
case C.AMOTION_EVENT_ACTION_DOWN, C.AMOTION_EVENT_ACTION_POINTER_DOWN:
959-
typ = pointer.Press
959+
kind = pointer.Press
960960
case C.AMOTION_EVENT_ACTION_UP, C.AMOTION_EVENT_ACTION_POINTER_UP:
961-
typ = pointer.Release
961+
kind = pointer.Release
962962
case C.AMOTION_EVENT_ACTION_CANCEL:
963-
typ = pointer.Cancel
963+
kind = pointer.Cancel
964964
case C.AMOTION_EVENT_ACTION_MOVE:
965-
typ = pointer.Move
965+
kind = pointer.Move
966966
case C.AMOTION_EVENT_ACTION_SCROLL:
967-
typ = pointer.Scroll
967+
kind = pointer.Scroll
968968
default:
969969
return
970970
}
@@ -994,7 +994,7 @@ func Java_org_gioui_GioView_onTouchEvent(env *C.JNIEnv, class C.jclass, handle C
994994
return
995995
}
996996
w.callbacks.Event(pointer.Event{
997-
Type: typ,
997+
Kind: kind,
998998
Source: src,
999999
Buttons: btns,
10001000
PointerID: pointer.ID(pointerID),

app/os_ios.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -236,24 +236,24 @@ func onText(view, str C.CFTypeRef) {
236236

237237
//export onTouch
238238
func onTouch(last C.int, view, touchRef C.CFTypeRef, phase C.NSInteger, x, y C.CGFloat, ti C.double) {
239-
var typ pointer.Type
239+
var kind pointer.Kind
240240
switch phase {
241241
case C.UITouchPhaseBegan:
242-
typ = pointer.Press
242+
kind = pointer.Press
243243
case C.UITouchPhaseMoved:
244-
typ = pointer.Move
244+
kind = pointer.Move
245245
case C.UITouchPhaseEnded:
246-
typ = pointer.Release
246+
kind = pointer.Release
247247
case C.UITouchPhaseCancelled:
248-
typ = pointer.Cancel
248+
kind = pointer.Cancel
249249
default:
250250
return
251251
}
252252
w := views[view]
253253
t := time.Duration(float64(ti) * float64(time.Second))
254254
p := f32.Point{X: float32(x), Y: float32(y)}
255255
w.w.Event(pointer.Event{
256-
Type: typ,
256+
Kind: typ,
257257
Source: pointer.Touch,
258258
PointerID: w.lookupTouch(last != 0, touchRef),
259259
Position: p,

app/os_js.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ func (w *window) addEventListeners() {
275275
}
276276
w.touches = w.touches[:0]
277277
w.w.Event(pointer.Event{
278-
Type: pointer.Cancel,
278+
Kind: pointer.Cancel,
279279
Source: pointer.Touch,
280280
})
281281
return nil
@@ -398,7 +398,7 @@ func modifiersFor(e js.Value) key.Modifiers {
398398
return mods
399399
}
400400

401-
func (w *window) touchEvent(typ pointer.Type, e js.Value) {
401+
func (w *window) touchEvent(kind pointer.Kind, e js.Value) {
402402
e.Call("preventDefault")
403403
t := time.Duration(e.Get("timeStamp").Int()) * time.Millisecond
404404
changedTouches := e.Get("changedTouches")
@@ -426,7 +426,7 @@ func (w *window) touchEvent(typ pointer.Type, e js.Value) {
426426
Y: float32(y) * scale,
427427
}
428428
w.w.Event(pointer.Event{
429-
Type: typ,
429+
Kind: kind,
430430
Source: pointer.Touch,
431431
Position: pos,
432432
PointerID: pid,
@@ -448,7 +448,7 @@ func (w *window) touchIDFor(touch js.Value) pointer.ID {
448448
return pid
449449
}
450450

451-
func (w *window) pointerEvent(typ pointer.Type, dx, dy float32, e js.Value) {
451+
func (w *window) pointerEvent(kind pointer.Kind, dx, dy float32, e js.Value) {
452452
e.Call("preventDefault")
453453
x, y := e.Get("clientX").Float(), e.Get("clientY").Float()
454454
rect := w.cnv.Call("getBoundingClientRect")
@@ -476,7 +476,7 @@ func (w *window) pointerEvent(typ pointer.Type, dx, dy float32, e js.Value) {
476476
btns |= pointer.ButtonTertiary
477477
}
478478
w.w.Event(pointer.Event{
479-
Type: typ,
479+
Kind: kind,
480480
Source: pointer.Mouse,
481481
Buttons: btns,
482482
Position: pos,

app/os_macos.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ func gio_onMouse(view, evt C.CFTypeRef, cdir C.int, cbtn C.NSInteger, x, y, dx,
526526
case 2:
527527
btn = pointer.ButtonTertiary
528528
}
529-
var typ pointer.Type
529+
var typ pointer.Kind
530530
switch cdir {
531531
case C.MOUSE_MOVE:
532532
typ = pointer.Move
@@ -550,7 +550,7 @@ func gio_onMouse(view, evt C.CFTypeRef, cdir C.int, cbtn C.NSInteger, x, y, dx,
550550
panic("invalid direction")
551551
}
552552
w.w.Event(pointer.Event{
553-
Type: typ,
553+
Kind: typ,
554554
Source: pointer.Mouse,
555555
Time: t,
556556
Buttons: w.pointerBtns,

app/os_wayland.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ func gio_onTouchDown(data unsafe.Pointer, touch *C.struct_wl_touch, serial, t C.
794794
Y: fromFixed(y) * float32(w.scale),
795795
}
796796
w.w.Event(pointer.Event{
797-
Type: pointer.Press,
797+
Kind: pointer.Press,
798798
Source: pointer.Touch,
799799
Position: w.lastTouch,
800800
PointerID: pointer.ID(id),
@@ -810,7 +810,7 @@ func gio_onTouchUp(data unsafe.Pointer, touch *C.struct_wl_touch, serial, t C.ui
810810
w := s.touchFoci[id]
811811
delete(s.touchFoci, id)
812812
w.w.Event(pointer.Event{
813-
Type: pointer.Release,
813+
Kind: pointer.Release,
814814
Source: pointer.Touch,
815815
Position: w.lastTouch,
816816
PointerID: pointer.ID(id),
@@ -828,7 +828,7 @@ func gio_onTouchMotion(data unsafe.Pointer, touch *C.struct_wl_touch, t C.uint32
828828
Y: fromFixed(y) * float32(w.scale),
829829
}
830830
w.w.Event(pointer.Event{
831-
Type: pointer.Move,
831+
Kind: pointer.Move,
832832
Position: w.lastTouch,
833833
Source: pointer.Touch,
834834
PointerID: pointer.ID(id),
@@ -847,7 +847,7 @@ func gio_onTouchCancel(data unsafe.Pointer, touch *C.struct_wl_touch) {
847847
for id, w := range s.touchFoci {
848848
delete(s.touchFoci, id)
849849
w.w.Event(pointer.Event{
850-
Type: pointer.Cancel,
850+
Kind: pointer.Cancel,
851851
Source: pointer.Touch,
852852
})
853853
}
@@ -872,7 +872,7 @@ func gio_onPointerLeave(data unsafe.Pointer, p *C.struct_wl_pointer, serial C.ui
872872
s.serial = serial
873873
if w.inCompositor {
874874
w.inCompositor = false
875-
w.w.Event(pointer.Event{Type: pointer.Cancel})
875+
w.w.Event(pointer.Event{Kind: pointer.Cancel})
876876
}
877877
}
878878

@@ -934,7 +934,7 @@ func gio_onPointerButton(data unsafe.Pointer, p *C.struct_wl_pointer, serial, t,
934934
w.flushScroll()
935935
w.resetFling()
936936
w.w.Event(pointer.Event{
937-
Type: typ,
937+
Kind: typ,
938938
Source: pointer.Mouse,
939939
Buttons: w.pointerBtns,
940940
Position: w.lastPos,
@@ -1581,7 +1581,7 @@ func (w *window) flushScroll() {
15811581
return
15821582
}
15831583
w.w.Event(pointer.Event{
1584-
Type: pointer.Scroll,
1584+
Kind: pointer.Scroll,
15851585
Source: pointer.Mouse,
15861586
Buttons: w.pointerBtns,
15871587
Position: w.lastPos,
@@ -1604,7 +1604,7 @@ func (w *window) onPointerMotion(x, y C.wl_fixed_t, t C.uint32_t) {
16041604
Y: fromFixed(y) * float32(w.scale),
16051605
}
16061606
w.w.Event(pointer.Event{
1607-
Type: pointer.Move,
1607+
Kind: pointer.Move,
16081608
Position: w.lastPos,
16091609
Buttons: w.pointerBtns,
16101610
Source: pointer.Mouse,

app/os_windows.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ func windowProc(hwnd syscall.Handle, msg uint32, wParam, lParam uintptr) uintptr
259259
w.pointerButton(pointer.ButtonTertiary, false, lParam, getModifiers())
260260
case windows.WM_CANCELMODE:
261261
w.w.Event(pointer.Event{
262-
Type: pointer.Cancel,
262+
Kind: pointer.Cancel,
263263
})
264264
case windows.WM_SETFOCUS:
265265
w.focused = true
@@ -288,7 +288,7 @@ func windowProc(hwnd syscall.Handle, msg uint32, wParam, lParam uintptr) uintptr
288288
x, y := coordsFromlParam(lParam)
289289
p := f32.Point{X: float32(x), Y: float32(y)}
290290
w.w.Event(pointer.Event{
291-
Type: pointer.Move,
291+
Kind: pointer.Move,
292292
Source: pointer.Mouse,
293293
Position: p,
294294
Buttons: w.pointerBtns,
@@ -501,15 +501,15 @@ func (w *window) pointerButton(btn pointer.Buttons, press bool, lParam uintptr,
501501
windows.SetFocus(w.hwnd)
502502
}
503503

504-
var typ pointer.Type
504+
var kind pointer.Kind
505505
if press {
506-
typ = pointer.Press
506+
kind = pointer.Press
507507
if w.pointerBtns == 0 {
508508
windows.SetCapture(w.hwnd)
509509
}
510510
w.pointerBtns |= btn
511511
} else {
512-
typ = pointer.Release
512+
kind = pointer.Release
513513
w.pointerBtns &^= btn
514514
if w.pointerBtns == 0 {
515515
windows.ReleaseCapture()
@@ -518,7 +518,7 @@ func (w *window) pointerButton(btn pointer.Buttons, press bool, lParam uintptr,
518518
x, y := coordsFromlParam(lParam)
519519
p := f32.Point{X: float32(x), Y: float32(y)}
520520
w.w.Event(pointer.Event{
521-
Type: typ,
521+
Kind: kind,
522522
Source: pointer.Mouse,
523523
Position: p,
524524
Buttons: w.pointerBtns,
@@ -553,7 +553,7 @@ func (w *window) scrollEvent(wParam, lParam uintptr, horizontal bool, kmods key.
553553
}
554554
}
555555
w.w.Event(pointer.Event{
556-
Type: pointer.Scroll,
556+
Kind: pointer.Scroll,
557557
Source: pointer.Mouse,
558558
Position: p,
559559
Buttons: w.pointerBtns,

app/os_x11.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ func (h *x11EventHandler) handleEvents() bool {
547547
case C.ButtonPress, C.ButtonRelease:
548548
bevt := (*C.XButtonEvent)(unsafe.Pointer(xev))
549549
ev := pointer.Event{
550-
Type: pointer.Press,
550+
Kind: pointer.Press,
551551
Source: pointer.Mouse,
552552
Position: f32.Point{
553553
X: float32(bevt.x),
@@ -607,7 +607,7 @@ func (h *x11EventHandler) handleEvents() bool {
607607
case C.MotionNotify:
608608
mevt := (*C.XMotionEvent)(unsafe.Pointer(xev))
609609
w.w.Event(pointer.Event{
610-
Type: pointer.Move,
610+
Kind: pointer.Move,
611611
Source: pointer.Mouse,
612612
Buttons: w.pointerBtns,
613613
Position: f32.Point{

gesture/gesture.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type Hover struct {
3939
func (h *Hover) Add(ops *op.Ops) {
4040
pointer.InputOp{
4141
Tag: h,
42-
Types: pointer.Enter | pointer.Leave,
42+
Kinds: pointer.Enter | pointer.Leave,
4343
}.Add(ops)
4444
}
4545

@@ -50,7 +50,7 @@ func (h *Hover) Hovered(q event.Queue) bool {
5050
if !ok {
5151
continue
5252
}
53-
switch e.Type {
53+
switch e.Kind {
5454
case pointer.Leave, pointer.Cancel:
5555
if h.entered && h.pid == e.PointerID {
5656
h.entered = false
@@ -163,7 +163,7 @@ const touchSlop = unit.Dp(3)
163163
func (c *Click) Add(ops *op.Ops) {
164164
pointer.InputOp{
165165
Tag: c,
166-
Types: pointer.Press | pointer.Release | pointer.Enter | pointer.Leave,
166+
Kinds: pointer.Press | pointer.Release | pointer.Enter | pointer.Leave,
167167
}.Add(ops)
168168
}
169169

@@ -185,7 +185,7 @@ func (c *Click) Events(q event.Queue) []ClickEvent {
185185
if !ok {
186186
continue
187187
}
188-
switch e.Type {
188+
switch e.Kind {
189189
case pointer.Release:
190190
if !c.pressed || c.pid != e.PointerID {
191191
break
@@ -254,7 +254,7 @@ func (s *Scroll) Add(ops *op.Ops, bounds image.Rectangle) {
254254
oph := pointer.InputOp{
255255
Tag: s,
256256
Grab: s.grab,
257-
Types: pointer.Press | pointer.Drag | pointer.Release | pointer.Scroll,
257+
Kinds: pointer.Press | pointer.Drag | pointer.Release | pointer.Scroll,
258258
ScrollBounds: bounds,
259259
}
260260
oph.Add(ops)
@@ -281,7 +281,7 @@ func (s *Scroll) Scroll(cfg unit.Metric, q event.Queue, t time.Time, axis Axis)
281281
if !ok {
282282
continue
283283
}
284-
switch e.Type {
284+
switch e.Kind {
285285
case pointer.Press:
286286
if s.dragging {
287287
break
@@ -368,7 +368,7 @@ func (d *Drag) Add(ops *op.Ops) {
368368
pointer.InputOp{
369369
Tag: d,
370370
Grab: d.grab,
371-
Types: pointer.Press | pointer.Drag | pointer.Release,
371+
Kinds: pointer.Press | pointer.Drag | pointer.Release,
372372
}.Add(ops)
373373
}
374374

@@ -381,7 +381,7 @@ func (d *Drag) Events(cfg unit.Metric, q event.Queue, axis Axis) []pointer.Event
381381
continue
382382
}
383383

384-
switch e.Type {
384+
switch e.Kind {
385385
case pointer.Press:
386386
if !(e.Buttons == pointer.ButtonPrimary || e.Source == pointer.Touch) {
387387
continue

gesture/gesture_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ func TestHover(t *testing.T) {
2626
r.Frame(ops)
2727

2828
r.Queue(
29-
pointer.Event{Type: pointer.Move, Position: f32.Pt(30, 30)},
29+
pointer.Event{Kind: pointer.Move, Position: f32.Pt(30, 30)},
3030
)
3131
if !h.Hovered(r) {
3232
t.Fatal("expected hovered")
3333
}
3434

3535
r.Queue(
36-
pointer.Event{Type: pointer.Move, Position: f32.Pt(50, 50)},
36+
pointer.Event{Kind: pointer.Move, Position: f32.Pt(50, 50)},
3737
)
3838
if h.Hovered(r) {
3939
t.Fatal("expected not hovered")
@@ -92,7 +92,7 @@ func TestMouseClicks(t *testing.T) {
9292

9393
func mouseClickEvents(times ...time.Duration) []event.Event {
9494
press := pointer.Event{
95-
Type: pointer.Press,
95+
Kind: pointer.Press,
9696
Source: pointer.Mouse,
9797
Buttons: pointer.ButtonPrimary,
9898
}
@@ -101,7 +101,7 @@ func mouseClickEvents(times ...time.Duration) []event.Event {
101101
press := press
102102
press.Time = t
103103
release := press
104-
release.Type = pointer.Release
104+
release.Kind = pointer.Release
105105
events = append(events, press, release)
106106
}
107107
return events

0 commit comments

Comments
 (0)