Button.xml 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <class name="Button" inherits="BaseButton" version="4.0">
  3. <brief_description>
  4. Standard themed Button.
  5. </brief_description>
  6. <description>
  7. Button is the standard themed button. It can contain text and an icon, and will display them according to the current [Theme].
  8. [b]Example of creating a button and assigning an action when pressed by code:[/b]
  9. [codeblocks]
  10. [gdscript]
  11. func _ready():
  12. var button = Button.new()
  13. button.text = "Click me"
  14. button.connect("pressed", self, "_button_pressed")
  15. add_child(button)
  16. func _button_pressed():
  17. print("Hello world!")
  18. [/gdscript]
  19. [csharp]
  20. public override void _Ready()
  21. {
  22. var button = new Button();
  23. button.Text = "Click me";
  24. button.Connect("pressed", this, nameof(ButtonPressed));
  25. AddChild(button);
  26. }
  27. private void ButtonPressed()
  28. {
  29. GD.Print("Hello world!");
  30. }
  31. [/csharp]
  32. [/codeblocks]
  33. Buttons (like all Control nodes) can also be created in the editor, but some situations may require creating them from code.
  34. See also [BaseButton] which contains common properties and methods associated with this node.
  35. [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, as [TouchScreenButton] supports multitouch.
  36. </description>
  37. <tutorials>
  38. <link title="2D Dodge The Creeps Demo">https://godotengine.org/asset-library/asset/515</link>
  39. <link title="OS Test Demo">https://godotengine.org/asset-library/asset/677</link>
  40. </tutorials>
  41. <methods>
  42. <method name="clear_opentype_features">
  43. <return type="void" />
  44. <description>
  45. Removes all OpenType features.
  46. </description>
  47. </method>
  48. <method name="get_opentype_feature" qualifiers="const">
  49. <return type="int" />
  50. <argument index="0" name="tag" type="String" />
  51. <description>
  52. Returns OpenType feature [code]tag[/code].
  53. </description>
  54. </method>
  55. <method name="set_opentype_feature">
  56. <return type="void" />
  57. <argument index="0" name="tag" type="String" />
  58. <argument index="1" name="value" type="int" />
  59. <description>
  60. Sets OpenType feature [code]tag[/code]. More info: [url=https://docs.microsoft.com/en-us/typography/opentype/spec/featuretags]OpenType feature tags[/url].
  61. </description>
  62. </method>
  63. </methods>
  64. <members>
  65. <member name="align" type="int" setter="set_text_align" getter="get_text_align" enum="Button.TextAlign" default="1">
  66. Text alignment policy for the button's text, use one of the [enum TextAlign] constants.
  67. </member>
  68. <member name="clip_text" type="bool" setter="set_clip_text" getter="get_clip_text" default="false">
  69. 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.
  70. </member>
  71. <member name="expand_icon" type="bool" setter="set_expand_icon" getter="is_expand_icon" default="false">
  72. When enabled, the button's icon will expand/shrink to fit the button's size while keeping its aspect.
  73. </member>
  74. <member name="flat" type="bool" setter="set_flat" getter="is_flat" default="false">
  75. Flat buttons don't display decoration.
  76. </member>
  77. <member name="icon" type="Texture2D" setter="set_button_icon" getter="get_button_icon">
  78. Button's icon, if text is present the icon will be placed before the text.
  79. </member>
  80. <member name="icon_align" type="int" setter="set_icon_align" getter="get_icon_align" enum="Button.TextAlign" default="0">
  81. Specifies if the icon should be aligned to the left, right, or center of a button. Uses the same [enum TextAlign] constants as the text alignment. If centered, text will draw on top of the icon.
  82. </member>
  83. <member name="language" type="String" setter="set_language" getter="get_language" default="&quot;&quot;">
  84. Language code used for line-breaking and text shaping algorithms, if left empty current locale is used instead.
  85. </member>
  86. <member name="text" type="String" setter="set_text" getter="get_text" default="&quot;&quot;">
  87. The button's text that will be displayed inside the button's area.
  88. </member>
  89. <member name="text_direction" type="int" setter="set_text_direction" getter="get_text_direction" enum="Control.TextDirection" default="0">
  90. Base text writing direction.
  91. </member>
  92. </members>
  93. <constants>
  94. <constant name="ALIGN_LEFT" value="0" enum="TextAlign">
  95. Align the text to the left.
  96. </constant>
  97. <constant name="ALIGN_CENTER" value="1" enum="TextAlign">
  98. Align the text to the center.
  99. </constant>
  100. <constant name="ALIGN_RIGHT" value="2" enum="TextAlign">
  101. Align the text to the right.
  102. </constant>
  103. </constants>
  104. <theme_items>
  105. <theme_item name="disabled" data_type="style" type="StyleBox">
  106. [StyleBox] used when the [Button] is disabled.
  107. </theme_item>
  108. <theme_item name="focus" data_type="style" type="StyleBox">
  109. [StyleBox] used when the [Button] is focused. It is displayed over the current [StyleBox], so using [StyleBoxEmpty] will just disable the focus visual effect.
  110. </theme_item>
  111. <theme_item name="font" data_type="font" type="Font">
  112. [Font] of the [Button]'s text.
  113. </theme_item>
  114. <theme_item name="font_color" data_type="color" type="Color" default="Color(0.88, 0.88, 0.88, 1)">
  115. Default text [Color] of the [Button].
  116. </theme_item>
  117. <theme_item name="font_disabled_color" data_type="color" type="Color" default="Color(0.9, 0.9, 0.9, 0.2)">
  118. Text [Color] used when the [Button] is disabled.
  119. </theme_item>
  120. <theme_item name="font_focus_color" data_type="color" type="Color" default="Color(0.94, 0.94, 0.94, 1)">
  121. 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.
  122. </theme_item>
  123. <theme_item name="font_hover_color" data_type="color" type="Color" default="Color(0.94, 0.94, 0.94, 1)">
  124. Text [Color] used when the [Button] is being hovered.
  125. </theme_item>
  126. <theme_item name="font_hover_pressed_color" data_type="color" type="Color" default="Color(1, 1, 1, 1)">
  127. Text [Color] used when the [Button] is being hovered and pressed.
  128. </theme_item>
  129. <theme_item name="font_outline_color" data_type="color" type="Color" default="Color(1, 1, 1, 1)">
  130. The tint of text outline of the [Button].
  131. </theme_item>
  132. <theme_item name="font_pressed_color" data_type="color" type="Color" default="Color(1, 1, 1, 1)">
  133. Text [Color] used when the [Button] is being pressed.
  134. </theme_item>
  135. <theme_item name="font_size" data_type="font_size" type="int">
  136. Font size of the [Button]'s text.
  137. </theme_item>
  138. <theme_item name="hover" data_type="style" type="StyleBox">
  139. [StyleBox] used when the [Button] is being hovered.
  140. </theme_item>
  141. <theme_item name="hseparation" data_type="constant" type="int" default="2">
  142. The horizontal space between [Button]'s icon and text.
  143. </theme_item>
  144. <theme_item name="icon_disabled_color" data_type="color" type="Color" default="Color(1, 1, 1, 1)">
  145. Icon modulate [Color] used when the [Button] is disabled.
  146. </theme_item>
  147. <theme_item name="icon_focus_color" data_type="color" type="Color" default="Color(1, 1, 1, 1)">
  148. 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.
  149. </theme_item>
  150. <theme_item name="icon_hover_color" data_type="color" type="Color" default="Color(1, 1, 1, 1)">
  151. Icon modulate [Color] used when the [Button] is being hovered.
  152. </theme_item>
  153. <theme_item name="icon_hover_pressed_color" data_type="color" type="Color" default="Color(1, 1, 1, 1)">
  154. Icon modulate [Color] used when the [Button] is being hovered and pressed.
  155. </theme_item>
  156. <theme_item name="icon_normal_color" data_type="color" type="Color" default="Color(1, 1, 1, 1)">
  157. Default icon modulate [Color] of the [Button].
  158. </theme_item>
  159. <theme_item name="icon_pressed_color" data_type="color" type="Color" default="Color(1, 1, 1, 1)">
  160. Icon modulate [Color] used when the [Button] is being pressed.
  161. </theme_item>
  162. <theme_item name="normal" data_type="style" type="StyleBox">
  163. Default [StyleBox] for the [Button].
  164. </theme_item>
  165. <theme_item name="outline_size" data_type="constant" type="int" default="0">
  166. The size of the text outline.
  167. </theme_item>
  168. <theme_item name="pressed" data_type="style" type="StyleBox">
  169. [StyleBox] used when the [Button] is being pressed.
  170. </theme_item>
  171. </theme_items>
  172. </class>