PopupMenu
A modal window used to display a list of options.
PopupMenu.swift:28class PopupMenu
PopupMenu
is a modal window used to display a list of options. Useful for toolbars and context menus.
The size of a PopupMenu
can be limited by using maxSize
. If the height of the list of items is larger than the maximum height of the PopupMenu
, a ScrollContainer
within the popup will allow the user to scroll the contents. If no maximum size is set, or if it is set to 0
, the PopupMenu
height will be limited by its parent rect.
All set_*
methods allow negative item indices, i.e. -1
to access the last item, -2
to select the second-to-last item, and so on.
Incremental search: Like ItemList
and Tree
, PopupMenu
supports searching within the list while the control is focused. Press a key that matches the first letter of an item’s name to select the first item starting with the given letter. After that point, there are two ways to perform incremental search: 1) Press the same key again before the timeout duration to select the next item starting with the same letter. 2) Press letter keys that match the rest of the word before the timeout duration to match to select the item in question directly. Both of these actions will be reset to the beginning of the list if the timeout duration has passed since the last keystroke was registered. You can adjust the timeout duration by changing ProjectSettings/gui/timers/incrementalSearchMaxIntervalMsec
.
This object emits the following signals:
Superclasses
class Popup
Base class for contextual windows and panels with fixed position.
Citizens in SwiftGodot
Conformances
protocol CustomStringConvertible
A type with a customized textual representation.
protocol Equatable
A type that can be compared for value equality.
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol Identifiable<ID>
A class of types whose instances hold the value of an entity with stable identity.
protocol VariantRepresentable
Types that conform to VariantRepresentable can be stored directly in
Variant
with no conversion. These include all of the Variant types from Godot (for exampleGString
,Rect
,Plane
), Godot objects (those that subclass SwiftGodot.Object) as well as the built-in Swift types UInt8, Int64 and Double.protocol VariantStorable
Types that conform to VariantStorable can be stored in a Variant and can be extracted back out of a Variant.
Types
class Signal1
Signal support.
class Signal2
Signal support.
class Signal3
Signal support.
Type members
Instance members
var allowSearch: Bool
If
true
, allows navigatingPopupMenu
with letter keys.var hideOnCheckableItemSelection: Bool
If
true
, hides thePopupMenu
when a checkbox or radio button is selected.var hideOnItemSelection: Bool
If
true
, hides thePopupMenu
when an item is selected.var hideOnStateItemSelection: Bool
If
true
, hides thePopupMenu
when a state item is selected.var idFocused: Signal2
Emitted when the user navigated to an item of some
id
using theProjectSettings/input/uiUp
orProjectSettings/input/uiDown
input action.var idPressed: Signal1
Emitted when an item of some
id
is pressed or its accelerator is activated.var indexPressed: Signal3
Emitted when an item of some
index
is pressed or its accelerator is activated.var itemCount: Int32
The number of items currently in the list.
func activateItemByEvent(InputEvent?, forGlobalOnly: Bool
) -> Bool Checks the provided
event
against thePopupMenu
’s shortcuts and accelerators, and activates the first item with matching events. IfforGlobalOnly
istrue
, only shortcuts and accelerators withglobal
set totrue
will be called.func addCheckItem(label: String, id: Int32, accel: Key
) Adds a new checkable item with text
label
.func addCheckShortcut(Shortcut?, id: Int32, global: Bool
) Adds a new checkable item and assigns the specified
Shortcut
to it. Sets the label of the checkbox to theShortcut
’s name.func addIconCheckItem(texture: Texture2D?, label: String, id: Int32, accel: Key
) Adds a new checkable item with text
label
and icontexture
.func addIconCheckShortcut(texture: Texture2D?, shortcut: Shortcut?, id: Int32, global: Bool
) Adds a new checkable item and assigns the specified
Shortcut
and icontexture
to it. Sets the label of the checkbox to theShortcut
’s name.func addIconItem(texture: Texture2D?, label: String, id: Int32, accel: Key
) Adds a new item with text
label
and icontexture
.func addIconRadioCheckItem(texture: Texture2D?, label: String, id: Int32, accel: Key
) Same as
addIconCheckItem(texture:label:id:accel:)
, but uses a radio check button.func addIconRadioCheckShortcut(texture: Texture2D?, shortcut: Shortcut?, id: Int32, global: Bool
) Same as
addIconCheckShortcut(texture:shortcut:id:global:)
, but uses a radio check button.func addIconShortcut(texture: Texture2D?, shortcut: Shortcut?, id: Int32, global: Bool, allowEcho: Bool
) Adds a new item and assigns the specified
Shortcut
and icontexture
to it. Sets the label of the checkbox to theShortcut
’s name.func addItem(label: String, id: Int32, accel: Key
) Adds a new item with text
label
.func addMultistateItem(label: String, maxStates: Int32, defaultState: Int32, id: Int32, accel: Key
) Adds a new multistate item with text
label
.func addRadioCheckItem(label: String, id: Int32, accel: Key
) Adds a new radio check button with text
label
.func addRadioCheckShortcut(Shortcut?, id: Int32, global: Bool
) Adds a new radio check button and assigns a
Shortcut
to it. Sets the label of the checkbox to theShortcut
’s name.func addSeparator(label: String, id: Int32
) Adds a separator between items. Separators also occupy an index, which you can set by using the
id
parameter.func addShortcut(Shortcut?, id: Int32, global: Bool, allowEcho: Bool
) Adds a
Shortcut
.func getFocusedItem(
) -> Int32 Returns the index of the currently focused item. Returns
-1
if no item is focused.func getItemAccelerator(index: Int32
) -> Key Returns the accelerator of the item at the given
index
. An accelerator is a keyboard shortcut that can be pressed to trigger the menu button even if it’s not currently open. The return value is an integer which is generally a combination ofKeyModifierMask
s andKey
s using bitwise OR such asKEY_MASK_CTRL | KEY_A
([kbd]Ctrl + A[/kbd]). If no accelerator is defined for the specifiedindex
,getItemAccelerator(index:)
returns0
(corresponding to@GlobalScope.KEY_NONE
).func getItemIcon(index: Int32
) -> Texture2D? Returns the icon of the item at the given
index
.func getItemIconMaxWidth(index: Int32
) -> Int32 Returns the maximum allowed width of the icon for the item at the given
index
.func getItemIconModulate(index: Int32
) -> Color Returns a
Color
modulating the item’s icon at the givenindex
.func getItemId(index: Int32
) -> Int32 Returns the ID of the item at the given
index
.id
can be manually assigned, while index can not.func getItemIndent(index: Int32
) -> Int32 Returns the horizontal offset of the item at the given
index
.func getItemIndex(id: Int32
) -> Int32 Returns the index of the item containing the specified
id
. Index is automatically assigned to each item by the engine and can not be set manually.func getItemLanguage(index: Int32
) -> String Returns item’s text language code.
func getItemMetadata(index: Int32
) -> Variant Returns the metadata of the specified item, which might be of any type. You can set it with
setItemMetadata(index:metadata:)
, which provides a simple way of assigning context data to items.func getItemShortcut(index: Int32
) -> Shortcut? Returns the
Shortcut
associated with the item at the givenindex
.func getItemText(index: Int32
) -> String Returns the text of the item at the given
index
.func getItemTextDirection(index: Int32
) -> Control.TextDirection Returns item’s text base writing direction.
func getItemTooltip(index: Int32
) -> String Returns the tooltip associated with the item at the given
index
.func isItemCheckable(index: Int32
) -> Bool Returns
true
if the item at the givenindex
is checkable in some way, i.e. if it has a checkbox or radio button.func isItemChecked(index: Int32
) -> Bool Returns
true
if the item at the givenindex
is checked.func isItemDisabled(index: Int32
) -> Bool Returns
true
if the item at the givenindex
is disabled. When it is disabled it can’t be selected, or its action invoked.func isItemRadioCheckable(index: Int32
) -> Bool Returns
true
if the item at the givenindex
has radio button-style checkability.func isItemSeparator(index: Int32
) -> Bool Returns
true
if the item is a separator. If it is, it will be displayed as a line. SeeaddSeparator(label:id:)
for more info on how to add a separator.func isItemShortcutDisabled(index: Int32
) -> Bool Returns
true
if the specified item’s shortcut is disabled.func removeItem(index: Int32
) Removes the item at the given
index
from the menu.func scrollToItem(index: Int32
) Moves the scroll view to make the item at the given
index
visible.func setFocusedItem(index: Int32
) Sets the currently focused item as the given
index
.func setItemAccelerator(index: Int32, accel: Key
) Sets the accelerator of the item at the given
index
. An accelerator is a keyboard shortcut that can be pressed to trigger the menu button even if it’s not currently open.accel
is generally a combination ofKeyModifierMask
s andKey
s using bitwise OR such asKEY_MASK_CTRL | KEY_A
([kbd]Ctrl + A[/kbd]).func setItemAsCheckable(index: Int32, enable: Bool
) Sets whether the item at the given
index
has a checkbox. Iffalse
, sets the type of the item to plain text.func setItemAsRadioCheckable(index: Int32, enable: Bool
) Sets the type of the item at the given
index
to radio button. Iffalse
, sets the type of the item to plain text.func setItemAsSeparator(index: Int32, enable: Bool
) Mark the item at the given
index
as a separator, which means that it would be displayed as a line. Iffalse
, sets the type of the item to plain text.func setItemChecked(index: Int32, checked: Bool
) Sets the checkstate status of the item at the given
index
.func setItemDisabled(index: Int32, disabled: Bool
) Enables/disables the item at the given
index
. When it is disabled, it can’t be selected and its action can’t be invoked.func setItemIcon(index: Int32, icon: Texture2D?
) Replaces the
Texture2D
icon of the item at the givenindex
.func setItemIconMaxWidth(index: Int32, width: Int32
) Sets the maximum allowed width of the icon for the item at the given
index
. This limit is applied on top of the default size of the icon and on top of [theme_item icon_max_width]. The height is adjusted according to the icon’s ratio.func setItemIconModulate(index: Int32, modulate: Color
) Sets a modulating
Color
of the item’s icon at the givenindex
.func setItemId(index: Int32, id: Int32
) Sets the
id
of the item at the givenindex
.func setItemIndent(index: Int32, indent: Int32
) Sets the horizontal offset of the item at the given
index
.func setItemLanguage(index: Int32, language: String
) Sets language code of item’s text used for line-breaking and text shaping algorithms, if left empty current locale is used instead.
func setItemMetadata(index: Int32, metadata: Variant
) Sets the metadata of an item, which may be of any type. You can later get it with
getItemMetadata(index:)
, which provides a simple way of assigning context data to items.func setItemMultistate(index: Int32, state: Int32
) Sets the state of a multistate item. See
addMultistateItem(label:maxStates:defaultState:id:accel:)
for details.func setItemShortcut(index: Int32, shortcut: Shortcut?, global: Bool
) Sets a
Shortcut
for the item at the givenindex
.func setItemShortcutDisabled(index: Int32, disabled: Bool
) Disables the
Shortcut
of the item at the givenindex
.func setItemText(index: Int32, text: String
) Sets the text of the item at the given
index
.func setItemTextDirection(index: Int32, direction: Control.TextDirection
) Sets item’s text base writing direction.
func setItemTooltip(index: Int32, tooltip: String
) Sets the
String
tooltip of the item at the givenindex
.func toggleItemChecked(index: Int32
) Toggles the check state of the item at the given
index
.func toggleItemMultistate(index: Int32
) Cycle to the next state of a multistate item. See
addMultistateItem(label:maxStates:defaultState:id:accel:)
for details.