class_tree.rst 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  2. .. DO NOT EDIT THIS FILE, but the Tree.xml source instead.
  3. .. The source is found in doc/classes or modules/<name>/doc_classes.
  4. .. _class_Tree:
  5. Tree
  6. ====
  7. **Inherits:** :ref:`Control<class_control>` **<** :ref:`CanvasItem<class_canvasitem>` **<** :ref:`Node<class_node>` **<** :ref:`Object<class_object>`
  8. **Category:** Core
  9. Brief Description
  10. -----------------
  11. Control to show a tree of items.
  12. Member Functions
  13. ----------------
  14. +----------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  15. | :ref:`bool<class_bool>` | :ref:`are_column_titles_visible<class_Tree_are_column_titles_visible>` **(** **)** const |
  16. +----------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  17. | void | :ref:`clear<class_Tree_clear>` **(** **)** |
  18. +----------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  19. | :ref:`Object<class_object>` | :ref:`create_item<class_Tree_create_item>` **(** :ref:`Object<class_object>` parent=null, :ref:`int<class_int>` idx=-1 **)** |
  20. +----------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  21. | void | :ref:`ensure_cursor_is_visible<class_Tree_ensure_cursor_is_visible>` **(** **)** |
  22. +----------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  23. | :ref:`int<class_int>` | :ref:`get_column_at_position<class_Tree_get_column_at_position>` **(** :ref:`Vector2<class_vector2>` position **)** const |
  24. +----------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  25. | :ref:`String<class_string>` | :ref:`get_column_title<class_Tree_get_column_title>` **(** :ref:`int<class_int>` column **)** const |
  26. +----------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  27. | :ref:`int<class_int>` | :ref:`get_column_width<class_Tree_get_column_width>` **(** :ref:`int<class_int>` column **)** const |
  28. +----------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  29. | :ref:`Rect2<class_rect2>` | :ref:`get_custom_popup_rect<class_Tree_get_custom_popup_rect>` **(** **)** const |
  30. +----------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  31. | :ref:`int<class_int>` | :ref:`get_drop_section_at_position<class_Tree_get_drop_section_at_position>` **(** :ref:`Vector2<class_vector2>` position **)** const |
  32. +----------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  33. | :ref:`TreeItem<class_treeitem>` | :ref:`get_edited<class_Tree_get_edited>` **(** **)** const |
  34. +----------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  35. | :ref:`int<class_int>` | :ref:`get_edited_column<class_Tree_get_edited_column>` **(** **)** const |
  36. +----------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  37. | :ref:`Rect2<class_rect2>` | :ref:`get_item_area_rect<class_Tree_get_item_area_rect>` **(** :ref:`Object<class_object>` item, :ref:`int<class_int>` column=-1 **)** const |
  38. +----------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  39. | :ref:`TreeItem<class_treeitem>` | :ref:`get_item_at_position<class_Tree_get_item_at_position>` **(** :ref:`Vector2<class_vector2>` position **)** const |
  40. +----------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`TreeItem<class_treeitem>` | :ref:`get_next_selected<class_Tree_get_next_selected>` **(** :ref:`Object<class_object>` from **)** |
  42. +----------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  43. | :ref:`int<class_int>` | :ref:`get_pressed_button<class_Tree_get_pressed_button>` **(** **)** const |
  44. +----------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`TreeItem<class_treeitem>` | :ref:`get_root<class_Tree_get_root>` **(** **)** |
  46. +----------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  47. | :ref:`Vector2<class_vector2>` | :ref:`get_scroll<class_Tree_get_scroll>` **(** **)** const |
  48. +----------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  49. | :ref:`TreeItem<class_treeitem>` | :ref:`get_selected<class_Tree_get_selected>` **(** **)** const |
  50. +----------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  51. | :ref:`int<class_int>` | :ref:`get_selected_column<class_Tree_get_selected_column>` **(** **)** const |
  52. +----------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  53. | void | :ref:`set_column_expand<class_Tree_set_column_expand>` **(** :ref:`int<class_int>` column, :ref:`bool<class_bool>` expand **)** |
  54. +----------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  55. | void | :ref:`set_column_min_width<class_Tree_set_column_min_width>` **(** :ref:`int<class_int>` column, :ref:`int<class_int>` min_width **)** |
  56. +----------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  57. | void | :ref:`set_column_title<class_Tree_set_column_title>` **(** :ref:`int<class_int>` column, :ref:`String<class_string>` title **)** |
  58. +----------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  59. | void | :ref:`set_column_titles_visible<class_Tree_set_column_titles_visible>` **(** :ref:`bool<class_bool>` visible **)** |
  60. +----------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
  61. Signals
  62. -------
  63. .. _class_Tree_button_pressed:
  64. - **button_pressed** **(** :ref:`Object<class_object>` item, :ref:`int<class_int>` column, :ref:`int<class_int>` id **)**
  65. Emitted when a button on the tree was pressed (see :ref:`TreeItem.add_button<class_TreeItem_add_button>`).
  66. .. _class_Tree_cell_selected:
  67. - **cell_selected** **(** **)**
  68. Emitted when a cell is selected.
  69. .. _class_Tree_column_title_pressed:
  70. - **column_title_pressed** **(** :ref:`int<class_int>` column **)**
  71. Emitted when a column's title is pressed.
  72. .. _class_Tree_custom_popup_edited:
  73. - **custom_popup_edited** **(** :ref:`bool<class_bool>` arrow_clicked **)**
  74. Emitted when a cell with the ``CELL_MODE_CUSTOM`` is clicked to be edited.
  75. .. _class_Tree_empty_tree_rmb_selected:
  76. - **empty_tree_rmb_selected** **(** :ref:`Vector2<class_vector2>` position **)**
  77. Emitted when the right mouse button is pressed if RMB selection is active and the tree is empty.
  78. .. _class_Tree_item_activated:
  79. - **item_activated** **(** **)**
  80. Emitted when an item is activated (double-clicked).
  81. .. _class_Tree_item_collapsed:
  82. - **item_collapsed** **(** :ref:`Object<class_object>` item **)**
  83. Emitted when an item is collapsed by a click on the folding arrow.
  84. .. _class_Tree_item_custom_button_pressed:
  85. - **item_custom_button_pressed** **(** **)**
  86. .. _class_Tree_item_double_clicked:
  87. - **item_double_clicked** **(** **)**
  88. Emitted when an item is double clicked.
  89. .. _class_Tree_item_edited:
  90. - **item_edited** **(** **)**
  91. Emitted when an item is edited.
  92. .. _class_Tree_item_rmb_edited:
  93. - **item_rmb_edited** **(** **)**
  94. Emitted when an item is edited using the right mouse button.
  95. .. _class_Tree_item_rmb_selected:
  96. - **item_rmb_selected** **(** :ref:`Vector2<class_vector2>` position **)**
  97. Emitted when an item is selected with right mouse button.
  98. .. _class_Tree_item_selected:
  99. - **item_selected** **(** **)**
  100. Emitted when an item is selected with right mouse button.
  101. .. _class_Tree_multi_selected:
  102. - **multi_selected** **(** :ref:`Object<class_object>` item, :ref:`int<class_int>` column, :ref:`bool<class_bool>` selected **)**
  103. Emitted instead of ``item_selected`` when ``select_mode`` is ``SELECT_MULTI``.
  104. .. _class_Tree_nothing_selected:
  105. - **nothing_selected** **(** **)**
  106. Member Variables
  107. ----------------
  108. .. _class_Tree_allow_reselect:
  109. - :ref:`bool<class_bool>` **allow_reselect** - If ``true`` the currently selected cell may be selected again.
  110. .. _class_Tree_allow_rmb_select:
  111. - :ref:`bool<class_bool>` **allow_rmb_select** - If ``true`` a right mouse button click can select items.
  112. .. _class_Tree_columns:
  113. - :ref:`int<class_int>` **columns** - The amount of columns.
  114. .. _class_Tree_drop_mode_flags:
  115. - :ref:`int<class_int>` **drop_mode_flags** - The drop mode as an OR combination of flags. See ``DROP_MODE_*`` constants.
  116. .. _class_Tree_hide_folding:
  117. - :ref:`bool<class_bool>` **hide_folding** - If ``true`` the folding arrow is hidden.
  118. .. _class_Tree_hide_root:
  119. - :ref:`bool<class_bool>` **hide_root** - If ``true`` the tree's root is hidden.
  120. .. _class_Tree_select_mode:
  121. - :ref:`SelectMode<enum_tree_selectmode>` **select_mode** - Allow single or multiple selection. See the ``SELECT_*`` constants.
  122. Enums
  123. -----
  124. .. _enum_Tree_DropModeFlags:
  125. enum **DropModeFlags**
  126. - **DROP_MODE_DISABLED** = **0**
  127. - **DROP_MODE_ON_ITEM** = **1**
  128. - **DROP_MODE_INBETWEEN** = **2**
  129. .. _enum_Tree_SelectMode:
  130. enum **SelectMode**
  131. - **SELECT_SINGLE** = **0** --- Allow selection of a single item at a time.
  132. - **SELECT_ROW** = **1**
  133. - **SELECT_MULTI** = **2** --- Allow selection of multiple items at the same time.
  134. Description
  135. -----------
  136. 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 structured displays and interactions.
  137. Trees are built via code, using :ref:`TreeItem<class_treeitem>` objects to create the structure. They have a single root but multiple roots can be simulated if a dummy hidden root is added.
  138. ::
  139. func _ready():
  140. var tree = Tree.new()
  141. var root = tree.create_item()
  142. tree.set_hide_root(true)
  143. var child1 = tree.create_item(root)
  144. var child2 = tree.create_item(root)
  145. var subchild1 = tree.create_item(child1)
  146. subchild1.set_text(0, "Subchild1")
  147. Member Function Description
  148. ---------------------------
  149. .. _class_Tree_are_column_titles_visible:
  150. - :ref:`bool<class_bool>` **are_column_titles_visible** **(** **)** const
  151. Returns ``true`` if the column titles are being shown.
  152. .. _class_Tree_clear:
  153. - void **clear** **(** **)**
  154. Clears the tree. This removes all items.
  155. .. _class_Tree_create_item:
  156. - :ref:`Object<class_object>` **create_item** **(** :ref:`Object<class_object>` parent=null, :ref:`int<class_int>` idx=-1 **)**
  157. 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 root's last child, or it'll the be the root itself if the tree is empty.
  158. .. _class_Tree_ensure_cursor_is_visible:
  159. - void **ensure_cursor_is_visible** **(** **)**
  160. Makes the currently selected item visible. This will scroll the tree to make sure the selected item is visible.
  161. .. _class_Tree_get_column_at_position:
  162. - :ref:`int<class_int>` **get_column_at_position** **(** :ref:`Vector2<class_vector2>` position **)** const
  163. Returns the column index under the given point.
  164. .. _class_Tree_get_column_title:
  165. - :ref:`String<class_string>` **get_column_title** **(** :ref:`int<class_int>` column **)** const
  166. Returns the column's title.
  167. .. _class_Tree_get_column_width:
  168. - :ref:`int<class_int>` **get_column_width** **(** :ref:`int<class_int>` column **)** const
  169. Returns the column's width in pixels.
  170. .. _class_Tree_get_custom_popup_rect:
  171. - :ref:`Rect2<class_rect2>` **get_custom_popup_rect** **(** **)** const
  172. Returns 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>`.
  173. .. _class_Tree_get_drop_section_at_position:
  174. - :ref:`int<class_int>` **get_drop_section_at_position** **(** :ref:`Vector2<class_vector2>` position **)** const
  175. .. _class_Tree_get_edited:
  176. - :ref:`TreeItem<class_treeitem>` **get_edited** **(** **)** const
  177. Returns the currently edited item. This is only available for custom cell mode.
  178. .. _class_Tree_get_edited_column:
  179. - :ref:`int<class_int>` **get_edited_column** **(** **)** const
  180. Returns the column for the currently edited item. This is only available for custom cell mode.
  181. .. _class_Tree_get_item_area_rect:
  182. - :ref:`Rect2<class_rect2>` **get_item_area_rect** **(** :ref:`Object<class_object>` item, :ref:`int<class_int>` column=-1 **)** const
  183. Returns the rectangle area for the specified item. If column is specified, only get the position and size of that column, otherwise get the rectangle containing all columns.
  184. .. _class_Tree_get_item_at_position:
  185. - :ref:`TreeItem<class_treeitem>` **get_item_at_position** **(** :ref:`Vector2<class_vector2>` position **)** const
  186. Returns the tree item at the specified position (relative to the tree origin position).
  187. .. _class_Tree_get_next_selected:
  188. - :ref:`TreeItem<class_treeitem>` **get_next_selected** **(** :ref:`Object<class_object>` from **)**
  189. Returns the next selected item after the given one.
  190. .. _class_Tree_get_pressed_button:
  191. - :ref:`int<class_int>` **get_pressed_button** **(** **)** const
  192. Returns the last pressed button's index.
  193. .. _class_Tree_get_root:
  194. - :ref:`TreeItem<class_treeitem>` **get_root** **(** **)**
  195. Returns the tree's root item.
  196. .. _class_Tree_get_scroll:
  197. - :ref:`Vector2<class_vector2>` **get_scroll** **(** **)** const
  198. Returns the current scrolling position.
  199. .. _class_Tree_get_selected:
  200. - :ref:`TreeItem<class_treeitem>` **get_selected** **(** **)** const
  201. Returns the currently selected item.
  202. .. _class_Tree_get_selected_column:
  203. - :ref:`int<class_int>` **get_selected_column** **(** **)** const
  204. Returns the current selection's column.
  205. .. _class_Tree_set_column_expand:
  206. - void **set_column_expand** **(** :ref:`int<class_int>` column, :ref:`bool<class_bool>` expand **)**
  207. If ``true`` the column will have the "Expand" flag of :ref:`Control<class_control>`.
  208. .. _class_Tree_set_column_min_width:
  209. - void **set_column_min_width** **(** :ref:`int<class_int>` column, :ref:`int<class_int>` min_width **)**
  210. Set the minimum width of a column.
  211. .. _class_Tree_set_column_title:
  212. - void **set_column_title** **(** :ref:`int<class_int>` column, :ref:`String<class_string>` title **)**
  213. Set the title of a column.
  214. .. _class_Tree_set_column_titles_visible:
  215. - void **set_column_titles_visible** **(** :ref:`bool<class_bool>` visible **)**
  216. If ``true`` column titles are visible.