summaryrefslogtreecommitdiff
path: root/doc/classes/Button.xml
blob: 4bbe74f88880cb2af607c665866879d86de89456 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?xml version="1.0" encoding="UTF-8" ?>
<class name="Button" inherits="BaseButton" version="4.0">
	<brief_description>
		Standard themed Button.
	</brief_description>
	<description>
		Button is the standard themed button. It can contain text and an icon, and will display them according to the current [Theme].
		[b]Example of creating a button and assigning an action when pressed by code:[/b]
		[codeblocks]
		[gdscript]
		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!")
		[/gdscript]
		[csharp]
		public override void _Ready()
		{
		    var button = new Button();
		    button.Text = "Click me";
		    button.Connect("pressed", this, nameof(ButtonPressed));
		    AddChild(button);
		}

		private void ButtonPressed()
		{
		    GD.Print("Hello world!");
		}
		[/csharp]
		[/codeblocks]
		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.
	</description>
	<tutorials>
		<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>
	</tutorials>
	<methods>
		<method name="clear_opentype_features">
			<return type="void">
			</return>
			<description>
				Removes all OpenType features.
			</description>
		</method>
		<method name="get_opentype_feature" qualifiers="const">
			<return type="int">
			</return>
			<argument index="0" name="tag" type="String">
			</argument>
			<description>
				Returns OpenType feature [code]tag[/code].
			</description>
		</method>
		<method name="set_opentype_feature">
			<return type="void">
			</return>
			<argument index="0" name="tag" type="String">
			</argument>
			<argument index="1" name="value" type="int">
			</argument>
			<description>
				Sets OpenType feature [code]tag[/code]. More info: [url=https://docs.microsoft.com/en-us/typography/opentype/spec/featuretags]OpenType feature tags[/url].
			</description>
		</method>
	</methods>
	<members>
		<member name="align" type="int" setter="set_text_align" getter="get_text_align" enum="Button.TextAlign" default="1">
			Text alignment policy for the button's text, use one of the [enum TextAlign] constants.
		</member>
		<member name="clip_text" type="bool" setter="set_clip_text" getter="get_clip_text" default="false">
			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.
		</member>
		<member name="expand_icon" type="bool" setter="set_expand_icon" getter="is_expand_icon" default="false">
			When enabled, the button's icon will expand/shrink to fit the button's size while keeping its aspect.
		</member>
		<member name="flat" type="bool" setter="set_flat" getter="is_flat" default="false">
			Flat buttons don't display decoration.
		</member>
		<member name="icon" type="Texture2D" setter="set_button_icon" getter="get_button_icon">
			Button's icon, if text is present the icon will be placed before the text.
		</member>
		<member name="language" type="String" setter="set_language" getter="get_language" default="&quot;&quot;">
			Language code used for line-breaking and text shaping algorithms, if left empty current locale is used instead.
		</member>
		<member name="text" type="String" setter="set_text" getter="get_text" default="&quot;&quot;">
			The button's text that will be displayed inside the button's area.
		</member>
		<member name="text_direction" type="int" setter="set_text_direction" getter="get_text_direction" enum="Control.TextDirection" default="0">
			Base text writing direction.
		</member>
	</members>
	<constants>
		<constant name="ALIGN_LEFT" value="0" enum="TextAlign">
			Align the text to the left.
		</constant>
		<constant name="ALIGN_CENTER" value="1" enum="TextAlign">
			Align the text to the center.
		</constant>
		<constant name="ALIGN_RIGHT" value="2" enum="TextAlign">
			Align the text to the right.
		</constant>
	</constants>
	<theme_items>
		<theme_item name="disabled" type="StyleBox">
			[StyleBox] used when the [Button] is disabled.
		</theme_item>
		<theme_item name="focus" type="StyleBox">
			[StyleBox] used when the [Button] is focused. It is displayed over the current [StyleBox], so using [StyleBoxEmpty] will just disable the focus visual effect.
		</theme_item>
		<theme_item name="font" type="Font">
			[Font] of the [Button]'s text.
		</theme_item>
		<theme_item name="font_color" type="Color" default="Color( 0.88, 0.88, 0.88, 1 )">
			Default text [Color] of the [Button].
		</theme_item>
		<theme_item name="font_disabled_color" type="Color" default="Color( 0.9, 0.9, 0.9, 0.2 )">
			Text [Color] used when the [Button] is disabled.
		</theme_item>
		<theme_item name="font_hover_color" type="Color" default="Color( 0.94, 0.94, 0.94, 1 )">
			Text [Color] used when the [Button] is being hovered.
		</theme_item>
		<theme_item name="font_outline_color" type="Color" default="Color( 1, 1, 1, 1 )">
			Text outline [Color] of the [Button].
		</theme_item>
		<theme_item name="font_pressed_color" type="Color" default="Color( 1, 1, 1, 1 )">
			Text [Color] used when the [Button] is being pressed.
		</theme_item>
		<theme_item name="font_size" type="int">
			Font size of the [Button]'s text.
		</theme_item>
		<theme_item name="hover" type="StyleBox">
			[StyleBox] used when the [Button] is being hovered.
		</theme_item>
		<theme_item name="hseparation" type="int" default="2">
			The horizontal space between [Button]'s icon and text.
		</theme_item>
		<theme_item name="normal" type="StyleBox">
			Default [StyleBox] for the [Button].
		</theme_item>
		<theme_item name="outline_size" type="int" default="0">
			Size of the [Button]'s text outline.
		</theme_item>
		<theme_item name="pressed" type="StyleBox">
			[StyleBox] used when the [Button] is being pressed.
		</theme_item>
	</theme_items>
</class>