| 1 | <?xml version="1.0" encoding="UTF-8" ?> |
| 2 | <class name="OptionButton" inherits="Button" keywords="select, dropdown" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd"> |
| 3 | <brief_description> |
| 4 | A button that brings up a dropdown with selectable options when pressed. |
| 5 | </brief_description> |
| 6 | <description> |
| 7 | [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. |
| 8 | See also [BaseButton] which contains common properties and methods associated with this node. |
| 9 | [b]Note:[/b] The IDs used for items are limited to signed 32-bit integers, not the full 64 bits of [int]. These have a range of [code]-2^31[/code] to [code]2^31 - 1[/code], that is, [code]-2147483648[/code] to [code]2147483647[/code]. |
| 10 | [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. |
| 11 | </description> |
| 12 | <tutorials> |
| 13 | </tutorials> |
| 14 | <methods> |
| 15 | <method name="add_icon_item"> |
| 16 | <return type="void" /> |
| 17 | <param index="0" name="texture" type="Texture2D" /> |
| 18 | <param index="1" name="label" type="String" /> |
| 19 | <param index="2" name="id" type="int" default="-1" /> |
| 20 | <description> |
| 21 | 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. |
| 22 | [b]Note:[/b] The item will be selected if there are no other items. |
| 23 | </description> |
| 24 | </method> |
| 25 | <method name="add_item"> |
| 26 | <return type="void" /> |
| 27 | <param index="0" name="label" type="String" /> |
| 28 | <param index="1" name="id" type="int" default="-1" /> |
| 29 | <description> |
| 30 | 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. |
| 31 | [b]Note:[/b] The item will be selected if there are no other items. |
| 32 | </description> |
| 33 | </method> |
| 34 | <method name="add_separator"> |
| 35 | <return type="void" /> |
| 36 | <param index="0" name="text" type="String" default="""" /> |
| 37 | <description> |
| 38 | 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. |
| 39 | </description> |
| 40 | </method> |
| 41 | <method name="clear"> |
| 42 | <return type="void" /> |
| 43 | <description> |
| 44 | Clears all the items in the [OptionButton]. |
| 45 | </description> |
| 46 | </method> |
| 47 | <method name="get_item_auto_translate_mode" qualifiers="const"> |
| 48 | <return type="int" enum="Node.AutoTranslateMode" /> |
| 49 | <param index="0" name="idx" type="int" /> |
| 50 | <description> |
| 51 | Returns the auto translate mode of the item at index [param idx]. |
| 52 | </description> |
| 53 | </method> |
| 54 | <method name="get_item_icon" qualifiers="const"> |
| 55 | <return type="Texture2D" /> |
| 56 | <param index="0" name="idx" type="int" /> |
| 57 | <description> |
| 58 | Returns the icon of the item at index [param idx]. |
| 59 | </description> |
| 60 | </method> |
| 61 | <method name="get_item_id" qualifiers="const"> |
| 62 | <return type="int" /> |
| 63 | <param index="0" name="idx" type="int" /> |
| 64 | <description> |
| 65 | Returns the ID of the item at index [param idx]. |
| 66 | </description> |
| 67 | </method> |
| 68 | <method name="get_item_index" qualifiers="const"> |
| 69 | <return type="int" /> |
| 70 | <param index="0" name="id" type="int" /> |
| 71 | <description> |
| 72 | Returns the index of the item with the given [param id]. |
| 73 | </description> |
| 74 | </method> |
| 75 | <method name="get_item_metadata" qualifiers="const"> |
| 76 | <return type="Variant" /> |
| 77 | <param index="0" name="idx" type="int" /> |
| 78 | <description> |
| 79 | 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. |
| 80 | </description> |
| 81 | </method> |
| 82 | <method name="get_item_text" qualifiers="const"> |
| 83 | <return type="String" /> |
| 84 | <param index="0" name="idx" type="int" /> |
| 85 | <description> |
| 86 | Returns the text of the item at index [param idx]. |
| 87 | </description> |
| 88 | </method> |
| 89 | <method name="get_item_tooltip" qualifiers="const"> |
| 90 | <return type="String" /> |
| 91 | <param index="0" name="idx" type="int" /> |
| 92 | <description> |
| 93 | Returns the tooltip of the item at index [param idx]. |
| 94 | </description> |
| 95 | </method> |
| 96 | <method name="get_popup" qualifiers="const"> |
| 97 | <return type="PopupMenu" /> |
| 98 | <description> |
| 99 | Returns the [PopupMenu] contained in this button. |
| 100 | [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. |
| 101 | </description> |
| 102 | </method> |
| 103 | <method name="get_selectable_item" qualifiers="const"> |
| 104 | <return type="int" /> |
| 105 | <param index="0" name="from_last" type="bool" default="false" /> |
| 106 | <description> |
| 107 | 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. |
| 108 | Returns [code]-1[/code] if no item is found. |
| 109 | </description> |
| 110 | </method> |
| 111 | <method name="get_selected_id" qualifiers="const"> |
| 112 | <return type="int" /> |
| 113 | <description> |
| 114 | Returns the ID of the selected item, or [code]-1[/code] if no item is selected. |
| 115 | </description> |
| 116 | </method> |
| 117 | <method name="get_selected_metadata" qualifiers="const"> |
| 118 | <return type="Variant" /> |
| 119 | <description> |
| 120 | Gets the metadata of the selected item. Metadata for items can be set using [method set_item_metadata]. |
| 121 | </description> |
| 122 | </method> |
| 123 | <method name="has_selectable_items" qualifiers="const"> |
| 124 | <return type="bool" /> |
| 125 | <description> |
| 126 | Returns [code]true[/code] if this button contains at least one item which is not disabled, or marked as a separator. |
| 127 | </description> |
| 128 | </method> |
| 129 | <method name="is_item_disabled" qualifiers="const"> |
| 130 | <return type="bool" /> |
| 131 | <param index="0" name="idx" type="int" /> |
| 132 | <description> |
| 133 | Returns [code]true[/code] if the item at index [param idx] is disabled. |
| 134 | </description> |
| 135 | </method> |
| 136 | <method name="is_item_separator" qualifiers="const"> |
| 137 | <return type="bool" /> |
| 138 | <param index="0" name="idx" type="int" /> |
| 139 | <description> |
| 140 | Returns [code]true[/code] if the item at index [param idx] is marked as a separator. |
| 141 | </description> |
| 142 | </method> |
| 143 | <method name="remove_item"> |
| 144 | <return type="void" /> |
| 145 | <param index="0" name="idx" type="int" /> |
| 146 | <description> |
| 147 | Removes the item at index [param idx]. |
| 148 | </description> |
| 149 | </method> |
| 150 | <method name="select"> |
| 151 | <return type="void" /> |
| 152 | <param index="0" name="idx" type="int" /> |
| 153 | <description> |
| 154 | Selects an item by index and makes it the current item. This will work even if the item is disabled. |
| 155 | Passing [code]-1[/code] as the index deselects any currently selected item. |
| 156 | </description> |
| 157 | </method> |
| 158 | <method name="set_disable_shortcuts"> |
| 159 | <return type="void" /> |
| 160 | <param index="0" name="disabled" type="bool" /> |
| 161 | <description> |
| 162 | If [code]true[/code], shortcuts are disabled and cannot be used to trigger the button. |
| 163 | </description> |
| 164 | </method> |
| 165 | <method name="set_item_auto_translate_mode"> |
| 166 | <return type="void" /> |
| 167 | <param index="0" name="idx" type="int" /> |
| 168 | <param index="1" name="mode" type="int" enum="Node.AutoTranslateMode" /> |
| 169 | <description> |
| 170 | Sets the auto translate mode of the item at index [param idx]. |
| 171 | Items use [constant Node.AUTO_TRANSLATE_MODE_INHERIT] by default, which uses the same auto translate mode as the [OptionButton] itself. |
| 172 | </description> |
| 173 | </method> |
| 174 | <method name="set_item_disabled"> |
| 175 | <return type="void" /> |
| 176 | <param index="0" name="idx" type="int" /> |
| 177 | <param index="1" name="disabled" type="bool" /> |
| 178 | <description> |
| 179 | Sets whether the item at index [param idx] is disabled. |
| 180 | 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. |
| 181 | </description> |
| 182 | </method> |
| 183 | <method name="set_item_icon"> |
| 184 | <return type="void" /> |
| 185 | <param index="0" name="idx" type="int" /> |
| 186 | <param index="1" name="texture" type="Texture2D" /> |
| 187 | <description> |
| 188 | Sets the icon of the item at index [param idx]. |
| 189 | </description> |
| 190 | </method> |
| 191 | <method name="set_item_id"> |
| 192 | <return type="void" /> |
| 193 | <param index="0" name="idx" type="int" /> |
| 194 | <param index="1" name="id" type="int" /> |
| 195 | <description> |
| 196 | Sets the ID of the item at index [param idx]. |
| 197 | </description> |
| 198 | </method> |
| 199 | <method name="set_item_metadata"> |
| 200 | <return type="void" /> |
| 201 | <param index="0" name="idx" type="int" /> |
| 202 | <param index="1" name="metadata" type="Variant" /> |
| 203 | <description> |
| 204 | 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. |
| 205 | </description> |
| 206 | </method> |
| 207 | <method name="set_item_text"> |
| 208 | <return type="void" /> |
| 209 | <param index="0" name="idx" type="int" /> |
| 210 | <param index="1" name="text" type="String" /> |
| 211 | <description> |
| 212 | Sets the text of the item at index [param idx]. |
| 213 | </description> |
| 214 | </method> |
| 215 | <method name="set_item_tooltip"> |
| 216 | <return type="void" /> |
| 217 | <param index="0" name="idx" type="int" /> |
| 218 | <param index="1" name="tooltip" type="String" /> |
| 219 | <description> |
| 220 | Sets the tooltip of the item at index [param idx]. |
| 221 | </description> |
| 222 | </method> |
| 223 | <method name="show_popup"> |
| 224 | <return type="void" /> |
| 225 | <description> |
| 226 | Adjusts popup position and sizing for the [OptionButton], then shows the [PopupMenu]. Prefer this over using [code]get_popup().popup()[/code]. |
| 227 | </description> |
| 228 | </method> |
| 229 | </methods> |
| 230 | <members> |
| 231 | <member name="action_mode" type="int" setter="set_action_mode" getter="get_action_mode" overrides="BaseButton" enum="BaseButton.ActionMode" default="0" /> |
| 232 | <member name="alignment" type="int" setter="set_text_alignment" getter="get_text_alignment" overrides="Button" enum="HorizontalAlignment" default="0" /> |
| 233 | <member name="allow_reselect" type="bool" setter="set_allow_reselect" getter="get_allow_reselect" default="false"> |
| 234 | If [code]true[/code], the currently selected item can be selected again. |
| 235 | </member> |
| 236 | <member name="fit_to_longest_item" type="bool" setter="set_fit_to_longest_item" getter="is_fit_to_longest_item" default="true"> |
| 237 | If [code]true[/code], minimum size will be determined by the longest item's text, instead of the currently selected one's. |
| 238 | [b]Note:[/b] For performance reasons, the minimum size doesn't update immediately when adding, removing or modifying items. |
| 239 | </member> |
| 240 | <member name="item_count" type="int" setter="set_item_count" getter="get_item_count" default="0"> |
| 241 | The number of items to select from. |
| 242 | </member> |
| 243 | <member name="selected" type="int" setter="_select_int" getter="get_selected" default="-1"> |
| 244 | The index of the currently selected item, or [code]-1[/code] if no item is selected. |
| 245 | </member> |
| 246 | <member name="toggle_mode" type="bool" setter="set_toggle_mode" getter="is_toggle_mode" overrides="BaseButton" default="true" /> |
| 247 | </members> |
| 248 | <signals> |
| 249 | <signal name="item_focused"> |
| 250 | <param index="0" name="index" type="int" /> |
| 251 | <description> |
| 252 | 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. |
| 253 | </description> |
| 254 | </signal> |
| 255 | <signal name="item_selected"> |
| 256 | <param index="0" name="index" type="int" /> |
| 257 | <description> |
| 258 | Emitted when the current item has been changed by the user. The index of the item selected is passed as argument. |
| 259 | [member allow_reselect] must be enabled to reselect an item. |
| 260 | </description> |
| 261 | </signal> |
| 262 | </signals> |
| 263 | <theme_items> |
| 264 | <theme_item name="arrow_margin" data_type="constant" type="int" default="4"> |
| 265 | The horizontal space between the arrow icon and the right edge of the button. |
| 266 | </theme_item> |
| 267 | <theme_item name="modulate_arrow" data_type="constant" type="int" default="0"> |
| 268 | If different than [code]0[/code], the arrow icon will be modulated to the font color. |
| 269 | </theme_item> |
| 270 | <theme_item name="arrow" data_type="icon" type="Texture2D"> |
| 271 | The arrow icon to be drawn on the right end of the button. |
| 272 | </theme_item> |
| 273 | </theme_items> |
| 274 | </class> |