Cell width not respected when using colspan

512 Views Asked by At

I'm trying to set a cell width in my LibGDX's table and it's ignoring the value I pass. I suspect it is because it's under rows that are fill and has colspan but I can't explain exactly why It is happenning.

Here's a screen: Example

I would like the cell of my play button to be smaller in width, so I wrote that code:

setDebug(true, true); //just mentionning, this is in the constructor of a class that extends Table, to prevent having table creation code on my screen

setWidth(400f);
setHeight(80f);

padLeft(30f);
padRight(30f);

Image image = new Image(assets.getTexture("gfx/menu/level-online.png")); //TODO icon depends on state
image.setScaling(Scaling.fill);

Button playButton = new TextButton(level.getType() == LevelType.RACE ? "Play" : "Visit", skin);
Button editButton = new TextButton("Edit", skin);

add(level.getName()).bottom().left().colspan(2).expand();
add(image).width(30f).height(30f);
row();
add(level.getOwner()).top().left().colspan(3).expand();
row();
add(playButton).width(40f).center(); //HERE
add(editButton).left().colspan(2); 

As you can see, the width of the cell of the play button is supposed to be 40 but it's way more. (For reference, the cloud is 30 x 30) How can I fix this ?

1

There are 1 best solutions below

0
On BEST ANSWER

Fixed it using a table in my last row to separate elements. Thanks to Xoppa and Tenfour04 for their help.

add(level.getName()).bottom().left().colspan(2).expand();
add(image).width(30f).height(30f);
row();
add(level.getOwner()).top().left().colspan(3).expand();
row();
Table buttons = new Table();

buttons.add(playButton).padRight(10f);
buttons.add(editButton);

add(buttons).expand().colspan(3).left();