class_basebutton.rst 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/make_rst.py in Godot's source tree.
  3. .. DO NOT EDIT THIS FILE, but the BaseButton.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_BaseButton:
  6. BaseButton
  7. ==========
  8. **Inherits:** :ref:`Control<class_Control>` **<** :ref:`CanvasItem<class_CanvasItem>` **<** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
  9. **Inherited By:** :ref:`Button<class_Button>`, :ref:`LinkButton<class_LinkButton>`, :ref:`TextureButton<class_TextureButton>`
  10. Base class for different kinds of buttons.
  11. Description
  12. -----------
  13. BaseButton is the abstract base class for buttons, so it shouldn't be used directly (it doesn't display anything). Other types of buttons inherit from it.
  14. Properties
  15. ----------
  16. +---------------------------------------------------+-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  17. | :ref:`ActionMode<enum_BaseButton_ActionMode>` | :ref:`action_mode<class_BaseButton_property_action_mode>` | ``1`` |
  18. +---------------------------------------------------+-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  19. | :ref:`ButtonGroup<class_ButtonGroup>` | :ref:`button_group<class_BaseButton_property_button_group>` | |
  20. +---------------------------------------------------+-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  21. | :ref:`MouseButton<enum_@GlobalScope_MouseButton>` | :ref:`button_mask<class_BaseButton_property_button_mask>` | ``1`` |
  22. +---------------------------------------------------+-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  23. | :ref:`bool<class_bool>` | :ref:`button_pressed<class_BaseButton_property_button_pressed>` | ``false`` |
  24. +---------------------------------------------------+-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  25. | :ref:`bool<class_bool>` | :ref:`disabled<class_BaseButton_property_disabled>` | ``false`` |
  26. +---------------------------------------------------+-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  27. | :ref:`FocusMode<enum_Control_FocusMode>` | focus_mode | ``2`` (overrides :ref:`Control<class_Control_property_focus_mode>`) |
  28. +---------------------------------------------------+-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  29. | :ref:`bool<class_bool>` | :ref:`keep_pressed_outside<class_BaseButton_property_keep_pressed_outside>` | ``false`` |
  30. +---------------------------------------------------+-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  31. | :ref:`Shortcut<class_Shortcut>` | :ref:`shortcut<class_BaseButton_property_shortcut>` | |
  32. +---------------------------------------------------+-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  33. | :ref:`Node<class_Node>` | :ref:`shortcut_context<class_BaseButton_property_shortcut_context>` | |
  34. +---------------------------------------------------+-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  35. | :ref:`bool<class_bool>` | :ref:`shortcut_in_tooltip<class_BaseButton_property_shortcut_in_tooltip>` | ``true`` |
  36. +---------------------------------------------------+-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  37. | :ref:`bool<class_bool>` | :ref:`toggle_mode<class_BaseButton_property_toggle_mode>` | ``false`` |
  38. +---------------------------------------------------+-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  39. Methods
  40. -------
  41. +-------------------------------------------+-------------------------------------------------------------------------------------------------------------------------+
  42. | void | :ref:`_pressed<class_BaseButton_method__pressed>` **(** **)** |virtual| |
  43. +-------------------------------------------+-------------------------------------------------------------------------------------------------------------------------+
  44. | void | :ref:`_toggled<class_BaseButton_method__toggled>` **(** :ref:`bool<class_bool>` button_pressed **)** |virtual| |
  45. +-------------------------------------------+-------------------------------------------------------------------------------------------------------------------------+
  46. | :ref:`DrawMode<enum_BaseButton_DrawMode>` | :ref:`get_draw_mode<class_BaseButton_method_get_draw_mode>` **(** **)** |const| |
  47. +-------------------------------------------+-------------------------------------------------------------------------------------------------------------------------+
  48. | :ref:`bool<class_bool>` | :ref:`is_hovered<class_BaseButton_method_is_hovered>` **(** **)** |const| |
  49. +-------------------------------------------+-------------------------------------------------------------------------------------------------------------------------+
  50. | void | :ref:`set_pressed_no_signal<class_BaseButton_method_set_pressed_no_signal>` **(** :ref:`bool<class_bool>` pressed **)** |
  51. +-------------------------------------------+-------------------------------------------------------------------------------------------------------------------------+
  52. Signals
  53. -------
  54. .. _class_BaseButton_signal_button_down:
  55. - **button_down** **(** **)**
  56. Emitted when the button starts being held down.
  57. ----
  58. .. _class_BaseButton_signal_button_up:
  59. - **button_up** **(** **)**
  60. Emitted when the button stops being held down.
  61. ----
  62. .. _class_BaseButton_signal_pressed:
  63. - **pressed** **(** **)**
  64. 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.
  65. 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.
  66. ----
  67. .. _class_BaseButton_signal_toggled:
  68. - **toggled** **(** :ref:`bool<class_bool>` button_pressed **)**
  69. 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 ``button_pressed`` argument.
  70. Enumerations
  71. ------------
  72. .. _enum_BaseButton_DrawMode:
  73. .. _class_BaseButton_constant_DRAW_NORMAL:
  74. .. _class_BaseButton_constant_DRAW_PRESSED:
  75. .. _class_BaseButton_constant_DRAW_HOVER:
  76. .. _class_BaseButton_constant_DRAW_DISABLED:
  77. .. _class_BaseButton_constant_DRAW_HOVER_PRESSED:
  78. enum **DrawMode**:
  79. - **DRAW_NORMAL** = **0** --- The normal state (i.e. not pressed, not hovered, not toggled and enabled) of buttons.
  80. - **DRAW_PRESSED** = **1** --- The state of buttons are pressed.
  81. - **DRAW_HOVER** = **2** --- The state of buttons are hovered.
  82. - **DRAW_DISABLED** = **3** --- The state of buttons are disabled.
  83. - **DRAW_HOVER_PRESSED** = **4** --- The state of buttons are both hovered and pressed.
  84. ----
  85. .. _enum_BaseButton_ActionMode:
  86. .. _class_BaseButton_constant_ACTION_MODE_BUTTON_PRESS:
  87. .. _class_BaseButton_constant_ACTION_MODE_BUTTON_RELEASE:
  88. enum **ActionMode**:
  89. - **ACTION_MODE_BUTTON_PRESS** = **0** --- Require just a press to consider the button clicked.
  90. - **ACTION_MODE_BUTTON_RELEASE** = **1** --- Require a press and a subsequent release before considering the button clicked.
  91. Property Descriptions
  92. ---------------------
  93. .. _class_BaseButton_property_action_mode:
  94. - :ref:`ActionMode<enum_BaseButton_ActionMode>` **action_mode**
  95. +-----------+------------------------+
  96. | *Default* | ``1`` |
  97. +-----------+------------------------+
  98. | *Setter* | set_action_mode(value) |
  99. +-----------+------------------------+
  100. | *Getter* | get_action_mode() |
  101. +-----------+------------------------+
  102. Determines when the button is considered clicked, one of the :ref:`ActionMode<enum_BaseButton_ActionMode>` constants.
  103. ----
  104. .. _class_BaseButton_property_button_group:
  105. - :ref:`ButtonGroup<class_ButtonGroup>` **button_group**
  106. +----------+-------------------------+
  107. | *Setter* | set_button_group(value) |
  108. +----------+-------------------------+
  109. | *Getter* | get_button_group() |
  110. +----------+-------------------------+
  111. The :ref:`ButtonGroup<class_ButtonGroup>` associated with the button. Not to be confused with node groups.
  112. ----
  113. .. _class_BaseButton_property_button_mask:
  114. - :ref:`MouseButton<enum_@GlobalScope_MouseButton>` **button_mask**
  115. +-----------+------------------------+
  116. | *Default* | ``1`` |
  117. +-----------+------------------------+
  118. | *Setter* | set_button_mask(value) |
  119. +-----------+------------------------+
  120. | *Getter* | get_button_mask() |
  121. +-----------+------------------------+
  122. Binary mask to choose which mouse buttons this button will respond to.
  123. To allow both left-click and right-click, use ``MOUSE_BUTTON_MASK_LEFT | MOUSE_BUTTON_MASK_RIGHT``.
  124. ----
  125. .. _class_BaseButton_property_button_pressed:
  126. - :ref:`bool<class_bool>` **button_pressed**
  127. +-----------+--------------------+
  128. | *Default* | ``false`` |
  129. +-----------+--------------------+
  130. | *Setter* | set_pressed(value) |
  131. +-----------+--------------------+
  132. | *Getter* | is_pressed() |
  133. +-----------+--------------------+
  134. 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``.
  135. \ **Note:** Setting :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>`.
  136. ----
  137. .. _class_BaseButton_property_disabled:
  138. - :ref:`bool<class_bool>` **disabled**
  139. +-----------+---------------------+
  140. | *Default* | ``false`` |
  141. +-----------+---------------------+
  142. | *Setter* | set_disabled(value) |
  143. +-----------+---------------------+
  144. | *Getter* | is_disabled() |
  145. +-----------+---------------------+
  146. If ``true``, the button is in disabled state and can't be clicked or toggled.
  147. ----
  148. .. _class_BaseButton_property_keep_pressed_outside:
  149. - :ref:`bool<class_bool>` **keep_pressed_outside**
  150. +-----------+---------------------------------+
  151. | *Default* | ``false`` |
  152. +-----------+---------------------------------+
  153. | *Setter* | set_keep_pressed_outside(value) |
  154. +-----------+---------------------------------+
  155. | *Getter* | is_keep_pressed_outside() |
  156. +-----------+---------------------------------+
  157. If ``true``, the button stays pressed when moving the cursor outside the button while pressing it.
  158. \ **Note:** This property only affects the button's visual appearance. Signals will be emitted at the same moment regardless of this property's value.
  159. ----
  160. .. _class_BaseButton_property_shortcut:
  161. - :ref:`Shortcut<class_Shortcut>` **shortcut**
  162. +----------+---------------------+
  163. | *Setter* | set_shortcut(value) |
  164. +----------+---------------------+
  165. | *Getter* | get_shortcut() |
  166. +----------+---------------------+
  167. :ref:`Shortcut<class_Shortcut>` associated to the button.
  168. ----
  169. .. _class_BaseButton_property_shortcut_context:
  170. - :ref:`Node<class_Node>` **shortcut_context**
  171. +----------+-----------------------------+
  172. | *Setter* | set_shortcut_context(value) |
  173. +----------+-----------------------------+
  174. | *Getter* | get_shortcut_context() |
  175. +----------+-----------------------------+
  176. The :ref:`Node<class_Node>` which must be a parent of the focused GUI :ref:`Control<class_Control>` for the shortcut to be activated. If ``null``, the shortcut can be activated when any control is focused (a global shortcut). This allows shortcuts to be accepted only when the user has a certain area of the GUI focused.
  177. ----
  178. .. _class_BaseButton_property_shortcut_in_tooltip:
  179. - :ref:`bool<class_bool>` **shortcut_in_tooltip**
  180. +-----------+----------------------------------+
  181. | *Default* | ``true`` |
  182. +-----------+----------------------------------+
  183. | *Setter* | set_shortcut_in_tooltip(value) |
  184. +-----------+----------------------------------+
  185. | *Getter* | is_shortcut_in_tooltip_enabled() |
  186. +-----------+----------------------------------+
  187. If ``true``, the button will add information about its shortcut in the tooltip.
  188. ----
  189. .. _class_BaseButton_property_toggle_mode:
  190. - :ref:`bool<class_bool>` **toggle_mode**
  191. +-----------+------------------------+
  192. | *Default* | ``false`` |
  193. +-----------+------------------------+
  194. | *Setter* | set_toggle_mode(value) |
  195. +-----------+------------------------+
  196. | *Getter* | is_toggle_mode() |
  197. +-----------+------------------------+
  198. If ``true``, the button is in toggle mode. Makes the button flip state between pressed and unpressed each time its area is clicked.
  199. Method Descriptions
  200. -------------------
  201. .. _class_BaseButton_method__pressed:
  202. - void **_pressed** **(** **)** |virtual|
  203. 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_method__toggled>` instead.
  204. ----
  205. .. _class_BaseButton_method__toggled:
  206. - void **_toggled** **(** :ref:`bool<class_bool>` button_pressed **)** |virtual|
  207. Called when the button is toggled (only if :ref:`toggle_mode<class_BaseButton_property_toggle_mode>` is active).
  208. ----
  209. .. _class_BaseButton_method_get_draw_mode:
  210. - :ref:`DrawMode<enum_BaseButton_DrawMode>` **get_draw_mode** **(** **)** |const|
  211. 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.
  212. ----
  213. .. _class_BaseButton_method_is_hovered:
  214. - :ref:`bool<class_bool>` **is_hovered** **(** **)** |const|
  215. Returns ``true`` if the mouse has entered the button and has not left it yet.
  216. ----
  217. .. _class_BaseButton_method_set_pressed_no_signal:
  218. - void **set_pressed_no_signal** **(** :ref:`bool<class_bool>` pressed **)**
  219. 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``.
  220. \ **Note:** This method doesn't unpress other buttons in :ref:`button_group<class_BaseButton_property_button_group>`.
  221. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  222. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  223. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  224. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  225. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  226. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`