class_menubutton.rst 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  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. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. Special button that brings up a :ref:`PopupMenu<class_PopupMenu>` when clicked.
  15. 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.
  16. See also :ref:`BaseButton<class_BaseButton>` which contains common properties and methods associated with this node.
  17. .. rst-class:: classref-reftable-group
  18. Properties
  19. ----------
  20. .. table::
  21. :widths: auto
  22. +-----------------------------------------------+-------------------------------------------------------------------+-------------------------------------------------------------------------------+
  23. | :ref:`ActionMode<enum_BaseButton_ActionMode>` | action_mode | ``0`` (overrides :ref:`BaseButton<class_BaseButton_property_action_mode>`) |
  24. +-----------------------------------------------+-------------------------------------------------------------------+-------------------------------------------------------------------------------+
  25. | :ref:`bool<class_bool>` | flat | ``true`` (overrides :ref:`Button<class_Button_property_flat>`) |
  26. +-----------------------------------------------+-------------------------------------------------------------------+-------------------------------------------------------------------------------+
  27. | :ref:`FocusMode<enum_Control_FocusMode>` | focus_mode | ``0`` (overrides :ref:`Control<class_Control_property_focus_mode>`) |
  28. +-----------------------------------------------+-------------------------------------------------------------------+-------------------------------------------------------------------------------+
  29. | :ref:`int<class_int>` | :ref:`item_count<class_MenuButton_property_item_count>` | ``0`` |
  30. +-----------------------------------------------+-------------------------------------------------------------------+-------------------------------------------------------------------------------+
  31. | :ref:`bool<class_bool>` | :ref:`switch_on_hover<class_MenuButton_property_switch_on_hover>` | ``false`` |
  32. +-----------------------------------------------+-------------------------------------------------------------------+-------------------------------------------------------------------------------+
  33. | :ref:`bool<class_bool>` | toggle_mode | ``true`` (overrides :ref:`BaseButton<class_BaseButton_property_toggle_mode>`) |
  34. +-----------------------------------------------+-------------------------------------------------------------------+-------------------------------------------------------------------------------+
  35. .. rst-class:: classref-reftable-group
  36. Methods
  37. -------
  38. .. table::
  39. :widths: auto
  40. +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`PopupMenu<class_PopupMenu>` | :ref:`get_popup<class_MenuButton_method_get_popup>` **(** **)** |const| |
  42. +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------+
  43. | void | :ref:`set_disable_shortcuts<class_MenuButton_method_set_disable_shortcuts>` **(** :ref:`bool<class_bool>` disabled **)** |
  44. +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------+
  45. | void | :ref:`show_popup<class_MenuButton_method_show_popup>` **(** **)** |
  46. +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------+
  47. .. rst-class:: classref-reftable-group
  48. Theme Properties
  49. ----------------
  50. .. table::
  51. :widths: auto
  52. +---------------------------------+------------------------------------------------------------------------------+-----------------------------------+
  53. | :ref:`Color<class_Color>` | :ref:`font_color<class_MenuButton_theme_color_font_color>` | ``Color(0.875, 0.875, 0.875, 1)`` |
  54. +---------------------------------+------------------------------------------------------------------------------+-----------------------------------+
  55. | :ref:`Color<class_Color>` | :ref:`font_disabled_color<class_MenuButton_theme_color_font_disabled_color>` | ``Color(1, 1, 1, 0.3)`` |
  56. +---------------------------------+------------------------------------------------------------------------------+-----------------------------------+
  57. | :ref:`Color<class_Color>` | :ref:`font_focus_color<class_MenuButton_theme_color_font_focus_color>` | ``Color(0.95, 0.95, 0.95, 1)`` |
  58. +---------------------------------+------------------------------------------------------------------------------+-----------------------------------+
  59. | :ref:`Color<class_Color>` | :ref:`font_hover_color<class_MenuButton_theme_color_font_hover_color>` | ``Color(0.95, 0.95, 0.95, 1)`` |
  60. +---------------------------------+------------------------------------------------------------------------------+-----------------------------------+
  61. | :ref:`Color<class_Color>` | :ref:`font_outline_color<class_MenuButton_theme_color_font_outline_color>` | ``Color(1, 1, 1, 1)`` |
  62. +---------------------------------+------------------------------------------------------------------------------+-----------------------------------+
  63. | :ref:`Color<class_Color>` | :ref:`font_pressed_color<class_MenuButton_theme_color_font_pressed_color>` | ``Color(1, 1, 1, 1)`` |
  64. +---------------------------------+------------------------------------------------------------------------------+-----------------------------------+
  65. | :ref:`int<class_int>` | :ref:`h_separation<class_MenuButton_theme_constant_h_separation>` | ``3`` |
  66. +---------------------------------+------------------------------------------------------------------------------+-----------------------------------+
  67. | :ref:`int<class_int>` | :ref:`outline_size<class_MenuButton_theme_constant_outline_size>` | ``0`` |
  68. +---------------------------------+------------------------------------------------------------------------------+-----------------------------------+
  69. | :ref:`Font<class_Font>` | :ref:`font<class_MenuButton_theme_font_font>` | |
  70. +---------------------------------+------------------------------------------------------------------------------+-----------------------------------+
  71. | :ref:`int<class_int>` | :ref:`font_size<class_MenuButton_theme_font_size_font_size>` | |
  72. +---------------------------------+------------------------------------------------------------------------------+-----------------------------------+
  73. | :ref:`StyleBox<class_StyleBox>` | :ref:`disabled<class_MenuButton_theme_style_disabled>` | |
  74. +---------------------------------+------------------------------------------------------------------------------+-----------------------------------+
  75. | :ref:`StyleBox<class_StyleBox>` | :ref:`focus<class_MenuButton_theme_style_focus>` | |
  76. +---------------------------------+------------------------------------------------------------------------------+-----------------------------------+
  77. | :ref:`StyleBox<class_StyleBox>` | :ref:`hover<class_MenuButton_theme_style_hover>` | |
  78. +---------------------------------+------------------------------------------------------------------------------+-----------------------------------+
  79. | :ref:`StyleBox<class_StyleBox>` | :ref:`normal<class_MenuButton_theme_style_normal>` | |
  80. +---------------------------------+------------------------------------------------------------------------------+-----------------------------------+
  81. | :ref:`StyleBox<class_StyleBox>` | :ref:`pressed<class_MenuButton_theme_style_pressed>` | |
  82. +---------------------------------+------------------------------------------------------------------------------+-----------------------------------+
  83. .. rst-class:: classref-section-separator
  84. ----
  85. .. rst-class:: classref-descriptions-group
  86. Signals
  87. -------
  88. .. _class_MenuButton_signal_about_to_popup:
  89. .. rst-class:: classref-signal
  90. **about_to_popup** **(** **)**
  91. Emitted when the :ref:`PopupMenu<class_PopupMenu>` of this MenuButton is about to show.
  92. .. rst-class:: classref-section-separator
  93. ----
  94. .. rst-class:: classref-descriptions-group
  95. Property Descriptions
  96. ---------------------
  97. .. _class_MenuButton_property_item_count:
  98. .. rst-class:: classref-property
  99. :ref:`int<class_int>` **item_count** = ``0``
  100. .. rst-class:: classref-property-setget
  101. - void **set_item_count** **(** :ref:`int<class_int>` value **)**
  102. - :ref:`int<class_int>` **get_item_count** **(** **)**
  103. The number of items currently in the list.
  104. .. rst-class:: classref-item-separator
  105. ----
  106. .. _class_MenuButton_property_switch_on_hover:
  107. .. rst-class:: classref-property
  108. :ref:`bool<class_bool>` **switch_on_hover** = ``false``
  109. .. rst-class:: classref-property-setget
  110. - void **set_switch_on_hover** **(** :ref:`bool<class_bool>` value **)**
  111. - :ref:`bool<class_bool>` **is_switch_on_hover** **(** **)**
  112. 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.
  113. .. rst-class:: classref-section-separator
  114. ----
  115. .. rst-class:: classref-descriptions-group
  116. Method Descriptions
  117. -------------------
  118. .. _class_MenuButton_method_get_popup:
  119. .. rst-class:: classref-method
  120. :ref:`PopupMenu<class_PopupMenu>` **get_popup** **(** **)** |const|
  121. Returns the :ref:`PopupMenu<class_PopupMenu>` contained in this button.
  122. \ **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.
  123. .. rst-class:: classref-item-separator
  124. ----
  125. .. _class_MenuButton_method_set_disable_shortcuts:
  126. .. rst-class:: classref-method
  127. void **set_disable_shortcuts** **(** :ref:`bool<class_bool>` disabled **)**
  128. If ``true``, shortcuts are disabled and cannot be used to trigger the button.
  129. .. rst-class:: classref-item-separator
  130. ----
  131. .. _class_MenuButton_method_show_popup:
  132. .. rst-class:: classref-method
  133. void **show_popup** **(** **)**
  134. Adjusts popup position and sizing for the **MenuButton**, then shows the :ref:`PopupMenu<class_PopupMenu>`. Prefer this over using ``get_popup().popup()``.
  135. .. rst-class:: classref-section-separator
  136. ----
  137. .. rst-class:: classref-descriptions-group
  138. Theme Property Descriptions
  139. ---------------------------
  140. .. _class_MenuButton_theme_color_font_color:
  141. .. rst-class:: classref-themeproperty
  142. :ref:`Color<class_Color>` **font_color** = ``Color(0.875, 0.875, 0.875, 1)``
  143. Default text :ref:`Color<class_Color>` of the **MenuButton**.
  144. .. rst-class:: classref-item-separator
  145. ----
  146. .. _class_MenuButton_theme_color_font_disabled_color:
  147. .. rst-class:: classref-themeproperty
  148. :ref:`Color<class_Color>` **font_disabled_color** = ``Color(1, 1, 1, 0.3)``
  149. Text :ref:`Color<class_Color>` used when the **MenuButton** is disabled.
  150. .. rst-class:: classref-item-separator
  151. ----
  152. .. _class_MenuButton_theme_color_font_focus_color:
  153. .. rst-class:: classref-themeproperty
  154. :ref:`Color<class_Color>` **font_focus_color** = ``Color(0.95, 0.95, 0.95, 1)``
  155. 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.
  156. .. rst-class:: classref-item-separator
  157. ----
  158. .. _class_MenuButton_theme_color_font_hover_color:
  159. .. rst-class:: classref-themeproperty
  160. :ref:`Color<class_Color>` **font_hover_color** = ``Color(0.95, 0.95, 0.95, 1)``
  161. Text :ref:`Color<class_Color>` used when the **MenuButton** is being hovered.
  162. .. rst-class:: classref-item-separator
  163. ----
  164. .. _class_MenuButton_theme_color_font_outline_color:
  165. .. rst-class:: classref-themeproperty
  166. :ref:`Color<class_Color>` **font_outline_color** = ``Color(1, 1, 1, 1)``
  167. The tint of text outline of the **MenuButton**.
  168. .. rst-class:: classref-item-separator
  169. ----
  170. .. _class_MenuButton_theme_color_font_pressed_color:
  171. .. rst-class:: classref-themeproperty
  172. :ref:`Color<class_Color>` **font_pressed_color** = ``Color(1, 1, 1, 1)``
  173. Text :ref:`Color<class_Color>` used when the **MenuButton** is being pressed.
  174. .. rst-class:: classref-item-separator
  175. ----
  176. .. _class_MenuButton_theme_constant_h_separation:
  177. .. rst-class:: classref-themeproperty
  178. :ref:`int<class_int>` **h_separation** = ``3``
  179. The horizontal space between **MenuButton**'s icon and text. Negative values will be treated as ``0`` when used.
  180. .. rst-class:: classref-item-separator
  181. ----
  182. .. _class_MenuButton_theme_constant_outline_size:
  183. .. rst-class:: classref-themeproperty
  184. :ref:`int<class_int>` **outline_size** = ``0``
  185. The size of the text outline.
  186. \ **Note:** If using a font with :ref:`FontFile.multichannel_signed_distance_field<class_FontFile_property_multichannel_signed_distance_field>` enabled, its :ref:`FontFile.msdf_pixel_range<class_FontFile_property_msdf_pixel_range>` must be set to at least *twice* the value of :ref:`outline_size<class_MenuButton_theme_constant_outline_size>` for outline rendering to look correct. Otherwise, the outline may appear to be cut off earlier than intended.
  187. .. rst-class:: classref-item-separator
  188. ----
  189. .. _class_MenuButton_theme_font_font:
  190. .. rst-class:: classref-themeproperty
  191. :ref:`Font<class_Font>` **font**
  192. :ref:`Font<class_Font>` of the **MenuButton**'s text.
  193. .. rst-class:: classref-item-separator
  194. ----
  195. .. _class_MenuButton_theme_font_size_font_size:
  196. .. rst-class:: classref-themeproperty
  197. :ref:`int<class_int>` **font_size**
  198. Font size of the **MenuButton**'s text.
  199. .. rst-class:: classref-item-separator
  200. ----
  201. .. _class_MenuButton_theme_style_disabled:
  202. .. rst-class:: classref-themeproperty
  203. :ref:`StyleBox<class_StyleBox>` **disabled**
  204. :ref:`StyleBox<class_StyleBox>` used when the **MenuButton** is disabled.
  205. .. rst-class:: classref-item-separator
  206. ----
  207. .. _class_MenuButton_theme_style_focus:
  208. .. rst-class:: classref-themeproperty
  209. :ref:`StyleBox<class_StyleBox>` **focus**
  210. :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.
  211. .. rst-class:: classref-item-separator
  212. ----
  213. .. _class_MenuButton_theme_style_hover:
  214. .. rst-class:: classref-themeproperty
  215. :ref:`StyleBox<class_StyleBox>` **hover**
  216. :ref:`StyleBox<class_StyleBox>` used when the **MenuButton** is being hovered.
  217. .. rst-class:: classref-item-separator
  218. ----
  219. .. _class_MenuButton_theme_style_normal:
  220. .. rst-class:: classref-themeproperty
  221. :ref:`StyleBox<class_StyleBox>` **normal**
  222. Default :ref:`StyleBox<class_StyleBox>` for the **MenuButton**.
  223. .. rst-class:: classref-item-separator
  224. ----
  225. .. _class_MenuButton_theme_style_pressed:
  226. .. rst-class:: classref-themeproperty
  227. :ref:`StyleBox<class_StyleBox>` **pressed**
  228. :ref:`StyleBox<class_StyleBox>` used when the **MenuButton** is being pressed.
  229. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  230. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  231. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  232. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  233. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  234. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`