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 currentTheme.
Example of creating a button and assigning an action when pressed by code:
func_ready():varbutton=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 alsoBaseButton 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. UseTouchScreenButton for buttons that trigger gameplay movement or actions, asTouchScreenButton supports multitouch.
Tutorials¶
Properties¶
| ||
| ||
| ||
| ||
|
Theme Properties¶
| ||
| ||
| ||
| ||
| ||
| ||
Enumerations¶
enumTextAlign:
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¶
TextAlignalign
Default |
|
Setter | set_text_align(value) |
Getter | get_text_align() |
Text alignment policy for the button's text, use one of theTextAlign constants.
boolclip_text
Default |
|
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.
boolexpand_icon
Default |
|
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.
boolflat
Default |
|
Setter | set_flat(value) |
Getter | is_flat() |
Flat buttons don't display decoration.
Textureicon
Setter | set_button_icon(value) |
Getter | get_button_icon() |
Button's icon, if text is present the icon will be placed before the text.
To edit margin and spacing of the icon, usehseparation theme property ofButton andcontent_margin_* properties of the usedStyleBoxes.
Stringtext
Default |
|
Setter | set_text(value) |
Getter | get_text() |
The button's text that will be displayed inside the button's area.
Theme Property Descriptions¶
Colorfont_color
Default |
|
Default textColor of theButton.
Colorfont_color_disabled
Default |
|
TextColor used when theButton is disabled.
Colorfont_color_focus
Default |
|
TextColor used when theButton is focused. Only replaces the normal text color of the button. Disabled, hovered, and pressed states take precedence over this color.
Colorfont_color_hover
Default |
|
TextColor used when theButton is being hovered.
Colorfont_color_pressed
Default |
|
TextColor used when theButton is being pressed.
inthseparation
Default |
|
The horizontal space betweenButton's icon and text.
Fontfont
Font of theButton's text.
StyleBoxdisabled
StyleBox used when theButton is disabled.
StyleBoxfocus
StyleBox used when theButton is focused. It is displayed over the currentStyleBox, so usingStyleBoxEmpty will just disable the focus visual effect.
StyleBoxhover
StyleBox used when theButton is being hovered.
StyleBoxnormal
DefaultStyleBox for theButton.
StyleBoxpressed
StyleBox used when theButton is being pressed.