OptionButton.xml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <class name="OptionButton" inherits="Button" keywords="select" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
  3. <brief_description>
  4. A button that brings up a dropdown with selectable options when pressed.
  5. </brief_description>
  6. <description>
  7. [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.
  8. See also [BaseButton] which contains common properties and methods associated with this node.
  9. [b]Note:[/b] The ID values used for items are limited to 32 bits, not full 64 bits of [int]. This has a range of [code]-2^32[/code] to [code]2^32 - 1[/code], i.e. [code]-2147483648[/code] to [code]2147483647[/code].
  10. [b]Note:[/b] The [member Button.text] and [member Button.icon] properties are set automatically based on the selected item. They shouldn't be changed manually.
  11. </description>
  12. <tutorials>
  13. </tutorials>
  14. <methods>
  15. <method name="add_icon_item">
  16. <return type="void" />
  17. <param index="0" name="texture" type="Texture2D" />
  18. <param index="1" name="label" type="String" />
  19. <param index="2" name="id" type="int" default="-1" />
  20. <description>
  21. Adds an item, with a [param texture] icon, text [param label] and (optionally) [param id]. If no [param id] is passed, the item index will be used as the item's ID. New items are appended at the end.
  22. </description>
  23. </method>
  24. <method name="add_item">
  25. <return type="void" />
  26. <param index="0" name="label" type="String" />
  27. <param index="1" name="id" type="int" default="-1" />
  28. <description>
  29. Adds an item, with text [param label] and (optionally) [param id]. If no [param id] is passed, the item index will be used as the item's ID. New items are appended at the end.
  30. </description>
  31. </method>
  32. <method name="add_separator">
  33. <return type="void" />
  34. <param index="0" name="text" type="String" default="&quot;&quot;" />
  35. <description>
  36. Adds a separator to the list of items. Separators help to group items, and can optionally be given a [param text] header. A separator also gets an index assigned, and is appended at the end of the item list.
  37. </description>
  38. </method>
  39. <method name="clear">
  40. <return type="void" />
  41. <description>
  42. Clears all the items in the [OptionButton].
  43. </description>
  44. </method>
  45. <method name="get_item_auto_translate_mode" qualifiers="const">
  46. <return type="int" enum="Node.AutoTranslateMode" />
  47. <param index="0" name="idx" type="int" />
  48. <description>
  49. Returns the auto translate mode of the item at index [param idx].
  50. </description>
  51. </method>
  52. <method name="get_item_icon" qualifiers="const">
  53. <return type="Texture2D" />
  54. <param index="0" name="idx" type="int" />
  55. <description>
  56. Returns the icon of the item at index [param idx].
  57. </description>
  58. </method>
  59. <method name="get_item_id" qualifiers="const">
  60. <return type="int" />
  61. <param index="0" name="idx" type="int" />
  62. <description>
  63. Returns the ID of the item at index [param idx].
  64. </description>
  65. </method>
  66. <method name="get_item_index" qualifiers="const">
  67. <return type="int" />
  68. <param index="0" name="id" type="int" />
  69. <description>
  70. Returns the index of the item with the given [param id].
  71. </description>
  72. </method>
  73. <method name="get_item_metadata" qualifiers="const">
  74. <return type="Variant" />
  75. <param index="0" name="idx" type="int" />
  76. <description>
  77. 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.
  78. </description>
  79. </method>
  80. <method name="get_item_text" qualifiers="const">
  81. <return type="String" />
  82. <param index="0" name="idx" type="int" />
  83. <description>
  84. Returns the text of the item at index [param idx].
  85. </description>
  86. </method>
  87. <method name="get_item_tooltip" qualifiers="const">
  88. <return type="String" />
  89. <param index="0" name="idx" type="int" />
  90. <description>
  91. Returns the tooltip of the item at index [param idx].
  92. </description>
  93. </method>
  94. <method name="get_popup" qualifiers="const">
  95. <return type="PopupMenu" />
  96. <description>
  97. Returns the [PopupMenu] contained in this button.
  98. [b]Warning:[/b] 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 [member Window.visible] property.
  99. </description>
  100. </method>
  101. <method name="get_selectable_item" qualifiers="const">
  102. <return type="int" />
  103. <param index="0" name="from_last" type="bool" default="false" />
  104. <description>
  105. Returns the index of the first item which is not disabled, or marked as a separator. If [param from_last] is [code]true[/code], the items will be searched in reverse order.
  106. Returns [code]-1[/code] if no item is found.
  107. </description>
  108. </method>
  109. <method name="get_selected_id" qualifiers="const">
  110. <return type="int" />
  111. <description>
  112. Returns the ID of the selected item, or [code]-1[/code] if no item is selected.
  113. </description>
  114. </method>
  115. <method name="get_selected_metadata" qualifiers="const">
  116. <return type="Variant" />
  117. <description>
  118. Gets the metadata of the selected item. Metadata for items can be set using [method set_item_metadata].
  119. </description>
  120. </method>
  121. <method name="has_selectable_items" qualifiers="const">
  122. <return type="bool" />
  123. <description>
  124. Returns [code]true[/code] if this button contains at least one item which is not disabled, or marked as a separator.
  125. </description>
  126. </method>
  127. <method name="is_item_disabled" qualifiers="const">
  128. <return type="bool" />
  129. <param index="0" name="idx" type="int" />
  130. <description>
  131. Returns [code]true[/code] if the item at index [param idx] is disabled.
  132. </description>
  133. </method>
  134. <method name="is_item_separator" qualifiers="const">
  135. <return type="bool" />
  136. <param index="0" name="idx" type="int" />
  137. <description>
  138. Returns [code]true[/code] if the item at index [param idx] is marked as a separator.
  139. </description>
  140. </method>
  141. <method name="remove_item">
  142. <return type="void" />
  143. <param index="0" name="idx" type="int" />
  144. <description>
  145. Removes the item at index [param idx].
  146. </description>
  147. </method>
  148. <method name="select">
  149. <return type="void" />
  150. <param index="0" name="idx" type="int" />
  151. <description>
  152. Selects an item by index and makes it the current item. This will work even if the item is disabled.
  153. Passing [code]-1[/code] as the index deselects any currently selected item.
  154. </description>
  155. </method>
  156. <method name="set_disable_shortcuts">
  157. <return type="void" />
  158. <param index="0" name="disabled" type="bool" />
  159. <description>
  160. If [code]true[/code], shortcuts are disabled and cannot be used to trigger the button.
  161. </description>
  162. </method>
  163. <method name="set_item_auto_translate_mode">
  164. <return type="void" />
  165. <param index="0" name="idx" type="int" />
  166. <param index="1" name="mode" type="int" enum="Node.AutoTranslateMode" />
  167. <description>
  168. Sets the auto translate mode of the item at index [param idx].
  169. Items use [constant Node.AUTO_TRANSLATE_MODE_INHERIT] by default, which uses the same auto translate mode as the [OptionButton] itself.
  170. </description>
  171. </method>
  172. <method name="set_item_disabled">
  173. <return type="void" />
  174. <param index="0" name="idx" type="int" />
  175. <param index="1" name="disabled" type="bool" />
  176. <description>
  177. Sets whether the item at index [param idx] is disabled.
  178. 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.
  179. </description>
  180. </method>
  181. <method name="set_item_icon">
  182. <return type="void" />
  183. <param index="0" name="idx" type="int" />
  184. <param index="1" name="texture" type="Texture2D" />
  185. <description>
  186. Sets the icon of the item at index [param idx].
  187. </description>
  188. </method>
  189. <method name="set_item_id">
  190. <return type="void" />
  191. <param index="0" name="idx" type="int" />
  192. <param index="1" name="id" type="int" />
  193. <description>
  194. Sets the ID of the item at index [param idx].
  195. </description>
  196. </method>
  197. <method name="set_item_metadata">
  198. <return type="void" />
  199. <param index="0" name="idx" type="int" />
  200. <param index="1" name="metadata" type="Variant" />
  201. <description>
  202. 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.
  203. </description>
  204. </method>
  205. <method name="set_item_text">
  206. <return type="void" />
  207. <param index="0" name="idx" type="int" />
  208. <param index="1" name="text" type="String" />
  209. <description>
  210. Sets the text of the item at index [param idx].
  211. </description>
  212. </method>
  213. <method name="set_item_tooltip">
  214. <return type="void" />
  215. <param index="0" name="idx" type="int" />
  216. <param index="1" name="tooltip" type="String" />
  217. <description>
  218. Sets the tooltip of the item at index [param idx].
  219. </description>
  220. </method>
  221. <method name="show_popup">
  222. <return type="void" />
  223. <description>
  224. Adjusts popup position and sizing for the [OptionButton], then shows the [PopupMenu]. Prefer this over using [code]get_popup().popup()[/code].
  225. </description>
  226. </method>
  227. </methods>
  228. <members>
  229. <member name="action_mode" type="int" setter="set_action_mode" getter="get_action_mode" overrides="BaseButton" enum="BaseButton.ActionMode" default="0" />
  230. <member name="alignment" type="int" setter="set_text_alignment" getter="get_text_alignment" overrides="Button" enum="HorizontalAlignment" default="0" />
  231. <member name="allow_reselect" type="bool" setter="set_allow_reselect" getter="get_allow_reselect" default="false">
  232. If [code]true[/code], the currently selected item can be selected again.
  233. </member>
  234. <member name="fit_to_longest_item" type="bool" setter="set_fit_to_longest_item" getter="is_fit_to_longest_item" default="true">
  235. If [code]true[/code], minimum size will be determined by the longest item's text, instead of the currently selected one's.
  236. [b]Note:[/b] For performance reasons, the minimum size doesn't update immediately when adding, removing or modifying items.
  237. </member>
  238. <member name="item_count" type="int" setter="set_item_count" getter="get_item_count" default="0">
  239. The number of items to select from.
  240. </member>
  241. <member name="selected" type="int" setter="_select_int" getter="get_selected" default="-1">
  242. The index of the currently selected item, or [code]-1[/code] if no item is selected.
  243. </member>
  244. <member name="toggle_mode" type="bool" setter="set_toggle_mode" getter="is_toggle_mode" overrides="BaseButton" default="true" />
  245. </members>
  246. <signals>
  247. <signal name="item_focused">
  248. <param index="0" name="index" type="int" />
  249. <description>
  250. Emitted when the user navigates to an item using the [member ProjectSettings.input/ui_up] or [member ProjectSettings.input/ui_down] input actions. The index of the item selected is passed as argument.
  251. </description>
  252. </signal>
  253. <signal name="item_selected">
  254. <param index="0" name="index" type="int" />
  255. <description>
  256. Emitted when the current item has been changed by the user. The index of the item selected is passed as argument.
  257. [member allow_reselect] must be enabled to reselect an item.
  258. </description>
  259. </signal>
  260. </signals>
  261. <theme_items>
  262. <theme_item name="arrow_margin" data_type="constant" type="int" default="4">
  263. The horizontal space between the arrow icon and the right edge of the button.
  264. </theme_item>
  265. <theme_item name="modulate_arrow" data_type="constant" type="int" default="0">
  266. If different than [code]0[/code], the arrow icon will be modulated to the font color.
  267. </theme_item>
  268. <theme_item name="arrow" data_type="icon" type="Texture2D">
  269. The arrow icon to be drawn on the right end of the button.
  270. </theme_item>
  271. </theme_items>
  272. </class>