Faithium
Faithium

Reputation: 131

LIBGDX - Label doesn't fit with font size

I have a probleme, my labels doesn't fit with my skin font size and I can't understand why

Here is my code:

import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.utils.Align;

public class MoveDetailBox extends Table
{
    private Label ppLabel;
    
    private Label moveTypeLabel;
    
    public MoveDetailBox(Skin skin) {
        super(skin);
        // TODO background name option box? rename it
        this.setBackground("optionbox");
        Table container = new Table();
        this.add(container).pad(5f); // TODO PADS
        this.ppLabel = new Label("??/??", super.getSkin());
        this.moveTypeLabel = new Label ("TYPE/??", super.getSkin());
        Table row1 = new Table();
        row1.add(new Label("PP", super.getSkin())).align(Align.left);
        row1.add(this.ppLabel).space(5f).align(Align.right);
        container.add(row1).space(5f).row();
        container.add(this.moveTypeLabel).space(5f).align(Align.left);
        container.debugAll();
    }
}

And this is what I get:

enter image description here

As you can see my labels (the green rectangles) are more little than the font size

Upvotes: 0

Views: 711

Answers (1)

Tejay
Tejay

Reputation: 236

A call to .pack should finalize the layout and width and height of the Table. At the end of the constructor:

this.add(container).pad(5f);
this.pack();

If the size looks wrong overwrite prefered size:

this.add(container).width(width).height(height).pad(5f);
this.pack();

Upvotes: 2

Related Questions