This package aims at handling touch (multitouch) events.
If you are new to elm like me (discovered elm at version 0.17.1) you may realize that touch interactions are not handled by default in elm. Originally, I needed to develop a user study (about outlining interactions) and I chose elm (with some excitement since it was my first elm project) to do it. Unfortunately it would not work on tablets (that are best fitted for this study). So here I am, rolling up my sleeves to create a package handling multitouch events.
elm-package install mpizenberg/elm-touch-eventsThis package provides types and functions to deal with single and multitouch events. For example, if you are in need of multitouch interactions, you may use the following types and functions :
-- Defined in Touch module: the type of touch event that can be triggered
type TouchEvent
= TouchStart
| TouchMove
| TouchEnd
| TouchCancel
-- Defined in Touch module: a simple type alias to represent a JavaScript Touch object
type alias Touch =
{ clientX : Float
, clientY : Float
}
-- Defined in MultiTouch module: To put somewhere in your model (or not).
-- The properties `touches`, `targetTouches` and `changedTouches`
-- are represented by dictionaries in which the keys are the
-- unique Int identifier of the Touch interactions.
type alias MultiTouch =
{ touchType : TouchEvent
, touches : Dict Int Touch
, targetTouches : Dict Int Touch
, changedTouches : Dict Int Touch
}
-- Defined in MultiTouch module: A simple touch event handler that can be
-- used in views with a msg builder (MultiTouch -> msg)
onMultiTouch : TouchEvent -> HE.Options -> (MultiTouch -> msg) -> H.Attribute msgTo try this package, please use a touchscreen platform (mobile, tablet, ...) since mouses do not generate touch interactions.
You can find a complete very simple example of a single touch interaction
in the file examples/singleTouch.elm.
For a complete multitouch example, please refer to the file
examples/multiTouch.elm.
The package documentation is available on the elm package website.
This Source Code Form is subject to the terms of the Mozilla Public License,v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
Original author: Matthieu Pizenberg ([email protected])