tree.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  1. /**************************************************************************/
  2. /* tree.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef TREE_H
  31. #define TREE_H
  32. #include "scene/gui/control.h"
  33. #include "scene/gui/line_edit.h"
  34. #include "scene/gui/popup_menu.h"
  35. #include "scene/gui/scroll_bar.h"
  36. #include "scene/gui/slider.h"
  37. #include "scene/resources/text_line.h"
  38. class Tree;
  39. class TreeItem : public Object {
  40. GDCLASS(TreeItem, Object);
  41. public:
  42. enum TreeCellMode {
  43. CELL_MODE_STRING, ///< just a string
  44. CELL_MODE_CHECK, ///< string + check
  45. CELL_MODE_RANGE, ///< Contains a range
  46. CELL_MODE_ICON, ///< Contains an icon, not editable
  47. CELL_MODE_CUSTOM, ///< Contains a custom value, show a string, and an edit button
  48. };
  49. private:
  50. friend class Tree;
  51. struct Cell {
  52. TreeCellMode mode = TreeItem::CELL_MODE_STRING;
  53. Ref<Texture2D> icon;
  54. Rect2i icon_region;
  55. String text;
  56. String suffix;
  57. Ref<TextLine> text_buf;
  58. String language;
  59. TextServer::StructuredTextParser st_parser = TextServer::STRUCTURED_TEXT_DEFAULT;
  60. Array st_args;
  61. Control::TextDirection text_direction = Control::TEXT_DIRECTION_INHERITED;
  62. bool dirty = true;
  63. double min = 0.0;
  64. double max = 100.0;
  65. double step = 1.0;
  66. double val = 0.0;
  67. int icon_max_w = 0;
  68. bool expr = false;
  69. bool checked = false;
  70. bool indeterminate = false;
  71. bool editable = false;
  72. bool selected = false;
  73. bool selectable = true;
  74. bool custom_color = false;
  75. Color color;
  76. bool custom_bg_color = false;
  77. bool custom_bg_outline = false;
  78. Color bg_color;
  79. bool custom_button = false;
  80. bool expand_right = false;
  81. Color icon_color = Color(1, 1, 1);
  82. Size2i cached_minimum_size;
  83. bool cached_minimum_size_dirty = true;
  84. HorizontalAlignment text_alignment = HORIZONTAL_ALIGNMENT_LEFT;
  85. Variant meta;
  86. String tooltip;
  87. ObjectID custom_draw_obj;
  88. StringName custom_draw_callback;
  89. struct Button {
  90. int id = 0;
  91. bool disabled = false;
  92. Ref<Texture2D> texture;
  93. Color color = Color(1, 1, 1, 1);
  94. String tooltip;
  95. };
  96. Vector<Button> buttons;
  97. Ref<Font> custom_font;
  98. int custom_font_size = -1;
  99. Cell() {
  100. text_buf.instantiate();
  101. }
  102. Size2 get_icon_size() const;
  103. void draw_icon(const RID &p_where, const Point2 &p_pos, const Size2 &p_size = Size2(), const Color &p_color = Color()) const;
  104. };
  105. Vector<Cell> cells;
  106. bool collapsed = false; // won't show children
  107. bool visible = true;
  108. bool disable_folding = false;
  109. int custom_min_height = 0;
  110. TreeItem *parent = nullptr; // parent item
  111. TreeItem *prev = nullptr; // previous in list
  112. TreeItem *next = nullptr; // next in list
  113. TreeItem *first_child = nullptr;
  114. Vector<TreeItem *> children_cache;
  115. bool is_root = false; // for tree root
  116. Tree *tree = nullptr; // tree (for reference)
  117. TreeItem(Tree *p_tree);
  118. void _changed_notify(int p_cell);
  119. void _changed_notify();
  120. void _cell_selected(int p_cell);
  121. void _cell_deselected(int p_cell);
  122. void _change_tree(Tree *p_tree);
  123. _FORCE_INLINE_ void _create_children_cache() {
  124. if (children_cache.is_empty()) {
  125. TreeItem *c = first_child;
  126. while (c) {
  127. children_cache.append(c);
  128. c = c->next;
  129. }
  130. }
  131. }
  132. _FORCE_INLINE_ void _unlink_from_tree() {
  133. TreeItem *p = get_prev();
  134. if (p) {
  135. p->next = next;
  136. }
  137. if (next) {
  138. next->prev = p;
  139. }
  140. if (parent) {
  141. if (!parent->children_cache.is_empty()) {
  142. parent->children_cache.remove_at(get_index());
  143. }
  144. if (parent->first_child == this) {
  145. parent->first_child = next;
  146. }
  147. }
  148. }
  149. bool _is_any_collapsed(bool p_only_visible);
  150. protected:
  151. static void _bind_methods();
  152. // Bind helpers
  153. Dictionary _get_range_config(int p_column) {
  154. Dictionary d;
  155. double min = 0.0, max = 0.0, step = 0.0;
  156. get_range_config(p_column, min, max, step);
  157. d["min"] = min;
  158. d["max"] = max;
  159. d["step"] = step;
  160. d["expr"] = false;
  161. return d;
  162. }
  163. void _call_recursive_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error);
  164. public:
  165. /* cell mode */
  166. void set_cell_mode(int p_column, TreeCellMode p_mode);
  167. TreeCellMode get_cell_mode(int p_column) const;
  168. /* check mode */
  169. void set_checked(int p_column, bool p_checked);
  170. void set_indeterminate(int p_column, bool p_indeterminate);
  171. bool is_checked(int p_column) const;
  172. bool is_indeterminate(int p_column) const;
  173. void propagate_check(int p_column, bool p_emit_signal = true);
  174. private:
  175. // Check helpers.
  176. void _propagate_check_through_children(int p_column, bool p_checked, bool p_emit_signal);
  177. void _propagate_check_through_parents(int p_column, bool p_emit_signal);
  178. TreeItem *_get_prev_visible(bool p_wrap = false);
  179. TreeItem *_get_next_visible(bool p_wrap = false);
  180. public:
  181. void set_text(int p_column, String p_text);
  182. String get_text(int p_column) const;
  183. void set_text_direction(int p_column, Control::TextDirection p_text_direction);
  184. Control::TextDirection get_text_direction(int p_column) const;
  185. void set_structured_text_bidi_override(int p_column, TextServer::StructuredTextParser p_parser);
  186. TextServer::StructuredTextParser get_structured_text_bidi_override(int p_column) const;
  187. void set_structured_text_bidi_override_options(int p_column, Array p_args);
  188. Array get_structured_text_bidi_override_options(int p_column) const;
  189. void set_language(int p_column, const String &p_language);
  190. String get_language(int p_column) const;
  191. void set_suffix(int p_column, String p_suffix);
  192. String get_suffix(int p_column) const;
  193. void set_icon(int p_column, const Ref<Texture2D> &p_icon);
  194. Ref<Texture2D> get_icon(int p_column) const;
  195. void set_icon_region(int p_column, const Rect2 &p_icon_region);
  196. Rect2 get_icon_region(int p_column) const;
  197. void set_icon_modulate(int p_column, const Color &p_modulate);
  198. Color get_icon_modulate(int p_column) const;
  199. void set_icon_max_width(int p_column, int p_max);
  200. int get_icon_max_width(int p_column) const;
  201. void add_button(int p_column, const Ref<Texture2D> &p_button, int p_id = -1, bool p_disabled = false, const String &p_tooltip = "");
  202. int get_button_count(int p_column) const;
  203. String get_button_tooltip_text(int p_column, int p_index) const;
  204. Ref<Texture2D> get_button(int p_column, int p_index) const;
  205. int get_button_id(int p_column, int p_index) const;
  206. void erase_button(int p_column, int p_index);
  207. int get_button_by_id(int p_column, int p_id) const;
  208. void set_button(int p_column, int p_index, const Ref<Texture2D> &p_button);
  209. void set_button_color(int p_column, int p_index, const Color &p_color);
  210. void set_button_disabled(int p_column, int p_index, bool p_disabled);
  211. bool is_button_disabled(int p_column, int p_index) const;
  212. /* range works for mode number or mode combo */
  213. void set_range(int p_column, double p_value);
  214. double get_range(int p_column) const;
  215. void set_range_config(int p_column, double p_min, double p_max, double p_step, bool p_exp = false);
  216. void get_range_config(int p_column, double &r_min, double &r_max, double &r_step) const;
  217. bool is_range_exponential(int p_column) const;
  218. void set_metadata(int p_column, const Variant &p_meta);
  219. Variant get_metadata(int p_column) const;
  220. void set_custom_draw(int p_column, Object *p_object, const StringName &p_callback);
  221. void set_collapsed(bool p_collapsed);
  222. bool is_collapsed();
  223. void set_collapsed_recursive(bool p_collapsed);
  224. bool is_any_collapsed(bool p_only_visible = false);
  225. void set_visible(bool p_visible);
  226. bool is_visible();
  227. void uncollapse_tree();
  228. void set_custom_minimum_height(int p_height);
  229. int get_custom_minimum_height() const;
  230. void set_selectable(int p_column, bool p_selectable);
  231. bool is_selectable(int p_column) const;
  232. bool is_selected(int p_column);
  233. void select(int p_column);
  234. void deselect(int p_column);
  235. void set_as_cursor(int p_column);
  236. void set_editable(int p_column, bool p_editable);
  237. bool is_editable(int p_column);
  238. void set_custom_color(int p_column, const Color &p_color);
  239. Color get_custom_color(int p_column) const;
  240. void clear_custom_color(int p_column);
  241. void set_custom_font(int p_column, const Ref<Font> &p_font);
  242. Ref<Font> get_custom_font(int p_column) const;
  243. void set_custom_font_size(int p_column, int p_font_size);
  244. int get_custom_font_size(int p_column) const;
  245. void set_custom_bg_color(int p_column, const Color &p_color, bool p_bg_outline = false);
  246. void clear_custom_bg_color(int p_column);
  247. Color get_custom_bg_color(int p_column) const;
  248. void set_custom_as_button(int p_column, bool p_button);
  249. bool is_custom_set_as_button(int p_column) const;
  250. void set_tooltip_text(int p_column, const String &p_tooltip);
  251. String get_tooltip_text(int p_column) const;
  252. void set_text_alignment(int p_column, HorizontalAlignment p_alignment);
  253. HorizontalAlignment get_text_alignment(int p_column) const;
  254. void set_expand_right(int p_column, bool p_enable);
  255. bool get_expand_right(int p_column) const;
  256. void set_disable_folding(bool p_disable);
  257. bool is_folding_disabled() const;
  258. Size2 get_minimum_size(int p_column);
  259. /* Item manipulation */
  260. TreeItem *create_child(int p_index = -1);
  261. Tree *get_tree() const;
  262. TreeItem *get_prev();
  263. TreeItem *get_next() const;
  264. TreeItem *get_parent() const;
  265. TreeItem *get_first_child() const;
  266. TreeItem *get_prev_visible(bool p_wrap = false);
  267. TreeItem *get_next_visible(bool p_wrap = false);
  268. TreeItem *get_child(int p_index);
  269. int get_visible_child_count();
  270. int get_child_count();
  271. TypedArray<TreeItem> get_children();
  272. int get_index();
  273. #ifdef DEV_ENABLED
  274. // This debugging code can be removed once the current refactoring of this class is complete.
  275. void validate_cache() const;
  276. #else
  277. void validate_cache() const {}
  278. #endif
  279. void move_before(TreeItem *p_item);
  280. void move_after(TreeItem *p_item);
  281. void remove_child(TreeItem *p_item);
  282. void call_recursive(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error);
  283. void clear_children();
  284. ~TreeItem();
  285. };
  286. VARIANT_ENUM_CAST(TreeItem::TreeCellMode);
  287. class VBoxContainer;
  288. class Tree : public Control {
  289. GDCLASS(Tree, Control);
  290. public:
  291. enum SelectMode {
  292. SELECT_SINGLE,
  293. SELECT_ROW,
  294. SELECT_MULTI
  295. };
  296. enum DropModeFlags {
  297. DROP_MODE_DISABLED = 0,
  298. DROP_MODE_ON_ITEM = 1,
  299. DROP_MODE_INBETWEEN = 2
  300. };
  301. private:
  302. friend class TreeItem;
  303. TreeItem *root = nullptr;
  304. TreeItem *popup_edited_item = nullptr;
  305. TreeItem *selected_item = nullptr;
  306. TreeItem *edited_item = nullptr;
  307. TreeItem *popup_pressing_edited_item = nullptr; // Candidate.
  308. int popup_pressing_edited_item_column = -1;
  309. TreeItem *drop_mode_over = nullptr;
  310. int drop_mode_section = 0;
  311. TreeItem *single_select_defer = nullptr;
  312. int single_select_defer_column = 0;
  313. int pressed_button = -1;
  314. bool pressing_for_editor = false;
  315. String pressing_for_editor_text;
  316. Vector2 pressing_pos;
  317. Rect2 pressing_item_rect;
  318. float range_drag_base = 0.0;
  319. bool range_drag_enabled = false;
  320. Vector2 range_drag_capture_pos;
  321. bool propagate_mouse_activated = false;
  322. //TreeItem *cursor_item;
  323. //int cursor_column;
  324. Rect2 custom_popup_rect;
  325. int edited_col = -1;
  326. int selected_col = -1;
  327. int popup_edited_item_col = -1;
  328. bool hide_root = false;
  329. SelectMode select_mode = SELECT_SINGLE;
  330. int blocked = 0;
  331. int drop_mode_flags = 0;
  332. struct ColumnInfo {
  333. int custom_min_width = 0;
  334. int expand_ratio = 1;
  335. bool expand = true;
  336. bool clip_content = false;
  337. String title;
  338. Ref<TextLine> text_buf;
  339. String language;
  340. Control::TextDirection text_direction = Control::TEXT_DIRECTION_INHERITED;
  341. ColumnInfo() {
  342. text_buf.instantiate();
  343. }
  344. };
  345. bool show_column_titles = false;
  346. VBoxContainer *popup_editor_vb = nullptr;
  347. Popup *popup_editor = nullptr;
  348. LineEdit *text_editor = nullptr;
  349. HSlider *value_editor = nullptr;
  350. bool updating_value_editor = false;
  351. uint64_t focus_in_id = 0;
  352. PopupMenu *popup_menu = nullptr;
  353. Vector<ColumnInfo> columns;
  354. Timer *range_click_timer = nullptr;
  355. TreeItem *range_item_last = nullptr;
  356. bool range_up_last = false;
  357. void _range_click_timeout();
  358. int compute_item_height(TreeItem *p_item) const;
  359. int get_item_height(TreeItem *p_item) const;
  360. void _update_all();
  361. void update_column(int p_col);
  362. void update_item_cell(TreeItem *p_item, int p_col);
  363. void update_item_cache(TreeItem *p_item);
  364. //void draw_item_text(String p_text,const Ref<Texture2D>& p_icon,int p_icon_max_w,bool p_tool,Rect2i p_rect,const Color& p_color);
  365. void draw_item_rect(TreeItem::Cell &p_cell, const Rect2i &p_rect, const Color &p_color, const Color &p_icon_color, int p_ol_size, const Color &p_ol_color);
  366. int draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 &p_draw_size, TreeItem *p_item);
  367. void select_single_item(TreeItem *p_selected, TreeItem *p_current, int p_col, TreeItem *p_prev = nullptr, bool *r_in_range = nullptr, bool p_force_deselect = false);
  368. int propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, int x_limit, bool p_double_click, TreeItem *p_item, MouseButton p_button, const Ref<InputEventWithModifiers> &p_mod);
  369. void _text_editor_submit(String p_text);
  370. void _text_editor_modal_close();
  371. void value_editor_changed(double p_value);
  372. void popup_select(int p_option);
  373. void _notification(int p_what);
  374. void item_edited(int p_column, TreeItem *p_item, MouseButton p_custom_mouse_index = MouseButton::NONE);
  375. void item_changed(int p_column, TreeItem *p_item);
  376. void item_selected(int p_column, TreeItem *p_item);
  377. void item_deselected(int p_column, TreeItem *p_item);
  378. void propagate_set_columns(TreeItem *p_item);
  379. struct ThemeCache {
  380. Ref<StyleBox> panel_style;
  381. Ref<StyleBox> focus_style;
  382. Ref<Font> font;
  383. Ref<Font> tb_font;
  384. int font_size = 0;
  385. int tb_font_size = 0;
  386. Ref<StyleBox> selected;
  387. Ref<StyleBox> selected_focus;
  388. Ref<StyleBox> cursor;
  389. Ref<StyleBox> cursor_unfocus;
  390. Ref<StyleBox> button_pressed;
  391. Ref<StyleBox> title_button;
  392. Ref<StyleBox> title_button_hover;
  393. Ref<StyleBox> title_button_pressed;
  394. Ref<StyleBox> custom_button;
  395. Ref<StyleBox> custom_button_hover;
  396. Ref<StyleBox> custom_button_pressed;
  397. Color title_button_color;
  398. Ref<Texture2D> checked;
  399. Ref<Texture2D> unchecked;
  400. Ref<Texture2D> indeterminate;
  401. Ref<Texture2D> arrow;
  402. Ref<Texture2D> arrow_collapsed;
  403. Ref<Texture2D> arrow_collapsed_mirrored;
  404. Ref<Texture2D> select_arrow;
  405. Ref<Texture2D> updown;
  406. Color font_color;
  407. Color font_selected_color;
  408. Color guide_color;
  409. Color drop_position_color;
  410. Color relationship_line_color;
  411. Color parent_hl_line_color;
  412. Color children_hl_line_color;
  413. Color custom_button_font_highlight;
  414. Color font_outline_color;
  415. float base_scale = 1.0;
  416. int h_separation = 0;
  417. int v_separation = 0;
  418. int item_margin = 0;
  419. int button_margin = 0;
  420. Point2 offset;
  421. int draw_relationship_lines = 0;
  422. int relationship_line_width = 0;
  423. int parent_hl_line_width = 0;
  424. int children_hl_line_width = 0;
  425. int parent_hl_line_margin = 0;
  426. int draw_guides = 0;
  427. int scroll_border = 0;
  428. int scroll_speed = 0;
  429. int font_outline_size = 0;
  430. } theme_cache;
  431. struct Cache {
  432. enum ClickType {
  433. CLICK_NONE,
  434. CLICK_TITLE,
  435. CLICK_BUTTON,
  436. };
  437. ClickType click_type = Cache::CLICK_NONE;
  438. ClickType hover_type = Cache::CLICK_NONE;
  439. int click_index = -1;
  440. int click_id = -1;
  441. TreeItem *click_item = nullptr;
  442. int click_column = 0;
  443. int hover_index = -1;
  444. Point2 click_pos;
  445. TreeItem *hover_item = nullptr;
  446. int hover_cell = -1;
  447. Point2i text_editor_position;
  448. bool rtl = false;
  449. } cache;
  450. int _get_title_button_height() const;
  451. void _scroll_moved(float p_value);
  452. HScrollBar *h_scroll = nullptr;
  453. VScrollBar *v_scroll = nullptr;
  454. bool h_scroll_enabled = true;
  455. bool v_scroll_enabled = true;
  456. Size2 get_internal_min_size() const;
  457. void update_scrollbars();
  458. Rect2 search_item_rect(TreeItem *p_from, TreeItem *p_item);
  459. //Rect2 get_item_rect(TreeItem *p_item);
  460. uint64_t last_keypress = 0;
  461. String incr_search;
  462. bool cursor_can_exit_tree = true;
  463. void _do_incr_search(const String &p_add);
  464. TreeItem *_search_item_text(TreeItem *p_at, const String &p_find, int *r_col, bool p_selectable, bool p_backwards = false);
  465. TreeItem *_find_item_at_pos(TreeItem *p_item, const Point2 &p_pos, int &r_column, int &h, int &section) const;
  466. /* float drag_speed;
  467. float drag_accum;
  468. float last_drag_accum;
  469. float last_drag_time;
  470. float time_since_motion;*/
  471. float drag_speed = 0.0;
  472. float drag_from = 0.0;
  473. float drag_accum = 0.0;
  474. Vector2 last_speed;
  475. bool drag_touching = false;
  476. bool drag_touching_deaccel = false;
  477. bool click_handled = false;
  478. bool allow_rmb_select = false;
  479. bool scrolling = false;
  480. bool allow_reselect = false;
  481. bool force_edit_checkbox_only_on_checkbox = false;
  482. bool hide_folding = false;
  483. bool enable_recursive_folding = true;
  484. int _count_selected_items(TreeItem *p_from) const;
  485. bool _is_branch_selected(TreeItem *p_from) const;
  486. bool _is_sibling_branch_selected(TreeItem *p_from) const;
  487. void _go_left();
  488. void _go_right();
  489. void _go_down();
  490. void _go_up();
  491. bool _scroll(bool p_horizontal, float p_pages);
  492. protected:
  493. virtual void _update_theme_item_cache() override;
  494. static void _bind_methods();
  495. public:
  496. virtual void gui_input(const Ref<InputEvent> &p_event) override;
  497. virtual String get_tooltip(const Point2 &p_pos) const override;
  498. TreeItem *get_item_at_position(const Point2 &p_pos) const;
  499. int get_column_at_position(const Point2 &p_pos) const;
  500. int get_drop_section_at_position(const Point2 &p_pos) const;
  501. int get_button_id_at_position(const Point2 &p_pos) const;
  502. void clear();
  503. TreeItem *create_item(TreeItem *p_parent = nullptr, int p_index = -1);
  504. TreeItem *get_root() const;
  505. TreeItem *get_last_item() const;
  506. void set_column_custom_minimum_width(int p_column, int p_min_width);
  507. void set_column_expand(int p_column, bool p_expand);
  508. void set_column_expand_ratio(int p_column, int p_ratio);
  509. void set_column_clip_content(int p_column, bool p_fit);
  510. int get_column_minimum_width(int p_column) const;
  511. int get_column_width(int p_column) const;
  512. int get_column_expand_ratio(int p_column) const;
  513. bool is_column_expanding(int p_column) const;
  514. bool is_column_clipping_content(int p_column) const;
  515. void set_hide_root(bool p_enabled);
  516. bool is_root_hidden() const;
  517. TreeItem *get_next_selected(TreeItem *p_item);
  518. TreeItem *get_selected() const;
  519. void set_selected(TreeItem *p_item, int p_column = 0);
  520. int get_selected_column() const;
  521. int get_pressed_button() const;
  522. void set_select_mode(SelectMode p_mode);
  523. SelectMode get_select_mode() const;
  524. void deselect_all();
  525. bool is_anything_selected();
  526. void set_columns(int p_columns);
  527. int get_columns() const;
  528. void set_column_title(int p_column, const String &p_title);
  529. String get_column_title(int p_column) const;
  530. void set_column_title_direction(int p_column, Control::TextDirection p_text_direction);
  531. Control::TextDirection get_column_title_direction(int p_column) const;
  532. void set_column_title_language(int p_column, const String &p_language);
  533. String get_column_title_language(int p_column) const;
  534. void set_column_titles_visible(bool p_show);
  535. bool are_column_titles_visible() const;
  536. TreeItem *get_edited() const;
  537. int get_edited_column() const;
  538. void ensure_cursor_is_visible();
  539. Rect2 get_custom_popup_rect() const;
  540. int get_item_offset(TreeItem *p_item) const;
  541. Rect2 get_item_rect(TreeItem *p_item, int p_column = -1, int p_button = -1) const;
  542. bool edit_selected();
  543. bool is_editing();
  544. // First item that starts with the text, from the current focused item down and wraps around.
  545. TreeItem *search_item_text(const String &p_find, int *r_col = nullptr, bool p_selectable = false);
  546. // First item that matches the whole text, from the first item down.
  547. TreeItem *get_item_with_text(const String &p_find) const;
  548. Point2 get_scroll() const;
  549. void scroll_to_item(TreeItem *p_item, bool p_center_on_item = false);
  550. void set_h_scroll_enabled(bool p_enable);
  551. bool is_h_scroll_enabled() const;
  552. void set_v_scroll_enabled(bool p_enable);
  553. bool is_v_scroll_enabled() const;
  554. void set_cursor_can_exit_tree(bool p_enable);
  555. VScrollBar *get_vscroll_bar() { return v_scroll; }
  556. void set_hide_folding(bool p_hide);
  557. bool is_folding_hidden() const;
  558. void set_enable_recursive_folding(bool p_enable);
  559. bool is_recursive_folding_enabled() const;
  560. void set_drop_mode_flags(int p_flags);
  561. int get_drop_mode_flags() const;
  562. void set_edit_checkbox_cell_only_when_checkbox_is_pressed(bool p_enable);
  563. bool get_edit_checkbox_cell_only_when_checkbox_is_pressed() const;
  564. void set_allow_rmb_select(bool p_allow);
  565. bool get_allow_rmb_select() const;
  566. void set_allow_reselect(bool p_allow);
  567. bool get_allow_reselect() const;
  568. Size2 get_minimum_size() const override;
  569. Tree();
  570. ~Tree();
  571. };
  572. VARIANT_ENUM_CAST(Tree::SelectMode);
  573. VARIANT_ENUM_CAST(Tree::DropModeFlags);
  574. #endif // TREE_H