Skip to main content

gestures

Package gestures provides gesture recognition for pointer input, including an arena for resolving competing recognizers and common gesture types like tap and pan.

Variables

DefaultArena is the global gesture arena for the app.

var DefaultArena = NewGestureArena()

DefaultTouchSlop is the movement threshold before a drag wins a gesture.

var DefaultTouchSlop = 12.0

type ArenaMember

ArenaMember participates in the gesture arena.

type ArenaMember interface {
AcceptGesture(pointerID int64)
RejectGesture(pointerID int64)
}

type DragAxis

DragAxis specifies the direction for axis-locked drag recognizers.

type DragAxis int
const (
// DragAxisHorizontal restricts drag detection to horizontal movement.
DragAxisHorizontal DragAxis = iota
// DragAxisVertical restricts drag detection to vertical movement.
DragAxisVertical
)

type DragEndDetails

DragEndDetails describes the end of a drag.

type DragEndDetails struct {
// Position is the final global position of the pointer.
Position rendering.Offset
// Velocity is the velocity of the pointer at release in pixels per second.
Velocity rendering.Offset
// PrimaryVelocity is the axis-specific velocity (0 for Pan, non-zero for axis-locked drags).
PrimaryVelocity float64
}

type DragStartDetails

DragStartDetails describes the start of a drag.

type DragStartDetails struct {
// Position is the global position where the drag started.
Position rendering.Offset
}

type DragUpdateDetails

DragUpdateDetails describes a drag update.

type DragUpdateDetails struct {
// Position is the current global position of the pointer.
Position rendering.Offset
// Delta is the change in position since the last update.
Delta rendering.Offset
// PrimaryDelta is the axis-specific delta (0 for Pan, non-zero for axis-locked drags).
PrimaryDelta float64
}

type GestureArena

GestureArena resolves competing gesture recognizers per pointer.

type GestureArena struct {
// contains filtered or unexported fields
}

func NewGestureArena

func NewGestureArena() *GestureArena

NewGestureArena creates a new arena instance.

func (*GestureArena) Add

func (a *GestureArena) Add(pointerID int64, member ArenaMember)

Add registers a member for a pointer.

func (*GestureArena) Close

func (a *GestureArena) Close(pointerID int64)

Close signals that no more members will be added for this pointer.

func (*GestureArena) Hold

func (a *GestureArena) Hold(pointerID int64, member ArenaMember) bool

Hold defers auto-resolution for this member. Returns true if the hold was added successfully. The member must already be in the arena.

func (*GestureArena) Reject

func (a *GestureArena) Reject(pointerID int64, member ArenaMember)

Reject removes a member from the arena.

func (*GestureArena) ReleaseHold

func (a *GestureArena) ReleaseHold(pointerID int64, member ArenaMember)

ReleaseHold removes a hold without resolving or rejecting.

func (*GestureArena) Resolve

func (a *GestureArena) Resolve(pointerID int64, member ArenaMember)

Resolve declares the winner for this pointer.

func (*GestureArena) Sweep

func (a *GestureArena) Sweep(pointerID int64)

Sweep clears the arena entry for a pointer.

type HorizontalDragGestureRecognizer

HorizontalDragGestureRecognizer detects horizontal drag gestures. It wins when |deltaX| > slop before |deltaY| > slop.

type HorizontalDragGestureRecognizer struct {
// contains filtered or unexported fields
}

func NewHorizontalDragGestureRecognizer

func NewHorizontalDragGestureRecognizer(arena *GestureArena) *HorizontalDragGestureRecognizer

NewHorizontalDragGestureRecognizer creates a horizontal drag recognizer.

func (*HorizontalDragGestureRecognizer) AcceptGesture

func (h *HorizontalDragGestureRecognizer) AcceptGesture(pointerID int64)

AcceptGesture is called by the arena when this recognizer wins.

func (*HorizontalDragGestureRecognizer) AddPointer

func (h *HorizontalDragGestureRecognizer) AddPointer(event PointerEvent)

AddPointer registers a pointer down event.

func (*HorizontalDragGestureRecognizer) Dispose

func (h *HorizontalDragGestureRecognizer) Dispose()

Dispose releases resources for the recognizer.

func (*HorizontalDragGestureRecognizer) HandleEvent

func (h *HorizontalDragGestureRecognizer) HandleEvent(event PointerEvent)

HandleEvent processes pointer events for drag detection.

func (*HorizontalDragGestureRecognizer) RejectGesture

func (h *HorizontalDragGestureRecognizer) RejectGesture(pointerID int64)

RejectGesture is called by the arena when this recognizer loses.

type PanGestureRecognizer

PanGestureRecognizer detects pan gestures.

type PanGestureRecognizer struct {
Arena *GestureArena
OnStart func(DragStartDetails)
OnUpdate func(DragUpdateDetails)
OnEnd func(DragEndDetails)
OnCancel func()
// contains filtered or unexported fields
}

