2017-09-13 04:42:36 +08:00
<?xml version="1.0" encoding="UTF-8" ?>
2023-03-01 08:44:37 +08:00
<class name= "Button" inherits= "BaseButton" version= "4.1" xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation= "../class.xsd" >
2017-09-13 04:42:36 +08:00
<brief_description >
2023-04-30 22:26:09 +08:00
A themed button that can contain text and an icon.
2017-09-13 04:42:36 +08:00
</brief_description>
<description >
2023-04-30 22:26:09 +08:00
[Button] is the standard themed button. It can contain text and an icon, and it will display them according to the current [Theme].
2020-07-15 22:31:10 +08:00
[b]Example of creating a button and assigning an action when pressed by code:[/b]
2020-07-31 22:07:26 +08:00
[codeblocks]
[gdscript]
2020-07-15 22:31:10 +08:00
func _ready():
var button = Button.new()
button.text = "Click me"
2022-10-30 07:56:46 +08:00
button.pressed.connect(self._button_pressed)
2020-07-15 22:31:10 +08:00
add_child(button)
func _button_pressed():
print("Hello world!")
2020-07-31 22:07:26 +08:00
[/gdscript]
[csharp]
public override void _Ready()
{
var button = new Button();
button.Text = "Click me";
2022-10-30 07:56:46 +08:00
button.Pressed += ButtonPressed;
2020-07-31 22:07:26 +08:00
AddChild(button);
}
private void ButtonPressed()
{
GD.Print("Hello world!");
}
[/csharp]
[/codeblocks]
2020-09-24 05:34:28 +08:00
See also [BaseButton] which contains common properties and methods associated with this node.
2023-04-30 22:26:09 +08:00
[b]Note:[/b] 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.
2017-09-13 04:42:36 +08:00
</description>
<tutorials >
2020-10-01 16:34:47 +08:00
<link title= "2D Dodge The Creeps Demo" > https://godotengine.org/asset-library/asset/515</link>
<link title= "OS Test Demo" > https://godotengine.org/asset-library/asset/677</link>
2017-09-13 04:42:36 +08:00
</tutorials>
<members >
2021-11-25 10:58:47 +08:00
<member name= "alignment" type= "int" setter= "set_text_alignment" getter= "get_text_alignment" enum= "HorizontalAlignment" default= "1" >
2022-11-01 22:29:38 +08:00
Text alignment policy for the button's text, use one of the [enum HorizontalAlignment] constants.
2017-09-13 04:42:36 +08:00
</member>
2019-06-29 18:38:01 +08:00
<member name= "clip_text" type= "bool" setter= "set_clip_text" getter= "get_clip_text" default= "false" >
2019-08-29 10:12:22 +08:00
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.
2017-09-13 04:42:36 +08:00
</member>
2019-08-21 00:41:14 +08:00
<member name= "expand_icon" type= "bool" setter= "set_expand_icon" getter= "is_expand_icon" default= "false" >
2023-04-01 03:17:59 +08:00
When enabled, the button's icon will expand/shrink to fit the button's size while keeping its aspect. See also [theme_item icon_max_width].
2019-08-21 00:41:14 +08:00
</member>
2019-06-29 18:38:01 +08:00
<member name= "flat" type= "bool" setter= "set_flat" getter= "is_flat" default= "false" >
2017-09-13 04:42:36 +08:00
Flat buttons don't display decoration.
</member>
2020-02-12 16:59:06 +08:00
<member name= "icon" type= "Texture2D" setter= "set_button_icon" getter= "get_button_icon" >
2017-09-13 04:42:36 +08:00
Button's icon, if text is present the icon will be placed before the text.
2022-04-15 05:20:28 +08:00
To edit margin and spacing of the icon, use [theme_item h_separation] theme property and [code]content_margin_*[/code] properties of the used [StyleBox]es.
2017-09-13 04:42:36 +08:00
</member>
2021-11-25 10:58:47 +08:00
<member name= "icon_alignment" type= "int" setter= "set_icon_alignment" getter= "get_icon_alignment" enum= "HorizontalAlignment" default= "0" >
2023-03-04 04:21:41 +08:00
Specifies if the icon should be aligned horizontally to the left, right, or center of a button. Uses the same [enum HorizontalAlignment] constants as the text alignment. If centered horizontally and vertically, text will draw on top of the icon.
2019-10-25 11:29:10 +08:00
</member>
2020-08-12 19:49:10 +08:00
<member name= "language" type= "String" setter= "set_language" getter= "get_language" default= """" >
Language code used for line-breaking and text shaping algorithms, if left empty current locale is used instead.
</member>
2019-06-29 18:38:01 +08:00
<member name= "text" type= "String" setter= "set_text" getter= "get_text" default= """" >
2017-09-13 04:42:36 +08:00
The button's text that will be displayed inside the button's area.
</member>
2020-08-12 19:49:10 +08:00
<member name= "text_direction" type= "int" setter= "set_text_direction" getter= "get_text_direction" enum= "Control.TextDirection" default= "0" >
Base text writing direction.
</member>
2022-06-15 16:01:45 +08:00
<member name= "text_overrun_behavior" type= "int" setter= "set_text_overrun_behavior" getter= "get_text_overrun_behavior" enum= "TextServer.OverrunBehavior" default= "0" >
Sets the clipping behavior when the text exceeds the node's bounding rectangle. See [enum TextServer.OverrunBehavior] for a description of all modes.
2022-06-09 00:02:27 +08:00
</member>
2023-03-04 04:21:41 +08:00
<member name= "vertical_icon_alignment" type= "int" setter= "set_vertical_icon_alignment" getter= "get_vertical_icon_alignment" enum= "VerticalAlignment" default= "1" >
Specifies if the icon should be aligned vertically to the top, bottom, or center of a button. Uses the same [enum VerticalAlignment] constants as the text alignment. If centered horizontally and vertically, text will draw on top of the icon.
</member>
2017-09-13 04:42:36 +08:00
</members>
<theme_items >
2021-12-31 00:22:06 +08:00
<theme_item name= "font_color" data_type= "color" type= "Color" default= "Color(0.875, 0.875, 0.875, 1)" >
2020-01-27 09:15:37 +08:00
Default text [Color] of the [Button].
2017-09-13 04:42:36 +08:00
</theme_item>
2021-12-31 00:22:06 +08:00
<theme_item name= "font_disabled_color" data_type= "color" type= "Color" default= "Color(0.875, 0.875, 0.875, 0.5)" >
2020-01-27 09:15:37 +08:00
Text [Color] used when the [Button] is disabled.
2017-09-13 04:42:36 +08:00
</theme_item>
2021-12-31 00:22:06 +08:00
<theme_item name= "font_focus_color" data_type= "color" type= "Color" default= "Color(0.95, 0.95, 0.95, 1)" >
2021-10-26 22:28:12 +08:00
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.
</theme_item>
2021-12-31 00:22:06 +08:00
<theme_item name= "font_hover_color" data_type= "color" type= "Color" default= "Color(0.95, 0.95, 0.95, 1)" >
2020-01-27 09:15:37 +08:00
Text [Color] used when the [Button] is being hovered.
2017-09-13 04:42:36 +08:00
</theme_item>
2021-08-05 00:54:41 +08:00
<theme_item name= "font_hover_pressed_color" data_type= "color" type= "Color" default= "Color(1, 1, 1, 1)" >
2021-01-27 15:22:23 +08:00
Text [Color] used when the [Button] is being hovered and pressed.
</theme_item>
2021-08-05 00:54:41 +08:00
<theme_item name= "font_outline_color" data_type= "color" type= "Color" default= "Color(1, 1, 1, 1)" >
2020-12-26 05:45:28 +08:00
The tint of text outline of the [Button].
2017-09-13 04:42:36 +08:00
</theme_item>
2021-08-05 00:54:41 +08:00
<theme_item name= "font_pressed_color" data_type= "color" type= "Color" default= "Color(1, 1, 1, 1)" >
2020-12-08 21:11:45 +08:00
Text [Color] used when the [Button] is being pressed.
2020-08-12 19:49:10 +08:00
</theme_item>
2022-02-09 00:42:00 +08:00
<theme_item name= "icon_disabled_color" data_type= "color" type= "Color" default= "Color(1, 1, 1, 0.4)" >
2020-05-08 14:03:52 +08:00
Icon modulate [Color] used when the [Button] is disabled.
</theme_item>
2021-10-26 22:28:12 +08:00
<theme_item name= "icon_focus_color" data_type= "color" type= "Color" default= "Color(1, 1, 1, 1)" >
Icon modulate [Color] used when the [Button] is focused. Only replaces the normal modulate color of the button. Disabled, hovered, and pressed states take precedence over this color.
</theme_item>
2021-08-05 00:54:41 +08:00
<theme_item name= "icon_hover_color" data_type= "color" type= "Color" default= "Color(1, 1, 1, 1)" >
2020-05-08 14:03:52 +08:00
Icon modulate [Color] used when the [Button] is being hovered.
</theme_item>
2021-08-05 00:54:41 +08:00
<theme_item name= "icon_hover_pressed_color" data_type= "color" type= "Color" default= "Color(1, 1, 1, 1)" >
2020-05-08 14:03:52 +08:00
Icon modulate [Color] used when the [Button] is being hovered and pressed.
</theme_item>
2021-08-05 00:54:41 +08:00
<theme_item name= "icon_normal_color" data_type= "color" type= "Color" default= "Color(1, 1, 1, 1)" >
2021-01-27 15:22:23 +08:00
Default icon modulate [Color] of the [Button].
2020-05-08 14:03:52 +08:00
</theme_item>
2021-08-05 00:54:41 +08:00
<theme_item name= "icon_pressed_color" data_type= "color" type= "Color" default= "Color(1, 1, 1, 1)" >
2020-05-08 14:03:52 +08:00
Icon modulate [Color] used when the [Button] is being pressed.
</theme_item>
2022-04-15 05:20:28 +08:00
<theme_item name= "h_separation" data_type= "constant" type= "int" default= "2" >
2022-08-12 19:39:22 +08:00
The horizontal space between [Button]'s icon and text. Negative values will be treated as [code]0[/code] when used.
2017-09-13 04:42:36 +08:00
</theme_item>
2023-04-01 03:17:59 +08:00
<theme_item name= "icon_max_width" data_type= "constant" type= "int" default= "0" >
The maximum allowed width of the [Button]'s icon. This limit is applied on top of the default size of the icon, or its expanded size if [member expand_icon] is [code]true[/code]. The height is adjusted according to the icon's ratio.
</theme_item>
2021-08-05 00:54:41 +08:00
<theme_item name= "outline_size" data_type= "constant" type= "int" default= "0" >
2020-12-26 05:45:28 +08:00
The size of the text outline.
2022-12-20 00:15:44 +08:00
[b]Note:[/b] If using a font with [member FontFile.multichannel_signed_distance_field] enabled, its [member FontFile.msdf_pixel_range] must be set to at least [i]twice[/i] the value of [theme_item outline_size] for outline rendering to look correct. Otherwise, the outline may appear to be cut off earlier than intended.
2020-08-12 19:49:10 +08:00
</theme_item>
2021-12-02 02:02:20 +08:00
<theme_item name= "font" data_type= "font" type= "Font" >
[Font] of the [Button]'s text.
</theme_item>
<theme_item name= "font_size" data_type= "font_size" type= "int" >
Font size of the [Button]'s text.
</theme_item>
<theme_item name= "disabled" data_type= "style" type= "StyleBox" >
[StyleBox] used when the [Button] is disabled.
</theme_item>
<theme_item name= "focus" data_type= "style" type= "StyleBox" >
2021-11-21 00:43:34 +08:00
[StyleBox] used when the [Button] is focused. The [code]focus[/code] [StyleBox] is displayed [i]over[/i] the base [StyleBox], so a partially transparent [StyleBox] should be used to ensure the base [StyleBox] remains visible. A [StyleBox] that represents an outline or an underline works well for this purpose. To disable the focus visual effect, assign a [StyleBoxEmpty] resource. Note that disabling the focus visual effect will harm keyboard/controller navigation usability, so this is not recommended for accessibility reasons.
2021-12-02 02:02:20 +08:00
</theme_item>
<theme_item name= "hover" data_type= "style" type= "StyleBox" >
[StyleBox] used when the [Button] is being hovered.
</theme_item>
<theme_item name= "normal" data_type= "style" type= "StyleBox" >
Default [StyleBox] for the [Button].
</theme_item>
2021-08-05 00:54:41 +08:00
<theme_item name= "pressed" data_type= "style" type= "StyleBox" >
2020-01-27 09:15:37 +08:00
[StyleBox] used when the [Button] is being pressed.
2017-09-13 04:42:36 +08:00
</theme_item>
</theme_items>
</class>