Debian Codegraph @

scene/gui/tree.h

raw symbols SCIP
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
31 #pragma once
32
33 #include "scene/gui/control.h"
34 #include "scene/resources/text_paragraph.h"
35
36 class VBoxContainer;
37 class HScrollBar;
38 class HSlider;
39 class LineEdit;
40 class Popup;
41 class PopupMenu;
42 class TextEdit;
43 class Timer;
44 class Tree;
45 class VScrollBar;
46
47 class TreeItem : public Object {
48 GDCLASS(TreeItem, Object);
49
50 public:
51 enum TreeCellMode {
52 CELL_MODE_STRING,
53 CELL_MODE_CHECK,
54 CELL_MODE_RANGE,
55 CELL_MODE_ICON,
56 CELL_MODE_CUSTOM,
57 };
58
59 private:
60 friend class Tree;
61
62 struct Cell {
63 mutable RID accessibility_cell_element;
64 TreeCellMode mode = TreeItem::CELL_MODE_STRING;
65
66 Ref<Texture2D> icon;
67 Ref<Texture2D> icon_overlay;
68 Rect2i icon_region;
69 String text;
70 String xl_text;
71 Node::AutoTranslateMode auto_translate_mode = Node::AUTO_TRANSLATE_MODE_INHERIT;
72 String description;
73 bool edit_multiline = false;
74 String suffix;
75 Ref<TextParagraph> text_buf;
76 String language;
77 TextServer::StructuredTextParser st_parser = TextServer::STRUCTURED_TEXT_DEFAULT;
78 Array st_args;
79 Control::TextDirection text_direction = Control::TEXT_DIRECTION_INHERITED;
80 TextServer::AutowrapMode autowrap_mode = TextServer::AUTOWRAP_OFF;
81 bool dirty = true;
82 double min = 0.0;
83 double max = 100.0;
84 double step = 1.0;
85 double val = 0.0;
86 int icon_max_w = 0;
87 bool expr = false;
88 bool checked = false;
89 bool indeterminate = false;
90 bool editable = false;
91 bool selected = false;
92 bool selectable = true;
93 bool custom_color = false;
94 Color color;
95 bool custom_bg_color = false;
96 bool custom_bg_outline = false;
97 Color bg_color;
98 bool custom_button = false;
99 bool expand_right = false;
100 Color icon_color = Color(1, 1, 1);
101 Ref<StyleBox> custom_stylebox;
102
103 Rect2 focus_rect;
104 Size2i cached_minimum_size;
105 bool cached_minimum_size_dirty = true;
106
107 HorizontalAlignment text_alignment = HORIZONTAL_ALIGNMENT_LEFT;
108
109 Variant meta;
110 String tooltip;
111
112 Callable custom_draw_callback;
113
114 struct Button {
115 mutable RID accessibility_button_element;
116 int id = 0;
117 bool disabled = false;
118 Ref<Texture2D> texture;
119 Color color = Color(1, 1, 1, 1);
120 String tooltip;
121 String description;
122 };
123
124 Vector<Button> buttons;
125
126 Ref<Font> custom_font;
127 int custom_font_size = -1;
128
129 Cell() {
130 text_buf.instantiate();
131 text_buf->set_text_overrun_behavior(TextServer::OVERRUN_TRIM_ELLIPSIS);
132 }
133
134 Size2 get_icon_size() const;
135 void draw_icon(const RID &p_where, const Point2 &p_pos, const Size2 &p_size = Size2(), const Rect2i &p_region = Rect2i(), const Color &p_color = Color()) const;
136 };
137
138 mutable RID accessibility_row_element;
139 mutable bool accessibility_row_dirty = true;
140
141 Vector<Cell> cells;
142
143 Rect2 focus_rect;
144 bool collapsed = false; // Won't show children.
145 bool visible = true;
146 bool parent_visible_in_tree = true;
147 bool disable_folding = false;
148 int custom_min_height = 0;
149
150 TreeItem *parent = nullptr; // Parent item.
151 TreeItem *prev = nullptr; // Previous in list.
152 TreeItem *next = nullptr; // Next in list.
153 TreeItem *first_child = nullptr;
154 TreeItem *last_child = nullptr;
155
156 LocalVector<TreeItem *> children_cache;
157 bool is_root = false; // For tree root.
158 Tree *tree = nullptr; // Tree (for reference).
159
160 TreeItem(Tree *p_tree);
161
162 void _changed_notify(int p_cell);
163 void _changed_notify();
164 void _cell_selected(int p_cell);
165 void _cell_deselected(int p_cell);
166 void _handle_visibility_changed(bool p_visible);
167 void _propagate_visibility_changed(bool p_parent_visible_in_tree);
168
169 void _change_tree(Tree *p_tree);
170
171 _FORCE_INLINE_ void _create_children_cache() {
172 if (children_cache.is_empty()) {
173 TreeItem *c = first_child;
174 while (c) {
175 children_cache.push_back(c);
176 c = c->next;
177 }
178 }
179 }
180
181 _FORCE_INLINE_ void _unlink_from_tree() {
182 if (accessibility_row_element.is_valid()) {
183 DisplayServer::get_singleton()->accessibility_free_element(accessibility_row_element);
184 accessibility_row_element = RID();
185 }
186 for (Cell &cell : cells) {
187 if (cell.accessibility_cell_element.is_valid()) {
188 DisplayServer::get_singleton()->accessibility_free_element(cell.accessibility_cell_element);
189 cell.accessibility_cell_element = RID();
190 }
191 for (Cell::Button &btn : cell.buttons) {
192 if (btn.accessibility_button_element.is_valid()) {
193 DisplayServer::get_singleton()->accessibility_free_element(btn.accessibility_button_element);
194 btn.accessibility_button_element = RID();
195 }
196 }
197 }
198 TreeItem *p = get_prev();
199 if (p) {
200 p->next = next;
201 }
202 if (next) {
203 next->prev = p;
204 }
205 if (parent) {
206 if (!parent->children_cache.is_empty()) {
207 parent->children_cache.erase(this);
208 }
209 if (parent->first_child == this) {
210 parent->first_child = next;
211 }
212 if (parent->last_child == this) {
213 parent->last_child = prev;
214 }
215 }
216 }
217
218 bool _is_any_collapsed(bool p_only_visible);
219
220 protected:
221 static void _bind_methods();
222
223 #ifndef DISABLE_DEPRECATED
224 void _add_button_bind_compat_76829(int p_column, const Ref<Texture2D> &p_button, int p_id, bool p_disabled, const String &p_tooltip);
225 static void _bind_compatibility_methods();
226 #endif
227
228 // Bind helpers.
229 Dictionary _get_range_config(int p_column) {
230 Dictionary d;
231 double min = 0.0, max = 0.0, step = 0.0;
232 get_range_config(p_column, min, max, step);
233 d["min"] = min;
234 d["max"] = max;
235 d["step"] = step;
236 d["expr"] = false;
237
238 return d;
239 }
240
241 void _call_recursive_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error);
242
243 public:
244 // Cell mode.
245 void set_cell_mode(int p_column, TreeCellMode p_mode);
246 TreeCellMode get_cell_mode(int p_column) const;
247
248 // Auto translate mode.
249 void set_auto_translate_mode(int p_column, Node::AutoTranslateMode p_mode);
250 Node::AutoTranslateMode get_auto_translate_mode(int p_column) const;
251
252 // Multiline editable.
253 void set_edit_multiline(int p_column, bool p_multiline);
254 bool is_edit_multiline(int p_column) const;
255
256 // Check mode.
257 void set_checked(int p_column, bool p_checked);
258 void set_indeterminate(int p_column, bool p_indeterminate);
259 bool is_checked(int p_column) const;
260 bool is_indeterminate(int p_column) const;
261
262 void propagate_check(int p_column, bool p_emit_signal = true);
263
264 String atr(int p_column, const String &p_text) const;
265
266 private:
267 // Check helpers.
268 void _propagate_check_through_children(int p_column, bool p_checked, bool p_emit_signal);
269 void _propagate_check_through_parents(int p_column, bool p_emit_signal);
270
271 TreeItem *_get_prev_in_tree(bool p_wrap = false, bool p_include_invisible = false);
272 TreeItem *_get_next_in_tree(bool p_wrap = false, bool p_include_invisible = false);
273
274 public:
275 void set_text(int p_column, String p_text);
276 String get_text(int p_column) const;
277
278 void set_description(int p_column, String p_text);
279 String get_description(int p_column) const;
280
281 void set_text_direction(int p_column, Control::TextDirection p_text_direction);
282 Control::TextDirection get_text_direction(int p_column) const;
283
284 void set_autowrap_mode(int p_column, TextServer::AutowrapMode p_mode);
285 TextServer::AutowrapMode get_autowrap_mode(int p_column) const;
286
287 void set_text_overrun_behavior(int p_column, TextServer::OverrunBehavior p_behavior);
288 TextServer::OverrunBehavior get_text_overrun_behavior(int p_column) const;
289
290 void set_structured_text_bidi_override(int p_column, TextServer::StructuredTextParser p_parser);
291 TextServer::StructuredTextParser get_structured_text_bidi_override(int p_column) const;
292
293 void set_structured_text_bidi_override_options(int p_column, const Array &p_args);
294 Array get_structured_text_bidi_override_options(int p_column) const;
295
296 void set_language(int p_column, const String &p_language);
297 String get_language(int p_column) const;
298
299 void set_suffix(int p_column, String p_suffix);
300 String get_suffix(int p_column) const;
301
302 void set_icon(int p_column, const Ref<Texture2D> &p_icon);
303 Ref<Texture2D> get_icon(int p_column) const;
304
305 void set_icon_overlay(int p_column, const Ref<Texture2D> &p_icon_overlay);
306 Ref<Texture2D> get_icon_overlay(int p_column) const;
307
308 void set_icon_region(int p_column, const Rect2 &p_icon_region);
309 Rect2 get_icon_region(int p_column) const;
310
311 void set_icon_modulate(int p_column, const Color &p_modulate);
312 Color get_icon_modulate(int p_column) const;
313
314 void set_icon_max_width(int p_column, int p_max);
315 int get_icon_max_width(int p_column) const;
316
317 void clear_buttons();
318 void add_button(int p_column, const Ref<Texture2D> &p_button, int p_id = -1, bool p_disabled = false, const String &p_tooltip = "", const String &p_description = "");
319 int get_button_count(int p_column) const;
320 String get_button_tooltip_text(int p_column, int p_index) const;
321 Ref<Texture2D> get_button(int p_column, int p_index) const;
322 int get_button_id(int p_column, int p_index) const;
323 void erase_button(int p_column, int p_index);
324 int get_button_by_id(int p_column, int p_id) const;
325 Color get_button_color(int p_column, int p_index) const;
326 void set_button_tooltip_text(int p_column, int p_index, const String &p_tooltip);
327 void set_button(int p_column, int p_index, const Ref<Texture2D> &p_button);
328 void set_button_description(int p_column, int p_index, const String &p_description);
329 void set_button_color(int p_column, int p_index, const Color &p_color);
330 void set_button_disabled(int p_column, int p_index, bool p_disabled);
331 bool is_button_disabled(int p_column, int p_index) const;
332
333 // Range works for mode number or mode combo.
334 void set_range(int p_column, double p_value);
335 double get_range(int p_column) const;
336
337 void set_range_config(int p_column, double p_min, double p_max, double p_step, bool p_exp = false);
338 void get_range_config(int p_column, double &r_min, double &r_max, double &r_step) const;
339 bool is_range_exponential(int p_column) const;
340
341 void set_metadata(int p_column, const Variant &p_meta);
342 Variant get_metadata(int p_column) const;
343
344 #ifndef DISABLE_DEPRECATED
345 void set_custom_draw(int p_column, Object *p_object, const StringName &p_callback);
346 #endif // DISABLE_DEPRECATED
347 void set_custom_draw_callback(int p_column, const Callable &p_callback);
348 Callable get_custom_draw_callback(int p_column) const;
349
350 void set_collapsed(bool p_collapsed);
351 bool is_collapsed();
352
353 void set_collapsed_recursive(bool p_collapsed);
354 bool is_any_collapsed(bool p_only_visible = false);
355
356 void set_visible(bool p_visible);
357 bool is_visible();
358 bool is_visible_in_tree() const;
359
360 void uncollapse_tree();
361
362 void set_custom_minimum_height(int p_height);
363 int get_custom_minimum_height() const;
364
365 void set_custom_stylebox(int p_column, const Ref<StyleBox> &p_stylebox);
366 Ref<StyleBox> get_custom_stylebox(int p_column) const;
367
368 void set_selectable(int p_column, bool p_selectable);
369 bool is_selectable(int p_column) const;
370
371 bool is_selected(int p_column);
372 bool is_any_column_selected() const;
373 void select(int p_column);
374 void deselect(int p_column);
375 void set_as_cursor(int p_column);
376
377 void set_editable(int p_column, bool p_editable);
378 bool is_editable(int p_column);
379
380 void set_custom_color(int p_column, const Color &p_color);
381 Color get_custom_color(int p_column) const;
382 void clear_custom_color(int p_column);
383
384 void set_custom_font(int p_column, const Ref<Font> &p_font);
385 Ref<Font> get_custom_font(int p_column) const;
386
387 void set_custom_font_size(int p_column, int p_font_size);
388 int get_custom_font_size(int p_column) const;
389
390 void set_custom_bg_color(int p_column, const Color &p_color, bool p_bg_outline = false);
391 void clear_custom_bg_color(int p_column);
392 Color get_custom_bg_color(int p_column) const;
393
394 void set_custom_as_button(int p_column, bool p_button);
395 bool is_custom_set_as_button(int p_column) const;
396
397 void set_tooltip_text(int p_column, const String &p_tooltip);
398 String get_tooltip_text(int p_column) const;
399
400 void set_text_alignment(int p_column, HorizontalAlignment p_alignment);
401 HorizontalAlignment get_text_alignment(int p_column) const;
402
403 void set_expand_right(int p_column, bool p_enable);
404 bool get_expand_right(int p_column) const;
405
406 void set_disable_folding(bool p_disable);
407 bool is_folding_disabled() const;
408
409 Size2 get_minimum_size(int p_column);
410
411 // Item manipulation.
412 TreeItem *create_child(int p_index = -1);
413 void add_child(TreeItem *p_item);
414 void remove_child(TreeItem *p_item);
415
416 Tree *get_tree() const;
417
418 TreeItem *get_prev();
419 TreeItem *get_next() const;
420 TreeItem *get_parent() const;
421 TreeItem *get_first_child() const;
422
423 TreeItem *get_prev_in_tree(bool p_wrap = false);
424 TreeItem *get_next_in_tree(bool p_wrap = false);
425
426 TreeItem *get_prev_visible(bool p_wrap = false);
427 TreeItem *get_next_visible(bool p_wrap = false);
428
429 TreeItem *get_child(int p_index);
430 int get_visible_child_count();
431 int get_child_count();
432 TypedArray<TreeItem> get_children();
433 void clear_children();
434 int get_index();
435
436 #ifdef DEV_ENABLED
437 // This debugging code can be removed once the current refactoring of this class is complete.
438 void validate_cache() const;
439 #else
440 void validate_cache() const {}
441 #endif
442
443 void move_before(TreeItem *p_item);
444 void move_after(TreeItem *p_item);
445
446 void call_recursive(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error);
447
448 ~TreeItem();
449 };
450
451 VARIANT_ENUM_CAST(TreeItem::TreeCellMode);
452
453 class Tree : public Control {
454 GDCLASS(Tree, Control);
455
456 public:
457 enum SelectMode {
458 SELECT_SINGLE,
459 SELECT_ROW,
460 SELECT_MULTI
461 };
462
463 enum DropModeFlags {
464 DROP_MODE_DISABLED = 0,
465 DROP_MODE_ON_ITEM = 1,
466 DROP_MODE_INBETWEEN = 2
467 };
468
469 enum ScrollHintMode {
470 SCROLL_HINT_MODE_DISABLED,
471 SCROLL_HINT_MODE_BOTH,
472 SCROLL_HINT_MODE_TOP,
473 SCROLL_HINT_MODE_BOTTOM,
474 };
475
476 private:
477 friend class TreeItem;
478
479 TreeItem *root = nullptr;
480 TreeItem *popup_edited_item = nullptr;
481 TreeItem *selected_item = nullptr;
482 TreeItem *edited_item = nullptr;
483 TreeItem *shift_anchor = nullptr;
484
485 TreeItem *popup_pressing_edited_item = nullptr; // Candidate.
486 int popup_pressing_edited_item_column = -1;
487
488 TreeItem *drop_mode_over = nullptr;
489 int drop_mode_section = 0;
490
491 TreeItem *single_select_defer = nullptr;
492 int single_select_defer_column = 0;
493
494 int pressed_button = -1;
495 bool pressing_for_editor = false;
496 Vector2 pressing_pos;
497
498 Vector2 hovered_pos;
499 bool is_mouse_hovering = false;
500
501 float range_drag_base = 0.0;
502 bool range_drag_enabled = false;
503 Vector2 range_drag_capture_pos;
504
505 bool propagate_mouse_activated = false;
506 float content_scale_factor = 0.0;
507
508 Rect2 custom_popup_rect;
509 int edited_col = -1;
510 int selected_col = -1;
511 int selected_button = -1;
512 int popup_edited_item_col = -1;
513 bool hide_root = false;
514 SelectMode select_mode = SELECT_SINGLE;
515
516 int blocked = 0;
517
518 int drop_mode_flags = 0;
519
520 struct ColumnInfo {
521 mutable RID accessibility_col_element;
522 int custom_min_width = 0;
523 int expand_ratio = 1;
524 bool expand = true;
525 bool clip_content = false;
526 String title_tooltip;
527 String title;
528 String xl_title;
529 HorizontalAlignment title_alignment = HORIZONTAL_ALIGNMENT_CENTER;
530 Ref<TextParagraph> text_buf;
531 String language;
532 Control::TextDirection text_direction = Control::TEXT_DIRECTION_INHERITED;
533
534 mutable int cached_minimum_width = 0;
535 mutable bool cached_minimum_width_dirty = true;
536
537 ColumnInfo() {
538 text_buf.instantiate();
539 }
540 };
541
542 bool show_column_titles = false;
543
544 bool popup_edit_committed = true;
545 RID accessibility_scroll_element;
546 RID header_ci; // Separate canvas item for drawing column headers
547 RID content_ci; // Separate canvas item for drawing tree rows
548
549 VBoxContainer *popup_editor_vb = nullptr;
550 Popup *popup_editor = nullptr;
551 LineEdit *line_editor = nullptr;
552 TextEdit *text_editor = nullptr;
553 HSlider *value_editor = nullptr;
554 bool updating_value_editor = false;
555 uint64_t focus_in_id = 0;
556 PopupMenu *popup_menu = nullptr;
557
558 Vector<ColumnInfo> columns;
559
560 Timer *range_click_timer = nullptr;
561 TreeItem *range_item_last = nullptr;
562 bool range_up_last = false;
563 void _range_click_timeout();
564
565 int compute_item_height(TreeItem *p_item) const;
566 int get_item_height(TreeItem *p_item) const;
567 Point2i convert_rtl_position(const Point2i &pos, int width = 0) const;
568 Rect2i convert_rtl_rect(const Rect2i &Rect2) const;
569 void _update_all();
570 void update_column(int p_col);
571 void update_item_cell(TreeItem *p_item, int p_col) const;
572 void update_item_cache(TreeItem *p_item) const;
573 void draw_item_rect(const 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) const;
574 int draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 &p_draw_size, TreeItem *p_item, int &r_self_height);
575 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);
576 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);
577 void _line_editor_submit(String p_text);
578 void _apply_multiline_edit(bool p_hide_focus = false);
579 void _text_editor_popup_modal_close();
580 void _text_editor_gui_input(const Ref<InputEvent> &p_event);
581 void value_editor_changed(double p_value);
582 void _update_popup_menu(const TreeItem::Cell &p_cell);
583 void _update_value_editor(const TreeItem::Cell &p_cell);
584
585 void popup_select(int p_option);
586
587 void item_edited(int p_column, TreeItem *p_item, MouseButton p_custom_mouse_index = MouseButton::NONE);
588 void item_changed(int p_column, TreeItem *p_item);
589 void item_selected(int p_column, TreeItem *p_item);
590 void item_deselected(int p_column, TreeItem *p_item);
591 void update_min_size_for_item_change();
592
593 void propagate_set_columns(TreeItem *p_item);
594
595 struct ThemeCache {
596 Ref<StyleBox> panel_style;
597 Ref<StyleBox> focus_style;
598
599 Ref<Font> font;
600 Ref<Font> tb_font;
601 int font_size = 0;
602 int tb_font_size = 0;
603
604 Ref<StyleBox> hovered;
605 Ref<StyleBox> hovered_dimmed;
606 Ref<StyleBox> hovered_selected;
607 Ref<StyleBox> hovered_selected_focus;
608 Ref<StyleBox> selected;
609 Ref<StyleBox> selected_focus;
610 Ref<StyleBox> cursor;
611 Ref<StyleBox> cursor_unfocus;
612 Ref<StyleBox> button_hover;
613 Ref<StyleBox> button_pressed;
614 Ref<StyleBox> title_button;
615 Ref<StyleBox> title_button_hover;
616 Ref<StyleBox> title_button_pressed;
617 Ref<StyleBox> custom_button;
618 Ref<StyleBox> custom_button_hover;
619 Ref<StyleBox> custom_button_pressed;
620
621 Color title_button_color;
622
623 Ref<Texture2D> checked;
624 Ref<Texture2D> unchecked;
625 Ref<Texture2D> checked_disabled;
626 Ref<Texture2D> unchecked_disabled;
627 Ref<Texture2D> indeterminate;
628 Ref<Texture2D> indeterminate_disabled;
629 Ref<Texture2D> arrow;
630 Ref<Texture2D> arrow_collapsed;
631 Ref<Texture2D> arrow_collapsed_mirrored;
632 Ref<Texture2D> select_arrow;
633 Ref<Texture2D> updown;
634 Ref<Texture2D> scroll_hint;
635
636 Color font_color;
637 Color font_hovered_color;
638 Color font_hovered_dimmed_color;
639 Color font_hovered_selected_color;
640 Color font_selected_color;
641 Color font_disabled_color;
642 Color guide_color;
643 Color drop_position_color;
644 Color relationship_line_color;
645 Color parent_hl_line_color;
646 Color children_hl_line_color;
647 Color custom_button_font_highlight;
648 Color font_outline_color;
649 Color scroll_hint_color;
650
651 float base_scale = 1.0;
652 int font_outline_size = 0;
653
654 int h_separation = 0;
655 int v_separation = 0;
656 int inner_item_margin_bottom = 0;
657 int inner_item_margin_left = 0;
658 int inner_item_margin_right = 0;
659 int inner_item_margin_top = 0;
660 int item_margin = 0;
661 int check_h_separation = 0;
662 int icon_h_separation = 0;
663 int button_margin = 0;
664 int icon_max_width = 0;
665 Point2 offset;
666
667 int draw_relationship_lines = 0;
668 int relationship_line_width = 0;
669 int parent_hl_line_width = 0;
670 int children_hl_line_width = 0;
671 int parent_hl_line_margin = 0;
672 int draw_guides = 0;
673
674 int dragging_unfold_wait_msec = 500;
675
676 int scroll_border = 0;
677 int scroll_speed = 0;
678
679 int scrollbar_margin_top = -1;
680 int scrollbar_margin_right = -1;
681 int scrollbar_margin_bottom = -1;
682 int scrollbar_margin_left = -1;
683 int scrollbar_h_separation = 0;
684 int scrollbar_v_separation = 0;
685 } theme_cache;
686
687 struct Cache {
688 enum ClickType {
689 CLICK_NONE,
690 CLICK_TITLE,
691 CLICK_BUTTON,
692 };
693
694 ClickType click_type = Cache::CLICK_NONE;
695 int click_index = -1;
696 int click_id = -1;
697 TreeItem *click_item = nullptr;
698 int click_column = 0;
699 int hover_header_column = -1;
700 bool hover_header_row = false;
701 Point2 click_pos;
702
703 TreeItem *hover_item = nullptr;
704 int hover_column = -1;
705 int hover_button_index_in_column = -1;
706
707 bool rtl = false;
708 } cache;
709
710 int _get_title_button_height() const;
711 Size2 _get_cell_icon_size(const TreeItem::Cell &p_cell) const;
712
713 void _scroll_moved(float p_value);
714 HScrollBar *h_scroll = nullptr;
715 VScrollBar *v_scroll = nullptr;
716
717 bool h_scroll_enabled = true;
718 bool v_scroll_enabled = true;
719
720 Size2 get_internal_min_size() const;
721 void update_scrollbars();
722
723 Rect2 search_item_rect(TreeItem *p_from, TreeItem *p_item);
724 uint64_t last_keypress = 0;
725 String incr_search;
726 bool cursor_can_exit_tree = true;
727 void _do_incr_search(const String &p_add);
728
729 TreeItem *_search_item_text(TreeItem *p_at, const String &p_find, int *r_col, bool p_selectable, bool p_backwards = false);
730
731 TreeItem *_find_item_at_pos(TreeItem *p_item, const Point2 &p_pos, int &r_column, int &r_height, int &r_section) const;
732
733 void _find_button_at_pos(const Point2 &p_pos, TreeItem *&r_item, int &r_column, int &r_index, int &r_section) const;
734
735 struct FindColumnButtonResult {
736 int column_index = -1;
737 int button_index = -1;
738 int column_width = -1;
739 int column_offset = -1;
740 int pos_x = -1;
741 };
742
743 FindColumnButtonResult _find_column_and_button_at_pos(int p_x, const TreeItem *p_item, int p_x_ofs, int p_x_limit) const;
744
745 float drag_speed = 0.0;
746 float drag_from = 0.0;
747 float drag_accum = 0.0;
748 bool drag_touching = false;
749 bool drag_touching_deaccel = false;
750 bool click_handled = false;
751 bool allow_rmb_select = false;
752 bool scrolling = false;
753
754 ScrollHintMode scroll_hint_mode = SCROLL_HINT_MODE_DISABLED;
755 bool tile_scroll_hint = false;
756
757 bool allow_reselect = false;
758 bool allow_search = true;
759
760 bool force_edit_checkbox_only_on_checkbox = false;
761
762 bool hide_folding = false;
763
764 bool enable_recursive_folding = true;
765
766 bool enable_drag_unfolding = true;
767 Timer *dropping_unfold_timer = nullptr;
768 void _on_dropping_unfold_timer_timeout();
769 void _reset_drop_mode_over();
770
771 bool enable_auto_tooltip = true;
772
773 bool hovered_update_queued = false;
774 void _determine_hovered_item();
775 void _queue_update_hovered_item();
776
777 int _count_selected_items(TreeItem *p_from) const;
778 bool _is_branch_selected(TreeItem *p_from) const;
779 bool _is_sibling_branch_selected(TreeItem *p_from) const;
780 void _go_left();
781 void _go_right();
782 void _go_down();
783 void _go_up();
784 void _shift_select_range(TreeItem *new_item);
785
786 bool _scroll(bool p_horizontal, float p_pages);
787
788 Rect2 _get_scrollbar_layout_rect() const;
789 Rect2 _get_content_rect() const; // Considering the background stylebox and scrollbars.
790 Rect2 _get_item_focus_rect(const TreeItem *p_item) const;
791
792 void _check_item_accessibility(TreeItem *p_item, PackedStringArray &r_warnings, int &r_row) const;
793
794 void _accessibility_clean_info(TreeItem *p_item);
795 void _accessibility_update_item(Point2 &r_ofs, TreeItem *p_item, int &r_row, int p_level);
796
797 protected:
798 virtual void _update_theme_item_cache() override;
799
800 void _notification(int p_what);
801 static void _bind_methods();
802
803 void _accessibility_action_scroll_down(const Variant &p_data);
804 void _accessibility_action_scroll_left(const Variant &p_data);
805 void _accessibility_action_scroll_right(const Variant &p_data);
806 void _accessibility_action_scroll_up(const Variant &p_data);
807 void _accessibility_action_scroll_set(const Variant &p_data);
808 void _accessibility_action_scroll_into_view(const Variant &p_data, TreeItem *p_item, int p_col);
809 void _accessibility_action_focus(const Variant &p_data, TreeItem *p_item, int p_col);
810 void _accessibility_action_blur(const Variant &p_data, TreeItem *p_item, int p_col);
811 void _accessibility_action_collapse(const Variant &p_data, TreeItem *p_item);
812 void _accessibility_action_expand(const Variant &p_data, TreeItem *p_item);
813 void _accessibility_action_set_text_value(const Variant &p_data, TreeItem *p_item, int p_col);
814 void _accessibility_action_set_num_value(const Variant &p_data, TreeItem *p_item, int p_col);
815 void _accessibility_action_set_bool_value(const Variant &p_data, TreeItem *p_item, int p_col);
816 void _accessibility_action_set_inc(const Variant &p_data, TreeItem *p_item, int p_col);
817 void _accessibility_action_set_dec(const Variant &p_data, TreeItem *p_item, int p_col);
818 void _accessibility_action_edit_custom(const Variant &p_data, TreeItem *p_item, int p_col);
819 void _accessibility_action_button_press(const Variant &p_data, TreeItem *p_item, int p_col, int p_btn);
820
821 public:
822 PackedStringArray get_accessibility_configuration_warnings() const override;
823 virtual RID get_focused_accessibility_element() const override;
824
825 virtual void set_self_modulate(const Color &p_self_modulate) override;
826
827 virtual void gui_input(const Ref<InputEvent> &p_event) override;
828
829 virtual String get_tooltip(const Point2 &p_pos) const override;
830
831 virtual bool can_drop_data(const Point2 &p_point, const Variant &p_data) const override;
832 virtual Variant get_drag_data(const Point2 &p_point) override;
833 TreeItem *get_item_at_position(const Point2 &p_pos) const;
834 int get_column_at_position(const Point2 &p_pos) const;
835 int get_drop_section_at_position(const Point2 &p_pos) const;
836 int get_button_id_at_position(const Point2 &p_pos) const;
837
838 void clear();
839
840 TreeItem *create_item(TreeItem *p_parent = nullptr, int p_index = -1);
841 TreeItem *get_root() const;
842 TreeItem *get_last_item() const;
843
844 void set_column_custom_minimum_width(int p_column, int p_min_width);
845 void set_column_expand(int p_column, bool p_expand);
846 void set_column_expand_ratio(int p_column, int p_ratio);
847 void set_column_clip_content(int p_column, bool p_fit);
848 int get_column_minimum_width(int p_column) const;
849 int get_column_width(int p_column) const;
850 int get_column_expand_ratio(int p_column) const;
851
852 bool is_column_expanding(int p_column) const;
853 bool is_column_clipping_content(int p_column) const;
854
855 void set_hide_root(bool p_enabled);
856 bool is_root_hidden() const;
857 TreeItem *get_next_selected(TreeItem *p_item);
858 TreeItem *get_selected() const;
859 void set_selected(TreeItem *p_item, int p_column = 0);
860 int get_selected_column() const;
861 int get_pressed_button() const;
862 void set_select_mode(SelectMode p_mode);
863 SelectMode get_select_mode() const;
864 void deselect_all();
865 bool is_anything_selected();
866
867 void set_columns(int p_columns);
868 int get_columns() const;
869
870 void set_column_title(int p_column, const String &p_title);
871 String get_column_title(int p_column) const;
872
873 void set_column_title_tooltip_text(int p_column, const String &p_tooltip);
874 String get_column_title_tooltip_text(int p_column) const;
875
876 void set_column_title_alignment(int p_column, HorizontalAlignment p_alignment);
877 HorizontalAlignment get_column_title_alignment(int p_column) const;
878
879 void set_column_title_direction(int p_column, Control::TextDirection p_text_direction);
880 Control::TextDirection get_column_title_direction(int p_column) const;
881
882 void set_column_title_language(int p_column, const String &p_language);
883 String get_column_title_language(int p_column) const;
884
885 void set_column_titles_visible(bool p_show);
886 bool are_column_titles_visible() const;
887
888 TreeItem *get_edited() const;
889 int get_edited_column() const;
890
891 void ensure_cursor_is_visible();
892
893 Rect2 get_custom_popup_rect() const;
894
895 int get_item_offset(TreeItem *p_item) const;
896 Rect2 get_item_rect(TreeItem *p_item, int p_column = -1, int p_button = -1) const;
897 bool edit_selected(bool p_force_edit = false);
898 bool is_editing();
899 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);
900
901 // First item that starts with the text, from the current focused item down and wraps around.
902 TreeItem *search_item_text(const String &p_find, int *r_col = nullptr, bool p_selectable = false);
903 // First item that matches the whole text, from the first item down.
904 TreeItem *get_item_with_text(const String &p_find) const;
905 TreeItem *get_item_with_metadata(const Variant &p_find, int p_column = -1) const;
906
907 Point2 get_scroll() const;
908 void scroll_to_item(TreeItem *p_item, bool p_center_on_item = false);
909 void set_h_scroll_enabled(bool p_enable);
910 bool is_h_scroll_enabled() const;
911 void set_v_scroll_enabled(bool p_enable);
912 bool is_v_scroll_enabled() const;
913
914 void set_scroll_hint_mode(ScrollHintMode p_mode);
915 ScrollHintMode get_scroll_hint_mode() const;
916
917 void set_tile_scroll_hint(bool p_enable);
918 bool is_scroll_hint_tiled();
919
920 void set_cursor_can_exit_tree(bool p_enable);
921
922 VScrollBar *get_vscroll_bar() { return v_scroll; }
923
924 void set_hide_folding(bool p_hide);
925 bool is_folding_hidden() const;
926
927 void set_enable_recursive_folding(bool p_enable);
928 bool is_recursive_folding_enabled() const;
929
930 void set_enable_drag_unfolding(bool p_enable);
931 bool is_drag_unfolding_enabled() const;
932
933 void set_drop_mode_flags(int p_flags);
934 int get_drop_mode_flags() const;
935
936 void set_edit_checkbox_cell_only_when_checkbox_is_pressed(bool p_enable);
937 bool get_edit_checkbox_cell_only_when_checkbox_is_pressed() const;
938
939 void set_allow_rmb_select(bool p_allow);
940 bool get_allow_rmb_select() const;
941
942 void set_allow_reselect(bool p_allow);
943 bool get_allow_reselect() const;
944
945 void set_allow_search(bool p_allow);
946 bool get_allow_search() const;
947
948 void set_auto_tooltip(bool p_enable);
949 bool is_auto_tooltip_enabled() const;
950
951 Size2 get_minimum_size() const override;
952
953 Tree();
954 ~Tree();
955 };
956
957 VARIANT_ENUM_CAST(Tree::SelectMode);
958 VARIANT_ENUM_CAST(Tree::DropModeFlags);
959 VARIANT_ENUM_CAST(Tree::ScrollHintMode);