io/pointer,gesture: report right and middle mouse button events

Updates gio#60

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-11-09 16:34:00 +01:00
parent a0050ab79b
commit dc7f9bab23
10 changed files with 160 additions and 36 deletions
+32
View File
@@ -5,6 +5,7 @@ package pointer
import (
"encoding/binary"
"image"
"strings"
"time"
"gioui.org/f32"
@@ -27,6 +28,8 @@ type Event struct {
// Time is when the event was received. The
// timestamp is relative to an undefined base.
Time time.Duration
// Buttons are the set of pressed mouse buttons for this event.
Buttons Buttons
// Hit is set when the event was within the registered
// area for the handler. Hit can be false when a pointer
// was pressed within the hit area, and then dragged
@@ -86,6 +89,9 @@ type Priority uint8
// Source of an Event.
type Source uint8
// Buttons is a set of mouse buttons
type Buttons uint8
// Must match app/internal/input.areaKind
type areaKind uint8
@@ -116,6 +122,12 @@ const (
Grabbed
)
const (
ButtonLeft Buttons = 1 << iota
ButtonRight
ButtonMiddle
)
const (
areaRect areaKind = iota
areaEllipse
@@ -199,4 +211,24 @@ func (s Source) String() string {
}
}
// Contain reports whether the set b contains
// all of the buttons.
func (b Buttons) Contain(buttons Buttons) bool {
return b&buttons == buttons
}
func (b Buttons) String() string {
var strs []string
if b.Contain(ButtonLeft) {
strs = append(strs, "ButtonLeft")
}
if b.Contain(ButtonRight) {
strs = append(strs, "ButtonRight")
}
if b.Contain(ButtonMiddle) {
strs = append(strs, "ButtonMiddle")
}
return strings.Join(strs, "|")
}
func (Event) ImplementsEvent() {}