class_tree.rst 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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. - **cell_selected** **(** **)**
  86. - **custom_popup_edited** **(** :ref:`bool<class_bool>` arrow_clicked **)**
  87. - **empty_tree_rmb_selected** **(** :ref:`Vector2<class_vector2>` pos **)**
  88. - **item_activated** **(** **)**
  89. - **item_collapsed** **(** :ref:`Object<class_object>` item **)**
  90. - **item_edited** **(** **)**
  91. - **item_rmb_selected** **(** :ref:`Vector2<class_vector2>` pos **)**
  92. - **item_selected** **(** **)**
  93. - **multi_selected** **(** :ref:`Object<class_object>` item, :ref:`int<class_int>` column, :ref:`bool<class_bool>` selected **)**
  94. Numeric Constants
  95. -----------------
  96. - **SELECT_SINGLE** = **0**
  97. - **SELECT_ROW** = **1**
  98. - **SELECT_MULTI** = **2**
  99. - **DROP_MODE_DISABLED** = **0**
  100. - **DROP_MODE_ON_ITEM** = **1**
  101. - **DROP_MODE_INBETWEEN** = **2**
  102. Description
  103. -----------
  104. 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.
  105. 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.
  106. ::
  107. func _ready():
  108. var tree = Tree.new()
  109. var root = tree.create_item()
  110. tree.set_hide_root(true)
  111. var child1 = tree.create_item(root)
  112. var child2 = tree.create_item(root)
  113. var subchild1 = tree.create_item(child1)
  114. subchild1.set_text(0, "Subchild1")
  115. Member Function Description
  116. ---------------------------
  117. .. _class_Tree_are_column_titles_visible:
  118. - :ref:`bool<class_bool>` **are_column_titles_visible** **(** **)** const
  119. Get whether the column titles are being shown.
  120. .. _class_Tree_clear:
  121. - void **clear** **(** **)**
  122. Clear the tree. This erases all of the items.
  123. .. _class_Tree_create_item:
  124. - :ref:`TreeItem<class_treeitem>` **create_item** **(** :ref:`TreeItem<class_treeitem>` parent=NULL **)**
  125. 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.
  126. .. _class_Tree_ensure_cursor_is_visible:
  127. - void **ensure_cursor_is_visible** **(** **)**
  128. Make the current selected item visible. This will scroll the tree to make sure the selected item is in sight.
  129. .. _class_Tree_get_allow_rmb_select:
  130. - :ref:`bool<class_bool>` **get_allow_rmb_select** **(** **)** const
  131. Get whether a right click can select items.
  132. .. _class_Tree_get_column_at_pos:
  133. - :ref:`int<class_int>` **get_column_at_pos** **(** :ref:`Vector2<class_vector2>` pos **)** const
  134. Get the column index under the given point.
  135. .. _class_Tree_get_column_title:
  136. - :ref:`String<class_string>` **get_column_title** **(** :ref:`int<class_int>` column **)** const
  137. Get the title of the given column.
  138. .. _class_Tree_get_column_width:
  139. - :ref:`int<class_int>` **get_column_width** **(** :ref:`int<class_int>` column **)** const
  140. Get the width of the given column in pixels.
  141. .. _class_Tree_get_columns:
  142. - :ref:`int<class_int>` **get_columns** **(** **)** const
  143. Get the amount of columns.
  144. .. _class_Tree_get_custom_popup_rect:
  145. - :ref:`Rect2<class_rect2>` **get_custom_popup_rect** **(** **)** const
  146. 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>`.
  147. .. _class_Tree_get_drop_mode_flags:
  148. - :ref:`int<class_int>` **get_drop_mode_flags** **(** **)** const
  149. Get the flags of the current drop mode.
  150. .. _class_Tree_get_edited:
  151. - :ref:`TreeItem<class_treeitem>` **get_edited** **(** **)** const
  152. Get the current edited item. This is only available for custom cell mode.
  153. .. _class_Tree_get_edited_column:
  154. - :ref:`int<class_int>` **get_edited_column** **(** **)** const
  155. Get the column of the cell for the current edited icon. This is only available for custom cell mode.
  156. .. _class_Tree_get_item_area_rect:
  157. - :ref:`Rect2<class_rect2>` **get_item_area_rect** **(** :ref:`TreeItem<class_treeitem>` item, :ref:`int<class_int>` column=-1 **)** const
  158. 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.
  159. .. _class_Tree_get_item_at_pos:
  160. - :ref:`TreeItem<class_treeitem>` **get_item_at_pos** **(** :ref:`Vector2<class_vector2>` pos **)** const
  161. Get the tree item at the specified position (relative to the tree origin position).
  162. .. _class_Tree_get_next_selected:
  163. - :ref:`TreeItem<class_treeitem>` **get_next_selected** **(** :ref:`TreeItem<class_treeitem>` from **)**
  164. Get the next selected item after the given one.
  165. .. _class_Tree_get_pressed_button:
  166. - :ref:`int<class_int>` **get_pressed_button** **(** **)** const
  167. Get the index of the last pressed button.
  168. .. _class_Tree_get_root:
  169. - :ref:`TreeItem<class_treeitem>` **get_root** **(** **)**
  170. Get the root item of the tree.
  171. .. _class_Tree_get_scroll:
  172. - :ref:`Vector2<class_vector2>` **get_scroll** **(** **)** const
  173. Get the current scrolling position.
  174. .. _class_Tree_get_selected:
  175. - :ref:`TreeItem<class_treeitem>` **get_selected** **(** **)** const
  176. Get the currently selected item.
  177. .. _class_Tree_get_selected_column:
  178. - :ref:`int<class_int>` **get_selected_column** **(** **)** const
  179. Get the column number of the current selection.
  180. .. _class_Tree_get_single_select_cell_editing_only_when_already_selected:
  181. - :ref:`bool<class_bool>` **get_single_select_cell_editing_only_when_already_selected** **(** **)** const
  182. Get whether the editing of a cell should only happen when it is already selected.
  183. .. _class_Tree_is_folding_hidden:
  184. - :ref:`bool<class_bool>` **is_folding_hidden** **(** **)** const
  185. Get whether the folding arrow is hidden.
  186. .. _class_Tree_set_allow_rmb_select:
  187. - void **set_allow_rmb_select** **(** :ref:`bool<class_bool>` allow **)**
  188. Set whether or not a right mouse button click can select items.
  189. .. _class_Tree_set_column_expand:
  190. - void **set_column_expand** **(** :ref:`int<class_int>` column, :ref:`bool<class_bool>` expand **)**
  191. Set whether a column will have the "Expand" flag of :ref:`Control<class_control>`.
  192. .. _class_Tree_set_column_min_width:
  193. - void **set_column_min_width** **(** :ref:`int<class_int>` column, :ref:`int<class_int>` min_width **)**
  194. Set the minimum width of a column.
  195. .. _class_Tree_set_column_title:
  196. - void **set_column_title** **(** :ref:`int<class_int>` column, :ref:`String<class_string>` title **)**
  197. Set the title of a column.
  198. .. _class_Tree_set_column_titles_visible:
  199. - void **set_column_titles_visible** **(** :ref:`bool<class_bool>` visible **)**
  200. Set whether the column titles visibility.
  201. .. _class_Tree_set_columns:
  202. - void **set_columns** **(** :ref:`int<class_int>` amount **)**
  203. Set the amount of columns.
  204. .. _class_Tree_set_drop_mode_flags:
  205. - void **set_drop_mode_flags** **(** :ref:`int<class_int>` flags **)**
  206. Set the drop mode as an OR combination of flags. See ``DROP_MODE\_\*`` constants.
  207. .. _class_Tree_set_hide_folding:
  208. - void **set_hide_folding** **(** :ref:`bool<class_bool>` hide **)**
  209. Set whether the folding arrow should be hidden.
  210. .. _class_Tree_set_hide_root:
  211. - void **set_hide_root** **(** :ref:`bool<class_bool>` enable **)**
  212. Set whether the root of the tree should be hidden.
  213. .. _class_Tree_set_select_mode:
  214. - void **set_select_mode** **(** :ref:`int<class_int>` mode **)**
  215. Set the selection mode. Use one of the ``SELECT\_\*`` constants.
  216. .. _class_Tree_set_single_select_cell_editing_only_when_already_selected:
  217. - void **set_single_select_cell_editing_only_when_already_selected** **(** :ref:`bool<class_bool>` enable **)**
  218. Set whether the editing of a cell should only happen when it is already selected.