37 if (mWidgetBar !=
nullptr)
44 if (mButtonLeft !=
nullptr)
51 if (mButtonRight !=
nullptr)
58 if (mButtonDecor !=
nullptr)
65 if (mItemTemplate !=
nullptr)
70#ifndef MYGUI_DONT_USE_OBSOLETE
71 if (mItemTemplate ==
nullptr)
74 if (mItemTemplate !=
nullptr)
82 Widget* showPatch =
nullptr;
84 if (showPatch !=
nullptr)
86 mWidgetsPatch.push_back(showPatch);
99 if (mEmpty ==
nullptr)
115 mWidgetsPatch.clear();
116 mWidgetBar =
nullptr;
117 mButtonLeft =
nullptr;
118 mButtonRight =
nullptr;
119 mButtonDecor =
nullptr;
120 mItemTemplate =
nullptr;
121 mEmptyBarWidget =
nullptr;
123 mHeaderPlace =
nullptr;
138 if (child !=
nullptr)
165 size_t lastIndex = mItemsInfo.size() - 1;
179 if (_index1 != _index2)
181 std::swap(mItemsInfo[_index1], mItemsInfo[_index2]);
209 if (_sender == mButtonLeft)
217 else if (_sender == mButtonRight)
219 if ((mStartIndex + 1) < mItemsInfo.size())
232 if (select == mIndexSelect)
238 size_t old = mIndexSelect;
239 mIndexSelect = select;
242 for (
size_t pos = 0; pos < mItemButton.size(); pos++)
244 Button* button = mItemButton[count]->castType<
Button>();
259 _showItem(mItemsInfo[mIndexSelect].item,
true, mSmoothShow);
260 _showItem(mItemsInfo[old].item,
false, mSmoothShow);
270 if (_getWidgetBar()->
getWidth() < 1)
273 if (_index == mStartIndex)
275 if (_index < mStartIndex)
277 mStartIndex = _index;
284 for (
size_t pos = mStartIndex; pos <= _index; pos++)
286 width += mItemsInfo[pos].width;
291 while ((mStartIndex < _index) && (width > _getWidgetBar()->
getWidth()))
293 width -= mItemsInfo[mStartIndex].width;
304 mButtonDefaultWidth = _width;
305 if (mButtonDefaultWidth < 1)
306 mButtonDefaultWidth = 1;
312 mButtonAutoWidth = _auto;
314 for (
auto& info : mItemsInfo)
317 if (mButtonAutoWidth)
320 width = mButtonDefaultWidth;
322 mWidthBar += width - info.width;
335 if (mButtonAutoWidth)
338 _width = mButtonDefaultWidth;
341 mWidthBar += _width - mItemsInfo[_index].width;
342 mItemsInfo[_index].width = _width;
350 mItemsInfo[_index].name = _name;
353 if (mButtonAutoWidth)
356 width = mButtonDefaultWidth;
358 mWidthBar += width - mItemsInfo[_index].width;
359 mItemsInfo[_index].width = width;
367 if (mIndexSelect == _index)
369 size_t old = mIndexSelect;
370 mIndexSelect = _index;
377 _showItem(mItemsInfo[mIndexSelect].item,
true, mSmoothShow);
378 _showItem(mItemsInfo[old].item,
false, mSmoothShow);
416 Button* TabControl::createButton()
419 if (mWidgetBar !=
nullptr)
421 else if (mHeaderPlace !=
nullptr)
422 parent = mHeaderPlace;
429 Button* button = createButton();
432 mItemButton.push_back(button);
437 if (mItemButton.empty())
440 UString save = mItemButton[0]->getCaption();
441 mItemButton[0]->setCaption(_text);
447 mItemButton[0]->setCaption(save);
449 return size.
width + mItemButton[0]->getWidth() - coord.
width;
460 mWidthBar -= mItemsInfo[index].width;
461 mItemsInfo.erase(mItemsInfo.begin() + index);
463 if (mItemsInfo.empty())
467 if (index < mIndexSelect)
469 else if (index == mIndexSelect)
471 if (mIndexSelect == mItemsInfo.size())
473 mItemsInfo[mIndexSelect].item->setVisible(
true);
474 mItemsInfo[mIndexSelect].item->setAlpha(
ALPHA_MAX);
484 _index = mItemsInfo.size();
487 int width = (mButtonAutoWidth ?
_getTextWidth(_name) : mButtonDefaultWidth);
490 mItemsInfo.insert(mItemsInfo.begin() + _index,
TabItemInfo(width, _name, _sheet, _data));
493 if (1 == mItemsInfo.size())
498 if (_index <= mIndexSelect)
508 mItemsInfo[_index].data = std::move(_data);
514 return mItemsInfo[_index].width;
520 return mItemsInfo[_index].name;
526 return mItemsInfo[_index].item;
537 while (!mItemsInfo.empty())
543 ControllerFadeAlpha* TabControl::createControllerFadeAlpha(
float _alpha,
float _coef,
bool _enable)
557 for (
size_t pos = 0; pos < mItemsInfo.size(); pos++)
559 if (mItemsInfo[pos].item == _item)
562 MYGUI_EXCEPT(
"item (" << _item <<
") not found, source 'TabControl::getItemIndex'");
567 for (
size_t pos = 0; pos < mItemsInfo.size(); pos++)
569 if (mItemsInfo[pos].item == _item)
577 for (
size_t pos = 0; pos < mItemsInfo.size(); pos++)
579 if (mItemsInfo[pos].name == _name)
587 for (
auto& info : mItemsInfo)
589 if (info.name == _name)
600 Widget* TabControl::_getWidgetTemplate()
602 return mItemTemplate ==
nullptr ? this : mItemTemplate;
605 Widget* TabControl::_getWidgetBar()
607 return mWidgetBar ==
nullptr ? this : mWidgetBar;
613 if (_key ==
"ButtonWidth")
617 else if (_key ==
"ButtonAutoWidth")
621 else if (_key ==
"SmoothShow")
625 else if (_key ==
"SelectItem")
639 return mItemsInfo.size();
727 return mButtonDefaultWidth;
732 return mButtonAutoWidth;
737 mSmoothShow = _value;
777 if (mHeaderPlace !=
nullptr)
783 void TabControl::updateBarOld()
786 if (_getWidgetBar()->
getWidth() < 1)
789 if ((_getWidgetBar()->
getWidth() < mWidthBar) && (1 < mItemsInfo.size()))
795 if (
nullptr != mButtonLeft)
797 if (
nullptr != mButtonRight)
799 if (
nullptr != mButtonDecor)
801 for (
auto& iter : mWidgetsPatch)
802 iter->setVisible(
true);
803 if (mWidgetBar !=
nullptr)
812 if (
nullptr != mButtonLeft)
814 if (
nullptr != mButtonRight)
816 if (
nullptr != mButtonDecor)
818 for (
auto& iter : mWidgetsPatch)
819 iter->setVisible(
false);
820 if (mWidgetBar !=
nullptr)
830 for (
size_t pos = mStartIndex; pos < mItemsInfo.size(); pos++)
831 width += mItemsInfo[pos].width;
834 while ((mStartIndex > 0) && ((width + mItemsInfo[mStartIndex - 1].width) <= _getWidgetBar()->
getWidth()))
837 width += mItemsInfo[mStartIndex].width;
844 size_t pos = mStartIndex;
845 for (; pos < mItemsInfo.size(); pos++)
848 if (width > _getWidgetBar()->
getWidth())
852 TabItemInfo& info = mItemsInfo[pos];
853 if ((width + info.width) > _getWidgetBar()->
getWidth())
859 if (count >= mItemButton.size())
863 Button* button = mItemButton[count]->castType<Button>();
864 button->setVisible(
true);
867 button->setStateSelected(pos == mIndexSelect);
869 if (button->getCaption() != info.name)
870 button->setCaption(info.name);
873 if (coord != button->getCoord())
874 button->setCoord(coord);
881 while (count < mItemButton.size())
883 mItemButton[count]->setVisible(
false);
888 if (pos == mItemsInfo.size())
892 if (mEmptyBarWidget !=
nullptr)
895 if (width < _getWidgetBar()->
getWidth())
907 if (mStartIndex == 0)
909 if (
nullptr != mButtonLeft)
914 if (
nullptr != mButtonLeft)
920 if (
nullptr != mButtonRight)
925 if (
nullptr != mButtonRight)
930 void TabControl::updateBarNew()
932 if (mHeaderPlace ==
nullptr)
939 int widthControls = 0;
940 if (mControls !=
nullptr)
941 widthControls = mControls->
getWidth();
943 if ((mHeaderPlace->
getWidth() < mWidthBar) && (1 < mItemsInfo.size()) &&
944 (mHeaderPlace->
getWidth() >= widthControls))
950 if (
nullptr != mControls)
954 if (mControls !=
nullptr)
967 if (
nullptr != mControls)
979 for (
size_t pos = mStartIndex; pos < mItemsInfo.size(); pos++)
980 width += mItemsInfo[pos].width;
983 while ((mStartIndex > 0) &&
984 ((width + mItemsInfo[mStartIndex - 1].width) <= (mHeaderPlace->
getWidth() - widthControls)))
987 width += mItemsInfo[mStartIndex].width;
994 size_t pos = mStartIndex;
995 for (; pos < mItemsInfo.size(); pos++)
998 if (width > (mHeaderPlace->
getWidth() - widthControls))
1002 TabItemInfo& info = mItemsInfo[pos];
1003 if ((width + info.width) > (mHeaderPlace->
getWidth() - widthControls))
1009 if (count >= mItemButton.size())
1013 Button* button = mItemButton[count];
1014 button->setVisible(
true);
1017 button->setStateSelected(pos == mIndexSelect);
1019 if (button->getCaption() != info.name)
1020 button->setCaption(info.name);
1023 if (coord != button->getCoord())
1024 button->setCoord(coord);
1026 width += info.width;
1031 while (count < mItemButton.size())
1033 mItemButton[count]->setVisible(
false);
1038 if (pos == mItemsInfo.size())
1041 if (mEmpty !=
nullptr)
1048 if (mStartIndex == 0)
1050 if (
nullptr != mButtonLeft)
1055 if (
nullptr != mButtonLeft)
1061 if (
nullptr != mButtonRight)
1066 if (
nullptr != mButtonRight)
#define MYGUI_EXCEPT(dest)
#define MYGUI_ASSERT_RANGE_INSERT(index, size, owner)
#define MYGUI_ASSERT_RANGE(index, size, owner)
static std::string_view getClassTypeName()
void setAlpha(float _value)
void setCoef(float _value)
void setEnabled(bool _value)
EventPairAddParameter< EventHandle_WidgetPtr, EventHandle_WidgetPtrControllerItemPtr > eventPostAction
ControllerItem * createItem(std::string_view _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 _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 setButtonWidth(TabItem *_item, int _width=DEFAULT_WIDTH)
Set button width.
int getButtonDefaultWidth() const
void beginToItemSelected()
Move all elements so selected becomes visible.
void setButtonDefaultWidth(int _width)
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 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)
void setSize(const IntSize &_size) override
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 setButtonWidthAt(size_t _index, int _width=DEFAULT_WIDTH)
Set button width at a specified position.
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)
void setButtonAutoWidth(bool _auto)
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 setItemName(TabItem *_item, const UString &_name)
Replace an item name.
void _removeItemAt(size_t _index) override
void _showItem(TabItem *_item, bool _show, bool _smooth)
size_t getItemIndex(const TabItem *_item) const
Get item index.
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 setPosition(const IntPoint &_point) override
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 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.
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 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.
static std::string_view getClassTypeName()
A UTF-16 string with implicit conversion to/from std::string and std::wstring.
bool isUserString(std::string_view _key) const
std::string_view getUserString(std::string_view _key) const
void _setInternalData(Any _data)
ValueType * _getInternalData(bool _throw=true) const
T parseValue(std::string_view _value)
const float TAB_SPEED_FADE_COEF
constexpr float ALPHA_MAX
constexpr float ALPHA_MIN
constexpr size_t ITEM_NONE
types::TCoord< int > IntCoord
types::TSize< int > IntSize
delegates::DelegateFunction< Args... > * newDelegate(void(*_func)(Args... args))