2017-09-12 22:42:36 +02:00
<?xml version="1.0" encoding="UTF-8" ?>
2023-07-06 10:08:05 +02:00
<class name= "OptionButton" inherits= "Button" xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation= "../class.xsd" >
2017-09-12 22:42:36 +02:00
<brief_description >
2023-04-30 16:26:09 +02:00
A button that brings up a dropdown with selectable options when pressed.
2017-09-12 22:42:36 +02:00
</brief_description>
<description >
2023-04-30 16:26:09 +02:00
[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.
2020-09-23 23:34:28 +02:00
See also [BaseButton] which contains common properties and methods associated with this node.
2022-03-19 13:36:10 +01:00
[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.
2023-05-19 11:41:16 +02:00
[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].
2023-04-30 16:26:09 +02:00
[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.
2017-09-12 22:42:36 +02:00
</description>
<tutorials >
</tutorials>
<methods >
<method name= "add_icon_item" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "texture" type= "Texture2D" />
<param index= "1" name= "label" type= "String" />
<param index= "2" name= "id" type= "int" default= "-1" />
2017-09-12 22:42:36 +02:00
<description >
2022-08-12 15:36:48 +02:00
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.
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "add_item" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "label" type= "String" />
<param index= "1" name= "id" type= "int" default= "-1" />
2017-09-12 22:42:36 +02:00
<description >
2022-08-12 15:36:48 +02:00
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.
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "add_separator" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "text" type= "String" default= """" />
2017-09-12 22:42:36 +02:00
<description >
2022-08-12 15:36:48 +02:00
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.
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "clear" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
2017-09-12 22:42:36 +02:00
<description >
2019-12-17 23:24:54 +01:00
Clears all the items in the [OptionButton].
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "get_item_icon" qualifiers= "const" >
2021-07-30 15:28:05 +02:00
<return type= "Texture2D" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "idx" type= "int" />
2017-09-12 22:42:36 +02:00
<description >
2022-08-12 15:36:48 +02:00
Returns the icon of the item at index [param idx].
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "get_item_id" qualifiers= "const" >
2021-07-30 15:28:05 +02:00
<return type= "int" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "idx" type= "int" />
2017-09-12 22:42:36 +02:00
<description >
2022-08-12 15:36:48 +02:00
Returns the ID of the item at index [param idx].
2019-01-28 16:31:24 +01:00
</description>
</method>
2019-02-16 14:40:52 +01:00
<method name= "get_item_index" qualifiers= "const" >
2021-07-30 15:28:05 +02:00
<return type= "int" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "id" type= "int" />
2019-02-16 14:40:52 +01:00
<description >
2022-08-12 15:36:48 +02:00
Returns the index of the item with the given [param id].
2019-02-16 14:40:52 +01:00
</description>
</method>
2017-09-12 22:42:36 +02:00
<method name= "get_item_metadata" qualifiers= "const" >
2021-07-30 15:28:05 +02:00
<return type= "Variant" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "idx" type= "int" />
2017-09-12 22:42:36 +02:00
<description >
2019-12-17 23:24:54 +01:00
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.
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "get_item_text" qualifiers= "const" >
2021-07-30 15:28:05 +02:00
<return type= "String" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "idx" type= "int" />
2017-09-12 22:42:36 +02:00
<description >
2022-08-12 15:36:48 +02:00
Returns the text of the item at index [param idx].
2017-09-12 22:42:36 +02:00
</description>
</method>
2022-03-17 06:50:16 +01:00
<method name= "get_item_tooltip" qualifiers= "const" >
<return type= "String" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "idx" type= "int" />
2022-03-17 06:50:16 +01:00
<description >
2022-08-12 15:36:48 +02:00
Returns the tooltip of the item at index [param idx].
2022-03-17 06:50:16 +01:00
</description>
</method>
2017-12-25 16:24:10 +01:00
<method name= "get_popup" qualifiers= "const" >
2021-07-30 15:28:05 +02:00
<return type= "PopupMenu" />
2017-12-25 16:24:10 +01:00
<description >
2019-05-24 04:15:43 +02:00
Returns the [PopupMenu] contained in this button.
2021-10-10 21:28:56 +02:00
[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.
2017-12-25 16:24:10 +01:00
</description>
</method>
2022-04-07 13:49:28 +02:00
<method name= "get_selectable_item" qualifiers= "const" >
<return type= "int" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "from_last" type= "bool" default= "false" />
2022-04-07 13:49:28 +02:00
<description >
2022-12-25 23:29:10 +01:00
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.
2022-04-07 13:49:28 +02:00
</description>
</method>
2017-09-12 22:42:36 +02:00
<method name= "get_selected_id" qualifiers= "const" >
2021-07-30 15:28:05 +02:00
<return type= "int" />
2017-09-12 22:42:36 +02:00
<description >
2022-01-28 23:03:45 +01:00
Returns the ID of the selected item, or [code]-1[/code] if no item is selected.
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "get_selected_metadata" qualifiers= "const" >
2021-07-30 15:28:05 +02:00
<return type= "Variant" />
2017-09-12 22:42:36 +02:00
<description >
2019-12-17 23:24:54 +01:00
Gets the metadata of the selected item. Metadata for items can be set using [method set_item_metadata].
2017-09-12 22:42:36 +02:00
</description>
</method>
2022-04-07 13:49:28 +02:00
<method name= "has_selectable_items" qualifiers= "const" >
<return type= "bool" />
<description >
2022-12-25 23:29:10 +01:00
Returns [code]true[/code] if this button contains at least one item which is not disabled, or marked as a separator.
2022-04-07 13:49:28 +02:00
</description>
</method>
2017-09-12 22:42:36 +02:00
<method name= "is_item_disabled" qualifiers= "const" >
2021-07-30 15:28:05 +02:00
<return type= "bool" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "idx" type= "int" />
2017-09-12 22:42:36 +02:00
<description >
2022-08-12 15:36:48 +02:00
Returns [code]true[/code] if the item at index [param idx] is disabled.
2017-09-12 22:42:36 +02:00
</description>
</method>
2022-04-07 13:49:28 +02:00
<method name= "is_item_separator" qualifiers= "const" >
<return type= "bool" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "idx" type= "int" />
2022-04-07 13:49:28 +02:00
<description >
2022-12-25 23:29:10 +01:00
Returns [code]true[/code] if the item at index [param idx] is marked as a separator.
2022-04-07 13:49:28 +02:00
</description>
</method>
2017-09-12 22:42:36 +02:00
<method name= "remove_item" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "idx" type= "int" />
2017-09-12 22:42:36 +02:00
<description >
2022-08-12 15:36:48 +02:00
Removes the item at index [param idx].
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "select" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "idx" type= "int" />
2017-09-12 22:42:36 +02:00
<description >
2019-12-17 23:24:54 +01:00
Selects an item by index and makes it the current item. This will work even if the item is disabled.
2022-01-28 23:03:45 +01:00
Passing [code]-1[/code] as the index deselects any currently selected item.
2017-09-12 22:42:36 +02:00
</description>
</method>
2023-08-03 10:38:20 +02:00
<method name= "set_disable_shortcuts" >
<return type= "void" />
<param index= "0" name= "disabled" type= "bool" />
<description >
If [code]true[/code], shortcuts are disabled and cannot be used to trigger the button.
</description>
</method>
2017-09-12 22:42:36 +02:00
<method name= "set_item_disabled" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "idx" type= "int" />
<param index= "1" name= "disabled" type= "bool" />
2017-09-12 22:42:36 +02:00
<description >
2022-08-12 15:36:48 +02:00
Sets whether the item at index [param idx] is disabled.
2019-12-17 23:24:54 +01:00
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.
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "set_item_icon" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "idx" type= "int" />
<param index= "1" name= "texture" type= "Texture2D" />
2017-09-12 22:42:36 +02:00
<description >
2022-08-12 15:36:48 +02:00
Sets the icon of the item at index [param idx].
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "set_item_id" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "idx" type= "int" />
<param index= "1" name= "id" type= "int" />
2017-09-12 22:42:36 +02:00
<description >
2022-08-12 15:36:48 +02:00
Sets the ID of the item at index [param idx].
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "set_item_metadata" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "idx" type= "int" />
<param index= "1" name= "metadata" type= "Variant" />
2017-09-12 22:42:36 +02:00
<description >
2019-12-17 23:24:54 +01:00
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.
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "set_item_text" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "idx" type= "int" />
<param index= "1" name= "text" type= "String" />
2017-09-12 22:42:36 +02:00
<description >
2022-08-12 15:36:48 +02:00
Sets the text of the item at index [param idx].
2017-09-12 22:42:36 +02:00
</description>
</method>
2022-03-17 06:50:16 +01:00
<method name= "set_item_tooltip" >
<return type= "void" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "idx" type= "int" />
<param index= "1" name= "tooltip" type= "String" />
2022-03-17 06:50:16 +01:00
<description >
2022-08-12 15:36:48 +02:00
Sets the tooltip of the item at index [param idx].
2022-03-17 06:50:16 +01:00
</description>
</method>
2022-10-02 08:46:37 +02:00
<method name= "show_popup" >
<return type= "void" />
<description >
Adjusts popup position and sizing for the [OptionButton], then shows the [PopupMenu]. Prefer this over using [code]get_popup().popup()[/code].
</description>
</method>
2017-09-12 22:42:36 +02:00
</methods>
<members >
2021-12-02 20:38:49 +01:00
<member name= "action_mode" type= "int" setter= "set_action_mode" getter= "get_action_mode" overrides= "BaseButton" enum= "BaseButton.ActionMode" default= "0" />
2021-11-25 03:58:47 +01:00
<member name= "alignment" type= "int" setter= "set_text_alignment" getter= "get_text_alignment" overrides= "Button" enum= "HorizontalAlignment" default= "0" />
2023-01-25 11:39:09 +01:00
<member name= "allow_reselect" type= "bool" setter= "set_allow_reselect" getter= "get_allow_reselect" default= "false" >
If [code]true[/code], the currently selected item can be selected again.
</member>
2022-03-19 02:15:55 +01:00
<member name= "fit_to_longest_item" type= "bool" setter= "set_fit_to_longest_item" getter= "is_fit_to_longest_item" default= "true" >
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.
</member>
2021-12-11 16:13:16 +01:00
<member name= "item_count" type= "int" setter= "set_item_count" getter= "get_item_count" default= "0" >
The number of items to select from.
</member>
2019-06-29 12:38:01 +02:00
<member name= "selected" type= "int" setter= "_select_int" getter= "get_selected" default= "-1" >
2019-12-17 23:24:54 +01:00
The index of the currently selected item, or [code]-1[/code] if no item is selected.
2017-09-12 22:42:36 +02:00
</member>
2021-12-02 20:38:49 +01:00
<member name= "toggle_mode" type= "bool" setter= "set_toggle_mode" getter= "is_toggle_mode" overrides= "BaseButton" default= "true" />
2017-09-12 22:42:36 +02:00
</members>
<signals >
2018-04-10 10:12:42 +02:00
<signal name= "item_focused" >
2022-08-06 20:11:48 +02:00
<param index= "0" name= "index" type= "int" />
2018-04-10 10:12:42 +02:00
<description >
2022-11-01 15:29:38 +01:00
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.
2018-04-10 10:12:42 +02:00
</description>
</signal>
2017-09-12 22:42:36 +02:00
<signal name= "item_selected" >
2022-08-06 20:11:48 +02:00
<param index= "0" name= "index" type= "int" />
2017-09-12 22:42:36 +02:00
<description >
2019-06-22 01:04:47 +02:00
Emitted when the current item has been changed by the user. The index of the item selected is passed as argument.
2023-01-25 11:39:09 +01:00
[member allow_reselect] must be enabled to reselect an item.
2017-09-12 22:42:36 +02:00
</description>
</signal>
</signals>
<theme_items >
2021-12-30 17:22:06 +01:00
<theme_item name= "font_color" data_type= "color" type= "Color" default= "Color(0.875, 0.875, 0.875, 1)" >
2020-02-04 08:46:01 +01:00
Default text [Color] of the [OptionButton].
2017-09-12 22:42:36 +02:00
</theme_item>
2021-12-30 17:22:06 +01:00
<theme_item name= "font_disabled_color" data_type= "color" type= "Color" default= "Color(0.875, 0.875, 0.875, 0.5)" >
2020-02-04 08:46:01 +01:00
Text [Color] used when the [OptionButton] is disabled.
2017-09-12 22:42:36 +02:00
</theme_item>
2021-12-30 17:22:06 +01:00
<theme_item name= "font_focus_color" data_type= "color" type= "Color" default= "Color(0.95, 0.95, 0.95, 1)" >
2021-10-26 16:28:12 +02:00
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.
</theme_item>
2021-12-30 17:22:06 +01:00
<theme_item name= "font_hover_color" data_type= "color" type= "Color" default= "Color(0.95, 0.95, 0.95, 1)" >
2020-02-04 08:46:01 +01:00
Text [Color] used when the [OptionButton] is being hovered.
2017-09-12 22:42:36 +02:00
</theme_item>
2022-08-11 14:15:04 +02:00
<theme_item name= "font_hover_pressed_color" data_type= "color" type= "Color" default= "Color(1, 1, 1, 1)" >
Text [Color] used when the [OptionButton] is being hovered and pressed.
</theme_item>
2021-08-04 18:54:41 +02:00
<theme_item name= "font_outline_color" data_type= "color" type= "Color" default= "Color(1, 1, 1, 1)" >
2020-12-25 22:45:28 +01:00
The tint of text outline of the [OptionButton].
</theme_item>
2021-08-04 18:54:41 +02:00
<theme_item name= "font_pressed_color" data_type= "color" type= "Color" default= "Color(1, 1, 1, 1)" >
2020-02-04 08:46:01 +01:00
Text [Color] used when the [OptionButton] is being pressed.
2017-09-12 22:42:36 +02:00
</theme_item>
2021-12-30 17:22:06 +01:00
<theme_item name= "arrow_margin" data_type= "constant" type= "int" default= "4" >
2021-12-01 19:02:20 +01:00
The horizontal space between the arrow icon and the right edge of the button.
</theme_item>
2023-08-05 06:13:48 +02:00
<theme_item name= "h_separation" data_type= "constant" type= "int" default= "4" >
2022-08-12 13:39:22 +02:00
The horizontal space between [OptionButton]'s icon and text. Negative values will be treated as [code]0[/code] when used.
2021-12-01 19:02:20 +01:00
</theme_item>
2022-08-11 14:15:04 +02:00
<theme_item name= "modulate_arrow" data_type= "constant" type= "int" default= "0" >
If different than [code]0[/code], the arrow icon will be modulated to the font color.
</theme_item>
2021-12-01 19:02:20 +01:00
<theme_item name= "outline_size" data_type= "constant" type= "int" default= "0" >
The size of the text outline.
2022-12-19 17:15:44 +01:00
[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.
2021-12-01 19:02:20 +01:00
</theme_item>
<theme_item name= "font" data_type= "font" type= "Font" >
[Font] of the [OptionButton]'s text.
</theme_item>
2021-08-04 18:54:41 +02:00
<theme_item name= "font_size" data_type= "font_size" type= "int" >
2020-08-12 13:49:10 +02:00
Font size of the [OptionButton]'s text.
</theme_item>
2021-12-01 19:02:20 +01:00
<theme_item name= "arrow" data_type= "icon" type= "Texture2D" >
The arrow icon to be drawn on the right end of the button.
</theme_item>
<theme_item name= "disabled" data_type= "style" type= "StyleBox" >
[StyleBox] used when the [OptionButton] is disabled (for left-to-right layouts).
</theme_item>
<theme_item name= "disabled_mirrored" data_type= "style" type= "StyleBox" >
[StyleBox] used when the [OptionButton] is disabled (for right-to-left layouts).
</theme_item>
<theme_item name= "focus" data_type= "style" type= "StyleBox" >
2021-11-20 17:43:34 +01:00
[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.
2021-12-01 19:02:20 +01:00
</theme_item>
2021-08-04 18:54:41 +02:00
<theme_item name= "hover" data_type= "style" type= "StyleBox" >
2020-08-12 13:49:10 +02:00
[StyleBox] used when the [OptionButton] is being hovered (for left-to-right layouts).
</theme_item>
2021-08-04 18:54:41 +02:00
<theme_item name= "hover_mirrored" data_type= "style" type= "StyleBox" >
2020-08-12 13:49:10 +02:00
[StyleBox] used when the [OptionButton] is being hovered (for right-to-left layouts).
2017-09-12 22:42:36 +02:00
</theme_item>
2021-08-04 18:54:41 +02:00
<theme_item name= "normal" data_type= "style" type= "StyleBox" >
2020-08-12 13:49:10 +02:00
Default [StyleBox] for the [OptionButton] (for left-to-right layouts).
</theme_item>
2021-08-04 18:54:41 +02:00
<theme_item name= "normal_mirrored" data_type= "style" type= "StyleBox" >
2020-08-12 13:49:10 +02:00
Default [StyleBox] for the [OptionButton] (for right-to-left layouts).
2017-09-12 22:42:36 +02:00
</theme_item>
2021-08-04 18:54:41 +02:00
<theme_item name= "pressed" data_type= "style" type= "StyleBox" >
2020-08-12 13:49:10 +02:00
[StyleBox] used when the [OptionButton] is being pressed (for left-to-right layouts).
</theme_item>
2021-08-04 18:54:41 +02:00
<theme_item name= "pressed_mirrored" data_type= "style" type= "StyleBox" >
2020-08-12 13:49:10 +02:00
[StyleBox] used when the [OptionButton] is being pressed (for right-to-left layouts).
2017-09-12 22:42:36 +02:00
</theme_item>
</theme_items>
</class>