A button that brings up a dropdown with selectable options when pressed.
[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.
[b]Note:[/b] Properties [member Button.text] and [member Button.icon] are automatically set based on the selected item. They shouldn't be changed manually.
[b]Note:[/b] The ID values used for items are limited to 32 bits, not full 64 bits of [int]. This has a range of [code]-2^32[/code] to [code]2^32 - 1[/code], i.e. [code]-2147483648[/code] to [code]2147483647[/code].
[b]Note:[/b] The ID values used for items are 32-bit, unlike [int] which is always 64-bit. They go from [code]-2147483648[/code] to [code]2147483647[/code].
[b]Note:[/b] The [member Button.text] and [member Button.icon] properties are set automatically based on the selected item. They shouldn't be changed manually.
Adds an item, with a [param texture] icon, text [param label] and (optionally) [param id]. If no [param 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 [param label] and (optionally) [param id]. If no [param 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 [param 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 [param idx].
Returns the ID of the item at index [param idx].
Returns the index of the item with the given [param 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 [param idx].
Returns the tooltip of the item at index [param idx].
Returns the [PopupMenu] contained in this button.
[b]Warning:[/b] 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 [member Window.visible] property.
Returns the index of the first item which is not disabled, or marked as a separator. If [param from_last] is [code]true[/code], the items will be searched in reverse order.
Returns [code]-1[/code] if no item is found.
Returns the ID of the selected item, or [code]-1[/code] if no item is selected.
Gets the metadata of the selected item. Metadata for items can be set using [method set_item_metadata].
Returns [code]true[/code] if this button contains at least one item which is not disabled, or marked as a separator.
Returns [code]true[/code] if the item at index [param idx] is disabled.
Returns [code]true[/code] if the item at index [param idx] is marked as a separator.
Removes the item at index [param idx].
Selects an item by index and makes it the current item. This will work even if the item is disabled.
Passing [code]-1[/code] as the index deselects any currently selected item.
Sets whether the item at index [param 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 [param idx].
Sets the ID of the item at index [param 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 [param idx].
Sets the tooltip of the item at index [param idx].
Adjusts popup position and sizing for the [OptionButton], then shows the [PopupMenu]. Prefer this over using [code]get_popup().popup()[/code].
If [code]true[/code], minimum size will be determined by the longest item's text, instead of the currently selected one's.
[b]Note:[/b] 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 [code]-1[/code] if no item is selected.
Emitted when the user navigates to an item using the [member ProjectSettings.input/ui_up] or [member 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.
Default text [Color] of the [OptionButton].
Text [Color] used when the [OptionButton] is disabled.
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.
Text [Color] used when the [OptionButton] is being hovered.
Text [Color] used when the [OptionButton] is being hovered and pressed.
The tint of text outline of the [OptionButton].
Text [Color] used when the [OptionButton] is being pressed.
The horizontal space between the arrow icon and the right edge of the button.
The horizontal space between [OptionButton]'s icon and text. Negative values will be treated as [code]0[/code] when used.
If different than [code]0[/code], the arrow icon will be modulated to the font color.
The size of the text outline.
[b]Note:[/b] If using a font with [member FontFile.multichannel_signed_distance_field] enabled, its [member FontFile.msdf_pixel_range] must be set to at least [i]twice[/i] the value of [theme_item outline_size] for outline rendering to look correct. Otherwise, the outline may appear to be cut off earlier than intended.
[Font] of the [OptionButton]'s text.
Font size of the [OptionButton]'s text.
The arrow icon to be drawn on the right end of the button.
[StyleBox] used when the [OptionButton] is disabled (for left-to-right layouts).
[StyleBox] used when the [OptionButton] is disabled (for right-to-left layouts).
[StyleBox] used when the [OptionButton] is focused. The [code]focus[/code] [StyleBox] is displayed [i]over[/i] the base [StyleBox], so a partially transparent [StyleBox] should be used to ensure the base [StyleBox] remains visible. A [StyleBox] that represents an outline or an underline works well for this purpose. To disable the focus visual effect, assign a [StyleBoxEmpty] resource. Note that disabling the focus visual effect will harm keyboard/controller navigation usability, so this is not recommended for accessibility reasons.
[StyleBox] used when the [OptionButton] is being hovered (for left-to-right layouts).
[StyleBox] used when the [OptionButton] is being hovered (for right-to-left layouts).
Default [StyleBox] for the [OptionButton] (for left-to-right layouts).
Default [StyleBox] for the [OptionButton] (for right-to-left layouts).
[StyleBox] used when the [OptionButton] is being pressed (for left-to-right layouts).
[StyleBox] used when the [OptionButton] is being pressed (for right-to-left layouts).