Author Topic: Suggestion: UIDraggablePanel with scrollbar  (Read 2438 times)

dlewis

  • Guest
Suggestion: UIDraggablePanel with scrollbar
« on: September 06, 2012, 01:10:45 AM »
I've just been playing around with clipped panels, scrollbars and the centerOnChild script. I have the scrollbars set to show only when dragging and I noticed that in combination with the CenterOnChild script it caused the scrollbar to fade out before the springPanel had a chance to finish.

I made a small modification to the UIDraggablePanel code which I think could be useful for other users.

From roughly line 600 in UIDraggablePanel
  1. // Only alpha if it's not springing
  2. SpringPanel spring = GetComponent<SpringPanel>();
  3. bool springing = false;
  4.  
  5. if ((spring != null && spring.enabled == true) || mMomentum.sqrMagnitude > 0)
  6. {
  7.         springing = true;
  8. }
  9.  
  10. if (verticalScrollBar)
  11. {
  12.         float alpha = verticalScrollBar.alpha;
  13.         alpha += (vertical || springing) ? delta * 6f : -delta * 3f;
  14.         alpha = Mathf.Clamp01(alpha);
  15.         if (verticalScrollBar.alpha != alpha) verticalScrollBar.alpha = alpha;
  16. }
  17.  
  18. if (horizontalScrollBar)
  19. {
  20.         float alpha = horizontalScrollBar.alpha;
  21.         alpha += (horizontal|| springing) ? delta * 6f : -delta * 3f;
  22.         alpha = Mathf.Clamp01(alpha);
  23.         if (horizontalScrollBar.alpha != alpha) horizontalScrollBar.alpha = alpha;
  24. }

edit: Modified the code so it makes more sense.
edit2: I also added some code so that if you fling the panel the scrollbar will not disappear until there is no momentum. It was fairly easy to get the objects in the panel moving but the scrollbar would completely fade away long before it stopped moving so I caught that case as well.
edit3: The spring panel could probably be cached to make it slightly faster as well.
« Last Edit: September 06, 2012, 09:01:34 PM by dlewis »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Suggestion: UIDraggablePanel with scrollbar
« Reply #1 on: September 06, 2012, 06:55:05 AM »
Cool, thanks for sharing!