MenuButton¶
Inherits: Button < BaseButton < Control < CanvasItem < Node < Object
A button that brings up a PopupMenu when clicked.
Description¶
A button that brings up a PopupMenu when clicked. To create new items inside this PopupMenu, use get_popup().add_item("My Item Name")
. You can also create them directly from Godot editor's inspector.
See also BaseButton which contains common properties and methods associated with this node.
Properties¶
action_mode |
|
|
flat |
|
|
focus_mode |
|
|
|
||
|
||
toggle_mode |
|
Methods¶
get_popup ( ) const |
|
void |
set_disable_shortcuts ( bool disabled ) |
void |
show_popup ( ) |
Theme Properties¶
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
Signals¶
about_to_popup ( )
Emitted when the PopupMenu of this MenuButton is about to show.
Property Descriptions¶
int item_count = 0
The number of items currently in the list.
bool switch_on_hover = false
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.
Method Descriptions¶
PopupMenu get_popup ( ) const
Returns the PopupMenu contained in this button.
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 Window.visible property.
void set_disable_shortcuts ( bool disabled )
If true
, shortcuts are disabled and cannot be used to trigger the button.
void show_popup ( )
Adjusts popup position and sizing for the MenuButton, then shows the PopupMenu. Prefer this over using get_popup().popup()
.
Theme Property Descriptions¶
Color font_color = Color(0.875, 0.875, 0.875, 1)
Default text Color of the MenuButton.
Color font_disabled_color = Color(1, 1, 1, 0.3)
Text Color used when the MenuButton is disabled.
Color font_focus_color = Color(0.95, 0.95, 0.95, 1)
Text 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.
Color font_hover_color = Color(0.95, 0.95, 0.95, 1)
Text Color used when the MenuButton is being hovered.
Color font_outline_color = Color(1, 1, 1, 1)
The tint of text outline of the MenuButton.
Color font_pressed_color = Color(1, 1, 1, 1)
Text Color used when the MenuButton is being pressed.
int h_separation = 4
The horizontal space between MenuButton's icon and text. Negative values will be treated as 0
when used.
int outline_size = 0
The size of the text outline.
Note: If using a font with FontFile.multichannel_signed_distance_field enabled, its FontFile.msdf_pixel_range must be set to at least twice the value of outline_size for outline rendering to look correct. Otherwise, the outline may appear to be cut off earlier than intended.
Font font
Font of the MenuButton's text.
int font_size
Font size of the MenuButton's text.
StyleBox disabled
StyleBox used when the MenuButton is disabled.
StyleBox focus
StyleBox used when the MenuButton is focused. The focus
StyleBox is displayed over the base StyleBox, so a partially transparent StyleBox should be used to ensure the base StyleBox remains visible. A StyleBox that represents an outline or an underline works well for this purpose. To disable the focus visual effect, assign a StyleBoxEmpty resource. Note that disabling the focus visual effect will harm keyboard/controller navigation usability, so this is not recommended for accessibility reasons.
StyleBox hover
StyleBox used when the MenuButton is being hovered.
StyleBox normal
Default StyleBox for the MenuButton.
StyleBox pressed
StyleBox used when the MenuButton is being pressed.