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
void | add_icon_item ( texture, String label, id=-1 ) |
void | |
void | ( ) |
void | clear ( ) |
get_item_count ( ) const | |
get_item_icon ( idx ) const | |
( int idx ) const | |
get_item_index ( id ) const | |
( int idx ) const | |
get_item_text ( idx ) const | |
( int idx ) const | |
get_popup ( ) const | |
get_selected_id ( ) const | |
get_selected_metadata ( ) const | |
is_item_disabled ( idx ) const | |
void | remove_item ( idx ) |
void | select ( idx ) |
void | set_item_disabled ( idx, bool disabled ) |
( int idx, texture ) | |
void | set_item_id ( idx, int id ) |
void | ( int idx, metadata ) |
void | set_item_text ( idx, String text ) |
void | ( int idx, tooltip ) |
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
- selected
The index of the currently selected item, or -1
if no item is selected.
- void add_icon_item ( texture, String label, id=-1 )
- void add_item ( String label, id=-1 )
Adds an item, with 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_separator ( )
Adds a separator to the list of items. Separators help to group items. Separator also takes up an index and is appended at the end.
- void clear ( )
Clears all the items in the OptionButton
.
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 id
.
- 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.
- String get_item_text ( idx ) const
Returns the text of the item at index idx
.
- String get_item_tooltip ( idx ) const
Returns the tooltip of the item at index idx
.
- PopupMenu get_popup ( ) const
Returns the 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 CanvasItem.visible property.
- get_selected_id ( ) const
Returns the ID of the selected item, or -1
if no item is selected.
- Variant get_selected_metadata ( ) const
Gets the metadata of the selected item. Metadata for items can be set using .
- bool is_item_disabled ( idx ) const
Returns true
if the item at index idx
is disabled.
- void remove_item ( int idx )
Removes the item at index idx
.
- void select ( 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.
- void set_item_disabled ( int idx, 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 ( int idx, texture )
Sets the icon of the item at index idx
.
- void set_item_id ( int idx, id )
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.
- void set_item_text ( int idx, text )
Sets the text of the item at index idx
.
- void set_item_tooltip ( int idx, tooltip )
Sets the tooltip of the item at index idx
.
Theme Property Descriptions
- font_color
Default |
Default text Color of the OptionButton
.
- font_color_disabled
Default |
|
Text Color used when the OptionButton
is disabled.
- font_color_focus
Text Color used when the OptionButton
is focused. Only replaces the normal text color of the button. Disabled, hovered, and pressed states take precedence over this color.
- font_color_hover
Default |
|
Text Color used when the OptionButton
is being hovered.
- font_color_pressed
Default |
|
Text Color used when the OptionButton
is being pressed.
- arrow_margin
The horizontal space between the arrow icon and the right edge of the button.
- int hseparation
Default |
|
The horizontal space between OptionButton
‘s icon and text.
- font
Font of the OptionButton
‘s text.
- arrow
The arrow icon to be drawn on the right end of the button.
- StyleBox disabled
used when the OptionButton
is disabled.
- StyleBox focus
used when the OptionButton
is focused. It is displayed over the current StyleBox, so using will just disable the focus visual effect.
- StyleBox hover
used when the OptionButton
is being hovered.
- StyleBox normal
used when the OptionButton
is being pressed.