class_menubutton.rst 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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/MenuButton.xml.
  6. .. _class_MenuButton:
  7. MenuButton
  8. ==========
  9. **Inherits:** :ref:`Button<class_Button>` **<** :ref:`BaseButton<class_BaseButton>` **<** :ref:`Control<class_Control>` **<** :ref:`CanvasItem<class_CanvasItem>` **<** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
  10. Special button that brings up a :ref:`PopupMenu<class_PopupMenu>` when clicked.
  11. Description
  12. -----------
  13. Special button that brings up a :ref:`PopupMenu<class_PopupMenu>` when clicked.
  14. New items can be created inside this :ref:`PopupMenu<class_PopupMenu>` using ``get_popup().add_item("My Item Name")``. You can also create them directly from the editor. To do so, select the ``MenuButton`` node, then in the toolbar at the top of the 2D editor, click **Items** then click **Add** in the popup. You will be able to give each item new properties.
  15. See also :ref:`BaseButton<class_BaseButton>` which contains common properties and methods associated with this node.
  16. Properties
  17. ----------
  18. +-----------------------------------------------+-------------------------------------------------------------------+-------------------------------------------------------------------------------+
  19. | :ref:`ActionMode<enum_BaseButton_ActionMode>` | action_mode | ``0`` (overrides :ref:`BaseButton<class_BaseButton_property_action_mode>`) |
  20. +-----------------------------------------------+-------------------------------------------------------------------+-------------------------------------------------------------------------------+
  21. | :ref:`bool<class_bool>` | flat | ``true`` (overrides :ref:`Button<class_Button_property_flat>`) |
  22. +-----------------------------------------------+-------------------------------------------------------------------+-------------------------------------------------------------------------------+
  23. | :ref:`FocusMode<enum_Control_FocusMode>` | focus_mode | ``0`` (overrides :ref:`Control<class_Control_property_focus_mode>`) |
  24. +-----------------------------------------------+-------------------------------------------------------------------+-------------------------------------------------------------------------------+
  25. | :ref:`int<class_int>` | :ref:`item_count<class_MenuButton_property_item_count>` | ``0`` |
  26. +-----------------------------------------------+-------------------------------------------------------------------+-------------------------------------------------------------------------------+
  27. | :ref:`bool<class_bool>` | :ref:`switch_on_hover<class_MenuButton_property_switch_on_hover>` | ``false`` |
  28. +-----------------------------------------------+-------------------------------------------------------------------+-------------------------------------------------------------------------------+
  29. | :ref:`bool<class_bool>` | toggle_mode | ``true`` (overrides :ref:`BaseButton<class_BaseButton_property_toggle_mode>`) |
  30. +-----------------------------------------------+-------------------------------------------------------------------+-------------------------------------------------------------------------------+
  31. Methods
  32. -------
  33. +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------+
  34. | :ref:`PopupMenu<class_PopupMenu>` | :ref:`get_popup<class_MenuButton_method_get_popup>` **(** **)** |const| |
  35. +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------+
  36. | void | :ref:`set_disable_shortcuts<class_MenuButton_method_set_disable_shortcuts>` **(** :ref:`bool<class_bool>` disabled **)** |
  37. +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------+
  38. Theme Properties
  39. ----------------
  40. +---------------------------------+------------------------------------------------------------------------------+-----------------------------------+
  41. | :ref:`Color<class_Color>` | :ref:`font_color<class_MenuButton_theme_color_font_color>` | ``Color(0.875, 0.875, 0.875, 1)`` |
  42. +---------------------------------+------------------------------------------------------------------------------+-----------------------------------+
  43. | :ref:`Color<class_Color>` | :ref:`font_disabled_color<class_MenuButton_theme_color_font_disabled_color>` | ``Color(1, 1, 1, 0.3)`` |
  44. +---------------------------------+------------------------------------------------------------------------------+-----------------------------------+
  45. | :ref:`Color<class_Color>` | :ref:`font_focus_color<class_MenuButton_theme_color_font_focus_color>` | ``Color(0.95, 0.95, 0.95, 1)`` |
  46. +---------------------------------+------------------------------------------------------------------------------+-----------------------------------+
  47. | :ref:`Color<class_Color>` | :ref:`font_hover_color<class_MenuButton_theme_color_font_hover_color>` | ``Color(0.95, 0.95, 0.95, 1)`` |
  48. +---------------------------------+------------------------------------------------------------------------------+-----------------------------------+
  49. | :ref:`Color<class_Color>` | :ref:`font_outline_color<class_MenuButton_theme_color_font_outline_color>` | ``Color(1, 1, 1, 1)`` |
  50. +---------------------------------+------------------------------------------------------------------------------+-----------------------------------+
  51. | :ref:`Color<class_Color>` | :ref:`font_pressed_color<class_MenuButton_theme_color_font_pressed_color>` | ``Color(1, 1, 1, 1)`` |
  52. +---------------------------------+------------------------------------------------------------------------------+-----------------------------------+
  53. | :ref:`int<class_int>` | :ref:`h_separation<class_MenuButton_theme_constant_h_separation>` | ``3`` |
  54. +---------------------------------+------------------------------------------------------------------------------+-----------------------------------+
  55. | :ref:`int<class_int>` | :ref:`outline_size<class_MenuButton_theme_constant_outline_size>` | ``0`` |
  56. +---------------------------------+------------------------------------------------------------------------------+-----------------------------------+
  57. | :ref:`Font<class_Font>` | :ref:`font<class_MenuButton_theme_font_font>` | |
  58. +---------------------------------+------------------------------------------------------------------------------+-----------------------------------+
  59. | :ref:`int<class_int>` | :ref:`font_size<class_MenuButton_theme_font_size_font_size>` | |
  60. +---------------------------------+------------------------------------------------------------------------------+-----------------------------------+
  61. | :ref:`StyleBox<class_StyleBox>` | :ref:`disabled<class_MenuButton_theme_style_disabled>` | |
  62. +---------------------------------+------------------------------------------------------------------------------+-----------------------------------+
  63. | :ref:`StyleBox<class_StyleBox>` | :ref:`focus<class_MenuButton_theme_style_focus>` | |
  64. +---------------------------------+------------------------------------------------------------------------------+-----------------------------------+
  65. | :ref:`StyleBox<class_StyleBox>` | :ref:`hover<class_MenuButton_theme_style_hover>` | |
  66. +---------------------------------+------------------------------------------------------------------------------+-----------------------------------+
  67. | :ref:`StyleBox<class_StyleBox>` | :ref:`normal<class_MenuButton_theme_style_normal>` | |
  68. +---------------------------------+------------------------------------------------------------------------------+-----------------------------------+
  69. | :ref:`StyleBox<class_StyleBox>` | :ref:`pressed<class_MenuButton_theme_style_pressed>` | |
  70. +---------------------------------+------------------------------------------------------------------------------+-----------------------------------+
  71. Signals
  72. -------
  73. .. _class_MenuButton_signal_about_to_popup:
  74. - **about_to_popup** **(** **)**
  75. Emitted when the :ref:`PopupMenu<class_PopupMenu>` of this MenuButton is about to show.
  76. Property Descriptions
  77. ---------------------
  78. .. _class_MenuButton_property_item_count:
  79. - :ref:`int<class_int>` **item_count**
  80. +-----------+-----------------------+
  81. | *Default* | ``0`` |
  82. +-----------+-----------------------+
  83. | *Setter* | set_item_count(value) |
  84. +-----------+-----------------------+
  85. | *Getter* | get_item_count() |
  86. +-----------+-----------------------+
  87. The number of items currently in the list.
  88. ----
  89. .. _class_MenuButton_property_switch_on_hover:
  90. - :ref:`bool<class_bool>` **switch_on_hover**
  91. +-----------+----------------------------+
  92. | *Default* | ``false`` |
  93. +-----------+----------------------------+
  94. | *Setter* | set_switch_on_hover(value) |
  95. +-----------+----------------------------+
  96. | *Getter* | is_switch_on_hover() |
  97. +-----------+----------------------------+
  98. If ``true``, when the cursor hovers above another ``MenuButton`` within the same parent which also has ``switch_on_hover`` enabled, it will close the current ``MenuButton`` and open the other one.
  99. Method Descriptions
  100. -------------------
  101. .. _class_MenuButton_method_get_popup:
  102. - :ref:`PopupMenu<class_PopupMenu>` **get_popup** **(** **)** |const|
  103. Returns the :ref:`PopupMenu<class_PopupMenu>` contained in this button.
  104. \ **Warning:** This is a required internal node, removing and freeing it may cause a crash. If you wish to hide it or any of its children, use their :ref:`Window.visible<class_Window_property_visible>` property.
  105. ----
  106. .. _class_MenuButton_method_set_disable_shortcuts:
  107. - void **set_disable_shortcuts** **(** :ref:`bool<class_bool>` disabled **)**
  108. If ``true``, shortcuts are disabled and cannot be used to trigger the button.
  109. Theme Property Descriptions
  110. ---------------------------
  111. .. _class_MenuButton_theme_color_font_color:
  112. - :ref:`Color<class_Color>` **font_color**
  113. +-----------+-----------------------------------+
  114. | *Default* | ``Color(0.875, 0.875, 0.875, 1)`` |
  115. +-----------+-----------------------------------+
  116. Default text :ref:`Color<class_Color>` of the ``MenuButton``.
  117. ----
  118. .. _class_MenuButton_theme_color_font_disabled_color:
  119. - :ref:`Color<class_Color>` **font_disabled_color**
  120. +-----------+-------------------------+
  121. | *Default* | ``Color(1, 1, 1, 0.3)`` |
  122. +-----------+-------------------------+
  123. Text :ref:`Color<class_Color>` used when the ``MenuButton`` is disabled.
  124. ----
  125. .. _class_MenuButton_theme_color_font_focus_color:
  126. - :ref:`Color<class_Color>` **font_focus_color**
  127. +-----------+--------------------------------+
  128. | *Default* | ``Color(0.95, 0.95, 0.95, 1)`` |
  129. +-----------+--------------------------------+
  130. Text :ref:`Color<class_Color>` used when the ``MenuButton`` is focused. Only replaces the normal text color of the button. Disabled, hovered, and pressed states take precedence over this color.
  131. ----
  132. .. _class_MenuButton_theme_color_font_hover_color:
  133. - :ref:`Color<class_Color>` **font_hover_color**
  134. +-----------+--------------------------------+
  135. | *Default* | ``Color(0.95, 0.95, 0.95, 1)`` |
  136. +-----------+--------------------------------+
  137. Text :ref:`Color<class_Color>` used when the ``MenuButton`` is being hovered.
  138. ----
  139. .. _class_MenuButton_theme_color_font_outline_color:
  140. - :ref:`Color<class_Color>` **font_outline_color**
  141. +-----------+-----------------------+
  142. | *Default* | ``Color(1, 1, 1, 1)`` |
  143. +-----------+-----------------------+
  144. The tint of text outline of the ``MenuButton``.
  145. ----
  146. .. _class_MenuButton_theme_color_font_pressed_color:
  147. - :ref:`Color<class_Color>` **font_pressed_color**
  148. +-----------+-----------------------+
  149. | *Default* | ``Color(1, 1, 1, 1)`` |
  150. +-----------+-----------------------+
  151. Text :ref:`Color<class_Color>` used when the ``MenuButton`` is being pressed.
  152. ----
  153. .. _class_MenuButton_theme_constant_h_separation:
  154. - :ref:`int<class_int>` **h_separation**
  155. +-----------+-------+
  156. | *Default* | ``3`` |
  157. +-----------+-------+
  158. The horizontal space between ``MenuButton``'s icon and text.
  159. ----
  160. .. _class_MenuButton_theme_constant_outline_size:
  161. - :ref:`int<class_int>` **outline_size**
  162. +-----------+-------+
  163. | *Default* | ``0`` |
  164. +-----------+-------+
  165. The size of the text outline.
  166. ----
  167. .. _class_MenuButton_theme_font_font:
  168. - :ref:`Font<class_Font>` **font**
  169. :ref:`Font<class_Font>` of the ``MenuButton``'s text.
  170. ----
  171. .. _class_MenuButton_theme_font_size_font_size:
  172. - :ref:`int<class_int>` **font_size**
  173. Font size of the ``MenuButton``'s text.
  174. ----
  175. .. _class_MenuButton_theme_style_disabled:
  176. - :ref:`StyleBox<class_StyleBox>` **disabled**
  177. :ref:`StyleBox<class_StyleBox>` used when the ``MenuButton`` is disabled.
  178. ----
  179. .. _class_MenuButton_theme_style_focus:
  180. - :ref:`StyleBox<class_StyleBox>` **focus**
  181. :ref:`StyleBox<class_StyleBox>` used when the ``MenuButton`` is focused. The ``focus`` :ref:`StyleBox<class_StyleBox>` is displayed *over* the base :ref:`StyleBox<class_StyleBox>`, so a partially transparent :ref:`StyleBox<class_StyleBox>` should be used to ensure the base :ref:`StyleBox<class_StyleBox>` remains visible. A :ref:`StyleBox<class_StyleBox>` that represents an outline or an underline works well for this purpose. To disable the focus visual effect, assign a :ref:`StyleBoxEmpty<class_StyleBoxEmpty>` resource. Note that disabling the focus visual effect will harm keyboard/controller navigation usability, so this is not recommended for accessibility reasons.
  182. ----
  183. .. _class_MenuButton_theme_style_hover:
  184. - :ref:`StyleBox<class_StyleBox>` **hover**
  185. :ref:`StyleBox<class_StyleBox>` used when the ``MenuButton`` is being hovered.
  186. ----
  187. .. _class_MenuButton_theme_style_normal:
  188. - :ref:`StyleBox<class_StyleBox>` **normal**
  189. Default :ref:`StyleBox<class_StyleBox>` for the ``MenuButton``.
  190. ----
  191. .. _class_MenuButton_theme_style_pressed:
  192. - :ref:`StyleBox<class_StyleBox>` **pressed**
  193. :ref:`StyleBox<class_StyleBox>` used when the ``MenuButton`` is being pressed.
  194. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  195. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  196. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  197. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  198. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  199. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`