Button

Inherits: BaseButton < Control < CanvasItem < Node < Object

Inherited By: CheckBox, CheckButton, ColorPickerButton, MenuButton, OptionButton, ToolButton

Standard themed Button.

Description

Button is the standard themed button. It can contain text and an icon, and will display them according to the current Theme.

Example of creating a button and assigning an action when pressed by code:

func _ready():
    var button = Button.new()
    button.text = "Click me"
    button.connect("pressed", self, "_button_pressed")
    add_child(button)

func _button_pressed():
    print("Hello world!")

Buttons (like all Control nodes) can also be created in the editor, but some situations may require creating them from code.

See also BaseButton which contains common properties and methods associated with this node.

Note: Buttons do not interpret touch input and therefore don't support multitouch, since mouse emulation can only press one button at a given time. Use TouchScreenButton for buttons that trigger gameplay movement or actions, as TouchScreenButton supports multitouch.

Tutorials

Properties

TextAlign

align

1

bool

clip_text

false

bool

expand_icon

false

bool

flat

false

Texture

icon

TextAlign

icon_align

0

String

text

""

Theme Properties

Color

font_color

Color( 0.88, 0.88, 0.88, 1 )

Color

font_color_disabled

Color( 0.9, 0.9, 0.9, 0.2 )

Color

font_color_focus

Color( 0.94, 0.94, 0.94, 1 )

Color

font_color_hover

Color( 0.94, 0.94, 0.94, 1 )

Color

font_color_pressed

Color( 1, 1, 1, 1 )

int

hseparation

2

Font

font

StyleBox

disabled

StyleBox

focus

StyleBox

hover

StyleBox

normal

StyleBox

pressed


Enumerations

enum TextAlign:

TextAlign ALIGN_LEFT = 0

Align the text to the left.

TextAlign ALIGN_CENTER = 1

Align the text to the center.

TextAlign ALIGN_RIGHT = 2

Align the text to the right.


Property Descriptions

TextAlign align = 1

Text alignment policy for the button's text, use one of the TextAlign constants.


bool clip_text = false

  • void set_clip_text ( bool value )

  • bool get_clip_text ( )

When this property is enabled, text that is too large to fit the button is clipped, when disabled the Button will always be wide enough to hold the text.


bool expand_icon = false

  • void set_expand_icon ( bool value )

  • bool is_expand_icon ( )

When enabled, the button's icon will expand/shrink to fit the button's size while keeping its aspect.


bool flat = false

  • void set_flat ( bool value )

  • bool is_flat ( )

Flat buttons don't display decoration.


Texture icon

Button's icon, if text is present the icon will be placed before the text.

To edit margin and spacing of the icon, use hseparation theme property of Button and content_margin_* properties of the used StyleBoxes.


TextAlign icon_align = 0

Specifies if the icon should be aligned to the left, right, or center of a button. Uses the same TextAlign constants as the text alignment. If centered, text will draw on top of the icon.


String text = ""

The button's text that will be displayed inside the button's area.


Theme Property Descriptions

Color font_color = Color( 0.88, 0.88, 0.88, 1 )

Default text Color of the Button.


Color font_color_disabled = Color( 0.9, 0.9, 0.9, 0.2 )

Text Color used when the Button is disabled.


Color font_color_focus = Color( 0.94, 0.94, 0.94, 1 )

Text Color used when the Button is focused. Only replaces the normal text color of the button. Disabled, hovered, and pressed states take precedence over this color.


Color font_color_hover = Color( 0.94, 0.94, 0.94, 1 )

Text Color used when the Button is being hovered.


Color font_color_pressed = Color( 1, 1, 1, 1 )

Text Color used when the Button is being pressed.


int hseparation = 2

The horizontal space between Button's icon and text.


Font font

Font of the Button's text.


StyleBox disabled

StyleBox used when the Button is disabled.


StyleBox focus

StyleBox used when the Button is focused. It is displayed over the current StyleBox, so using StyleBoxEmpty will just disable the focus visual effect.


StyleBox hover

StyleBox used when the Button is being hovered.


StyleBox normal

Default StyleBox for the Button.


StyleBox pressed

StyleBox used when the Button is being pressed.