class_basebutton.rst 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/BaseButton.xml.
  6. .. _class_BaseButton:
  7. BaseButton
  8. ==========
  9. **Inherits:** :ref:`Control<class_Control>` **<** :ref:`CanvasItem<class_CanvasItem>` **<** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
  10. **Inherited By:** :ref:`Button<class_Button>`, :ref:`LinkButton<class_LinkButton>`, :ref:`TextureButton<class_TextureButton>`
  11. Abstract base class for GUI buttons.
  12. .. rst-class:: classref-introduction-group
  13. Description
  14. -----------
  15. **BaseButton** is an abstract base class for GUI buttons. It doesn't display anything by itself.
  16. .. rst-class:: classref-reftable-group
  17. Properties
  18. ----------
  19. .. table::
  20. :widths: auto
  21. +-------------------------------------------------------------------------+-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  22. | :ref:`ActionMode<enum_BaseButton_ActionMode>` | :ref:`action_mode<class_BaseButton_property_action_mode>` | ``1`` |
  23. +-------------------------------------------------------------------------+-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  24. | :ref:`ButtonGroup<class_ButtonGroup>` | :ref:`button_group<class_BaseButton_property_button_group>` | |
  25. +-------------------------------------------------------------------------+-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  26. | |bitfield|\[:ref:`MouseButtonMask<enum_@GlobalScope_MouseButtonMask>`\] | :ref:`button_mask<class_BaseButton_property_button_mask>` | ``1`` |
  27. +-------------------------------------------------------------------------+-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  28. | :ref:`bool<class_bool>` | :ref:`button_pressed<class_BaseButton_property_button_pressed>` | ``false`` |
  29. +-------------------------------------------------------------------------+-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  30. | :ref:`bool<class_bool>` | :ref:`disabled<class_BaseButton_property_disabled>` | ``false`` |
  31. +-------------------------------------------------------------------------+-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  32. | :ref:`FocusMode<enum_Control_FocusMode>` | focus_mode | ``2`` (overrides :ref:`Control<class_Control_property_focus_mode>`) |
  33. +-------------------------------------------------------------------------+-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  34. | :ref:`bool<class_bool>` | :ref:`keep_pressed_outside<class_BaseButton_property_keep_pressed_outside>` | ``false`` |
  35. +-------------------------------------------------------------------------+-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  36. | :ref:`Shortcut<class_Shortcut>` | :ref:`shortcut<class_BaseButton_property_shortcut>` | |
  37. +-------------------------------------------------------------------------+-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  38. | :ref:`bool<class_bool>` | :ref:`shortcut_feedback<class_BaseButton_property_shortcut_feedback>` | ``true`` |
  39. +-------------------------------------------------------------------------+-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  40. | :ref:`bool<class_bool>` | :ref:`shortcut_in_tooltip<class_BaseButton_property_shortcut_in_tooltip>` | ``true`` |
  41. +-------------------------------------------------------------------------+-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  42. | :ref:`bool<class_bool>` | :ref:`toggle_mode<class_BaseButton_property_toggle_mode>` | ``false`` |
  43. +-------------------------------------------------------------------------+-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  44. .. rst-class:: classref-reftable-group
  45. Methods
  46. -------
  47. .. table::
  48. :widths: auto
  49. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------+
  50. | |void| | :ref:`_pressed<class_BaseButton_private_method__pressed>`\ (\ ) |virtual| |
  51. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------+
  52. | |void| | :ref:`_toggled<class_BaseButton_private_method__toggled>`\ (\ toggled_on\: :ref:`bool<class_bool>`\ ) |virtual| |
  53. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------+
  54. | :ref:`DrawMode<enum_BaseButton_DrawMode>` | :ref:`get_draw_mode<class_BaseButton_method_get_draw_mode>`\ (\ ) |const| |
  55. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------+
  56. | :ref:`bool<class_bool>` | :ref:`is_hovered<class_BaseButton_method_is_hovered>`\ (\ ) |const| |
  57. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------+
  58. | |void| | :ref:`set_pressed_no_signal<class_BaseButton_method_set_pressed_no_signal>`\ (\ pressed\: :ref:`bool<class_bool>`\ ) |
  59. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------------+
  60. .. rst-class:: classref-section-separator
  61. ----
  62. .. rst-class:: classref-descriptions-group
  63. Signals
  64. -------
  65. .. _class_BaseButton_signal_button_down:
  66. .. rst-class:: classref-signal
  67. **button_down**\ (\ ) :ref:`🔗<class_BaseButton_signal_button_down>`
  68. Emitted when the button starts being held down.
  69. .. rst-class:: classref-item-separator
  70. ----
  71. .. _class_BaseButton_signal_button_up:
  72. .. rst-class:: classref-signal
  73. **button_up**\ (\ ) :ref:`🔗<class_BaseButton_signal_button_up>`
  74. Emitted when the button stops being held down.
  75. .. rst-class:: classref-item-separator
  76. ----
  77. .. _class_BaseButton_signal_pressed:
  78. .. rst-class:: classref-signal
  79. **pressed**\ (\ ) :ref:`🔗<class_BaseButton_signal_pressed>`
  80. Emitted when the button is toggled or pressed. This is on :ref:`button_down<class_BaseButton_signal_button_down>` if :ref:`action_mode<class_BaseButton_property_action_mode>` is :ref:`ACTION_MODE_BUTTON_PRESS<class_BaseButton_constant_ACTION_MODE_BUTTON_PRESS>` and on :ref:`button_up<class_BaseButton_signal_button_up>` otherwise.
  81. If you need to know the button's pressed state (and :ref:`toggle_mode<class_BaseButton_property_toggle_mode>` is active), use :ref:`toggled<class_BaseButton_signal_toggled>` instead.
  82. .. rst-class:: classref-item-separator
  83. ----
  84. .. _class_BaseButton_signal_toggled:
  85. .. rst-class:: classref-signal
  86. **toggled**\ (\ toggled_on\: :ref:`bool<class_bool>`\ ) :ref:`🔗<class_BaseButton_signal_toggled>`
  87. Emitted when the button was just toggled between pressed and normal states (only if :ref:`toggle_mode<class_BaseButton_property_toggle_mode>` is active). The new state is contained in the ``toggled_on`` argument.
  88. .. rst-class:: classref-section-separator
  89. ----
  90. .. rst-class:: classref-descriptions-group
  91. Enumerations
  92. ------------
  93. .. _enum_BaseButton_DrawMode:
  94. .. rst-class:: classref-enumeration
  95. enum **DrawMode**: :ref:`🔗<enum_BaseButton_DrawMode>`
  96. .. _class_BaseButton_constant_DRAW_NORMAL:
  97. .. rst-class:: classref-enumeration-constant
  98. :ref:`DrawMode<enum_BaseButton_DrawMode>` **DRAW_NORMAL** = ``0``
  99. The normal state (i.e. not pressed, not hovered, not toggled and enabled) of buttons.
  100. .. _class_BaseButton_constant_DRAW_PRESSED:
  101. .. rst-class:: classref-enumeration-constant
  102. :ref:`DrawMode<enum_BaseButton_DrawMode>` **DRAW_PRESSED** = ``1``
  103. The state of buttons are pressed.
  104. .. _class_BaseButton_constant_DRAW_HOVER:
  105. .. rst-class:: classref-enumeration-constant
  106. :ref:`DrawMode<enum_BaseButton_DrawMode>` **DRAW_HOVER** = ``2``
  107. The state of buttons are hovered.
  108. .. _class_BaseButton_constant_DRAW_DISABLED:
  109. .. rst-class:: classref-enumeration-constant
  110. :ref:`DrawMode<enum_BaseButton_DrawMode>` **DRAW_DISABLED** = ``3``
  111. The state of buttons are disabled.
  112. .. _class_BaseButton_constant_DRAW_HOVER_PRESSED:
  113. .. rst-class:: classref-enumeration-constant
  114. :ref:`DrawMode<enum_BaseButton_DrawMode>` **DRAW_HOVER_PRESSED** = ``4``
  115. The state of buttons are both hovered and pressed.
  116. .. rst-class:: classref-item-separator
  117. ----
  118. .. _enum_BaseButton_ActionMode:
  119. .. rst-class:: classref-enumeration
  120. enum **ActionMode**: :ref:`🔗<enum_BaseButton_ActionMode>`
  121. .. _class_BaseButton_constant_ACTION_MODE_BUTTON_PRESS:
  122. .. rst-class:: classref-enumeration-constant
  123. :ref:`ActionMode<enum_BaseButton_ActionMode>` **ACTION_MODE_BUTTON_PRESS** = ``0``
  124. Require just a press to consider the button clicked.
  125. .. _class_BaseButton_constant_ACTION_MODE_BUTTON_RELEASE:
  126. .. rst-class:: classref-enumeration-constant
  127. :ref:`ActionMode<enum_BaseButton_ActionMode>` **ACTION_MODE_BUTTON_RELEASE** = ``1``
  128. Require a press and a subsequent release before considering the button clicked.
  129. .. rst-class:: classref-section-separator
  130. ----
  131. .. rst-class:: classref-descriptions-group
  132. Property Descriptions
  133. ---------------------
  134. .. _class_BaseButton_property_action_mode:
  135. .. rst-class:: classref-property
  136. :ref:`ActionMode<enum_BaseButton_ActionMode>` **action_mode** = ``1`` :ref:`🔗<class_BaseButton_property_action_mode>`
  137. .. rst-class:: classref-property-setget
  138. - |void| **set_action_mode**\ (\ value\: :ref:`ActionMode<enum_BaseButton_ActionMode>`\ )
  139. - :ref:`ActionMode<enum_BaseButton_ActionMode>` **get_action_mode**\ (\ )
  140. Determines when the button is considered clicked, one of the :ref:`ActionMode<enum_BaseButton_ActionMode>` constants.
  141. .. rst-class:: classref-item-separator
  142. ----
  143. .. _class_BaseButton_property_button_group:
  144. .. rst-class:: classref-property
  145. :ref:`ButtonGroup<class_ButtonGroup>` **button_group** :ref:`🔗<class_BaseButton_property_button_group>`
  146. .. rst-class:: classref-property-setget
  147. - |void| **set_button_group**\ (\ value\: :ref:`ButtonGroup<class_ButtonGroup>`\ )
  148. - :ref:`ButtonGroup<class_ButtonGroup>` **get_button_group**\ (\ )
  149. The :ref:`ButtonGroup<class_ButtonGroup>` associated with the button. Not to be confused with node groups.
  150. \ **Note:** The button will be configured as a radio button if a :ref:`ButtonGroup<class_ButtonGroup>` is assigned to it.
  151. .. rst-class:: classref-item-separator
  152. ----
  153. .. _class_BaseButton_property_button_mask:
  154. .. rst-class:: classref-property
  155. |bitfield|\[:ref:`MouseButtonMask<enum_@GlobalScope_MouseButtonMask>`\] **button_mask** = ``1`` :ref:`🔗<class_BaseButton_property_button_mask>`
  156. .. rst-class:: classref-property-setget
  157. - |void| **set_button_mask**\ (\ value\: |bitfield|\[:ref:`MouseButtonMask<enum_@GlobalScope_MouseButtonMask>`\]\ )
  158. - |bitfield|\[:ref:`MouseButtonMask<enum_@GlobalScope_MouseButtonMask>`\] **get_button_mask**\ (\ )
  159. Binary mask to choose which mouse buttons this button will respond to.
  160. To allow both left-click and right-click, use ``MOUSE_BUTTON_MASK_LEFT | MOUSE_BUTTON_MASK_RIGHT``.
  161. .. rst-class:: classref-item-separator
  162. ----
  163. .. _class_BaseButton_property_button_pressed:
  164. .. rst-class:: classref-property
  165. :ref:`bool<class_bool>` **button_pressed** = ``false`` :ref:`🔗<class_BaseButton_property_button_pressed>`
  166. .. rst-class:: classref-property-setget
  167. - |void| **set_pressed**\ (\ value\: :ref:`bool<class_bool>`\ )
  168. - :ref:`bool<class_bool>` **is_pressed**\ (\ )
  169. If ``true``, the button's state is pressed. Means the button is pressed down or toggled (if :ref:`toggle_mode<class_BaseButton_property_toggle_mode>` is active). Only works if :ref:`toggle_mode<class_BaseButton_property_toggle_mode>` is ``true``.
  170. \ **Note:** Changing the value of :ref:`button_pressed<class_BaseButton_property_button_pressed>` will result in :ref:`toggled<class_BaseButton_signal_toggled>` to be emitted. If you want to change the pressed state without emitting that signal, use :ref:`set_pressed_no_signal<class_BaseButton_method_set_pressed_no_signal>`.
  171. .. rst-class:: classref-item-separator
  172. ----
  173. .. _class_BaseButton_property_disabled:
  174. .. rst-class:: classref-property
  175. :ref:`bool<class_bool>` **disabled** = ``false`` :ref:`🔗<class_BaseButton_property_disabled>`
  176. .. rst-class:: classref-property-setget
  177. - |void| **set_disabled**\ (\ value\: :ref:`bool<class_bool>`\ )
  178. - :ref:`bool<class_bool>` **is_disabled**\ (\ )
  179. If ``true``, the button is in disabled state and can't be clicked or toggled.
  180. .. rst-class:: classref-item-separator
  181. ----
  182. .. _class_BaseButton_property_keep_pressed_outside:
  183. .. rst-class:: classref-property
  184. :ref:`bool<class_bool>` **keep_pressed_outside** = ``false`` :ref:`🔗<class_BaseButton_property_keep_pressed_outside>`
  185. .. rst-class:: classref-property-setget
  186. - |void| **set_keep_pressed_outside**\ (\ value\: :ref:`bool<class_bool>`\ )
  187. - :ref:`bool<class_bool>` **is_keep_pressed_outside**\ (\ )
  188. If ``true``, the button stays pressed when moving the cursor outside the button while pressing it.
  189. \ **Note:** This property only affects the button's visual appearance. Signals will be emitted at the same moment regardless of this property's value.
  190. .. rst-class:: classref-item-separator
  191. ----
  192. .. _class_BaseButton_property_shortcut:
  193. .. rst-class:: classref-property
  194. :ref:`Shortcut<class_Shortcut>` **shortcut** :ref:`🔗<class_BaseButton_property_shortcut>`
  195. .. rst-class:: classref-property-setget
  196. - |void| **set_shortcut**\ (\ value\: :ref:`Shortcut<class_Shortcut>`\ )
  197. - :ref:`Shortcut<class_Shortcut>` **get_shortcut**\ (\ )
  198. :ref:`Shortcut<class_Shortcut>` associated to the button.
  199. .. rst-class:: classref-item-separator
  200. ----
  201. .. _class_BaseButton_property_shortcut_feedback:
  202. .. rst-class:: classref-property
  203. :ref:`bool<class_bool>` **shortcut_feedback** = ``true`` :ref:`🔗<class_BaseButton_property_shortcut_feedback>`
  204. .. rst-class:: classref-property-setget
  205. - |void| **set_shortcut_feedback**\ (\ value\: :ref:`bool<class_bool>`\ )
  206. - :ref:`bool<class_bool>` **is_shortcut_feedback**\ (\ )
  207. If ``true``, the button will highlight for a short amount of time when its shortcut is activated. If ``false`` and :ref:`toggle_mode<class_BaseButton_property_toggle_mode>` is ``false``, the shortcut will activate without any visual feedback.
  208. .. rst-class:: classref-item-separator
  209. ----
  210. .. _class_BaseButton_property_shortcut_in_tooltip:
  211. .. rst-class:: classref-property
  212. :ref:`bool<class_bool>` **shortcut_in_tooltip** = ``true`` :ref:`🔗<class_BaseButton_property_shortcut_in_tooltip>`
  213. .. rst-class:: classref-property-setget
  214. - |void| **set_shortcut_in_tooltip**\ (\ value\: :ref:`bool<class_bool>`\ )
  215. - :ref:`bool<class_bool>` **is_shortcut_in_tooltip_enabled**\ (\ )
  216. If ``true``, the button will add information about its shortcut in the tooltip.
  217. \ **Note:** This property does nothing when the tooltip control is customized using :ref:`Control._make_custom_tooltip<class_Control_private_method__make_custom_tooltip>`.
  218. .. rst-class:: classref-item-separator
  219. ----
  220. .. _class_BaseButton_property_toggle_mode:
  221. .. rst-class:: classref-property
  222. :ref:`bool<class_bool>` **toggle_mode** = ``false`` :ref:`🔗<class_BaseButton_property_toggle_mode>`
  223. .. rst-class:: classref-property-setget
  224. - |void| **set_toggle_mode**\ (\ value\: :ref:`bool<class_bool>`\ )
  225. - :ref:`bool<class_bool>` **is_toggle_mode**\ (\ )
  226. If ``true``, the button is in toggle mode. Makes the button flip state between pressed and unpressed each time its area is clicked.
  227. .. rst-class:: classref-section-separator
  228. ----
  229. .. rst-class:: classref-descriptions-group
  230. Method Descriptions
  231. -------------------
  232. .. _class_BaseButton_private_method__pressed:
  233. .. rst-class:: classref-method
  234. |void| **_pressed**\ (\ ) |virtual| :ref:`🔗<class_BaseButton_private_method__pressed>`
  235. Called when the button is pressed. If you need to know the button's pressed state (and :ref:`toggle_mode<class_BaseButton_property_toggle_mode>` is active), use :ref:`_toggled<class_BaseButton_private_method__toggled>` instead.
  236. .. rst-class:: classref-item-separator
  237. ----
  238. .. _class_BaseButton_private_method__toggled:
  239. .. rst-class:: classref-method
  240. |void| **_toggled**\ (\ toggled_on\: :ref:`bool<class_bool>`\ ) |virtual| :ref:`🔗<class_BaseButton_private_method__toggled>`
  241. Called when the button is toggled (only if :ref:`toggle_mode<class_BaseButton_property_toggle_mode>` is active).
  242. .. rst-class:: classref-item-separator
  243. ----
  244. .. _class_BaseButton_method_get_draw_mode:
  245. .. rst-class:: classref-method
  246. :ref:`DrawMode<enum_BaseButton_DrawMode>` **get_draw_mode**\ (\ ) |const| :ref:`🔗<class_BaseButton_method_get_draw_mode>`
  247. Returns the visual state used to draw the button. This is useful mainly when implementing your own draw code by either overriding _draw() or connecting to "draw" signal. The visual state of the button is defined by the :ref:`DrawMode<enum_BaseButton_DrawMode>` enum.
  248. .. rst-class:: classref-item-separator
  249. ----
  250. .. _class_BaseButton_method_is_hovered:
  251. .. rst-class:: classref-method
  252. :ref:`bool<class_bool>` **is_hovered**\ (\ ) |const| :ref:`🔗<class_BaseButton_method_is_hovered>`
  253. Returns ``true`` if the mouse has entered the button and has not left it yet.
  254. .. rst-class:: classref-item-separator
  255. ----
  256. .. _class_BaseButton_method_set_pressed_no_signal:
  257. .. rst-class:: classref-method
  258. |void| **set_pressed_no_signal**\ (\ pressed\: :ref:`bool<class_bool>`\ ) :ref:`🔗<class_BaseButton_method_set_pressed_no_signal>`
  259. Changes the :ref:`button_pressed<class_BaseButton_property_button_pressed>` state of the button, without emitting :ref:`toggled<class_BaseButton_signal_toggled>`. Use when you just want to change the state of the button without sending the pressed event (e.g. when initializing scene). Only works if :ref:`toggle_mode<class_BaseButton_property_toggle_mode>` is ``true``.
  260. \ **Note:** This method doesn't unpress other buttons in :ref:`button_group<class_BaseButton_property_button_group>`.
  261. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  262. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  263. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  264. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  265. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  266. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  267. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
  268. .. |void| replace:: :abbr:`void (No return value.)`