Skip to content

Commit

Permalink
io/pointer: [API] rename PointerEvent.Type to Kind
Browse files Browse the repository at this point in the history
Kind is the idiomatic field name for distinguishing a struct without
using separate types.

Signed-off-by: Elias Naur <[email protected]>
  • Loading branch information
eliasnaur committed Oct 6, 2023
1 parent e1b3928 commit 9cb0cc5
Show file tree
Hide file tree
Showing 26 changed files with 218 additions and 218 deletions.
14 changes: 7 additions & 7 deletions app/os_android.go
Original file line number Diff line number Diff line change
Expand Up @@ -953,18 +953,18 @@ func Java_org_gioui_GioView_onKeyEvent(env *C.JNIEnv, class C.jclass, handle C.j
//export Java_org_gioui_GioView_onTouchEvent
func Java_org_gioui_GioView_onTouchEvent(env *C.JNIEnv, class C.jclass, handle C.jlong, action, pointerID, tool C.jint, x, y, scrollX, scrollY C.jfloat, jbtns C.jint, t C.jlong) {
w := cgo.Handle(handle).Value().(*window)
var typ pointer.Type
var kind pointer.Kind
switch action {
case C.AMOTION_EVENT_ACTION_DOWN, C.AMOTION_EVENT_ACTION_POINTER_DOWN:
typ = pointer.Press
kind = pointer.Press
case C.AMOTION_EVENT_ACTION_UP, C.AMOTION_EVENT_ACTION_POINTER_UP:
typ = pointer.Release
kind = pointer.Release
case C.AMOTION_EVENT_ACTION_CANCEL:
typ = pointer.Cancel
kind = pointer.Cancel
case C.AMOTION_EVENT_ACTION_MOVE:
typ = pointer.Move
kind = pointer.Move
case C.AMOTION_EVENT_ACTION_SCROLL:
typ = pointer.Scroll
kind = pointer.Scroll
default:
return
}
Expand Down Expand Up @@ -994,7 +994,7 @@ func Java_org_gioui_GioView_onTouchEvent(env *C.JNIEnv, class C.jclass, handle C
return
}
w.callbacks.Event(pointer.Event{
Type: typ,
Kind: kind,
Source: src,
Buttons: btns,
PointerID: pointer.ID(pointerID),
Expand Down
12 changes: 6 additions & 6 deletions app/os_ios.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,24 +236,24 @@ func onText(view, str C.CFTypeRef) {

//export onTouch
func onTouch(last C.int, view, touchRef C.CFTypeRef, phase C.NSInteger, x, y C.CGFloat, ti C.double) {
var typ pointer.Type
var kind pointer.Kind
switch phase {
case C.UITouchPhaseBegan:
typ = pointer.Press
kind = pointer.Press
case C.UITouchPhaseMoved:
typ = pointer.Move
kind = pointer.Move
case C.UITouchPhaseEnded:
typ = pointer.Release
kind = pointer.Release
case C.UITouchPhaseCancelled:
typ = pointer.Cancel
kind = pointer.Cancel
default:
return
}
w := views[view]
t := time.Duration(float64(ti) * float64(time.Second))
p := f32.Point{X: float32(x), Y: float32(y)}
w.w.Event(pointer.Event{
Type: typ,
Kind: typ,
Source: pointer.Touch,
PointerID: w.lookupTouch(last != 0, touchRef),
Position: p,
Expand Down
10 changes: 5 additions & 5 deletions app/os_js.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func (w *window) addEventListeners() {
}
w.touches = w.touches[:0]
w.w.Event(pointer.Event{
Type: pointer.Cancel,
Kind: pointer.Cancel,
Source: pointer.Touch,
})
return nil
Expand Down Expand Up @@ -398,7 +398,7 @@ func modifiersFor(e js.Value) key.Modifiers {
return mods
}

func (w *window) touchEvent(typ pointer.Type, e js.Value) {
func (w *window) touchEvent(kind pointer.Kind, e js.Value) {
e.Call("preventDefault")
t := time.Duration(e.Get("timeStamp").Int()) * time.Millisecond
changedTouches := e.Get("changedTouches")
Expand Down Expand Up @@ -426,7 +426,7 @@ func (w *window) touchEvent(typ pointer.Type, e js.Value) {
Y: float32(y) * scale,
}
w.w.Event(pointer.Event{
Type: typ,
Kind: kind,
Source: pointer.Touch,
Position: pos,
PointerID: pid,
Expand All @@ -448,7 +448,7 @@ func (w *window) touchIDFor(touch js.Value) pointer.ID {
return pid
}

func (w *window) pointerEvent(typ pointer.Type, dx, dy float32, e js.Value) {
func (w *window) pointerEvent(kind pointer.Kind, dx, dy float32, e js.Value) {
e.Call("preventDefault")
x, y := e.Get("clientX").Float(), e.Get("clientY").Float()
rect := w.cnv.Call("getBoundingClientRect")
Expand Down Expand Up @@ -476,7 +476,7 @@ func (w *window) pointerEvent(typ pointer.Type, dx, dy float32, e js.Value) {
btns |= pointer.ButtonTertiary
}
w.w.Event(pointer.Event{
Type: typ,
Kind: kind,
Source: pointer.Mouse,
Buttons: btns,
Position: pos,
Expand Down
4 changes: 2 additions & 2 deletions app/os_macos.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ func gio_onMouse(view, evt C.CFTypeRef, cdir C.int, cbtn C.NSInteger, x, y, dx,
case 2:
btn = pointer.ButtonTertiary
}
var typ pointer.Type
var typ pointer.Kind
switch cdir {
case C.MOUSE_MOVE:
typ = pointer.Move
Expand All @@ -550,7 +550,7 @@ func gio_onMouse(view, evt C.CFTypeRef, cdir C.int, cbtn C.NSInteger, x, y, dx,
panic("invalid direction")
}
w.w.Event(pointer.Event{
Type: typ,
Kind: typ,
Source: pointer.Mouse,
Time: t,
Buttons: w.pointerBtns,
Expand Down
16 changes: 8 additions & 8 deletions app/os_wayland.go
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ func gio_onTouchDown(data unsafe.Pointer, touch *C.struct_wl_touch, serial, t C.
Y: fromFixed(y) * float32(w.scale),
}
w.w.Event(pointer.Event{
Type: pointer.Press,
Kind: pointer.Press,
Source: pointer.Touch,
Position: w.lastTouch,
PointerID: pointer.ID(id),
Expand All @@ -810,7 +810,7 @@ func gio_onTouchUp(data unsafe.Pointer, touch *C.struct_wl_touch, serial, t C.ui
w := s.touchFoci[id]
delete(s.touchFoci, id)
w.w.Event(pointer.Event{
Type: pointer.Release,
Kind: pointer.Release,
Source: pointer.Touch,
Position: w.lastTouch,
PointerID: pointer.ID(id),
Expand All @@ -828,7 +828,7 @@ func gio_onTouchMotion(data unsafe.Pointer, touch *C.struct_wl_touch, t C.uint32
Y: fromFixed(y) * float32(w.scale),
}
w.w.Event(pointer.Event{
Type: pointer.Move,
Kind: pointer.Move,
Position: w.lastTouch,
Source: pointer.Touch,
PointerID: pointer.ID(id),
Expand All @@ -847,7 +847,7 @@ func gio_onTouchCancel(data unsafe.Pointer, touch *C.struct_wl_touch) {
for id, w := range s.touchFoci {
delete(s.touchFoci, id)
w.w.Event(pointer.Event{
Type: pointer.Cancel,
Kind: pointer.Cancel,
Source: pointer.Touch,
})
}
Expand All @@ -872,7 +872,7 @@ func gio_onPointerLeave(data unsafe.Pointer, p *C.struct_wl_pointer, serial C.ui
s.serial = serial
if w.inCompositor {
w.inCompositor = false
w.w.Event(pointer.Event{Type: pointer.Cancel})
w.w.Event(pointer.Event{Kind: pointer.Cancel})
}
}

Expand Down Expand Up @@ -934,7 +934,7 @@ func gio_onPointerButton(data unsafe.Pointer, p *C.struct_wl_pointer, serial, t,
w.flushScroll()
w.resetFling()
w.w.Event(pointer.Event{
Type: typ,
Kind: typ,
Source: pointer.Mouse,
Buttons: w.pointerBtns,
Position: w.lastPos,
Expand Down Expand Up @@ -1581,7 +1581,7 @@ func (w *window) flushScroll() {
return
}
w.w.Event(pointer.Event{
Type: pointer.Scroll,
Kind: pointer.Scroll,
Source: pointer.Mouse,
Buttons: w.pointerBtns,
Position: w.lastPos,
Expand All @@ -1604,7 +1604,7 @@ func (w *window) onPointerMotion(x, y C.wl_fixed_t, t C.uint32_t) {
Y: fromFixed(y) * float32(w.scale),
}
w.w.Event(pointer.Event{
Type: pointer.Move,
Kind: pointer.Move,
Position: w.lastPos,
Buttons: w.pointerBtns,
Source: pointer.Mouse,
Expand Down
14 changes: 7 additions & 7 deletions app/os_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func windowProc(hwnd syscall.Handle, msg uint32, wParam, lParam uintptr) uintptr
w.pointerButton(pointer.ButtonTertiary, false, lParam, getModifiers())
case windows.WM_CANCELMODE:
w.w.Event(pointer.Event{
Type: pointer.Cancel,
Kind: pointer.Cancel,
})
case windows.WM_SETFOCUS:
w.focused = true
Expand Down Expand Up @@ -288,7 +288,7 @@ func windowProc(hwnd syscall.Handle, msg uint32, wParam, lParam uintptr) uintptr
x, y := coordsFromlParam(lParam)
p := f32.Point{X: float32(x), Y: float32(y)}
w.w.Event(pointer.Event{
Type: pointer.Move,
Kind: pointer.Move,
Source: pointer.Mouse,
Position: p,
Buttons: w.pointerBtns,
Expand Down Expand Up @@ -501,15 +501,15 @@ func (w *window) pointerButton(btn pointer.Buttons, press bool, lParam uintptr,
windows.SetFocus(w.hwnd)
}

var typ pointer.Type
var kind pointer.Kind
if press {
typ = pointer.Press
kind = pointer.Press
if w.pointerBtns == 0 {
windows.SetCapture(w.hwnd)
}
w.pointerBtns |= btn
} else {
typ = pointer.Release
kind = pointer.Release
w.pointerBtns &^= btn
if w.pointerBtns == 0 {
windows.ReleaseCapture()
Expand All @@ -518,7 +518,7 @@ func (w *window) pointerButton(btn pointer.Buttons, press bool, lParam uintptr,
x, y := coordsFromlParam(lParam)
p := f32.Point{X: float32(x), Y: float32(y)}
w.w.Event(pointer.Event{
Type: typ,
Kind: kind,
Source: pointer.Mouse,
Position: p,
Buttons: w.pointerBtns,
Expand Down Expand Up @@ -553,7 +553,7 @@ func (w *window) scrollEvent(wParam, lParam uintptr, horizontal bool, kmods key.
}
}
w.w.Event(pointer.Event{
Type: pointer.Scroll,
Kind: pointer.Scroll,
Source: pointer.Mouse,
Position: p,
Buttons: w.pointerBtns,
Expand Down
4 changes: 2 additions & 2 deletions app/os_x11.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ func (h *x11EventHandler) handleEvents() bool {
case C.ButtonPress, C.ButtonRelease:
bevt := (*C.XButtonEvent)(unsafe.Pointer(xev))
ev := pointer.Event{
Type: pointer.Press,
Kind: pointer.Press,
Source: pointer.Mouse,
Position: f32.Point{
X: float32(bevt.x),
Expand Down Expand Up @@ -607,7 +607,7 @@ func (h *x11EventHandler) handleEvents() bool {
case C.MotionNotify:
mevt := (*C.XMotionEvent)(unsafe.Pointer(xev))
w.w.Event(pointer.Event{
Type: pointer.Move,
Kind: pointer.Move,
Source: pointer.Mouse,
Buttons: w.pointerBtns,
Position: f32.Point{
Expand Down
16 changes: 8 additions & 8 deletions gesture/gesture.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type Hover struct {
func (h *Hover) Add(ops *op.Ops) {
pointer.InputOp{
Tag: h,
Types: pointer.Enter | pointer.Leave,
Kinds: pointer.Enter | pointer.Leave,
}.Add(ops)
}

Expand All @@ -50,7 +50,7 @@ func (h *Hover) Hovered(q event.Queue) bool {
if !ok {
continue
}
switch e.Type {
switch e.Kind {
case pointer.Leave, pointer.Cancel:
if h.entered && h.pid == e.PointerID {
h.entered = false
Expand Down Expand Up @@ -163,7 +163,7 @@ const touchSlop = unit.Dp(3)
func (c *Click) Add(ops *op.Ops) {
pointer.InputOp{
Tag: c,
Types: pointer.Press | pointer.Release | pointer.Enter | pointer.Leave,
Kinds: pointer.Press | pointer.Release | pointer.Enter | pointer.Leave,
}.Add(ops)
}

Expand All @@ -185,7 +185,7 @@ func (c *Click) Events(q event.Queue) []ClickEvent {
if !ok {
continue
}
switch e.Type {
switch e.Kind {
case pointer.Release:
if !c.pressed || c.pid != e.PointerID {
break
Expand Down Expand Up @@ -254,7 +254,7 @@ func (s *Scroll) Add(ops *op.Ops, bounds image.Rectangle) {
oph := pointer.InputOp{
Tag: s,
Grab: s.grab,
Types: pointer.Press | pointer.Drag | pointer.Release | pointer.Scroll,
Kinds: pointer.Press | pointer.Drag | pointer.Release | pointer.Scroll,
ScrollBounds: bounds,
}
oph.Add(ops)
Expand All @@ -281,7 +281,7 @@ func (s *Scroll) Scroll(cfg unit.Metric, q event.Queue, t time.Time, axis Axis)
if !ok {
continue
}
switch e.Type {
switch e.Kind {
case pointer.Press:
if s.dragging {
break
Expand Down Expand Up @@ -368,7 +368,7 @@ func (d *Drag) Add(ops *op.Ops) {
pointer.InputOp{
Tag: d,
Grab: d.grab,
Types: pointer.Press | pointer.Drag | pointer.Release,
Kinds: pointer.Press | pointer.Drag | pointer.Release,
}.Add(ops)
}

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

switch e.Type {
switch e.Kind {
case pointer.Press:
if !(e.Buttons == pointer.ButtonPrimary || e.Source == pointer.Touch) {
continue
Expand Down
8 changes: 4 additions & 4 deletions gesture/gesture_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ func TestHover(t *testing.T) {
r.Frame(ops)

r.Queue(
pointer.Event{Type: pointer.Move, Position: f32.Pt(30, 30)},
pointer.Event{Kind: pointer.Move, Position: f32.Pt(30, 30)},
)
if !h.Hovered(r) {
t.Fatal("expected hovered")
}

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

func mouseClickEvents(times ...time.Duration) []event.Event {
press := pointer.Event{
Type: pointer.Press,
Kind: pointer.Press,
Source: pointer.Mouse,
Buttons: pointer.ButtonPrimary,
}
Expand All @@ -101,7 +101,7 @@ func mouseClickEvents(times ...time.Duration) []event.Event {
press := press
press.Time = t
release := press
release.Type = pointer.Release
release.Kind = pointer.Release
events = append(events, press, release)
}
return events
Expand Down
Loading

0 comments on commit 9cb0cc5

Please sign in to comment.