class_basebutton.rst 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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 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. **Category:** Core
  11. Brief Description
  12. -----------------
  13. Base class for different kinds of buttons.
  14. Properties
  15. ----------
  16. +-----------------------------------------------+-----------------------------------------------------------------------------+----------+
  17. | :ref:`ActionMode<enum_BaseButton_ActionMode>` | :ref:`action_mode<class_BaseButton_property_action_mode>` | 1 |
  18. +-----------------------------------------------+-----------------------------------------------------------------------------+----------+
  19. | :ref:`int<class_int>` | :ref:`button_mask<class_BaseButton_property_button_mask>` | 1 |
  20. +-----------------------------------------------+-----------------------------------------------------------------------------+----------+
  21. | :ref:`bool<class_bool>` | :ref:`disabled<class_BaseButton_property_disabled>` | false |
  22. +-----------------------------------------------+-----------------------------------------------------------------------------+----------+
  23. | :ref:`FocusMode<enum_Control_FocusMode>` | :ref:`enabled_focus_mode<class_BaseButton_property_enabled_focus_mode>` | 2 |
  24. +-----------------------------------------------+-----------------------------------------------------------------------------+----------+
  25. | :ref:`FocusMode<enum_Control_FocusMode>` | focus_mode | **O:** 2 |
  26. +-----------------------------------------------+-----------------------------------------------------------------------------+----------+
  27. | :ref:`ButtonGroup<class_ButtonGroup>` | :ref:`group<class_BaseButton_property_group>` | |
  28. +-----------------------------------------------+-----------------------------------------------------------------------------+----------+
  29. | :ref:`bool<class_bool>` | :ref:`keep_pressed_outside<class_BaseButton_property_keep_pressed_outside>` | false |
  30. +-----------------------------------------------+-----------------------------------------------------------------------------+----------+
  31. | :ref:`bool<class_bool>` | :ref:`pressed<class_BaseButton_property_pressed>` | false |
  32. +-----------------------------------------------+-----------------------------------------------------------------------------+----------+
  33. | :ref:`ShortCut<class_ShortCut>` | :ref:`shortcut<class_BaseButton_property_shortcut>` | |
  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. Signals
  51. -------
  52. .. _class_BaseButton_signal_button_down:
  53. - **button_down** **(** **)**
  54. Emitted when the button starts being held down.
  55. .. _class_BaseButton_signal_button_up:
  56. - **button_up** **(** **)**
  57. Emitted when the button stops being held down.
  58. .. _class_BaseButton_signal_pressed:
  59. - **pressed** **(** **)**
  60. 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.
  61. .. _class_BaseButton_signal_toggled:
  62. - **toggled** **(** :ref:`bool<class_bool>` button_pressed **)**
  63. 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.
  64. Enumerations
  65. ------------
  66. .. _enum_BaseButton_DrawMode:
  67. .. _class_BaseButton_constant_DRAW_NORMAL:
  68. .. _class_BaseButton_constant_DRAW_PRESSED:
  69. .. _class_BaseButton_constant_DRAW_HOVER:
  70. .. _class_BaseButton_constant_DRAW_DISABLED:
  71. .. _class_BaseButton_constant_DRAW_HOVER_PRESSED:
  72. enum **DrawMode**:
  73. - **DRAW_NORMAL** = **0** --- The normal state (i.e. not pressed, not hovered, not toggled and enabled) of buttons.
  74. - **DRAW_PRESSED** = **1** --- The state of buttons are pressed.
  75. - **DRAW_HOVER** = **2** --- The state of buttons are hovered.
  76. - **DRAW_DISABLED** = **3** --- The state of buttons are disabled.
  77. - **DRAW_HOVER_PRESSED** = **4**
  78. .. _enum_BaseButton_ActionMode:
  79. .. _class_BaseButton_constant_ACTION_MODE_BUTTON_PRESS:
  80. .. _class_BaseButton_constant_ACTION_MODE_BUTTON_RELEASE:
  81. enum **ActionMode**:
  82. - **ACTION_MODE_BUTTON_PRESS** = **0** --- Require just a press to consider the button clicked.
  83. - **ACTION_MODE_BUTTON_RELEASE** = **1** --- Require a press and a subsequent release before considering the button clicked.
  84. Description
  85. -----------
  86. 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.
  87. Property Descriptions
  88. ---------------------
  89. .. _class_BaseButton_property_action_mode:
  90. - :ref:`ActionMode<enum_BaseButton_ActionMode>` **action_mode**
  91. +-----------+------------------------+
  92. | *Default* | 1 |
  93. +-----------+------------------------+
  94. | *Setter* | set_action_mode(value) |
  95. +-----------+------------------------+
  96. | *Getter* | get_action_mode() |
  97. +-----------+------------------------+
  98. Determines when the button is considered clicked, one of the ``ACTION_MODE_*`` constants.
  99. .. _class_BaseButton_property_button_mask:
  100. - :ref:`int<class_int>` **button_mask**
  101. +-----------+------------------------+
  102. | *Default* | 1 |
  103. +-----------+------------------------+
  104. | *Setter* | set_button_mask(value) |
  105. +-----------+------------------------+
  106. | *Getter* | get_button_mask() |
  107. +-----------+------------------------+
  108. Binary mask to choose which mouse buttons this button will respond to.
  109. To allow both left-click and right-click, use ``BUTTON_MASK_LEFT | BUTTON_MASK_RIGHT``.
  110. .. _class_BaseButton_property_disabled:
  111. - :ref:`bool<class_bool>` **disabled**
  112. +-----------+---------------------+
  113. | *Default* | false |
  114. +-----------+---------------------+
  115. | *Setter* | set_disabled(value) |
  116. +-----------+---------------------+
  117. | *Getter* | is_disabled() |
  118. +-----------+---------------------+
  119. If ``true``, the button is in disabled state and can't be clicked or toggled.
  120. .. _class_BaseButton_property_enabled_focus_mode:
  121. - :ref:`FocusMode<enum_Control_FocusMode>` **enabled_focus_mode**
  122. +-----------+-------------------------------+
  123. | *Default* | 2 |
  124. +-----------+-------------------------------+
  125. | *Setter* | set_enabled_focus_mode(value) |
  126. +-----------+-------------------------------+
  127. | *Getter* | get_enabled_focus_mode() |
  128. +-----------+-------------------------------+
  129. Focus access mode to use when switching between enabled/disabled (see :ref:`Control.focus_mode<class_Control_property_focus_mode>` and :ref:`disabled<class_BaseButton_property_disabled>`).
  130. .. _class_BaseButton_property_group:
  131. - :ref:`ButtonGroup<class_ButtonGroup>` **group**
  132. +----------+-------------------------+
  133. | *Setter* | set_button_group(value) |
  134. +----------+-------------------------+
  135. | *Getter* | get_button_group() |
  136. +----------+-------------------------+
  137. :ref:`ButtonGroup<class_ButtonGroup>` associated to the button.
  138. .. _class_BaseButton_property_keep_pressed_outside:
  139. - :ref:`bool<class_bool>` **keep_pressed_outside**
  140. +-----------+---------------------------------+
  141. | *Default* | false |
  142. +-----------+---------------------------------+
  143. | *Setter* | set_keep_pressed_outside(value) |
  144. +-----------+---------------------------------+
  145. | *Getter* | is_keep_pressed_outside() |
  146. +-----------+---------------------------------+
  147. If ``true``, the button stays pressed when moving the cursor outside the button while pressing it.
  148. .. _class_BaseButton_property_pressed:
  149. - :ref:`bool<class_bool>` **pressed**
  150. +-----------+--------------------+
  151. | *Default* | false |
  152. +-----------+--------------------+
  153. | *Setter* | set_pressed(value) |
  154. +-----------+--------------------+
  155. | *Getter* | is_pressed() |
  156. +-----------+--------------------+
  157. If ``true``, the button's state is pressed. Means the button is pressed down or toggled (if toggle_mode is active).
  158. .. _class_BaseButton_property_shortcut:
  159. - :ref:`ShortCut<class_ShortCut>` **shortcut**
  160. +----------+---------------------+
  161. | *Setter* | set_shortcut(value) |
  162. +----------+---------------------+
  163. | *Getter* | get_shortcut() |
  164. +----------+---------------------+
  165. :ref:`ShortCut<class_ShortCut>` associated to the button.
  166. .. _class_BaseButton_property_shortcut_in_tooltip:
  167. - :ref:`bool<class_bool>` **shortcut_in_tooltip**
  168. +-----------+----------------------------------+
  169. | *Default* | true |
  170. +-----------+----------------------------------+
  171. | *Setter* | set_shortcut_in_tooltip(value) |
  172. +-----------+----------------------------------+
  173. | *Getter* | is_shortcut_in_tooltip_enabled() |
  174. +-----------+----------------------------------+
  175. If ``true``, the button will add information about its shortcut in the tooltip.
  176. .. _class_BaseButton_property_toggle_mode:
  177. - :ref:`bool<class_bool>` **toggle_mode**
  178. +-----------+------------------------+
  179. | *Default* | false |
  180. +-----------+------------------------+
  181. | *Setter* | set_toggle_mode(value) |
  182. +-----------+------------------------+
  183. | *Getter* | is_toggle_mode() |
  184. +-----------+------------------------+
  185. If ``true``, the button is in toggle mode. Makes the button flip state between pressed and unpressed each time its area is clicked.
  186. Method Descriptions
  187. -------------------
  188. .. _class_BaseButton_method__pressed:
  189. - void **_pressed** **(** **)** virtual
  190. Called when the button is pressed.
  191. .. _class_BaseButton_method__toggled:
  192. - void **_toggled** **(** :ref:`bool<class_bool>` button_pressed **)** virtual
  193. Called when the button is toggled (only if toggle_mode is active).
  194. .. _class_BaseButton_method_get_draw_mode:
  195. - :ref:`DrawMode<enum_BaseButton_DrawMode>` **get_draw_mode** **(** **)** const
  196. 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 ``DRAW_*`` enum.
  197. .. _class_BaseButton_method_is_hovered:
  198. - :ref:`bool<class_bool>` **is_hovered** **(** **)** const
  199. Returns ``true`` if the mouse has entered the button and has not left it yet.