Author Topic: Object columns generated by UITable are not equidistant when using UILabels  (Read 6244 times)

MoProductions

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 45
    • View Profile
Part of our game involves a code generated grid of letters.  I'm using a UITable object which I fill with the letters, then call
myTable.Reposition().  For a while everything seemed fine but when we were looking more closely at things due to a bug we noticed that while the elements in the rows/columns line up, the columns themselves are not equidistant from each other.  It's most easily seen when creating a table with zero padding:



Notice how the columns 4 and 5 (top letters are P and Y), and columns 9 and 10 (top letters are L and O) have different spacing.  This has been confirmed by debug code. 
I assume what's happening is that UITable.Reposition() will find out the minimum distance needed between columns based on the two widest elements next to each other, then adds the padding.  Well, since fonts aren't equal sized in that creates inconsistencies.
The solution I was going to try was instead of creating the UITable out of font elements, I would create the table out of
(fontSize x fontSize) sprite elements, making them all the same size.  Then after Reposition() is called, I'd go back through the grid and place each font element at the sprite element's transform.position. 
I'm pretty sure that would work, but is there a way to toggle something in NGUI or UITable that would force consistent spacing between the columns based on the widest spacing needed or perhaps a hardcoded value and not based on elements with different widths?
Thanks!
-Mo

MoProductions

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 45
    • View Profile
BTW I know a UIGrid could achieve what I'm looking for but all our code/math was based on UITable so I'm trying to avoid changing class type if I can.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
UITable uses widget size, and widgets can have sizes that don't divide by 2 cleanly, so centering them may not work well.

Grid is your best bet. You basically have a grid there, not sure why you are using a table to be honest.