class_menubutton.rst 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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 MenuButton.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_MenuButton:
  6. MenuButton
  7. ==========
  8. **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>`
  9. Special button that brings up a :ref:`PopupMenu<class_PopupMenu>` when clicked.
  10. Description
  11. -----------
  12. Special button that brings up a :ref:`PopupMenu<class_PopupMenu>` when clicked.
  13. 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.
  14. See also :ref:`BaseButton<class_BaseButton>` which contains common properties and methods associated with this node.
  15. Properties
  16. ----------
  17. +-----------------------------------------------+-------------------------------------------------------------------+-------------------------------------------------------------------------------+
  18. | :ref:`ActionMode<enum_BaseButton_ActionMode>` | action_mode | ``0`` (overrides :ref:`BaseButton<class_BaseButton_property_action_mode>`) |
  19. +-----------------------------------------------+-------------------------------------------------------------------+-------------------------------------------------------------------------------+
  20. | :ref:`bool<class_bool>` | flat | ``true`` (overrides :ref:`Button<class_Button_property_flat>`) |
  21. +-----------------------------------------------+-------------------------------------------------------------------+-------------------------------------------------------------------------------+
  22. | :ref:`FocusMode<enum_Control_FocusMode>` | focus_mode | ``0`` (overrides :ref:`Control<class_Control_property_focus_mode>`) |
  23. +-----------------------------------------------+-------------------------------------------------------------------+-------------------------------------------------------------------------------+
  24. | :ref:`int<class_int>` | :ref:`item_count<class_MenuButton_property_item_count>` | ``0`` |
  25. +-----------------------------------------------+-------------------------------------------------------------------+-------------------------------------------------------------------------------+
  26. | :ref:`bool<class_bool>` | :ref:`switch_on_hover<class_MenuButton_property_switch_on_hover>` | ``false`` |
  27. +-----------------------------------------------+-------------------------------------------------------------------+-------------------------------------------------------------------------------+
  28. | :ref:`bool<class_bool>` | toggle_mode | ``true`` (overrides :ref:`BaseButton<class_BaseButton_property_toggle_mode>`) |
  29. +-----------------------------------------------+-------------------------------------------------------------------+-------------------------------------------------------------------------------+
  30. Methods
  31. -------
  32. +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------+
  33. | :ref:`PopupMenu<class_PopupMenu>` | :ref:`get_popup<class_MenuButton_method_get_popup>` **(** **)** |const| |
  34. +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------+
  35. | void | :ref:`set_disable_shortcuts<class_MenuButton_method_set_disable_shortcuts>` **(** :ref:`bool<class_bool>` disabled **)** |
  36. +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------+
  37. Theme Properties
  38. ----------------
  39. +---------------------------------+------------------------------------------------------------------------------+-----------------------------------+
  40. | :ref:`Color<class_Color>` | :ref:`font_color<class_MenuButton_theme_color_font_color>` | ``Color(0.875, 0.875, 0.875, 1)`` |
  41. +---------------------------------+------------------------------------------------------------------------------+-----------------------------------+
  42. | :ref:`Color<class_Color>` | :ref:`font_disabled_color<class_MenuButton_theme_color_font_disabled_color>` | ``Color(1, 1, 1, 0.3)`` |
  43. +---------------------------------+------------------------------------------------------------------------------+-----------------------------------+
  44. | :ref:`Color<class_Color>` | :ref:`font_focus_color<class_MenuButton_theme_color_font_focus_color>` | ``Color(0.95, 0.95, 0.95, 1)`` |
  45. +---------------------------------+------------------------------------------------------------------------------+-----------------------------------+
  46. | :ref:`Color<class_Color>` | :ref:`font_hover_color<class_MenuButton_theme_color_font_hover_color>` | ``Color(0.95, 0.95, 0.95, 1)`` |
  47. +---------------------------------+------------------------------------------------------------------------------+-----------------------------------+
  48. | :ref:`Color<class_Color>` | :ref:`font_outline_color<class_MenuButton_theme_color_font_outline_color>` | ``Color(1, 1, 1, 1)`` |
  49. +---------------------------------+------------------------------------------------------------------------------+-----------------------------------+
  50. | :ref:`Color<class_Color>` | :ref:`font_pressed_color<class_MenuButton_theme_color_font_pressed_color>` | ``Color(1, 1, 1, 1)`` |
  51. +---------------------------------+------------------------------------------------------------------------------+-----------------------------------+
  52. | :ref:`int<class_int>` | :ref:`hseparation<class_MenuButton_theme_constant_hseparation>` | ``3`` |
  53. +---------------------------------+------------------------------------------------------------------------------+-----------------------------------+
  54. | :ref:`int<class_int>` | :ref:`outline_size<class_MenuButton_theme_constant_outline_size>` | ``0`` |
  55. +---------------------------------+------------------------------------------------------------------------------+-----------------------------------+
  56. | :ref:`Font<class_Font>` | :ref:`font<class_MenuButton_theme_font_font>` | |
  57. +---------------------------------+------------------------------------------------------------------------------+-----------------------------------+
  58. | :ref:`int<class_int>` | :ref:`font_size<class_MenuButton_theme_font_size_font_size>` | |
  59. +---------------------------------+------------------------------------------------------------------------------+-----------------------------------+
  60. | :ref:`StyleBox<class_StyleBox>` | :ref:`disabled<class_MenuButton_theme_style_disabled>` | |
  61. +---------------------------------+------------------------------------------------------------------------------+-----------------------------------+
  62. | :ref:`StyleBox<class_StyleBox>` | :ref:`focus<class_MenuButton_theme_style_focus>` | |
  63. +---------------------------------+------------------------------------------------------------------------------+-----------------------------------+
  64. | :ref:`StyleBox<class_StyleBox>` | :ref:`hover<class_MenuButton_theme_style_hover>` | |
  65. +---------------------------------+------------------------------------------------------------------------------+-----------------------------------+
  66. | :ref:`StyleBox<class_StyleBox>` | :ref:`normal<class_MenuButton_theme_style_normal>` | |
  67. +---------------------------------+------------------------------------------------------------------------------+-----------------------------------+
  68. | :ref:`StyleBox<class_StyleBox>` | :ref:`pressed<class_MenuButton_theme_style_pressed>` | |
  69. +---------------------------------+------------------------------------------------------------------------------+-----------------------------------+
  70. Signals
  71. -------
  72. .. _class_MenuButton_signal_about_to_popup:
  73. - **about_to_popup** **(** **)**
  74. Emitted when the :ref:`PopupMenu<class_PopupMenu>` of this MenuButton is about to show.
  75. Property Descriptions
  76. ---------------------
  77. .. _class_MenuButton_property_item_count:
  78. - :ref:`int<class_int>` **item_count**
  79. +-----------+-----------------------+
  80. | *Default* | ``0`` |
  81. +-----------+-----------------------+
  82. | *Setter* | set_item_count(value) |
  83. +-----------+-----------------------+
  84. | *Getter* | get_item_count() |
  85. +-----------+-----------------------+
  86. The number of items currently in the list.
  87. ----
  88. .. _class_MenuButton_property_switch_on_hover:
  89. - :ref:`bool<class_bool>` **switch_on_hover**
  90. +-----------+----------------------------+
  91. | *Default* | ``false`` |
  92. +-----------+----------------------------+
  93. | *Setter* | set_switch_on_hover(value) |
  94. +-----------+----------------------------+
  95. | *Getter* | is_switch_on_hover() |
  96. +-----------+----------------------------+
  97. 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.
  98. Method Descriptions
  99. -------------------
  100. .. _class_MenuButton_method_get_popup:
  101. - :ref:`PopupMenu<class_PopupMenu>` **get_popup** **(** **)** |const|
  102. Returns the :ref:`PopupMenu<class_PopupMenu>` contained in this button.
  103. \ **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.
  104. ----
  105. .. _class_MenuButton_method_set_disable_shortcuts:
  106. - void **set_disable_shortcuts** **(** :ref:`bool<class_bool>` disabled **)**
  107. If ``true``, shortcuts are disabled and cannot be used to trigger the button.
  108. Theme Property Descriptions
  109. ---------------------------
  110. .. _class_MenuButton_theme_color_font_color:
  111. - :ref:`Color<class_Color>` **font_color**
  112. +-----------+-----------------------------------+
  113. | *Default* | ``Color(0.875, 0.875, 0.875, 1)`` |
  114. +-----------+-----------------------------------+
  115. Default text :ref:`Color<class_Color>` of the ``MenuButton``.
  116. ----
  117. .. _class_MenuButton_theme_color_font_disabled_color:
  118. - :ref:`Color<class_Color>` **font_disabled_color**
  119. +-----------+-------------------------+
  120. | *Default* | ``Color(1, 1, 1, 0.3)`` |
  121. +-----------+-------------------------+
  122. Text :ref:`Color<class_Color>` used when the ``MenuButton`` is disabled.
  123. ----
  124. .. _class_MenuButton_theme_color_font_focus_color:
  125. - :ref:`Color<class_Color>` **font_focus_color**
  126. +-----------+--------------------------------+
  127. | *Default* | ``Color(0.95, 0.95, 0.95, 1)`` |
  128. +-----------+--------------------------------+
  129. 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.
  130. ----
  131. .. _class_MenuButton_theme_color_font_hover_color:
  132. - :ref:`Color<class_Color>` **font_hover_color**
  133. +-----------+--------------------------------+
  134. | *Default* | ``Color(0.95, 0.95, 0.95, 1)`` |
  135. +-----------+--------------------------------+
  136. Text :ref:`Color<class_Color>` used when the ``MenuButton`` is being hovered.
  137. ----
  138. .. _class_MenuButton_theme_color_font_outline_color:
  139. - :ref:`Color<class_Color>` **font_outline_color**
  140. +-----------+-----------------------+
  141. | *Default* | ``Color(1, 1, 1, 1)`` |
  142. +-----------+-----------------------+
  143. The tint of text outline of the ``MenuButton``.
  144. ----
  145. .. _class_MenuButton_theme_color_font_pressed_color:
  146. - :ref:`Color<class_Color>` **font_pressed_color**
  147. +-----------+-----------------------+
  148. | *Default* | ``Color(1, 1, 1, 1)`` |
  149. +-----------+-----------------------+
  150. Text :ref:`Color<class_Color>` used when the ``MenuButton`` is being pressed.
  151. ----
  152. .. _class_MenuButton_theme_constant_hseparation:
  153. - :ref:`int<class_int>` **hseparation**
  154. +-----------+-------+
  155. | *Default* | ``3`` |
  156. +-----------+-------+
  157. The horizontal space between ``MenuButton``'s icon and text.
  158. ----
  159. .. _class_MenuButton_theme_constant_outline_size:
  160. - :ref:`int<class_int>` **outline_size**
  161. +-----------+-------+
  162. | *Default* | ``0`` |
  163. +-----------+-------+
  164. The size of the text outline.
  165. ----
  166. .. _class_MenuButton_theme_font_font:
  167. - :ref:`Font<class_Font>` **font**
  168. :ref:`Font<class_Font>` of the ``MenuButton``'s text.
  169. ----
  170. .. _class_MenuButton_theme_font_size_font_size:
  171. - :ref:`int<class_int>` **font_size**
  172. Font size of the ``MenuButton``'s text.
  173. ----
  174. .. _class_MenuButton_theme_style_disabled:
  175. - :ref:`StyleBox<class_StyleBox>` **disabled**
  176. :ref:`StyleBox<class_StyleBox>` used when the ``MenuButton`` is disabled.
  177. ----
  178. .. _class_MenuButton_theme_style_focus:
  179. - :ref:`StyleBox<class_StyleBox>` **focus**
  180. :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.
  181. ----
  182. .. _class_MenuButton_theme_style_hover:
  183. - :ref:`StyleBox<class_StyleBox>` **hover**
  184. :ref:`StyleBox<class_StyleBox>` used when the ``MenuButton`` is being hovered.
  185. ----
  186. .. _class_MenuButton_theme_style_normal:
  187. - :ref:`StyleBox<class_StyleBox>` **normal**
  188. Default :ref:`StyleBox<class_StyleBox>` for the ``MenuButton``.
  189. ----
  190. .. _class_MenuButton_theme_style_pressed:
  191. - :ref:`StyleBox<class_StyleBox>` **pressed**
  192. :ref:`StyleBox<class_StyleBox>` used when the ``MenuButton`` is being pressed.
  193. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  194. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  195. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  196. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  197. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  198. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`