Touch events

These events are used to track multipoint touches. Single touches emulate mouse events.If you do not need to track multi-point touches, then it is easier to use mouse events

Event Constant Description
"touch-start" TouchStart The surface touched.
"touch-end" TouchEnd Surface touch completed.
"touch-move" TouchMove One or more touches changed position
"touch-cancel" TouchCancel The touch is interrupted.

The main event data listener has the following format:


func(View, TouchEvent)

where the second argument describes the touch parameters. The TouchEvent structure has the following fields:

Field Type Description
TimeStamp uint64 The time the event was created (in milliseconds). The starting point depends on the browser implementation (EPOCH, browser launch, etc.).
Touches []Touch Array of Touch structures, each describing one touch
CtrlKey bool The Ctrl key was active when the event occurred.
ShiftKey bool The Shift key was active when the event occurred.
AltKey bool The Alt (Option or ⌥ in OS X) key was active when the event occurred.
MetaKey bool The Meta key (for Mac, this is the ⌘ Command key; for Windows, the Windows key ⊞) was active when the event occurred.

The Touch structure describes a single touch and has the following fields

Field Type Description
Identifier int A unique identifier assigned to each touch and does not change until it is completed.
X float64 The horizontal position of the mouse relative to the origin View
Y float64 The vertical position of the mouse relative to the origin View
ClientX float64 Horizontal position of the mouse relative to the upper left corner of the application
ClientY float64 The vertical position of the mouse relative to the upper left corner of the application
ScreenX float64 Horizontal position of the mouse relative to the upper left corner of the screen
ScreenY float64 Vertical position of the mouse relative to the upper left corner of the screen
RadiusX float64 The x-radius of the ellipse, in pixels, that most closely delimits the area of contact with the screen.
RadiusY float64 The y-radius of the ellipse, in pixels, that most closely delimits the area of contact with the screen.
RotationAngle float64 The angle (in degrees) to rotate the ellipse clockwise, described by the radiusX and radiusY parameters, to best cover the contact area between the user and the surface.
Force float64 The amount of pressure from 0.0 (no pressure) to 1.0 (maximum pressure) that the user applies to the surface.

You can also use listeners in the following formats:

  • func(TouchEvent)
  • func(View)
  • func()

You can get lists of listeners for touch events using the functions:

func GetTouchStartListeners(view View, subviewID ...string) []func(View, TouchEvent)
func GetTouchEndListeners(view View, subviewID ...string) []func(View, TouchEvent)
func GetTouchMoveListeners(view View, subviewID ...string) []func(View, TouchEvent)
func GetTouchCancelListeners(view View, subviewID ...string) []func(View, TouchEvent)