mwcraig / ipyevents

A custom widget for returning mouse and keyboard events to Python. Documentation:
https://ipyevents.readthedocs.io/en/latest/index.html
BSD 3-Clause "New" or "Revised" License
112 stars 27 forks source link

added basic touch functionality #63

Closed akaszynski closed 3 years ago

akaszynski commented 3 years ago

Touch Events

This PR adds a basic interface to the following touch events:

It's not perfect; _get_position doesn't work as touch events don't appear to have client* attributes, but they do have page* attributes that can be used instead to provide relative (x, y) coordinates.

It actually works quite well, though ideally mouse_standard_event_message_names would have a touch corollary (though, mouse events still work quite well).

mwcraig commented 3 years ago

@akaszynski -- I'm (finally) getting around to looking at this. Are you ok with something like this getting merged?

akaszynski commented 3 years ago

Totally!

mwcraig commented 3 years ago

@akaszynski -- I'll flesh this out a bit (adding touch_standard_event_message_names, looking for other places to make the touch interface similar to mouse and keyboard) unless you would prefer to do that. I'm fine either way, and have the time this week to wrap it up.

mwcraig commented 3 years ago

I hadn't really understood how touch events work until I started revising this. It turns out the location information is buried one level deeper than top-level touch event. The touch events have three lists attached, each of which consists of an individual touch point on the screen. Those individual touch points have essentially the same position attributes as a mouse event.

That means that using the position information from a touch event is a little more convoluted than using the position information from a mouse event. Getting clientX, for example, when there is a single touch point on the screen means doing event['changedTouches'][0]['clientX'] which is a little convoluted.

Though this could maybe be simplified if there is only one touch point it seems better to mirror the format of the HTML TouchEvent which contains three TouchLists of individual Touch points.

mwcraig commented 3 years ago

@akaszynski -- can you take a quick look at this when you get a chance?

mwcraig commented 3 years ago

Merging so that the new features can be released :)

mwcraig commented 3 years ago

@akaszynski -- this has been released in 0.9.0. I'm planning to release the first stable version, 2.0.0, tomorrow.

0.9.0 supports jlab 2 and 3. The stable release will support only jlab3 and higher.