~eliasnaur/gio

1a070a36b677363bbcd3b437b3fd35b3361ec08d — Gordon Klaus a month ago cb5cc02
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>
M gesture/gesture.go => gesture/gesture.go +2 -2
@@ 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
			}

M io/pointer/doc.go => io/pointer/doc.go +2 -2
@@ 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.

M io/pointer/pointer.go => io/pointer/pointer.go +4 -0
@@ 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:

M io/router/pointer.go => io/router/pointer.go +4 -0
@@ 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)

M io/router/pointer_test.go => io/router/pointer_test.go +2 -2
@@ 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)
}