tree.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  1. /*************************************************************************/
  2. /* tree.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  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. protected:
  150. static void _bind_methods();
  151. // Bind helpers
  152. Dictionary _get_range_config(int p_column) {
  153. Dictionary d;
  154. double min = 0.0, max = 0.0, step = 0.0;
  155. get_range_config(p_column, min, max, step);
  156. d["min"] = min;
  157. d["max"] = max;
  158. d["step"] = step;
  159. d["expr"] = false;
  160. return d;
  161. }
  162. void _call_recursive_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error);
  163. public:
  164. /* cell mode */
  165. void set_cell_mode(int p_column, TreeCellMode p_mode);
  166. TreeCellMode get_cell_mode(int p_column) const;
  167. /* check mode */
  168. void set_checked(int p_column, bool p_checked);
  169. void set_indeterminate(int p_column, bool p_indeterminate);
  170. bool is_checked(int p_column) const;
  171. bool is_indeterminate(int p_column) const;
  172. void propagate_check(int p_column, bool p_emit_signal = true);
  173. private:
  174. // Check helpers.
  175. void _propagate_check_through_children(int p_column, bool p_checked, bool p_emit_signal);
  176. void _propagate_check_through_parents(int p_column, bool p_emit_signal);
  177. TreeItem *_get_prev_visible(bool p_wrap = false);
  178. TreeItem *_get_next_visible(bool p_wrap = false);
  179. public:
  180. void set_text(int p_column, String p_text);
  181. String get_text(int p_column) const;
  182. void set_text_direction(int p_column, Control::TextDirection p_text_direction);
  183. Control::TextDirection get_text_direction(int p_column) const;
  184. void set_structured_text_bidi_override(int p_column, TextServer::StructuredTextParser p_parser);
  185. TextServer::StructuredTextParser get_structured_text_bidi_override(int p_column) const;
  186. void set_structured_text_bidi_override_options(int p_column, Array p_args);
  187. Array get_structured_text_bidi_override_options(int p_column) const;
  188. void set_language(int p_column, const String &p_language);
  189. String get_language(int p_column) const;
  190. void set_suffix(int p_column, String p_suffix);
  191. String get_suffix(int p_column) const;
  192. void set_icon(int p_column, const Ref<Texture2D> &p_icon);
  193. Ref<Texture2D> get_icon(int p_column) const;
  194. void set_icon_region(int p_column, const Rect2 &p_icon_region);
  195. Rect2 get_icon_region(int p_column) const;
  196. void set_icon_modulate(int p_column, const Color &p_modulate);
  197. Color get_icon_modulate(int p_column) const;
  198. void set_icon_max_width(int p_column, int p_max);
  199. int get_icon_max_width(int p_column) const;
  200. void add_button(int p_column, const Ref<Texture2D> &p_button, int p_id = -1, bool p_disabled = false, const String &p_tooltip = "");
  201. int get_button_count(int p_column) const;
  202. String get_button_tooltip_text(int p_column, int p_idx) const;
  203. Ref<Texture2D> get_button(int p_column, int p_idx) const;
  204. int get_button_id(int p_column, int p_idx) const;
  205. void erase_button(int p_column, int p_idx);
  206. int get_button_by_id(int p_column, int p_id) const;
  207. void set_button(int p_column, int p_idx, const Ref<Texture2D> &p_button);
  208. void set_button_color(int p_column, int p_idx, const Color &p_color);
  209. void set_button_disabled(int p_column, int p_idx, bool p_disabled);
  210. bool is_button_disabled(int p_column, int p_idx) const;
  211. /* range works for mode number or mode combo */
  212. void set_range(int p_column, double p_value);
  213. double get_range(int p_column) const;
  214. void set_range_config(int p_column, double p_min, double p_max, double p_step, bool p_exp = false);
  215. void get_range_config(int p_column, double &r_min, double &r_max, double &r_step) const;
  216. bool is_range_exponential(int p_column) const;
  217. void set_metadata(int p_column, const Variant &p_meta);
  218. Variant get_metadata(int p_column) const;
  219. void set_custom_draw(int p_column, Object *p_object, const StringName &p_callback);
  220. void set_collapsed(bool p_collapsed);
  221. bool is_collapsed();
  222. void set_visible(bool p_visible);
  223. bool is_visible();
  224. void uncollapse_tree();
  225. void set_custom_minimum_height(int p_height);
  226. int get_custom_minimum_height() const;
  227. void set_selectable(int p_column, bool p_selectable);
  228. bool is_selectable(int p_column) const;
  229. bool is_selected(int p_column);
  230. void select(int p_column);
  231. void deselect(int p_column);
  232. void set_as_cursor(int p_column);
  233. void set_editable(int p_column, bool p_editable);
  234. bool is_editable(int p_column);
  235. void set_custom_color(int p_column, const Color &p_color);
  236. Color get_custom_color(int p_column) const;
  237. void clear_custom_color(int p_column);
  238. void set_custom_font(int p_column, const Ref<Font> &p_font);
  239. Ref<Font> get_custom_font(int p_column) const;
  240. void set_custom_font_size(int p_column, int p_font_size);
  241. int get_custom_font_size(int p_column) const;
  242. void set_custom_bg_color(int p_column, const Color &p_color, bool p_bg_outline = false);
  243. void clear_custom_bg_color(int p_column);
  244. Color get_custom_bg_color(int p_column) const;
  245. void set_custom_as_button(int p_column, bool p_button);
  246. bool is_custom_set_as_button(int p_column) const;
  247. void set_tooltip_text(int p_column, const String &p_tooltip);
  248. String get_tooltip_text(int p_column) const;
  249. void set_text_alignment(int p_column, HorizontalAlignment p_alignment);
  250. HorizontalAlignment get_text_alignment(int p_column) const;
  251. void set_expand_right(int p_column, bool p_enable);
  252. bool get_expand_right(int p_column) const;
  253. void set_disable_folding(bool p_disable);
  254. bool is_folding_disabled() const;
  255. Size2 get_minimum_size(int p_column);
  256. /* Item manipulation */
  257. TreeItem *create_child(int p_idx = -1);
  258. Tree *get_tree() const;
  259. TreeItem *get_prev();
  260. TreeItem *get_next() const;
  261. TreeItem *get_parent() const;
  262. TreeItem *get_first_child() const;
  263. TreeItem *get_prev_visible(bool p_wrap = false);
  264. TreeItem *get_next_visible(bool p_wrap = false);
  265. TreeItem *get_child(int p_idx);
  266. int get_visible_child_count();
  267. int get_child_count();
  268. TypedArray<TreeItem> get_children();
  269. int get_index();
  270. #ifdef DEV_ENABLED
  271. // This debugging code can be removed once the current refactoring of this class is complete.
  272. void validate_cache() const;
  273. #else
  274. void validate_cache() const {}
  275. #endif
  276. void move_before(TreeItem *p_item);
  277. void move_after(TreeItem *p_item);
  278. void remove_child(TreeItem *p_item);
  279. void call_recursive(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error);
  280. void clear_children();
  281. ~TreeItem();
  282. };
  283. VARIANT_ENUM_CAST(TreeItem::TreeCellMode);
  284. class VBoxContainer;
  285. class Tree : public Control {
  286. GDCLASS(Tree, Control);
  287. public:
  288. enum SelectMode {
  289. SELECT_SINGLE,
  290. SELECT_ROW,
  291. SELECT_MULTI
  292. };
  293. enum DropModeFlags {
  294. DROP_MODE_DISABLED = 0,
  295. DROP_MODE_ON_ITEM = 1,
  296. DROP_MODE_INBETWEEN = 2
  297. };
  298. private:
  299. friend class TreeItem;
  300. TreeItem *root = nullptr;
  301. TreeItem *popup_edited_item = nullptr;
  302. TreeItem *selected_item = nullptr;
  303. TreeItem *edited_item = nullptr;
  304. TreeItem *popup_pressing_edited_item = nullptr; // Candidate.
  305. int popup_pressing_edited_item_column = -1;
  306. TreeItem *drop_mode_over = nullptr;
  307. int drop_mode_section = 0;
  308. TreeItem *single_select_defer = nullptr;
  309. int single_select_defer_column = 0;
  310. int pressed_button = -1;
  311. bool pressing_for_editor = false;
  312. String pressing_for_editor_text;
  313. Vector2 pressing_pos;
  314. Rect2 pressing_item_rect;
  315. float range_drag_base = 0.0;
  316. bool range_drag_enabled = false;
  317. Vector2 range_drag_capture_pos;
  318. bool propagate_mouse_activated = false;
  319. //TreeItem *cursor_item;
  320. //int cursor_column;
  321. Rect2 custom_popup_rect;
  322. int edited_col = -1;
  323. int selected_col = -1;
  324. int popup_edited_item_col = -1;
  325. bool hide_root = false;
  326. SelectMode select_mode = SELECT_SINGLE;
  327. int blocked = 0;
  328. int drop_mode_flags = 0;
  329. struct ColumnInfo {
  330. int custom_min_width = 0;
  331. int expand_ratio = 1;
  332. bool expand = true;
  333. bool clip_content = false;
  334. String title;
  335. Ref<TextLine> text_buf;
  336. String language;
  337. Control::TextDirection text_direction = Control::TEXT_DIRECTION_INHERITED;
  338. ColumnInfo() {
  339. text_buf.instantiate();
  340. }
  341. };
  342. bool show_column_titles = false;
  343. VBoxContainer *popup_editor_vb = nullptr;
  344. Popup *popup_editor = nullptr;
  345. LineEdit *text_editor = nullptr;
  346. HSlider *value_editor = nullptr;
  347. bool updating_value_editor = false;
  348. uint64_t focus_in_id = 0;
  349. PopupMenu *popup_menu = nullptr;
  350. Vector<ColumnInfo> columns;
  351. Timer *range_click_timer = nullptr;
  352. TreeItem *range_item_last = nullptr;
  353. bool range_up_last = false;
  354. void _range_click_timeout();
  355. int compute_item_height(TreeItem *p_item) const;
  356. int get_item_height(TreeItem *p_item) const;
  357. void _update_all();
  358. void update_column(int p_col);
  359. void update_item_cell(TreeItem *p_item, int p_col);
  360. void update_item_cache(TreeItem *p_item);
  361. //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);
  362. 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);
  363. int draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 &p_draw_size, TreeItem *p_item);
  364. 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);
  365. 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);
  366. void _text_editor_submit(String p_text);
  367. void _text_editor_modal_close();
  368. void value_editor_changed(double p_value);
  369. void popup_select(int p_option);
  370. void _notification(int p_what);
  371. void item_edited(int p_column, TreeItem *p_item, MouseButton p_custom_mouse_index = MouseButton::NONE);
  372. void item_changed(int p_column, TreeItem *p_item);
  373. void item_selected(int p_column, TreeItem *p_item);
  374. void item_deselected(int p_column, TreeItem *p_item);
  375. void propagate_set_columns(TreeItem *p_item);
  376. struct Cache {
  377. Ref<Font> font;
  378. Ref<Font> tb_font;
  379. int font_size = 0;
  380. int tb_font_size = 0;
  381. Ref<StyleBox> bg;
  382. Ref<StyleBox> selected;
  383. Ref<StyleBox> selected_focus;
  384. Ref<StyleBox> cursor;
  385. Ref<StyleBox> cursor_unfocus;
  386. Ref<StyleBox> button_pressed;
  387. Ref<StyleBox> title_button;
  388. Ref<StyleBox> title_button_hover;
  389. Ref<StyleBox> title_button_pressed;
  390. Ref<StyleBox> custom_button;
  391. Ref<StyleBox> custom_button_hover;
  392. Ref<StyleBox> custom_button_pressed;
  393. Color title_button_color;
  394. Ref<Texture2D> checked;
  395. Ref<Texture2D> unchecked;
  396. Ref<Texture2D> indeterminate;
  397. Ref<Texture2D> arrow_collapsed;
  398. Ref<Texture2D> arrow;
  399. Ref<Texture2D> select_arrow;
  400. Ref<Texture2D> updown;
  401. Color font_color;
  402. Color font_selected_color;
  403. Color guide_color;
  404. Color drop_position_color;
  405. Color relationship_line_color;
  406. Color parent_hl_line_color;
  407. Color children_hl_line_color;
  408. Color custom_button_font_highlight;
  409. Color font_outline_color;
  410. float base_scale = 1.0;
  411. int hseparation = 0;
  412. int vseparation = 0;
  413. int item_margin = 0;
  414. int button_margin = 0;
  415. Point2 offset;
  416. int draw_relationship_lines = 0;
  417. int relationship_line_width = 0;
  418. int parent_hl_line_width = 0;
  419. int children_hl_line_width = 0;
  420. int parent_hl_line_margin = 0;
  421. int draw_guides = 0;
  422. int scroll_border = 0;
  423. int scroll_speed = 0;
  424. int font_outline_size = 0;
  425. enum ClickType {
  426. CLICK_NONE,
  427. CLICK_TITLE,
  428. CLICK_BUTTON,
  429. };
  430. ClickType click_type = Cache::CLICK_NONE;
  431. ClickType hover_type = Cache::CLICK_NONE;
  432. int click_index = -1;
  433. int click_id = -1;
  434. TreeItem *click_item = nullptr;
  435. int click_column = 0;
  436. int hover_index = -1;
  437. Point2 click_pos;
  438. TreeItem *hover_item = nullptr;
  439. int hover_cell = -1;
  440. Point2i text_editor_position;
  441. bool rtl = false;
  442. } cache;
  443. int _get_title_button_height() const;
  444. void _scroll_moved(float p_value);
  445. HScrollBar *h_scroll = nullptr;
  446. VScrollBar *v_scroll = nullptr;
  447. bool h_scroll_enabled = true;
  448. bool v_scroll_enabled = true;
  449. Size2 get_internal_min_size() const;
  450. void update_cache();
  451. void update_scrollbars();
  452. Rect2 search_item_rect(TreeItem *p_from, TreeItem *p_item);
  453. //Rect2 get_item_rect(TreeItem *p_item);
  454. uint64_t last_keypress = 0;
  455. String incr_search;
  456. bool cursor_can_exit_tree = true;
  457. void _do_incr_search(const String &p_add);
  458. TreeItem *_search_item_text(TreeItem *p_at, const String &p_find, int *r_col, bool p_selectable, bool p_backwards = false);
  459. TreeItem *_find_item_at_pos(TreeItem *p_item, const Point2 &p_pos, int &r_column, int &h, int &section) const;
  460. /* float drag_speed;
  461. float drag_accum;
  462. float last_drag_accum;
  463. float last_drag_time;
  464. float time_since_motion;*/
  465. float drag_speed = 0.0;
  466. float drag_from = 0.0;
  467. float drag_accum = 0.0;
  468. Vector2 last_speed;
  469. bool drag_touching = false;
  470. bool drag_touching_deaccel = false;
  471. bool click_handled = false;
  472. bool allow_rmb_select = false;
  473. bool scrolling = false;
  474. bool allow_reselect = false;
  475. bool force_edit_checkbox_only_on_checkbox = false;
  476. bool hide_folding = false;
  477. int _count_selected_items(TreeItem *p_from) const;
  478. bool _is_branch_selected(TreeItem *p_from) const;
  479. bool _is_sibling_branch_selected(TreeItem *p_from) const;
  480. void _go_left();
  481. void _go_right();
  482. void _go_down();
  483. void _go_up();
  484. bool _scroll(bool p_horizontal, float p_pages);
  485. protected:
  486. static void _bind_methods();
  487. public:
  488. virtual void gui_input(const Ref<InputEvent> &p_event) override;
  489. virtual String get_tooltip(const Point2 &p_pos) const override;
  490. TreeItem *get_item_at_position(const Point2 &p_pos) const;
  491. int get_column_at_position(const Point2 &p_pos) const;
  492. int get_drop_section_at_position(const Point2 &p_pos) const;
  493. int get_button_id_at_position(const Point2 &p_pos) const;
  494. void clear();
  495. TreeItem *create_item(TreeItem *p_parent = nullptr, int p_idx = -1);
  496. TreeItem *get_root() const;
  497. TreeItem *get_last_item() const;
  498. void set_column_custom_minimum_width(int p_column, int p_min_width);
  499. void set_column_expand(int p_column, bool p_expand);
  500. void set_column_expand_ratio(int p_column, int p_ratio);
  501. void set_column_clip_content(int p_column, bool p_fit);
  502. int get_column_minimum_width(int p_column) const;
  503. int get_column_width(int p_column) const;
  504. int get_column_expand_ratio(int p_column) const;
  505. bool is_column_expanding(int p_column) const;
  506. bool is_column_clipping_content(int p_column) const;
  507. void set_hide_root(bool p_enabled);
  508. bool is_root_hidden() const;
  509. TreeItem *get_next_selected(TreeItem *p_item);
  510. TreeItem *get_selected() const;
  511. int get_selected_column() const;
  512. int get_pressed_button() const;
  513. void set_select_mode(SelectMode p_mode);
  514. SelectMode get_select_mode() const;
  515. void deselect_all();
  516. bool is_anything_selected();
  517. void set_columns(int p_columns);
  518. int get_columns() const;
  519. void set_column_title(int p_column, const String &p_title);
  520. String get_column_title(int p_column) const;
  521. void set_column_title_direction(int p_column, Control::TextDirection p_text_direction);
  522. Control::TextDirection get_column_title_direction(int p_column) const;
  523. void set_column_title_language(int p_column, const String &p_language);
  524. String get_column_title_language(int p_column) const;
  525. void set_column_titles_visible(bool p_show);
  526. bool are_column_titles_visible() const;
  527. TreeItem *get_edited() const;
  528. int get_edited_column() const;
  529. void ensure_cursor_is_visible();
  530. Rect2 get_custom_popup_rect() const;
  531. int get_item_offset(TreeItem *p_item) const;
  532. Rect2 get_item_rect(TreeItem *p_item, int p_column = -1, int p_button = -1) const;
  533. bool edit_selected();
  534. bool is_editing();
  535. // First item that starts with the text, from the current focused item down and wraps around.
  536. TreeItem *search_item_text(const String &p_find, int *r_col = nullptr, bool p_selectable = false);
  537. // First item that matches the whole text, from the first item down.
  538. TreeItem *get_item_with_text(const String &p_find) const;
  539. Point2 get_scroll() const;
  540. void scroll_to_item(TreeItem *p_item, bool p_center_on_item = false);
  541. void set_h_scroll_enabled(bool p_enable);
  542. bool is_h_scroll_enabled() const;
  543. void set_v_scroll_enabled(bool p_enable);
  544. bool is_v_scroll_enabled() const;
  545. void set_cursor_can_exit_tree(bool p_enable);
  546. VScrollBar *get_vscroll_bar() { return v_scroll; }
  547. void set_hide_folding(bool p_hide);
  548. bool is_folding_hidden() const;
  549. void set_drop_mode_flags(int p_flags);
  550. int get_drop_mode_flags() const;
  551. void set_edit_checkbox_cell_only_when_checkbox_is_pressed(bool p_enable);
  552. bool get_edit_checkbox_cell_only_when_checkbox_is_pressed() const;
  553. void set_allow_rmb_select(bool p_allow);
  554. bool get_allow_rmb_select() const;
  555. void set_allow_reselect(bool p_allow);
  556. bool get_allow_reselect() const;
  557. Size2 get_minimum_size() const override;
  558. Tree();
  559. ~Tree();
  560. };
  561. VARIANT_ENUM_CAST(Tree::SelectMode);
  562. VARIANT_ENUM_CAST(Tree::DropModeFlags);
  563. #endif // TREE_H