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 #ifdef _IRR_COMPILE_WITH_GUI_
\r
11 #include "IGUITabControl.h"
\r
12 #include "irrArray.h"
\r
13 #include "IGUISkin.h"
\r
19 class CGUITabControl;
\r
22 // A tab, onto which other gui elements could be added.
\r
23 class CGUITab : public IGUITab
\r
28 CGUITab(IGUIEnvironment* environment,
\r
29 IGUIElement* parent, const core::rect<s32>& rectangle,
\r
32 //! draws the element and its children
\r
33 void draw() override;
\r
35 //! sets if the tab should draw its background
\r
36 void setDrawBackground(bool draw=true) override;
\r
38 //! sets the color of the background, if it should be drawn.
\r
39 void setBackgroundColor(video::SColor c) override;
\r
41 //! sets the color of the text
\r
42 void setTextColor(video::SColor c) override;
\r
44 //! returns true if the tab is drawing its background, false if not
\r
45 bool isDrawingBackground() const override;
\r
47 //! returns the color of the background
\r
48 video::SColor getBackgroundColor() const override;
\r
50 video::SColor getTextColor() const override;
\r
54 video::SColor BackColor;
\r
55 bool OverrideTextColorEnabled;
\r
56 video::SColor TextColor;
\r
57 bool DrawBackground;
\r
61 //! A standard tab control
\r
62 class CGUITabControl : public IGUITabControl
\r
67 CGUITabControl(IGUIEnvironment* environment,
\r
68 IGUIElement* parent, const core::rect<s32>& rectangle,
\r
69 bool fillbackground=true, bool border=true, s32 id=-1);
\r
72 virtual ~CGUITabControl();
\r
75 IGUITab* addTab(const wchar_t* caption, s32 id=-1) override;
\r
77 //! Adds an existing tab
\r
78 s32 addTab(IGUITab* tab) override;
\r
80 //! Insert the tab at the given index
\r
81 IGUITab* insertTab(s32 idx, const wchar_t* caption, s32 id=-1) override;
\r
83 //! Insert an existing tab
\r
84 /** Note that it will also add the tab as a child of this TabControl.
\r
85 \return Index of added tab (should be same as the one passed) or -1 for failure*/
\r
86 s32 insertTab(s32 idx, IGUITab* tab, bool serializationMode) override;
\r
88 //! Removes a tab from the tabcontrol
\r
89 void removeTab(s32 idx) override;
\r
91 //! Clears the tabcontrol removing all tabs
\r
92 void clear() override;
\r
94 //! Returns amount of tabs in the tabcontrol
\r
95 s32 getTabCount() const override;
\r
97 //! Returns a tab based on zero based index
\r
98 IGUITab* getTab(s32 idx) const override;
\r
100 //! Brings a tab to front.
\r
101 bool setActiveTab(s32 idx) override;
\r
103 //! Brings a tab to front.
\r
104 bool setActiveTab(IGUITab *tab) override;
\r
106 //! For given given tab find it's zero-based index (or -1 for not found)
\r
107 s32 getTabIndex(const IGUIElement *tab) const override;
\r
109 //! Returns which tab is currently active
\r
110 s32 getActiveTab() const override;
\r
112 //! get the the id of the tab at the given absolute coordinates
\r
113 s32 getTabAt(s32 xpos, s32 ypos) const override;
\r
115 //! called if an event happened.
\r
116 bool OnEvent(const SEvent& event) override;
\r
118 //! draws the element and its children
\r
119 void draw() override;
\r
121 //! Removes a child.
\r
122 void removeChild(IGUIElement* child) override;
\r
124 //! Set the height of the tabs
\r
125 void setTabHeight( s32 height ) override;
\r
127 //! Get the height of the tabs
\r
128 s32 getTabHeight() const override;
\r
130 //! set the maximal width of a tab. Per default width is 0 which means "no width restriction".
\r
131 void setTabMaxWidth(s32 width ) override;
\r
133 //! get the maximal width of a tab
\r
134 s32 getTabMaxWidth() const override;
\r
136 //! Set the alignment of the tabs
\r
137 //! note: EGUIA_CENTER is not an option
\r
138 void setTabVerticalAlignment( gui::EGUI_ALIGNMENT alignment ) override;
\r
140 //! Get the alignment of the tabs
\r
141 gui::EGUI_ALIGNMENT getTabVerticalAlignment() const override;
\r
143 //! Set the extra width added to tabs on each side of the text
\r
144 void setTabExtraWidth( s32 extraWidth ) override;
\r
146 //! Get the extra width added to tabs on each side of the text
\r
147 s32 getTabExtraWidth() const override;
\r
149 //! Update the position of the element, decides scroll button status
\r
150 void updateAbsolutePosition() override;
\r
155 void scrollRight();
\r
156 //! Indicates whether the tabs overflow in X direction
\r
157 bool needScrollControl( s32 startIndex=0, bool withScrollControl=false, s32 *pos_rightmost=nullptr );
\r
158 //! Left index calculation based on the selected tab
\r
159 s32 calculateScrollIndexFromActive();
\r
160 s32 calcTabWidth(IGUIFont* font, const wchar_t* text) const;
\r
161 core::rect<s32> calcTabPos();
\r
162 void setVisibleTab(s32 idx);
\r
163 void removeTabButNotChild(s32 idx);
\r
165 void recalculateScrollButtonPlacement();
\r
166 void recalculateScrollBar();
\r
167 void refreshSprites();
\r
169 core::array<IGUITab*> Tabs;
\r
170 s32 ActiveTabIndex;
\r
172 bool FillBackground;
\r
173 bool ScrollControl;
\r
175 gui::EGUI_ALIGNMENT VerticalAlignment;
\r
176 IGUIButton* UpButton;
\r
177 IGUIButton* DownButton;
\r
179 s32 CurrentScrollTabIndex;
\r
184 } // end namespace gui
\r
185 } // end namespace irr
\r
187 #endif // _IRR_COMPILE_WITH_GUI_
\r