class_optionbutton.rst 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  3. .. DO NOT EDIT THIS FILE, but the OptionButton.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_OptionButton:
  6. OptionButton
  7. ============
  8. **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>`
  9. Button control that provides selectable options when pressed.
  10. Description
  11. -----------
  12. 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.
  13. Properties
  14. ----------
  15. +-----------------------------------------------+-------------------------------------------------------+------------------------------+
  16. | :ref:`ActionMode<enum_BaseButton_ActionMode>` | action_mode | ``0`` *(parent override)* |
  17. +-----------------------------------------------+-------------------------------------------------------+------------------------------+
  18. | :ref:`TextAlign<enum_Button_TextAlign>` | align | ``0`` *(parent override)* |
  19. +-----------------------------------------------+-------------------------------------------------------+------------------------------+
  20. | :ref:`int<class_int>` | :ref:`selected<class_OptionButton_property_selected>` | ``-1`` |
  21. +-----------------------------------------------+-------------------------------------------------------+------------------------------+
  22. | :ref:`bool<class_bool>` | toggle_mode | ``true`` *(parent override)* |
  23. +-----------------------------------------------+-------------------------------------------------------+------------------------------+
  24. Methods
  25. -------
  26. +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  27. | void | :ref:`add_icon_item<class_OptionButton_method_add_icon_item>` **(** :ref:`Texture<class_Texture>` texture, :ref:`String<class_String>` label, :ref:`int<class_int>` id=-1 **)** |
  28. +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  29. | void | :ref:`add_item<class_OptionButton_method_add_item>` **(** :ref:`String<class_String>` label, :ref:`int<class_int>` id=-1 **)** |
  30. +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  31. | void | :ref:`add_separator<class_OptionButton_method_add_separator>` **(** **)** |
  32. +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  33. | void | :ref:`clear<class_OptionButton_method_clear>` **(** **)** |
  34. +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  35. | :ref:`int<class_int>` | :ref:`get_item_count<class_OptionButton_method_get_item_count>` **(** **)** |const| |
  36. +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  37. | :ref:`Texture<class_Texture>` | :ref:`get_item_icon<class_OptionButton_method_get_item_icon>` **(** :ref:`int<class_int>` idx **)** |const| |
  38. +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  39. | :ref:`int<class_int>` | :ref:`get_item_id<class_OptionButton_method_get_item_id>` **(** :ref:`int<class_int>` idx **)** |const| |
  40. +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`int<class_int>` | :ref:`get_item_index<class_OptionButton_method_get_item_index>` **(** :ref:`int<class_int>` id **)** |const| |
  42. +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | :ref:`Variant<class_Variant>` | :ref:`get_item_metadata<class_OptionButton_method_get_item_metadata>` **(** :ref:`int<class_int>` idx **)** |const| |
  44. +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`String<class_String>` | :ref:`get_item_text<class_OptionButton_method_get_item_text>` **(** :ref:`int<class_int>` idx **)** |const| |
  46. +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | :ref:`PopupMenu<class_PopupMenu>` | :ref:`get_popup<class_OptionButton_method_get_popup>` **(** **)** |const| |
  48. +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | :ref:`int<class_int>` | :ref:`get_selected_id<class_OptionButton_method_get_selected_id>` **(** **)** |const| |
  50. +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | :ref:`Variant<class_Variant>` | :ref:`get_selected_metadata<class_OptionButton_method_get_selected_metadata>` **(** **)** |const| |
  52. +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | :ref:`bool<class_bool>` | :ref:`is_item_disabled<class_OptionButton_method_is_item_disabled>` **(** :ref:`int<class_int>` idx **)** |const| |
  54. +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | void | :ref:`remove_item<class_OptionButton_method_remove_item>` **(** :ref:`int<class_int>` idx **)** |
  56. +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | void | :ref:`select<class_OptionButton_method_select>` **(** :ref:`int<class_int>` idx **)** |
  58. +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  59. | void | :ref:`set_item_disabled<class_OptionButton_method_set_item_disabled>` **(** :ref:`int<class_int>` idx, :ref:`bool<class_bool>` disabled **)** |
  60. +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  61. | void | :ref:`set_item_icon<class_OptionButton_method_set_item_icon>` **(** :ref:`int<class_int>` idx, :ref:`Texture<class_Texture>` texture **)** |
  62. +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  63. | void | :ref:`set_item_id<class_OptionButton_method_set_item_id>` **(** :ref:`int<class_int>` idx, :ref:`int<class_int>` id **)** |
  64. +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  65. | void | :ref:`set_item_metadata<class_OptionButton_method_set_item_metadata>` **(** :ref:`int<class_int>` idx, :ref:`Variant<class_Variant>` metadata **)** |
  66. +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  67. | void | :ref:`set_item_text<class_OptionButton_method_set_item_text>` **(** :ref:`int<class_int>` idx, :ref:`String<class_String>` text **)** |
  68. +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  69. Theme Properties
  70. ----------------
  71. +---------------------------------+---------------------+------------------------------+
  72. | :ref:`Texture<class_Texture>` | arrow | |
  73. +---------------------------------+---------------------+------------------------------+
  74. | :ref:`int<class_int>` | arrow_margin | 2 |
  75. +---------------------------------+---------------------+------------------------------+
  76. | :ref:`StyleBox<class_StyleBox>` | disabled | |
  77. +---------------------------------+---------------------+------------------------------+
  78. | :ref:`StyleBox<class_StyleBox>` | focus | |
  79. +---------------------------------+---------------------+------------------------------+
  80. | :ref:`Font<class_Font>` | font | |
  81. +---------------------------------+---------------------+------------------------------+
  82. | :ref:`Color<class_Color>` | font_color | Color( 0.88, 0.88, 0.88, 1 ) |
  83. +---------------------------------+---------------------+------------------------------+
  84. | :ref:`Color<class_Color>` | font_color_disabled | Color( 0.9, 0.9, 0.9, 0.2 ) |
  85. +---------------------------------+---------------------+------------------------------+
  86. | :ref:`Color<class_Color>` | font_color_hover | Color( 0.94, 0.94, 0.94, 1 ) |
  87. +---------------------------------+---------------------+------------------------------+
  88. | :ref:`Color<class_Color>` | font_color_pressed | Color( 1, 1, 1, 1 ) |
  89. +---------------------------------+---------------------+------------------------------+
  90. | :ref:`StyleBox<class_StyleBox>` | hover | |
  91. +---------------------------------+---------------------+------------------------------+
  92. | :ref:`int<class_int>` | hseparation | 2 |
  93. +---------------------------------+---------------------+------------------------------+
  94. | :ref:`StyleBox<class_StyleBox>` | normal | |
  95. +---------------------------------+---------------------+------------------------------+
  96. | :ref:`StyleBox<class_StyleBox>` | pressed | |
  97. +---------------------------------+---------------------+------------------------------+
  98. Signals
  99. -------
  100. .. _class_OptionButton_signal_item_focused:
  101. - **item_focused** **(** :ref:`int<class_int>` index **)**
  102. Emitted when the user navigates to an item using the ``ui_up`` or ``ui_down`` actions. The index of the item selected is passed as argument.
  103. ----
  104. .. _class_OptionButton_signal_item_selected:
  105. - **item_selected** **(** :ref:`int<class_int>` index **)**
  106. Emitted when the current item has been changed by the user. The index of the item selected is passed as argument.
  107. Property Descriptions
  108. ---------------------
  109. .. _class_OptionButton_property_selected:
  110. - :ref:`int<class_int>` **selected**
  111. +-----------+----------------+
  112. | *Default* | ``-1`` |
  113. +-----------+----------------+
  114. | *Getter* | get_selected() |
  115. +-----------+----------------+
  116. The index of the currently selected item, or ``-1`` if no item is selected.
  117. Method Descriptions
  118. -------------------
  119. .. _class_OptionButton_method_add_icon_item:
  120. - void **add_icon_item** **(** :ref:`Texture<class_Texture>` texture, :ref:`String<class_String>` label, :ref:`int<class_int>` id=-1 **)**
  121. 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.
  122. ----
  123. .. _class_OptionButton_method_add_item:
  124. - void **add_item** **(** :ref:`String<class_String>` label, :ref:`int<class_int>` id=-1 **)**
  125. 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.
  126. ----
  127. .. _class_OptionButton_method_add_separator:
  128. - void **add_separator** **(** **)**
  129. Adds a separator to the list of items. Separators help to group items. Separator also takes up an index and is appended at the end.
  130. ----
  131. .. _class_OptionButton_method_clear:
  132. - void **clear** **(** **)**
  133. Clears all the items in the ``OptionButton``.
  134. ----
  135. .. _class_OptionButton_method_get_item_count:
  136. - :ref:`int<class_int>` **get_item_count** **(** **)** |const|
  137. Returns the amount of items in the OptionButton, including separators.
  138. ----
  139. .. _class_OptionButton_method_get_item_icon:
  140. - :ref:`Texture<class_Texture>` **get_item_icon** **(** :ref:`int<class_int>` idx **)** |const|
  141. Returns the icon of the item at index ``idx``.
  142. ----
  143. .. _class_OptionButton_method_get_item_id:
  144. - :ref:`int<class_int>` **get_item_id** **(** :ref:`int<class_int>` idx **)** |const|
  145. Returns the ID of the item at index ``idx``.
  146. ----
  147. .. _class_OptionButton_method_get_item_index:
  148. - :ref:`int<class_int>` **get_item_index** **(** :ref:`int<class_int>` id **)** |const|
  149. Returns the index of the item with the given ``id``.
  150. ----
  151. .. _class_OptionButton_method_get_item_metadata:
  152. - :ref:`Variant<class_Variant>` **get_item_metadata** **(** :ref:`int<class_int>` idx **)** |const|
  153. 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.
  154. ----
  155. .. _class_OptionButton_method_get_item_text:
  156. - :ref:`String<class_String>` **get_item_text** **(** :ref:`int<class_int>` idx **)** |const|
  157. Returns the text of the item at index ``idx``.
  158. ----
  159. .. _class_OptionButton_method_get_popup:
  160. - :ref:`PopupMenu<class_PopupMenu>` **get_popup** **(** **)** |const|
  161. Returns the :ref:`PopupMenu<class_PopupMenu>` contained in this button.
  162. ----
  163. .. _class_OptionButton_method_get_selected_id:
  164. - :ref:`int<class_int>` **get_selected_id** **(** **)** |const|
  165. Returns the ID of the selected item, or ``0`` if no item is selected.
  166. ----
  167. .. _class_OptionButton_method_get_selected_metadata:
  168. - :ref:`Variant<class_Variant>` **get_selected_metadata** **(** **)** |const|
  169. Gets the metadata of the selected item. Metadata for items can be set using :ref:`set_item_metadata<class_OptionButton_method_set_item_metadata>`.
  170. ----
  171. .. _class_OptionButton_method_is_item_disabled:
  172. - :ref:`bool<class_bool>` **is_item_disabled** **(** :ref:`int<class_int>` idx **)** |const|
  173. Returns ``true`` if the item at index ``idx`` is disabled.
  174. ----
  175. .. _class_OptionButton_method_remove_item:
  176. - void **remove_item** **(** :ref:`int<class_int>` idx **)**
  177. Removes the item at index ``idx``.
  178. ----
  179. .. _class_OptionButton_method_select:
  180. - void **select** **(** :ref:`int<class_int>` idx **)**
  181. Selects an item by index and makes it the current item. This will work even if the item is disabled.
  182. ----
  183. .. _class_OptionButton_method_set_item_disabled:
  184. - void **set_item_disabled** **(** :ref:`int<class_int>` idx, :ref:`bool<class_bool>` disabled **)**
  185. Sets whether the item at index ``idx`` is disabled.
  186. 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.
  187. ----
  188. .. _class_OptionButton_method_set_item_icon:
  189. - void **set_item_icon** **(** :ref:`int<class_int>` idx, :ref:`Texture<class_Texture>` texture **)**
  190. Sets the icon of the item at index ``idx``.
  191. ----
  192. .. _class_OptionButton_method_set_item_id:
  193. - void **set_item_id** **(** :ref:`int<class_int>` idx, :ref:`int<class_int>` id **)**
  194. Sets the ID of the item at index ``idx``.
  195. ----
  196. .. _class_OptionButton_method_set_item_metadata:
  197. - void **set_item_metadata** **(** :ref:`int<class_int>` idx, :ref:`Variant<class_Variant>` metadata **)**
  198. 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.
  199. ----
  200. .. _class_OptionButton_method_set_item_text:
  201. - void **set_item_text** **(** :ref:`int<class_int>` idx, :ref:`String<class_String>` text **)**
  202. Sets the text of the item at index ``idx``.
  203. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  204. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  205. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`