MenuButton

继承: Button < BaseButton < Control < CanvasItem < Node < Object

A button that brings up a PopupMenu when clicked.

描述

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.

属性

ActionModeaction_mode
boolflat
FocusModefocus_mode
intitem_count
boolswitch_on_hover
booltoggle_mode

方法

PopupMenuget_popup ( ) const1
voidset_disable_shortcuts ( disabled: bool )
voidshow_popup ( )

信号

about_to_popup ( )

Emitted when the PopupMenu of this MenuButton is about to show.


属性说明

int item_count = 0

  • void set_item_count ( value: int )
  • int get_item_count ( )

The number of items currently in the list.


bool switch_on_hover = false

  • void set_switch_on_hover ( value: bool )
  • bool is_switch_on_hover ( )

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.


方法说明

PopupMenu get_popup ( ) const1

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 ( disabled: bool )

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().

2

本方法通常需要用户覆盖才能生效。

1

本方法无副作用,不会修改该实例的任何成员变量。

3

本方法除了能接受在此处描述的参数外,还能够继续接受任意数量的参数。

4

本方法用于构造某个类型。

5

调用本方法无需实例,可直接使用类名进行调用。

6

本方法描述的是使用本类型作为左操作数的有效运算符。

7

这个值是由下列位标志构成位掩码的整数。

8

无返回值。