OptionButton

Inherits: Button < BaseButton < Control < CanvasItem < Node < Object Button control that provides selectable options when pressed.

Description

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. BaseButton which contains common properties and methods associated with this node.

Properties

Methods

Theme Properties

Signals

  • item_focused ( int index ) ui_up or ui_down actions. The index of the item selected is passed as argument.

  • item_selected ( int index ) Emitted when the current item has been changed by the user. The index of the item selected is passed as argument.

    Property Descriptions

  • int selected -1 if no item is selected.

    Method Descriptions

  • add_icon_item ( Texture texture, String label, int id=-1 ) 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.

  • add_item ( String label, int id=-1 ) 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.

  • 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.

  • clear ( ) OptionButton.

  • int get_item_count ( ) const Returns the amount of items in the OptionButton, including separators.

  • Texture get_item_icon ( int idx ) const idx.

  • int get_item_id ( int idx ) const idx.

  • int get_item_index ( int id ) const id.

  • Variant get_item_metadata ( int 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 ( int idx ) const idx.

  • String get_item_tooltip ( int idx ) const idx.

  • PopupMenu get_popup ( ) const 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 CanvasItem.visible property.

  • int get_selected_id ( ) const -1 if no item is selected.

  • Variant get_selected_metadata ( ) const set_item_metadata.

  • bool is_item_disabled ( int idx ) const true if the item at index idx is disabled.

  • remove_item ( int idx ) idx.

  • select ( int idx ) Selects an item by index and makes it the current item. This will work even if the item is disabled. -1 as the index deselects any currently selected item.

  • set_item_disabled ( int idx, bool disabled ) 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.

  • set_item_icon ( int idx, Texture texture ) idx.

  • set_item_id ( int idx, int id ) idx.

  • set_item_metadata ( int idx, Variant metadata ) 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.

  • set_item_text ( int idx, String text ) idx.

  • set_item_tooltip ( int idx, String tooltip ) idx.

    Theme Property Descriptions

  • Color font_color Color of the OptionButton.

  • Color font_color_disabled Color used when the OptionButton is disabled.

  • Color font_color_focus 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.

  • Color font_color_hover Color used when the OptionButton is being hovered.

  • Color font_color_pressed Color used when the OptionButton is being pressed.

  • int arrow_margin The horizontal space between the arrow icon and the right edge of the button.

  • int hseparation OptionButton‘s icon and text.

  • Font font Font of the OptionButton‘s text.

  • Texture arrow The arrow icon to be drawn on the right end of the button.

  • StyleBox disabled StyleBox used when the OptionButton is disabled.

  • StyleBox focus StyleBox used when the OptionButton is focused. It is displayed over the current StyleBox, so using StyleBoxEmpty will just disable the focus visual effect.

  • StyleBox hover StyleBox used when the OptionButton is being hovered.

  • StyleBox normal StyleBox for the OptionButton.

  • StyleBox pressed StyleBox used when the OptionButton is being pressed.