Author Topic: UIScrollView Jumps on button click  (Read 4156 times)

AeornFlippout

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 46
    • View Profile
UIScrollView Jumps on button click
« on: August 13, 2014, 11:14:54 AM »
I'm seeing an issue in 3.68 where, when I select a button in a draggable scrollview with a controller or the enter key, the list suddenly jumps upon release of the button.

I'm still investigating the exact cause here. It seems that releasing a key sends a series of events that eventually causes the panel to start a Drag() event, and a raycast results in a non-zero offset.
It's not clear to me if it's intended that a key press should result in a drag like this that seems to be looking at drag/touch values.

I'll reply here if I can determine with more accuracy what's going on, but if anyone's seen this type of thing or has any ideas, I'd love to hear!


AeornFlippout

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 46
    • View Profile
Re: UIScrollView Jumps on button click
« Reply #1 on: August 13, 2014, 11:32:45 AM »
I shuld also note that the jump seems more or less severe based on where the mouse is at the time on the screen.
Feels like the wires are being crossed a bit here, I just haven't nailed down exactly how.

AeornFlippout

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 46
    • View Profile
Re: UIScrollView Jumps on button click
« Reply #2 on: August 13, 2014, 01:48:18 PM »
So, the intricacies of the input processing for key presses and how ProcessTouch() works are still a bit beyond me, but I did find what appears to be a solution...

It seems that this code that processes the submit press/unpress:
  1. if (submitKeyDown || submitKeyUp)
  2.       {
  3.          currentScheme = ControlScheme.Controller;
  4.          
  5.           currentTouch.last = currentTouch.current;
  6.           currentTouch.current = mCurrentSelection;
  7.          
  8.          
  9.          ProcessTouch(submitKeyDown, submitKeyUp);
  10.          currentTouch.last = null;
  11.       }
  12.  

Guarantees that when the un-press happens, currentTouch.current is not equal to currentTouch.last.

This in turn triggers this code:
  1.         // If the drag process hasn't started yet but we've already moved off the object, start it immediately
  2.                         if (!currentTouch.dragStarted && currentTouch.last != currentTouch.current)
  3.  

This ultimately means that Drag() gets called on the scroll view, which seems to be looking at mouse/touch deltas or something and coming up with some bogus values that aren't relevant.

My solution was to swap these two lines around, which has the end result that a submit key release won't be considered a "drag" event at all:

  currentTouch.last = currentTouch.current;
  currentTouch.current = mCurrentSelection;

Does that seem like an appropriate fix?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIScrollView Jumps on button click
« Reply #3 on: August 14, 2014, 07:25:54 AM »
I can see that breaking something else. You're basically getting rid of sending drag events with controller. What if you wanted to press on one button, navigate to another, then release, thus doing a drag & drop with a controller? (think tile swapping game)

A better way would be to ignore drag events on the scroll view if the input device happens to be a controller. Add this to the top of UIScrollView.Drag:
  1. if (UICamera.currentScheme == UICamera.ControlScheme.Controller) return;
P.S. You may also need to add the same line to UIScrollView.Press as well.