MyGUI 3.4.3
MyGUI_TabControl.h
Go to the documentation of this file.
1/*
2 * This source file is part of MyGUI. For the latest info, see http://mygui.info/
3 * Distributed under the MIT License
4 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
5 */
6
7#ifndef MYGUI_TAB_CONTROL_H_
8#define MYGUI_TAB_CONTROL_H_
9
10#include "MyGUI_Prerequest.h"
11#include "MyGUI_Widget.h"
12#include "MyGUI_Any.h"
13#include "MyGUI_EventPair.h"
15#include "MyGUI_IItem.h"
17
18namespace MyGUI
19{
20
22
26 class MYGUI_EXPORT TabControl : public Widget, public IItemContainer, public MemberObsolete<TabControl>
27 {
28 // для уведобления об удалении
29 //FIXME
30 friend class TabItem;
31
33
34 public:
36 {
37 TabItemInfo(int _width, const UString& _name, TabItem* _item, Any _data) :
38 width(_width),
39 name(_name),
40 item(_item),
41 data(_data)
42 {
43 }
44
45 int width;
49 };
50
51 using VectorTabItemInfo = std::vector<TabItemInfo>;
52
53 static constexpr int DEFAULT_WIDTH = -1;
54
56 void setPosition(const IntPoint& _point) override;
58 void setSize(const IntSize& _size) override;
60 void setCoord(const IntCoord& _coord) override;
61
63 using Widget::setSize;
64 using Widget::setCoord;
65
66 //------------------------------------------------------------------------------//
67 // манипуляции айтемами
68
70 size_t getItemCount() const;
71
73 TabItem* insertItemAt(size_t _index, const UString& _name, Any _data = Any::Null);
75 TabItem* insertItem(TabItem* _to, const UString& _name, Any _data = Any::Null);
76
78 TabItem* addItem(const UString& _name, Any _data = Any::Null);
79
81 void removeItemAt(size_t _index);
83 void removeItem(TabItem* _item);
84
86 void removeAllItems();
87
88
90 TabItem* getItemAt(size_t _index) const;
91
93 size_t getItemIndex(const TabItem* _item) const;
94
96 size_t findItemIndex(const TabItem* _item);
97
99 size_t findItemIndexWith(const UString& _name);
100
102 TabItem* findItemWith(const UString& _name);
103
104 void swapItems(size_t _index1, size_t _index2);
105
106 //------------------------------------------------------------------------------//
107 // манипуляции выделениями
108
110 size_t getIndexSelected() const;
111
113 TabItem* getItemSelected() const;
114
116 void setIndexSelected(size_t _index);
117
119 void setItemSelected(TabItem* _item);
120
121
122 //------------------------------------------------------------------------------//
123 // манипуляции данными
124
126 void setItemDataAt(size_t _index, Any _data);
128 void setItemData(TabItem* _item, Any _data);
129
131 void clearItemDataAt(size_t _index);
133 void clearItemData(TabItem* _item);
134
136 template<typename ValueType>
137 ValueType* getItemDataAt(size_t _index, bool _throw = true)
138 {
139 MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "TabControl::getItemDataAt");
140 return mItemsInfo[_index].data.castType<ValueType>(_throw);
141 }
142
143 template<typename ValueType>
144 ValueType* getItemData(TabItem* _item, bool _throw = true)
145 {
146 return getItemDataAt<ValueType>(getItemIndex(_item), _throw);
147 }
148
149
150 //------------------------------------------------------------------------------//
151 // манипуляции отображением
152
154 void setItemNameAt(size_t _index, const UString& _name);
155
157 void setItemName(TabItem* _item, const UString& _name);
158
160 const UString& getItemNameAt(size_t _index) const;
161
163 const UString& getItemName(const TabItem* _item) const;
164
165
166 //------------------------------------------------------------------------------//
167 // манипуляции выдимостью
168
170 void beginToItemAt(size_t _index);
171
173 void beginToItem(const TabItem* _item);
175 void beginToItemFirst();
177 void beginToItemLast();
179 void beginToItemSelected();
180
181
182 //------------------------------------------------------------------------------//
183 // остальные манипуляции
184
186 void setButtonWidthAt(size_t _index, int _width = DEFAULT_WIDTH);
188 void setButtonWidth(TabItem* _item, int _width = DEFAULT_WIDTH);
189
191 int getButtonWidthAt(size_t _index) const;
193 int getButtonWidth(TabItem* _item) const;
194
195 //------------------------------------------------------------------------------//
196
198 void setButtonDefaultWidth(int _width);
200 int getButtonDefaultWidth() const;
201
203 void setButtonAutoWidth(bool _auto);
205 bool getButtonAutoWidth() const;
206
208 void setSmoothShow(bool _value);
210 bool getSmoothShow() const;
211
212 /*events:*/
219
220 /*internal:*/
221 // IItemContainer impl
222 size_t _getItemCount() const override;
223 void _addItem(const MyGUI::UString& _name) override;
224 void _removeItemAt(size_t _index) override;
225 Widget* _getItemAt(size_t _index) const override;
226 void _setItemNameAt(size_t _index, const UString& _name) override;
227 const UString& _getItemNameAt(size_t _index) const override;
228
229 protected:
230 void initialiseOverride() override;
231 void shutdownOverride() override;
232
233 void updateBar();
234
237
238 int _getTextWidth(const UString& _text);
239
240 void _showItem(TabItem* _item, bool _show, bool _smooth);
241
242 void _createItemButton();
243
244 void _insertItem(size_t _index, const UString& _name, TabItem* _sheet, Any _data);
245
246 // вкладка при удалении уведомляет таб
247 void _notifyDeleteItem(TabItem* _sheet);
248
249 void onWidgetCreated(Widget* _widget) override;
250
251 void setPropertyOverride(std::string_view _key, std::string_view _value) override;
252
253 private:
254 void actionWidgetHide(Widget* _widget, ControllerItem* _controller);
255
256 ControllerFadeAlpha* createControllerFadeAlpha(float _alpha, float _coef, bool _enable);
257
258 Widget* _getWidgetTemplate();
259 Widget* _getWidgetBar();
260
261 Button* createButton();
262 void updateBarOld();
263 void updateBarNew();
264
265 private:
266 int mOffsetTab{0}; // смещение бара при показе кнопок
267 bool mButtonShow{true};
268 int mWidthBar{0}; // ширина в которую помещаються все кнопки
269 std::vector<Button*> mItemButton; // список кнопок, не должно равно списку страниц
270 std::string mButtonSkinName;
271 std::string mEmptySkinName;
272
273 Widget* mWidgetBar{nullptr};
274 Button* mButtonLeft{nullptr};
275 Button* mButtonRight{nullptr};
276 Widget* mButtonDecor{nullptr};
277 VectorWidgetPtr mWidgetsPatch; // список виджетов которые нужно показать при показе кнопки
278 Widget* mEmptyBarWidget{nullptr};
279 Widget* mItemTemplate{nullptr};
280
281 // информация о вкладках
282 VectorTabItemInfo mItemsInfo;
283 size_t mStartIndex{0};
284 size_t mIndexSelect{ITEM_NONE};
285
286 int mButtonDefaultWidth{1};
287 bool mSmoothShow{true};
288 bool mButtonAutoWidth{true};
289
290 // флаг, чтобы отсеч уведомления от вкладок, при общем шутдауне виджета
291 bool mShutdown{false};
292
293 Widget* mHeaderPlace{nullptr};
294 Widget* mControls{nullptr};
295 Widget* mEmpty{nullptr};
296 };
297
298} // namespace MyGUI
299
300#endif // MYGUI_TAB_CONTROL_H_
#define MYGUI_ASSERT_RANGE(index, size, owner)
#define MYGUI_EXPORT
#define MYGUI_RTTI_DERIVED(DerivedType)
Definition MyGUI_RTTI.h:69
static const Any Null
Definition MyGUI_Any.h:58
widget description should be here.
widget description should be here.
EventPair< EventHandle_WidgetSizeT, EventHandle_TabPtrSizeT > eventTabChangeSelect
int _getTextWidth(const UString &_text)
void _notifyDeleteItem(TabItem *_sheet)
size_t getIndexSelected() const
Get index of selected item (ITEM_NONE if none selected)
void _setItemNameAt(size_t _index, const UString &_name) override
size_t findItemIndex(const TabItem *_item)
Search item, returns the position of the first occurrence in array or ITEM_NONE if item not found.
void swapItems(size_t _index1, size_t _index2)
void clearItemDataAt(size_t _index)
Clear an item data at a specified position.
void setItemDataAt(size_t _index, Any _data)
Replace an item data at a specified position.
void onWidgetCreated(Widget *_widget) override
void removeAllItems()
Remove all items.
static constexpr int DEFAULT_WIDTH
ValueType * getItemData(TabItem *_item, bool _throw=true)
Get item data.
void _insertItem(size_t _index, const UString &_name, TabItem *_sheet, Any _data)
ValueType * getItemDataAt(size_t _index, bool _throw=true)
Get item data from specified position.
void setSize(const IntSize &_size) override
size_t getItemCount() const
Get number of items.
size_t findItemIndexWith(const UString &_name)
Search item, returns the position of the first occurrence in array or ITEM_NONE if item not found.
void setItemSelected(TabItem *_item)
Select item.
TabItem * findItemWith(const UString &_name)
Search item, returns the item of the first occurrence in array or nullptr if item not found.
TabItem * getItemSelected() const
Get selected item (nullptr if none selected)
size_t _getItemCount() const override
TabItem * insertItem(TabItem *_to, const UString &_name, Any _data=Any::Null)
Insert an item into a array.
void shutdownOverride() override
void setCoord(const IntCoord &_coord) override
void _addItem(const MyGUI::UString &_name) override
void setIndexSelected(size_t _index)
Select specified _index.
void _removeItemAt(size_t _index) override
void _showItem(TabItem *_item, bool _show, bool _smooth)
size_t getItemIndex(const TabItem *_item) const
Get item index.
Widget * _getItemAt(size_t _index) const override
void removeItemAt(size_t _index)
Remove item at a specified position.
void clearItemData(TabItem *_item)
Clear an item data.
void notifyPressedBarButtonEvent(MyGUI::Widget *_sender)
void setPosition(const IntPoint &_point) override
void setItemData(TabItem *_item, Any _data)
Replace an item data.
void removeItem(TabItem *_item)
Remove item.
const UString & _getItemNameAt(size_t _index) const override
TabItem * addItem(const UString &_name, Any _data=Any::Null)
Add an item to the end of a array.
std::vector< TabItemInfo > VectorTabItemInfo
TabItem * getItemAt(size_t _index) const
Get item from specified position.
void initialiseOverride() override
TabItem * insertItemAt(size_t _index, const UString &_name, Any _data=Any::Null)
Insert an item into a array at a specified position.
void notifyPressedButtonEvent(MyGUI::Widget *_sender)
void setPropertyOverride(std::string_view _key, std::string_view _value) override
widget description should be here.
A UTF-16 string with implicit conversion to/from std::string and std::wstring.
widget description should be here.
void setSize(const IntSize &_size) override
void setPosition(const IntPoint &_point) override
void setCoord(const IntCoord &_coord) override
delegates::MultiDelegate< TabControl *, size_t > EventHandle_TabPtrSizeT
types::TPoint< int > IntPoint
Definition MyGUI_Types.h:27
constexpr size_t ITEM_NONE
types::TCoord< int > IntCoord
Definition MyGUI_Types.h:36
types::TSize< int > IntSize
Definition MyGUI_Types.h:30
std::vector< Widget * > VectorWidgetPtr
TabItemInfo(int _width, const UString &_name, TabItem *_item, Any _data)