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