TableLayout for libgdx’s scene2d

I’ve been doing everything I can to keep from finishing my RTS game. I recently started a new OSS project called TableLayout for laying out GUIs using tables. It is GUI toolkit agnostic and currently supports Swing, TWL, and now libgdx. As of just now, TableLayout can be used to layout actors in your 2D scenes. Eg, this TableLayout definition:

debug
* spacing:10 size:50
'1' '2' '3'
---
'4' '5' '6'
---
'7' '8' '9'
---
'#' '0' '*'

Produces this:

“debug” causes the red and green borders to show up, so you can see the table (green) and edges of the actors (red). The properties after the asterisk apply to all cells. The single quoted values create a label. You could also put in a bunch of images, buttons, or any libgdx actor (write your own fancy one). Conveniently libgdx actors already have names, so you can just add actors to your scene, then reference the names in the TableLayout with square brackets:

* spacing:10 size:50
[1] [2] [3]
---
[4] [5] [6]
---
[7] [8] [9]
---
[#] [0] [*]

Using TableLayout with libgdx lets you describe a table that has cells that expand, actors can fill any percentage of a cell, etc. This means you can easily have layouts that work on many different screen resolutions. Coding this manually can be tedious.

See the TableLayout docs for many other features such as describing nested tables, setting bean properties, etc. There is a libgdx example here. TableLayout has a Swing-based editor that renders the TableLayout as you type, allowing you to quickly describe a layout which you can then use in Swing, TWL, or libgdx.

-Nate

5 thoughts on “TableLayout for libgdx’s scene2d

  1. Hey. Pretty nice. I am not sure the world requires yet another table based layout manager but the compatibility with libgdx is of course trump. 🙂

    Side note: The layout seam to be created from markup. Is it possible to dynamically alter a layout and than relayout?

    I will definitely give it a try.

  2. @Moritz, show me any table based layout that isn’t crap. 🙂 See the bottom of the TableLayout page for comparisons with other layout managers. Not only do all the other ones suck, but they are not toolkit agnostic.

    Yes, you can call TableLayout#layout() to relayout at any time. You can get a reference to the cells that contain widgets and change their properties on the fly. You can specify a new TableLayout definition to change the layout of the entire table. You can also use the Java API instead of markup.

Leave a Reply

Your email address will not be published.