Author Topic: UITable not spacing resized items properly  (Read 1907 times)

appminis-mike

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 32
    • View Profile
UITable not spacing resized items properly
« on: March 05, 2014, 08:45:26 PM »
I'm adding some elements to a UITable (using NGUITools.AddChild), and I set their heights according to their needs of their contents. After all of this, I call the UITable's Reposition() function. However, the elements are not spaced properly. There are large gaps between them, as though the table still thinks they are their original size. I have the table's padding set to 6, so I would expect only 6 pixels of gap between them, but there is much, much more.

What might cause this behavior?

Thank you.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UITable not spacing resized items properly
« Reply #1 on: March 06, 2014, 10:46:54 AM »
You set heights of what, exactly? And what's the structure of what you're instantiating via AddChild?

appminis-mike

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 32
    • View Profile
Re: UITable not spacing resized items properly
« Reply #2 on: March 06, 2014, 11:31:25 AM »
They're prefabs with UIWidget scripts on them, and child elements with other UIWidgets, UILabels, and UISprites. I'm setting the height of the top level UIWidgets.

It looks like this:

Element (UIWidget)
  Background (UIWidget)
    Sprite (UISprite)
  Title (UILabel)
  Description (UILabel)

where Element.height is what I'm setting, and I'm adding an arbitrary number of those to the UITable.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UITable not spacing resized items properly
« Reply #3 on: March 06, 2014, 11:57:39 AM »
Are they anchored? Anchors won't update until later, unless you explicitly call UpdateAnchors() on all the widgets (you can gameObject.BroadcastMessage it).

appminis-mike

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 32
    • View Profile
Re: UITable not spacing resized items properly
« Reply #4 on: March 06, 2014, 12:10:43 PM »
Element is not anchored, and it is being sized properly (I can see the borders in the scene view). Its children are, though, and I tried calling gameObject.BroadcastMessage("UpdateAnchors"), but that didn't help. Everything looks to be sizing properly, it's just the positions within the UITable that are off.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UITable not spacing resized items properly
« Reply #5 on: March 07, 2014, 10:37:16 AM »
Calling UpdateAnchors should immediately update the position of everything, and the table considers the bounds of all the children underneath your "Element" widget when calculating the final bounds. If you can't figure this out, I can have a look if you give me a small repro case (just don't post it here -- email to support at tasharen.com).