class_menubutton.rst 15 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`` *(parent override)* |
  19. +-----------------------------------------------+-------------------------------------------------------------------+------------------------------+
  20. | :ref:`bool<class_bool>` | flat | ``true`` *(parent override)* |
  21. +-----------------------------------------------+-------------------------------------------------------------------+------------------------------+
  22. | :ref:`FocusMode<enum_Control_FocusMode>` | focus_mode | ``0`` *(parent override)* |
  23. +-----------------------------------------------+-------------------------------------------------------------------+------------------------------+
  24. | :ref:`int<class_int>` | :ref:`items_count<class_MenuButton_property_items_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`` *(parent override)* |
  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:`StyleBox<class_StyleBox>` | :ref:`disabled<class_MenuButton_theme_style_disabled>` | |
  41. +---------------------------------+------------------------------------------------------------------------------+--------------------------------+
  42. | :ref:`StyleBox<class_StyleBox>` | :ref:`focus<class_MenuButton_theme_style_focus>` | |
  43. +---------------------------------+------------------------------------------------------------------------------+--------------------------------+
  44. | :ref:`Font<class_Font>` | :ref:`font<class_MenuButton_theme_font_font>` | |
  45. +---------------------------------+------------------------------------------------------------------------------+--------------------------------+
  46. | :ref:`Color<class_Color>` | :ref:`font_color<class_MenuButton_theme_color_font_color>` | ``Color(0.88, 0.88, 0.88, 1)`` |
  47. +---------------------------------+------------------------------------------------------------------------------+--------------------------------+
  48. | :ref:`Color<class_Color>` | :ref:`font_disabled_color<class_MenuButton_theme_color_font_disabled_color>` | ``Color(1, 1, 1, 0.3)`` |
  49. +---------------------------------+------------------------------------------------------------------------------+--------------------------------+
  50. | :ref:`Color<class_Color>` | :ref:`font_focus_color<class_MenuButton_theme_color_font_focus_color>` | ``Color(0.94, 0.94, 0.94, 1)`` |
  51. +---------------------------------+------------------------------------------------------------------------------+--------------------------------+
  52. | :ref:`Color<class_Color>` | :ref:`font_hover_color<class_MenuButton_theme_color_font_hover_color>` | ``Color(0.94, 0.94, 0.94, 1)`` |
  53. +---------------------------------+------------------------------------------------------------------------------+--------------------------------+
  54. | :ref:`Color<class_Color>` | :ref:`font_outline_color<class_MenuButton_theme_color_font_outline_color>` | ``Color(1, 1, 1, 1)`` |
  55. +---------------------------------+------------------------------------------------------------------------------+--------------------------------+
  56. | :ref:`Color<class_Color>` | :ref:`font_pressed_color<class_MenuButton_theme_color_font_pressed_color>` | ``Color(1, 1, 1, 1)`` |
  57. +---------------------------------+------------------------------------------------------------------------------+--------------------------------+
  58. | :ref:`int<class_int>` | :ref:`font_size<class_MenuButton_theme_font_size_font_size>` | |
  59. +---------------------------------+------------------------------------------------------------------------------+--------------------------------+
  60. | :ref:`StyleBox<class_StyleBox>` | :ref:`hover<class_MenuButton_theme_style_hover>` | |
  61. +---------------------------------+------------------------------------------------------------------------------+--------------------------------+
  62. | :ref:`int<class_int>` | :ref:`hseparation<class_MenuButton_theme_constant_hseparation>` | ``3`` |
  63. +---------------------------------+------------------------------------------------------------------------------+--------------------------------+
  64. | :ref:`StyleBox<class_StyleBox>` | :ref:`normal<class_MenuButton_theme_style_normal>` | |
  65. +---------------------------------+------------------------------------------------------------------------------+--------------------------------+
  66. | :ref:`int<class_int>` | :ref:`outline_size<class_MenuButton_theme_constant_outline_size>` | ``0`` |
  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_items_count:
  78. - :ref:`int<class_int>` **items_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_style_disabled:
  111. - :ref:`StyleBox<class_StyleBox>` **disabled**
  112. :ref:`StyleBox<class_StyleBox>` used when the ``MenuButton`` is disabled.
  113. ----
  114. .. _class_MenuButton_theme_style_focus:
  115. - :ref:`StyleBox<class_StyleBox>` **focus**
  116. :ref:`StyleBox<class_StyleBox>` used when the ``MenuButton`` is focused. It is displayed over the current :ref:`StyleBox<class_StyleBox>`, so using :ref:`StyleBoxEmpty<class_StyleBoxEmpty>` will just disable the focus visual effect.
  117. ----
  118. .. _class_MenuButton_theme_font_font:
  119. - :ref:`Font<class_Font>` **font**
  120. :ref:`Font<class_Font>` of the ``MenuButton``'s text.
  121. ----
  122. .. _class_MenuButton_theme_color_font_color:
  123. - :ref:`Color<class_Color>` **font_color**
  124. +-----------+--------------------------------+
  125. | *Default* | ``Color(0.88, 0.88, 0.88, 1)`` |
  126. +-----------+--------------------------------+
  127. Default text :ref:`Color<class_Color>` of the ``MenuButton``.
  128. ----
  129. .. _class_MenuButton_theme_color_font_disabled_color:
  130. - :ref:`Color<class_Color>` **font_disabled_color**
  131. +-----------+-------------------------+
  132. | *Default* | ``Color(1, 1, 1, 0.3)`` |
  133. +-----------+-------------------------+
  134. Text :ref:`Color<class_Color>` used when the ``MenuButton`` is disabled.
  135. ----
  136. .. _class_MenuButton_theme_color_font_focus_color:
  137. - :ref:`Color<class_Color>` **font_focus_color**
  138. +-----------+--------------------------------+
  139. | *Default* | ``Color(0.94, 0.94, 0.94, 1)`` |
  140. +-----------+--------------------------------+
  141. 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.
  142. ----
  143. .. _class_MenuButton_theme_color_font_hover_color:
  144. - :ref:`Color<class_Color>` **font_hover_color**
  145. +-----------+--------------------------------+
  146. | *Default* | ``Color(0.94, 0.94, 0.94, 1)`` |
  147. +-----------+--------------------------------+
  148. Text :ref:`Color<class_Color>` used when the ``MenuButton`` is being hovered.
  149. ----
  150. .. _class_MenuButton_theme_color_font_outline_color:
  151. - :ref:`Color<class_Color>` **font_outline_color**
  152. +-----------+-----------------------+
  153. | *Default* | ``Color(1, 1, 1, 1)`` |
  154. +-----------+-----------------------+
  155. The tint of text outline of the ``MenuButton``.
  156. ----
  157. .. _class_MenuButton_theme_color_font_pressed_color:
  158. - :ref:`Color<class_Color>` **font_pressed_color**
  159. +-----------+-----------------------+
  160. | *Default* | ``Color(1, 1, 1, 1)`` |
  161. +-----------+-----------------------+
  162. Text :ref:`Color<class_Color>` used when the ``MenuButton`` is being pressed.
  163. ----
  164. .. _class_MenuButton_theme_font_size_font_size:
  165. - :ref:`int<class_int>` **font_size**
  166. Font size of the ``MenuButton``'s text.
  167. ----
  168. .. _class_MenuButton_theme_style_hover:
  169. - :ref:`StyleBox<class_StyleBox>` **hover**
  170. :ref:`StyleBox<class_StyleBox>` used when the ``MenuButton`` is being hovered.
  171. ----
  172. .. _class_MenuButton_theme_constant_hseparation:
  173. - :ref:`int<class_int>` **hseparation**
  174. +-----------+-------+
  175. | *Default* | ``3`` |
  176. +-----------+-------+
  177. The horizontal space between ``MenuButton``'s icon and text.
  178. ----
  179. .. _class_MenuButton_theme_style_normal:
  180. - :ref:`StyleBox<class_StyleBox>` **normal**
  181. Default :ref:`StyleBox<class_StyleBox>` for the ``MenuButton``.
  182. ----
  183. .. _class_MenuButton_theme_constant_outline_size:
  184. - :ref:`int<class_int>` **outline_size**
  185. +-----------+-------+
  186. | *Default* | ``0`` |
  187. +-----------+-------+
  188. The size of the text outline.
  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.)`