Author Topic: Wrap Content not centering sometimes  (Read 6251 times)

Shifty Geezer

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 9
  • Posts: 226
    • View Profile
Wrap Content not centering sometimes
« on: December 27, 2015, 10:20:19 AM »
Using a scrollview with a UIWrapContent component as per the examples, if I click an item it centres, but if I drag the scrollview, sometimes the item doesn't snap to the centre. The items are 110 pixels wide. If I set the UIWrapContent's Item Width to 110, it never centres on items. If I set Item Width to 100, it centres most times.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Wrap Content not centering sometimes
« Reply #1 on: December 27, 2015, 05:07:16 PM »
The width shouldn't matter in this case. I'd need a repro case to better understand the issue.

Shifty Geezer

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 9
  • Posts: 226
    • View Profile
Re: Wrap Content not centering sometimes
« Reply #2 on: December 30, 2015, 04:44:07 PM »
Just tried creating a new test project and NGUI 3.9.6c has a broken Example 14. New Unity project. Import NGUI. Run example 14. The middle vertical scrollview of green numbers won't drag properly or centre on item when clicked. It seems to work if I resize the window although not smoothly as it wrestles between snapping to centre and scrolling.

The other scrollviews seem to be scrolling twice the mouse speed. Is there an intentional acceleration in effect? I can't see an option for that.
« Last Edit: December 30, 2015, 04:49:17 PM by Shifty Geezer »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Wrap Content not centering sometimes
« Reply #3 on: January 01, 2016, 07:14:59 PM »
You're right, something odd is going on there. I'm going to look into it...

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Wrap Content not centering sometimes
« Reply #4 on: January 01, 2016, 09:24:23 PM »
Ok found the issue. UIDragScrollview.OnDisable should be changed to:
  1.         void OnDisable ()
  2.         {
  3.                 if (mScroll != null && mScroll.GetComponentInChildren<UIWrapContent>() == null)
  4.                 {
  5.                         mScroll.Press(false);
  6.                         mScroll = null;
  7.                 }
  8.         }
P.S. Also uploaded 3.9.6d with the same fix for your convenience.
« Last Edit: January 01, 2016, 09:36:56 PM by ArenMook »

Shifty Geezer

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 9
  • Posts: 226
    • View Profile
Re: Wrap Content not centering sometimes
« Reply #5 on: January 02, 2016, 02:27:43 PM »
Thanks. The original issue was my problem - I had "Centre On Child" on every item in the list.

Amsterdam

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Wrap Content not centering sometimes
« Reply #6 on: February 05, 2016, 07:28:13 AM »
Ok found the issue. UIDragScrollview.OnDisable should be changed to:
  1.         void OnDisable ()
  2.         {
  3.                 if (mScroll != null && mScroll.GetComponentInChildren<UIWrapContent>() == null)
  4.                 {
  5.                         mScroll.Press(false);
  6.                         mScroll = null;
  7.                 }
  8.         }
P.S. Also uploaded 3.9.6d with the same fix for your convenience.

Hey. I have issue with this solution! Im attach UIPanel (Clipping = Constraint But Dont Clip) + UIScrollView( DragEffect = Momentum And Spring, RestrictWithinPanel = true) to my game object. And at next i put items with UIDragScrollView component into grid container, which is the child of Scroll View. This work correctly. But if i want remove items from this scroll list then it call restrictWithinPanel automatically and move scroll view.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Wrap Content not centering sometimes
« Reply #7 on: February 07, 2016, 12:17:53 AM »
I'll need a more detailed explanation, Amsterdam. How can I reproduce the issue with one of NGUI's examples?

