tree.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784
  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_paragraph.h"
  38. class TextEdit;
  39. class Tree;
  40. class TreeItem : public Object {
  41. GDCLASS(TreeItem, Object);
  42. public:
  43. enum TreeCellMode {
  44. CELL_MODE_STRING, ///< just a string
  45. CELL_MODE_CHECK, ///< string + check
  46. CELL_MODE_RANGE, ///< Contains a range
  47. CELL_MODE_ICON, ///< Contains an icon, not editable
  48. CELL_MODE_CUSTOM, ///< Contains a custom value, show a string, and an edit button
  49. };
  50. private:
  51. friend class Tree;
  52. struct Cell {
  53. TreeCellMode mode = TreeItem::CELL_MODE_STRING;
  54. Ref<Texture2D> icon;
  55. Rect2i icon_region;
  56. String text;
  57. bool edit_multiline = false;
  58. String suffix;
  59. Ref<TextParagraph> text_buf;
  60. String language;
  61. TextServer::StructuredTextParser st_parser = TextServer::STRUCTURED_TEXT_DEFAULT;
  62. Array st_args;
  63. Control::TextDirection text_direction = Control::TEXT_DIRECTION_INHERITED;
  64. TextServer::AutowrapMode autowrap_mode = TextServer::AUTOWRAP_OFF;
  65. bool dirty = true;
  66. double min = 0.0;
  67. double max = 100.0;
  68. double step = 1.0;
  69. double val = 0.0;
  70. int icon_max_w = 0;
  71. bool expr = false;
  72. bool checked = false;
  73. bool indeterminate = false;
  74. bool editable = false;
  75. bool selected = false;
  76. bool selectable = true;
  77. bool custom_color = false;
  78. Color color;
  79. bool custom_bg_color = false;
  80. bool custom_bg_outline = false;
  81. Color bg_color;
  82. bool custom_button = false;
  83. bool expand_right = false;
  84. Color icon_color = Color(1, 1, 1);
  85. Size2i cached_minimum_size;
  86. bool cached_minimum_size_dirty = true;
  87. HorizontalAlignment text_alignment = HORIZONTAL_ALIGNMENT_LEFT;
  88. Variant meta;
  89. String tooltip;
  90. ObjectID custom_draw_obj;
  91. StringName custom_draw_callback;
  92. struct Button {
  93. int id = 0;
  94. bool disabled = false;
  95. Ref<Texture2D> texture;
  96. Color color = Color(1, 1, 1, 1);
  97. String tooltip;
  98. };
  99. Vector<Button> buttons;
  100. Ref<Font> custom_font;
  101. int custom_font_size = -1;
  102. Cell() {
  103. text_buf.instantiate();
  104. }
  105. Size2 get_icon_size() const;
  106. void draw_icon(const RID &p_where, const Point2 &p_pos, const Size2 &p_size = Size2(), const Color &p_color = Color()) const;
  107. };
  108. Vector<Cell> cells;
  109. bool collapsed = false; // won't show children
  110. bool visible = true;
  111. bool disable_folding = false;
  112. int custom_min_height = 0;
  113. TreeItem *parent = nullptr; // parent item
  114. TreeItem *prev = nullptr; // previous in list
  115. TreeItem *next = nullptr; // next in list
  116. TreeItem *first_child = nullptr;
  117. Vector<TreeItem *> children_cache;
  118. bool is_root = false; // for tree root
  119. Tree *tree = nullptr; // tree (for reference)
  120. TreeItem(Tree *p_tree);
  121. void _changed_notify(int p_cell);
  122. void _changed_notify();
  123. void _cell_selected(int p_cell);
  124. void _cell_deselected(int p_cell);
  125. void _change_tree(Tree *p_tree);
  126. _FORCE_INLINE_ void _create_children_cache() {
  127. if (children_cache.is_empty()) {
  128. TreeItem *c = first_child;
  129. while (c) {
  130. children_cache.append(c);
  131. c = c->next;
  132. }
  133. }
  134. }
  135. _FORCE_INLINE_ void _unlink_from_tree() {
  136. TreeItem *p = get_prev();
  137. if (p) {
  138. p->next = next;
  139. }
  140. if (next) {
  141. next->prev = p;
  142. }
  143. if (parent) {
  144. if (!parent->children_cache.is_empty()) {
  145. parent->children_cache.remove_at(get_index());
  146. }
  147. if (parent->first_child == this) {
  148. parent->first_child = next;
  149. }
  150. }
  151. }
  152. bool _is_any_collapsed(bool p_only_visible);
  153. protected:
  154. static void _bind_methods();
  155. // Bind helpers
  156. Dictionary _get_range_config(int p_column) {
  157. Dictionary d;
  158. double min = 0.0, max = 0.0, step = 0.0;
  159. get_range_config(p_column, min, max, step);
  160. d["min"] = min;
  161. d["max"] = max;
  162. d["step"] = step;
  163. d["expr"] = false;
  164. return d;
  165. }
  166. void _call_recursive_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error);
  167. public:
  168. /* cell mode */
  169. void set_cell_mode(int p_column, TreeCellMode p_mode);
  170. TreeCellMode get_cell_mode(int p_column) const;
  171. /* multiline editable */
  172. void set_edit_multiline(int p_column, bool p_multiline);
  173. bool is_edit_multiline(int p_column) const;
  174. /* check mode */
  175. void set_checked(int p_column, bool p_checked);
  176. void set_indeterminate(int p_column, bool p_indeterminate);
  177. bool is_checked(int p_column) const;
  178. bool is_indeterminate(int p_column) const;
  179. void propagate_check(int p_column, bool p_emit_signal = true);
  180. private:
  181. // Check helpers.
  182. void _propagate_check_through_children(int p_column, bool p_checked, bool p_emit_signal);
  183. void _propagate_check_through_parents(int p_column, bool p_emit_signal);
  184. TreeItem *_get_prev_in_tree(bool p_wrap = false, bool p_include_invisible = false);
  185. TreeItem *_get_next_in_tree(bool p_wrap = false, bool p_include_invisible = false);
  186. public:
  187. void set_text(int p_column, String p_text);
  188. String get_text(int p_column) const;
  189. void set_text_direction(int p_column, Control::TextDirection p_text_direction);
  190. Control::TextDirection get_text_direction(int p_column) const;
  191. void set_autowrap_mode(int p_column, TextServer::AutowrapMode p_mode);
  192. TextServer::AutowrapMode get_autowrap_mode(int p_column) const;
  193. void set_structured_text_bidi_override(int p_column, TextServer::StructuredTextParser p_parser);
  194. TextServer::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_text(int p_column, int p_index) const;
  212. Ref<Texture2D> get_button(int p_column, int p_index) const;
  213. int get_button_id(int p_column, int p_index) const;
  214. void erase_button(int p_column, int p_index);
  215. int get_button_by_id(int p_column, int p_id) const;
  216. void set_button(int p_column, int p_index, const Ref<Texture2D> &p_button);
  217. void set_button_color(int p_column, int p_index, const Color &p_color);
  218. void set_button_disabled(int p_column, int p_index, bool p_disabled);
  219. bool is_button_disabled(int p_column, int p_index) const;
  220. /* range works for mode number or mode combo */
  221. void set_range(int p_column, double p_value);
  222. double get_range(int p_column) const;
  223. void set_range_config(int p_column, double p_min, double p_max, double p_step, bool p_exp = false);
  224. void get_range_config(int p_column, double &r_min, double &r_max, double &r_step) const;
  225. bool is_range_exponential(int p_column) const;
  226. void set_metadata(int p_column, const Variant &p_meta);
  227. Variant get_metadata(int p_column) const;
  228. void set_custom_draw(int p_column, Object *p_object, const StringName &p_callback);
  229. void set_collapsed(bool p_collapsed);
  230. bool is_collapsed();
  231. void set_collapsed_recursive(bool p_collapsed);
  232. bool is_any_collapsed(bool p_only_visible = false);
  233. void set_visible(bool p_visible);
  234. bool is_visible();
  235. void uncollapse_tree();
  236. void set_custom_minimum_height(int p_height);
  237. int get_custom_minimum_height() const;
  238. void set_selectable(int p_column, bool p_selectable);
  239. bool is_selectable(int p_column) const;
  240. bool is_selected(int p_column);
  241. void select(int p_column);
  242. void deselect(int p_column);
  243. void set_as_cursor(int p_column);
  244. void set_editable(int p_column, bool p_editable);
  245. bool is_editable(int p_column);
  246. void set_custom_color(int p_column, const Color &p_color);
  247. Color get_custom_color(int p_column) const;
  248. void clear_custom_color(int p_column);
  249. void set_custom_font(int p_column, const Ref<Font> &p_font);
  250. Ref<Font> get_custom_font(int p_column) const;
  251. void set_custom_font_size(int p_column, int p_font_size);
  252. int get_custom_font_size(int p_column) const;
  253. void set_custom_bg_color(int p_column, const Color &p_color, bool p_bg_outline = false);
  254. void clear_custom_bg_color(int p_column);
  255. Color get_custom_bg_color(int p_column) const;
  256. void set_custom_as_button(int p_column, bool p_button);
  257. bool is_custom_set_as_button(int p_column) const;
  258. void set_tooltip_text(int p_column, const String &p_tooltip);
  259. String get_tooltip_text(int p_column) const;
  260. void set_text_alignment(int p_column, HorizontalAlignment p_alignment);
  261. HorizontalAlignment get_text_alignment(int p_column) const;
  262. void set_expand_right(int p_column, bool p_enable);
  263. bool get_expand_right(int p_column) const;
  264. void set_disable_folding(bool p_disable);
  265. bool is_folding_disabled() const;
  266. Size2 get_minimum_size(int p_column);
  267. /* Item manipulation */
  268. TreeItem *create_child(int p_index = -1);
  269. void add_child(TreeItem *p_item);
  270. void remove_child(TreeItem *p_item);
  271. Tree *get_tree() const;
  272. TreeItem *get_prev();
  273. TreeItem *get_next() const;
  274. TreeItem *get_parent() const;
  275. TreeItem *get_first_child() const;
  276. TreeItem *get_prev_in_tree(bool p_wrap = false);
  277. TreeItem *get_next_in_tree(bool p_wrap = false);
  278. TreeItem *get_prev_visible(bool p_wrap = false);
  279. TreeItem *get_next_visible(bool p_wrap = false);
  280. TreeItem *get_child(int p_index);
  281. int get_visible_child_count();
  282. int get_child_count();
  283. TypedArray<TreeItem> get_children();
  284. void clear_children();
  285. int get_index();
  286. #ifdef DEV_ENABLED
  287. // This debugging code can be removed once the current refactoring of this class is complete.
  288. void validate_cache() const;
  289. #else
  290. void validate_cache() const {}
  291. #endif
  292. void move_before(TreeItem *p_item);
  293. void move_after(TreeItem *p_item);
  294. void call_recursive(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error);
  295. ~TreeItem();
  296. };
  297. VARIANT_ENUM_CAST(TreeItem::TreeCellMode);
  298. class VBoxContainer;
  299. class Tree : public Control {
  300. GDCLASS(Tree, Control);
  301. public:
  302. enum SelectMode {
  303. SELECT_SINGLE,
  304. SELECT_ROW,
  305. SELECT_MULTI
  306. };
  307. enum DropModeFlags {
  308. DROP_MODE_DISABLED = 0,
  309. DROP_MODE_ON_ITEM = 1,
  310. DROP_MODE_INBETWEEN = 2
  311. };
  312. private:
  313. friend class TreeItem;
  314. TreeItem *root = nullptr;
  315. TreeItem *popup_edited_item = nullptr;
  316. TreeItem *selected_item = nullptr;
  317. TreeItem *edited_item = nullptr;
  318. TreeItem *popup_pressing_edited_item = nullptr; // Candidate.
  319. int popup_pressing_edited_item_column = -1;
  320. TreeItem *drop_mode_over = nullptr;
  321. int drop_mode_section = 0;
  322. TreeItem *single_select_defer = nullptr;
  323. int single_select_defer_column = 0;
  324. int pressed_button = -1;
  325. bool pressing_for_editor = false;
  326. String pressing_for_editor_text;
  327. Vector2 pressing_pos;
  328. Rect2 pressing_item_rect;
  329. float range_drag_base = 0.0;
  330. bool range_drag_enabled = false;
  331. Vector2 range_drag_capture_pos;
  332. bool propagate_mouse_activated = false;
  333. //TreeItem *cursor_item;
  334. //int cursor_column;
  335. Rect2 custom_popup_rect;
  336. int edited_col = -1;
  337. int selected_col = -1;
  338. int popup_edited_item_col = -1;
  339. bool hide_root = false;
  340. SelectMode select_mode = SELECT_SINGLE;
  341. int blocked = 0;
  342. int drop_mode_flags = 0;
  343. struct ColumnInfo {
  344. int custom_min_width = 0;
  345. int expand_ratio = 1;
  346. bool expand = true;
  347. bool clip_content = false;
  348. String title;
  349. HorizontalAlignment title_alignment = HORIZONTAL_ALIGNMENT_CENTER;
  350. Ref<TextParagraph> text_buf;
  351. String language;
  352. Control::TextDirection text_direction = Control::TEXT_DIRECTION_INHERITED;
  353. ColumnInfo() {
  354. text_buf.instantiate();
  355. }
  356. };
  357. bool show_column_titles = false;
  358. VBoxContainer *popup_editor_vb = nullptr;
  359. Popup *popup_editor = nullptr;
  360. LineEdit *line_editor = nullptr;
  361. TextEdit *text_editor = nullptr;
  362. HSlider *value_editor = nullptr;
  363. bool updating_value_editor = false;
  364. uint64_t focus_in_id = 0;
  365. PopupMenu *popup_menu = nullptr;
  366. Vector<ColumnInfo> columns;
  367. Timer *range_click_timer = nullptr;
  368. TreeItem *range_item_last = nullptr;
  369. bool range_up_last = false;
  370. void _range_click_timeout();
  371. int compute_item_height(TreeItem *p_item) const;
  372. int get_item_height(TreeItem *p_item) const;
  373. void _update_all();
  374. void update_column(int p_col);
  375. void update_item_cell(TreeItem *p_item, int p_col);
  376. void update_item_cache(TreeItem *p_item);
  377. //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);
  378. 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);
  379. int draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 &p_draw_size, TreeItem *p_item, int *r_self_height = nullptr);
  380. 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);
  381. 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);
  382. void _line_editor_submit(String p_text);
  383. void _apply_multiline_edit();
  384. void _text_editor_popup_modal_close();
  385. void _text_editor_gui_input(const Ref<InputEvent> &p_event);
  386. void value_editor_changed(double p_value);
  387. void popup_select(int p_option);
  388. void _notification(int p_what);
  389. void item_edited(int p_column, TreeItem *p_item, MouseButton p_custom_mouse_index = MouseButton::NONE);
  390. void item_changed(int p_column, TreeItem *p_item);
  391. void item_selected(int p_column, TreeItem *p_item);
  392. void item_deselected(int p_column, TreeItem *p_item);
  393. void propagate_set_columns(TreeItem *p_item);
  394. struct ThemeCache {
  395. Ref<StyleBox> panel_style;
  396. Ref<StyleBox> focus_style;
  397. Ref<Font> font;
  398. Ref<Font> tb_font;
  399. int font_size = 0;
  400. int tb_font_size = 0;
  401. Ref<StyleBox> selected;
  402. Ref<StyleBox> selected_focus;
  403. Ref<StyleBox> cursor;
  404. Ref<StyleBox> cursor_unfocus;
  405. Ref<StyleBox> button_pressed;
  406. Ref<StyleBox> title_button;
  407. Ref<StyleBox> title_button_hover;
  408. Ref<StyleBox> title_button_pressed;
  409. Ref<StyleBox> custom_button;
  410. Ref<StyleBox> custom_button_hover;
  411. Ref<StyleBox> custom_button_pressed;
  412. Color title_button_color;
  413. Ref<Texture2D> checked;
  414. Ref<Texture2D> unchecked;
  415. Ref<Texture2D> indeterminate;
  416. Ref<Texture2D> arrow;
  417. Ref<Texture2D> arrow_collapsed;
  418. Ref<Texture2D> arrow_collapsed_mirrored;
  419. Ref<Texture2D> select_arrow;
  420. Ref<Texture2D> updown;
  421. Color font_color;
  422. Color font_selected_color;
  423. Color guide_color;
  424. Color drop_position_color;
  425. Color relationship_line_color;
  426. Color parent_hl_line_color;
  427. Color children_hl_line_color;
  428. Color custom_button_font_highlight;
  429. Color font_outline_color;
  430. float base_scale = 1.0;
  431. int font_outline_size = 0;
  432. int h_separation = 0;
  433. int v_separation = 0;
  434. int item_margin = 0;
  435. int button_margin = 0;
  436. int icon_max_width = 0;
  437. Point2 offset;
  438. int draw_relationship_lines = 0;
  439. int relationship_line_width = 0;
  440. int parent_hl_line_width = 0;
  441. int children_hl_line_width = 0;
  442. int parent_hl_line_margin = 0;
  443. int draw_guides = 0;
  444. int scroll_border = 0;
  445. int scroll_speed = 0;
  446. int scrollbar_margin_top = -1;
  447. int scrollbar_margin_right = -1;
  448. int scrollbar_margin_bottom = -1;
  449. int scrollbar_margin_left = -1;
  450. int scrollbar_h_separation = 0;
  451. int scrollbar_v_separation = 0;
  452. } theme_cache;
  453. struct Cache {
  454. enum ClickType {
  455. CLICK_NONE,
  456. CLICK_TITLE,
  457. CLICK_BUTTON,
  458. };
  459. ClickType click_type = Cache::CLICK_NONE;
  460. ClickType hover_type = Cache::CLICK_NONE;
  461. int click_index = -1;
  462. int click_id = -1;
  463. TreeItem *click_item = nullptr;
  464. int click_column = 0;
  465. int hover_index = -1;
  466. Point2 click_pos;
  467. TreeItem *hover_item = nullptr;
  468. int hover_cell = -1;
  469. bool rtl = false;
  470. } cache;
  471. int _get_title_button_height() const;
  472. Size2 _get_cell_icon_size(const TreeItem::Cell &p_cell) const;
  473. void _scroll_moved(float p_value);
  474. HScrollBar *h_scroll = nullptr;
  475. VScrollBar *v_scroll = nullptr;
  476. bool h_scroll_enabled = true;
  477. bool v_scroll_enabled = true;
  478. Size2 get_internal_min_size() const;
  479. void update_scrollbars();
  480. Rect2 search_item_rect(TreeItem *p_from, TreeItem *p_item);
  481. //Rect2 get_item_rect(TreeItem *p_item);
  482. uint64_t last_keypress = 0;
  483. String incr_search;
  484. bool cursor_can_exit_tree = true;
  485. void _do_incr_search(const String &p_add);
  486. TreeItem *_search_item_text(TreeItem *p_at, const String &p_find, int *r_col, bool p_selectable, bool p_backwards = false);
  487. TreeItem *_find_item_at_pos(TreeItem *p_item, const Point2 &p_pos, int &r_column, int &h, int &section) const;
  488. /* float drag_speed;
  489. float drag_accum;
  490. float last_drag_accum;
  491. float last_drag_time;
  492. float time_since_motion;*/
  493. float drag_speed = 0.0;
  494. float drag_from = 0.0;
  495. float drag_accum = 0.0;
  496. Vector2 last_speed;
  497. bool drag_touching = false;
  498. bool drag_touching_deaccel = false;
  499. bool click_handled = false;
  500. bool allow_rmb_select = false;
  501. bool scrolling = false;
  502. bool allow_reselect = false;
  503. bool allow_search = true;
  504. bool force_edit_checkbox_only_on_checkbox = false;
  505. bool hide_folding = false;
  506. bool enable_recursive_folding = true;
  507. int _count_selected_items(TreeItem *p_from) const;
  508. bool _is_branch_selected(TreeItem *p_from) const;
  509. bool _is_sibling_branch_selected(TreeItem *p_from) const;
  510. void _go_left();
  511. void _go_right();
  512. void _go_down();
  513. void _go_up();
  514. bool _scroll(bool p_horizontal, float p_pages);
  515. Rect2 _get_scrollbar_layout_rect() const;
  516. Rect2 _get_content_rect() const; // Considering the background stylebox and scrollbars.
  517. protected:
  518. virtual void _update_theme_item_cache() override;
  519. static void _bind_methods();
  520. public:
  521. virtual void gui_input(const Ref<InputEvent> &p_event) override;
  522. virtual String get_tooltip(const Point2 &p_pos) const override;
  523. TreeItem *get_item_at_position(const Point2 &p_pos) const;
  524. int get_column_at_position(const Point2 &p_pos) const;
  525. int get_drop_section_at_position(const Point2 &p_pos) const;
  526. int get_button_id_at_position(const Point2 &p_pos) const;
  527. void clear();
  528. TreeItem *create_item(TreeItem *p_parent = nullptr, int p_index = -1);
  529. TreeItem *get_root() const;
  530. TreeItem *get_last_item() const;
  531. void set_column_custom_minimum_width(int p_column, int p_min_width);
  532. void set_column_expand(int p_column, bool p_expand);
  533. void set_column_expand_ratio(int p_column, int p_ratio);
  534. void set_column_clip_content(int p_column, bool p_fit);
  535. int get_column_minimum_width(int p_column) const;
  536. int get_column_width(int p_column) const;
  537. int get_column_expand_ratio(int p_column) const;
  538. bool is_column_expanding(int p_column) const;
  539. bool is_column_clipping_content(int p_column) const;
  540. void set_hide_root(bool p_enabled);
  541. bool is_root_hidden() const;
  542. TreeItem *get_next_selected(TreeItem *p_item);
  543. TreeItem *get_selected() const;
  544. void set_selected(TreeItem *p_item, int p_column = 0);
  545. int get_selected_column() const;
  546. int get_pressed_button() const;
  547. void set_select_mode(SelectMode p_mode);
  548. SelectMode get_select_mode() const;
  549. void deselect_all();
  550. bool is_anything_selected();
  551. void set_columns(int p_columns);
  552. int get_columns() const;
  553. void set_column_title(int p_column, const String &p_title);
  554. String get_column_title(int p_column) const;
  555. void set_column_title_alignment(int p_column, HorizontalAlignment p_alignment);
  556. HorizontalAlignment get_column_title_alignment(int p_column) const;
  557. void set_column_title_direction(int p_column, Control::TextDirection p_text_direction);
  558. Control::TextDirection get_column_title_direction(int p_column) const;
  559. void set_column_title_language(int p_column, const String &p_language);
  560. String get_column_title_language(int p_column) const;
  561. void set_column_titles_visible(bool p_show);
  562. bool are_column_titles_visible() const;
  563. TreeItem *get_edited() const;
  564. int get_edited_column() const;
  565. void ensure_cursor_is_visible();
  566. Rect2 get_custom_popup_rect() const;
  567. int get_item_offset(TreeItem *p_item) const;
  568. Rect2 get_item_rect(TreeItem *p_item, int p_column = -1, int p_button = -1) const;
  569. bool edit_selected(bool p_force_edit = false);
  570. bool is_editing();
  571. void set_editor_selection(int p_from_line, int p_to_line, int p_from_column = -1, int p_to_column = -1, int p_caret = 0);
  572. // First item that starts with the text, from the current focused item down and wraps around.
  573. TreeItem *search_item_text(const String &p_find, int *r_col = nullptr, bool p_selectable = false);
  574. // First item that matches the whole text, from the first item down.
  575. TreeItem *get_item_with_text(const String &p_find) const;
  576. TreeItem *get_item_with_metadata(const Variant &p_find, int p_column = -1) const;
  577. Point2 get_scroll() const;
  578. void scroll_to_item(TreeItem *p_item, bool p_center_on_item = false);
  579. void set_h_scroll_enabled(bool p_enable);
  580. bool is_h_scroll_enabled() const;
  581. void set_v_scroll_enabled(bool p_enable);
  582. bool is_v_scroll_enabled() const;
  583. void set_cursor_can_exit_tree(bool p_enable);
  584. VScrollBar *get_vscroll_bar() { return v_scroll; }
  585. void set_hide_folding(bool p_hide);
  586. bool is_folding_hidden() const;
  587. void set_enable_recursive_folding(bool p_enable);
  588. bool is_recursive_folding_enabled() const;
  589. void set_drop_mode_flags(int p_flags);
  590. int get_drop_mode_flags() const;
  591. void set_edit_checkbox_cell_only_when_checkbox_is_pressed(bool p_enable);
  592. bool get_edit_checkbox_cell_only_when_checkbox_is_pressed() const;
  593. void set_allow_rmb_select(bool p_allow);
  594. bool get_allow_rmb_select() const;
  595. void set_allow_reselect(bool p_allow);
  596. bool get_allow_reselect() const;
  597. void set_allow_search(bool p_allow);
  598. bool get_allow_search() const;
  599. Size2 get_minimum_size() const override;
  600. Tree();
  601. ~Tree();
  602. };
  603. VARIANT_ENUM_CAST(Tree::SelectMode);
  604. VARIANT_ENUM_CAST(Tree::DropModeFlags);
  605. #endif // TREE_H