class_optionbutton.rst 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/OptionButton.xml.
  6. .. _class_OptionButton:
  7. OptionButton
  8. ============
  9. **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>`
  10. Button control that provides selectable options when pressed.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. 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.
  15. See also :ref:`BaseButton<class_BaseButton>` which contains common properties and methods associated with this node.
  16. \ **Note:** Properties :ref:`Button.text<class_Button_property_text>` and :ref:`Button.icon<class_Button_property_icon>` are automatically set based on the selected item. They shouldn't be changed manually.
  17. \ **Note:** The ID values used for items are limited to 32 bits, not full 64 bits of :ref:`int<class_int>`. This has a range of ``-2^32`` to ``2^32 - 1``, i.e. ``-2147483648`` to ``2147483647``.
  18. .. rst-class:: classref-reftable-group
  19. Properties
  20. ----------
  21. .. table::
  22. :widths: auto
  23. +-------------------------------------------------------------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------+
  24. | :ref:`ActionMode<enum_BaseButton_ActionMode>` | action_mode | ``0`` (overrides :ref:`BaseButton<class_BaseButton_property_action_mode>`) |
  25. +-------------------------------------------------------------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------+
  26. | :ref:`HorizontalAlignment<enum_@GlobalScope_HorizontalAlignment>` | alignment | ``0`` (overrides :ref:`Button<class_Button_property_alignment>`) |
  27. +-------------------------------------------------------------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------+
  28. | :ref:`bool<class_bool>` | :ref:`allow_reselect<class_OptionButton_property_allow_reselect>` | ``false`` |
  29. +-------------------------------------------------------------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------+
  30. | :ref:`bool<class_bool>` | :ref:`fit_to_longest_item<class_OptionButton_property_fit_to_longest_item>` | ``true`` |
  31. +-------------------------------------------------------------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------+
  32. | :ref:`int<class_int>` | :ref:`item_count<class_OptionButton_property_item_count>` | ``0`` |
  33. +-------------------------------------------------------------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------+
  34. | :ref:`int<class_int>` | :ref:`selected<class_OptionButton_property_selected>` | ``-1`` |
  35. +-------------------------------------------------------------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------+
  36. | :ref:`bool<class_bool>` | toggle_mode | ``true`` (overrides :ref:`BaseButton<class_BaseButton_property_toggle_mode>`) |
  37. +-------------------------------------------------------------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------+
  38. .. rst-class:: classref-reftable-group
  39. Methods
  40. -------
  41. .. table::
  42. :widths: auto
  43. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  44. | void | :ref:`add_icon_item<class_OptionButton_method_add_icon_item>` **(** :ref:`Texture2D<class_Texture2D>` texture, :ref:`String<class_String>` label, :ref:`int<class_int>` id=-1 **)** |
  45. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  46. | void | :ref:`add_item<class_OptionButton_method_add_item>` **(** :ref:`String<class_String>` label, :ref:`int<class_int>` id=-1 **)** |
  47. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  48. | void | :ref:`add_separator<class_OptionButton_method_add_separator>` **(** :ref:`String<class_String>` text="" **)** |
  49. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  50. | void | :ref:`clear<class_OptionButton_method_clear>` **(** **)** |
  51. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  52. | :ref:`Texture2D<class_Texture2D>` | :ref:`get_item_icon<class_OptionButton_method_get_item_icon>` **(** :ref:`int<class_int>` idx **)** |const| |
  53. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  54. | :ref:`int<class_int>` | :ref:`get_item_id<class_OptionButton_method_get_item_id>` **(** :ref:`int<class_int>` idx **)** |const| |
  55. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  56. | :ref:`int<class_int>` | :ref:`get_item_index<class_OptionButton_method_get_item_index>` **(** :ref:`int<class_int>` id **)** |const| |
  57. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  58. | :ref:`Variant<class_Variant>` | :ref:`get_item_metadata<class_OptionButton_method_get_item_metadata>` **(** :ref:`int<class_int>` idx **)** |const| |
  59. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  60. | :ref:`String<class_String>` | :ref:`get_item_text<class_OptionButton_method_get_item_text>` **(** :ref:`int<class_int>` idx **)** |const| |
  61. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  62. | :ref:`String<class_String>` | :ref:`get_item_tooltip<class_OptionButton_method_get_item_tooltip>` **(** :ref:`int<class_int>` idx **)** |const| |
  63. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  64. | :ref:`PopupMenu<class_PopupMenu>` | :ref:`get_popup<class_OptionButton_method_get_popup>` **(** **)** |const| |
  65. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  66. | :ref:`int<class_int>` | :ref:`get_selectable_item<class_OptionButton_method_get_selectable_item>` **(** :ref:`bool<class_bool>` from_last=false **)** |const| |
  67. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  68. | :ref:`int<class_int>` | :ref:`get_selected_id<class_OptionButton_method_get_selected_id>` **(** **)** |const| |
  69. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  70. | :ref:`Variant<class_Variant>` | :ref:`get_selected_metadata<class_OptionButton_method_get_selected_metadata>` **(** **)** |const| |
  71. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  72. | :ref:`bool<class_bool>` | :ref:`has_selectable_items<class_OptionButton_method_has_selectable_items>` **(** **)** |const| |
  73. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  74. | :ref:`bool<class_bool>` | :ref:`is_item_disabled<class_OptionButton_method_is_item_disabled>` **(** :ref:`int<class_int>` idx **)** |const| |
  75. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  76. | :ref:`bool<class_bool>` | :ref:`is_item_separator<class_OptionButton_method_is_item_separator>` **(** :ref:`int<class_int>` idx **)** |const| |
  77. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  78. | void | :ref:`remove_item<class_OptionButton_method_remove_item>` **(** :ref:`int<class_int>` idx **)** |
  79. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  80. | void | :ref:`select<class_OptionButton_method_select>` **(** :ref:`int<class_int>` idx **)** |
  81. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  82. | void | :ref:`set_item_disabled<class_OptionButton_method_set_item_disabled>` **(** :ref:`int<class_int>` idx, :ref:`bool<class_bool>` disabled **)** |
  83. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  84. | void | :ref:`set_item_icon<class_OptionButton_method_set_item_icon>` **(** :ref:`int<class_int>` idx, :ref:`Texture2D<class_Texture2D>` texture **)** |
  85. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  86. | void | :ref:`set_item_id<class_OptionButton_method_set_item_id>` **(** :ref:`int<class_int>` idx, :ref:`int<class_int>` id **)** |
  87. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  88. | void | :ref:`set_item_metadata<class_OptionButton_method_set_item_metadata>` **(** :ref:`int<class_int>` idx, :ref:`Variant<class_Variant>` metadata **)** |
  89. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  90. | void | :ref:`set_item_text<class_OptionButton_method_set_item_text>` **(** :ref:`int<class_int>` idx, :ref:`String<class_String>` text **)** |
  91. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  92. | void | :ref:`set_item_tooltip<class_OptionButton_method_set_item_tooltip>` **(** :ref:`int<class_int>` idx, :ref:`String<class_String>` tooltip **)** |
  93. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  94. | void | :ref:`show_popup<class_OptionButton_method_show_popup>` **(** **)** |
  95. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  96. .. rst-class:: classref-reftable-group
  97. Theme Properties
  98. ----------------
  99. .. table::
  100. :widths: auto
  101. +-----------------------------------+------------------------------------------------------------------------------------------+-------------------------------------+
  102. | :ref:`Color<class_Color>` | :ref:`font_color<class_OptionButton_theme_color_font_color>` | ``Color(0.875, 0.875, 0.875, 1)`` |
  103. +-----------------------------------+------------------------------------------------------------------------------------------+-------------------------------------+
  104. | :ref:`Color<class_Color>` | :ref:`font_disabled_color<class_OptionButton_theme_color_font_disabled_color>` | ``Color(0.875, 0.875, 0.875, 0.5)`` |
  105. +-----------------------------------+------------------------------------------------------------------------------------------+-------------------------------------+
  106. | :ref:`Color<class_Color>` | :ref:`font_focus_color<class_OptionButton_theme_color_font_focus_color>` | ``Color(0.95, 0.95, 0.95, 1)`` |
  107. +-----------------------------------+------------------------------------------------------------------------------------------+-------------------------------------+
  108. | :ref:`Color<class_Color>` | :ref:`font_hover_color<class_OptionButton_theme_color_font_hover_color>` | ``Color(0.95, 0.95, 0.95, 1)`` |
  109. +-----------------------------------+------------------------------------------------------------------------------------------+-------------------------------------+
  110. | :ref:`Color<class_Color>` | :ref:`font_hover_pressed_color<class_OptionButton_theme_color_font_hover_pressed_color>` | ``Color(1, 1, 1, 1)`` |
  111. +-----------------------------------+------------------------------------------------------------------------------------------+-------------------------------------+
  112. | :ref:`Color<class_Color>` | :ref:`font_outline_color<class_OptionButton_theme_color_font_outline_color>` | ``Color(1, 1, 1, 1)`` |
  113. +-----------------------------------+------------------------------------------------------------------------------------------+-------------------------------------+
  114. | :ref:`Color<class_Color>` | :ref:`font_pressed_color<class_OptionButton_theme_color_font_pressed_color>` | ``Color(1, 1, 1, 1)`` |
  115. +-----------------------------------+------------------------------------------------------------------------------------------+-------------------------------------+
  116. | :ref:`int<class_int>` | :ref:`arrow_margin<class_OptionButton_theme_constant_arrow_margin>` | ``4`` |
  117. +-----------------------------------+------------------------------------------------------------------------------------------+-------------------------------------+
  118. | :ref:`int<class_int>` | :ref:`h_separation<class_OptionButton_theme_constant_h_separation>` | ``2`` |
  119. +-----------------------------------+------------------------------------------------------------------------------------------+-------------------------------------+
  120. | :ref:`int<class_int>` | :ref:`modulate_arrow<class_OptionButton_theme_constant_modulate_arrow>` | ``0`` |
  121. +-----------------------------------+------------------------------------------------------------------------------------------+-------------------------------------+
  122. | :ref:`int<class_int>` | :ref:`outline_size<class_OptionButton_theme_constant_outline_size>` | ``0`` |
  123. +-----------------------------------+------------------------------------------------------------------------------------------+-------------------------------------+
  124. | :ref:`Font<class_Font>` | :ref:`font<class_OptionButton_theme_font_font>` | |
  125. +-----------------------------------+------------------------------------------------------------------------------------------+-------------------------------------+
  126. | :ref:`int<class_int>` | :ref:`font_size<class_OptionButton_theme_font_size_font_size>` | |
  127. +-----------------------------------+------------------------------------------------------------------------------------------+-------------------------------------+
  128. | :ref:`Texture2D<class_Texture2D>` | :ref:`arrow<class_OptionButton_theme_icon_arrow>` | |
  129. +-----------------------------------+------------------------------------------------------------------------------------------+-------------------------------------+
  130. | :ref:`StyleBox<class_StyleBox>` | :ref:`disabled<class_OptionButton_theme_style_disabled>` | |
  131. +-----------------------------------+------------------------------------------------------------------------------------------+-------------------------------------+
  132. | :ref:`StyleBox<class_StyleBox>` | :ref:`disabled_mirrored<class_OptionButton_theme_style_disabled_mirrored>` | |
  133. +-----------------------------------+------------------------------------------------------------------------------------------+-------------------------------------+
  134. | :ref:`StyleBox<class_StyleBox>` | :ref:`focus<class_OptionButton_theme_style_focus>` | |
  135. +-----------------------------------+------------------------------------------------------------------------------------------+-------------------------------------+
  136. | :ref:`StyleBox<class_StyleBox>` | :ref:`hover<class_OptionButton_theme_style_hover>` | |
  137. +-----------------------------------+------------------------------------------------------------------------------------------+-------------------------------------+
  138. | :ref:`StyleBox<class_StyleBox>` | :ref:`hover_mirrored<class_OptionButton_theme_style_hover_mirrored>` | |
  139. +-----------------------------------+------------------------------------------------------------------------------------------+-------------------------------------+
  140. | :ref:`StyleBox<class_StyleBox>` | :ref:`normal<class_OptionButton_theme_style_normal>` | |
  141. +-----------------------------------+------------------------------------------------------------------------------------------+-------------------------------------+
  142. | :ref:`StyleBox<class_StyleBox>` | :ref:`normal_mirrored<class_OptionButton_theme_style_normal_mirrored>` | |
  143. +-----------------------------------+------------------------------------------------------------------------------------------+-------------------------------------+
  144. | :ref:`StyleBox<class_StyleBox>` | :ref:`pressed<class_OptionButton_theme_style_pressed>` | |
  145. +-----------------------------------+------------------------------------------------------------------------------------------+-------------------------------------+
  146. | :ref:`StyleBox<class_StyleBox>` | :ref:`pressed_mirrored<class_OptionButton_theme_style_pressed_mirrored>` | |
  147. +-----------------------------------+------------------------------------------------------------------------------------------+-------------------------------------+
  148. .. rst-class:: classref-section-separator
  149. ----
  150. .. rst-class:: classref-descriptions-group
  151. Signals
  152. -------
  153. .. _class_OptionButton_signal_item_focused:
  154. .. rst-class:: classref-signal
  155. **item_focused** **(** :ref:`int<class_int>` index **)**
  156. 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.
  157. .. rst-class:: classref-item-separator
  158. ----
  159. .. _class_OptionButton_signal_item_selected:
  160. .. rst-class:: classref-signal
  161. **item_selected** **(** :ref:`int<class_int>` index **)**
  162. Emitted when the current item has been changed by the user. The index of the item selected is passed as argument.
  163. \ :ref:`allow_reselect<class_OptionButton_property_allow_reselect>` must be enabled to reselect an item.
  164. .. rst-class:: classref-section-separator
  165. ----
  166. .. rst-class:: classref-descriptions-group
  167. Property Descriptions
  168. ---------------------
  169. .. _class_OptionButton_property_allow_reselect:
  170. .. rst-class:: classref-property
  171. :ref:`bool<class_bool>` **allow_reselect** = ``false``
  172. .. rst-class:: classref-property-setget
  173. - void **set_allow_reselect** **(** :ref:`bool<class_bool>` value **)**
  174. - :ref:`bool<class_bool>` **get_allow_reselect** **(** **)**
  175. If ``true``, the currently selected item can be selected again.
  176. .. rst-class:: classref-item-separator
  177. ----
  178. .. _class_OptionButton_property_fit_to_longest_item:
  179. .. rst-class:: classref-property
  180. :ref:`bool<class_bool>` **fit_to_longest_item** = ``true``
  181. .. rst-class:: classref-property-setget
  182. - void **set_fit_to_longest_item** **(** :ref:`bool<class_bool>` value **)**
  183. - :ref:`bool<class_bool>` **is_fit_to_longest_item** **(** **)**
  184. If ``true``, minimum size will be determined by the longest item's text, instead of the currently selected one's.
  185. \ **Note:** For performance reasons, the minimum size doesn't update immediately when adding, removing or modifying items.
  186. .. rst-class:: classref-item-separator
  187. ----
  188. .. _class_OptionButton_property_item_count:
  189. .. rst-class:: classref-property
  190. :ref:`int<class_int>` **item_count** = ``0``
  191. .. rst-class:: classref-property-setget
  192. - void **set_item_count** **(** :ref:`int<class_int>` value **)**
  193. - :ref:`int<class_int>` **get_item_count** **(** **)**
  194. The number of items to select from.
  195. .. rst-class:: classref-item-separator
  196. ----
  197. .. _class_OptionButton_property_selected:
  198. .. rst-class:: classref-property
  199. :ref:`int<class_int>` **selected** = ``-1``
  200. .. rst-class:: classref-property-setget
  201. - :ref:`int<class_int>` **get_selected** **(** **)**
  202. The index of the currently selected item, or ``-1`` if no item is selected.
  203. .. rst-class:: classref-section-separator
  204. ----
  205. .. rst-class:: classref-descriptions-group
  206. Method Descriptions
  207. -------------------
  208. .. _class_OptionButton_method_add_icon_item:
  209. .. rst-class:: classref-method
  210. void **add_icon_item** **(** :ref:`Texture2D<class_Texture2D>` texture, :ref:`String<class_String>` label, :ref:`int<class_int>` id=-1 **)**
  211. 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.
  212. .. rst-class:: classref-item-separator
  213. ----
  214. .. _class_OptionButton_method_add_item:
  215. .. rst-class:: classref-method
  216. void **add_item** **(** :ref:`String<class_String>` label, :ref:`int<class_int>` id=-1 **)**
  217. 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.
  218. .. rst-class:: classref-item-separator
  219. ----
  220. .. _class_OptionButton_method_add_separator:
  221. .. rst-class:: classref-method
  222. void **add_separator** **(** :ref:`String<class_String>` text="" **)**
  223. 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.
  224. .. rst-class:: classref-item-separator
  225. ----
  226. .. _class_OptionButton_method_clear:
  227. .. rst-class:: classref-method
  228. void **clear** **(** **)**
  229. Clears all the items in the **OptionButton**.
  230. .. rst-class:: classref-item-separator
  231. ----
  232. .. _class_OptionButton_method_get_item_icon:
  233. .. rst-class:: classref-method
  234. :ref:`Texture2D<class_Texture2D>` **get_item_icon** **(** :ref:`int<class_int>` idx **)** |const|
  235. Returns the icon of the item at index ``idx``.
  236. .. rst-class:: classref-item-separator
  237. ----
  238. .. _class_OptionButton_method_get_item_id:
  239. .. rst-class:: classref-method
  240. :ref:`int<class_int>` **get_item_id** **(** :ref:`int<class_int>` idx **)** |const|
  241. Returns the ID of the item at index ``idx``.
  242. .. rst-class:: classref-item-separator
  243. ----
  244. .. _class_OptionButton_method_get_item_index:
  245. .. rst-class:: classref-method
  246. :ref:`int<class_int>` **get_item_index** **(** :ref:`int<class_int>` id **)** |const|
  247. Returns the index of the item with the given ``id``.
  248. .. rst-class:: classref-item-separator
  249. ----
  250. .. _class_OptionButton_method_get_item_metadata:
  251. .. rst-class:: classref-method
  252. :ref:`Variant<class_Variant>` **get_item_metadata** **(** :ref:`int<class_int>` idx **)** |const|
  253. 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.
  254. .. rst-class:: classref-item-separator
  255. ----
  256. .. _class_OptionButton_method_get_item_text:
  257. .. rst-class:: classref-method
  258. :ref:`String<class_String>` **get_item_text** **(** :ref:`int<class_int>` idx **)** |const|
  259. Returns the text of the item at index ``idx``.
  260. .. rst-class:: classref-item-separator
  261. ----
  262. .. _class_OptionButton_method_get_item_tooltip:
  263. .. rst-class:: classref-method
  264. :ref:`String<class_String>` **get_item_tooltip** **(** :ref:`int<class_int>` idx **)** |const|
  265. Returns the tooltip of the item at index ``idx``.
  266. .. rst-class:: classref-item-separator
  267. ----
  268. .. _class_OptionButton_method_get_popup:
  269. .. rst-class:: classref-method
  270. :ref:`PopupMenu<class_PopupMenu>` **get_popup** **(** **)** |const|
  271. Returns the :ref:`PopupMenu<class_PopupMenu>` contained in this button.
  272. \ **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.
  273. .. rst-class:: classref-item-separator
  274. ----
  275. .. _class_OptionButton_method_get_selectable_item:
  276. .. rst-class:: classref-method
  277. :ref:`int<class_int>` **get_selectable_item** **(** :ref:`bool<class_bool>` from_last=false **)** |const|
  278. 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.
  279. Returns ``-1`` if no item is found.
  280. .. rst-class:: classref-item-separator
  281. ----
  282. .. _class_OptionButton_method_get_selected_id:
  283. .. rst-class:: classref-method
  284. :ref:`int<class_int>` **get_selected_id** **(** **)** |const|
  285. Returns the ID of the selected item, or ``-1`` if no item is selected.
  286. .. rst-class:: classref-item-separator
  287. ----
  288. .. _class_OptionButton_method_get_selected_metadata:
  289. .. rst-class:: classref-method
  290. :ref:`Variant<class_Variant>` **get_selected_metadata** **(** **)** |const|
  291. Gets the metadata of the selected item. Metadata for items can be set using :ref:`set_item_metadata<class_OptionButton_method_set_item_metadata>`.
  292. .. rst-class:: classref-item-separator
  293. ----
  294. .. _class_OptionButton_method_has_selectable_items:
  295. .. rst-class:: classref-method
  296. :ref:`bool<class_bool>` **has_selectable_items** **(** **)** |const|
  297. Returns ``true`` if this button contains at least one item which is not disabled, or marked as a separator.
  298. .. rst-class:: classref-item-separator
  299. ----
  300. .. _class_OptionButton_method_is_item_disabled:
  301. .. rst-class:: classref-method
  302. :ref:`bool<class_bool>` **is_item_disabled** **(** :ref:`int<class_int>` idx **)** |const|
  303. Returns ``true`` if the item at index ``idx`` is disabled.
  304. .. rst-class:: classref-item-separator
  305. ----
  306. .. _class_OptionButton_method_is_item_separator:
  307. .. rst-class:: classref-method
  308. :ref:`bool<class_bool>` **is_item_separator** **(** :ref:`int<class_int>` idx **)** |const|
  309. Returns ``true`` if the item at index ``idx`` is marked as a separator.
  310. .. rst-class:: classref-item-separator
  311. ----
  312. .. _class_OptionButton_method_remove_item:
  313. .. rst-class:: classref-method
  314. void **remove_item** **(** :ref:`int<class_int>` idx **)**
  315. Removes the item at index ``idx``.
  316. .. rst-class:: classref-item-separator
  317. ----
  318. .. _class_OptionButton_method_select:
  319. .. rst-class:: classref-method
  320. void **select** **(** :ref:`int<class_int>` idx **)**
  321. Selects an item by index and makes it the current item. This will work even if the item is disabled.
  322. Passing ``-1`` as the index deselects any currently selected item.
  323. .. rst-class:: classref-item-separator
  324. ----
  325. .. _class_OptionButton_method_set_item_disabled:
  326. .. rst-class:: classref-method
  327. void **set_item_disabled** **(** :ref:`int<class_int>` idx, :ref:`bool<class_bool>` disabled **)**
  328. Sets whether the item at index ``idx`` is disabled.
  329. 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.
  330. .. rst-class:: classref-item-separator
  331. ----
  332. .. _class_OptionButton_method_set_item_icon:
  333. .. rst-class:: classref-method
  334. void **set_item_icon** **(** :ref:`int<class_int>` idx, :ref:`Texture2D<class_Texture2D>` texture **)**
  335. Sets the icon of the item at index ``idx``.
  336. .. rst-class:: classref-item-separator
  337. ----
  338. .. _class_OptionButton_method_set_item_id:
  339. .. rst-class:: classref-method
  340. void **set_item_id** **(** :ref:`int<class_int>` idx, :ref:`int<class_int>` id **)**
  341. Sets the ID of the item at index ``idx``.
  342. .. rst-class:: classref-item-separator
  343. ----
  344. .. _class_OptionButton_method_set_item_metadata:
  345. .. rst-class:: classref-method
  346. void **set_item_metadata** **(** :ref:`int<class_int>` idx, :ref:`Variant<class_Variant>` metadata **)**
  347. 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.
  348. .. rst-class:: classref-item-separator
  349. ----
  350. .. _class_OptionButton_method_set_item_text:
  351. .. rst-class:: classref-method
  352. void **set_item_text** **(** :ref:`int<class_int>` idx, :ref:`String<class_String>` text **)**
  353. Sets the text of the item at index ``idx``.
  354. .. rst-class:: classref-item-separator
  355. ----
  356. .. _class_OptionButton_method_set_item_tooltip:
  357. .. rst-class:: classref-method
  358. void **set_item_tooltip** **(** :ref:`int<class_int>` idx, :ref:`String<class_String>` tooltip **)**
  359. Sets the tooltip of the item at index ``idx``.
  360. .. rst-class:: classref-item-separator
  361. ----
  362. .. _class_OptionButton_method_show_popup:
  363. .. rst-class:: classref-method
  364. void **show_popup** **(** **)**
  365. Adjusts popup position and sizing for the **OptionButton**, then shows the :ref:`PopupMenu<class_PopupMenu>`. Prefer this over using ``get_popup().popup()``.
  366. .. rst-class:: classref-section-separator
  367. ----
  368. .. rst-class:: classref-descriptions-group
  369. Theme Property Descriptions
  370. ---------------------------
  371. .. _class_OptionButton_theme_color_font_color:
  372. .. rst-class:: classref-themeproperty
  373. :ref:`Color<class_Color>` **font_color** = ``Color(0.875, 0.875, 0.875, 1)``
  374. Default text :ref:`Color<class_Color>` of the **OptionButton**.
  375. .. rst-class:: classref-item-separator
  376. ----
  377. .. _class_OptionButton_theme_color_font_disabled_color:
  378. .. rst-class:: classref-themeproperty
  379. :ref:`Color<class_Color>` **font_disabled_color** = ``Color(0.875, 0.875, 0.875, 0.5)``
  380. Text :ref:`Color<class_Color>` used when the **OptionButton** is disabled.
  381. .. rst-class:: classref-item-separator
  382. ----
  383. .. _class_OptionButton_theme_color_font_focus_color:
  384. .. rst-class:: classref-themeproperty
  385. :ref:`Color<class_Color>` **font_focus_color** = ``Color(0.95, 0.95, 0.95, 1)``
  386. Text :ref:`Color<class_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.
  387. .. rst-class:: classref-item-separator
  388. ----
  389. .. _class_OptionButton_theme_color_font_hover_color:
  390. .. rst-class:: classref-themeproperty
  391. :ref:`Color<class_Color>` **font_hover_color** = ``Color(0.95, 0.95, 0.95, 1)``
  392. Text :ref:`Color<class_Color>` used when the **OptionButton** is being hovered.
  393. .. rst-class:: classref-item-separator
  394. ----
  395. .. _class_OptionButton_theme_color_font_hover_pressed_color:
  396. .. rst-class:: classref-themeproperty
  397. :ref:`Color<class_Color>` **font_hover_pressed_color** = ``Color(1, 1, 1, 1)``
  398. Text :ref:`Color<class_Color>` used when the **OptionButton** is being hovered and pressed.
  399. .. rst-class:: classref-item-separator
  400. ----
  401. .. _class_OptionButton_theme_color_font_outline_color:
  402. .. rst-class:: classref-themeproperty
  403. :ref:`Color<class_Color>` **font_outline_color** = ``Color(1, 1, 1, 1)``
  404. The tint of text outline of the **OptionButton**.
  405. .. rst-class:: classref-item-separator
  406. ----
  407. .. _class_OptionButton_theme_color_font_pressed_color:
  408. .. rst-class:: classref-themeproperty
  409. :ref:`Color<class_Color>` **font_pressed_color** = ``Color(1, 1, 1, 1)``
  410. Text :ref:`Color<class_Color>` used when the **OptionButton** is being pressed.
  411. .. rst-class:: classref-item-separator
  412. ----
  413. .. _class_OptionButton_theme_constant_arrow_margin:
  414. .. rst-class:: classref-themeproperty
  415. :ref:`int<class_int>` **arrow_margin** = ``4``
  416. The horizontal space between the arrow icon and the right edge of the button.
  417. .. rst-class:: classref-item-separator
  418. ----
  419. .. _class_OptionButton_theme_constant_h_separation:
  420. .. rst-class:: classref-themeproperty
  421. :ref:`int<class_int>` **h_separation** = ``2``
  422. The horizontal space between **OptionButton**'s icon and text. Negative values will be treated as ``0`` when used.
  423. .. rst-class:: classref-item-separator
  424. ----
  425. .. _class_OptionButton_theme_constant_modulate_arrow:
  426. .. rst-class:: classref-themeproperty
  427. :ref:`int<class_int>` **modulate_arrow** = ``0``
  428. If different than ``0``, the arrow icon will be modulated to the font color.
  429. .. rst-class:: classref-item-separator
  430. ----
  431. .. _class_OptionButton_theme_constant_outline_size:
  432. .. rst-class:: classref-themeproperty
  433. :ref:`int<class_int>` **outline_size** = ``0``
  434. The size of the text outline.
  435. \ **Note:** If using a font with :ref:`FontFile.multichannel_signed_distance_field<class_FontFile_property_multichannel_signed_distance_field>` enabled, its :ref:`FontFile.msdf_pixel_range<class_FontFile_property_msdf_pixel_range>` must be set to at least *twice* the value of :ref:`outline_size<class_OptionButton_theme_constant_outline_size>` for outline rendering to look correct. Otherwise, the outline may appear to be cut off earlier than intended.
  436. .. rst-class:: classref-item-separator
  437. ----
  438. .. _class_OptionButton_theme_font_font:
  439. .. rst-class:: classref-themeproperty
  440. :ref:`Font<class_Font>` **font**
  441. :ref:`Font<class_Font>` of the **OptionButton**'s text.
  442. .. rst-class:: classref-item-separator
  443. ----
  444. .. _class_OptionButton_theme_font_size_font_size:
  445. .. rst-class:: classref-themeproperty
  446. :ref:`int<class_int>` **font_size**
  447. Font size of the **OptionButton**'s text.
  448. .. rst-class:: classref-item-separator
  449. ----
  450. .. _class_OptionButton_theme_icon_arrow:
  451. .. rst-class:: classref-themeproperty
  452. :ref:`Texture2D<class_Texture2D>` **arrow**
  453. The arrow icon to be drawn on the right end of the button.
  454. .. rst-class:: classref-item-separator
  455. ----
  456. .. _class_OptionButton_theme_style_disabled:
  457. .. rst-class:: classref-themeproperty
  458. :ref:`StyleBox<class_StyleBox>` **disabled**
  459. :ref:`StyleBox<class_StyleBox>` used when the **OptionButton** is disabled (for left-to-right layouts).
  460. .. rst-class:: classref-item-separator
  461. ----
  462. .. _class_OptionButton_theme_style_disabled_mirrored:
  463. .. rst-class:: classref-themeproperty
  464. :ref:`StyleBox<class_StyleBox>` **disabled_mirrored**
  465. :ref:`StyleBox<class_StyleBox>` used when the **OptionButton** is disabled (for right-to-left layouts).
  466. .. rst-class:: classref-item-separator
  467. ----
  468. .. _class_OptionButton_theme_style_focus:
  469. .. rst-class:: classref-themeproperty
  470. :ref:`StyleBox<class_StyleBox>` **focus**
  471. :ref:`StyleBox<class_StyleBox>` used when the **OptionButton** is focused. The ``focus`` :ref:`StyleBox<class_StyleBox>` is displayed *over* the base :ref:`StyleBox<class_StyleBox>`, so a partially transparent :ref:`StyleBox<class_StyleBox>` should be used to ensure the base :ref:`StyleBox<class_StyleBox>` remains visible. A :ref:`StyleBox<class_StyleBox>` that represents an outline or an underline works well for this purpose. To disable the focus visual effect, assign a :ref:`StyleBoxEmpty<class_StyleBoxEmpty>` resource. Note that disabling the focus visual effect will harm keyboard/controller navigation usability, so this is not recommended for accessibility reasons.
  472. .. rst-class:: classref-item-separator
  473. ----
  474. .. _class_OptionButton_theme_style_hover:
  475. .. rst-class:: classref-themeproperty
  476. :ref:`StyleBox<class_StyleBox>` **hover**
  477. :ref:`StyleBox<class_StyleBox>` used when the **OptionButton** is being hovered (for left-to-right layouts).
  478. .. rst-class:: classref-item-separator
  479. ----
  480. .. _class_OptionButton_theme_style_hover_mirrored:
  481. .. rst-class:: classref-themeproperty
  482. :ref:`StyleBox<class_StyleBox>` **hover_mirrored**
  483. :ref:`StyleBox<class_StyleBox>` used when the **OptionButton** is being hovered (for right-to-left layouts).
  484. .. rst-class:: classref-item-separator
  485. ----
  486. .. _class_OptionButton_theme_style_normal:
  487. .. rst-class:: classref-themeproperty
  488. :ref:`StyleBox<class_StyleBox>` **normal**
  489. Default :ref:`StyleBox<class_StyleBox>` for the **OptionButton** (for left-to-right layouts).
  490. .. rst-class:: classref-item-separator
  491. ----
  492. .. _class_OptionButton_theme_style_normal_mirrored:
  493. .. rst-class:: classref-themeproperty
  494. :ref:`StyleBox<class_StyleBox>` **normal_mirrored**
  495. Default :ref:`StyleBox<class_StyleBox>` for the **OptionButton** (for right-to-left layouts).
  496. .. rst-class:: classref-item-separator
  497. ----
  498. .. _class_OptionButton_theme_style_pressed:
  499. .. rst-class:: classref-themeproperty
  500. :ref:`StyleBox<class_StyleBox>` **pressed**
  501. :ref:`StyleBox<class_StyleBox>` used when the **OptionButton** is being pressed (for left-to-right layouts).
  502. .. rst-class:: classref-item-separator
  503. ----
  504. .. _class_OptionButton_theme_style_pressed_mirrored:
  505. .. rst-class:: classref-themeproperty
  506. :ref:`StyleBox<class_StyleBox>` **pressed_mirrored**
  507. :ref:`StyleBox<class_StyleBox>` used when the **OptionButton** is being pressed (for right-to-left layouts).
  508. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  509. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  510. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  511. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  512. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  513. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`