26 mButtonRight(nullptr),
27 mButtonDecor(nullptr),
28 mEmptyBarWidget(nullptr),
29 mItemTemplate(nullptr),
32 mButtonDefaultWidth(1),
34 mButtonAutoWidth(true),
36 mHeaderPlace(nullptr),
44 Base::initialiseOverride();
51 mOffsetTab = utility::parseValue<int>(
getUserString(
"OffsetBar"));
59 if (mWidgetBar !=
nullptr)
66 if (mButtonLeft !=
nullptr)
73 if (mButtonRight !=
nullptr)
80 if (mButtonDecor !=
nullptr)
87 if (mItemTemplate !=
nullptr)
92#ifndef MYGUI_DONT_USE_OBSOLETE
93 if (mItemTemplate ==
nullptr)
96 if (mItemTemplate !=
nullptr)
104 Widget* showPatch =
nullptr;
106 if (showPatch !=
nullptr)
108 mWidgetsPatch.push_back(showPatch);
121 if (mEmpty ==
nullptr)
136 mWidgetsPatch.clear();
137 mWidgetBar =
nullptr;
138 mButtonLeft =
nullptr;
139 mButtonRight =
nullptr;
140 mButtonDecor =
nullptr;
141 mItemTemplate =
nullptr;
142 mEmptyBarWidget =
nullptr;
144 mHeaderPlace =
nullptr;
151 Base::shutdownOverride();
156 Base::onWidgetCreated(_widget);
159 if (child !=
nullptr)
174 size_t lastIndex = mItemsInfo.size() - 1;
188 if (_index1 != _index2)
190 std::swap(mItemsInfo[_index1], mItemsInfo[_index2]);
197 Base::setPosition(_point);
204 Base::setSize(_size);
211 Base::setCoord(_coord);
218 if (_sender == mButtonLeft)
226 else if (_sender == mButtonRight)
228 if ((mStartIndex + 1) < mItemsInfo.size())
241 if (select == mIndexSelect)
247 size_t old = mIndexSelect;
248 mIndexSelect = select;
251 for (
size_t pos = 0; pos < mItemButton.size(); pos++)
253 Button* button = mItemButton[count]->castType<
Button>();
268 _showItem(mItemsInfo[mIndexSelect].item,
true, mSmoothShow);
269 _showItem(mItemsInfo[old].item,
false, mSmoothShow);
279 if (_getWidgetBar()->
getWidth() < 1)
282 if (_index == mStartIndex)
284 else if (_index < mStartIndex)
286 mStartIndex = _index;
293 for (
size_t pos = mStartIndex; pos <= _index; pos++)
295 width += mItemsInfo[pos].width;
300 while ((mStartIndex < _index) && (width > _getWidgetBar()->
getWidth()))
302 width -= mItemsInfo[mStartIndex].width;
313 mButtonDefaultWidth = _width;
314 if (mButtonDefaultWidth < 1)
315 mButtonDefaultWidth = 1;
321 mButtonAutoWidth = _auto;
323 for (
size_t pos = 0; pos < mItemsInfo.size(); pos++)
326 if (mButtonAutoWidth)
329 width = mButtonDefaultWidth;
331 mWidthBar += width - mItemsInfo[pos].width;
332 mItemsInfo[pos].width = width;
344 if (mButtonAutoWidth)
347 _width = mButtonDefaultWidth;
350 mWidthBar += _width - mItemsInfo[_index].width;
351 mItemsInfo[_index].width = _width;
359 mItemsInfo[_index].name = _name;
362 if (mButtonAutoWidth)
365 width = mButtonDefaultWidth;
367 mWidthBar += width - mItemsInfo[_index].width;
368 mItemsInfo[_index].width = width;
376 if (mIndexSelect == _index)
378 size_t old = mIndexSelect;
379 mIndexSelect = _index;
386 _showItem(mItemsInfo[mIndexSelect].item,
true, mSmoothShow);
387 _showItem(mItemsInfo[old].item,
false, mSmoothShow);
423 Button* TabControl::createButton()
426 if (mWidgetBar !=
nullptr)
428 else if (mHeaderPlace !=
nullptr)
429 parent = mHeaderPlace;
436 Button* button = createButton();
439 mItemButton.push_back(button);
444 if (mItemButton.empty())
447 UString save = mItemButton[0]->getCaption();
448 mItemButton[0]->setCaption(_text);
454 mItemButton[0]->setCaption(save);
456 return size.
width + mItemButton[0]->getWidth() - coord.
width;
467 mWidthBar -= mItemsInfo[index].width;
468 mItemsInfo.erase(mItemsInfo.begin() + index);
470 if (mItemsInfo.empty())
474 if (index < mIndexSelect)
476 else if (index == mIndexSelect)
478 if (mIndexSelect == mItemsInfo.size())
480 mItemsInfo[mIndexSelect].item->setVisible(
true);
481 mItemsInfo[mIndexSelect].item->setAlpha(
ALPHA_MAX);
491 _index = mItemsInfo.size();
494 int width = (mButtonAutoWidth ?
_getTextWidth(_name) : mButtonDefaultWidth);
497 mItemsInfo.insert(mItemsInfo.begin() + _index,
TabItemInfo(width, _name, _sheet, _data));
500 if (1 == mItemsInfo.size())
505 if (_index <= mIndexSelect)
515 mItemsInfo[_index].data = _data;
521 return mItemsInfo[_index].width;
527 return mItemsInfo[_index].name;
533 return mItemsInfo[_index].item;
544 while (!mItemsInfo.empty())
550 ControllerFadeAlpha* TabControl::createControllerFadeAlpha(
float _alpha,
float _coef,
bool _enable)
564 for (
size_t pos = 0; pos < mItemsInfo.size(); pos++)
566 if (mItemsInfo[pos].item == _item)
569 MYGUI_EXCEPT(
"item (" << _item <<
") not found, source 'TabControl::getItemIndex'");
574 for (
size_t pos = 0; pos < mItemsInfo.size(); pos++)
576 if (mItemsInfo[pos].item == _item)
584 for (
size_t pos = 0; pos < mItemsInfo.size(); pos++)
586 if (mItemsInfo[pos].name == _name)
594 for (
size_t pos = 0; pos < mItemsInfo.size(); pos++)
596 if (mItemsInfo[pos].name == _name)
597 return mItemsInfo[pos].item;
607 Widget* TabControl::_getWidgetTemplate()
609 return mItemTemplate ==
nullptr ? this : mItemTemplate;
612 Widget* TabControl::_getWidgetBar()
614 return mWidgetBar ==
nullptr ? this : mWidgetBar;
620 if (_key ==
"ButtonWidth")
624 else if (_key ==
"ButtonAutoWidth")
628 else if (_key ==
"SmoothShow")
632 else if (_key ==
"SelectItem")
637 Base::setPropertyOverride(_key, _value);
646 return mItemsInfo.size();
734 return mButtonDefaultWidth;
739 return mButtonAutoWidth;
744 mSmoothShow = _value;
784 if (mHeaderPlace !=
nullptr)
790 void TabControl::updateBarOld()
793 if (_getWidgetBar()->
getWidth() < 1)
796 if ((_getWidgetBar()->
getWidth() < mWidthBar) && (1 < mItemsInfo.size()))
802 if (
nullptr != mButtonLeft)
804 if (
nullptr != mButtonRight)
806 if (
nullptr != mButtonDecor)
808 for (VectorWidgetPtr::iterator iter = mWidgetsPatch.begin(); iter != mWidgetsPatch.end(); ++iter)
809 (*iter)->setVisible(
true);
810 if (mWidgetBar !=
nullptr)
819 if (
nullptr != mButtonLeft)
821 if (
nullptr != mButtonRight)
823 if (
nullptr != mButtonDecor)
825 for (VectorWidgetPtr::iterator iter = mWidgetsPatch.begin(); iter != mWidgetsPatch.end(); ++iter)
826 (*iter)->setVisible(
false);
827 if (mWidgetBar !=
nullptr)
837 for (
size_t pos = mStartIndex; pos < mItemsInfo.size(); pos++)
838 width += mItemsInfo[pos].width;
841 while ((mStartIndex > 0) && ((width + mItemsInfo[mStartIndex - 1].width) <= _getWidgetBar()->
getWidth()))
844 width += mItemsInfo[mStartIndex].width;
851 size_t pos = mStartIndex;
852 for (; pos < mItemsInfo.size(); pos++)
855 if (width > _getWidgetBar()->
getWidth())
859 TabItemInfo& info = mItemsInfo[pos];
860 if ((width + info.width) > _getWidgetBar()->
getWidth())
866 if (count >= mItemButton.size())
870 Button* button = mItemButton[count]->castType<Button>();
871 button->setVisible(
true);
874 button->setStateSelected(pos == mIndexSelect);
876 if (button->getCaption() != info.name)
877 button->setCaption(info.name);
880 if (coord != button->getCoord())
881 button->setCoord(coord);
888 while (count < mItemButton.size())
890 mItemButton[count]->setVisible(
false);
895 if (pos == mItemsInfo.size())
899 if (mEmptyBarWidget !=
nullptr)
902 if (width < _getWidgetBar()->
getWidth())
914 if (mStartIndex == 0)
916 if (
nullptr != mButtonLeft)
921 if (
nullptr != mButtonLeft)
927 if (
nullptr != mButtonRight)
932 if (
nullptr != mButtonRight)
937 void TabControl::updateBarNew()
939 if (mHeaderPlace ==
nullptr)
946 int widthControls = 0;
947 if (mControls !=
nullptr)
948 widthControls = mControls->
getWidth();
950 if ((mHeaderPlace->
getWidth() < mWidthBar) && (1 < mItemsInfo.size()) && (mHeaderPlace->
getWidth() >= widthControls))
956 if (
nullptr != mControls)
960 if (mControls !=
nullptr)
969 if (
nullptr != mControls)
981 for (
size_t pos = mStartIndex; pos < mItemsInfo.size(); pos++)
982 width += mItemsInfo[pos].width;
985 while ((mStartIndex > 0) && ((width + mItemsInfo[mStartIndex - 1].width) <= (mHeaderPlace->
getWidth() - widthControls)))
988 width += mItemsInfo[mStartIndex].width;
995 size_t pos = mStartIndex;
996 for (; pos < mItemsInfo.size(); pos++)
999 if (width > (mHeaderPlace->
getWidth() - widthControls))
1003 TabItemInfo& info = mItemsInfo[pos];
1004 if ((width + info.width) > (mHeaderPlace->
getWidth() - widthControls))
1010 if (count >= mItemButton.size())
1014 Button* button = mItemButton[count];
1015 button->setVisible(
true);
1018 button->setStateSelected(pos == mIndexSelect);
1020 if (button->getCaption() != info.name)
1021 button->setCaption(info.name);
1024 if (coord != button->getCoord())
1025 button->setCoord(coord);
1027 width += info.width;
1032 while (count < mItemButton.size())
1034 mItemButton[count]->setVisible(
false);
1039 if (pos == mItemsInfo.size())
1042 if (mEmpty !=
nullptr)
1049 if (mStartIndex == 0)
1051 if (
nullptr != mButtonLeft)
1056 if (
nullptr != mButtonLeft)
1062 if (
nullptr != mButtonRight)
1067 if (
nullptr != mButtonRight)
#define MYGUI_EXCEPT(dest)
#define MYGUI_ASSERT_RANGE_INSERT(index, size, owner)
#define MYGUI_ASSERT_RANGE(index, size, owner)
static const std::string & getClassTypeName()
void setAlpha(float _value)
void setCoef(float _value)
void setEnabled(bool _value)
EventPairAddParameter< EventHandle_WidgetPtr, EventHandle_WidgetPtrControllerItemPtr > eventPostAction
ControllerItem * createItem(const std::string &_type)
static ControllerManager & getInstance()
void removeItem(Widget *_widget)
void addItem(Widget *_widget, ControllerItem *_item)
int getAbsoluteLeft() const
const IntCoord & getCoord() const
int getAbsoluteTop() const
Type * castType(bool _throw=true)
virtual IntSize getTextSize() const
EventPair< EventHandle_WidgetSizeT, EventHandle_TabPtrSizeT > eventTabChangeSelect
void setItemNameAt(size_t _index, const UString &_name)
Replace an item name at a specified position.
int _getTextWidth(const UString &_text)
void setButtonWidthAt(size_t _index, int _width=DEFAULT)
Set button width at a specified position.
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)
int getButtonDefaultWidth() const
void beginToItemSelected()
Move all elements so selected becomes visible.
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 beginToItemFirst()
Move all elements so first becomes visible.
void _notifyDeleteItem(TabItem *_item)
void beginToItemLast()
Move all elements so last becomes visible.
void onWidgetCreated(Widget *_widget) override
void removeAllItems()
Remove all items.
void setSmoothShow(bool _value)
void _insertItem(size_t _index, const UString &_name, TabItem *_sheet, Any _data)
size_t getItemCount() const
Get number of items.
void beginToItem(const TabItem *_item)
Move all elements so specified becomes visible.
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.
void setCoord(const IntCoord &_value) override
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 setPosition(const IntPoint &_value) override
void shutdownOverride() override
void setButtonWidth(TabItem *_item, int _width=DEFAULT)
Set button width.
void _addItem(const MyGUI::UString &_name) override
void setIndexSelected(size_t _index)
Select specified _index.
void setItemName(TabItem *_item, const UString &_name)
Replace an item name.
void _removeItemAt(size_t _index) override
size_t getItemIndex(const TabItem *_item) const
Get item index.
void setSize(const IntSize &_value) override
int getButtonWidth(TabItem *_item) const
Get button width.
Widget * _getItemAt(size_t _index) const override
void removeItemAt(size_t _index)
Remove item at a specified position.
void beginToItemAt(size_t _index)
Move all elements so specified becomes visible.
void clearItemData(TabItem *_item)
Clear an item data.
void notifyPressedBarButtonEvent(MyGUI::Widget *_sender)
void setButtonAutoWidth(bool _value)
const UString & getItemNameAt(size_t _index) const
Get item name from specified position.
void setItemData(TabItem *_item, Any _data)
Replace an item data.
bool getSmoothShow() const
void setPropertyOverride(const std::string &_key, const std::string &_value) override
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.
int getButtonWidthAt(size_t _index) const
Get button width at a specified position.
void _showItem(TabItem *_sheet, bool _show, bool _smooth)
bool getButtonAutoWidth() const
TabItem * getItemAt(size_t _index) const
Get item from specified position.
const UString & getItemName(const TabItem *_item) const
Get item name.
void setButtonDefaultWidth(int _value)
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)
widget description should be here.
static const std::string & getClassTypeName()
A UTF-16 string with implicit conversion to/from std::string and std::wstring.
bool isUserString(const std::string &_key) const
void _setInternalData(Any _data)
const std::string & getUserString(const std::string &_key) const
ValueType * _getInternalData(bool _throw=true) const
const float TAB_SPEED_FADE_COEF
types::TCoord< int > IntCoord
types::TSize< int > IntSize
delegates::DelegateFunction< Args... > * newDelegate(void(*_func)(Args... args))