3
\$\begingroup\$

I'm using Godot 4. I want to increase the distance between the Button's Text (and possibly icon, later on), and it's outer edges, while keeping the "Colors" options such as "Font Hover Color". The equivalent effect of padding on a CSS styled button.

What I've tried:

I've searched online to find my answer, but that led mostly to different threads about containers, not buttons. Only this rejected GitHub issue to add "Padding" for controls seemed relevant; I think it was rejected mostly because there are already other ways to achieve the effect of paddings? But I can't seem to distill from that thread how to set this up for buttons.

I've gone through all the "Theme Overrides" options in the Godot editor, but only H Separation seemed relevant but that's for space between the icon and text.

I've tried leaving the Button's text empty and creating a child MarginContainer with a child Label but then (a) the button size is nearly zero, plus I worry the "Colors" from the button's theme options won't work.

Bottom line:

How do you set a "padding" (a fixed number of pixels between the edge and contents) of a button in Godot 4?

\$\endgroup\$

1 Answer 1

4
\$\begingroup\$

What you use are the define style overrides, which means you have to do it separately for Normal, Hover, Pressed, Disabled, and Focus states.

All the kinds of StyleBox* have content margin properties that can do what you want.

The StyleBoxFlat also have border width properties. This border comes outside of the contents, but it is part of the sizing of the Control. StyleBoxFlat also allows you to specify rounded corners.

Similarly, StyleBoxTexture has texture margin properties, which lets you specify how much of the texture will be treated as border. There are no properties for rounded corners, but you can do them with transparency in the texture.

Both StyleBoxTexture and StyleBoxFlat also have expand margin properties that would make the Control larger, but they are not part of its sizing. StyleBoxFlat also allows you to specify shadows which aren't part of the sizing of the Control either.

By the way, I know it can be somewhat frustrating that there is disparity on the features provided by the different kinds of StyleBox*. However, know that a Button can have children Controls, so you can use a ColorRect or TextureRect for the background and a Label for the text.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .