class_optionbutton.rst 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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>` | -1 |
  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 | 2 |
  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 | Color( 0.88, 0.88, 0.88, 1 ) |
  76. +---------------------------------+---------------------+------------------------------+
  77. | :ref:`Color<class_Color>` | font_color_disabled | Color( 0.9, 0.9, 0.9, 0.2 ) |
  78. +---------------------------------+---------------------+------------------------------+
  79. | :ref:`Color<class_Color>` | font_color_hover | Color( 0.94, 0.94, 0.94, 1 ) |
  80. +---------------------------------+---------------------+------------------------------+
  81. | :ref:`Color<class_Color>` | font_color_pressed | Color( 1, 1, 1, 1 ) |
  82. +---------------------------------+---------------------+------------------------------+
  83. | :ref:`StyleBox<class_StyleBox>` | hover | |
  84. +---------------------------------+---------------------+------------------------------+
  85. | :ref:`int<class_int>` | hseparation | 2 |
  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. 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.
  96. .. _class_OptionButton_signal_item_selected:
  97. - **item_selected** **(** :ref:`int<class_int>` id **)**
  98. Emitted when the current item has been changed by the user. The 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. | *Default* | -1 |
  108. +-----------+----------------+
  109. | *Getter* | get_selected() |
  110. +-----------+----------------+
  111. Method Descriptions
  112. -------------------
  113. .. _class_OptionButton_method_add_icon_item:
  114. - void **add_icon_item** **(** :ref:`Texture<class_Texture>` texture, :ref:`String<class_String>` label, :ref:`int<class_int>` id=-1 **)**
  115. 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.
  116. .. _class_OptionButton_method_add_item:
  117. - void **add_item** **(** :ref:`String<class_String>` label, :ref:`int<class_int>` id=-1 **)**
  118. 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.
  119. .. _class_OptionButton_method_add_separator:
  120. - void **add_separator** **(** **)**
  121. 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.
  122. .. _class_OptionButton_method_clear:
  123. - void **clear** **(** **)**
  124. Clear all the items in the ``OptionButton``.
  125. .. _class_OptionButton_method_get_item_count:
  126. - :ref:`int<class_int>` **get_item_count** **(** **)** const
  127. Returns the amount of items in the OptionButton.
  128. .. _class_OptionButton_method_get_item_icon:
  129. - :ref:`Texture<class_Texture>` **get_item_icon** **(** :ref:`int<class_int>` idx **)** const
  130. Returns the icon of the item at index ``idx``.
  131. .. _class_OptionButton_method_get_item_id:
  132. - :ref:`int<class_int>` **get_item_id** **(** :ref:`int<class_int>` idx **)** const
  133. Returns the ID of the item at index ``idx``.
  134. .. _class_OptionButton_method_get_item_index:
  135. - :ref:`int<class_int>` **get_item_index** **(** :ref:`int<class_int>` id **)** const
  136. Returns the index of the item with the given ``id``.
  137. .. _class_OptionButton_method_get_item_metadata:
  138. - :ref:`Variant<class_Variant>` **get_item_metadata** **(** :ref:`int<class_int>` idx **)** const
  139. .. _class_OptionButton_method_get_item_text:
  140. - :ref:`String<class_String>` **get_item_text** **(** :ref:`int<class_int>` idx **)** const
  141. Returns the text of the item at index ``idx``.
  142. .. _class_OptionButton_method_get_popup:
  143. - :ref:`PopupMenu<class_PopupMenu>` **get_popup** **(** **)** const
  144. Returns the :ref:`PopupMenu<class_PopupMenu>` contained in this button.
  145. .. _class_OptionButton_method_get_selected_id:
  146. - :ref:`int<class_int>` **get_selected_id** **(** **)** const
  147. .. _class_OptionButton_method_get_selected_metadata:
  148. - :ref:`Variant<class_Variant>` **get_selected_metadata** **(** **)** const
  149. .. _class_OptionButton_method_is_item_disabled:
  150. - :ref:`bool<class_bool>` **is_item_disabled** **(** :ref:`int<class_int>` idx **)** const
  151. .. _class_OptionButton_method_remove_item:
  152. - void **remove_item** **(** :ref:`int<class_int>` idx **)**
  153. .. _class_OptionButton_method_select:
  154. - void **select** **(** :ref:`int<class_int>` idx **)**
  155. Select an item by index and make it the current item.
  156. .. _class_OptionButton_method_set_item_disabled:
  157. - void **set_item_disabled** **(** :ref:`int<class_int>` idx, :ref:`bool<class_bool>` disabled **)**
  158. .. _class_OptionButton_method_set_item_icon:
  159. - void **set_item_icon** **(** :ref:`int<class_int>` idx, :ref:`Texture<class_Texture>` texture **)**
  160. Sets the icon of an item at index ``idx``.
  161. .. _class_OptionButton_method_set_item_id:
  162. - void **set_item_id** **(** :ref:`int<class_int>` idx, :ref:`int<class_int>` id **)**
  163. Sets the ID of an item at index ``idx``.
  164. .. _class_OptionButton_method_set_item_metadata:
  165. - void **set_item_metadata** **(** :ref:`int<class_int>` idx, :ref:`Variant<class_Variant>` metadata **)**
  166. .. _class_OptionButton_method_set_item_text:
  167. - void **set_item_text** **(** :ref:`int<class_int>` idx, :ref:`String<class_String>` text **)**
  168. Sets the text of an item at index ``idx``.