func NewPanGestureRecognizer

func NewPanGestureRecognizer(arena *GestureArena) *PanGestureRecognizer

NewPanGestureRecognizer creates a pan recognizer.

func (*PanGestureRecognizer) AcceptGesture

func (p *PanGestureRecognizer) AcceptGesture(pointerID int64)

AcceptGesture is called by the arena when this recognizer wins.

func (*PanGestureRecognizer) AddPointer

func (p *PanGestureRecognizer) AddPointer(event PointerEvent)

AddPointer registers a pointer down event.

func (*PanGestureRecognizer) Dispose

func (p *PanGestureRecognizer) Dispose()

Dispose releases resources for the recognizer.

func (*PanGestureRecognizer) HandleEvent

func (p *PanGestureRecognizer) HandleEvent(event PointerEvent)

HandleEvent processes pointer events for drag detection.

func (*PanGestureRecognizer) RejectGesture

func (p *PanGestureRecognizer) RejectGesture(pointerID int64)

RejectGesture is called by the arena when this recognizer loses.

type PointerEvent

PointerEvent represents a pointer event routed to gesture recognizers.

type PointerEvent struct {
// PointerID uniquely identifies this pointer (finger/mouse).
PointerID int64
// Position is the pointer location in logical pixels.
Position rendering.Offset
// Delta is the change in position since the last event.
Delta rendering.Offset
// Phase indicates the current phase of the pointer interaction.
Phase PointerPhase
}

type PointerPhase

PointerPhase represents the phase of a pointer event.

type PointerPhase int
const (
// PointerPhaseDown indicates the pointer made contact with the surface.
PointerPhaseDown PointerPhase = iota
// PointerPhaseMove indicates the pointer moved while in contact.
PointerPhaseMove
// PointerPhaseUp indicates the pointer lifted from the surface.
PointerPhaseUp
// PointerPhaseCancel indicates the pointer interaction was cancelled.
PointerPhaseCancel
)

func (PointerPhase) String

func (p PointerPhase) String() string

String returns the string representation of the pointer phase.

type TapGestureRecognizer

TapGestureRecognizer detects taps.

type TapGestureRecognizer struct {
Arena *GestureArena
OnTap func()
// contains filtered or unexported fields
}

func NewTapGestureRecognizer

func NewTapGestureRecognizer(arena *GestureArena) *TapGestureRecognizer

NewTapGestureRecognizer creates a tap recognizer.

func (*TapGestureRecognizer) AcceptGesture

func (t *TapGestureRecognizer) AcceptGesture(pointerID int64)

AcceptGesture is called by the arena when this recognizer wins.

func (*TapGestureRecognizer) AddPointer

func (t *TapGestureRecognizer) AddPointer(event PointerEvent)

AddPointer registers a pointer down event.

func (*TapGestureRecognizer) Dispose

func (t *TapGestureRecognizer) Dispose()

Dispose releases resources for the recognizer.

func (*TapGestureRecognizer) HandleEvent

func (t *TapGestureRecognizer) HandleEvent(event PointerEvent)

HandleEvent processes pointer events for tap detection.

func (*TapGestureRecognizer) RejectGesture

func (t *TapGestureRecognizer) RejectGesture(pointerID int64)

RejectGesture is called by the arena when this recognizer loses.

type VerticalDragGestureRecognizer

VerticalDragGestureRecognizer detects vertical drag gestures. It wins when |deltaY| > slop before |deltaX| > slop.

type VerticalDragGestureRecognizer struct {
// contains filtered or unexported fields
}

func NewVerticalDragGestureRecognizer

func NewVerticalDragGestureRecognizer(arena *GestureArena) *VerticalDragGestureRecognizer

NewVerticalDragGestureRecognizer creates a vertical drag recognizer.

func (*VerticalDragGestureRecognizer) AcceptGesture

func (v *VerticalDragGestureRecognizer) AcceptGesture(pointerID int64)

AcceptGesture is called by the arena when this recognizer wins.

func (*VerticalDragGestureRecognizer) AddPointer

func (v *VerticalDragGestureRecognizer) AddPointer(event PointerEvent)

AddPointer registers a pointer down event.

func (*VerticalDragGestureRecognizer) Dispose

func (v *VerticalDragGestureRecognizer) Dispose()

Dispose releases resources for the recognizer.

func (*VerticalDragGestureRecognizer) HandleEvent

func (v *VerticalDragGestureRecognizer) HandleEvent(event PointerEvent)

HandleEvent processes pointer events for drag detection.

func (*VerticalDragGestureRecognizer) RejectGesture

func (v *VerticalDragGestureRecognizer) RejectGesture(pointerID int64)

RejectGesture is called by the arena when this recognizer loses.

Generated by gomarkdoc