1 /*************************************************************************/
2 /*  tab_container.h                                                      */
3 /*************************************************************************/
4 /*                       This file is part of:                           */
5 /*                           GODOT ENGINE                                */
6 /*                      https://godotengine.org                          */
7 /*************************************************************************/
8 /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur.                 */
9 /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md).   */
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 class TabContainer : public Container {
37 
38 	GDCLASS(TabContainer, Container);
39 
40 public:
41 	enum TabAlign {
42 
43 		ALIGN_LEFT,
44 		ALIGN_CENTER,
45 		ALIGN_RIGHT
46 	};
47 
48 private:
49 	int first_tab_cache;
50 	int tabs_ofs_cache;
51 	int last_tab_cache;
52 	int current;
53 	int previous;
54 	bool tabs_visible;
55 	bool buttons_visible_cache;
56 	bool menu_hovered;
57 	int highlight_arrow;
58 	TabAlign align;
59 	Control *_get_tab(int p_idx) const;
60 	int _get_top_margin() const;
61 	mutable ObjectID popup_obj_id;
62 	bool drag_to_rearrange_enabled;
63 	bool use_hidden_tabs_for_min_size;
64 	int tabs_rearrange_group;
65 
66 	Vector<Control *> _get_tabs() const;
67 	int _get_tab_width(int p_index) const;
68 	void _on_theme_changed();
69 	void _repaint();
70 	void _on_mouse_exited();
71 	void _update_current_tab();
72 
73 protected:
74 	void _child_renamed_callback();
75 	void _gui_input(const Ref<InputEvent> &p_event);
76 	void _notification(int p_what);
77 	virtual void add_child_notify(Node *p_child);
78 	virtual void remove_child_notify(Node *p_child);
79 
80 	Variant get_drag_data(const Point2 &p_point);
81 	bool can_drop_data(const Point2 &p_point, const Variant &p_data) const;
82 	void drop_data(const Point2 &p_point, const Variant &p_data);
83 	int get_tab_idx_at_point(const Point2 &p_point) const;
84 
85 	static void _bind_methods();
86 
87 public:
88 	void set_tab_align(TabAlign p_align);
89 	TabAlign get_tab_align() const;
90 
91 	void set_tabs_visible(bool p_visible);
92 	bool are_tabs_visible() const;
93 
94 	void set_tab_title(int p_tab, const String &p_title);
95 	String get_tab_title(int p_tab) const;
96 
97 	void set_tab_icon(int p_tab, const Ref<Texture> &p_icon);
98 	Ref<Texture> get_tab_icon(int p_tab) const;
99 
100 	void set_tab_disabled(int p_tab, bool p_disabled);
101 	bool get_tab_disabled(int p_tab) const;
102 
103 	void set_tab_hidden(int p_tab, bool p_hidden);
104 	bool get_tab_hidden(int p_tab) const;
105 
106 	int get_tab_count() const;
107 	void set_current_tab(int p_current);
108 	int get_current_tab() const;
109 	int get_previous_tab() const;
110 
111 	Control *get_tab_control(int p_idx) const;
112 	Control *get_current_tab_control() const;
113 
114 	virtual Size2 get_minimum_size() const;
115 
116 	virtual void get_translatable_strings(List<String> *p_strings) const;
117 
118 	void set_popup(Node *p_popup);
119 	Popup *get_popup() const;
120 
121 	void set_drag_to_rearrange_enabled(bool p_enabled);
122 	bool get_drag_to_rearrange_enabled() const;
123 	void set_tabs_rearrange_group(int p_group_id);
124 	int get_tabs_rearrange_group() const;
125 	void set_use_hidden_tabs_for_min_size(bool p_use_hidden_tabs);
126 	bool get_use_hidden_tabs_for_min_size() const;
127 
128 	TabContainer();
129 };
130 
131 VARIANT_ENUM_CAST(TabContainer::TabAlign);
132 
133 #endif // TAB_CONTAINER_H
134