class_optionbutton.rst 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. **Category:** Core
  10. Brief Description
  11. -----------------
  12. Button control that provides selectable options when pressed.
  13. Properties
  14. ----------
  15. +-----------------------+-------------------------------------------------------+----+
  16. | :ref:`int<class_int>` | :ref:`selected<class_OptionButton_property_selected>` | -1 |
  17. +-----------------------+-------------------------------------------------------+----+
  18. Methods
  19. -------
  20. +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  21. | 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 **)** |
  22. +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  23. | void | :ref:`add_item<class_OptionButton_method_add_item>` **(** :ref:`String<class_String>` label, :ref:`int<class_int>` id=-1 **)** |
  24. +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  25. | void | :ref:`add_separator<class_OptionButton_method_add_separator>` **(** **)** |
  26. +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  27. | void | :ref:`clear<class_OptionButton_method_clear>` **(** **)** |
  28. +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  29. | :ref:`int<class_int>` | :ref:`get_item_count<class_OptionButton_method_get_item_count>` **(** **)** const |
  30. +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  31. | :ref:`Texture<class_Texture>` | :ref:`get_item_icon<class_OptionButton_method_get_item_icon>` **(** :ref:`int<class_int>` idx **)** const |
  32. +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  33. | :ref:`int<class_int>` | :ref:`get_item_id<class_OptionButton_method_get_item_id>` **(** :ref:`int<class_int>` idx **)** const |
  34. +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  35. | :ref:`int<class_int>` | :ref:`get_item_index<class_OptionButton_method_get_item_index>` **(** :ref:`int<class_int>` id **)** const |
  36. +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  37. | :ref:`Variant<class_Variant>` | :ref:`get_item_metadata<class_OptionButton_method_get_item_metadata>` **(** :ref:`int<class_int>` idx **)** const |
  38. +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  39. | :ref:`String<class_String>` | :ref:`get_item_text<class_OptionButton_method_get_item_text>` **(** :ref:`int<class_int>` idx **)** const |
  40. +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`PopupMenu<class_PopupMenu>` | :ref:`get_popup<class_OptionButton_method_get_popup>` **(** **)** const |
  42. +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | :ref:`int<class_int>` | :ref:`get_selected_id<class_OptionButton_method_get_selected_id>` **(** **)** const |
  44. +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`Variant<class_Variant>` | :ref:`get_selected_metadata<class_OptionButton_method_get_selected_metadata>` **(** **)** const |
  46. +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | :ref:`bool<class_bool>` | :ref:`is_item_disabled<class_OptionButton_method_is_item_disabled>` **(** :ref:`int<class_int>` idx **)** const |
  48. +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | void | :ref:`remove_item<class_OptionButton_method_remove_item>` **(** :ref:`int<class_int>` idx **)** |
  50. +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | void | :ref:`select<class_OptionButton_method_select>` **(** :ref:`int<class_int>` idx **)** |
  52. +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | void | :ref:`set_item_disabled<class_OptionButton_method_set_item_disabled>` **(** :ref:`int<class_int>` idx, :ref:`bool<class_bool>` disabled **)** |
  54. +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | void | :ref:`set_item_icon<class_OptionButton_method_set_item_icon>` **(** :ref:`int<class_int>` idx, :ref:`Texture<class_Texture>` texture **)** |
  56. +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | void | :ref:`set_item_id<class_OptionButton_method_set_item_id>` **(** :ref:`int<class_int>` idx, :ref:`int<class_int>` id **)** |
  58. +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  59. | void | :ref:`set_item_metadata<class_OptionButton_method_set_item_metadata>` **(** :ref:`int<class_int>` idx, :ref:`Variant<class_Variant>` metadata **)** |
  60. +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  61. | void | :ref:`set_item_text<class_OptionButton_method_set_item_text>` **(** :ref:`int<class_int>` idx, :ref:`String<class_String>` text **)** |
  62. +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  63. Theme Properties
  64. ----------------
  65. +---------------------------------+---------------------+------------------------------+
  66. | :ref:`Texture<class_Texture>` | arrow | |
  67. +---------------------------------+---------------------+------------------------------+
  68. | :ref:`int<class_int>` | arrow_margin | 2 |
  69. +---------------------------------+---------------------+------------------------------+
  70. | :ref:`StyleBox<class_StyleBox>` | disabled | |
  71. +---------------------------------+---------------------+------------------------------+
  72. | :ref:`StyleBox<class_StyleBox>` | focus | |
  73. +---------------------------------+---------------------+------------------------------+
  74. | :ref:`Font<class_Font>` | font | |
  75. +---------------------------------+---------------------+------------------------------+
  76. | :ref:`Color<class_Color>` | font_color | Color( 0.88, 0.88, 0.88, 1 ) |
  77. +---------------------------------+---------------------+------------------------------+
  78. | :ref:`Color<class_Color>` | font_color_disabled | Color( 0.9, 0.9, 0.9, 0.2 ) |
  79. +---------------------------------+---------------------+------------------------------+
  80. | :ref:`Color<class_Color>` | font_color_hover | Color( 0.94, 0.94, 0.94, 1 ) |
  81. +---------------------------------+---------------------+------------------------------+
  82. | :ref:`Color<class_Color>` | font_color_pressed | Color( 1, 1, 1, 1 ) |
  83. +---------------------------------+---------------------+------------------------------+
  84. | :ref:`StyleBox<class_StyleBox>` | hover | |
  85. +---------------------------------+---------------------+------------------------------+
  86. | :ref:`int<class_int>` | hseparation | 2 |
  87. +---------------------------------+---------------------+------------------------------+
  88. | :ref:`StyleBox<class_StyleBox>` | normal | |
  89. +---------------------------------+---------------------+------------------------------+
  90. | :ref:`StyleBox<class_StyleBox>` | pressed | |
  91. +---------------------------------+---------------------+------------------------------+
  92. Signals
  93. -------
  94. .. _class_OptionButton_signal_item_focused:
  95. - **item_focused** **(** :ref:`int<class_int>` id **)**
  96. Emitted the when user navigates to an item using the ``ui_up`` or ``ui_down`` actions. The index of the item selected is passed as argument.
  97. .. _class_OptionButton_signal_item_selected:
  98. - **item_selected** **(** :ref:`int<class_int>` id **)**
  99. Emitted when the current item has been changed by the user. The index of the item selected is passed as argument.
  100. Description
  101. -----------
  102. 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.
  103. Property Descriptions
  104. ---------------------
  105. .. _class_OptionButton_property_selected:
  106. - :ref:`int<class_int>` **selected**
  107. +-----------+----------------+
  108. | *Default* | -1 |
  109. +-----------+----------------+
  110. | *Getter* | get_selected() |
  111. +-----------+----------------+
  112. Method Descriptions
  113. -------------------
  114. .. _class_OptionButton_method_add_icon_item:
  115. - void **add_icon_item** **(** :ref:`Texture<class_Texture>` texture, :ref:`String<class_String>` label, :ref:`int<class_int>` id=-1 **)**
  116. Adds an item, with a ``texture`` icon, text ``label`` and (optionally) ``id``. If no ``id`` is passed, ``id`` becomes the item index. New items are appended at the end.
  117. .. _class_OptionButton_method_add_item:
  118. - void **add_item** **(** :ref:`String<class_String>` label, :ref:`int<class_int>` id=-1 **)**
  119. Adds an item, with text ``label`` and (optionally) ``id``. If no ``id`` is passed, ``id`` becomes the item index. New items are appended at the end.
  120. .. _class_OptionButton_method_add_separator:
  121. - void **add_separator** **(** **)**
  122. 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.
  123. .. _class_OptionButton_method_clear:
  124. - void **clear** **(** **)**
  125. Clear all the items in the ``OptionButton``.
  126. .. _class_OptionButton_method_get_item_count:
  127. - :ref:`int<class_int>` **get_item_count** **(** **)** const
  128. Returns the amount of items in the OptionButton.
  129. .. _class_OptionButton_method_get_item_icon:
  130. - :ref:`Texture<class_Texture>` **get_item_icon** **(** :ref:`int<class_int>` idx **)** const
  131. Returns the icon of the item at index ``idx``.
  132. .. _class_OptionButton_method_get_item_id:
  133. - :ref:`int<class_int>` **get_item_id** **(** :ref:`int<class_int>` idx **)** const
  134. Returns the ID of the item at index ``idx``.
  135. .. _class_OptionButton_method_get_item_index:
  136. - :ref:`int<class_int>` **get_item_index** **(** :ref:`int<class_int>` id **)** const
  137. Returns the index of the item with the given ``id``.
  138. .. _class_OptionButton_method_get_item_metadata:
  139. - :ref:`Variant<class_Variant>` **get_item_metadata** **(** :ref:`int<class_int>` idx **)** const
  140. .. _class_OptionButton_method_get_item_text:
  141. - :ref:`String<class_String>` **get_item_text** **(** :ref:`int<class_int>` idx **)** const
  142. Returns the text of the item at index ``idx``.
  143. .. _class_OptionButton_method_get_popup:
  144. - :ref:`PopupMenu<class_PopupMenu>` **get_popup** **(** **)** const
  145. Returns the :ref:`PopupMenu<class_PopupMenu>` contained in this button.
  146. .. _class_OptionButton_method_get_selected_id:
  147. - :ref:`int<class_int>` **get_selected_id** **(** **)** const
  148. .. _class_OptionButton_method_get_selected_metadata:
  149. - :ref:`Variant<class_Variant>` **get_selected_metadata** **(** **)** const
  150. .. _class_OptionButton_method_is_item_disabled:
  151. - :ref:`bool<class_bool>` **is_item_disabled** **(** :ref:`int<class_int>` idx **)** const
  152. .. _class_OptionButton_method_remove_item:
  153. - void **remove_item** **(** :ref:`int<class_int>` idx **)**
  154. .. _class_OptionButton_method_select:
  155. - void **select** **(** :ref:`int<class_int>` idx **)**
  156. Select an item by index and make it the current item.
  157. .. _class_OptionButton_method_set_item_disabled:
  158. - void **set_item_disabled** **(** :ref:`int<class_int>` idx, :ref:`bool<class_bool>` disabled **)**
  159. .. _class_OptionButton_method_set_item_icon:
  160. - void **set_item_icon** **(** :ref:`int<class_int>` idx, :ref:`Texture<class_Texture>` texture **)**
  161. Sets the icon of an item at index ``idx``.
  162. .. _class_OptionButton_method_set_item_id:
  163. - void **set_item_id** **(** :ref:`int<class_int>` idx, :ref:`int<class_int>` id **)**
  164. Sets the ID of an item at index ``idx``.
  165. .. _class_OptionButton_method_set_item_metadata:
  166. - void **set_item_metadata** **(** :ref:`int<class_int>` idx, :ref:`Variant<class_Variant>` metadata **)**
  167. .. _class_OptionButton_method_set_item_text:
  168. - void **set_item_text** **(** :ref:`int<class_int>` idx, :ref:`String<class_String>` text **)**
  169. Sets the text of an item at index ``idx``.