I have a typical skin json file, like the sample one here:
https://github.com/libgdx/libgdx/blob/master/tests/gdx-tests-android/assets/data/uiskin.json
is it possible to specify "inner" padding for text buttons (the space around the text to the edge of the button) in the skin file - or can we only do that programatically at runtime?
Thanks
Buttons in scene2d use the background drawable to determine padding. To the best of my knowledge, the only three reliable ways to set the padding of a Button are
Use a 9 patch drawable for the background drawable. The 9 patch defines its own padding.
Programatically modify any Drawable to have padding by using its setTopHeight()
, setLeftWidth()
, etc. methods. Then apply this Drawable as the Button's background programatically.
Edit: As of LibGDX 1.7.2, this is now possible to do by specifying a TextureRegionDrawable in the JSON file. Use a TextureRegionDrawable as the background of the button and define its padding like this:
com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable: {
paddedWhite: { region: white, leftWidth: 5, rightWidth: 5, topHeight: 4, bottomHeight: 4 }
}
Note that if you simply use button.pad(...)
, your padding settings will be cancelled the moment the button is pressed the first time.