Author Topic: UIScrollView - Disable bounds caching  (Read 1612 times)

Vesuvian

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 32
    • View Profile
UIScrollView - Disable bounds caching
« on: June 27, 2014, 03:34:42 AM »
Hey guys

We have a scenario where we have a UILabel with a UIInput as an immediate child to a UIScrollView panel.

In editor, changing the text value of the label causes the UIScrollView bounds (the orange box) to be recalculated, which is ideal. However, while running the scene, the bounds do not seem to update.

I'm not sure why this behaviour would be different while playing, but it seems to me that the reason the bounds aren't being recalculated is because of the following property in UIScrollView:

  1.         /// <summary>
  2.         /// Calculate the bounds used by the widgets.
  3.         /// </summary>
  4.  
  5.         public virtual Bounds bounds
  6.         {
  7.                 get
  8.                 {
  9.                         if (!mCalculatedBounds)
  10.                         {
  11.                                 mCalculatedBounds = true;
  12.                                 mTrans = transform;
  13.                                 mBounds = NGUIMath.CalculateRelativeWidgetBounds(mTrans, mTrans);
  14.                         }
  15.                         return mBounds;
  16.                 }
  17.         }

I can't imagine it being particularly expensive to calculate the bounds for a few rects. Perhaps we could have the option to disable caching bounds in the inspector?

For now I believe I can work around this by calling InvalidateBounds() as needed.

Thanks,
Ves

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIScrollView - Disable bounds caching
« Reply #1 on: June 27, 2014, 01:17:16 PM »
Calculating bounds is pretty expensive, especially considering that you need to do a GetComponentsInChildren which allocates memory causing GC. It's cached because in most cases bounds won't change dynamically, and if they do, you can always call InvalidateBounds() as you mentioned.