Debian Codegraph @

scene/gui/tab_container.h

raw symbols SCIP
1 /**************************************************************************/
2 /* tab_container.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/container.h"
34 #include "scene/gui/popup.h"
35 #include "scene/gui/tab_bar.h"
36 #include "scene/property_list_helper.h"
37
38 class TabContainer : public Container {
39 GDCLASS(TabContainer, Container);
40
41 public:
42 enum TabPosition {
43 POSITION_TOP,
44 POSITION_BOTTOM,
45 POSITION_MAX,
46 };
47
48 private:
49 TabBar *tab_bar = nullptr;
50 bool tabs_visible = true;
51 bool all_tabs_in_front = false;
52 TabPosition tabs_position = POSITION_TOP;
53 bool menu_hovered = false;
54 mutable ObjectID popup_obj_id;
55 bool use_hidden_tabs_for_min_size = false;
56 bool theme_changing = false;
57 Vector<Control *> children_removing;
58 bool drag_to_rearrange_enabled = false;
59 // Set the default setup current tab to be an invalid index.
60 int setup_current_tab = -2;
61 bool updating_visibility = false;
62
63 struct ThemeCache {
64 int side_margin = 0;
65
66 Ref<StyleBox> panel_style;
67 Ref<StyleBox> tabbar_style;
68
69 Ref<Texture2D> menu_icon;
70 Ref<Texture2D> menu_hl_icon;
71
72 // TabBar overrides.
73 int icon_separation = 0;
74 int tab_separation = 0;
75 int icon_max_width = 0;
76 int outline_size = 0;
77
78 Ref<StyleBox> tab_unselected_style;
79 Ref<StyleBox> tab_hovered_style;
80 Ref<StyleBox> tab_selected_style;
81 Ref<StyleBox> tab_disabled_style;
82 Ref<StyleBox> tab_focus_style;
83
84 Ref<Texture2D> increment_icon;
85 Ref<Texture2D> increment_hl_icon;
86 Ref<Texture2D> decrement_icon;
87 Ref<Texture2D> decrement_hl_icon;
88 Ref<Texture2D> drop_mark_icon;
89 Color drop_mark_color;
90
91 Color font_selected_color;
92 Color font_hovered_color;
93 Color font_unselected_color;
94 Color font_disabled_color;
95 Color font_outline_color;
96
97 Color icon_selected_color;
98 Color icon_hovered_color;
99 Color icon_unselected_color;
100 Color icon_disabled_color;
101
102 Ref<Font> tab_font;
103 int tab_font_size;
104 } theme_cache;
105 struct CachedTab {
106 bool has_title = false;
107 String title;
108 Ref<Texture2D> icon;
109 bool disabled = false;
110 bool hidden = false;
111 };
112
113 static inline PropertyListHelper base_property_helper;
114 PropertyListHelper property_helper;
115
116 mutable Vector<CachedTab> pending_tabs;
117 CachedTab &get_pending_tab(int p_idx) const;
118
119 HashMap<Node *, RID> tab_panels;
120
121 Rect2 _get_tab_rect() const;
122 int _get_tab_height() const;
123 Vector<Control *> _get_tab_controls() const;
124 void _on_theme_changed();
125 void _repaint();
126 void _refresh_tab_indices();
127 void _refresh_tab_names();
128 void _update_margins();
129 void _on_mouse_exited();
130 void _on_tab_changed(int p_tab);
131 void _on_tab_clicked(int p_tab);
132 void _on_tab_hovered(int p_tab);
133 void _on_tab_selected(int p_tab);
134 void _on_tab_button_pressed(int p_tab);
135 void _on_active_tab_rearranged(int p_tab);
136 void _on_tab_visibility_changed(Control *p_child);
137
138 Variant _get_drag_data_fw(const Point2 &p_point, Control *p_from_control);
139 bool _can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from_control) const;
140 void _drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from_control);
141 void _drag_move_tab(int p_from_index, int p_to_index);
142 void _drag_move_tab_from(TabBar *p_from_tabbar, int p_from_index, int p_to_index);
143
144 protected:
145 virtual void gui_input(const Ref<InputEvent> &p_event) override;
146
147 bool _set(const StringName &p_name, const Variant &p_value) { return property_helper.property_set_value(p_name, p_value); }
148 bool _get(const StringName &p_name, Variant &r_ret) const { return property_helper.property_get_value(p_name, r_ret); }
149 void _get_property_list(List<PropertyInfo> *p_list) const;
150 bool _property_can_revert(const StringName &p_name) const { return property_helper.property_can_revert(p_name); }
151 bool _property_get_revert(const StringName &p_name, Variant &r_property) const;
152
153 void _notification(int p_what);
154 virtual void add_child_notify(Node *p_child) override;
155 virtual void move_child_notify(Node *p_child) override;
156 virtual void remove_child_notify(Node *p_child) override;
157 static void _bind_methods();
158
159 public:
160 virtual bool accessibility_override_tree_hierarchy() const override { return true; }
161
162 TabBar *get_tab_bar() const;
163
164 int get_tab_idx_at_point(const Point2 &p_point) const;
165 int get_tab_idx_from_control(Control *p_child) const;
166
167 void set_tab_alignment(TabBar::AlignmentMode p_alignment);
168 TabBar::AlignmentMode get_tab_alignment() const;
169
170 void set_tabs_position(TabPosition p_tab_position);
171 TabPosition get_tabs_position() const;
172
173 void set_tab_focus_mode(FocusMode p_focus_mode);
174 FocusMode get_tab_focus_mode() const;
175
176 void set_clip_tabs(bool p_clip_tabs);
177 bool get_clip_tabs() const;
178
179 void set_tabs_visible(bool p_visible);
180 bool are_tabs_visible() const;
181
182 void set_all_tabs_in_front(bool p_is_front);
183 bool is_all_tabs_in_front() const;
184
185 void set_tab_title(int p_tab, const String &p_title);
186 String get_tab_title(int p_tab) const;
187
188 void set_tab_tooltip(int p_tab, const String &p_tooltip);
189 String get_tab_tooltip(int p_tab) const;
190
191 void set_tab_icon(int p_tab, const Ref<Texture2D> &p_icon);
192 Ref<Texture2D> get_tab_icon(int p_tab) const;
193
194 void set_tab_icon_max_width(int p_tab, int p_width);
195 int get_tab_icon_max_width(int p_tab) const;
196
197 void set_tab_disabled(int p_tab, bool p_disabled);
198 bool is_tab_disabled(int p_tab) const;
199
200 void set_tab_hidden(int p_tab, bool p_hidden);
201 bool is_tab_hidden(int p_tab) const;
202
203 void set_tab_metadata(int p_tab, const Variant &p_metadata);
204 Variant get_tab_metadata(int p_tab) const;
205
206 void set_tab_button_icon(int p_tab, const Ref<Texture2D> &p_icon);
207 Ref<Texture2D> get_tab_button_icon(int p_tab) const;
208
209 int get_tab_count() const;
210 void set_current_tab(int p_current);
211 int get_current_tab() const;
212 int get_previous_tab() const;
213
214 bool select_previous_available();
215 bool select_next_available();
216
217 void set_deselect_enabled(bool p_enabled);
218 bool get_deselect_enabled() const;
219
220 Control *get_tab_control(int p_idx) const;
221 Control *get_current_tab_control() const;
222
223 virtual Size2 get_minimum_size() const override;
224
225 void set_popup(Node *p_popup);
226 Popup *get_popup() const;
227
228 void move_tab_from_tab_container(TabContainer *p_from, int p_from_index, int p_to_index = -1);
229
230 void set_switch_on_drag_hover(bool p_enabled);
231 bool get_switch_on_drag_hover() const;
232 void set_drag_to_rearrange_enabled(bool p_enabled);
233 bool get_drag_to_rearrange_enabled() const;
234 void set_tabs_rearrange_group(int p_group_id);
235 int get_tabs_rearrange_group() const;
236 void set_use_hidden_tabs_for_min_size(bool p_use_hidden_tabs);
237 bool get_use_hidden_tabs_for_min_size() const;
238
239 virtual Vector<int> get_allowed_size_flags_horizontal() const override;
240 virtual Vector<int> get_allowed_size_flags_vertical() const override;
241
242 TabContainer();
243 };
244
245 VARIANT_ENUM_CAST(TabContainer::TabPosition);