This godot.StyleBox can be used to achieve all kinds of looks without the need of a texture. The following properties are customizable:
-
Color
-
Border width (individual width for each border)
-
Rounded corners (individual radius for each corner)
-
Shadow (with blur and offset)
Setting corner radius to high values is allowed. As soon as corners overlap, the stylebox will switch to a relative system. Example:
height = 30
corner_radius_top_left = 50
corner_radius_bottom_left = 100
The relative system now would take the 1:2 ratio of the two left corners to calculate the actual corner width. Both corners added will never be more than the height. Result:
corner_radius_top_left: 10
corner_radius_bottom_left: 20
Constructor
Variables
antiAliasing:Bool
Antialiasing draws a small ring around the edges, which fades to transparency. As a result, edges look much smoother. This is only noticeable when using rounded corners.
Note: When using beveled corners with 45-degree angles (godot.StyleBoxFlat.cornerDetail = 1), it is recommended to set godot.StyleBoxFlat.antiAliasing to false to ensure crisp visuals and avoid possible visual glitches.
antiAliasingSize:Single
This changes the size of the faded ring. Higher values can be used to achieve a "blurry" effect.
cornerDetail:Int
This sets the number of vertices used for each corner. Higher values result in rounder corners but take more processing power to compute. When choosing a value, you should take the corner radius (godot.StyleBoxFlat.setCornerRadiusAll) into account.
For corner radii less than 10, 4 or 5 should be enough. For corner radii less than 30, values between 8 and 12 should be enough.
A corner detail of 1 will result in chamfered corners instead of rounded corners, which is useful for some artistic effects.
expandMarginBottom:Single
Expands the stylebox outside of the control rect on the bottom edge. Useful in combination with godot.StyleBoxFlat.borderWidthBottom to draw a border outside the control rect.
expandMarginLeft:Single
Expands the stylebox outside of the control rect on the left edge. Useful in combination with godot.StyleBoxFlat.borderWidthLeft to draw a border outside the control rect.
expandMarginRight:Single
Expands the stylebox outside of the control rect on the right edge. Useful in combination with godot.StyleBoxFlat.borderWidthRight to draw a border outside the control rect.
expandMarginTop:Single
Expands the stylebox outside of the control rect on the top edge. Useful in combination with godot.StyleBoxFlat.borderWidthTop to draw a border outside the control rect.
shadowColor:Color
The color of the shadow. This has no effect if godot.StyleBoxFlat.shadowSize is lower than 1.
shadowOffset:Vector2
The shadow offset in pixels. Adjusts the position of the shadow relatively to the stylebox.
Methods
getBorderWidth(margin:Margin):Int
Returns the given margin's border width. See godot.Margin for possible values.
getCornerRadius(corner:Corner):Int
Returns the given corner's radius. See godot.Corner for possible values.
getExpandMargin(margin:Margin):Single
Returns the size of the given margin's expand margin. See godot.Margin for possible values.
setBorderWidth(margin:Margin, width:Int):Void
Sets the border width to width pixels for the given margin. See godot.Margin for possible values.
setCornerRadius(corner:Corner, radius:Int):Void
Sets the corner radius to radius pixels for the given corner. See godot.Corner for possible values.
setCornerRadiusIndividual(radiusTopLeft:Int, radiusTopRight:Int, radiusBottomRight:Int, radiusBottomLeft:Int):Void
Sets the corner radius for each corner to radius_top_left, radius_top_right, radius_bottom_right, and radius_bottom_left pixels.
setExpandMargin(margin:Margin, size:Single):Void
Sets the expand margin to size pixels for the given margin. See godot.Margin for possible values.
setExpandMarginIndividual(sizeLeft:Single, sizeTop:Single, sizeRight:Single, sizeBottom:Single):Void
Sets the expand margin for each margin to size_left, size_top, size_right, and size_bottom pixels.