Button

Inherits: BaseButton < Control < CanvasItem < Node < Object

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

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.

Methods

void

clear_opentype_features ( )

int

get_opentype_feature ( String tag ) const

void

set_opentype_feature ( String tag, int value )

Theme Properties

StyleBox

disabled

StyleBox

focus

Font

font

Color

font_color

Color(0.88, 0.88, 0.88, 1)

Color

font_disabled_color

Color(0.9, 0.9, 0.9, 0.2)

Color

font_hover_color

Color(0.94, 0.94, 0.94, 1)

Color

font_hover_pressed_color

Color(1, 1, 1, 1)

Color

font_outline_color

Color(1, 1, 1, 1)

Color

font_pressed_color

Color(1, 1, 1, 1)

int

font_size

StyleBox

hover

int

hseparation

2

Color

icon_disabled_color

Color(1, 1, 1, 1)

Color

icon_hover_color

Color(1, 1, 1, 1)

Color

icon_hover_pressed_color

Color(1, 1, 1, 1)

Color

icon_normal_color

Color(1, 1, 1, 1)

Color

icon_pressed_color

Color(1, 1, 1, 1)

StyleBox

normal

int

outline_size

0

StyleBox

pressed

Enumerations

enum TextAlign:

  • ALIGN_LEFT = 0 --- Align the text to the left.

  • ALIGN_CENTER = 1 --- Align the text to the center.

  • ALIGN_RIGHT = 2 --- Align the text to the right.

Property Descriptions

Default

1

Setter

set_text_align(value)

Getter

get_text_align()

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


Default

false

Setter

set_clip_text(value)

Getter

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.


Default

false

Setter

set_expand_icon(value)

Getter

is_expand_icon()

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


Default

false

Setter

set_flat(value)

Getter

is_flat()

Flat buttons don't display decoration.


Setter

set_button_icon(value)

Getter

get_button_icon()

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


Default

0

Setter

set_icon_align(value)

Getter

get_icon_align()

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.


Default

""

Setter

set_language(value)

Getter

get_language()

Language code used for line-breaking and text shaping algorithms, if left empty current locale is used instead.


Default

""

Setter

set_text(value)

Getter

get_text()

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


Default

0

Setter

set_text_direction(value)

Getter

get_text_direction()

Base text writing direction.

Method Descriptions

  • void clear_opentype_features ( )

Removes all OpenType features.


  • int get_opentype_feature ( String tag ) const

Returns OpenType feature tag.


  • void set_opentype_feature ( String tag, int value )

Sets OpenType feature tag. More info: OpenType feature tags.

Theme Property Descriptions

StyleBox used when the Button is disabled.


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


Font of the Button's text.


Default

Color(0.88, 0.88, 0.88, 1)

Default text Color of the Button.


  • Color font_disabled_color

Default

Color(0.9, 0.9, 0.9, 0.2)

Text Color used when the Button is disabled.


Default

Color(0.94, 0.94, 0.94, 1)

Text Color used when the Button is being hovered.


  • Color font_hover_pressed_color

Default

Color(1, 1, 1, 1)

Text Color used when the Button is being hovered and pressed.


  • Color font_outline_color

Default

Color(1, 1, 1, 1)

The tint of text outline of the Button.


  • Color font_pressed_color

Default

Color(1, 1, 1, 1)

Text Color used when the Button is being pressed.


  • int font_size

Font size of the Button's text.


StyleBox used when the Button is being hovered.


  • int hseparation

Default

2

The horizontal space between Button's icon and text.


  • Color icon_disabled_color

Default

Color(1, 1, 1, 1)

Icon modulate Color used when the Button is disabled.


Default

Color(1, 1, 1, 1)

Icon modulate Color used when the Button is being hovered.


  • Color icon_hover_pressed_color

Default

Color(1, 1, 1, 1)

Icon modulate Color used when the Button is being hovered and pressed.


  • Color icon_normal_color

Default

Color(1, 1, 1, 1)

Default icon modulate Color of the Button.


  • Color icon_pressed_color

Default

Color(1, 1, 1, 1)

Icon modulate Color used when the Button is being pressed.


Default StyleBox for the Button.


  • int outline_size

Default

0

The size of the text outline.


StyleBox used when the Button is being pressed.