As someone who is quite experienced with CSS, I’m trying to understand the “table layout” which scene2d ui in libgdx uses.
However everything I do seems to yield counter-intuitive results. Like using left(), top, right, bottom whatever or width(float) and its being completely ignored
So I have this simple test code:
public class CopyOfLetsDoMenus extends ApplicationAdapter
{
Stage stage;
public void create ()
{
stage = new Stage();
Gdx.input.setInputProcessor(stage);
Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
Table rootTable = new Table();
rootTable.setFillParent(true);
rootTable.debug();
Table table = new Table();
table.debug();
Label nameLabel = new Label("Name:", skin);
TextField nameText = new TextField("ble", skin);
Label addressLabel = new Label("Address:", skin);
TextField addressText = new TextField("bla", skin);
table.add(nameLabel);
table.add(nameText).width(100);
table.row();
table.add(addressLabel);
table.add(addressText).width(100);
rootTable.addActor(table);
stage.addActor(rootTable);
}
public void render () {
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
stage.act(Gdx.graphics.getDeltaTime());
stage.draw();
Table.drawDebug(stage);
}
public void resize (int width, int height) {
stage.setViewport(width, height, true);
}
public boolean needsGL20 () {
return true;
}
public void dispose () {
stage.dispose();
}
public static void main(String[] args)
{
LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration();
cfg.useGL20 = true;
cfg.width = 480;
cfg.height = 320;
new LwjglApplication(new CopyOfLetsDoMenus(), cfg);
}
}
Very short very sweet.
However, the result is this :
It seems to think the frame is twice it’s size and then center the stuff… Why ?
I’m actually just trying to follow the official guide: https://code.google.com/p/table-layout/