Going crazy with creating UI tables

Hi,

I would say I am an advanced beginner with Unity but creating tables for the UI is really driving me crazy. It is probably very easy, however, feel free to laugh at me :smiley:

I have a very simple setup just to test everything. So basically I have a screen, that has a menubar with 6 buttons. Each button should simply switch through the screens that are shown below the menubar:

The buttons don’t have any function right now. What is more important, is the part under the buttons. There should be a table with columns. Right now, I am just spamming random data into the tables, just to play around. I want the table to spread over the whole width of the screen.

So I created a ScrollView (“TableView”)

I dont want a horizontal scroll bar, so I simply deleted it.

The object “Content” has a Vertical Layout Group that should force the rows to be expanded over the width of the screen.

The “RowTemplate” has a Horizontal Layout Group

There is a script filling the table with random data. The output is this:

I want the 3 columns in the table to have a width, that fills up the whole screen. It is probably very easy but I couldn’t figure it out.

For a pure grid you probably want to use the GridLayoutGroup stuff.

You would have one GridLayoutGroup for your header (those buttons) that isn’t within your scroll rect, then another identical GridLayoutGroup within the scrollrect and some kind of ContentSizeFitter to expand it as you add rows.

BTW, you’re very right to iterate on this stuff… what you contemplate is doable, but it does take some experimentation.

OK, thanks a lot. Indeed, it turned out that working with a Grid is way easier than the way I did. That helped a lot, thank you.

The only downside is that GridLayoutGroup does kinda force you to… well, a grid.

If you need varying width columns you would need to go to a stack of HorizontalLayoutGroups within either a GridLayoutGroup (one long grid cell per line), or within a VerticalLayoutGroup.

With a HoriziontalLayoutgroup you can then more-finely control the column widths of each by putting a LayoutElement on each one. The easiest is to force the width of all but the final cell.

It is really powerful, just finicky. I still prefer it over UIElements just because it is Components on GameObjects right there in my scene. Others hate it for exactly that reason.

ALSO: be sure you set up your scaling correct first or when you change screen sizes you’ll be very sad. :slight_smile:

For Unity UGUI, here are the official docs on how to make your UI handle various resolutions and aspect ratios cleanly:

Here are some notes on UI Anchoring, Scaling, CanvasScaler, etc:

Usually you need to choose a suitable ScaleMode and MatchMode in the Canvas Scaler and stick with it 100%. Generally if you change those settings you will often need to redo your UI entirely.

Here’s some more fit-inside-UI-content notes:

I also use this CanvasScalerOrientationDriver utility to make sharing UI for Landscape / Portrait easier. Read what it does carefully.

It’s pretty darn simple with UI Toolkit / UI Builder. :wink: