47 mButtonDefaultWidth(1),
49 mButtonAutoWidth(true),
59 Base::initialiseOverride();
66 mOffsetTab = utility::parseValue<int>(
getUserString(
"OffsetBar"));
73 if (mWidgetBar !=
nullptr)
79 if (mButtonLeft !=
nullptr)
85 if (mButtonRight !=
nullptr)
92 if (mButtonDecor !=
nullptr)
98 if (mItemTemplate !=
nullptr)
103 #ifndef MYGUI_DONT_USE_OBSOLETE
104 if (mItemTemplate ==
nullptr)
107 if (mItemTemplate !=
nullptr)
112 #endif // MYGUI_DONT_USE_OBSOLETE
115 Widget* showPatch =
nullptr;
117 if (showPatch !=
nullptr)
119 mWidgetsPatch.push_back(showPatch);
127 if (mEmpty ==
nullptr)
142 mWidgetsPatch.clear();
143 mWidgetBar =
nullptr;
144 mButtonLeft =
nullptr;
145 mButtonRight =
nullptr;
146 mButtonDecor =
nullptr;
147 mItemTemplate =
nullptr;
148 mEmptyBarWidget =
nullptr;
150 mHeaderPlace =
nullptr;
157 Base::shutdownOverride();
162 Base::onWidgetCreated(_widget);
165 if (child !=
nullptr)
180 size_t lastIndex = mItemsInfo.size() - 1;
186 return widget->castType<
TabItem>();
194 if (_index1 != _index2)
196 std::swap(mItemsInfo[_index1], mItemsInfo[_index2]);
203 Base::setPosition(_point);
210 Base::setSize(_size);
217 Base::setCoord(_coord);
224 if (_sender == mButtonLeft)
232 else if (_sender == mButtonRight)
234 if ((mStartIndex + 1) < mItemsInfo.size())
247 if (select == mIndexSelect)
253 size_t old = mIndexSelect;
254 mIndexSelect = select;
257 for (
size_t pos = 0; pos < mItemButton.size(); pos++)
259 Button* button = mItemButton[count]->castType<
Button>();
274 _showItem(mItemsInfo[mIndexSelect].item,
true, mSmoothShow);
275 _showItem(mItemsInfo[old].item,
false, mSmoothShow);
285 if (_getWidgetBar()->
getWidth() < 1)
288 if (_index == mStartIndex)
290 else if (_index < mStartIndex)
292 mStartIndex = _index;
299 for (
size_t pos = mStartIndex; pos <= _index; pos++)
301 width += mItemsInfo[pos].width;
306 while ((mStartIndex < _index) && (width > _getWidgetBar()->
getWidth()))
308 width -= mItemsInfo[mStartIndex].width;
319 mButtonDefaultWidth = _width;
320 if (mButtonDefaultWidth < 1)
321 mButtonDefaultWidth = 1;
327 mButtonAutoWidth = _auto;
329 for (
size_t pos = 0; pos < mItemsInfo.size(); pos++)
332 if (mButtonAutoWidth)
335 width = mButtonDefaultWidth;
337 mWidthBar += width - mItemsInfo[pos].width;
338 mItemsInfo[pos].width = width;
350 if (mButtonAutoWidth)
353 _width = mButtonDefaultWidth;
356 mWidthBar += _width - mItemsInfo[_index].width;
357 mItemsInfo[_index].width = _width;
365 mItemsInfo[_index].name = _name;
368 if (mButtonAutoWidth)
371 width = mButtonDefaultWidth;
373 mWidthBar += width - mItemsInfo[_index].width;
374 mItemsInfo[_index].width = width;
382 if (mIndexSelect == _index)
384 size_t old = mIndexSelect;
385 mIndexSelect = _index;
392 _showItem(mItemsInfo[mIndexSelect].item,
true, mSmoothShow);
393 _showItem(mItemsInfo[old].item,
false, mSmoothShow);
398 void TabControl::actionWidgetHide(
Widget* _widget)
429 Button* TabControl::createButton()
432 if (mWidgetBar !=
nullptr)
434 else if (mHeaderPlace !=
nullptr)
435 parent = mHeaderPlace;
442 Button* button = createButton();
445 mItemButton.push_back(button);
450 if (mItemButton.empty())
453 UString save = mItemButton[0]->getCaption();
454 mItemButton[0]->setCaption(_text);
460 mItemButton[0]->setCaption(save);
462 return size.
width + mItemButton[0]->getWidth() - coord.
width;
473 mWidthBar -= mItemsInfo[index].width;
474 mItemsInfo.erase(mItemsInfo.begin() + index);
476 if (mItemsInfo.empty())
480 if (index < mIndexSelect)
482 else if (index == mIndexSelect)
484 if (mIndexSelect == mItemsInfo.size())
486 mItemsInfo[mIndexSelect].item->setVisible(
true);
487 mItemsInfo[mIndexSelect].item->setAlpha(
ALPHA_MAX);
497 _index = mItemsInfo.size();
500 int width = (mButtonAutoWidth ?
_getTextWidth(_name) : mButtonDefaultWidth);
503 mItemsInfo.insert(mItemsInfo.begin() + _index,
TabItemInfo(width, _name, _sheet, _data));
506 if (1 == mItemsInfo.size())
511 if (_index <= mIndexSelect)
521 mItemsInfo[_index].data = _data;
527 return mItemsInfo[_index].width;
533 return mItemsInfo[_index].name;
539 return mItemsInfo[_index].item;
550 while (!mItemsInfo.empty())
556 ControllerFadeAlpha* TabControl::createControllerFadeAlpha(
float _alpha,
float _coef,
bool _enable)
570 for (
size_t pos = 0; pos < mItemsInfo.size(); pos++)
572 if (mItemsInfo[pos].item == _item)
575 MYGUI_EXCEPT(
"item (" << _item <<
") not found, source 'TabControl::getItemIndex'");
580 for (
size_t pos = 0; pos < mItemsInfo.size(); pos++)
582 if (mItemsInfo[pos].item == _item)
590 for (
size_t pos = 0; pos < mItemsInfo.size(); pos++)
592 if (mItemsInfo[pos].name == _name)
600 for (
size_t pos = 0; pos < mItemsInfo.size(); pos++)
602 if (mItemsInfo[pos].name == _name)
603 return mItemsInfo[pos].item;
613 Widget* TabControl::_getWidgetTemplate()
615 return mItemTemplate ==
nullptr ?
this : mItemTemplate;
618 Widget* TabControl::_getWidgetBar()
620 return mWidgetBar ==
nullptr ?
this : mWidgetBar;
625 if (_key ==
"ButtonWidth")
627 else if (_key ==
"ButtonAutoWidth")
629 else if (_key ==
"SmoothShow")
631 else if (_key ==
"SelectItem")
635 Base::setPropertyOverride(_key, _value);
658 return mItemsInfo.size();
746 return mButtonDefaultWidth;
751 return mButtonAutoWidth;
756 mSmoothShow = _value;
796 if (mHeaderPlace !=
nullptr)
802 void TabControl::updateBarOld()
805 if (_getWidgetBar()->
getWidth() < 1)
808 if ((_getWidgetBar()->
getWidth() < mWidthBar) && (1 < mItemsInfo.size()))
814 if (
nullptr != mButtonLeft)
816 if (
nullptr != mButtonRight)
818 if (
nullptr != mButtonDecor)
820 for (VectorWidgetPtr::iterator iter = mWidgetsPatch.begin(); iter != mWidgetsPatch.end(); ++iter)
821 (*iter)->setVisible(
true);
822 if (mWidgetBar !=
nullptr)
831 if (
nullptr != mButtonLeft)
833 if (
nullptr != mButtonRight)
835 if (
nullptr != mButtonDecor)
837 for (VectorWidgetPtr::iterator iter = mWidgetsPatch.begin(); iter != mWidgetsPatch.end(); ++iter)
838 (*iter)->setVisible(
false);
839 if (mWidgetBar !=
nullptr)
849 for (
size_t pos = mStartIndex; pos < mItemsInfo.size(); pos++)
850 width += mItemsInfo[pos].width;
853 while ((mStartIndex > 0) && ((width + mItemsInfo[mStartIndex - 1].width) <= _getWidgetBar()->
getWidth()))
856 width += mItemsInfo[mStartIndex].width;
863 size_t pos = mStartIndex;
864 for (; pos < mItemsInfo.size(); pos++)
867 if (width > _getWidgetBar()->
getWidth())
871 TabItemInfo& info = mItemsInfo[pos];
872 if ((width + info.width) > _getWidgetBar()->
getWidth())
878 if (count >= mItemButton.size())
882 Button* button = mItemButton[count]->castType<Button>();
883 button->setVisible(
true);
886 button->setStateSelected(pos == mIndexSelect);
888 if (button->getCaption() != info.name)
889 button->setCaption(info.name);
892 if (coord != button->getCoord())
893 button->setCoord(coord);
900 while (count < mItemButton.size())
902 mItemButton[count]->setVisible(
false);
907 if (pos == mItemsInfo.size())
911 if (mEmptyBarWidget !=
nullptr)
914 if (width < _getWidgetBar()->
getWidth())
926 if (mStartIndex == 0)
928 if (
nullptr != mButtonLeft)
933 if (
nullptr != mButtonLeft)
939 if (
nullptr != mButtonRight)
944 if (
nullptr != mButtonRight)
949 void TabControl::updateBarNew()
955 if (mHeaderPlace ==
nullptr)
958 int widthControls = 0;
959 if (mControls !=
nullptr)
960 widthControls = mControls->
getWidth();
962 if ((mHeaderPlace->
getWidth() < mWidthBar) && (1 < mItemsInfo.size()) && (mHeaderPlace->
getWidth() >= widthControls))
968 if (
nullptr != mControls)
972 if (mControls !=
nullptr)
981 if (
nullptr != mControls)
993 for (
size_t pos = mStartIndex; pos < mItemsInfo.size(); pos++)
994 width += mItemsInfo[pos].width;
997 while ((mStartIndex > 0) && ((width + mItemsInfo[mStartIndex - 1].width) <= (mHeaderPlace->
getWidth() - widthControls)))
1000 width += mItemsInfo[mStartIndex].width;
1007 size_t pos = mStartIndex;
1008 for (; pos < mItemsInfo.size(); pos++)
1011 if (width > (mHeaderPlace->
getWidth() - widthControls))
1015 TabItemInfo& info = mItemsInfo[pos];
1016 if ((width + info.width) > (mHeaderPlace->
getWidth() - widthControls))
1022 if (count >= mItemButton.size())
1026 Button* button = mItemButton[count];
1027 button->setVisible(
true);
1030 button->setStateSelected(pos == mIndexSelect);
1032 if (button->getCaption() != info.name)
1033 button->setCaption(info.name);
1036 if (coord != button->getCoord())
1037 button->setCoord(coord);
1039 width += info.
width;
1044 while (count < mItemButton.size())
1046 mItemButton[count]->setVisible(
false);
1051 if (pos == mItemsInfo.size())
1054 if (mEmpty !=
nullptr)
1061 if (mStartIndex == 0)
1063 if (
nullptr != mButtonLeft)
1068 if (
nullptr != mButtonLeft)
1074 if (
nullptr != mButtonRight)
1079 if (
nullptr != mButtonRight)
void addItem(Widget *_widget, ControllerItem *_item)
int getAbsoluteLeft() const
virtual void onWidgetCreated(Widget *_widget)
void removeItemAt(size_t _index)
Remove item at a specified position.
virtual void _addItem(const MyGUI::UString &_name)
TabItem * findItemWith(const UString &_name)
Search item, returns the item of the first occurrence in array or nullptr if item not found...
size_t getIndexSelected() const
Get index of selected item (ITEM_NONE if none selected)
bool getButtonAutoWidth() const
int _getTextWidth(const UString &_text)
const IntCoord & getCoord() const
types::TSize< int > IntSize
void _notifyDeleteItem(TabItem *_item)
virtual void setPropertyOverride(const std::string &_key, const std::string &_value)
delegates::IDelegate0 * newDelegate(void(*_func)())
virtual size_t _getItemCount()
static ControllerManager & getInstance()
void setButtonDefaultWidth(int _value)
void _insertItem(size_t _index, const UString &_name, TabItem *_sheet, Any _data)
void setButtonWidth(TabItem *_item, int _width=DEFAULT)
Set button width.
void setItemNameAt(size_t _index, const UString &_name)
Replace an item name at a specified position.
size_t findItemIndex(TabItem *_item)
Search item, returns the position of the first occurrence in array or ITEM_NONE if item not found...
void beginToItemAt(size_t _index)
Move all elements so specified becomes visible.
size_t getItemCount() const
Get number of items.
int getAbsoluteTop() const
TabItem * insertItemAt(size_t _index, const UString &_name, Any _data=Any::Null)
Insert an item into a array at a specified position.
void swapItems(size_t _index1, size_t _index2)
void setSmoothShow(bool _value)
void setItemDataAt(size_t _index, Any _data)
Replace an item data at a specified position.
void beginToItemLast()
Move all elements so last becomes visible.
int getButtonWidth(TabItem *_item)
Get button width.
virtual void setCoord(const IntCoord &_value)
virtual void setPosition(const IntPoint &_value)
void removeItem(TabItem *_item)
Remove item.
types::TCoord< int > IntCoord
static const std::string & getClassTypeName()
const UString & getItemNameAt(size_t _index)
Get item name from specified position.
void removeAllItems()
Remove all items.
TabItem * insertItem(TabItem *_to, const UString &_name, Any _data=Any::Null)
Insert an item into a array.
void setButtonWidthAt(size_t _index, int _width=DEFAULT)
Set button width at a specified position.
#define MYGUI_EXCEPT(dest)
void setButtonAutoWidth(bool _value)
void setItemData(TabItem *_item, Any _data)
Replace an item data.
static const std::string & getClassTypeName()
void setItemName(TabItem *_item, const UString &_name)
Replace an item name.
void notifyPressedButtonEvent(MyGUI::Widget *_sender)
void setAlpha(float _value)
void _setInternalData(Any _data)
void setCoef(float _value)
TabItem * getItemAt(size_t _index)
Get item from specified position.
const UString & getItemName(TabItem *_item)
Get item name.
virtual Widget * _getItemAt(size_t _index)
void beginToItemFirst()
Move all elements so first becomes visible.
void _showItem(TabItem *_sheet, bool _show, bool _smooth)
TabItem * getItemSelected()
Get selected item (nullptr if none selected)
void setEnabled(bool _value)
virtual void _removeItemAt(size_t _index)
int getButtonWidthAt(size_t _index)
Get button width at a specified position.
Type * castType(bool _throw=true)
TabItem * addItem(const UString &_name, Any _data=Any::Null)
Add an item to the end of a array.
delegates::CMultiDelegate1< Widget * > eventPostAction
bool getSmoothShow() const
size_t getItemIndex(TabItem *_item)
Get item index.
virtual void _setItemNameAt(size_t _index, const UString &_name)
bool isUserString(const std::string &_key) const
void removeItem(Widget *_widget)
void notifyPressedBarButtonEvent(MyGUI::Widget *_sender)
virtual void setSize(const IntSize &_value)
#define MYGUI_ASSERT_RANGE(index, size, owner)
size_t findItemIndexWith(const UString &_name)
Search item, returns the position of the first occurrence in array or ITEM_NONE if item not found...
virtual void initialiseOverride()
int getButtonDefaultWidth() const
EventPair< EventHandle_WidgetSizeT, EventHandle_TabPtrSizeT > eventTabChangeSelect
A UTF-16 string with implicit conversion to/from std::string and std::wstring.
void setItemSelected(TabItem *_item)
Select item.
const float TAB_SPEED_FADE_COEF
virtual IntSize getTextSize()
virtual void shutdownOverride()
void clearItemDataAt(size_t _index)
Clear an item data at a specified position.
virtual const UString & _getItemNameAt(size_t _index)
void setIndexSelected(size_t _index)
Select specified _index.
void beginToItem(TabItem *_item)
Move all elements so specified becomes visible.
#define MYGUI_ASSERT_RANGE_INSERT(index, size, owner)
ValueType * _getInternalData(bool _throw=true)
void beginToItemSelected()
Move all elements so selected becomes visible.
void clearItemData(TabItem *_item)
Clear an item data.
const std::string & getUserString(const std::string &_key) const
ControllerItem * createItem(const std::string &_type)
types::TPoint< int > IntPoint