class_optionbutton.rst 44 KB

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