OptionButton is a type of button that brings up a dropdown with selectable items when pressed. The item selected becomes the "current" item and is displayed as the button text.
See also BaseButton which contains common properties and methods associated with this node.
Emitted when the user navigates to an item using the ProjectSettings.input/ui_up or ProjectSettings.input/ui_down input actions. The index of the item selected is passed as argument.
Emitted when the current item has been changed by the user. The index of the item selected is passed as argument.
allow_reselect must be enabled to reselect an item.
If true
, the currently selected item can be selected again.
If true
, minimum size will be determined by the longest item's text, instead of the currently selected one's.
Note: For performance reasons, the minimum size doesn't update immediately when adding, removing or modifying items.
The number of items to select from.
The index of the currently selected item, or -1
if no item is selected.
Adds an item, with a texture
icon, text label
and (optionally) id
. If no id
is passed, the item index will be used as the item's ID. New items are appended at the end.
Adds an item, with text label
and (optionally) id
. If no id
is passed, the item index will be used as the item's ID. New items are appended at the end.
Adds a separator to the list of items. Separators help to group items, and can optionally be given a text
header. A separator also gets an index assigned, and is appended at the end of the item list.
Clears all the items in the OptionButton.
Returns the icon of the item at index idx
.
Returns the ID of the item at index idx
.
Returns the index of the item with the given id
.
Retrieves the metadata of an item. Metadata may be any type and can be used to store extra information about an item, such as an external string ID.
Returns the text of the item at index idx
.
Returns the tooltip of the item at index idx
.
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.
Returns the index of the first item which is not disabled, or marked as a separator. If from_last
is true
, the items will be searched in reverse order.
Returns -1
if no item is found.
Returns the ID of the selected item, or -1
if no item is selected.
Gets the metadata of the selected item. Metadata for items can be set using set_item_metadata.
Returns true
if this button contains at least one item which is not disabled, or marked as a separator.
Returns true
if the item at index idx
is disabled.
Returns true
if the item at index idx
is marked as a separator.
Removes the item at index idx
.
Selects an item by index and makes it the current item. This will work even if the item is disabled.
Passing -1
as the index deselects any currently selected item.
If true
, shortcuts are disabled and cannot be used to trigger the button.
Sets whether the item at index idx
is disabled.
Disabled items are drawn differently in the dropdown and are not selectable by the user. If the current selected item is set as disabled, it will remain selected.
Sets the icon of the item at index idx
.
Sets the ID of the item at index idx
.
Sets the metadata of an item. Metadata may be of any type and can be used to store extra information about an item, such as an external string ID.
Sets the text of the item at index idx
.
Sets the tooltip of the item at index idx
.
Adjusts popup position and sizing for the OptionButton, then shows the PopupMenu. Prefer this over using get_popup().popup()
.