Author Topic: Drag & Drop first item padding  (Read 4248 times)

slumtrimpet

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 3
  • Posts: 13
    • View Profile
Drag & Drop first item padding
« on: July 01, 2014, 01:17:17 PM »
In Example 11, if you grab items and drop them in the 'first' slot at the top of the list you'll see the padding on that first cell get larger and larger as you drop more items in "slot one". 

I assume the scroll position of the scroller is being incremented unnecessarily when items are dropped here.  Is there a fix for this short of listening for an event manually and resetting the scroller position?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Drag & Drop first item padding
« Reply #1 on: July 02, 2014, 05:06:50 AM »
I don't quite follow. What padding are you talking about? I see nothing abnormal as I drag items over. The scroll position remains at the position it was prior to the drop.

slumtrimpet

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 3
  • Posts: 13
    • View Profile
Re: Drag & Drop first item padding
« Reply #2 on: July 03, 2014, 11:10:55 AM »
I've created a video demonstrating the issue.  What I'm doing here is dragging a few items out of the left hand side column so it's no longer 'full' then I show how dragging items to the first position in that column seems to inflate the padding on that first cell.

http://youtu.be/TZhyO7SUcEE

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Drag & Drop first item padding
« Reply #3 on: July 04, 2014, 01:23:41 PM »
Ah, likely related to the scroll view trying to maintain its current scrolled position with you changing the first item.

slumtrimpet

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 3
  • Posts: 13
    • View Profile
Re: Drag & Drop first item padding
« Reply #4 on: July 07, 2014, 07:52:56 AM »
Right, so just so we are on the same page...  does that mean you agree there is an issue and might take a look at it, or do you think this is a corner case I've hit that I should piece together a workaround for myself?  (Either answer is ok... just trying to deduce what the direction was from your last reply so I'm not waiting when I should be coding  :) )
« Last Edit: July 07, 2014, 08:10:14 AM by slumtrimpet »

slumtrimpet

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 3
  • Posts: 13
    • View Profile
Re: Drag & Drop first item padding
« Reply #5 on: July 07, 2014, 11:32:33 AM »
Here's my hack fix... found that the UIDragScrollView was being enabled too soon so it was registering a drag instead of just reordering items. 

(All changes to vanilla noted with 'XX' below... please let me know if you might plan to incorporate something like this in a future release, I'd much rather use your base class instead of my hack subclass)

Thanks!

  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class XXUIDragDropItem : UIDragDropItem {
  5.  
  6.   override protected void OnDragDropRelease (GameObject surface)
  7.         {
  8.                 if (!cloneOnDrag)
  9.                 {
  10.                         mTouchID = int.MinValue;
  11.  
  12.                         // Re-enable the collider
  13.                         if (mButton != null) mButton.isEnabled = true;
  14.                         else if (mCollider != null) mCollider.enabled = true;
  15.  
  16.                         // Is there a droppable container?
  17.                         UIDragDropContainer container = surface ? NGUITools.FindInParents<UIDragDropContainer>(surface) : null;
  18.  
  19.                         if (container != null)
  20.                         {
  21.                                 // Container found -- parent this object to the container
  22.                                 mTrans.parent = (container.reparentTarget != null) ? container.reparentTarget : container.transform;
  23.  
  24.                                 Vector3 pos = mTrans.localPosition;
  25.                                 pos.z = 0f;
  26.                                 mTrans.localPosition = pos;
  27.                         }
  28.                         else
  29.                         {
  30.                                 // No valid container under the mouse -- revert the item's parent
  31.                                 mTrans.parent = mParent;
  32.                         }
  33.  
  34.                         // Update the grid and table references
  35.                         mParent = mTrans.parent;
  36.                         mGrid = NGUITools.FindInParents<UIGrid>(mParent);
  37.                         mTable = NGUITools.FindInParents<UITable>(mParent);
  38.  
  39.                         // Re-enable the drag scroll view script
  40.                         if (mDragScrollView != null)
  41.                           /*XX*  mDragScrollView.enabled = true; */
  42.                           /*XX*/ StartCoroutine(this.activateScrollViewLater());
  43.  
  44.                         // Notify the widgets that the parent has changed
  45.                         NGUITools.MarkParentAsChanged(gameObject);
  46.  
  47.                         if (mTable != null) mTable.repositionNow = true;
  48.                         if (mGrid != null) mGrid.repositionNow = true;
  49.  
  50.                 }
  51.                 else NGUITools.Destroy(gameObject);
  52.         }
  53.  
  54.   /*XX ADD****************************/
  55.   IEnumerator activateScrollViewLater() {
  56.     yield return new WaitForEndOfFrame();
  57.     mDragScrollView.enabled = true;
  58.   }
  59.   /*XX ADD END************************/
  60.  
  61. }
  62.  

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Drag & Drop first item padding
« Reply #6 on: July 08, 2014, 08:51:08 AM »
Nice fix, and thank you for taking the time to investigate it. :)

I'll certainly add your changes to the current version.