Set size for checkbox image in libgdx interface

I can't figure out how to control the size of the checkboxes. Of course, in my Texture atlas you can create a different image size and accept the appropriate one, but I do not want to do this.

Here is my code:

AtlasRegion checkboxOn = AssetsHelper.textures.findRegion("checked"); AtlasRegion checkboxOff = AssetsHelper.textures.findRegion("unchecked"); CheckBoxStyle checkBoxStyle = new CheckBoxStyle(); checkBoxStyle.font = AssetsHelper.font66yellow; checkBoxStyle.checkboxOff = checkboxOff; checkBoxStyle.checkboxOn = checkboxOn; CheckBox cbSound = new CheckBox(" Sound", checkBoxStyle); 

The cbSound object does not have such methods for displaying the flag image, but there is a getImage () method, but it does not seem to work either. This does not work:

 cbSound.getImage().width = 120; cbSound.getImage().height = 120; 

FYI: for example, when I wanted to draw an image, I liked:

 batch.draw(textureRegion, 0, 0, widthIwant, heightIwant); 

But in the CheckBox class, only this is overridden (without setting the width and height):

 public void draw (SpriteBatch batch, float parentAlpha) { image.setRegion(isChecked ? style.checkboxOn : style.checkboxOff); super.draw(batch, parentAlpha); } 

Question : how to change the width and height of the checkbox image?

Thanks in advance.

+6
source share
1 answer

Libgdx widgets use drawings to draw images. The selector is automatically scaled to fit the cell in which it is located. Therefore, to resize the image, resize the cell:

 cbSound.getCells().get(0).size(widht, height); 

For best results, you should use nine drawing patches.

+7
source

All Articles