Documentation
¶
Overview ¶
Package constraint implements touch recognizers.
Create the touch recognizer in the Build function.
func (v *MyView) Build(ctx *view.Context) view.Model {
tap := &touch.TapRecognizer{
Count: 1,
OnTouch: func(e *touch.TapEvent) {
// Respond to touch events. This callback occurs on main thread.
fmt.Println("view touched")
},
}
...
Attach the recognizer to the view.
...
return view.Model{
Options: []view.Option{
touch.RecognizerList{tap},
},
}
}
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ButtonEvent ¶
ButtonEvent is emitted by ButtonRecognizer, representing its current state.
type ButtonRecognizer ¶
type ButtonRecognizer struct {
OnTouch func(e *ButtonEvent)
IgnoresScroll bool
}
ButtonRecognizer is a discrete recognizer that mimics the behavior of a button. The recognizer will fail if the touch ends outside of the view's bounds.
type EventKind ¶
type EventKind int
EventKind are the possible recognizer states
Discrete gestures:
EventKindPossible -> EventKindFailed EventKindPossible -> EventKindRecognized
Continuous gestures:
EventKindPossible -> EventKindChanged(optionally) -> EventKindFailed EventKindPossible -> EventKindChanged(optionally) -> EventKindRecognized
const ( // Finger is down, but before gesture has been recognized. EventKindPossible EventKind = iota // After the continuous gesture has been recognized, while the finger is still down. Only for continuous recognizers. EventKindChanged // Gesture recognition failed or cancelled. EventKindFailed // Gesture recognition succeded. EventKindRecognized )
type PressEvent ¶
type PressEvent struct {
Kind EventKind // TODO(KD): Does this work?
Timestamp time.Time
Position layout.Point
Duration time.Duration
}
PressEvent is emitted by PressRecognizer, representing its current state.
type PressRecognizer ¶
type PressRecognizer struct {
MinDuration time.Duration
OnTouch func(e *PressEvent)
}
PressRecognizer is a continuous recognizer that detects single presses with a given duration.
type Recognizer ¶
type Recognizer interface {
// contains filtered or unexported methods
}
type RecognizerList ¶
type RecognizerList []Recognizer
func (RecognizerList) OptionsKey ¶
func (r RecognizerList) OptionsKey() string
type TapRecognizer ¶
PressRecognizer is a discrete recognizer that detects a number of taps.