Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

StyleBoxFlat

Inherits: StyleBox < Resource < RefCounted < Object

A customizable StyleBox that doesn't use a texture.

Description

By configuring various properties of this style box, you can achieve many common looks without the need of a texture. This includes optionally rounded borders, antialiasing, shadows, and skew.

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

Properties

bool

anti_aliasing

true

float

anti_aliasing_size

1.0

Color

bg_color

Color(0.6, 0.6, 0.6, 1)

bool

border_blend

false

Color

border_color

Color(0.8, 0.8, 0.8, 1)

int

border_width_bottom

0

int

border_width_left

0

int

border_width_right

0

int

border_width_top

0

int

corner_detail

8

int

corner_radius_bottom_left

0

int

corner_radius_bottom_right

0

int

corner_radius_top_left

0

int

corner_radius_top_right

0

bool

draw_center

true

float

expand_margin_bottom

0.0

float

expand_margin_left

0.0

float

expand_margin_right

0.0

float

expand_margin_top

0.0

Color

shadow_color

Color(0, 0, 0, 0.6)

Vector2

shadow_offset

Vector2(0, 0)

int

shadow_size

0

Vector2

skew

Vector2(0, 0)

Methods

int

get_border_width ( Side margin ) const

int

get_border_width_min ( ) const

int

get_corner_radius ( Corner corner ) const

float

get_expand_margin ( Side margin ) const

void

set_border_width ( Side margin, int width )

void

set_border_width_all ( int width )

void

set_corner_radius ( Corner corner, int radius )

void

set_corner_radius_all ( int radius )

void

set_expand_margin ( Side margin, float size )

void

set_expand_margin_all ( float size )


Property Descriptions

bool anti_aliasing = true

  • void set_anti_aliased ( bool value )

  • bool is_anti_aliased ( )

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 or skew.

Note: When using beveled corners with 45-degree angles (corner_detail = 1), it is recommended to set anti_aliasing to false to ensure crisp visuals and avoid possible visual glitches.


float anti_aliasing_size = 1.0

  • void set_aa_size ( float value )

  • float get_aa_size ( )

This changes the size of the antialiasing effect. 1.0 is recommended for an optimal result at 100% scale, identical to how rounded rectangles are rendered in web browsers and most vector drawing software.

Note: Higher values may produce a blur effect but can also create undesired artifacts on small boxes with large-radius corners.


Color bg_color = Color(0.6, 0.6, 0.6, 1)

  • void set_bg_color ( Color value )

  • Color get_bg_color ( )

The background color of the stylebox.


bool border_blend = false

  • void set_border_blend ( bool value )

  • bool get_border_blend ( )

If true, the border will fade into the background color.


Color border_color = Color(0.8, 0.8, 0.8, 1)

  • void set_border_color ( Color value )

  • Color get_border_color ( )

Sets the color of the border.


int border_width_bottom = 0

  • void set_border_width ( Side margin, int width )

  • int get_border_width ( Side margin ) const

Border width for the bottom border.


int border_width_left = 0

  • void set_border_width ( Side margin, int width )

  • int get_border_width ( Side margin ) const

Border width for the left border.


int border_width_right = 0

  • void set_border_width ( Side margin, int width )

  • int get_border_width ( Side margin ) const

Border width for the right border.


int border_width_top = 0

  • void set_border_width ( Side margin, int width )

  • int get_border_width ( Side margin ) const

Border width for the top border.


int corner_detail = 8

  • void set_corner_detail ( int value )

  • int get_corner_detail ( )

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 (set_corner_radius_all) 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.


int corner_radius_bottom_left = 0

  • void set_corner_radius ( Corner corner, int radius )

  • int get_corner_radius ( Corner corner ) const

The bottom-left corner's radius. If 0, the corner is not rounded.


int corner_radius_bottom_right = 0

  • void set_corner_radius ( Corner corner, int radius )

  • int get_corner_radius ( Corner corner ) const

The bottom-right corner's radius. If 0, the corner is not rounded.


int corner_radius_top_left = 0

  • void set_corner_radius ( Corner corner, int radius )

  • int get_corner_radius ( Corner corner ) const

The top-left corner's radius. If 0, the corner is not rounded.


int corner_radius_top_right = 0

  • void set_corner_radius ( Corner corner, int radius )

  • int get_corner_radius ( Corner corner ) const

The top-right corner's radius. If 0, the corner is not rounded.


bool draw_center = true

  • void set_draw_center ( bool value )

  • bool is_draw_center_enabled ( )

Toggles drawing of the inner part of the stylebox.


float expand_margin_bottom = 0.0

  • void set_expand_margin ( Side margin, float size )

  • float get_expand_margin ( Side margin ) const

Expands the stylebox outside of the control rect on the bottom edge. Useful in combination with border_width_bottom to draw a border outside the control rect.

Note: Unlike StyleBox.content_margin_bottom, expand_margin_bottom does not affect the size of the clickable area for Controls. This can negatively impact usability if used wrong, as the user may try to click an area of the StyleBox that cannot actually receive clicks.


float expand_margin_left = 0.0

  • void set_expand_margin ( Side margin, float size )

  • float get_expand_margin ( Side margin ) const

Expands the stylebox outside of the control rect on the left edge. Useful in combination with border_width_left to draw a border outside the control rect.

Note: Unlike StyleBox.content_margin_left, expand_margin_left does not affect the size of the clickable area for Controls. This can negatively impact usability if used wrong, as the user may try to click an area of the StyleBox that cannot actually receive clicks.


float expand_margin_right = 0.0

  • void set_expand_margin ( Side margin, float size )

  • float get_expand_margin ( Side margin ) const

Expands the stylebox outside of the control rect on the right edge. Useful in combination with border_width_right to draw a border outside the control rect.

Note: Unlike StyleBox.content_margin_right, expand_margin_right does not affect the size of the clickable area for Controls. This can negatively impact usability if used wrong, as the user may try to click an area of the StyleBox that cannot actually receive clicks.


float expand_margin_top = 0.0

  • void set_expand_margin ( Side margin, float size )

  • float get_expand_margin ( Side margin ) const

Expands the stylebox outside of the control rect on the top edge. Useful in combination with border_width_top to draw a border outside the control rect.

Note: Unlike StyleBox.content_margin_top, expand_margin_top does not affect the size of the clickable area for Controls. This can negatively impact usability if used wrong, as the user may try to click an area of the StyleBox that cannot actually receive clicks.


Color shadow_color = Color(0, 0, 0, 0.6)

  • void set_shadow_color (