MyGUI: MyGUI_TabControl.h Source File

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"
14#include "MyGUI_ControllerFadeAlpha.h"
15#include "MyGUI_IItem.h"
16#include "MyGUI_IItemContainer.h"
17
18namespace MyGUI
19{
20
21 using EventHandle_TabPtrSizeT = delegates::MultiDelegate<TabControl*, size_t>;
22
26 class MYGUI_EXPORT TabControl : public Widget, public IItemContainer, public MemberObsolete<TabControl>
27 {
28 // для уведобления об удалении
29 //FIXME
30 friend class TabItem;
31
32 MYGUI_RTTI_DERIVED(TabControl)
33
34 public:
35 struct TabItemInfo
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;
46 UString name;
47 TabItem* item;
48 Any data;
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
62 using Widget::setPosition;
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:*/
218 EventPair<EventHandle_WidgetSizeT, EventHandle_TabPtrSizeT> eventTabChangeSelect;
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
235 void notifyPressedButtonEvent(MyGUI::Widget* _sender);
236 void notifyPressedBarButtonEvent(MyGUI::Widget* _sender);
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_
MyGUI_Any.h
MyGUI_ControllerFadeAlpha.h
MYGUI_ASSERT_RANGE
#define MYGUI_ASSERT_RANGE(index, size, owner)
Definition MyGUI_Diagnostic.h:44
MyGUI_EventPair.h
MyGUI_IItem.h
MyGUI_IItemContainer.h
MYGUI_EXPORT
#define MYGUI_EXPORT
Definition MyGUI_Platform.h:77
MyGUI_Prerequest.h
MYGUI_RTTI_DERIVED
#define MYGUI_RTTI_DERIVED(DerivedType)
Definition MyGUI_RTTI.h:69
MyGUI_Widget.h
MyGUI::Any
Definition MyGUI_Any.h:56
MyGUI::Any::Null
static const Any Null
Definition MyGUI_Any.h:58
MyGUI::Button
widget description should be here.
Definition MyGUI_Button.h:20
MyGUI::ControllerFadeAlpha
Definition MyGUI_ControllerFadeAlpha.h:19
MyGUI::ControllerItem
Definition MyGUI_ControllerItem.h:26
MyGUI::EventPair
Definition MyGUI_EventPair.h:99
MyGUI::IItemContainer
Definition MyGUI_IItemContainer.h:19
MyGUI::MemberObsolete
Definition MyGUI_DeprecatedTypes.h:14
MyGUI::TabControl
widget description should be here.
Definition MyGUI_TabControl.h:27
MyGUI::TabControl::eventTabChangeSelect
EventPair< EventHandle_WidgetSizeT, EventHandle_TabPtrSizeT > eventTabChangeSelect
Definition MyGUI_TabControl.h:218
MyGUI::TabControl::_getTextWidth
int _getTextWidth(const UString &_text)
Definition MyGUI_TabControl.cpp:435
MyGUI::TabControl::_notifyDeleteItem
void _notifyDeleteItem(TabItem *_sheet)
Definition MyGUI_TabControl.cpp:452
MyGUI::TabControl::getIndexSelected
size_t getIndexSelected() const
Get index of selected item (ITEM_NONE if none selected)
Definition MyGUI_TabControl.cpp:657
MyGUI::TabControl::_setItemNameAt
void _setItemNameAt(size_t _index, const UString &_name) override
Definition MyGUI_TabControl.cpp:765
MyGUI::TabControl::findItemIndex
size_t findItemIndex(const TabItem *_item)
Search item, returns the position of the first occurrence in array or ITEM_NONE if item not found.
Definition MyGUI_TabControl.cpp:565
MyGUI::TabControl::updateBar
void updateBar()
Definition MyGUI_TabControl.cpp:775
MyGUI::TabControl::swapItems
void swapItems(size_t _index1, size_t _index2)
Definition MyGUI_TabControl.cpp:174
MyGUI::TabControl::clearItemDataAt
void clearItemDataAt(size_t _index)
Clear an item data at a specified position.
Definition MyGUI_TabControl.cpp:672
MyGUI::TabControl::setItemDataAt
void setItemDataAt(size_t _index, Any _data)
Replace an item data at a specified position.
Definition MyGUI_TabControl.cpp:505
MyGUI::TabControl::onWidgetCreated
void onWidgetCreated(Widget *_widget) override
Definition MyGUI_TabControl.cpp:133
MyGUI::TabControl::removeAllItems
void removeAllItems()
Remove all items.
Definition MyGUI_TabControl.cpp:535
MyGUI::TabControl::DEFAULT_WIDTH
static constexpr int DEFAULT_WIDTH
Definition MyGUI_TabControl.h:53
MyGUI::TabControl::getItemData
ValueType * getItemData(TabItem *_item, bool _throw=true)
Get item data.
Definition MyGUI_TabControl.h:144
MyGUI::TabControl::_insertItem
void _insertItem(size_t _index, const UString &_name, TabItem *_sheet, Any _data)
Definition MyGUI_TabControl.cpp:481
MyGUI::TabControl::getItemDataAt
ValueType * getItemDataAt(size_t _index, bool _throw=true)
Get item data from specified position.
Definition MyGUI_TabControl.h:137
MyGUI::TabControl::setSize
void setSize(const IntSize &_size) override
Definition MyGUI_TabControl.cpp:193
MyGUI::TabControl::getItemCount
size_t getItemCount() const
Get number of items.
Definition MyGUI_TabControl.cpp:637
MyGUI::TabControl::findItemIndexWith
size_t findItemIndexWith(const UString &_name)
Search item, returns the position of the first occurrence in array or ITEM_NONE if item not found.
Definition MyGUI_TabControl.cpp:575
MyGUI::TabControl::setItemSelected
void setItemSelected(TabItem *_item)
Select item.
Definition MyGUI_TabControl.cpp:662
MyGUI::TabControl::TabItem
friend class TabItem
Definition MyGUI_TabControl.h:30
MyGUI::TabControl::findItemWith
TabItem * findItemWith(const UString &_name)
Search item, returns the item of the first occurrence in array or nullptr if item not found.
Definition MyGUI_TabControl.cpp:585
MyGUI::TabControl::getItemSelected
TabItem * getItemSelected() const
Get selected item (nullptr if none selected)
Definition MyGUI_TabControl.cpp:595
MyGUI::TabControl::_getItemCount
size_t _getItemCount() const override
Definition MyGUI_TabControl.cpp:745
MyGUI::TabControl::insertItem
TabItem * insertItem(TabItem *_to, const UString &_name, Any _data=Any::Null)
Insert an item into a array.
Definition MyGUI_TabControl.cpp:642
MyGUI::TabControl::shutdownOverride
void shutdownOverride() override
Definition MyGUI_TabControl.cpp:113
MyGUI::TabControl::setCoord
void setCoord(const IntCoord &_coord) override
Definition MyGUI_TabControl.cpp:200
MyGUI::TabControl::_addItem
void _addItem(const MyGUI::UString &_name) override
Definition MyGUI_TabControl.cpp:750
MyGUI::TabControl::setIndexSelected
void setIndexSelected(size_t _index)
Select specified _index.
Definition MyGUI_TabControl.cpp:364
MyGUI::TabControl::_removeItemAt
void _removeItemAt(size_t _index) override
Definition MyGUI_TabControl.cpp:755
MyGUI::TabControl::_showItem
void _showItem(TabItem *_item, bool _show, bool _smooth)
Definition MyGUI_TabControl.cpp:389
MyGUI::TabControl::getItemIndex
size_t getItemIndex(const TabItem *_item) const
Get item index.
Definition MyGUI_TabControl.cpp:555
MyGUI::TabControl::_getItemAt
Widget * _getItemAt(size_t _index) const override
Definition MyGUI_TabControl.cpp:760
MyGUI::TabControl::removeItemAt
void removeItemAt(size_t _index)
Remove item at a specified position.
Definition MyGUI_TabControl.cpp:529
MyGUI::TabControl::clearItemData
void clearItemData(TabItem *_item)
Clear an item data.
Definition MyGUI_TabControl.cpp:677
MyGUI::TabControl::notifyPressedBarButtonEvent
void notifyPressedBarButtonEvent(MyGUI::Widget *_sender)
Definition MyGUI_TabControl.cpp:228
MyGUI::TabControl::setPosition
void setPosition(const IntPoint &_point) override
Definition MyGUI_TabControl.cpp:186
MyGUI::TabControl::setItemData
void setItemData(TabItem *_item, Any _data)
Replace an item data.
Definition MyGUI_TabControl.cpp:667
MyGUI::TabControl::removeItem
void removeItem(TabItem *_item)
Remove item.
Definition MyGUI_TabControl.cpp:652
MyGUI::TabControl::_getItemNameAt
const UString & _getItemNameAt(size_t _index) const override
Definition MyGUI_TabControl.cpp:770
MyGUI::TabControl::addItem
TabItem * addItem(const UString &_name, Any _data=Any::Null)
Add an item to the end of a array.
Definition MyGUI_TabControl.cpp:647
MyGUI::TabControl::VectorTabItemInfo
std::vector< TabItemInfo > VectorTabItemInfo
Definition MyGUI_TabControl.h:51
MyGUI::TabControl::_createItemButton
void _createItemButton()
Definition MyGUI_TabControl.cpp:427
MyGUI::TabControl::getItemAt
TabItem * getItemAt(size_t _index) const
Get item from specified position.
Definition MyGUI_TabControl.cpp:523
MyGUI::TabControl::initialiseOverride
void initialiseOverride() override
Definition MyGUI_TabControl.cpp:20
MyGUI::TabControl::insertItemAt
TabItem * insertItemAt(size_t _index, const UString &_name, Any _data=Any::Null)
Insert an item into a array at a specified position.
Definition MyGUI_TabControl.cpp:151
MyGUI::TabControl::notifyPressedButtonEvent
void notifyPressedButtonEvent(MyGUI::Widget *_sender)
Definition MyGUI_TabControl.cpp:207
MyGUI::TabControl::setPropertyOverride
void setPropertyOverride(std::string_view _key, std::string_view _value) override
Definition MyGUI_TabControl.cpp:610
MyGUI::TabItem
widget description should be here.
Definition MyGUI_TabItem.h:21
MyGUI::UString
A UTF-16 string with implicit conversion to/from std::string and std::wstring.
Definition MyGUI_UString.h:144
MyGUI::Widget
widget description should be here.
Definition MyGUI_Widget.h:40
MyGUI::Widget::setSize
void setSize(const IntSize &_size) override
Definition MyGUI_Widget.cpp:693
MyGUI::Widget::setPosition
void setPosition(const IntPoint &_point) override
Definition MyGUI_Widget.cpp:676
MyGUI::Widget::setCoord
void setCoord(const IntCoord &_coord) override
Definition MyGUI_Widget.cpp:730
MyGUI::delegates::MultiDelegate
Definition MyGUI_Delegate.h:190
MyGUI
Definition MyGUI_ActionController.h:15
MyGUI::EventHandle_TabPtrSizeT
delegates::MultiDelegate< TabControl *, size_t > EventHandle_TabPtrSizeT
Definition MyGUI_TabControl.h:21
MyGUI::IntPoint
types::TPoint< int > IntPoint
Definition MyGUI_Types.h:27
MyGUI::ITEM_NONE
constexpr size_t ITEM_NONE
Definition MyGUI_Macros.h:19
MyGUI::IntCoord
types::TCoord< int > IntCoord
Definition MyGUI_Types.h:36
MyGUI::IntSize
types::TSize< int > IntSize
Definition MyGUI_Types.h:30
MyGUI::VectorWidgetPtr
std::vector< Widget * > VectorWidgetPtr
Definition MyGUI_WidgetDefines.h:20
MyGUI::TabControl::TabItemInfo::width
int width
Definition MyGUI_TabControl.h:45
MyGUI::TabControl::TabItemInfo::TabItemInfo
TabItemInfo(int _width, const UString &_name, TabItem *_item, Any _data)
Definition MyGUI_TabControl.h:37
MyGUI::TabControl::TabItemInfo::name
UString name
Definition MyGUI_TabControl.h:46
MyGUI::TabControl::TabItemInfo::item
TabItem * item
Definition MyGUI_TabControl.h:47
MyGUI::TabControl::TabItemInfo::data
Any data
Definition MyGUI_TabControl.h:48