kettle11 / kapp

A pure Rust window and input library for Windows, Mac, and Web. (Work in progress)
Apache License 2.0
56 stars 4 forks source link

Refactor double click events, implement them for web #50

Closed lunabunn closed 3 years ago

lunabunn commented 3 years ago

Fixes https://github.com/kettle11/kapp/issues/21 EXCEPT implementing DoubleClickUp for Windows. The detail property is always 0 for pointerdown (https://github.com/w3c/pointerevents/issues/98), so I had to add mousedown just for the double clicks.

lunabunn commented 3 years ago

One naive implementation we could use for Windows is to have 4 AtomicBools for each button type, set them to true when they're double clicked, then in the mouse up callbacks check for the values to fire DoubleClickUp. Windows doesn't seem to provide a direct way to fire events on double click up.

However, I'm not sure with this approach what will happen if the user double clicks in the window, drags the mouse outside the window without releasing the double click, releases the double click, comes back into the window, then presses & releases the button again. If BUTTONDOWN events are guaranteed to fire before BUTTONDBLCLICK events, (BUTTONDOWN isn't fired on double clicks) we could set the bools to false in BUTTONDOWN?

lunabunn commented 3 years ago

Implemented "naive" approach described above, seems to work well. If a better method were to be found, that could be its own PR, but for now this should be "good enough".

Should be ready for merge, if you're okay with the API changes! 🎉

kettle11 commented 3 years ago

Lots of great stuff. Thanks!

I'll merge this now, but I think we should also add a comment somewhere to the Windows code about why we're using the atomic bools. I'm very bad about forgetting why things like that are necessary when I'm reviewing code in the future.