class_optionbutton.rst 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. :github_url: hide
  2. .. meta::
  3. :keywords: select
  4. .. DO NOT EDIT THIS FILE!!!
  5. .. Generated automatically from Godot engine sources.
  6. .. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
  7. .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/OptionButton.xml.
  8. .. _class_OptionButton:
  9. OptionButton
  10. ============
  11. **Inherits:** :ref:`Button<class_Button>` **<** :ref:`BaseButton<class_BaseButton>` **<** :ref:`Control<class_Control>` **<** :ref:`CanvasItem<class_CanvasItem>` **<** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
  12. A button that brings up a dropdown with selectable options when pressed.
  13. .. rst-class:: classref-introduction-group
  14. Description
  15. -----------
  16. **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.
  17. See also :ref:`BaseButton<class_BaseButton>` which contains common properties and methods associated with this node.
  18. \ **Note:** The IDs used for items are limited to signed 32-bit integers, not the full 64 bits of :ref:`int<class_int>`. These have a range of ``-2^31`` to ``2^31 - 1``, that is, ``-2147483648`` to ``2147483647``.
  19. \ **Note:** The :ref:`Button.text<class_Button_property_text>` and :ref:`Button.icon<class_Button_property_icon>` properties are set automatically based on the selected item. They shouldn't be changed manually.
  20. .. rst-class:: classref-reftable-group
  21. Properties
  22. ----------
  23. .. table::
  24. :widths: auto
  25. +-------------------------------------------------------------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------+
  26. | :ref:`ActionMode<enum_BaseButton_ActionMode>` | action_mode | ``0`` (overrides :ref:`BaseButton<class_BaseButton_property_action_mode>`) |
  27. +-------------------------------------------------------------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------+
  28. | :ref:`HorizontalAlignment<enum_@GlobalScope_HorizontalAlignment>` | alignment | ``0`` (overrides :ref:`Button<class_Button_property_alignment>`) |
  29. +-------------------------------------------------------------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------+
  30. | :ref:`bool<class_bool>` | :ref:`allow_reselect<class_OptionButton_property_allow_reselect>` | ``false`` |
  31. +-------------------------------------------------------------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------+
  32. | :ref:`bool<class_bool>` | :ref:`fit_to_longest_item<class_OptionButton_property_fit_to_longest_item>` | ``true`` |
  33. +-------------------------------------------------------------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------+
  34. | :ref:`int<class_int>` | :ref:`item_count<class_OptionButton_property_item_count>` | ``0`` |
  35. +-------------------------------------------------------------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------+
  36. | :ref:`int<class_int>` | :ref:`selected<class_OptionButton_property_selected>` | ``-1`` |
  37. +-------------------------------------------------------------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------+
  38. | :ref:`bool<class_bool>` | toggle_mode | ``true`` (overrides :ref:`BaseButton<class_BaseButton_property_toggle_mode>`) |
  39. +-------------------------------------------------------------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------+
  40. .. rst-class:: classref-reftable-group
  41. Methods
  42. -------
  43. .. table::
  44. :widths: auto
  45. +-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  46. | |void| | :ref:`add_icon_item<class_OptionButton_method_add_icon_item>`\ (\ texture\: :ref:`Texture2D<class_Texture2D>`, label\: :ref:`String<class_String>`, id\: :ref:`int<class_int>` = -1\ ) |
  47. +-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  48. | |void| | :ref:`add_item<class_OptionButton_method_add_item>`\ (\ label\: :ref:`String<class_String>`, id\: :ref:`int<class_int>` = -1\ ) |
  49. +-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  50. | |void| | :ref:`add_separator<class_OptionButton_method_add_separator>`\ (\ text\: :ref:`String<class_String>` = ""\ ) |
  51. +-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  52. | |void| | :ref:`clear<class_OptionButton_method_clear>`\ (\ ) |
  53. +-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  54. | :ref:`AutoTranslateMode<enum_Node_AutoTranslateMode>` | :ref:`get_item_auto_translate_mode<class_OptionButton_method_get_item_auto_translate_mode>`\ (\ idx\: :ref:`int<class_int>`\ ) |const| |
  55. +-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  56. | :ref:`Texture2D<class_Texture2D>` | :ref:`get_item_icon<class_OptionButton_method_get_item_icon>`\ (\ idx\: :ref:`int<class_int>`\ ) |const| |
  57. +-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  58. | :ref:`int<class_int>` | :ref:`get_item_id<class_OptionButton_method_get_item_id>`\ (\ idx\: :ref:`int<class_int>`\ ) |const| |
  59. +-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  60. | :ref:`int<class_int>` | :ref:`get_item_index<class_OptionButton_method_get_item_index>`\ (\ id\: :ref:`int<class_int>`\ ) |const| |
  61. +-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  62. | :ref:`Variant<class_Variant>` | :ref:`get_item_metadata<class_OptionButton_method_get_item_metadata>`\ (\ idx\: :ref:`int<class_int>`\ ) |const| |
  63. +-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  64. | :ref:`String<class_String>` | :ref:`get_item_text<class_OptionButton_method_get_item_text>`\ (\ idx\: :ref:`int<class_int>`\ ) |const| |
  65. +-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  66. | :ref:`String<class_String>` | :ref:`get_item_tooltip<class_OptionButton_method_get_item_tooltip>`\ (\ idx\: :ref:`int<class_int>`\ ) |const| |
  67. +-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  68. | :ref:`PopupMenu<class_PopupMenu>` | :ref:`get_popup<class_OptionButton_method_get_popup>`\ (\ ) |const| |
  69. +-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  70. | :ref:`int<class_int>` | :ref:`get_selectable_item<class_OptionButton_method_get_selectable_item>`\ (\ from_last\: :ref:`bool<class_bool>` = false\ ) |const| |
  71. +-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  72. | :ref:`int<class_int>` | :ref:`get_selected_id<class_OptionButton_method_get_selected_id>`\ (\ ) |const| |
  73. +-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  74. | :ref:`Variant<class_Variant>` | :ref:`get_selected_metadata<class_OptionButton_method_get_selected_metadata>`\ (\ ) |const| |
  75. +-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  76. | :ref:`bool<class_bool>` | :ref:`has_selectable_items<class_OptionButton_method_has_selectable_items>`\ (\ ) |const| |
  77. +-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  78. | :ref:`bool<class_bool>` | :ref:`is_item_disabled<class_OptionButton_method_is_item_disabled>`\ (\ idx\: :ref:`int<class_int>`\ ) |const| |
  79. +-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  80. | :ref:`bool<class_bool>` | :ref:`is_item_separator<class_OptionButton_method_is_item_separator>`\ (\ idx\: :ref:`int<class_int>`\ ) |const| |
  81. +-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  82. | |void| | :ref:`remove_item<class_OptionButton_method_remove_item>`\ (\ idx\: :ref:`int<class_int>`\ ) |
  83. +-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  84. | |void| | :ref:`select<class_OptionButton_method_select>`\ (\ idx\: :ref:`int<class_int>`\ ) |
  85. +-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  86. | |void| | :ref:`set_disable_shortcuts<class_OptionButton_method_set_disable_shortcuts>`\ (\ disabled\: :ref:`bool<class_bool>`\ ) |
  87. +-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  88. | |void| | :ref:`set_item_auto_translate_mode<class_OptionButton_method_set_item_auto_translate_mode>`\ (\ idx\: :ref:`int<class_int>`, mode\: :ref:`AutoTranslateMode<enum_Node_AutoTranslateMode>`\ ) |
  89. +-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  90. | |void| | :ref:`set_item_disabled<class_OptionButton_method_set_item_disabled>`\ (\ idx\: :ref:`int<class_int>`, disabled\: :ref:`bool<class_bool>`\ ) |
  91. +-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  92. | |void| | :ref:`set_item_icon<class_OptionButton_method_set_item_icon>`\ (\ idx\: :ref:`int<class_int>`, texture\: :ref:`Texture2D<class_Texture2D>`\ ) |
  93. +-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  94. | |void| | :ref:`set_item_id<class_OptionButton_method_set_item_id>`\ (\ idx\: :ref:`int<class_int>`, id\: :ref:`int<class_int>`\ ) |
  95. +-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  96. | |void| | :ref:`set_item_metadata<class_OptionButton_method_set_item_metadata>`\ (\ idx\: :ref:`int<class_int>`, metadata\: :ref:`Variant<class_Variant>`\ ) |
  97. +-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  98. | |void| | :ref:`set_item_text<class_OptionButton_method_set_item_text>`\ (\ idx\: :ref:`int<class_int>`, text\: :ref:`String<class_String>`\ ) |
  99. +-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  100. | |void| | :ref:`set_item_tooltip<class_OptionButton_method_set_item_tooltip>`\ (\ idx\: :ref:`int<class_int>`, tooltip\: :ref:`String<class_String>`\ ) |
  101. +-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  102. | |void| | :ref:`show_popup<class_OptionButton_method_show_popup>`\ (\ ) |
  103. +-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  104. .. rst-class:: classref-reftable-group
  105. Theme Properties
  106. ----------------
  107. .. table::
  108. :widths: auto
  109. +-----------------------------------+-------------------------------------------------------------------------+-------+
  110. | :ref:`int<class_int>` | :ref:`arrow_margin<class_OptionButton_theme_constant_arrow_margin>` | ``4`` |
  111. +-----------------------------------+-------------------------------------------------------------------------+-------+
  112. | :ref:`int<class_int>` | :ref:`modulate_arrow<class_OptionButton_theme_constant_modulate_arrow>` | ``0`` |
  113. +-----------------------------------+-------------------------------------------------------------------------+-------+
  114. | :ref:`Texture2D<class_Texture2D>` | :ref:`arrow<class_OptionButton_theme_icon_arrow>` | |
  115. +-----------------------------------+-------------------------------------------------------------------------+-------+
  116. .. rst-class:: classref-section-separator
  117. ----
  118. .. rst-class:: classref-descriptions-group
  119. Signals
  120. -------
  121. .. _class_OptionButton_signal_item_focused:
  122. .. rst-class:: classref-signal
  123. **item_focused**\ (\ index\: :ref:`int<class_int>`\ ) :ref:`🔗<class_OptionButton_signal_item_focused>`
  124. Emitted when the user navigates to an item using the :ref:`ProjectSettings.input/ui_up<class_ProjectSettings_property_input/ui_up>` or :ref:`ProjectSettings.input/ui_down<class_ProjectSettings_property_input/ui_down>` input actions. The index of the item selected is passed as argument.
  125. .. rst-class:: classref-item-separator
  126. ----
  127. .. _class_OptionButton_signal_item_selected:
  128. .. rst-class:: classref-signal
  129. **item_selected**\ (\ index\: :ref:`int<class_int>`\ ) :ref:`🔗<class_OptionButton_signal_item_selected>`
  130. Emitted when the current item has been changed by the user. The index of the item selected is passed as argument.
  131. \ :ref:`allow_reselect<class_OptionButton_property_allow_reselect>` must be enabled to reselect an item.
  132. .. rst-class:: classref-section-separator
  133. ----
  134. .. rst-class:: classref-descriptions-group
  135. Property Descriptions
  136. ---------------------
  137. .. _class_OptionButton_property_allow_reselect:
  138. .. rst-class:: classref-property
  139. :ref:`bool<class_bool>` **allow_reselect** = ``false`` :ref:`🔗<class_OptionButton_property_allow_reselect>`
  140. .. rst-class:: classref-property-setget
  141. - |void| **set_allow_reselect**\ (\ value\: :ref:`bool<class_bool>`\ )
  142. - :ref:`bool<class_bool>` **get_allow_reselect**\ (\ )
  143. If ``true``, the currently selected item can be selected again.
  144. .. rst-class:: classref-item-separator
  145. ----
  146. .. _class_OptionButton_property_fit_to_longest_item:
  147. .. rst-class:: classref-property
  148. :ref:`bool<class_bool>` **fit_to_longest_item** = ``true`` :ref:`🔗<class_OptionButton_property_fit_to_longest_item>`
  149. .. rst-class:: classref-property-setget
  150. - |void| **set_fit_to_longest_item**\ (\ value\: :ref:`bool<class_bool>`\ )
  151. - :ref:`bool<class_bool>` **is_fit_to_longest_item**\ (\ )
  152. If ``true``, minimum size will be determined by the longest item's text, instead of the currently selected one's.
  153. \ **Note:** For performance reasons, the minimum size doesn't update immediately when adding, removing or modifying items.
  154. .. rst-class:: classref-item-separator
  155. ----
  156. .. _class_OptionButton_property_item_count:
  157. .. rst-class:: classref-property
  158. :ref:`int<class_int>` **item_count** = ``0`` :ref:`🔗<class_OptionButton_property_item_count>`
  159. .. rst-class:: classref-property-setget
  160. - |void| **set_item_count**\ (\ value\: :ref:`int<class_int>`\ )
  161. - :ref:`int<class_int>` **get_item_count**\ (\ )
  162. The number of items to select from.
  163. .. rst-class:: classref-item-separator
  164. ----
  165. .. _class_OptionButton_property_selected:
  166. .. rst-class:: classref-property
  167. :ref:`int<class_int>` **selected** = ``-1`` :ref:`🔗<class_OptionButton_property_selected>`
  168. .. rst-class:: classref-property-setget
  169. - :ref:`int<class_int>` **get_selected**\ (\ )
  170. The index of the currently selected item, or ``-1`` if no item is selected.
  171. .. rst-class:: classref-section-separator
  172. ----
  173. .. rst-class:: classref-descriptions-group
  174. Method Descriptions
  175. -------------------
  176. .. _class_OptionButton_method_add_icon_item:
  177. .. rst-class:: classref-method
  178. |void| **add_icon_item**\ (\ texture\: :ref:`Texture2D<class_Texture2D>`, label\: :ref:`String<class_String>`, id\: :ref:`int<class_int>` = -1\ ) :ref:`🔗<class_OptionButton_method_add_icon_item>`
  179. Adds an item, with a ``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.
  180. \ **Note:** The item will be selected if there are no other items.
  181. .. rst-class:: classref-item-separator
  182. ----
  183. .. _class_OptionButton_method_add_item:
  184. .. rst-class:: classref-method
  185. |void| **add_item**\ (\ label\: :ref:`String<class_String>`, id\: :ref:`int<class_int>` = -1\ ) :ref:`🔗<class_OptionButton_method_add_item>`
  186. Adds an item, with 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.
  187. \ **Note:** The item will be selected if there are no other items.
  188. .. rst-class:: classref-item-separator
  189. ----
  190. .. _class_OptionButton_method_add_separator:
  191. .. rst-class:: classref-method
  192. |void| **add_separator**\ (\ text\: :ref:`String<class_String>` = ""\ ) :ref:`🔗<class_OptionButton_method_add_separator>`
  193. Adds a separator to the list of items. Separators help to group items, and can optionally be given a ``text`` header. A separator also gets an index assigned, and is appended at the end of the item list.
  194. .. rst-class:: classref-item-separator
  195. ----
  196. .. _class_OptionButton_method_clear:
  197. .. rst-class:: classref-method
  198. |void| **clear**\ (\ ) :ref:`🔗<class_OptionButton_method_clear>`
  199. Clears all the items in the **OptionButton**.
  200. .. rst-class:: classref-item-separator
  201. ----
  202. .. _class_OptionButton_method_get_item_auto_translate_mode:
  203. .. rst-class:: classref-method
  204. :ref:`AutoTranslateMode<enum_Node_AutoTranslateMode>` **get_item_auto_translate_mode**\ (\ idx\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_OptionButton_method_get_item_auto_translate_mode>`
  205. Returns the auto translate mode of the item at index ``idx``.
  206. .. rst-class:: classref-item-separator
  207. ----
  208. .. _class_OptionButton_method_get_item_icon:
  209. .. rst-class:: classref-method
  210. :ref:`Texture2D<class_Texture2D>` **get_item_icon**\ (\ idx\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_OptionButton_method_get_item_icon>`
  211. Returns the icon of the item at index ``idx``.
  212. .. rst-class:: classref-item-separator
  213. ----
  214. .. _class_OptionButton_method_get_item_id:
  215. .. rst-class:: classref-method
  216. :ref:`int<class_int>` **get_item_id**\ (\ idx\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_OptionButton_method_get_item_id>`
  217. Returns the ID of the item at index ``idx``.
  218. .. rst-class:: classref-item-separator
  219. ----
  220. .. _class_OptionButton_method_get_item_index:
  221. .. rst-class:: classref-method
  222. :ref:`int<class_int>` **get_item_index**\ (\ id\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_OptionButton_method_get_item_index>`
  223. Returns the index of the item with the given ``id``.
  224. .. rst-class:: classref-item-separator
  225. ----
  226. .. _class_OptionButton_method_get_item_metadata:
  227. .. rst-class:: classref-method
  228. :ref:`Variant<class_Variant>` **get_item_metadata**\ (\ idx\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_OptionButton_method_get_item_metadata>`
  229. 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.
  230. .. rst-class:: classref-item-separator
  231. ----
  232. .. _class_OptionButton_method_get_item_text:
  233. .. rst-class:: classref-method
  234. :ref:`String<class_String>` **get_item_text**\ (\ idx\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_OptionButton_method_get_item_text>`
  235. Returns the text of the item at index ``idx``.
  236. .. rst-class:: classref-item-separator
  237. ----
  238. .. _class_OptionButton_method_get_item_tooltip:
  239. .. rst-class:: classref-method
  240. :ref:`String<class_String>` **get_item_tooltip**\ (\ idx\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_OptionButton_method_get_item_tooltip>`
  241. Returns the tooltip of the item at index ``idx``.
  242. .. rst-class:: classref-item-separator
  243. ----
  244. .. _class_OptionButton_method_get_popup:
  245. .. rst-class:: classref-method
  246. :ref:`PopupMenu<class_PopupMenu>` **get_popup**\ (\ ) |const| :ref:`🔗<class_OptionButton_method_get_popup>`
  247. Returns the :ref:`PopupMenu<class_PopupMenu>` contained in this button.
  248. \ **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 :ref:`Window.visible<class_Window_property_visible>` property.
  249. .. rst-class:: classref-item-separator
  250. ----
  251. .. _class_OptionButton_method_get_selectable_item:
  252. .. rst-class:: classref-method
  253. :ref:`int<class_int>` **get_selectable_item**\ (\ from_last\: :ref:`bool<class_bool>` = false\ ) |const| :ref:`🔗<class_OptionButton_method_get_selectable_item>`
  254. Returns the index of the first item which is not disabled, or marked as a separator. If ``from_last`` is ``true``, the items will be searched in reverse order.
  255. Returns ``-1`` if no item is found.
  256. .. rst-class:: classref-item-separator
  257. ----
  258. .. _class_OptionButton_method_get_selected_id:
  259. .. rst-class:: classref-method
  260. :ref:`int<class_int>` **get_selected_id**\ (\ ) |const| :ref:`🔗<class_OptionButton_method_get_selected_id>`
  261. Returns the ID of the selected item, or ``-1`` if no item is selected.
  262. .. rst-class:: classref-item-separator
  263. ----
  264. .. _class_OptionButton_method_get_selected_metadata:
  265. .. rst-class:: classref-method
  266. :ref:`Variant<class_Variant>` **get_selected_metadata**\ (\ ) |const| :ref:`🔗<class_OptionButton_method_get_selected_metadata>`
  267. Gets the metadata of the selected item. Metadata for items can be set using :ref:`set_item_metadata()<class_OptionButton_method_set_item_metadata>`.
  268. .. rst-class:: classref-item-separator
  269. ----
  270. .. _class_OptionButton_method_has_selectable_items:
  271. .. rst-class:: classref-method
  272. :ref:`bool<class_bool>` **has_selectable_items**\ (\ ) |const| :ref:`🔗<class_OptionButton_method_has_selectable_items>`
  273. Returns ``true`` if this button contains at least one item which is not disabled, or marked as a separator.
  274. .. rst-class:: classref-item-separator
  275. ----
  276. .. _class_OptionButton_method_is_item_disabled:
  277. .. rst-class:: classref-method
  278. :ref:`bool<class_bool>` **is_item_disabled**\ (\ idx\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_OptionButton_method_is_item_disabled>`
  279. Returns ``true`` if the item at index ``idx`` is disabled.
  280. .. rst-class:: classref-item-separator
  281. ----
  282. .. _class_OptionButton_method_is_item_separator:
  283. .. rst-class:: classref-method
  284. :ref:`bool<class_bool>` **is_item_separator**\ (\ idx\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_OptionButton_method_is_item_separator>`
  285. Returns ``true`` if the item at index ``idx`` is marked as a separator.
  286. .. rst-class:: classref-item-separator
  287. ----
  288. .. _class_OptionButton_method_remove_item:
  289. .. rst-class:: classref-method
  290. |void| **remove_item**\ (\ idx\: :ref:`int<class_int>`\ ) :ref:`🔗<class_OptionButton_method_remove_item>`
  291. Removes the item at index ``idx``.
  292. .. rst-class:: classref-item-separator
  293. ----
  294. .. _class_OptionButton_method_select:
  295. .. rst-class:: classref-method
  296. |void| **select**\ (\ idx\: :ref:`int<class_int>`\ ) :ref:`🔗<class_OptionButton_method_select>`
  297. Selects an item by index and makes it the current item. This will work even if the item is disabled.
  298. Passing ``-1`` as the index deselects any currently selected item.
  299. .. rst-class:: classref-item-separator
  300. ----
  301. .. _class_OptionButton_method_set_disable_shortcuts:
  302. .. rst-class:: classref-method
  303. |void| **set_disable_shortcuts**\ (\ disabled\: :ref:`bool<class_bool>`\ ) :ref:`🔗<class_OptionButton_method_set_disable_shortcuts>`
  304. If ``true``, shortcuts are disabled and cannot be used to trigger the button.
  305. .. rst-class:: classref-item-separator
  306. ----
  307. .. _class_OptionButton_method_set_item_auto_translate_mode:
  308. .. rst-class:: classref-method
  309. |void| **set_item_auto_translate_mode**\ (\ idx\: :ref:`int<class_int>`, mode\: :ref:`AutoTranslateMode<enum_Node_AutoTranslateMode>`\ ) :ref:`🔗<class_OptionButton_method_set_item_auto_translate_mode>`
  310. Sets the auto translate mode of the item at index ``idx``.
  311. Items use :ref:`Node.AUTO_TRANSLATE_MODE_INHERIT<class_Node_constant_AUTO_TRANSLATE_MODE_INHERIT>` by default, which uses the same auto translate mode as the **OptionButton** itself.
  312. .. rst-class:: classref-item-separator
  313. ----
  314. .. _class_OptionButton_method_set_item_disabled:
  315. .. rst-class:: classref-method
  316. |void| **set_item_disabled**\ (\ idx\: :ref:`int<class_int>`, disabled\: :ref:`bool<class_bool>`\ ) :ref:`🔗<class_OptionButton_method_set_item_disabled>`
  317. Sets whether the item at index ``idx`` is disabled.
  318. 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.
  319. .. rst-class:: classref-item-separator
  320. ----
  321. .. _class_OptionButton_method_set_item_icon:
  322. .. rst-class:: classref-method
  323. |void| **set_item_icon**\ (\ idx\: :ref:`int<class_int>`, texture\: :ref:`Texture2D<class_Texture2D>`\ ) :ref:`🔗<class_OptionButton_method_set_item_icon>`
  324. Sets the icon of the item at index ``idx``.
  325. .. rst-class:: classref-item-separator
  326. ----
  327. .. _class_OptionButton_method_set_item_id:
  328. .. rst-class:: classref-method
  329. |void| **set_item_id**\ (\ idx\: :ref:`int<class_int>`, id\: :ref:`int<class_int>`\ ) :ref:`🔗<class_OptionButton_method_set_item_id>`
  330. Sets the ID of the item at index ``idx``.
  331. .. rst-class:: classref-item-separator
  332. ----
  333. .. _class_OptionButton_method_set_item_metadata:
  334. .. rst-class:: classref-method
  335. |void| **set_item_metadata**\ (\ idx\: :ref:`int<class_int>`, metadata\: :ref:`Variant<class_Variant>`\ ) :ref:`🔗<class_OptionButton_method_set_item_metadata>`
  336. 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.
  337. .. rst-class:: classref-item-separator
  338. ----
  339. .. _class_OptionButton_method_set_item_text:
  340. .. rst-class:: classref-method
  341. |void| **set_item_text**\ (\ idx\: :ref:`int<class_int>`, text\: :ref:`String<class_String>`\ ) :ref:`🔗<class_OptionButton_method_set_item_text>`
  342. Sets the text of the item at index ``idx``.
  343. .. rst-class:: classref-item-separator
  344. ----
  345. .. _class_OptionButton_method_set_item_tooltip:
  346. .. rst-class:: classref-method
  347. |void| **set_item_tooltip**\ (\ idx\: :ref:`int<class_int>`, tooltip\: :ref:`String<class_String>`\ ) :ref:`🔗<class_OptionButton_method_set_item_tooltip>`
  348. Sets the tooltip of the item at index ``idx``.
  349. .. rst-class:: classref-item-separator
  350. ----
  351. .. _class_OptionButton_method_show_popup:
  352. .. rst-class:: classref-method
  353. |void| **show_popup**\ (\ ) :ref:`🔗<class_OptionButton_method_show_popup>`
  354. Adjusts popup position and sizing for the **OptionButton**, then shows the :ref:`PopupMenu<class_PopupMenu>`. Prefer this over using ``get_popup().popup()``.
  355. .. rst-class:: classref-section-separator
  356. ----
  357. .. rst-class:: classref-descriptions-group
  358. Theme Property Descriptions
  359. ---------------------------
  360. .. _class_OptionButton_theme_constant_arrow_margin:
  361. .. rst-class:: classref-themeproperty
  362. :ref:`int<class_int>` **arrow_margin** = ``4`` :ref:`🔗<class_OptionButton_theme_constant_arrow_margin>`
  363. The horizontal space between the arrow icon and the right edge of the button.
  364. .. rst-class:: classref-item-separator
  365. ----
  366. .. _class_OptionButton_theme_constant_modulate_arrow:
  367. .. rst-class:: classref-themeproperty
  368. :ref:`int<class_int>` **modulate_arrow** = ``0`` :ref:`🔗<class_OptionButton_theme_constant_modulate_arrow>`
  369. If different than ``0``, the arrow icon will be modulated to the font color.
  370. .. rst-class:: classref-item-separator
  371. ----
  372. .. _class_OptionButton_theme_icon_arrow:
  373. .. rst-class:: classref-themeproperty
  374. :ref:`Texture2D<class_Texture2D>` **arrow** :ref:`🔗<class_OptionButton_theme_icon_arrow>`
  375. The arrow icon to be drawn on the right end of the button.
  376. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  377. .. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)`
  378. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  379. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  380. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  381. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  382. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  383. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
  384. .. |void| replace:: :abbr:`void (No return value.)`