Bug (and possible fix): Viewport dragging on touch screens with multiple fingers

Hi guys :slight_smile:

When enabling finger dragging on the Viewport class via setScrollOnDragEnabled, the dragging process can be interrupted when the user touches the screen with a second finger.

It all boils down to this line in juce_Viewport.cpp:

if (Desktop::getInstance().getNumDraggingMouseSources() == 1 && ! doesMouseEventComponentBlockViewportDrag (e.eventComponent))

I see what you did here (avoid having multiple fingers dragging the same viewport), but I think that rather than checking if the number of mouse sources is 1, the code should check that the dragging source is the one that actually started the dragging on the Viewport. The current code causes the interruption of the drag not only for the linked Viewport, but also for other Viewports where a second finger is added.

I bet (haven’t really tried it though) that if you add two instances of ListBox in the same Component, the user isn’t currently able to drag them both at the same time, using two separate fingers.

So, on to the fix: what about having a member pointer to the MouseInputSource that started the dragging? At mouseDown, if the pointer is invalid, you take it from the incoming MouseEvent reference, then you use it to do the checking at mouseDrags and finally, if that’s the one being removed, you reset it to nullptr at mouseUp.

Cheers :clinking_glasses:

2 Likes

Here’s a patch. I ended up using a member variable instead of a pointer.
Let me know what you think…

Viewport.patch (2.6 KB)

1 Like

:crying_cat_face:

3 Likes

There’s also a problem with the inertia. Recently @SQUARESEQUENCE posted a workaround which addresses both issues:

The other issue is that swiping pages with GUI elements does not work as one would expect. If one begins a swipe movement over a button, one expects to swipe the viewport, not click the button. So one needs a considerable amount of custom code to get things to work properly and things get tricky when it comes to comboboxes, sliders, a viewport inside the viewport, etc.

I think an update of the Viewport which fixes these issues and adds a swiping mode which behaves as in iOS and Android would be a very reasonable feature request!

1 Like

Oh I see. I ended up doing basically the same thing (using an external class), but yeah, I agree: these things should be fixed in the library.

1 Like

Thanks for your patience. I’ve put together a fix for the initial issue (secondary touches interrupting Viewport scrolling), but we’re currently only merging very high-priority bugfixes to develop so that we can put out a bugfix release in a week or so. The fix for this issue will probably land on develop shortly after this bugfix release.

3 Likes

28d313beb008de8213ebcb4bb7d45c97_400x400

2 Likes

This issue should be fixed by this patch:

Please try it out and let us know if you encounter any new issues.

Fantastic, thanks :smiley_cat:

Great, thanks!