class_menubutton.rst 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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:`bool<class_bool>` | :ref:`switch_on_hover<class_MenuButton_property_switch_on_hover>` | ``false`` |
  25. +-----------------------------------------------+-------------------------------------------------------------------+------------------------------+
  26. | :ref:`bool<class_bool>` | toggle_mode | ``true`` *(parent override)* |
  27. +-----------------------------------------------+-------------------------------------------------------------------+------------------------------+
  28. Methods
  29. -------
  30. +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------+
  31. | :ref:`PopupMenu<class_PopupMenu>` | :ref:`get_popup<class_MenuButton_method_get_popup>` **(** **)** |const| |
  32. +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------+
  33. | void | :ref:`set_disable_shortcuts<class_MenuButton_method_set_disable_shortcuts>` **(** :ref:`bool<class_bool>` disabled **)** |
  34. +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------+
  35. Theme Properties
  36. ----------------
  37. +---------------------------------+------------------------------------------------------------------------------+----------------------------------+
  38. | :ref:`Color<class_Color>` | :ref:`font_color<class_MenuButton_theme_color_font_color>` | ``Color( 0.88, 0.88, 0.88, 1 )`` |
  39. +---------------------------------+------------------------------------------------------------------------------+----------------------------------+
  40. | :ref:`Color<class_Color>` | :ref:`font_color_disabled<class_MenuButton_theme_color_font_color_disabled>` | ``Color( 1, 1, 1, 0.3 )`` |
  41. +---------------------------------+------------------------------------------------------------------------------+----------------------------------+
  42. | :ref:`Color<class_Color>` | :ref:`font_color_focus<class_MenuButton_theme_color_font_color_focus>` | ``Color( 0.94, 0.94, 0.94, 1 )`` |
  43. +---------------------------------+------------------------------------------------------------------------------+----------------------------------+
  44. | :ref:`Color<class_Color>` | :ref:`font_color_hover<class_MenuButton_theme_color_font_color_hover>` | ``Color( 0.94, 0.94, 0.94, 1 )`` |
  45. +---------------------------------+------------------------------------------------------------------------------+----------------------------------+
  46. | :ref:`Color<class_Color>` | :ref:`font_color_pressed<class_MenuButton_theme_color_font_color_pressed>` | ``Color( 1, 1, 1, 1 )`` |
  47. +---------------------------------+------------------------------------------------------------------------------+----------------------------------+
  48. | :ref:`int<class_int>` | :ref:`hseparation<class_MenuButton_theme_constant_hseparation>` | ``3`` |
  49. +---------------------------------+------------------------------------------------------------------------------+----------------------------------+
  50. | :ref:`Font<class_Font>` | :ref:`font<class_MenuButton_theme_font_font>` | |
  51. +---------------------------------+------------------------------------------------------------------------------+----------------------------------+
  52. | :ref:`StyleBox<class_StyleBox>` | :ref:`disabled<class_MenuButton_theme_style_disabled>` | |
  53. +---------------------------------+------------------------------------------------------------------------------+----------------------------------+
  54. | :ref:`StyleBox<class_StyleBox>` | :ref:`focus<class_MenuButton_theme_style_focus>` | |
  55. +---------------------------------+------------------------------------------------------------------------------+----------------------------------+
  56. | :ref:`StyleBox<class_StyleBox>` | :ref:`hover<class_MenuButton_theme_style_hover>` | |
  57. +---------------------------------+------------------------------------------------------------------------------+----------------------------------+
  58. | :ref:`StyleBox<class_StyleBox>` | :ref:`normal<class_MenuButton_theme_style_normal>` | |
  59. +---------------------------------+------------------------------------------------------------------------------+----------------------------------+
  60. | :ref:`StyleBox<class_StyleBox>` | :ref:`pressed<class_MenuButton_theme_style_pressed>` | |
  61. +---------------------------------+------------------------------------------------------------------------------+----------------------------------+
  62. Signals
  63. -------
  64. .. _class_MenuButton_signal_about_to_show:
  65. - **about_to_show** **(** **)**
  66. Emitted when :ref:`PopupMenu<class_PopupMenu>` of this MenuButton is about to show.
  67. Property Descriptions
  68. ---------------------
  69. .. _class_MenuButton_property_switch_on_hover:
  70. - :ref:`bool<class_bool>` **switch_on_hover**
  71. +-----------+----------------------------+
  72. | *Default* | ``false`` |
  73. +-----------+----------------------------+
  74. | *Setter* | set_switch_on_hover(value) |
  75. +-----------+----------------------------+
  76. | *Getter* | is_switch_on_hover() |
  77. +-----------+----------------------------+
  78. 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.
  79. Method Descriptions
  80. -------------------
  81. .. _class_MenuButton_method_get_popup:
  82. - :ref:`PopupMenu<class_PopupMenu>` **get_popup** **(** **)** |const|
  83. Returns the :ref:`PopupMenu<class_PopupMenu>` contained in this button.
  84. **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:`CanvasItem.visible<class_CanvasItem_property_visible>` property.
  85. ----
  86. .. _class_MenuButton_method_set_disable_shortcuts:
  87. - void **set_disable_shortcuts** **(** :ref:`bool<class_bool>` disabled **)**
  88. If ``true``, shortcuts are disabled and cannot be used to trigger the button.
  89. Theme Property Descriptions
  90. ---------------------------
  91. .. _class_MenuButton_theme_color_font_color:
  92. - :ref:`Color<class_Color>` **font_color**
  93. +-----------+----------------------------------+
  94. | *Default* | ``Color( 0.88, 0.88, 0.88, 1 )`` |
  95. +-----------+----------------------------------+
  96. Default text :ref:`Color<class_Color>` of the ``MenuButton``.
  97. ----
  98. .. _class_MenuButton_theme_color_font_color_disabled:
  99. - :ref:`Color<class_Color>` **font_color_disabled**
  100. +-----------+---------------------------+
  101. | *Default* | ``Color( 1, 1, 1, 0.3 )`` |
  102. +-----------+---------------------------+
  103. Text :ref:`Color<class_Color>` used when the ``MenuButton`` is disabled.
  104. ----
  105. .. _class_MenuButton_theme_color_font_color_focus:
  106. - :ref:`Color<class_Color>` **font_color_focus**
  107. +-----------+----------------------------------+
  108. | *Default* | ``Color( 0.94, 0.94, 0.94, 1 )`` |
  109. +-----------+----------------------------------+
  110. 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.
  111. ----
  112. .. _class_MenuButton_theme_color_font_color_hover:
  113. - :ref:`Color<class_Color>` **font_color_hover**
  114. +-----------+----------------------------------+
  115. | *Default* | ``Color( 0.94, 0.94, 0.94, 1 )`` |
  116. +-----------+----------------------------------+
  117. Text :ref:`Color<class_Color>` used when the ``MenuButton`` is being hovered.
  118. ----
  119. .. _class_MenuButton_theme_color_font_color_pressed:
  120. - :ref:`Color<class_Color>` **font_color_pressed**
  121. +-----------+-------------------------+
  122. | *Default* | ``Color( 1, 1, 1, 1 )`` |
  123. +-----------+-------------------------+
  124. Text :ref:`Color<class_Color>` used when the ``MenuButton`` is being pressed.
  125. ----
  126. .. _class_MenuButton_theme_constant_hseparation:
  127. - :ref:`int<class_int>` **hseparation**
  128. +-----------+-------+
  129. | *Default* | ``3`` |
  130. +-----------+-------+
  131. The horizontal space between ``MenuButton``'s icon and text.
  132. ----
  133. .. _class_MenuButton_theme_font_font:
  134. - :ref:`Font<class_Font>` **font**
  135. :ref:`Font<class_Font>` of the ``MenuButton``'s text.
  136. ----
  137. .. _class_MenuButton_theme_style_disabled:
  138. - :ref:`StyleBox<class_StyleBox>` **disabled**
  139. :ref:`StyleBox<class_StyleBox>` used when the ``MenuButton`` is disabled.
  140. ----
  141. .. _class_MenuButton_theme_style_focus:
  142. - :ref:`StyleBox<class_StyleBox>` **focus**
  143. :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.
  144. ----
  145. .. _class_MenuButton_theme_style_hover:
  146. - :ref:`StyleBox<class_StyleBox>` **hover**
  147. :ref:`StyleBox<class_StyleBox>` used when the ``MenuButton`` is being hovered.
  148. ----
  149. .. _class_MenuButton_theme_style_normal:
  150. - :ref:`StyleBox<class_StyleBox>` **normal**
  151. Default :ref:`StyleBox<class_StyleBox>` for the ``MenuButton``.
  152. ----
  153. .. _class_MenuButton_theme_style_pressed:
  154. - :ref:`StyleBox<class_StyleBox>` **pressed**
  155. :ref:`StyleBox<class_StyleBox>` used when the ``MenuButton`` is being pressed.
  156. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  157. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  158. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`