Author Topic: Tiny cosmetic issue with adding items to scrollable view  (Read 4451 times)

prinky

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 13
    • View Profile
Tiny cosmetic issue with adding items to scrollable view
« on: March 21, 2014, 01:47:40 AM »
So I have a scrollable view with a scrollbar (vertical). There is a grid inside of the scrollable panel.  The items are added after the scene loads via a script attached to the uigrid object. Something like this:
  1. int levelIndex = 0;
  2. foreach(string levelName in mLevelNames)
  3. {
  4.   Transform newLevelItem = NGUITools.AddChild(this.gameObject,   mLevelItemPrefab.gameObject).transform;
  5.   MenuLevelItem menuLevelItem =  newLevelItem.GetComponent<MenuLevelItem>();
  6.   menuLevelItem.mLevelName = levelName;
  7.   newLevelItem.name = levelIndex.ToString("00");
  8.   newLevelItem.localScale = new Vector3(1.0f, 1.0f, 1.0f);
  9.   newLevelItem.localPosition = new Vector3(0.0f, 0.0f,0.0f);
  10.   menuLevelItem.DisableButton();
  11.   levelIndex++;
  12. }
  13.  

The items are added correctly...however the scrollbar foreground (the draggable part) appears to be the incorrect size. It corrects itself after I start to scroll the area, which is a bit jarring. Setting repositionNow to true on the UIGrid doesn't seem to help, and neither does calling ResetPosition on the UIScrollView. Any thoughts? Thanks.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tiny cosmetic issue with adding items to scrollable view
« Reply #1 on: March 21, 2014, 01:27:30 PM »
Have you tried calling UIScrollView's UpdateScrollbars function?

prinky

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 13
    • View Profile
Re: Tiny cosmetic issue with adding items to scrollable view
« Reply #2 on: March 21, 2014, 03:53:31 PM »
Have you tried calling UIScrollView's UpdateScrollbars function?

Since the UIGrid is a child of the panel containing the UIScrollView, I did this:
this.transform.parent.GetComponent<UIScrollView>().UpdateScrollbars(true);

No dice. Now you do have a drag drop example...and in that example it would appear that the scrollbar updates dynamically. You basically just call UpdateScrollbars when each item is "dropped" into the destination scroll view?



ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tiny cosmetic issue with adding items to scrollable view
« Reply #3 on: March 21, 2014, 05:05:51 PM »
UIGrid used by the drag & drop example has "animate smoothly" turned on, which uses SpringPosition to move items into place. SpringPosition has the "Update Scrollview" flag turned on, which simply calls scrollView.UpdateScrollBars(true) on line 108 of SpringPosition.cs -- inside its Update() function.

prinky

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 13
    • View Profile
Re: Tiny cosmetic issue with adding items to scrollable view
« Reply #4 on: March 22, 2014, 05:55:57 PM »
UIGrid used by the drag & drop example has "animate smoothly" turned on, which uses SpringPosition to move items into place. SpringPosition has the "Update Scrollview" flag turned on, which simply calls scrollView.UpdateScrollBars(true) on line 108 of SpringPosition.cs -- inside its Update() function.

Ok so I basically have a bool now that is set to false. I update the grid in Update() if the flag is false, then set the flag to true post-update. That seems to work. It doesn't work when I try to set the grid in Awake...at least the former function is called once.