Author Topic: UIDraggablePanel Snapping to item  (Read 9385 times)

soofaloofa

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 27
    • View Profile
UIDraggablePanel Snapping to item
« on: April 18, 2012, 06:04:27 PM »
Hi,

I have a grid contained within a UIDraggablePanel. My goal is to have the draggable panel focus on a specific element in the grid programmatically. Any advice?

I'm looking at the UIDraggablePanel.SetDragAmount function and thinking I could calculate the total number of items in my grid and the position of the item I want to focus; then taking this as a percentage pass the value to SetDragAmount.

Is there a better way?

Kevin

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIDraggablePanel Snapping to item
« Reply #1 on: April 18, 2012, 08:27:22 PM »
The snapping to items is an often-requested feature that I'll add in a future update, but for now you can indeed achieve what you want by using SetDragAmount.

soofaloofa

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 27
    • View Profile
Re: UIDraggablePanel Snapping to item
« Reply #2 on: May 05, 2012, 01:58:17 PM »
Hi,

Any update on adding this to NGUI. I'm debating whether to start programming this on my own or wait for a future NGUI update.

Thanks,

Kevin

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIDraggablePanel Snapping to item
« Reply #3 on: May 05, 2012, 02:23:57 PM »
I haven't done any work on this yet.

soofaloofa

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 27
    • View Profile
Re: UIDraggablePanel Snapping to item
« Reply #4 on: May 11, 2012, 12:25:20 PM »
I started my implementation and have a quick question. I've calculated the position of each of my pages as a percentage of the draggable panel size.

I have something like this:

  1. float scrollAmount = desiredChildNumber/totalNumberOfChildren;
  2. scrollBar.scrollValue = scrollAmount; // scrollbar is set to a UIScrollbar component
  3.  

This works great to reposition my draggable panel on the desired child transform. What I want to do is LERP the UIScrollbar.scrollValue so that the transition to the next position is done smoothly.

Could you provide an example of how this would be done?

Thanks again!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIDraggablePanel Snapping to item
« Reply #5 on: May 11, 2012, 02:49:56 PM »
Not sure I understand the complexity in this... just have some script (or write a tweener) interpolate from A to B, and update the scroll bar's scrollValue.

soofaloofa

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 27
    • View Profile
Re: UIDraggablePanel Snapping to item
« Reply #6 on: May 11, 2012, 03:39:02 PM »
Yes that's exactly what I would like to do. I just don't understand Lerp functions that well. I'll read up on it and try it out.