io/pointer: rename button names to reflect their meaning, not placement

For example, ButtonLeft may be the right-most button for a left-handed user.
Rename the button names to match their intended use.

This is an API change. Use the following commands to update your
projects:

    $ gofmt -r 'pointer.ButtonLeft -> pointer.ButtonPrimary' -w .
    $ gofmt -r 'pointer.ButtonRight -> pointer.ButtonSecondary' -w .
    $ gofmt -r 'pointer.ButtonMiddle -> pointer.ButtonTertiary' -w .

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2021-03-03 11:03:38 +01:00
parent f36ed04380
commit ffb26b0e17
13 changed files with 48 additions and 43 deletions
+3 -3
View File
@@ -523,13 +523,13 @@ func Java_org_gioui_GioView_onTouchEvent(env *C.JNIEnv, class C.jclass, handle C
var src pointer.Source var src pointer.Source
var btns pointer.Buttons var btns pointer.Buttons
if jbtns&C.AMOTION_EVENT_BUTTON_PRIMARY != 0 { if jbtns&C.AMOTION_EVENT_BUTTON_PRIMARY != 0 {
btns |= pointer.ButtonLeft btns |= pointer.ButtonPrimary
} }
if jbtns&C.AMOTION_EVENT_BUTTON_SECONDARY != 0 { if jbtns&C.AMOTION_EVENT_BUTTON_SECONDARY != 0 {
btns |= pointer.ButtonRight btns |= pointer.ButtonSecondary
} }
if jbtns&C.AMOTION_EVENT_BUTTON_TERTIARY != 0 { if jbtns&C.AMOTION_EVENT_BUTTON_TERTIARY != 0 {
btns |= pointer.ButtonMiddle btns |= pointer.ButtonTertiary
} }
switch tool { switch tool {
case C.AMOTION_EVENT_TOOL_TYPE_FINGER: case C.AMOTION_EVENT_TOOL_TYPE_FINGER:
+3 -3
View File
@@ -382,13 +382,13 @@ func (w *window) pointerEvent(typ pointer.Type, dx, dy float32, e js.Value) {
jbtns := e.Get("buttons").Int() jbtns := e.Get("buttons").Int()
var btns pointer.Buttons var btns pointer.Buttons
if jbtns&1 != 0 { if jbtns&1 != 0 {
btns |= pointer.ButtonLeft btns |= pointer.ButtonPrimary
} }
if jbtns&2 != 0 { if jbtns&2 != 0 {
btns |= pointer.ButtonRight btns |= pointer.ButtonSecondary
} }
if jbtns&4 != 0 { if jbtns&4 != 0 {
btns |= pointer.ButtonMiddle btns |= pointer.ButtonTertiary
} }
w.w.Event(pointer.Event{ w.w.Event(pointer.Event{
Type: typ, Type: typ,
+3 -3
View File
@@ -200,13 +200,13 @@ func gio_onMouse(view C.CFTypeRef, cdir C.int, cbtns C.NSUInteger, x, y, dx, dy
} }
var btns pointer.Buttons var btns pointer.Buttons
if cbtns&(1<<0) != 0 { if cbtns&(1<<0) != 0 {
btns |= pointer.ButtonLeft btns |= pointer.ButtonPrimary
} }
if cbtns&(1<<1) != 0 { if cbtns&(1<<1) != 0 {
btns |= pointer.ButtonRight btns |= pointer.ButtonSecondary
} }
if cbtns&(1<<2) != 0 { if cbtns&(1<<2) != 0 {
btns |= pointer.ButtonMiddle btns |= pointer.ButtonTertiary
} }
t := time.Duration(float64(ti)*float64(time.Second) + .5) t := time.Duration(float64(ti)*float64(time.Second) + .5)
w := mustView(view) w := mustView(view)
+3 -3
View File
@@ -801,11 +801,11 @@ func gio_onPointerButton(data unsafe.Pointer, p *C.struct_wl_pointer, serial, t,
var btn pointer.Buttons var btn pointer.Buttons
switch wbtn { switch wbtn {
case BTN_LEFT: case BTN_LEFT:
btn = pointer.ButtonLeft btn = pointer.ButtonPrimary
case BTN_RIGHT: case BTN_RIGHT:
btn = pointer.ButtonRight btn = pointer.ButtonSecondary
case BTN_MIDDLE: case BTN_MIDDLE:
btn = pointer.ButtonMiddle btn = pointer.ButtonTertiary
default: default:
return return
} }
+6 -6
View File
@@ -257,17 +257,17 @@ func windowProc(hwnd syscall.Handle, msg uint32, wParam, lParam uintptr) uintptr
w.w.Event(e) w.w.Event(e)
} }
case windows.WM_LBUTTONDOWN: case windows.WM_LBUTTONDOWN:
w.pointerButton(pointer.ButtonLeft, true, lParam, getModifiers()) w.pointerButton(pointer.ButtonPrimary, true, lParam, getModifiers())
case windows.WM_LBUTTONUP: case windows.WM_LBUTTONUP:
w.pointerButton(pointer.ButtonLeft, false, lParam, getModifiers()) w.pointerButton(pointer.ButtonPrimary, false, lParam, getModifiers())
case windows.WM_RBUTTONDOWN: case windows.WM_RBUTTONDOWN:
w.pointerButton(pointer.ButtonRight, true, lParam, getModifiers()) w.pointerButton(pointer.ButtonSecondary, true, lParam, getModifiers())
case windows.WM_RBUTTONUP: case windows.WM_RBUTTONUP:
w.pointerButton(pointer.ButtonRight, false, lParam, getModifiers()) w.pointerButton(pointer.ButtonSecondary, false, lParam, getModifiers())
case windows.WM_MBUTTONDOWN: case windows.WM_MBUTTONDOWN:
w.pointerButton(pointer.ButtonMiddle, true, lParam, getModifiers()) w.pointerButton(pointer.ButtonTertiary, true, lParam, getModifiers())
case windows.WM_MBUTTONUP: case windows.WM_MBUTTONUP:
w.pointerButton(pointer.ButtonMiddle, 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, Type: pointer.Cancel,
+3 -3
View File
@@ -362,11 +362,11 @@ func (h *x11EventHandler) handleEvents() bool {
const scrollScale = 10 const scrollScale = 10
switch bevt.button { switch bevt.button {
case C.Button1: case C.Button1:
btn = pointer.ButtonLeft btn = pointer.ButtonPrimary
case C.Button2: case C.Button2:
btn = pointer.ButtonMiddle btn = pointer.ButtonTertiary
case C.Button3: case C.Button3:
btn = pointer.ButtonRight btn = pointer.ButtonSecondary
case C.Button4: case C.Button4:
// scroll up // scroll up
ev.Type = pointer.Scroll ev.Type = pointer.Scroll
+2 -2
View File
@@ -172,7 +172,7 @@ func (c *Click) Events(q event.Queue) []ClickEvent {
if c.pressed { if c.pressed {
break break
} }
if e.Source == pointer.Mouse && e.Buttons != pointer.ButtonLeft { if e.Source == pointer.Mouse && e.Buttons != pointer.ButtonPrimary {
break break
} }
if !c.entered { if !c.entered {
@@ -341,7 +341,7 @@ func (d *Drag) Events(cfg unit.Metric, q event.Queue, axis Axis) []pointer.Event
switch e.Type { switch e.Type {
case pointer.Press: case pointer.Press:
if !(e.Buttons == pointer.ButtonLeft || e.Source == pointer.Touch) { if !(e.Buttons == pointer.ButtonPrimary || e.Source == pointer.Touch) {
continue continue
} }
if d.dragging { if d.dragging {
+1 -1
View File
@@ -64,7 +64,7 @@ func mouseClickEvents(times ...time.Duration) []event.Event {
press := pointer.Event{ press := pointer.Event{
Type: pointer.Press, Type: pointer.Press,
Source: pointer.Mouse, Source: pointer.Mouse,
Buttons: pointer.ButtonLeft, Buttons: pointer.ButtonPrimary,
} }
events := make([]event.Event, 0, 2*len(times)) events := make([]event.Event, 0, 2*len(times))
for _, t := range times { for _, t := range times {
+14 -9
View File
@@ -148,9 +148,14 @@ const (
) )
const ( const (
ButtonLeft Buttons = 1 << iota // ButtonPrimary is the primary button, usually the left button for a
ButtonRight // right-handed user.
ButtonMiddle ButtonPrimary Buttons = 1 << iota
// ButtonSecondary is the secondary button, usually the right button for a
// right-handed user.
ButtonSecondary
// ButtonTertiary is the tertiary button, usually the middle button.
ButtonTertiary
) )
const ( const (
@@ -265,14 +270,14 @@ func (b Buttons) Contain(buttons Buttons) bool {
func (b Buttons) String() string { func (b Buttons) String() string {
var strs []string var strs []string
if b.Contain(ButtonLeft) { if b.Contain(ButtonPrimary) {
strs = append(strs, "ButtonLeft") strs = append(strs, "ButtonPrimary")
} }
if b.Contain(ButtonRight) { if b.Contain(ButtonSecondary) {
strs = append(strs, "ButtonRight") strs = append(strs, "ButtonSecondary")
} }
if b.Contain(ButtonMiddle) { if b.Contain(ButtonTertiary) {
strs = append(strs, "ButtonMiddle") strs = append(strs, "ButtonTertiary")
} }
return strings.Join(strs, "|") return strings.Join(strs, "|")
} }
+1 -1
View File
@@ -488,7 +488,7 @@ func TestCursorNameOp(t *testing.T) {
return pointer.Event{ return pointer.Event{
Type: pointer.Move, Type: pointer.Move,
Source: pointer.Mouse, Source: pointer.Mouse,
Buttons: pointer.ButtonLeft, Buttons: pointer.ButtonPrimary,
Position: f32.Pt(x, y), Position: f32.Pt(x, y),
} }
} }
+6 -6
View File
@@ -43,7 +43,7 @@ func TestListPosition(t *testing.T) {
scroll: _s( scroll: _s(
pointer.Event{ pointer.Event{
Source: pointer.Mouse, Source: pointer.Mouse,
Buttons: pointer.ButtonLeft, Buttons: pointer.ButtonPrimary,
Type: pointer.Press, Type: pointer.Press,
Position: f32.Pt(0, 0), Position: f32.Pt(0, 0),
}, },
@@ -54,7 +54,7 @@ func TestListPosition(t *testing.T) {
}, },
pointer.Event{ pointer.Event{
Source: pointer.Mouse, Source: pointer.Mouse,
Buttons: pointer.ButtonLeft, Buttons: pointer.ButtonPrimary,
Type: pointer.Release, Type: pointer.Release,
Position: f32.Pt(5, 0), Position: f32.Pt(5, 0),
}, },
@@ -63,7 +63,7 @@ func TestListPosition(t *testing.T) {
scroll: _s( scroll: _s(
pointer.Event{ pointer.Event{
Source: pointer.Mouse, Source: pointer.Mouse,
Buttons: pointer.ButtonLeft, Buttons: pointer.ButtonPrimary,
Type: pointer.Press, Type: pointer.Press,
Position: f32.Pt(0, 0), Position: f32.Pt(0, 0),
}, },
@@ -74,7 +74,7 @@ func TestListPosition(t *testing.T) {
}, },
pointer.Event{ pointer.Event{
Source: pointer.Mouse, Source: pointer.Mouse,
Buttons: pointer.ButtonLeft, Buttons: pointer.ButtonPrimary,
Type: pointer.Release, Type: pointer.Release,
Position: f32.Pt(5, 0), Position: f32.Pt(5, 0),
}, },
@@ -83,7 +83,7 @@ func TestListPosition(t *testing.T) {
scroll: _s( scroll: _s(
pointer.Event{ pointer.Event{
Source: pointer.Mouse, Source: pointer.Mouse,
Buttons: pointer.ButtonLeft, Buttons: pointer.ButtonPrimary,
Type: pointer.Press, Type: pointer.Press,
Position: f32.Pt(0, 0), Position: f32.Pt(0, 0),
}, },
@@ -94,7 +94,7 @@ func TestListPosition(t *testing.T) {
}, },
pointer.Event{ pointer.Event{
Source: pointer.Mouse, Source: pointer.Mouse,
Buttons: pointer.ButtonLeft, Buttons: pointer.ButtonPrimary,
Type: pointer.Release, Type: pointer.Release,
Position: f32.Pt(15, 0), Position: f32.Pt(15, 0),
}, },
+1 -1
View File
@@ -373,7 +373,7 @@ g123456789g
tq := &testQueue{ tq := &testQueue{
events: []event.Event{ events: []event.Event{
pointer.Event{ pointer.Event{
Buttons: pointer.ButtonLeft, Buttons: pointer.ButtonPrimary,
Type: pointer.Press, Type: pointer.Press,
Source: pointer.Mouse, Source: pointer.Mouse,
Position: f32.Pt(textWidth(e, startPos.lineCol.Y, 0, startPos.lineCol.X), textHeight(e, startPos.lineCol.Y)), Position: f32.Pt(textWidth(e, startPos.lineCol.Y, 0, startPos.lineCol.X), textHeight(e, startPos.lineCol.Y)),
+2 -2
View File
@@ -44,13 +44,13 @@ func ExampleClickable_passthrough() {
r.Queue( r.Queue(
pointer.Event{ pointer.Event{
Source: pointer.Mouse, Source: pointer.Mouse,
Buttons: pointer.ButtonLeft, Buttons: pointer.ButtonPrimary,
Type: pointer.Press, Type: pointer.Press,
Position: f32.Pt(50, 50), Position: f32.Pt(50, 50),
}, },
pointer.Event{ pointer.Event{
Source: pointer.Mouse, Source: pointer.Mouse,
Buttons: pointer.ButtonLeft, Buttons: pointer.ButtonPrimary,
Type: pointer.Release, Type: pointer.Release,
Position: f32.Pt(50, 50), Position: f32.Pt(50, 50),
}, },