Touch module in Elm 0.17

376 views
Skip to first unread message

Tobias Hermann

unread,
May 14, 2016, 2:39:25 PM5/14/16
to Elm Discuss
Hi,

I'm currently trying to update some of my old elm code to version 0.17. I see that Mouse and Keyboard were moved to separate packages, but I can not find anything touch related. Can the touch functionality still be found somewhere?

Tobias

Janis Voigtländer

unread,
May 14, 2016, 2:50:51 PM5/14/16
to elm-d...@googlegroups.com
Touch support is gone for now.
--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Joey Eremondi

unread,
May 14, 2016, 2:53:02 PM5/14/16
to elm-d...@googlegroups.com
In principle, could you do touch support with Ports?

Support for anything is never truly gone with ports!

Janis Voigtländer

unread,
May 14, 2016, 2:54:03 PM5/14/16
to elm-d...@googlegroups.com
True, but I don't think that was the question. 

Tobias Hermann

unread,
May 14, 2016, 3:02:13 PM5/14/16
to Elm Discuss
OK, thanks guys. I will consider using ports for this. But perhaps I will abandon some projects completely. This one for example is around since Elm 0.10 and very far away from current best practice. :D

Tobias Hermann

unread,
May 15, 2016, 8:19:58 AM5/15/16
to Elm Discuss
I decided to update my old projects. It was a relatively big change to switch from signals to the Elm architecture, but I learned a lot and the code became easier to understand. But now I am back to my touch question. :D
Is there a specific reason the functionality is no longer available? I would think it is not that different from the mouse stuff, or is it?

Glen Mailer

unread,
May 15, 2016, 8:59:23 AM5/15/16
to Elm Discuss
If you skim over the code in the new mouse module, you'll see there's not a huge amount there.

You can probably write some very similar code using the "on" function in Html.Events with a custom decoder.

This has to be applied to an HTML element rather than being global, but if you pick something near the top of your tree you should get a similar effect

Hope that helps!
Glen

Tobias Hermann

unread,
May 15, 2016, 12:17:11 PM5/15/16
to Elm Discuss
Thanks. I now can get messages for a touchstart on a specific element if I use Json.Decode.succeed to produce a fixed message. Additionally I would like to get the pixel coordinates for the touches. Any ideas on how the decoder for this could look like?

Steve Schafer

unread,
May 16, 2016, 11:35:13 AM5/16/16
to Elm Discuss
That's like saying Elm supports everything, as long as you define "dropping out to JavaScript" as "part of Elm."

art yerkes

unread,
May 16, 2016, 2:09:26 PM5/16/16
to Elm Discuss
I do it like this:

D.oneOf [
D.at ["touches", "0"] (D.object2 TouchPosition ("pageX" := D.float) ("pageY" := D.float))
, D.object2 TouchPosition ("pageX" := D.float) ("pageY" := D.float) ]

Which can be bound to both touch and mouse events and yields whatever the event has.

Tobias Hermann

unread,
May 16, 2016, 2:44:59 PM5/16/16
to Elm Discuss
Thank you very much. It works.
In case anybody is interested, here is the full minimal example using the snippet: https://gist.github.com/Dobiasd/5aba6bbf872301977bc35790a04bfde0

John Bugner

unread,
Jul 26, 2016, 1:07:51 PM7/26/16
to Elm Discuss
May I ask why touch support disappeared? Was it hard to convert to using subscriptions or something?

(Sorry for bumping an 2-month-old thread, if I'm not supposed to do that.)

Janis Voigtländer

unread,
Jul 26, 2016, 1:35:07 PM7/26/16
to elm-d...@googlegroups.com

I don’t think there was a technical reason or specific complication. The Touch module had simply never been really finished API-wise, and during the transition from Elm 0.16 to 0.17 there was no priority to polish touch support in particular. So while stuff like Keyboard and Mouse and Graphics was taken out of core, but preserved with some modifications (mainly signals vs. subscriptions) in separate packages, Touch was dropped for the moment. I guess because it’s much less clear for it than for the other three mentioned modules what the “final” API will look like. (All that is just my inference from discussion traffic, I wasn’t privy to the decisions being made then and there.)

Rex van der Spuy

unread,
Jul 27, 2016, 12:36:26 PM7/27/16
to Elm Discuss


On Tuesday, July 26, 2016 at 1:35:07 PM UTC-4, Janis Voigtländer wrote:

 I guess because it’s much less clear for it than for the other three mentioned modules what the “final” API will look like.

 Would it make sense to combine both mouse and touch into a single `pointer` object?

OvermindDL1

unread,
Jul 27, 2016, 12:50:39 PM7/27/16
to Elm Discuss
As long as you have multiple pointer objects.

Linux supports multiple simultaneous mice (no clue if browsers do) so there is precedent there.  And touch's are basically multiple mice (although some interfaces expose a 'strength' or 'pressure' or so too to say how hard the person is touching).  Could easily be combined.

art yerkes

unread,
Jul 27, 2016, 1:18:28 PM7/27/16
to elm-d...@googlegroups.com
A proper expression of touch includes multiple touches that can come and go independently, along with extra parameters for each (pressure is one but velocity is another too).  Neither was relevant to the things I was writing but it'd be awesome to see a touch API that exposes touch fully in a way that doesn't get weighed down with model state or require too much boilerplate.

--
You received this message because you are subscribed to a topic in the Google Groups "Elm Discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/elm-discuss/6Dj7FyoQF2g/unsubscribe.
To unsubscribe from this group and all its topics, send an email to elm-discuss...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages