Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix click drag on touch + WebBrowsers #563

Merged

Conversation

FrostKiwi
Copy link
Contributor

@FrostKiwi FrostKiwi commented Jun 26, 2023

This one has been driving me insane. Each time I tested my WebApp on a touch device, like a Smartphone, tablet, iPad, what have you, Window resizing and the property click-drag behavior was busted. Touch works a bit differently on Webbrosers and doesn't update the mouse position regularly, which leads to huge deltas, as Nuklear just saves the previous frame's mouse position.

This PR fixes this by setting the drag during the click part of the click-drag to zero. This fixes the breaking behaviour in the video below. Thanks to Chrome's mobile device emulation, I tracked it down. Why this doesn't occur on Scrollbars and Window dragging, I'm not sure, but this seems to be a fix without having a negative effect on other things.

2023-06-26.19-46-09.1.mp4

@FrostKiwi FrostKiwi changed the title Fix click drag on touch + WebBroswers Fix click drag on touch + WebBrowsers Jun 26, 2023
@dumblob
Copy link
Member

dumblob commented Jun 27, 2023

Just a clarification - the video recording of your setup is before or after applying this patch?

It looks horrendously jumpy - "touch and drag" makes the window resize seemingly in the next frame and first then starts the actuall "resize" operation from there on.

@FrostKiwi
Copy link
Contributor Author

Just a clarification - the video recording of your setup is before or after applying this patch?

It looks horrendously jumpy - "touch and drag" makes the window resize seemingly in the next frame and first then starts the actuall "resize" operation from there on.

Ohh, should have led with that^^
The video is before the patch. That horrible jumping is exactly what has driving me insane and can also be observed straight in the SDL2 Web demo of Nuklear, when using the browser on a touch enabled device.

@dumblob
Copy link
Member

dumblob commented Jun 28, 2023

I have to admit I do not have any quick way to test this now. Would you mind if I left this PR opened until someone picks it up and tests it?

It sounds too important to make a mistake - so I would rather want others to test it with several backends on mobile as well as non-mobile devices.

@FrostKiwi
Copy link
Contributor Author

FrostKiwi commented Jun 29, 2023

I have to admit I do not have any quick way to test this now. Would you mind if I left this PR opened until someone picks it up and tests it?

It sounds too important to make a mistake - so I would rather want others to test it with several backends on mobile as well as non-mobile devices.

Sure 👍
I will have the WebApp here if you want to test it with your own:
https://mirror.frost.kiwi
It will replaced by a pure js rewrite next week (almost done), but the WASM + Nuklear branches will stay online. In that state the touch jumping is fixed via commit FrostKiwi/Mirrorball@d66f393 And this is the commit prior with all the jumping and stuff: FrostKiwi/Mirrorball@5ec9aa4

Since the Nuklear WebApp is autocompiled via GitHub actions and auto-published via GitHub pages, you can just make changes to compare right in GitHub and watch it being deployed 5 mins later automatically. https://github.com/FrostKiwi/frostorama/actions/runs/5377023469/jobs/9754955853

The SDL2 demo within this repo should show the same behavior: https://github.com/Immediate-Mode-UI/Nuklear/tree/master/demo/sdl_opengles2

You can test via a mobile, touch enabled device or by going into chrome and turning on mobile device emulation in the dev panel. The crux of the bug stems from the way input is not being updated, even though the event and rendering loop are, which is an optimization that browsers perform, leading to big deltas being computed in this line

in->mouse.delta.x = in->mouse.pos.x - in->mouse.prev.x;

Copy link
Contributor

@RobLoach RobLoach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this makes sense. The issue could happen if you're moving the mouse and then initiate the drag at the same time? Tested locally, and while I wasn't quite able to reproduce the issue, I was able to confirm things are still working.

@RobLoach
Copy link
Contributor

RobLoach commented Aug 3, 2023

After a bit more testing, I think this is good to go. Let's merge this, and then revert if there are reports of mouse movement being borked.

@RobLoach RobLoach merged commit 614abce into Immediate-Mode-UI:master Aug 3, 2023
@dumblob
Copy link
Member

dumblob commented Aug 5, 2023

Thanks @RobLoach for spending some time with & merging this (also all the other PRs recently). Really appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants