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