class_optionbutton.rst 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871
  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. .. rst-class:: classref-reftable-group
  18. Properties
  19. ----------
  20. .. table::
  21. :widths: auto
  22. +-------------------------------------------------------------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------+
  23. | :ref:`ActionMode<enum_BaseButton_ActionMode>` | action_mode | ``0`` (overrides :ref:`BaseButton<class_BaseButton_property_action_mode>`) |
  24. +-------------------------------------------------------------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------+
  25. | :ref:`HorizontalAlignment<enum_@GlobalScope_HorizontalAlignment>` | alignment | ``0`` (overrides :ref:`Button<class_Button_property_alignment>`) |
  26. +-------------------------------------------------------------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------+
  27. | :ref:`bool<class_bool>` | :ref:`fit_to_longest_item<class_OptionButton_property_fit_to_longest_item>` | ``true`` |
  28. +-------------------------------------------------------------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------+
  29. | :ref:`int<class_int>` | :ref:`item_count<class_OptionButton_property_item_count>` | ``0`` |
  30. +-------------------------------------------------------------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------+
  31. | :ref:`int<class_int>` | :ref:`selected<class_OptionButton_property_selected>` | ``-1`` |
  32. +-------------------------------------------------------------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------+
  33. | :ref:`bool<class_bool>` | toggle_mode | ``true`` (overrides :ref:`BaseButton<class_BaseButton_property_toggle_mode>`) |
  34. +-------------------------------------------------------------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------+
  35. .. rst-class:: classref-reftable-group
  36. Methods
  37. -------
  38. .. table::
  39. :widths: auto
  40. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  41. | 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 **)** |
  42. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | void | :ref:`add_item<class_OptionButton_method_add_item>` **(** :ref:`String<class_String>` label, :ref:`int<class_int>` id=-1 **)** |
  44. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | void | :ref:`add_separator<class_OptionButton_method_add_separator>` **(** :ref:`String<class_String>` text="" **)** |
  46. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | void | :ref:`clear<class_OptionButton_method_clear>` **(** **)** |
  48. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | :ref:`Texture2D<class_Texture2D>` | :ref:`get_item_icon<class_OptionButton_method_get_item_icon>` **(** :ref:`int<class_int>` idx **)** |const| |
  50. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | :ref:`int<class_int>` | :ref:`get_item_id<class_OptionButton_method_get_item_id>` **(** :ref:`int<class_int>` idx **)** |const| |
  52. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | :ref:`int<class_int>` | :ref:`get_item_index<class_OptionButton_method_get_item_index>` **(** :ref:`int<class_int>` id **)** |const| |
  54. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | :ref:`Variant<class_Variant>` | :ref:`get_item_metadata<class_OptionButton_method_get_item_metadata>` **(** :ref:`int<class_int>` idx **)** |const| |
  56. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | :ref:`String<class_String>` | :ref:`get_item_text<class_OptionButton_method_get_item_text>` **(** :ref:`int<class_int>` idx **)** |const| |
  58. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  59. | :ref:`String<class_String>` | :ref:`get_item_tooltip<class_OptionButton_method_get_item_tooltip>` **(** :ref:`int<class_int>` idx **)** |const| |
  60. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  61. | :ref:`PopupMenu<class_PopupMenu>` | :ref:`get_popup<class_OptionButton_method_get_popup>` **(** **)** |const| |
  62. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  63. | :ref:`int<class_int>` | :ref:`get_selectable_item<class_OptionButton_method_get_selectable_item>` **(** :ref:`bool<class_bool>` from_last=false **)** |const| |
  64. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  65. | :ref:`int<class_int>` | :ref:`get_selected_id<class_OptionButton_method_get_selected_id>` **(** **)** |const| |
  66. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  67. | :ref:`Variant<class_Variant>` | :ref:`get_selected_metadata<class_OptionButton_method_get_selected_metadata>` **(** **)** |const| |
  68. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  69. | :ref:`bool<class_bool>` | :ref:`has_selectable_items<class_OptionButton_method_has_selectable_items>` **(** **)** |const| |
  70. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  71. | :ref:`bool<class_bool>` | :ref:`is_item_disabled<class_OptionButton_method_is_item_disabled>` **(** :ref:`int<class_int>` idx **)** |const| |
  72. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  73. | :ref:`bool<class_bool>` | :ref:`is_item_separator<class_OptionButton_method_is_item_separator>` **(** :ref:`int<class_int>` idx **)** |const| |
  74. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  75. | void | :ref:`remove_item<class_OptionButton_method_remove_item>` **(** :ref:`int<class_int>` idx **)** |
  76. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  77. | void | :ref:`select<class_OptionButton_method_select>` **(** :ref:`int<class_int>` idx **)** |
  78. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  79. | void | :ref:`set_item_disabled<class_OptionButton_method_set_item_disabled>` **(** :ref:`int<class_int>` idx, :ref:`bool<class_bool>` disabled **)** |
  80. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  81. | void | :ref:`set_item_icon<class_OptionButton_method_set_item_icon>` **(** :ref:`int<class_int>` idx, :ref:`Texture2D<class_Texture2D>` texture **)** |
  82. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  83. | void | :ref:`set_item_id<class_OptionButton_method_set_item_id>` **(** :ref:`int<class_int>` idx, :ref:`int<class_int>` id **)** |
  84. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  85. | void | :ref:`set_item_metadata<class_OptionButton_method_set_item_metadata>` **(** :ref:`int<class_int>` idx, :ref:`Variant<class_Variant>` metadata **)** |
  86. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  87. | void | :ref:`set_item_text<class_OptionButton_method_set_item_text>` **(** :ref:`int<class_int>` idx, :ref:`String<class_String>` text **)** |
  88. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  89. | void | :ref:`set_item_tooltip<class_OptionButton_method_set_item_tooltip>` **(** :ref:`int<class_int>` idx, :ref:`String<class_String>` tooltip **)** |
  90. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  91. | void | :ref:`show_popup<class_OptionButton_method_show_popup>` **(** **)** |
  92. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  93. .. rst-class:: classref-reftable-group
  94. Theme Properties
  95. ----------------
  96. .. table::
  97. :widths: auto
  98. +-----------------------------------+------------------------------------------------------------------------------------------+-------------------------------------+
  99. | :ref:`Color<class_Color>` | :ref:`font_color<class_OptionButton_theme_color_font_color>` | ``Color(0.875, 0.875, 0.875, 1)`` |
  100. +-----------------------------------+------------------------------------------------------------------------------------------+-------------------------------------+
  101. | :ref:`Color<class_Color>` | :ref:`font_disabled_color<class_OptionButton_theme_color_font_disabled_color>` | ``Color(0.875, 0.875, 0.875, 0.5)`` |
  102. +-----------------------------------+------------------------------------------------------------------------------------------+-------------------------------------+
  103. | :ref:`Color<class_Color>` | :ref:`font_focus_color<class_OptionButton_theme_color_font_focus_color>` | ``Color(0.95, 0.95, 0.95, 1)`` |
  104. +-----------------------------------+------------------------------------------------------------------------------------------+-------------------------------------+
  105. | :ref:`Color<class_Color>` | :ref:`font_hover_color<class_OptionButton_theme_color_font_hover_color>` | ``Color(0.95, 0.95, 0.95, 1)`` |
  106. +-----------------------------------+------------------------------------------------------------------------------------------+-------------------------------------+
  107. | :ref:`Color<class_Color>` | :ref:`font_hover_pressed_color<class_OptionButton_theme_color_font_hover_pressed_color>` | ``Color(1, 1, 1, 1)`` |
  108. +-----------------------------------+------------------------------------------------------------------------------------------+-------------------------------------+
  109. | :ref:`Color<class_Color>` | :ref:`font_outline_color<class_OptionButton_theme_color_font_outline_color>` | ``Color(1, 1, 1, 1)`` |
  110. +-----------------------------------+------------------------------------------------------------------------------------------+-------------------------------------+
  111. | :ref:`Color<class_Color>` | :ref:`font_pressed_color<class_OptionButton_theme_color_font_pressed_color>` | ``Color(1, 1, 1, 1)`` |
  112. +-----------------------------------+------------------------------------------------------------------------------------------+-------------------------------------+
  113. | :ref:`int<class_int>` | :ref:`arrow_margin<class_OptionButton_theme_constant_arrow_margin>` | ``4`` |
  114. +-----------------------------------+------------------------------------------------------------------------------------------+-------------------------------------+
  115. | :ref:`int<class_int>` | :ref:`h_separation<class_OptionButton_theme_constant_h_separation>` | ``2`` |
  116. +-----------------------------------+------------------------------------------------------------------------------------------+-------------------------------------+
  117. | :ref:`int<class_int>` | :ref:`modulate_arrow<class_OptionButton_theme_constant_modulate_arrow>` | ``0`` |
  118. +-----------------------------------+------------------------------------------------------------------------------------------+-------------------------------------+
  119. | :ref:`int<class_int>` | :ref:`outline_size<class_OptionButton_theme_constant_outline_size>` | ``0`` |
  120. +-----------------------------------+------------------------------------------------------------------------------------------+-------------------------------------+
  121. | :ref:`Font<class_Font>` | :ref:`font<class_OptionButton_theme_font_font>` | |
  122. +-----------------------------------+------------------------------------------------------------------------------------------+-------------------------------------+
  123. | :ref:`int<class_int>` | :ref:`font_size<class_OptionButton_theme_font_size_font_size>` | |
  124. +-----------------------------------+------------------------------------------------------------------------------------------+-------------------------------------+
  125. | :ref:`Texture2D<class_Texture2D>` | :ref:`arrow<class_OptionButton_theme_icon_arrow>` | |
  126. +-----------------------------------+------------------------------------------------------------------------------------------+-------------------------------------+
  127. | :ref:`StyleBox<class_StyleBox>` | :ref:`disabled<class_OptionButton_theme_style_disabled>` | |
  128. +-----------------------------------+------------------------------------------------------------------------------------------+-------------------------------------+
  129. | :ref:`StyleBox<class_StyleBox>` | :ref:`disabled_mirrored<class_OptionButton_theme_style_disabled_mirrored>` | |
  130. +-----------------------------------+------------------------------------------------------------------------------------------+-------------------------------------+
  131. | :ref:`StyleBox<class_StyleBox>` | :ref:`focus<class_OptionButton_theme_style_focus>` | |
  132. +-----------------------------------+------------------------------------------------------------------------------------------+-------------------------------------+
  133. | :ref:`StyleBox<class_StyleBox>` | :ref:`hover<class_OptionButton_theme_style_hover>` | |
  134. +-----------------------------------+------------------------------------------------------------------------------------------+-------------------------------------+
  135. | :ref:`StyleBox<class_StyleBox>` | :ref:`hover_mirrored<class_OptionButton_theme_style_hover_mirrored>` | |
  136. +-----------------------------------+------------------------------------------------------------------------------------------+-------------------------------------+
  137. | :ref:`StyleBox<class_StyleBox>` | :ref:`normal<class_OptionButton_theme_style_normal>` | |
  138. +-----------------------------------+------------------------------------------------------------------------------------------+-------------------------------------+
  139. | :ref:`StyleBox<class_StyleBox>` | :ref:`normal_mirrored<class_OptionButton_theme_style_normal_mirrored>` | |
  140. +-----------------------------------+------------------------------------------------------------------------------------------+-------------------------------------+
  141. | :ref:`StyleBox<class_StyleBox>` | :ref:`pressed<class_OptionButton_theme_style_pressed>` | |
  142. +-----------------------------------+------------------------------------------------------------------------------------------+-------------------------------------+
  143. | :ref:`StyleBox<class_StyleBox>` | :ref:`pressed_mirrored<class_OptionButton_theme_style_pressed_mirrored>` | |
  144. +-----------------------------------+------------------------------------------------------------------------------------------+-------------------------------------+
  145. .. rst-class:: classref-section-separator
  146. ----
  147. .. rst-class:: classref-descriptions-group
  148. Signals
  149. -------
  150. .. _class_OptionButton_signal_item_focused:
  151. .. rst-class:: classref-signal
  152. **item_focused** **(** :ref:`int<class_int>` index **)**
  153. 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.
  154. .. rst-class:: classref-item-separator
  155. ----
  156. .. _class_OptionButton_signal_item_selected:
  157. .. rst-class:: classref-signal
  158. **item_selected** **(** :ref:`int<class_int>` index **)**
  159. Emitted when the current item has been changed by the user. The index of the item selected is passed as argument.
  160. .. rst-class:: classref-section-separator
  161. ----
  162. .. rst-class:: classref-descriptions-group
  163. Property Descriptions
  164. ---------------------
  165. .. _class_OptionButton_property_fit_to_longest_item:
  166. .. rst-class:: classref-property
  167. :ref:`bool<class_bool>` **fit_to_longest_item** = ``true``
  168. .. rst-class:: classref-property-setget
  169. - void **set_fit_to_longest_item** **(** :ref:`bool<class_bool>` value **)**
  170. - :ref:`bool<class_bool>` **is_fit_to_longest_item** **(** **)**
  171. If ``true``, minimum size will be determined by the longest item's text, instead of the currently selected one's.
  172. \ **Note:** For performance reasons, the minimum size doesn't update immediately when adding, removing or modifying items.
  173. .. rst-class:: classref-item-separator
  174. ----
  175. .. _class_OptionButton_property_item_count:
  176. .. rst-class:: classref-property
  177. :ref:`int<class_int>` **item_count** = ``0``
  178. .. rst-class:: classref-property-setget
  179. - void **set_item_count** **(** :ref:`int<class_int>` value **)**
  180. - :ref:`int<class_int>` **get_item_count** **(** **)**
  181. The number of items to select from.
  182. .. rst-class:: classref-item-separator
  183. ----
  184. .. _class_OptionButton_property_selected:
  185. .. rst-class:: classref-property
  186. :ref:`int<class_int>` **selected** = ``-1``
  187. .. rst-class:: classref-property-setget
  188. - :ref:`int<class_int>` **get_selected** **(** **)**
  189. The index of the currently selected item, or ``-1`` if no item is selected.
  190. .. rst-class:: classref-section-separator
  191. ----
  192. .. rst-class:: classref-descriptions-group
  193. Method Descriptions
  194. -------------------
  195. .. _class_OptionButton_method_add_icon_item:
  196. .. rst-class:: classref-method
  197. void **add_icon_item** **(** :ref:`Texture2D<class_Texture2D>` texture, :ref:`String<class_String>` label, :ref:`int<class_int>` id=-1 **)**
  198. 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.
  199. .. rst-class:: classref-item-separator
  200. ----
  201. .. _class_OptionButton_method_add_item:
  202. .. rst-class:: classref-method
  203. void **add_item** **(** :ref:`String<class_String>` label, :ref:`int<class_int>` id=-1 **)**
  204. 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.
  205. .. rst-class:: classref-item-separator
  206. ----
  207. .. _class_OptionButton_method_add_separator:
  208. .. rst-class:: classref-method
  209. void **add_separator** **(** :ref:`String<class_String>` text="" **)**
  210. 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.
  211. .. rst-class:: classref-item-separator
  212. ----
  213. .. _class_OptionButton_method_clear:
  214. .. rst-class:: classref-method
  215. void **clear** **(** **)**
  216. Clears all the items in the **OptionButton**.
  217. .. rst-class:: classref-item-separator
  218. ----
  219. .. _class_OptionButton_method_get_item_icon:
  220. .. rst-class:: classref-method
  221. :ref:`Texture2D<class_Texture2D>` **get_item_icon** **(** :ref:`int<class_int>` idx **)** |const|
  222. Returns the icon of the item at index ``idx``.
  223. .. rst-class:: classref-item-separator
  224. ----
  225. .. _class_OptionButton_method_get_item_id:
  226. .. rst-class:: classref-method
  227. :ref:`int<class_int>` **get_item_id** **(** :ref:`int<class_int>` idx **)** |const|
  228. Returns the ID of the item at index ``idx``.
  229. .. rst-class:: classref-item-separator
  230. ----
  231. .. _class_OptionButton_method_get_item_index:
  232. .. rst-class:: classref-method
  233. :ref:`int<class_int>` **get_item_index** **(** :ref:`int<class_int>` id **)** |const|
  234. Returns the index of the item with the given ``id``.
  235. .. rst-class:: classref-item-separator
  236. ----
  237. .. _class_OptionButton_method_get_item_metadata:
  238. .. rst-class:: classref-method
  239. :ref:`Variant<class_Variant>` **get_item_metadata** **(** :ref:`int<class_int>` idx **)** |const|
  240. 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.
  241. .. rst-class:: classref-item-separator
  242. ----
  243. .. _class_OptionButton_method_get_item_text:
  244. .. rst-class:: classref-method
  245. :ref:`String<class_String>` **get_item_text** **(** :ref:`int<class_int>` idx **)** |const|
  246. Returns the text of the item at index ``idx``.
  247. .. rst-class:: classref-item-separator
  248. ----
  249. .. _class_OptionButton_method_get_item_tooltip:
  250. .. rst-class:: classref-method
  251. :ref:`String<class_String>` **get_item_tooltip** **(** :ref:`int<class_int>` idx **)** |const|
  252. Returns the tooltip of the item at index ``idx``.
  253. .. rst-class:: classref-item-separator
  254. ----
  255. .. _class_OptionButton_method_get_popup:
  256. .. rst-class:: classref-method
  257. :ref:`PopupMenu<class_PopupMenu>` **get_popup** **(** **)** |const|
  258. Returns the :ref:`PopupMenu<class_PopupMenu>` contained in this button.
  259. \ **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.
  260. .. rst-class:: classref-item-separator
  261. ----
  262. .. _class_OptionButton_method_get_selectable_item:
  263. .. rst-class:: classref-method
  264. :ref:`int<class_int>` **get_selectable_item** **(** :ref:`bool<class_bool>` from_last=false **)** |const|
  265. .. container:: contribute
  266. There is currently no description for this method. Please help us by :ref:`contributing one <doc_updating_the_class_reference>`!
  267. .. rst-class:: classref-item-separator
  268. ----
  269. .. _class_OptionButton_method_get_selected_id:
  270. .. rst-class:: classref-method
  271. :ref:`int<class_int>` **get_selected_id** **(** **)** |const|
  272. Returns the ID of the selected item, or ``-1`` if no item is selected.
  273. .. rst-class:: classref-item-separator
  274. ----
  275. .. _class_OptionButton_method_get_selected_metadata:
  276. .. rst-class:: classref-method
  277. :ref:`Variant<class_Variant>` **get_selected_metadata** **(** **)** |const|
  278. Gets the metadata of the selected item. Metadata for items can be set using :ref:`set_item_metadata<class_OptionButton_method_set_item_metadata>`.
  279. .. rst-class:: classref-item-separator
  280. ----
  281. .. _class_OptionButton_method_has_selectable_items:
  282. .. rst-class:: classref-method
  283. :ref:`bool<class_bool>` **has_selectable_items** **(** **)** |const|
  284. .. container:: contribute
  285. There is currently no description for this method. Please help us by :ref:`contributing one <doc_updating_the_class_reference>`!
  286. .. rst-class:: classref-item-separator
  287. ----
  288. .. _class_OptionButton_method_is_item_disabled:
  289. .. rst-class:: classref-method
  290. :ref:`bool<class_bool>` **is_item_disabled** **(** :ref:`int<class_int>` idx **)** |const|
  291. Returns ``true`` if the item at index ``idx`` is disabled.
  292. .. rst-class:: classref-item-separator
  293. ----
  294. .. _class_OptionButton_method_is_item_separator:
  295. .. rst-class:: classref-method
  296. :ref:`bool<class_bool>` **is_item_separator** **(** :ref:`int<class_int>` idx **)** |const|
  297. .. container:: contribute
  298. There is currently no description for this method. Please help us by :ref:`contributing one <doc_updating_the_class_reference>`!
  299. .. rst-class:: classref-item-separator
  300. ----
  301. .. _class_OptionButton_method_remove_item:
  302. .. rst-class:: classref-method
  303. void **remove_item** **(** :ref:`int<class_int>` idx **)**
  304. Removes the item at index ``idx``.
  305. .. rst-class:: classref-item-separator
  306. ----
  307. .. _class_OptionButton_method_select:
  308. .. rst-class:: classref-method
  309. void **select** **(** :ref:`int<class_int>` idx **)**
  310. Selects an item by index and makes it the current item. This will work even if the item is disabled.
  311. Passing ``-1`` as the index deselects any currently selected item.
  312. .. rst-class:: classref-item-separator
  313. ----
  314. .. _class_OptionButton_method_set_item_disabled:
  315. .. rst-class:: classref-method
  316. void **set_item_disabled** **(** :ref:`int<class_int>` idx, :ref:`bool<class_bool>` 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** **(** :ref:`int<class_int>` idx, :ref:`Texture2D<class_Texture2D>` texture **)**
  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** **(** :ref:`int<class_int>` idx, :ref:`int<class_int>` 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** **(** :ref:`int<class_int>` idx, :ref:`Variant<class_Variant>` 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** **(** :ref:`int<class_int>` idx, :ref:`String<class_String>` 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** **(** :ref:`int<class_int>` idx, :ref:`String<class_String>` 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** **(** **)**
  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_color_font_color:
  361. .. rst-class:: classref-themeproperty
  362. :ref:`Color<class_Color>` **font_color** = ``Color(0.875, 0.875, 0.875, 1)``
  363. Default text :ref:`Color<class_Color>` of the **OptionButton**.
  364. .. rst-class:: classref-item-separator
  365. ----
  366. .. _class_OptionButton_theme_color_font_disabled_color:
  367. .. rst-class:: classref-themeproperty
  368. :ref:`Color<class_Color>` **font_disabled_color** = ``Color(0.875, 0.875, 0.875, 0.5)``
  369. Text :ref:`Color<class_Color>` used when the **OptionButton** is disabled.
  370. .. rst-class:: classref-item-separator
  371. ----
  372. .. _class_OptionButton_theme_color_font_focus_color:
  373. .. rst-class:: classref-themeproperty
  374. :ref:`Color<class_Color>` **font_focus_color** = ``Color(0.95, 0.95, 0.95, 1)``
  375. 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.
  376. .. rst-class:: classref-item-separator
  377. ----
  378. .. _class_OptionButton_theme_color_font_hover_color:
  379. .. rst-class:: classref-themeproperty
  380. :ref:`Color<class_Color>` **font_hover_color** = ``Color(0.95, 0.95, 0.95, 1)``
  381. Text :ref:`Color<class_Color>` used when the **OptionButton** is being hovered.
  382. .. rst-class:: classref-item-separator
  383. ----
  384. .. _class_OptionButton_theme_color_font_hover_pressed_color:
  385. .. rst-class:: classref-themeproperty
  386. :ref:`Color<class_Color>` **font_hover_pressed_color** = ``Color(1, 1, 1, 1)``
  387. Text :ref:`Color<class_Color>` used when the **OptionButton** is being hovered and pressed.
  388. .. rst-class:: classref-item-separator
  389. ----
  390. .. _class_OptionButton_theme_color_font_outline_color:
  391. .. rst-class:: classref-themeproperty
  392. :ref:`Color<class_Color>` **font_outline_color** = ``Color(1, 1, 1, 1)``
  393. The tint of text outline of the **OptionButton**.
  394. .. rst-class:: classref-item-separator
  395. ----
  396. .. _class_OptionButton_theme_color_font_pressed_color:
  397. .. rst-class:: classref-themeproperty
  398. :ref:`Color<class_Color>` **font_pressed_color** = ``Color(1, 1, 1, 1)``
  399. Text :ref:`Color<class_Color>` used when the **OptionButton** is being pressed.
  400. .. rst-class:: classref-item-separator
  401. ----
  402. .. _class_OptionButton_theme_constant_arrow_margin:
  403. .. rst-class:: classref-themeproperty
  404. :ref:`int<class_int>` **arrow_margin** = ``4``
  405. The horizontal space between the arrow icon and the right edge of the button.
  406. .. rst-class:: classref-item-separator
  407. ----
  408. .. _class_OptionButton_theme_constant_h_separation:
  409. .. rst-class:: classref-themeproperty
  410. :ref:`int<class_int>` **h_separation** = ``2``
  411. The horizontal space between **OptionButton**'s icon and text. Negative values will be treated as ``0`` when used.
  412. .. rst-class:: classref-item-separator
  413. ----
  414. .. _class_OptionButton_theme_constant_modulate_arrow:
  415. .. rst-class:: classref-themeproperty
  416. :ref:`int<class_int>` **modulate_arrow** = ``0``
  417. If different than ``0``, the arrow icon will be modulated to the font color.
  418. .. rst-class:: classref-item-separator
  419. ----
  420. .. _class_OptionButton_theme_constant_outline_size:
  421. .. rst-class:: classref-themeproperty
  422. :ref:`int<class_int>` **outline_size** = ``0``
  423. The size of the text outline.
  424. \ **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.
  425. .. rst-class:: classref-item-separator
  426. ----
  427. .. _class_OptionButton_theme_font_font:
  428. .. rst-class:: classref-themeproperty
  429. :ref:`Font<class_Font>` **font**
  430. :ref:`Font<class_Font>` of the **OptionButton**'s text.
  431. .. rst-class:: classref-item-separator
  432. ----
  433. .. _class_OptionButton_theme_font_size_font_size:
  434. .. rst-class:: classref-themeproperty
  435. :ref:`int<class_int>` **font_size**
  436. Font size of the **OptionButton**'s text.
  437. .. rst-class:: classref-item-separator
  438. ----
  439. .. _class_OptionButton_theme_icon_arrow:
  440. .. rst-class:: classref-themeproperty
  441. :ref:`Texture2D<class_Texture2D>` **arrow**
  442. The arrow icon to be drawn on the right end of the button.
  443. .. rst-class:: classref-item-separator
  444. ----
  445. .. _class_OptionButton_theme_style_disabled:
  446. .. rst-class:: classref-themeproperty
  447. :ref:`StyleBox<class_StyleBox>` **disabled**
  448. :ref:`StyleBox<class_StyleBox>` used when the **OptionButton** is disabled (for left-to-right layouts).
  449. .. rst-class:: classref-item-separator
  450. ----
  451. .. _class_OptionButton_theme_style_disabled_mirrored:
  452. .. rst-class:: classref-themeproperty
  453. :ref:`StyleBox<class_StyleBox>` **disabled_mirrored**
  454. :ref:`StyleBox<class_StyleBox>` used when the **OptionButton** is disabled (for right-to-left layouts).
  455. .. rst-class:: classref-item-separator
  456. ----
  457. .. _class_OptionButton_theme_style_focus:
  458. .. rst-class:: classref-themeproperty
  459. :ref:`StyleBox<class_StyleBox>` **focus**
  460. :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.
  461. .. rst-class:: classref-item-separator
  462. ----
  463. .. _class_OptionButton_theme_style_hover:
  464. .. rst-class:: classref-themeproperty
  465. :ref:`StyleBox<class_StyleBox>` **hover**
  466. :ref:`StyleBox<class_StyleBox>` used when the **OptionButton** is being hovered (for left-to-right layouts).
  467. .. rst-class:: classref-item-separator
  468. ----
  469. .. _class_OptionButton_theme_style_hover_mirrored:
  470. .. rst-class:: classref-themeproperty
  471. :ref:`StyleBox<class_StyleBox>` **hover_mirrored**
  472. :ref:`StyleBox<class_StyleBox>` used when the **OptionButton** is being hovered (for right-to-left layouts).
  473. .. rst-class:: classref-item-separator
  474. ----
  475. .. _class_OptionButton_theme_style_normal:
  476. .. rst-class:: classref-themeproperty
  477. :ref:`StyleBox<class_StyleBox>` **normal**
  478. Default :ref:`StyleBox<class_StyleBox>` for the **OptionButton** (for left-to-right layouts).
  479. .. rst-class:: classref-item-separator
  480. ----
  481. .. _class_OptionButton_theme_style_normal_mirrored:
  482. .. rst-class:: classref-themeproperty
  483. :ref:`StyleBox<class_StyleBox>` **normal_mirrored**
  484. Default :ref:`StyleBox<class_StyleBox>` for the **OptionButton** (for right-to-left layouts).
  485. .. rst-class:: classref-item-separator
  486. ----
  487. .. _class_OptionButton_theme_style_pressed:
  488. .. rst-class:: classref-themeproperty
  489. :ref:`StyleBox<class_StyleBox>` **pressed**
  490. :ref:`StyleBox<class_StyleBox>` used when the **OptionButton** is being pressed (for left-to-right layouts).
  491. .. rst-class:: classref-item-separator
  492. ----
  493. .. _class_OptionButton_theme_style_pressed_mirrored:
  494. .. rst-class:: classref-themeproperty
  495. :ref:`StyleBox<class_StyleBox>` **pressed_mirrored**
  496. :ref:`StyleBox<class_StyleBox>` used when the **OptionButton** is being pressed (for right-to-left layouts).
  497. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  498. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  499. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  500. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  501. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  502. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`