Amsterdam

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Wrap Content not centering sometimes
« Reply #8 on: February 08, 2016, 04:17:40 AM »
I'll need a more detailed explanation, Amsterdam. How can I reproduce the issue with one of NGUI's examples?
Hey! You need to create scroll list using UIPanel with Clipping = Constraint But Dont Clip and using UIScrollView with DragEffect equals to Momentum and Spring and RestrictWithinPanel equals to true. At next you need to create scroll list items with UIDragScrollView component and put this items to UIGrid as a childs. In the play mode scroll list to some item. If you do something that is call OnDisable in UIDragScrollView components of scroll list items, then your ScrollView will make the call RestrictWithinBounds, and this spring your panel. If i remove
  1.        
  2.         void OnDisable ()
  3.         {
  4.                 if (mScroll != null && mScroll.GetComponentInChildren<UIWrapContent>() == null)
  5.                 {
  6.                         mScroll.Press(false);
  7.                         mScroll = null;
  8.                 }
  9.         }
  10.  

this code from UIDragScrollView, all works correctly.

P.S. Im use pool for contains my scroll list items. Pool's root game object is disabled, and if i return items to pool, then items are disabled after changing parent transform to pool's root game object, which brings to a call OnDisable in UIDragScrollView.


Hierarchy image


ScrollView inspector image


Scroll list item inspector image

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Wrap Content not centering sometimes
« Reply #9 on: February 09, 2016, 02:43:22 AM »
Well, if your particular case is fixed by removing that, then keep it like that. If I remove it on my end, it will break the issue it resolved in the first place.

RaHaN

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: Wrap Content not centering sometimes
« Reply #10 on: February 09, 2016, 05:38:17 PM »
Hello Everyone,

I'm fairly new to nGUI, so I may have missed something, but I stumbled upon this topic and it may actually be the issue I'm facing.

I have a simple infinite vertical scrollview with 0 to 9 numbers, and I'm trying to have it center on elements, so I used the following (simple) structure:

|- ScrollView (UI Scroll View script)
   |-- Wrapper (UI Wrap Content) + UI Center on Child
      |--- 0 (UI Drag Scroll View)
      |--- 1 (UI Drag Scroll View)
      |--- 2 (UI Drag Scroll View)
      |--- 3 (UI Drag Scroll View)
      |--- 4 (UI Drag Scroll View)
      |--- 5 (UI Drag Scroll View)
      |--- 6 (UI Drag Scroll View)
      |--- 7 (UI Drag Scroll View)
      |--- 8 (UI Drag Scroll View)
      |--- 9 (UI Drag Scroll View)


Th scrolling and wrapping work perfectly fine, but not the Center on Child feature. It just appears to scroll freely, despite the Center On Child script being attached to my wrapper object, UNLESS I click, then it centers correctly (however, it's not the Center On Click script I used, I assure you :p).

Could it be because of the same issue raised by the OP ?

(added screenshots of my inspectors and hierarchy to make sure)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Wrap Content not centering sometimes
« Reply #11 on: February 10, 2016, 05:41:57 PM »
Seems to be how the endless scroll views example is set up for the green cells and it works as expected. What's different?

RaHaN

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: Wrap Content not centering sometimes
« Reply #12 on: February 11, 2016, 07:26:03 AM »
Thanks for that quick answer.

Well, now that you mention it, it doesn't seem to work either on the example (I assume you are talking about example 14's middle vertical  row) when I load it in my project.

I'm running Unity 5.3.1 and nGUI 3.9.6d. I'm seeing now there's an update - I'll install it and see.

Other than that, I guess I'll have to try on a new blank project first. Any initial thoughts on where it may come from ? (the only other thing I'm running with is Playmaker, and there isn't much in the project yet).

EDIT - I updated everything, started a new blank project, imported the latest nGUI package and opened the Example 14's scene; it still behaves as observed, meaning it doesn't automatically center on the children, only does when I click...
« Last Edit: February 11, 2016, 07:40:23 AM by RaHaN »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Wrap Content not centering sometimes
« Reply #13 on: February 12, 2016, 08:37:11 PM »
I just tried NGUI 3.9.7 with Unity 5.3.2 just to be sure. Opened example 14, hit Play. The central scroll view automatically centers on "2". When I drag and release, it gets re-centered on the appropriate item as expected.

RaHaN

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: Wrap Content not centering sometimes
« Reply #14 on: February 14, 2016, 12:27:08 PM »
So I tried opening the project on my PC rather than my mac, and it does work fine.

I'm even more puzzled now :O