class_menubutton.rst 18 KB

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