Author Topic: "Endless" scrolling + Drag and Drop  (Read 3756 times)

tanner027

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
"Endless" scrolling + Drag and Drop
« on: May 13, 2014, 11:40:54 AM »
Hello NGUI-ans,
I'm trying to combine the endless scroll (UIWrap) with the drag and drop capabilities and I feel that I'm missing something silly. I'm starting with the endless scrolling NGUI example and then adding the drop/drop resources where they belong. When all is said and done I have endless scrolling with drag and drop capabilities but the scroll view layout gets all screwy (there are blank positions in the view, spacing seems off).

I haven't really dug my claws into what's going on in these examples code-wise but I'm really reaching out to see anyone has done this before and has some straightforwards steps. If not maybe a hint in the right direction of a function to start at. Any help is appreciated. I will post updates if I stumble on a solution or if I can bring anymore details to the front.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: "Endless" scrolling + Drag and Drop
« Reply #1 on: May 14, 2014, 05:36:44 AM »
UIWrapContent script caches the list of children (UIWrapContent.mChildren). If you add things dynamically, you will need to update this list. Call UIWrapContent.SortBasedOnScrollMovement() to do this.

tanner027

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: "Endless" scrolling + Drag and Drop
« Reply #2 on: May 14, 2014, 11:58:24 AM »
So I've got some items populated on the Grid/WrapContent via code and that all looks fine. The issue comes from when the drag/drop happens. It seems like the WrapContent is attempting to do its SortBasedOnScrollMovement bit at the same time that the Grid is running Reposition() which is messing up the arrangement.

The Grid provides a lot of the functionality that I need (like adding children and constrain to panel) so I think I'm going to attempt to integrate the "endless" logic in UIGrid (or something derived from it). If you had advice on the best way to get these two to play nicely together I would love to hear it.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: "Endless" scrolling + Drag and Drop
« Reply #3 on: May 14, 2014, 11:32:31 PM »
You should not mix grids and wrap content, as both reposition children. It doesn't make sense to have both active -- one will simply override what the other did -- so customization is indeed the way to go here.

tanner027

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: "Endless" scrolling + Drag and Drop
« Reply #4 on: May 23, 2014, 01:58:51 PM »
On the subject of the endless scroll: if someone is looking to add content to a wrapper dynamically and get the "wrap" portions to work correctly, the following code snippet worked for me
  1.                         // after all content is added to the Wrapper
  2.                         wrapper.SortBasedOnScrollMovement();
  3.                         wrapper.WrapContent();
  4.