OptionButton
Button control that provides selectable options when pressed.
OptionButton is a type button that provides a selectable list of items when pressed. The item selected becomes the “current” item and is displayed as the button text.
See also which contains common properties and methods associated with this node.
Properties
Theme Properties
- item_focused ( int index )
Emitted when the user navigates to an item using the ui_up
or ui_down
actions. The index of the item selected is passed as argument.
- item_selected ( index )
Emitted when the current item has been changed by the user. The index of the item selected is passed as argument.
Property Descriptions
The index of the currently selected item, or -1
if no item is selected.
Adds an item, with a texture
icon, text 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.
- void add_item ( label, int id=-1 )
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.
- void add_separator ( )
- void clear ( )
Clears all the items in the OptionButton
.
- get_item_count ( ) const
Returns the amount of items in the OptionButton, including separators.
- Texture get_item_icon ( idx ) const
Returns the icon of the item at index idx
.
- int get_item_id ( idx ) const
Returns the ID of the item at index idx
.
- int get_item_index ( id ) const
Returns the index of the item with the given .
- Variant get_item_metadata ( idx ) const
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
.
- PopupMenu get_popup ( ) const
Returns the contained in this button.
- int get_selected_id ( ) const
- get_selected_metadata ( ) const
Gets the metadata of the selected item. Metadata for items can be set using set_item_metadata.
- is_item_disabled ( int idx ) const
Returns true
if the item at index idx
is disabled.
- void remove_item ( idx )
Removes the item at index idx
.
- void select ( int idx )
Selects an item by index and makes it the current item. This will work even if the item is disabled.
- void set_item_disabled ( idx, bool disabled )
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.
- void set_item_icon ( idx, Texture texture )
Sets the icon of the item at index idx
.
- void set_item_id ( idx, int id )
Sets the ID of the item at index idx
.
- void set_item_text ( idx, String text )
Sets the text of the item at index .