Skip to content

Commit 650ccea

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 <mail@eliasnaur.com>
1 parent e1b3928 commit 650ccea

26 files changed

+226
-226
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: kind,
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: 11 additions & 11 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

@@ -920,21 +920,21 @@ func gio_onPointerButton(data unsafe.Pointer, p *C.struct_wl_pointer, serial, t,
920920
}
921921
}
922922
}
923-
var typ pointer.Type
923+
var kind pointer.Kind
924924
switch state {
925925
case 0:
926926
w.pointerBtns &^= btn
927-
typ = pointer.Release
927+
kind = pointer.Release
928928
// Move or resize gestures no longer applies.
929929
w.inCompositor = false
930930
case 1:
931931
w.pointerBtns |= btn
932-
typ = pointer.Press
932+
kind = pointer.Press
933933
}
934934
w.flushScroll()
935935
w.resetFling()
936936
w.w.Event(pointer.Event{
937-
Type: typ,
937+
Kind: kind,
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: 7 additions & 7 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),
@@ -557,7 +557,7 @@ func (h *x11EventHandler) handleEvents() bool {
557557
Modifiers: w.xkb.Modifiers(),
558558
}
559559
if bevt._type == C.ButtonRelease {
560-
ev.Type = pointer.Release
560+
ev.Kind = pointer.Release
561561
}
562562
var btn pointer.Buttons
563563
const scrollScale = 10
@@ -569,7 +569,7 @@ func (h *x11EventHandler) handleEvents() bool {
569569
case C.Button3:
570570
btn = pointer.ButtonSecondary
571571
case C.Button4:
572-
ev.Type = pointer.Scroll
572+
ev.Kind = pointer.Scroll
573573
// scroll up or left (if shift is pressed).
574574
if ev.Modifiers == key.ModShift {
575575
ev.Scroll.X = -scrollScale
@@ -578,7 +578,7 @@ func (h *x11EventHandler) handleEvents() bool {
578578
}
579579
case C.Button5:
580580
// scroll down or right (if shift is pressed).
581-
ev.Type = pointer.Scroll
581+
ev.Kind = pointer.Scroll
582582
if ev.Modifiers == key.ModShift {
583583
ev.Scroll.X = +scrollScale
584584
} else {
@@ -587,11 +587,11 @@ func (h *x11EventHandler) handleEvents() bool {
587587
case 6:
588588
// http://xahlee.info/linux/linux_x11_mouse_button_number.html
589589
// scroll left.
590-
ev.Type = pointer.Scroll
590+
ev.Kind = pointer.Scroll
591591
ev.Scroll.X = -scrollScale * 2
592592
case 7:
593593
// scroll right
594-
ev.Type = pointer.Scroll
594+
ev.Kind = pointer.Scroll
595595
ev.Scroll.X = +scrollScale * 2
596596
default:
597597
continue
@@ -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{

0 commit comments

Comments
 (0)