MyGUI_TabControl.h
Go to the documentation of this file.
/*
* This source file is part of MyGUI. For the latest info, see http://mygui.info/
* Distributed under the MIT License
* (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
*/
#ifndef MYGUI_TAB_CONTROL_H_
#define MYGUI_TAB_CONTROL_H_
#include "MyGUI_Prerequest.h"
#include "MyGUI_Widget.h"
#include "MyGUI_Any.h"
#include "MyGUI_EventPair.h"
#include "MyGUI_ControllerFadeAlpha.h"
#include "MyGUI_IItem.h"
#include "MyGUI_IItemContainer.h"
namespace MyGUI
{
using EventHandle_TabPtrSizeT = delegates::MultiDelegate<TabControl*, size_t>;
class MYGUI_EXPORT TabControl : public Widget, public IItemContainer, public MemberObsolete<TabControl>
{
// для уведобления об удалении
//FIXME
friend class TabItem;
MYGUI_RTTI_DERIVED(TabControl)
public:
struct TabItemInfo
{
TabItemInfo(int _width, const UString& _name, TabItem* _item, Any _data) :
width(_width),
name(_name),
item(_item),
data(_data)
{
}
int width;
UString name;
TabItem* item;
Any data;
};
using VectorTabItemInfo = std::vector<TabItemInfo>;
static constexpr int DEFAULT_WIDTH = -1;
void setPosition(const IntPoint& _point) override;
void setSize(const IntSize& _size) override;
void setCoord(const IntCoord& _coord) override;
using Widget::setPosition;
using Widget::setSize;
using Widget::setCoord;
//------------------------------------------------------------------------------//
// манипуляции айтемами
size_t getItemCount() const;
TabItem* insertItemAt(size_t _index, const UString& _name, Any _data = Any::Null);
TabItem* insertItem(TabItem* _to, const UString& _name, Any _data = Any::Null);
TabItem* addItem(const UString& _name, Any _data = Any::Null);
void removeItemAt(size_t _index);
void removeItem(TabItem* _item);
void removeAllItems();
TabItem* getItemAt(size_t _index) const;
size_t getItemIndex(const TabItem* _item) const;
size_t findItemIndex(const TabItem* _item);
size_t findItemIndexWith(const UString& _name);
TabItem* findItemWith(const UString& _name);
void swapItems(size_t _index1, size_t _index2);
//------------------------------------------------------------------------------//
// манипуляции выделениями
size_t getIndexSelected() const;
TabItem* getItemSelected() const;
void setIndexSelected(size_t _index);
void setItemSelected(TabItem* _item);
//------------------------------------------------------------------------------//
// манипуляции данными
void setItemDataAt(size_t _index, Any _data);
void setItemData(TabItem* _item, Any _data);
void clearItemDataAt(size_t _index);
void clearItemData(TabItem* _item);
template<typename ValueType>
ValueType* getItemDataAt(size_t _index, bool _throw = true)
{
MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "TabControl::getItemDataAt");
return mItemsInfo[_index].data.castType<ValueType>(_throw);
}
template<typename ValueType>
ValueType* getItemData(TabItem* _item, bool _throw = true)
{
return getItemDataAt<ValueType>(getItemIndex(_item), _throw);
}
//------------------------------------------------------------------------------//
// манипуляции отображением
void setItemNameAt(size_t _index, const UString& _name);
void setItemName(TabItem* _item, const UString& _name);
const UString& getItemNameAt(size_t _index) const;
const UString& getItemName(const TabItem* _item) const;
//------------------------------------------------------------------------------//
// манипуляции выдимостью
void beginToItemAt(size_t _index);
void beginToItem(const TabItem* _item);
void beginToItemFirst();
void beginToItemLast();
void beginToItemSelected();
//------------------------------------------------------------------------------//
// остальные манипуляции
void setButtonWidthAt(size_t _index, int _width = DEFAULT_WIDTH);
void setButtonWidth(TabItem* _item, int _width = DEFAULT_WIDTH);
int getButtonWidthAt(size_t _index) const;
int getButtonWidth(TabItem* _item) const;
//------------------------------------------------------------------------------//
void setButtonDefaultWidth(int _width);
int getButtonDefaultWidth() const;
void setButtonAutoWidth(bool _auto);
bool getButtonAutoWidth() const;
void setSmoothShow(bool _value);
bool getSmoothShow() const;
/*events:*/
EventPair<EventHandle_WidgetSizeT, EventHandle_TabPtrSizeT> eventTabChangeSelect;
/*internal:*/
// IItemContainer impl
size_t _getItemCount() const override;
void _addItem(const MyGUI::UString& _name) override;
void _removeItemAt(size_t _index) override;
Widget* _getItemAt(size_t _index) const override;
void _setItemNameAt(size_t _index, const UString& _name) override;
const UString& _getItemNameAt(size_t _index) const override;
protected:
void initialiseOverride() override;
void shutdownOverride() override;
void updateBar();
void notifyPressedButtonEvent(MyGUI::Widget* _sender);
void notifyPressedBarButtonEvent(MyGUI::Widget* _sender);
int _getTextWidth(const UString& _text);
void _showItem(TabItem* _item, bool _show, bool _smooth);
void _createItemButton();
void _insertItem(size_t _index, const UString& _name, TabItem* _sheet, Any _data);
// вкладка при удалении уведомляет таб
void _notifyDeleteItem(TabItem* _sheet);
void onWidgetCreated(Widget* _widget) override;
void setPropertyOverride(std::string_view _key, std::string_view _value) override;
private:
void actionWidgetHide(Widget* _widget, ControllerItem* _controller);
ControllerFadeAlpha* createControllerFadeAlpha(float _alpha, float _coef, bool _enable);
Widget* _getWidgetTemplate();
Widget* _getWidgetBar();
Button* createButton();
void updateBarOld();
void updateBarNew();
private:
int mOffsetTab{0}; // смещение бара при показе кнопок
bool mButtonShow{true};
int mWidthBar{0}; // ширина в которую помещаються все кнопки
std::vector<Button*> mItemButton; // список кнопок, не должно равно списку страниц
std::string mButtonSkinName;
std::string mEmptySkinName;
Widget* mWidgetBar{nullptr};
Button* mButtonLeft{nullptr};
Button* mButtonRight{nullptr};
Widget* mButtonDecor{nullptr};
VectorWidgetPtr mWidgetsPatch; // список виджетов которые нужно показать при показе кнопки
Widget* mEmptyBarWidget{nullptr};
Widget* mItemTemplate{nullptr};
// информация о вкладках
VectorTabItemInfo mItemsInfo;
size_t mStartIndex{0};
size_t mIndexSelect{ITEM_NONE};
int mButtonDefaultWidth{1};
bool mSmoothShow{true};
bool mButtonAutoWidth{true};
// флаг, чтобы отсеч уведомления от вкладок, при общем шутдауне виджета
bool mShutdown{false};
Widget* mHeaderPlace{nullptr};
Widget* mControls{nullptr};
Widget* mEmpty{nullptr};
};
} // namespace MyGUI
#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