class_button.rst 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  3. .. DO NOT EDIT THIS FILE, but the Button.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_Button:
  6. Button
  7. ======
  8. **Inherits:** :ref:`BaseButton<class_BaseButton>` **<** :ref:`Control<class_Control>` **<** :ref:`CanvasItem<class_CanvasItem>` **<** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
  9. **Inherited By:** :ref:`CheckBox<class_CheckBox>`, :ref:`CheckButton<class_CheckButton>`, :ref:`ColorPickerButton<class_ColorPickerButton>`, :ref:`MenuButton<class_MenuButton>`, :ref:`OptionButton<class_OptionButton>`, :ref:`ToolButton<class_ToolButton>`
  10. Standard themed Button.
  11. Description
  12. -----------
  13. Button is the standard themed button. It can contain text and an icon, and will display them according to the current :ref:`Theme<class_Theme>`.
  14. **Example of creating a button and assigning an action when pressed by code:**
  15. ::
  16. func _ready():
  17. var button = Button.new()
  18. button.text = "Click me"
  19. button.connect("pressed", self, "_button_pressed")
  20. add_child(button)
  21. func _button_pressed():
  22. print("Hello world!")
  23. Buttons (like all Control nodes) can also be created in the editor, but some situations may require creating them from code.
  24. See also :ref:`BaseButton<class_BaseButton>` which contains common properties and methods associated with this node.
  25. Tutorials
  26. ---------
  27. - `https://godotengine.org/asset-library/asset/515 <https://godotengine.org/asset-library/asset/515>`_
  28. - `https://godotengine.org/asset-library/asset/677 <https://godotengine.org/asset-library/asset/677>`_
  29. Properties
  30. ----------
  31. +-----------------------------------------+-------------------------------------------------------+-----------+
  32. | :ref:`TextAlign<enum_Button_TextAlign>` | :ref:`align<class_Button_property_align>` | ``1`` |
  33. +-----------------------------------------+-------------------------------------------------------+-----------+
  34. | :ref:`bool<class_bool>` | :ref:`clip_text<class_Button_property_clip_text>` | ``false`` |
  35. +-----------------------------------------+-------------------------------------------------------+-----------+
  36. | :ref:`bool<class_bool>` | :ref:`expand_icon<class_Button_property_expand_icon>` | ``false`` |
  37. +-----------------------------------------+-------------------------------------------------------+-----------+
  38. | :ref:`bool<class_bool>` | :ref:`flat<class_Button_property_flat>` | ``false`` |
  39. +-----------------------------------------+-------------------------------------------------------+-----------+
  40. | :ref:`Texture<class_Texture>` | :ref:`icon<class_Button_property_icon>` | |
  41. +-----------------------------------------+-------------------------------------------------------+-----------+
  42. | :ref:`String<class_String>` | :ref:`text<class_Button_property_text>` | ``""`` |
  43. +-----------------------------------------+-------------------------------------------------------+-----------+
  44. Theme Properties
  45. ----------------
  46. +---------------------------------+---------------------+------------------------------+
  47. | :ref:`StyleBox<class_StyleBox>` | disabled | |
  48. +---------------------------------+---------------------+------------------------------+
  49. | :ref:`StyleBox<class_StyleBox>` | focus | |
  50. +---------------------------------+---------------------+------------------------------+
  51. | :ref:`Font<class_Font>` | font | |
  52. +---------------------------------+---------------------+------------------------------+
  53. | :ref:`Color<class_Color>` | font_color | Color( 0.88, 0.88, 0.88, 1 ) |
  54. +---------------------------------+---------------------+------------------------------+
  55. | :ref:`Color<class_Color>` | font_color_disabled | Color( 0.9, 0.9, 0.9, 0.2 ) |
  56. +---------------------------------+---------------------+------------------------------+
  57. | :ref:`Color<class_Color>` | font_color_hover | Color( 0.94, 0.94, 0.94, 1 ) |
  58. +---------------------------------+---------------------+------------------------------+
  59. | :ref:`Color<class_Color>` | font_color_pressed | Color( 1, 1, 1, 1 ) |
  60. +---------------------------------+---------------------+------------------------------+
  61. | :ref:`StyleBox<class_StyleBox>` | hover | |
  62. +---------------------------------+---------------------+------------------------------+
  63. | :ref:`int<class_int>` | hseparation | 2 |
  64. +---------------------------------+---------------------+------------------------------+
  65. | :ref:`StyleBox<class_StyleBox>` | normal | |
  66. +---------------------------------+---------------------+------------------------------+
  67. | :ref:`StyleBox<class_StyleBox>` | pressed | |
  68. +---------------------------------+---------------------+------------------------------+
  69. Enumerations
  70. ------------
  71. .. _enum_Button_TextAlign:
  72. .. _class_Button_constant_ALIGN_LEFT:
  73. .. _class_Button_constant_ALIGN_CENTER:
  74. .. _class_Button_constant_ALIGN_RIGHT:
  75. enum **TextAlign**:
  76. - **ALIGN_LEFT** = **0** --- Align the text to the left.
  77. - **ALIGN_CENTER** = **1** --- Align the text to the center.
  78. - **ALIGN_RIGHT** = **2** --- Align the text to the right.
  79. Property Descriptions
  80. ---------------------
  81. .. _class_Button_property_align:
  82. - :ref:`TextAlign<enum_Button_TextAlign>` **align**
  83. +-----------+-----------------------+
  84. | *Default* | ``1`` |
  85. +-----------+-----------------------+
  86. | *Setter* | set_text_align(value) |
  87. +-----------+-----------------------+
  88. | *Getter* | get_text_align() |
  89. +-----------+-----------------------+
  90. Text alignment policy for the button's text, use one of the :ref:`TextAlign<enum_Button_TextAlign>` constants.
  91. ----
  92. .. _class_Button_property_clip_text:
  93. - :ref:`bool<class_bool>` **clip_text**
  94. +-----------+----------------------+
  95. | *Default* | ``false`` |
  96. +-----------+----------------------+
  97. | *Setter* | set_clip_text(value) |
  98. +-----------+----------------------+
  99. | *Getter* | get_clip_text() |
  100. +-----------+----------------------+
  101. 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.
  102. ----
  103. .. _class_Button_property_expand_icon:
  104. - :ref:`bool<class_bool>` **expand_icon**
  105. +-----------+------------------------+
  106. | *Default* | ``false`` |
  107. +-----------+------------------------+
  108. | *Setter* | set_expand_icon(value) |
  109. +-----------+------------------------+
  110. | *Getter* | is_expand_icon() |
  111. +-----------+------------------------+
  112. When enabled, the button's icon will expand/shrink to fit the button's size while keeping its aspect.
  113. ----
  114. .. _class_Button_property_flat:
  115. - :ref:`bool<class_bool>` **flat**
  116. +-----------+-----------------+
  117. | *Default* | ``false`` |
  118. +-----------+-----------------+
  119. | *Setter* | set_flat(value) |
  120. +-----------+-----------------+
  121. | *Getter* | is_flat() |
  122. +-----------+-----------------+
  123. Flat buttons don't display decoration.
  124. ----
  125. .. _class_Button_property_icon:
  126. - :ref:`Texture<class_Texture>` **icon**
  127. +----------+------------------------+
  128. | *Setter* | set_button_icon(value) |
  129. +----------+------------------------+
  130. | *Getter* | get_button_icon() |
  131. +----------+------------------------+
  132. Button's icon, if text is present the icon will be placed before the text.
  133. ----
  134. .. _class_Button_property_text:
  135. - :ref:`String<class_String>` **text**
  136. +-----------+-----------------+
  137. | *Default* | ``""`` |
  138. +-----------+-----------------+
  139. | *Setter* | set_text(value) |
  140. +-----------+-----------------+
  141. | *Getter* | get_text() |
  142. +-----------+-----------------+
  143. The button's text that will be displayed inside the button's area.
  144. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  145. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  146. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`