| 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 | #ifndef TAB_CONTAINER_H |
| 32 | #define TAB_CONTAINER_H |
| 33 | |
| 34 | #include "scene/gui/container.h" |
| 35 | #include "scene/gui/popup.h" |
| 36 | #include "scene/gui/tab_bar.h" |
| 37 | |
| 38 | class TabContainer : public Container { |
| 39 | GDCLASS(TabContainer, Container); |
| 40 | |
| 41 | TabBar *tab_bar = nullptr; |
| 42 | bool tabs_visible = true; |
| 43 | bool all_tabs_in_front = false; |
| 44 | bool = false; |
| 45 | mutable ObjectID ; |
| 46 | bool drag_to_rearrange_enabled = false; |
| 47 | bool use_hidden_tabs_for_min_size = false; |
| 48 | bool theme_changing = false; |
| 49 | Vector<Control *> children_removing; |
| 50 | |
| 51 | struct ThemeCache { |
| 52 | int side_margin = 0; |
| 53 | |
| 54 | Ref<StyleBox> panel_style; |
| 55 | Ref<StyleBox> tabbar_style; |
| 56 | |
| 57 | Ref<Texture2D> ; |
| 58 | Ref<Texture2D> ; |
| 59 | |
| 60 | // TabBar overrides. |
| 61 | int icon_separation = 0; |
| 62 | int icon_max_width = 0; |
| 63 | int outline_size = 0; |
| 64 | |
| 65 | Ref<StyleBox> tab_unselected_style; |
| 66 | Ref<StyleBox> tab_hovered_style; |
| 67 | Ref<StyleBox> tab_selected_style; |
| 68 | Ref<StyleBox> tab_disabled_style; |
| 69 | |
| 70 | Ref<Texture2D> increment_icon; |
| 71 | Ref<Texture2D> increment_hl_icon; |
| 72 | Ref<Texture2D> decrement_icon; |
| 73 | Ref<Texture2D> decrement_hl_icon; |
| 74 | Ref<Texture2D> drop_mark_icon; |
| 75 | Color drop_mark_color; |
| 76 | |
| 77 | Color font_selected_color; |
| 78 | Color font_hovered_color; |
| 79 | Color font_unselected_color; |
| 80 | Color font_disabled_color; |
| 81 | Color font_outline_color; |
| 82 | |
| 83 | Ref<Font> tab_font; |
| 84 | int tab_font_size; |
| 85 | } theme_cache; |
| 86 | |
| 87 | int _get_top_margin() const; |
| 88 | Vector<Control *> _get_tab_controls() const; |
| 89 | void _on_theme_changed(); |
| 90 | void _repaint(); |
| 91 | void _refresh_tab_names(); |
| 92 | void _update_margins(); |
| 93 | void _on_mouse_exited(); |
| 94 | void _on_tab_changed(int p_tab); |
| 95 | void _on_tab_clicked(int p_tab); |
| 96 | void _on_tab_hovered(int p_tab); |
| 97 | void _on_tab_selected(int p_tab); |
| 98 | void _on_tab_button_pressed(int p_tab); |
| 99 | |
| 100 | Variant _get_drag_data_fw(const Point2 &p_point, Control *p_from_control); |
| 101 | bool _can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from_control) const; |
| 102 | void _drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from_control); |
| 103 | |
| 104 | protected: |
| 105 | virtual void gui_input(const Ref<InputEvent> &p_event) override; |
| 106 | |
| 107 | void _notification(int p_what); |
| 108 | virtual void add_child_notify(Node *p_child) override; |
| 109 | virtual void move_child_notify(Node *p_child) override; |
| 110 | virtual void remove_child_notify(Node *p_child) override; |
| 111 | static void _bind_methods(); |
| 112 | |
| 113 | public: |
| 114 | int get_tab_idx_at_point(const Point2 &p_point) const; |
| 115 | int get_tab_idx_from_control(Control *p_child) const; |
| 116 | |
| 117 | void set_tab_alignment(TabBar::AlignmentMode p_alignment); |
| 118 | TabBar::AlignmentMode get_tab_alignment() const; |
| 119 | |
| 120 | void set_clip_tabs(bool p_clip_tabs); |
| 121 | bool get_clip_tabs() const; |
| 122 | |
| 123 | void set_tabs_visible(bool p_visible); |
| 124 | bool are_tabs_visible() const; |
| 125 | |
| 126 | void set_all_tabs_in_front(bool p_is_front); |
| 127 | bool is_all_tabs_in_front() const; |
| 128 | |
| 129 | void set_tab_title(int p_tab, const String &p_title); |
| 130 | String get_tab_title(int p_tab) const; |
| 131 | |
| 132 | void set_tab_icon(int p_tab, const Ref<Texture2D> &p_icon); |
| 133 | Ref<Texture2D> get_tab_icon(int p_tab) const; |
| 134 | |
| 135 | void set_tab_disabled(int p_tab, bool p_disabled); |
| 136 | bool is_tab_disabled(int p_tab) const; |
| 137 | |
| 138 | void set_tab_hidden(int p_tab, bool p_hidden); |
| 139 | bool is_tab_hidden(int p_tab) const; |
| 140 | |
| 141 | void set_tab_metadata(int p_tab, const Variant &p_metadata); |
| 142 | Variant get_tab_metadata(int p_tab) const; |
| 143 | |
| 144 | void set_tab_button_icon(int p_tab, const Ref<Texture2D> &p_icon); |
| 145 | Ref<Texture2D> get_tab_button_icon(int p_tab) const; |
| 146 | |
| 147 | int get_tab_count() const; |
| 148 | void set_current_tab(int p_current); |
| 149 | int get_current_tab() const; |
| 150 | int get_previous_tab() const; |
| 151 | |
| 152 | Control *get_tab_control(int p_idx) const; |
| 153 | Control *get_current_tab_control() const; |
| 154 | |
| 155 | virtual Size2 get_minimum_size() const override; |
| 156 | |
| 157 | void (Node *); |
| 158 | Popup *() const; |
| 159 | |
| 160 | void set_drag_to_rearrange_enabled(bool p_enabled); |
| 161 | bool get_drag_to_rearrange_enabled() const; |
| 162 | void set_tabs_rearrange_group(int p_group_id); |
| 163 | int get_tabs_rearrange_group() const; |
| 164 | void set_use_hidden_tabs_for_min_size(bool p_use_hidden_tabs); |
| 165 | bool get_use_hidden_tabs_for_min_size() const; |
| 166 | |
| 167 | virtual Vector<int> get_allowed_size_flags_horizontal() const override; |
| 168 | virtual Vector<int> get_allowed_size_flags_vertical() const override; |
| 169 | |
| 170 | TabContainer(); |
| 171 | }; |
| 172 | |
| 173 | #endif // TAB_CONTAINER_H |
| 174 | |