Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
MenuButton
继承: Button < BaseButton < Control < CanvasItem < Node < Object
点击后会弹出 PopupMenu 的按钮。
描述
点击后会弹出 PopupMenu 的按钮。可以使用 get_popup().add_item("菜单项名称") 在这个 PopupMenu 中创建新的菜单项,也可以直接从 Godot 编辑器的检查器中创建。
另见 BaseButton,提供了与该节点相关的常用属性和方法。
属性
action_mode |
|
|
flat |
|
|
focus_mode |
|
|
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
toggle_mode |
|
方法
get_popup() const |
|
void |
set_disable_shortcuts(disabled: bool) |
void |
信号
about_to_popup() 🔗
该 MenuButton 的 PopupMenu 即将显示时发出。
属性说明
当前列表中的项目数。
int popup/item_{index}/checkable = 0 🔗
索引为 index 的可勾选菜单项的类型。
注意: index 的取值必须在 0 .. item_count - 1 范围内。
bool popup/item_{index}/checked = false 🔗
如果设置为 true,那么位于 index 位置的选项就会被勾选。
注意: index 的取值范围在 0 到 item_count - 1 之间。
bool popup/item_{index}/disabled = false 🔗
如果为 true,则禁用位于 index 处的项目。
注意: index 的取值范围为 0 .. item_count - 1。
Texture2D popup/item_{index}/icon 🔗
位于 index 处的项目的图标。
注意: index 的取值范围为 0 .. item_count - 1。
int popup/item_{index}/id = 0 🔗
索引为 index 的菜单项的 ID。
注意: index 的取值必须在 0 .. item_count - 1 范围内。
bool popup/item_{index}/separator = false 🔗
如果为 true,则索引为 index 的菜单项是一个分隔符。
注意: index 的取值必须在 0 .. item_count - 1 范围内。
String popup/item_{index}/text = "" 🔗
位于 index 处的项目的文本。
注意: index 的取值范围为 0 .. item_count - 1。
bool switch_on_hover = false 🔗
如果为 true,当光标悬停在同一父级中也启用了 switch_on_hover 的另一个 MenuButton 上方时,它将关闭当前的 MenuButton 并打开另一个。
方法说明
返回这个按钮中包含的 PopupMenu。
警告:这是一个必需的内部节点,移除和释放它可能会导致崩溃。如果你想隐藏它或它的任何子节点,请使用其 Window.visible 属性。
void set_disable_shortcuts(disabled: bool) 🔗
如果为 true,快捷方式将被禁用,无法用于触发按钮。
void show_popup() 🔗
调整该 MenuButton 的弹出位置和大小,然后显示该 PopupMenu。请优先使用此方法,而不是使用 get_popup().popup()。