class_optionbutton.rst 16 KB

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