1 // Copyright (C) 2002-2012 Nikolaus Gebhardt
\r
2 // This file is part of the "Irrlicht Engine".
\r
3 // For conditions of distribution and use, see copyright notice in irrlicht.h
\r
5 #ifndef __C_GUI_TAB_CONTROL_H_INCLUDED__
\r
6 #define __C_GUI_TAB_CONTROL_H_INCLUDED__
\r
8 #include "IrrCompileConfig.h"
\r
9 #include "IGUITabControl.h"
\r
10 #include "irrArray.h"
\r
11 #include "IGUISkin.h"
\r
17 class CGUITabControl;
\r
20 // A tab, onto which other gui elements could be added.
\r
21 class CGUITab : public IGUITab
\r
26 CGUITab(IGUIEnvironment* environment,
\r
27 IGUIElement* parent, const core::rect<s32>& rectangle,
\r
30 //! draws the element and its children
\r
31 void draw() override;
\r
33 //! sets if the tab should draw its background
\r
34 void setDrawBackground(bool draw=true) override;
\r
36 //! sets the color of the background, if it should be drawn.
\r
37 void setBackgroundColor(video::SColor c) override;
\r
39 //! sets the color of the text
\r
40 void setTextColor(video::SColor c) override;
\r
42 //! returns true if the tab is drawing its background, false if not
\r
43 bool isDrawingBackground() const override;
\r
45 //! returns the color of the background
\r
46 video::SColor getBackgroundColor() const override;
\r
48 video::SColor getTextColor() const override;
\r
52 video::SColor BackColor;
\r
53 bool OverrideTextColorEnabled;
\r
54 video::SColor TextColor;
\r
55 bool DrawBackground;
\r
59 //! A standard tab control
\r
60 class CGUITabControl : public IGUITabControl
\r
65 CGUITabControl(IGUIEnvironment* environment,
\r
66 IGUIElement* parent, const core::rect<s32>& rectangle,
\r
67 bool fillbackground=true, bool border=true, s32 id=-1);
\r
70 virtual ~CGUITabControl();
\r
73 IGUITab* addTab(const wchar_t* caption, s32 id=-1) override;
\r
75 //! Adds an existing tab
\r
76 s32 addTab(IGUITab* tab) override;
\r
78 //! Insert the tab at the given index
\r
79 IGUITab* insertTab(s32 idx, const wchar_t* caption, s32 id=-1) override;
\r
81 //! Insert an existing tab
\r
82 /** Note that it will also add the tab as a child of this TabControl.
\r
83 \return Index of added tab (should be same as the one passed) or -1 for failure*/
\r
84 s32 insertTab(s32 idx, IGUITab* tab, bool serializationMode) override;
\r
86 //! Removes a tab from the tabcontrol
\r
87 void removeTab(s32 idx) override;
\r
89 //! Clears the tabcontrol removing all tabs
\r
90 void clear() override;
\r
92 //! Returns amount of tabs in the tabcontrol
\r
93 s32 getTabCount() const override;
\r
95 //! Returns a tab based on zero based index
\r
96 IGUITab* getTab(s32 idx) const override;
\r
98 //! Brings a tab to front.
\r
99 bool setActiveTab(s32 idx) override;
\r
101 //! Brings a tab to front.
\r
102 bool setActiveTab(IGUITab *tab) override;
\r
104 //! For given given tab find it's zero-based index (or -1 for not found)
\r
105 s32 getTabIndex(const IGUIElement *tab) const override;
\r
107 //! Returns which tab is currently active
\r
108 s32 getActiveTab() const override;
\r
110 //! get the the id of the tab at the given absolute coordinates
\r
111 s32 getTabAt(s32 xpos, s32 ypos) const override;
\r
113 //! called if an event happened.
\r
114 bool OnEvent(const SEvent& event) override;
\r
116 //! draws the element and its children
\r
117 void draw() override;
\r
119 //! Removes a child.
\r
120 void removeChild(IGUIElement* child) override;
\r
122 //! Set the height of the tabs
\r
123 void setTabHeight( s32 height ) override;
\r
125 //! Get the height of the tabs
\r
126 s32 getTabHeight() const override;
\r
128 //! set the maximal width of a tab. Per default width is 0 which means "no width restriction".
\r
129 void setTabMaxWidth(s32 width ) override;
\r
131 //! get the maximal width of a tab
\r
132 s32 getTabMaxWidth() const override;
\r
134 //! Set the alignment of the tabs
\r
135 //! note: EGUIA_CENTER is not an option
\r
136 void setTabVerticalAlignment( gui::EGUI_ALIGNMENT alignment ) override;
\r
138 //! Get the alignment of the tabs
\r
139 gui::EGUI_ALIGNMENT getTabVerticalAlignment() const override;
\r
141 //! Set the extra width added to tabs on each side of the text
\r
142 void setTabExtraWidth( s32 extraWidth ) override;
\r
144 //! Get the extra width added to tabs on each side of the text
\r
145 s32 getTabExtraWidth() const override;
\r
147 //! Update the position of the element, decides scroll button status
\r
148 void updateAbsolutePosition() override;
\r
153 void scrollRight();
\r
154 //! Indicates whether the tabs overflow in X direction
\r
155 bool needScrollControl( s32 startIndex=0, bool withScrollControl=false, s32 *pos_rightmost=nullptr );
\r
156 //! Left index calculation based on the selected tab
\r
157 s32 calculateScrollIndexFromActive();
\r
158 s32 calcTabWidth(IGUIFont* font, const wchar_t* text) const;
\r
159 core::rect<s32> calcTabPos();
\r
160 void setVisibleTab(s32 idx);
\r
161 void removeTabButNotChild(s32 idx);
\r
163 void recalculateScrollButtonPlacement();
\r
164 void recalculateScrollBar();
\r
165 void refreshSprites();
\r
167 core::array<IGUITab*> Tabs;
\r
168 s32 ActiveTabIndex;
\r
170 bool FillBackground;
\r
171 bool ScrollControl;
\r
173 gui::EGUI_ALIGNMENT VerticalAlignment;
\r
174 IGUIButton* UpButton;
\r
175 IGUIButton* DownButton;
\r
177 s32 CurrentScrollTabIndex;
\r
182 } // end namespace gui
\r
183 } // end namespace irr
\r