class_tree.rst 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  2. .. DO NOT EDIT THIS FILE, but the doc/base/classes.xml source instead.
  3. .. _class_Tree:
  4. Tree
  5. ====
  6. **Inherits:** :ref:`Control<class_control>` **<** :ref:`CanvasItem<class_canvasitem>` **<** :ref:`Node<class_node>` **<** :ref:`Object<class_object>`
  7. **Category:** Core
  8. Brief Description
  9. -----------------
  10. Control to show a tree of items.
  11. Member Functions
  12. ----------------
  13. +----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  14. | :ref:`bool<class_bool>` | :ref:`are_column_titles_visible<class_Tree_are_column_titles_visible>` **(** **)** const |
  15. +----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  16. | void | :ref:`clear<class_Tree_clear>` **(** **)** |
  17. +----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  18. | :ref:`TreeItem<class_treeitem>` | :ref:`create_item<class_Tree_create_item>` **(** :ref:`TreeItem<class_treeitem>` parent=NULL **)** |
  19. +----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  20. | void | :ref:`ensure_cursor_is_visible<class_Tree_ensure_cursor_is_visible>` **(** **)** |
  21. +----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  22. | :ref:`bool<class_bool>` | :ref:`get_allow_rmb_select<class_Tree_get_allow_rmb_select>` **(** **)** const |
  23. +----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  24. | :ref:`int<class_int>` | :ref:`get_column_at_pos<class_Tree_get_column_at_pos>` **(** :ref:`Vector2<class_vector2>` pos **)** const |
  25. +----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  26. | :ref:`String<class_string>` | :ref:`get_column_title<class_Tree_get_column_title>` **(** :ref:`int<class_int>` column **)** const |
  27. +----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  28. | :ref:`int<class_int>` | :ref:`get_column_width<class_Tree_get_column_width>` **(** :ref:`int<class_int>` column **)** const |
  29. +----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  30. | :ref:`int<class_int>` | :ref:`get_columns<class_Tree_get_columns>` **(** **)** const |
  31. +----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  32. | :ref:`Rect2<class_rect2>` | :ref:`get_custom_popup_rect<class_Tree_get_custom_popup_rect>` **(** **)** const |
  33. +----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  34. | :ref:`int<class_int>` | :ref:`get_drop_mode_flags<class_Tree_get_drop_mode_flags>` **(** **)** const |
  35. +----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  36. | :ref:`TreeItem<class_treeitem>` | :ref:`get_edited<class_Tree_get_edited>` **(** **)** const |
  37. +----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  38. | :ref:`int<class_int>` | :ref:`get_edited_column<class_Tree_get_edited_column>` **(** **)** const |
  39. +----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  40. | :ref:`Rect2<class_rect2>` | :ref:`get_item_area_rect<class_Tree_get_item_area_rect>` **(** :ref:`TreeItem<class_treeitem>` item, :ref:`int<class_int>` column=-1 **)** const |
  41. +----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  42. | :ref:`TreeItem<class_treeitem>` | :ref:`get_item_at_pos<class_Tree_get_item_at_pos>` **(** :ref:`Vector2<class_vector2>` pos **)** const |
  43. +----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  44. | :ref:`TreeItem<class_treeitem>` | :ref:`get_next_selected<class_Tree_get_next_selected>` **(** :ref:`TreeItem<class_treeitem>` from **)** |
  45. +----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  46. | :ref:`int<class_int>` | :ref:`get_pressed_button<class_Tree_get_pressed_button>` **(** **)** const |
  47. +----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  48. | :ref:`TreeItem<class_treeitem>` | :ref:`get_root<class_Tree_get_root>` **(** **)** |
  49. +----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  50. | :ref:`Vector2<class_vector2>` | :ref:`get_scroll<class_Tree_get_scroll>` **(** **)** const |
  51. +----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  52. | :ref:`TreeItem<class_treeitem>` | :ref:`get_selected<class_Tree_get_selected>` **(** **)** const |
  53. +----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  54. | :ref:`int<class_int>` | :ref:`get_selected_column<class_Tree_get_selected_column>` **(** **)** const |
  55. +----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  56. | :ref:`bool<class_bool>` | :ref:`get_single_select_cell_editing_only_when_already_selected<class_Tree_get_single_select_cell_editing_only_when_already_selected>` **(** **)** const |
  57. +----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  58. | :ref:`bool<class_bool>` | :ref:`is_folding_hidden<class_Tree_is_folding_hidden>` **(** **)** const |
  59. +----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  60. | void | :ref:`set_allow_rmb_select<class_Tree_set_allow_rmb_select>` **(** :ref:`bool<class_bool>` allow **)** |
  61. +----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  62. | void | :ref:`set_column_expand<class_Tree_set_column_expand>` **(** :ref:`int<class_int>` column, :ref:`bool<class_bool>` expand **)** |
  63. +----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  64. | void | :ref:`set_column_min_width<class_Tree_set_column_min_width>` **(** :ref:`int<class_int>` column, :ref:`int<class_int>` min_width **)** |
  65. +----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  66. | void | :ref:`set_column_title<class_Tree_set_column_title>` **(** :ref:`int<class_int>` column, :ref:`String<class_string>` title **)** |
  67. +----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  68. | void | :ref:`set_column_titles_visible<class_Tree_set_column_titles_visible>` **(** :ref:`bool<class_bool>` visible **)** |
  69. +----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  70. | void | :ref:`set_columns<class_Tree_set_columns>` **(** :ref:`int<class_int>` amount **)** |
  71. +----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  72. | void | :ref:`set_drop_mode_flags<class_Tree_set_drop_mode_flags>` **(** :ref:`int<class_int>` flags **)** |
  73. +----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  74. | void | :ref:`set_hide_folding<class_Tree_set_hide_folding>` **(** :ref:`bool<class_bool>` hide **)** |
  75. +----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  76. | void | :ref:`set_hide_root<class_Tree_set_hide_root>` **(** :ref:`bool<class_bool>` enable **)** |
  77. +----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  78. | void | :ref:`set_select_mode<class_Tree_set_select_mode>` **(** :ref:`int<class_int>` mode **)** |
  79. +----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  80. | void | :ref:`set_single_select_cell_editing_only_when_already_selected<class_Tree_set_single_select_cell_editing_only_when_already_selected>` **(** :ref:`bool<class_bool>` enable **)** |
  81. +----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  82. Signals
  83. -------
  84. - **button_pressed** **(** :ref:`Object<class_object>` item, :ref:`int<class_int>` column, :ref:`int<class_int>` id **)**
  85. Emitted when a button on the tree was pressed (see :ref:`TreeItem.add_button<class_TreeItem_add_button>`).
  86. - **cell_selected** **(** **)**
  87. Emitted when a cell is selected.
  88. - **column_title_pressed** **(** :ref:`int<class_int>` column **)**
  89. - **custom_popup_edited** **(** :ref:`bool<class_bool>` arrow_clicked **)**
  90. Emitted when a cell with the ``CELL_MODE_CUSTOM`` is clicked to be edited.
  91. - **empty_tree_rmb_selected** **(** :ref:`Vector2<class_vector2>` pos **)**
  92. Emitted when the right mouse button is pressed if RMB selection is active and the tree is empty.
  93. - **item_activated** **(** **)**
  94. Emitted when an item is activated (double-clicked).
  95. - **item_collapsed** **(** :ref:`Object<class_object>` item **)**
  96. Emitted when an item is collapsed by a click on the folding arrow.
  97. - **item_edited** **(** **)**
  98. Emitted when an item is editted.
  99. - **item_rmb_selected** **(** :ref:`Vector2<class_vector2>` pos **)**
  100. Emitted when an item is selected with right mouse button.
  101. - **item_selected** **(** **)**
  102. Emitted when an item is selected with right mouse button.
  103. - **multi_selected** **(** :ref:`Object<class_object>` item, :ref:`int<class_int>` column, :ref:`bool<class_bool>` selected **)**
  104. Numeric Constants
  105. -----------------
  106. - **SELECT_SINGLE** = **0**
  107. - **SELECT_ROW** = **1**
  108. - **SELECT_MULTI** = **2**
  109. - **DROP_MODE_DISABLED** = **0**
  110. - **DROP_MODE_ON_ITEM** = **1**
  111. - **DROP_MODE_INBETWEEN** = **2**
  112. Description
  113. -----------
  114. This shows a tree of items that can be selected, expanded and collapsed. The tree can have multiple columns with custom controls like text editing, buttons and popups. It can be useful for structural displaying and interactions.
  115. Trees are built via code, using :ref:`TreeItem<class_treeitem>` objects to create the structure. They have a single root but multiple root can be simulated if a dummy hidden root is added.
  116. ::
  117. func _ready():
  118. var tree = Tree.new()
  119. var root = tree.create_item()
  120. tree.set_hide_root(true)
  121. var child1 = tree.create_item(root)
  122. var child2 = tree.create_item(root)
  123. var subchild1 = tree.create_item(child1)
  124. subchild1.set_text(0, "Subchild1")
  125. Member Function Description
  126. ---------------------------
  127. .. _class_Tree_are_column_titles_visible:
  128. - :ref:`bool<class_bool>` **are_column_titles_visible** **(** **)** const
  129. Get whether the column titles are being shown.
  130. .. _class_Tree_clear:
  131. - void **clear** **(** **)**
  132. Clear the tree. This erases all of the items.
  133. .. _class_Tree_create_item:
  134. - :ref:`TreeItem<class_treeitem>` **create_item** **(** :ref:`TreeItem<class_treeitem>` parent=NULL **)**
  135. Create an item in the tree and add it as the last child of ``parent``. If parent is not given, it will be added as the last child of the root, or it'll the be the root itself if the tree is empty.
  136. .. _class_Tree_ensure_cursor_is_visible:
  137. - void **ensure_cursor_is_visible** **(** **)**
  138. Make the current selected item visible. This will scroll the tree to make sure the selected item is in sight.
  139. .. _class_Tree_get_allow_rmb_select:
  140. - :ref:`bool<class_bool>` **get_allow_rmb_select** **(** **)** const
  141. Get whether a right click can select items.
  142. .. _class_Tree_get_column_at_pos:
  143. - :ref:`int<class_int>` **get_column_at_pos** **(** :ref:`Vector2<class_vector2>` pos **)** const
  144. Get the column index under the given point.
  145. .. _class_Tree_get_column_title:
  146. - :ref:`String<class_string>` **get_column_title** **(** :ref:`int<class_int>` column **)** const
  147. Get the title of the given column.
  148. .. _class_Tree_get_column_width:
  149. - :ref:`int<class_int>` **get_column_width** **(** :ref:`int<class_int>` column **)** const
  150. Get the width of the given column in pixels.
  151. .. _class_Tree_get_columns:
  152. - :ref:`int<class_int>` **get_columns** **(** **)** const
  153. Get the amount of columns.
  154. .. _class_Tree_get_custom_popup_rect:
  155. - :ref:`Rect2<class_rect2>` **get_custom_popup_rect** **(** **)** const
  156. Get the rectangle for custom popups. Helper to create custom cell controls that display a popup. See :ref:`TreeItem.set_cell_mode<class_TreeItem_set_cell_mode>`.
  157. .. _class_Tree_get_drop_mode_flags:
  158. - :ref:`int<class_int>` **get_drop_mode_flags** **(** **)** const
  159. Get the flags of the current drop mode.
  160. .. _class_Tree_get_edited:
  161. - :ref:`TreeItem<class_treeitem>` **get_edited** **(** **)** const
  162. Get the current edited item. This is only available for custom cell mode.
  163. .. _class_Tree_get_edited_column:
  164. - :ref:`int<class_int>` **get_edited_column** **(** **)** const
  165. Get the column of the cell for the current edited icon. This is only available for custom cell mode.
  166. .. _class_Tree_get_item_area_rect:
  167. - :ref:`Rect2<class_rect2>` **get_item_area_rect** **(** :ref:`TreeItem<class_treeitem>` item, :ref:`int<class_int>` column=-1 **)** const
  168. Get the rectangle area of the the specified item. If column is specified, only get the position and size of that column, otherwise get the rectangle containing all columns.
  169. .. _class_Tree_get_item_at_pos:
  170. - :ref:`TreeItem<class_treeitem>` **get_item_at_pos** **(** :ref:`Vector2<class_vector2>` pos **)** const
  171. Get the tree item at the specified position (relative to the tree origin position).
  172. .. _class_Tree_get_next_selected:
  173. - :ref:`TreeItem<class_treeitem>` **get_next_selected** **(** :ref:`TreeItem<class_treeitem>` from **)**
  174. Get the next selected item after the given one.
  175. .. _class_Tree_get_pressed_button:
  176. - :ref:`int<class_int>` **get_pressed_button** **(** **)** const
  177. Get the index of the last pressed button.
  178. .. _class_Tree_get_root:
  179. - :ref:`TreeItem<class_treeitem>` **get_root** **(** **)**
  180. Get the root item of the tree.
  181. .. _class_Tree_get_scroll:
  182. - :ref:`Vector2<class_vector2>` **get_scroll** **(** **)** const
  183. Get the current scrolling position.
  184. .. _class_Tree_get_selected:
  185. - :ref:`TreeItem<class_treeitem>` **get_selected** **(** **)** const
  186. Get the currently selected item.
  187. .. _class_Tree_get_selected_column:
  188. - :ref:`int<class_int>` **get_selected_column** **(** **)** const
  189. Get the column number of the current selection.
  190. .. _class_Tree_get_single_select_cell_editing_only_when_already_selected:
  191. - :ref:`bool<class_bool>` **get_single_select_cell_editing_only_when_already_selected** **(** **)** const
  192. Get whether the editing of a cell should only happen when it is already selected.
  193. .. _class_Tree_is_folding_hidden:
  194. - :ref:`bool<class_bool>` **is_folding_hidden** **(** **)** const
  195. Get whether the folding arrow is hidden.
  196. .. _class_Tree_set_allow_rmb_select:
  197. - void **set_allow_rmb_select** **(** :ref:`bool<class_bool>` allow **)**
  198. Set whether or not a right mouse button click can select items.
  199. .. _class_Tree_set_column_expand:
  200. - void **set_column_expand** **(** :ref:`int<class_int>` column, :ref:`bool<class_bool>` expand **)**
  201. Set whether a column will have the "Expand" flag of :ref:`Control<class_control>`.
  202. .. _class_Tree_set_column_min_width:
  203. - void **set_column_min_width** **(** :ref:`int<class_int>` column, :ref:`int<class_int>` min_width **)**
  204. Set the minimum width of a column.
  205. .. _class_Tree_set_column_title:
  206. - void **set_column_title** **(** :ref:`int<class_int>` column, :ref:`String<class_string>` title **)**
  207. Set the title of a column.
  208. .. _class_Tree_set_column_titles_visible:
  209. - void **set_column_titles_visible** **(** :ref:`bool<class_bool>` visible **)**
  210. Set whether the column titles visibility.
  211. .. _class_Tree_set_columns:
  212. - void **set_columns** **(** :ref:`int<class_int>` amount **)**
  213. Set the amount of columns.
  214. .. _class_Tree_set_drop_mode_flags:
  215. - void **set_drop_mode_flags** **(** :ref:`int<class_int>` flags **)**
  216. Set the drop mode as an OR combination of flags. See ``DROP_MODE\_\*`` constants.
  217. .. _class_Tree_set_hide_folding:
  218. - void **set_hide_folding** **(** :ref:`bool<class_bool>` hide **)**
  219. Set whether the folding arrow should be hidden.
  220. .. _class_Tree_set_hide_root:
  221. - void **set_hide_root** **(** :ref:`bool<class_bool>` enable **)**
  222. Set whether the root of the tree should be hidden.
  223. .. _class_Tree_set_select_mode:
  224. - void **set_select_mode** **(** :ref:`int<class_int>` mode **)**
  225. Set the selection mode. Use one of the ``SELECT\_\*`` constants.
  226. .. _class_Tree_set_single_select_cell_editing_only_when_already_selected:
  227. - void **set_single_select_cell_editing_only_when_already_selected** **(** :ref:`bool<class_bool>` enable **)**
  228. Set whether the editing of a cell should only happen when it is already selected.