- Home /
What is the best method of displaying tabular data with Unity's 4.6+ UI?
The question pretty much says it all.
I'm trying to create clean tables without having to set up a whole bunch of insane anchors.
Tried using a Grid Layout; that doesn't allow me to force the number of columns. Tried using a Vertical Layout holding a bunch of Horizontal Layouts, but I can't lock the Horizontal Layout groups' sizes, so the rows are always skewed.
I've tried a couple searches but haven't found anything, meaning it's either stupid-simple or nobody wants to look at a table in a game :\
I'm using unity 5 ins$$anonymous$$d of 4.6, but I checked the Grid Layout Group UI component and I can set the Constraint variable to Fixed Column Count. That's not possible in 4.6?
Ha! I knew it (see question): it was stupid-simple. I must have had that section of the window just a little too small and didn't scroll the window down, because I just did not notice that. Go ahead and add answer and I'll give you the points :P
Ooh also - is there a way to not use fixed size for the cells of a grid component?
Okay; wait... I don't think that's exactly what I want. I'm looking for something that gives me:
A fixed number of columns (grid does this)
An unlimited number of rows (vertical layout group does this)
Cells which can expand automatically... (horizontal layout group does this)
... but when a cell is forced to expand, it ensures that all the other cells in its column match its expansion
Could I do a Horizontal Layout Group holding Vertical Layout Group(s) then?
O$$anonymous$$ for now I'm going to actually leave this unanswered, as this is not as easy as it should be. Surely there is a way. The Grid doesn't work, and using a Horizontal Layout Group holding Vertical Layout Group(s) with specific LayoutElement overrides for each of the Vertical Layout Groups (to control column widths and such with $$anonymous$$Width) is the best I can come up with.
There's got to be a better way!
Answer by pfreese · Mar 17, 2015 at 01:38 AM
The Grid Layout component does most of what you want, but it assumes a fixed cell size. Probably the best way to handle this for now would be to roll your own layout script, using GridLayoutGroup as a model (basically just changing the fixed cell with to use the max width of the elements in each column. The UI code is Open Source; info on getting it is here: https://bitbucket.org/Unity-Technologies/ui
There's also documentation on the Layout interfaces here: http://docs.unity3d.com/$$anonymous$$anual/UIAutoLayout.html . See the Technical Details section near the bottom of the page.
Uh oh - first link is dead
Edit: also second link :\
Double edit: the periods are getting included in the links; you might want to edit it for future. Both links work fine with the periods removed :)