io/pointer: add Drag event type

This eliminates needless redraws for handlers that care about drag events and not move events, like gesture.Scroll.

Signed-off-by: Gordon Klaus <gordon.klaus@gmail.com>
This commit is contained in:
Gordon Klaus
2020-06-03 18:44:42 +02:00
committed by Elias Naur
parent cb5cc02560
commit 1a070a36b6
5 changed files with 14 additions and 6 deletions
+2 -2
View File
@@ -174,7 +174,7 @@ func (s *Scroll) Add(ops *op.Ops) {
oph := pointer.InputOp{
Tag: s,
Grab: s.grab,
Types: pointer.Press | pointer.Move | pointer.Release | pointer.Scroll,
Types: pointer.Press | pointer.Drag | pointer.Release | pointer.Scroll,
}
oph.Add(ops)
if s.flinger.Active() {
@@ -234,7 +234,7 @@ func (s *Scroll) Scroll(cfg unit.Converter, q event.Queue, t time.Time, axis Axi
iscroll := int(s.scroll)
s.scroll -= float32(iscroll)
total += iscroll
case pointer.Move:
case pointer.Drag:
if !s.dragging || s.pid != e.PointerID {
continue
}
+2 -2
View File
@@ -12,7 +12,7 @@ Types
Only events that match a specified list of types are delivered to a handler.
For example, to receive Press, Move, and Release events (but not Enter,
For example, to receive Press, Drag, and Release events (but not Move, Enter,
Leave, or Scroll):
var ops op.Ops
@@ -20,7 +20,7 @@ Leave, or Scroll):
pointer.InputOp{
Tag: h,
Types: pointer.Press | pointer.Move | pointer.Release,
Types: pointer.Press | pointer.Drag | pointer.Release,
}.Add(ops)
Scroll events are only delivered to the foremost scroll handler.
+4
View File
@@ -92,6 +92,8 @@ const (
Release
// Move of a pointer.
Move
// Drag of a pointer.
Drag
// Pointer enters an area watching for pointer input
Enter
// Pointer leaves an area watching for pointer input
@@ -180,6 +182,8 @@ func (t Type) String() string {
return "Cancel"
case Move:
return "Move"
case Drag:
return "Drag"
case Enter:
return "Enter"
case Leave:
+4
View File
@@ -235,6 +235,10 @@ func (q *pointerQueue) Push(e pointer.Event, events *handlerEvents) {
}
p := &q.pointers[pidx]
if e.Type == pointer.Move && p.pressed {
e.Type = pointer.Drag
}
q.deliverEnterLeaveEvents(p, events, e)
if e.Type == pointer.Release {
q.deliverEvent(p, events, e)
+2 -2
View File
@@ -39,7 +39,7 @@ func TestPointerDrag(t *testing.T) {
},
},
)
assertEventSequence(t, r.Events(handler), pointer.Cancel, pointer.Enter, pointer.Press, pointer.Leave, pointer.Move)
assertEventSequence(t, r.Events(handler), pointer.Cancel, pointer.Enter, pointer.Press, pointer.Leave, pointer.Drag)
}
func TestPointerMove(t *testing.T) {
@@ -446,7 +446,7 @@ func addPointerHandler(ops *op.Ops, tag event.Tag, area image.Rectangle) {
pointer.Rect(area).Add(ops)
pointer.InputOp{
Tag: tag,
Types: pointer.Press | pointer.Move | pointer.Release | pointer.Enter | pointer.Leave,
Types: pointer.Press | pointer.Release | pointer.Move | pointer.Drag | pointer.Enter | pointer.Leave,
}.Add(ops)
}