tabs.h
1 /*************************************************************************/
2 /* tabs.h */
3 /*************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* http://www.godotengine.org */
7 /*************************************************************************/
8 /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
9 /* */
10 /* Permission is hereby granted, free of charge, to any person obtaining */
11 /* a copy of this software and associated documentation files (the */
12 /* "Software"), to deal in the Software without restriction, including */
13 /* without limitation the rights to use, copy, modify, merge, publish, */
14 /* distribute, sublicense, and/or sell copies of the Software, and to */
15 /* permit persons to whom the Software is furnished to do so, subject to */
16 /* the following conditions: */
17 /* */
18 /* The above copyright notice and this permission notice shall be */
19 /* included in all copies or substantial portions of the Software. */
20 /* */
21 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
22 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
23 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
24 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
25 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
26 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
27 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
28 /*************************************************************************/
29 #ifndef TABS_H
30 #define TABS_H
31 
32 #include "scene/gui/control.h"
33 
34 class Tabs : public Control {
35 
36  OBJ_TYPE( Tabs, Control );
37 public:
38 
39  enum TabAlign {
40 
41  ALIGN_LEFT,
42  ALIGN_CENTER,
43  ALIGN_RIGHT
44  };
45 
46  enum CloseButtonDisplayPolicy {
47 
48  CLOSE_BUTTON_SHOW_NEVER,
49  CLOSE_BUTTON_SHOW_ACTIVE_ONLY,
50  CLOSE_BUTTON_SHOW_ALWAYS,
51  };
52 private:
53 
54 
55  struct Tab {
56 
57  String text;
58  Ref<Texture> icon;
59  int ofs_cache;
60  int size_cache;
61  int x_cache;
62  int x_size_cache;
63 
64  Ref<Texture> right_button;
65  Rect2 rb_rect;
66  Rect2 cb_rect;
67 
68  };
69 
70 
71  int offset;
72  int max_drawn_tab;
73  int hilite_arrow;
74  bool buttons_visible;
75  bool missing_right;
76  Vector<Tab> tabs;
77  int current;
78  Control *_get_tab(int idx) const;
79  int _get_top_margin() const;
80  TabAlign tab_align;
81  int rb_hover;
82  bool rb_pressing;
83 
84  int cb_hover;
85  bool cb_pressing;
86  CloseButtonDisplayPolicy cb_displaypolicy;
87 
88  int hover; // hovered tab
89 
90  int get_tab_width(int p_idx) const;
91  void _ensure_no_over_offset();
92 
93 protected:
94 
95  void _input_event(const InputEvent& p_event);
96  void _notification(int p_what);
97  static void _bind_methods();
98 
99 public:
100 
101  void add_tab(const String& p_str="",const Ref<Texture>& p_icon=Ref<Texture>());
102 
103  void set_tab_title(int p_tab,const String& p_title);
104  String get_tab_title(int p_tab) const;
105 
106  void set_tab_icon(int p_tab,const Ref<Texture>& p_icon);
107  Ref<Texture> get_tab_icon(int p_tab) const;
108 
109  void set_tab_right_button(int p_tab,const Ref<Texture>& p_right_button);
110  Ref<Texture> get_tab_right_button(int p_tab) const;
111 
112  void set_tab_align(TabAlign p_align);
113  TabAlign get_tab_align() const;
114 
115  void set_tab_close_display_policy(CloseButtonDisplayPolicy p_policy);
116 
117  int get_tab_count() const;
118  void set_current_tab(int p_current);
119  int get_current_tab() const;
120 
121  void remove_tab(int p_idx);
122 
123  void clear_tabs();
124 
125  void ensure_tab_visible(int p_idx);
126 
127  Size2 get_minimum_size() const;
128 
129  Tabs();
130 };
131 
132 VARIANT_ENUM_CAST(Tabs::TabAlign);
133 
134 #endif // TABS_H
Definition: math_2d.h:204
Definition: input_event.h:263
Definition: math_2d.h:65
Definition: control.h:47
Definition: ustring.h:64
Definition: tabs.h:34