Author Topic: Scroll View Snap to Item and Drag Issue  (Read 22181 times)

MetaMythril

  • Guest
Scroll View Snap to Item and Drag Issue
« on: May 27, 2012, 01:06:06 AM »
I've created a scroll list to scroll through about 3 full screen panels that make up a map with buttons attached to each panel for stage selection. I'm trying to figure out how to best "snap" to the closest item in the list.

I'm also having an issue when dragging the panels, the first and last panel are able to be dragged to half of the screen width.



Any help would be greatly appreciated!
« Last Edit: May 27, 2012, 10:53:32 AM by MetaMythril »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Scroll View Snap to Item and Drag Issue
« Reply #1 on: May 27, 2012, 12:41:04 PM »
When you release the mouse, figure out the distance to the center of each of your map pieces. Choose the closest one, and SpringPosition there.

I am not quite sure what you mean by the last part.

MetaMythril

  • Guest
Re: Scroll View Snap to Item and Drag Issue
« Reply #2 on: May 27, 2012, 12:48:25 PM »
When you release the mouse, figure out the distance to the center of each of your map pieces. Choose the closest one, and SpringPosition there.

I am not quite sure what you mean by the last part.

I'm not quite sure how to use SpringPosition, do you have an example somewhere?

As for the last problem. What I'm saying is that the edge of the map should not go to the half point of the screen but for some reason it is. For example, in your Scroll View example, the edge of last and first items should meet the edge of the scroll view area when released, for some reason my map piece just stays anywhere between the edge and the half way point of the screen.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Scroll View Snap to Item and Drag Issue
« Reply #3 on: May 27, 2012, 12:50:11 PM »
  1. SpringPosition.Begin(gameObjectToMove, targetPosition, strength);

...where 'strength' is how fast you want it to move. 3 is slow and smooth, 8 is quick. 1000 is instant.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Scroll View Snap to Item and Drag Issue
« Reply #4 on: May 27, 2012, 12:52:12 PM »
Make sure "Restrict Within Panel" checkbox is checked on UIDraggablePanel.

MetaMythril

  • Guest
Re: Scroll View Snap to Item and Drag Issue
« Reply #5 on: May 27, 2012, 12:56:34 PM »
Make sure "Restrict Within Panel" checkbox is checked on UIDraggablePanel.

That option is checked, which makes it odd why it's not stopping at the edge of the item.

MetaMythril

  • Guest
Re: Scroll View Snap to Item and Drag Issue
« Reply #6 on: May 27, 2012, 12:59:38 PM »
  1. SpringPosition.Begin(gameObjectToMove, targetPosition, strength);

...where 'strength' is how fast you want it to move. 3 is slow and smooth, 8 is quick. 1000 is instant.

So basically I'll need to add a custom script attached to the panel to check the distance and apply the SpringPosition of the child objects in the UIGrid?

I really appreciate the help with this. :)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Scroll View Snap to Item and Drag Issue
« Reply #7 on: May 27, 2012, 01:20:07 PM »
Not to the panel but to whatever you're dragging. The same object that has UIDragPanel.

MetaMythril

  • Guest
Re: Scroll View Snap to Item and Drag Issue
« Reply #8 on: May 27, 2012, 02:21:18 PM »
Not to the panel but to whatever you're dragging. The same object that has UIDragPanel.

I'm using UIDragPanelContents if that makes any difference.

Any ideas about the scrolling of my objects past the edge?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Scroll View Snap to Item and Drag Issue
« Reply #9 on: May 27, 2012, 02:27:24 PM »
The ability to scroll past the edge is in the dragging style specified on UIDraggablePanel. MomentumAndSpring is the default, which means you can go past the edge. Try others.

The springing back into place after you release the mouse button is what "Restrict Within Panel" does.

MetaMythril

  • Guest
Re: Scroll View Snap to Item and Drag Issue
« Reply #10 on: May 27, 2012, 11:49:13 PM »
The ability to scroll past the edge is in the dragging style specified on UIDraggablePanel. MomentumAndSpring is the default, which means you can go past the edge. Try others.

The springing back into place after you release the mouse button is what "Restrict Within Panel" does.

That's the problem, it's not springing back to the edge (if you use MomentumAndSpring). It will let me pull it all the way off screen, then it will only spring the left side of the map to the middle of the screen instead of going all the way back to the left side.

I'm also using the "Restrict Within Panel" option, so I'm not sure what I'm missing.

MetaMythril

  • Guest
Re: Scroll View Snap to Item and Drag Issue
« Reply #11 on: May 28, 2012, 12:40:32 AM »
Ok, I managed to fix the issue. It seems that when I set it to "Hard Clip" that I needed to set the size of the clipping area. For some reason it was rendering fine without defining this, but was causing issues with dragging. After I defined the clipping size it is working fine.

Now I just need to get the snapping done. Thanks again for the help, sorry to be a bit of a pain. My first day really sitting down to use this. Though I've been reading and watching plenty of material to get me started. So far I'm making amazing progress with my UI that took me a lot more time when I was using EZ GUI. :)

MetaMythril

  • Guest
Re: Scroll View Snap to Item and Drag Issue
« Reply #12 on: June 03, 2012, 03:58:20 PM »
Not to the panel but to whatever you're dragging. The same object that has UIDragPanel.

Just not getting back to this after dealing with other issues. How do I determine that I have stopped dragging so that I can apply the snap? I don't see anything exposed that could be useful.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Scroll View Snap to Item and Drag Issue
« Reply #13 on: June 03, 2012, 07:33:28 PM »
You get OnPress(false) when you release the touch.

MetaMythril

  • Guest
Re: Scroll View Snap to Item and Drag Issue
« Reply #14 on: June 05, 2012, 11:25:19 PM »
Thanks, though I'm still having problems. Seems like trying to move the drag panel with SpringPosition has issues with the clipping.

Would love to see something like magnet snapping for items in a scroll view as a standard feature. I'm still new to this system so it's a bit difficult to know what I can and can't do at the moment, so I'm probably approaching things from the wrong angle.

I know EZGUI had the snapping feature but obviously it probably doesn't translate well over to NGUI.

Any other help you could offer with this? I greatly appreciate the help.