tree.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  1. /*************************************************************************/
  2. /* tree.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 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. enum TextAlign {
  50. ALIGN_LEFT,
  51. ALIGN_CENTER,
  52. ALIGN_RIGHT
  53. };
  54. private:
  55. friend class Tree;
  56. struct Cell {
  57. TreeCellMode mode = TreeItem::CELL_MODE_STRING;
  58. Ref<Texture2D> icon;
  59. Rect2i icon_region;
  60. String text;
  61. String suffix;
  62. Ref<TextLine> text_buf;
  63. Dictionary opentype_features;
  64. String language;
  65. Control::StructuredTextParser st_parser = Control::STRUCTURED_TEXT_DEFAULT;
  66. Array st_args;
  67. Control::TextDirection text_direction = Control::TEXT_DIRECTION_INHERITED;
  68. bool dirty = true;
  69. double min = 0.0;
  70. double max = 100.0;
  71. double step = 1.0;
  72. double val = 0.0;
  73. int icon_max_w = 0;
  74. bool expr = false;
  75. bool checked = false;
  76. bool indeterminate = false;
  77. bool editable = false;
  78. bool selected = false;
  79. bool selectable = true;
  80. bool custom_color = false;
  81. Color color;
  82. bool custom_bg_color = false;
  83. bool custom_bg_outline = false;
  84. Color bg_color;
  85. bool custom_button = false;
  86. bool expand_right = false;
  87. Color icon_color = Color(1, 1, 1);
  88. Size2i cached_minimum_size;
  89. bool cached_minimum_size_dirty = true;
  90. TextAlign text_align = ALIGN_LEFT;
  91. Variant meta;
  92. String tooltip;
  93. ObjectID custom_draw_obj;
  94. StringName custom_draw_callback;
  95. struct Button {
  96. int id = 0;
  97. bool disabled = false;
  98. Ref<Texture2D> texture;
  99. Color color = Color(1, 1, 1, 1);
  100. String tooltip;
  101. };
  102. Vector<Button> buttons;
  103. Ref<Font> custom_font;
  104. int custom_font_size = -1;
  105. Cell() {
  106. text_buf.instantiate();
  107. }
  108. Size2 get_icon_size() const;
  109. void draw_icon(const RID &p_where, const Point2 &p_pos, const Size2 &p_size = Size2(), const Color &p_color = Color()) const;
  110. };
  111. Vector<Cell> cells;
  112. bool collapsed = false; // won't show children
  113. bool disable_folding = false;
  114. int custom_min_height = 0;
  115. TreeItem *parent = nullptr; // parent item
  116. TreeItem *prev = nullptr; // previous in list
  117. TreeItem *next = nullptr; // next in list
  118. TreeItem *first_child = nullptr;
  119. Vector<TreeItem *> children_cache;
  120. bool is_root = false; // for tree root
  121. Tree *tree; // tree (for reference)
  122. TreeItem(Tree *p_tree);
  123. void _changed_notify(int p_cell);
  124. void _changed_notify();
  125. void _cell_selected(int p_cell);
  126. void _cell_deselected(int p_cell);
  127. void _change_tree(Tree *p_tree);
  128. _FORCE_INLINE_ void _create_children_cache() {
  129. if (children_cache.is_empty()) {
  130. TreeItem *c = first_child;
  131. while (c) {
  132. children_cache.append(c);
  133. c = c->next;
  134. }
  135. }
  136. }
  137. _FORCE_INLINE_ void _unlink_from_tree() {
  138. TreeItem *p = get_prev();
  139. if (p) {
  140. p->next = next;
  141. }
  142. if (next) {
  143. next->prev = p;
  144. }
  145. if (parent) {
  146. if (!parent->children_cache.is_empty()) {
  147. parent->children_cache.remove(get_index());
  148. }
  149. if (parent->first_child == this) {
  150. parent->first_child = next;
  151. }
  152. }
  153. }
  154. protected:
  155. static void _bind_methods();
  156. // Bind helpers
  157. Dictionary _get_range_config(int p_column) {
  158. Dictionary d;
  159. double min = 0.0, max = 0.0, step = 0.0;
  160. get_range_config(p_column, min, max, step);
  161. d["min"] = min;
  162. d["max"] = max;
  163. d["step"] = step;
  164. d["expr"] = false;
  165. return d;
  166. }
  167. void _remove_child(Object *p_child) {
  168. remove_child(Object::cast_to<TreeItem>(p_child));
  169. }
  170. void _move_before(Object *p_item) {
  171. move_before(Object::cast_to<TreeItem>(p_item));
  172. }
  173. void _move_after(Object *p_item) {
  174. move_after(Object::cast_to<TreeItem>(p_item));
  175. }
  176. Variant _call_recursive_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error);
  177. public:
  178. /* cell mode */
  179. void set_cell_mode(int p_column, TreeCellMode p_mode);
  180. TreeCellMode get_cell_mode(int p_column) const;
  181. /* check mode */
  182. void set_checked(int p_column, bool p_checked);
  183. void set_indeterminate(int p_column, bool p_indeterminate);
  184. bool is_checked(int p_column) const;
  185. bool is_indeterminate(int p_column) const;
  186. void set_text(int p_column, String p_text);
  187. String get_text(int p_column) const;
  188. void set_text_direction(int p_column, Control::TextDirection p_text_direction);
  189. Control::TextDirection get_text_direction(int p_column) const;
  190. void set_opentype_feature(int p_column, const String &p_name, int p_value);
  191. int get_opentype_feature(int p_column, const String &p_name) const;
  192. void clear_opentype_features(int p_column);
  193. void set_structured_text_bidi_override(int p_column, Control::StructuredTextParser p_parser);
  194. Control::StructuredTextParser get_structured_text_bidi_override(int p_column) const;
  195. void set_structured_text_bidi_override_options(int p_column, Array p_args);
  196. Array get_structured_text_bidi_override_options(int p_column) const;
  197. void set_language(int p_column, const String &p_language);
  198. String get_language(int p_column) const;
  199. void set_suffix(int p_column, String p_suffix);
  200. String get_suffix(int p_column) const;
  201. void set_icon(int p_column, const Ref<Texture2D> &p_icon);
  202. Ref<Texture2D> get_icon(int p_column) const;
  203. void set_icon_region(int p_column, const Rect2 &p_icon_region);
  204. Rect2 get_icon_region(int p_column) const;
  205. void set_icon_modulate(int p_column, const Color &p_modulate);
  206. Color get_icon_modulate(int p_column) const;
  207. void set_icon_max_width(int p_column, int p_max);
  208. int get_icon_max_width(int p_column) const;
  209. void add_button(int p_column, const Ref<Texture2D> &p_button, int p_id = -1, bool p_disabled = false, const String &p_tooltip = "");
  210. int get_button_count(int p_column) const;
  211. String get_button_tooltip(int p_column, int p_idx) const;
  212. Ref<Texture2D> get_button(int p_column, int p_idx) const;
  213. void erase_button(int p_column, int p_idx);
  214. int get_button_by_id(int p_column, int p_id) const;
  215. void set_button(int p_column, int p_idx, const Ref<Texture2D> &p_button);
  216. void set_button_color(int p_column, int p_idx, const Color &p_color);
  217. void set_button_disabled(int p_column, int p_idx, bool p_disabled);
  218. bool is_button_disabled(int p_column, int p_idx) const;
  219. /* range works for mode number or mode combo */
  220. void set_range(int p_column, double p_value);
  221. double get_range(int p_column) const;
  222. void set_range_config(int p_column, double p_min, double p_max, double p_step, bool p_exp = false);
  223. void get_range_config(int p_column, double &r_min, double &r_max, double &r_step) const;
  224. bool is_range_exponential(int p_column) const;
  225. void set_metadata(int p_column, const Variant &p_meta);
  226. Variant get_metadata(int p_column) const;
  227. void set_custom_draw(int p_column, Object *p_object, const StringName &p_callback);
  228. void set_collapsed(bool p_collapsed);
  229. bool is_collapsed();
  230. void uncollapse_tree();
  231. void set_custom_minimum_height(int p_height);
  232. int get_custom_minimum_height() const;
  233. void set_selectable(int p_column, bool p_selectable);
  234. bool is_selectable(int p_column) const;
  235. bool is_selected(int p_column);
  236. void select(int p_column);
  237. void deselect(int p_column);
  238. void set_as_cursor(int p_column);
  239. void set_editable(int p_column, bool p_editable);
  240. bool is_editable(int p_column);
  241. void set_custom_color(int p_column, const Color &p_color);
  242. Color get_custom_color(int p_column) const;
  243. void clear_custom_color(int p_column);
  244. void set_custom_font(int p_column, const Ref<Font> &p_font);
  245. Ref<Font> get_custom_font(int p_column) const;
  246. void set_custom_font_size(int p_column, int p_font_size);
  247. int get_custom_font_size(int p_column) const;
  248. void set_custom_bg_color(int p_column, const Color &p_color, bool p_bg_outline = false);
  249. void clear_custom_bg_color(int p_column);
  250. Color get_custom_bg_color(int p_column) const;
  251. void set_custom_as_button(int p_column, bool p_button);
  252. bool is_custom_set_as_button(int p_column) const;
  253. void set_tooltip(int p_column, const String &p_tooltip);
  254. String get_tooltip(int p_column) const;
  255. void set_text_align(int p_column, TextAlign p_align);
  256. TextAlign get_text_align(int p_column) const;
  257. void set_expand_right(int p_column, bool p_enable);
  258. bool get_expand_right(int p_column) const;
  259. void set_disable_folding(bool p_disable);
  260. bool is_folding_disabled() const;
  261. Size2 get_minimum_size(int p_column);
  262. /* Item manipulation */
  263. TreeItem *create_child(int p_idx = -1);
  264. Tree *get_tree() const;
  265. TreeItem *get_prev();
  266. TreeItem *get_next() const;
  267. TreeItem *get_parent() const;
  268. TreeItem *get_first_child() const;
  269. TreeItem *get_prev_visible(bool p_wrap = false);
  270. TreeItem *get_next_visible(bool p_wrap = false);
  271. TreeItem *get_child(int p_idx);
  272. int get_child_count();
  273. Array get_children();
  274. int get_index();
  275. void move_before(TreeItem *p_item);
  276. void move_after(TreeItem *p_item);
  277. void remove_child(TreeItem *p_item);
  278. void call_recursive(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error);
  279. void clear_children();
  280. ~TreeItem();
  281. };
  282. VARIANT_ENUM_CAST(TreeItem::TreeCellMode);
  283. VARIANT_ENUM_CAST(TreeItem::TextAlign);
  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 *drop_mode_over = nullptr;
  305. int drop_mode_section = 0;
  306. TreeItem *single_select_defer = nullptr;
  307. int single_select_defer_column = 0;
  308. int pressed_button = -1;
  309. bool pressing_for_editor = false;
  310. String pressing_for_editor_text;
  311. Vector2 pressing_pos;
  312. Rect2 pressing_item_rect;
  313. float range_drag_base = 0.0;
  314. bool range_drag_enabled = false;
  315. Vector2 range_drag_capture_pos;
  316. bool propagate_mouse_activated = false;
  317. //TreeItem *cursor_item;
  318. //int cursor_column;
  319. Rect2 custom_popup_rect;
  320. int edited_col = -1;
  321. int selected_col = -1;
  322. int popup_edited_item_col = -1;
  323. bool hide_root = false;
  324. SelectMode select_mode = SELECT_SINGLE;
  325. int blocked = 0;
  326. int drop_mode_flags = 0;
  327. struct ColumnInfo {
  328. int custom_min_width = 0;
  329. int expand_ratio = 1;
  330. bool expand = true;
  331. bool clip_content = false;
  332. String title;
  333. Ref<TextLine> text_buf;
  334. Dictionary opentype_features;
  335. String language;
  336. Control::TextDirection text_direction = Control::TEXT_DIRECTION_INHERITED;
  337. ColumnInfo() {
  338. text_buf.instantiate();
  339. }
  340. };
  341. bool show_column_titles = false;
  342. VBoxContainer *popup_editor_vb;
  343. Popup *popup_editor;
  344. LineEdit *text_editor = nullptr;
  345. HSlider *value_editor;
  346. bool updating_value_editor = false;
  347. uint64_t focus_in_id = 0;
  348. PopupMenu *popup_menu = nullptr;
  349. Vector<ColumnInfo> columns;
  350. Timer *range_click_timer;
  351. TreeItem *range_item_last = nullptr;
  352. bool range_up_last = false;
  353. void _range_click_timeout();
  354. int compute_item_height(TreeItem *p_item) const;
  355. int get_item_height(TreeItem *p_item) const;
  356. void _update_all();
  357. void update_column(int p_col);
  358. void update_item_cell(TreeItem *p_item, int p_col);
  359. void update_item_cache(TreeItem *p_item);
  360. //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);
  361. 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);
  362. int draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 &p_draw_size, TreeItem *p_item);
  363. 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);
  364. int propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, int x_limit, bool p_double_click, TreeItem *p_item, int p_button, const Ref<InputEventWithModifiers> &p_mod);
  365. void _text_editor_submit(String p_text);
  366. void _text_editor_modal_close();
  367. void value_editor_changed(double p_value);
  368. void popup_select(int p_option);
  369. void _notification(int p_what);
  370. void item_edited(int p_column, TreeItem *p_item, bool p_lmb = true);
  371. void item_changed(int p_column, TreeItem *p_item);
  372. void item_selected(int p_column, TreeItem *p_item);
  373. void item_deselected(int p_column, TreeItem *p_item);
  374. void propagate_set_columns(TreeItem *p_item);
  375. struct Cache {
  376. Ref<Font> font;
  377. Ref<Font> tb_font;
  378. int font_size = 0;
  379. int tb_font_size = 0;
  380. Ref<StyleBox> bg;
  381. Ref<StyleBox> selected;
  382. Ref<StyleBox> selected_focus;
  383. Ref<StyleBox> cursor;
  384. Ref<StyleBox> cursor_unfocus;
  385. Ref<StyleBox> button_pressed;
  386. Ref<StyleBox> title_button;
  387. Ref<StyleBox> title_button_hover;
  388. Ref<StyleBox> title_button_pressed;
  389. Ref<StyleBox> custom_button;
  390. Ref<StyleBox> custom_button_hover;
  391. Ref<StyleBox> custom_button_pressed;
  392. Color title_button_color;
  393. Ref<Texture2D> checked;
  394. Ref<Texture2D> unchecked;
  395. Ref<Texture2D> indeterminate;
  396. Ref<Texture2D> arrow_collapsed;
  397. Ref<Texture2D> arrow;
  398. Ref<Texture2D> select_arrow;
  399. Ref<Texture2D> updown;
  400. Color font_color;
  401. Color font_selected_color;
  402. Color guide_color;
  403. Color drop_position_color;
  404. Color relationship_line_color;
  405. Color parent_hl_line_color;
  406. Color children_hl_line_color;
  407. Color custom_button_font_highlight;
  408. Color font_outline_color;
  409. float base_scale = 1.0;
  410. int hseparation = 0;
  411. int vseparation = 0;
  412. int item_margin = 0;
  413. int button_margin = 0;
  414. Point2 offset;
  415. int draw_relationship_lines = 0;
  416. int relationship_line_width = 0;
  417. int parent_hl_line_width = 0;
  418. int children_hl_line_width = 0;
  419. int parent_hl_line_margin = 0;
  420. int draw_guides = 0;
  421. int scroll_border = 0;
  422. int scroll_speed = 0;
  423. int font_outline_size = 0;
  424. enum ClickType {
  425. CLICK_NONE,
  426. CLICK_TITLE,
  427. CLICK_BUTTON,
  428. };
  429. ClickType click_type = Cache::CLICK_NONE;
  430. ClickType hover_type = Cache::CLICK_NONE;
  431. int click_index = -1;
  432. int click_id = -1;
  433. TreeItem *click_item = nullptr;
  434. int click_column = 0;
  435. int hover_index = -1;
  436. Point2 click_pos;
  437. TreeItem *hover_item = nullptr;
  438. int hover_cell = -1;
  439. Point2i text_editor_position;
  440. bool rtl = false;
  441. } cache;
  442. int _get_title_button_height() const;
  443. void _scroll_moved(float p_value);
  444. HScrollBar *h_scroll;
  445. VScrollBar *v_scroll;
  446. bool h_scroll_enabled = true;
  447. bool v_scroll_enabled = true;
  448. Size2 get_internal_min_size() const;
  449. void update_cache();
  450. void update_scrollbars();
  451. Rect2 search_item_rect(TreeItem *p_from, TreeItem *p_item);
  452. //Rect2 get_item_rect(TreeItem *p_item);
  453. uint64_t last_keypress = 0;
  454. String incr_search;
  455. bool cursor_can_exit_tree = true;
  456. void _do_incr_search(const String &p_add);
  457. TreeItem *_search_item_text(TreeItem *p_at, const String &p_find, int *r_col, bool p_selectable, bool p_backwards = false);
  458. TreeItem *_find_item_at_pos(TreeItem *p_item, const Point2 &p_pos, int &r_column, int &h, int &section) const;
  459. /* float drag_speed;
  460. float drag_accum;
  461. float last_drag_accum;
  462. float last_drag_time;
  463. float time_since_motion;*/
  464. float drag_speed = 0.0;
  465. float drag_from = 0.0;
  466. float drag_accum = 0.0;
  467. Vector2 last_speed;
  468. bool drag_touching = false;
  469. bool drag_touching_deaccel = false;
  470. bool click_handled = false;
  471. bool allow_rmb_select = false;
  472. bool scrolling = false;
  473. bool allow_reselect = false;
  474. bool force_edit_checkbox_only_on_checkbox = false;
  475. bool hide_folding = false;
  476. int _count_selected_items(TreeItem *p_from) const;
  477. bool _is_branch_selected(TreeItem *p_from) const;
  478. bool _is_sibling_branch_selected(TreeItem *p_from) const;
  479. void _go_left();
  480. void _go_right();
  481. void _go_down();
  482. void _go_up();
  483. protected:
  484. static void _bind_methods();
  485. //bind helpers
  486. TreeItem *_create_item(Object *p_parent, int p_idx = -1) {
  487. return create_item(Object::cast_to<TreeItem>(p_parent), p_idx);
  488. }
  489. TreeItem *_get_next_selected(Object *p_item) {
  490. return get_next_selected(Object::cast_to<TreeItem>(p_item));
  491. }
  492. Rect2 _get_item_rect(Object *p_item, int p_column) const {
  493. return get_item_rect(Object::cast_to<TreeItem>(p_item), p_column);
  494. }
  495. void _scroll_to_item(Object *p_item) {
  496. scroll_to_item(Object::cast_to<TreeItem>(p_item));
  497. }
  498. public:
  499. virtual void gui_input(const Ref<InputEvent> &p_event) override;
  500. virtual String get_tooltip(const Point2 &p_pos) const override;
  501. TreeItem *get_item_at_position(const Point2 &p_pos) const;
  502. int get_column_at_position(const Point2 &p_pos) const;
  503. int get_drop_section_at_position(const Point2 &p_pos) const;
  504. int get_button_id_at_position(const Point2 &p_pos) const;
  505. void clear();
  506. TreeItem *create_item(TreeItem *p_parent = nullptr, int p_idx = -1);
  507. TreeItem *get_root() const;
  508. TreeItem *get_last_item() const;
  509. void set_column_custom_minimum_width(int p_column, int p_min_width);
  510. void set_column_expand(int p_column, bool p_expand);
  511. void set_column_expand_ratio(int p_column, int p_ratio);
  512. void set_column_clip_content(int p_column, bool p_fit);
  513. int get_column_minimum_width(int p_column) const;
  514. int get_column_width(int p_column) const;
  515. int get_column_expand_ratio(int p_column) const;
  516. bool is_column_expanding(int p_column) const;
  517. bool is_column_clipping_content(int p_column) const;
  518. void set_hide_root(bool p_enabled);
  519. bool is_root_hidden() const;
  520. TreeItem *get_next_selected(TreeItem *p_item);
  521. TreeItem *get_selected() const;
  522. int get_selected_column() const;
  523. int get_pressed_button() const;
  524. void set_select_mode(SelectMode p_mode);
  525. SelectMode get_select_mode() const;
  526. void deselect_all();
  527. bool is_anything_selected();
  528. void set_columns(int p_columns);
  529. int get_columns() const;
  530. void set_column_title(int p_column, const String &p_title);
  531. String get_column_title(int p_column) const;
  532. void set_column_title_direction(int p_column, Control::TextDirection p_text_direction);
  533. Control::TextDirection get_column_title_direction(int p_column) const;
  534. void set_column_title_opentype_feature(int p_column, const String &p_name, int p_value);
  535. int get_column_title_opentype_feature(int p_column, const String &p_name) const;
  536. void clear_column_title_opentype_features(int p_column);
  537. void set_column_title_language(int p_column, const String &p_language);
  538. String get_column_title_language(int p_column) const;
  539. void set_column_titles_visible(bool p_show);
  540. bool are_column_titles_visible() const;
  541. TreeItem *get_edited() const;
  542. int get_edited_column() const;
  543. void ensure_cursor_is_visible();
  544. Rect2 get_custom_popup_rect() const;
  545. int get_item_offset(TreeItem *p_item) const;
  546. Rect2 get_item_rect(TreeItem *p_item, int p_column = -1) const;
  547. bool edit_selected();
  548. bool is_editing();
  549. // First item that starts with the text, from the current focused item down and wraps around.
  550. TreeItem *search_item_text(const String &p_find, int *r_col = nullptr, bool p_selectable = false);
  551. // First item that matches the whole text, from the first item down.
  552. TreeItem *get_item_with_text(const String &p_find) const;
  553. Point2 get_scroll() const;
  554. void scroll_to_item(TreeItem *p_item);
  555. void set_h_scroll_enabled(bool p_enable);
  556. bool is_h_scroll_enabled() const;
  557. void set_v_scroll_enabled(bool p_enable);
  558. bool is_v_scroll_enabled() const;
  559. void set_cursor_can_exit_tree(bool p_enable);
  560. VScrollBar *get_vscroll_bar() { return v_scroll; }
  561. void set_hide_folding(bool p_hide);
  562. bool is_folding_hidden() const;
  563. void set_drop_mode_flags(int p_flags);
  564. int get_drop_mode_flags() const;
  565. void set_edit_checkbox_cell_only_when_checkbox_is_pressed(bool p_enable);
  566. bool get_edit_checkbox_cell_only_when_checkbox_is_pressed() const;
  567. void set_allow_rmb_select(bool p_allow);
  568. bool get_allow_rmb_select() const;
  569. void set_allow_reselect(bool p_allow);
  570. bool get_allow_reselect() const;
  571. Size2 get_minimum_size() const override;
  572. Tree();
  573. ~Tree();
  574. };
  575. VARIANT_ENUM_CAST(Tree::SelectMode);
  576. VARIANT_ENUM_CAST(Tree::DropModeFlags);
  577. #endif