Author Topic: How to do a colspan with UITables?  (Read 4614 times)

ozRocker

  • Guest
How to do a colspan with UITables?
« on: April 25, 2012, 01:57:04 PM »
What's the best way to span multiple columns in a table?  What I'm trying to do is have rows with 2 cells in them: an icon, a name.  When you click anywhere on that row a long description will appear straight after the row (using a tweening effect so it expands gradually).  This long description will have to span 2 columns so it takes up the whole row.  Is there an easy way to do this?  Should I just use 1 cell in the previous row and put a 2x1 table in that?  I'm sure that would work but it adds a fair bit of overhead.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to do a colspan with UITables?
« Reply #1 on: April 25, 2012, 02:52:28 PM »
Create a prefab for what your table's row should be like, and then your table will be just 1 column and everything will line up.

ozRocker

  • Guest
Re: How to do a colspan with UITables?
« Reply #2 on: April 26, 2012, 01:44:38 PM »
ok cool.  I'm trying to use prefabs now but its proving to be very difficult.  I'm getting a lot of side effects when instantiating the prefab, updating the labels and textures in the prefab and putting them in a table.  Some table cells don't line up correctly, the bottom row moves around when scrolling.  Repositioning does not fix it completely.  I've made sure the positions are 0,0,0 and scale 1,1,1 for the widgets and gameobjects.  Even tried setting the positions during runtime in code.  Spent hours fiddling with this :(  If anyone has used prefabs for table rows with dynamic content, please show me an example.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to do a colspan with UITables?
« Reply #3 on: April 26, 2012, 03:29:47 PM »
1. Instantiate the prefab via NGUITools.AddChild(tableGameObject, yourRowPrefab) and don't move the object.
2. Use labels with a fixed line width and multi-line disabled.
3. Create a background sliced sprite for your row that will cover the entire area of the row, showing you what it should look like (and make sure these bounds don't get exceeded).
4. After adding all your children, set UITable's "repositionNow" to 'true'. Don't use Reposition() right after instantiation, it likely won't work properly.

I use this approach in several places in Windward: news screen, player list, ship list, summary screen, and everything works as expected.

ozRocker

  • Guest
Re: How to do a colspan with UITables?
« Reply #4 on: April 27, 2012, 01:03:34 AM »
yes, that works very well.  In fact its not difficult at all! :) Thanks mate.  I'm just very noob at the moment.