Question

I am trying to a create a gui in libGDX, but I am having problems with my buttons. I am currently using a 9patch image for my button, which looks like this: enter image description here

This button scales perfectly well, it's just that when I add text to the button there is too much space between the top of the button, and the top of this text. Like this:enter image description here

The red line marks the amount of space between the top of the button and the top of the text. This space is too large, and I am wondering if there is any way to reduce it.

The font I am using is not scaled, and it is a normal BitmapFont with no filter. Regardless of the scale, the space between the text and the top edge is always proportionate, meaning that the space still looks the same size when I am using a small font or a large font, relative to the text size.

Any suggestions would be appreciated.

Was it helpful?

Solution

To solve this problem I did the following.

When adding the button to the table, I used the following Code.

table.add(button).height(HEIGHT).width(WIDTH);

This did not solve the mentioned issue, but it allowed me to explicitly set the desired width and height of the button, which played a part in solving the actual issue. When creating the button, the button, being an extension of Cell, I used to add() function to re-position the text.

button = new TextButton("button", style);
button.add(button.getLabel()).padBottom(CONSTANT);

combined with the Cell.height() function, I was able to use a constant padding variable to position the button's text (or label) in the middle of the button.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top