20 void TabControl::initialiseOverride()
22 Base::initialiseOverride();
24 if (isUserString(
"ButtonSkin"))
25 mButtonSkinName = getUserString(
"ButtonSkin");
28 if (isUserString(
"OffsetBar"))
32 if (isUserString(
"EmptyBarSkin"))
33 mEmptySkinName = getUserString(
"EmptyBarSkin");
36 assignWidget(mWidgetBar,
"Bar");
37 if (mWidgetBar !=
nullptr)
39 mWidgetBar->setSize(mWidgetBar->getWidth() - mOffsetTab, mWidgetBar->getHeight());
43 assignWidget(mButtonLeft,
"Left");
44 if (mButtonLeft !=
nullptr)
46 mButtonLeft->eventMouseButtonClick +=
newDelegate(
this, &TabControl::notifyPressedButtonEvent);
50 assignWidget(mButtonRight,
"Right");
51 if (mButtonRight !=
nullptr)
53 mButtonRight->eventMouseButtonClick +=
newDelegate(
this, &TabControl::notifyPressedButtonEvent);
57 assignWidget(mButtonDecor,
"ButtonDecor");
58 if (mButtonDecor !=
nullptr)
60 mButtonDecor->setVisible(
false);
64 assignWidget(mItemTemplate,
"TabItem");
65 if (mItemTemplate !=
nullptr)
67 mItemTemplate->setVisible(
false);
70#ifndef MYGUI_DONT_USE_OBSOLETE
71 if (mItemTemplate ==
nullptr)
73 assignWidget(mItemTemplate,
"Sheet");
74 if (mItemTemplate !=
nullptr)
76 mItemTemplate->setVisible(
false);
82 Widget* showPatch =
nullptr;
83 assignWidget(showPatch,
"ShowPatch");
84 if (showPatch !=
nullptr)
86 mWidgetsPatch.push_back(showPatch);
87 showPatch->setVisible(
false);
91 assignWidget(mHeaderPlace,
"HeaderPlace");
94 assignWidget(mControls,
"Controls");
97 assignWidget(mEmpty,
"Empty");
99 if (mEmpty ==
nullptr)
104 _getWidgetBar()->createWidget<Widget>(mEmptySkinName,
IntCoord(), Align::Left | Align::Top);
113 void TabControl::shutdownOverride()
115 mWidgetsPatch.clear();
116 mWidgetBar =
nullptr;
117 mButtonLeft =
nullptr;
118 mButtonRight =
nullptr;
119 mButtonDecor =
nullptr;
120 mItemTemplate =
nullptr;
121 mEmptyBarWidget =
nullptr;
123 mHeaderPlace =
nullptr;
130 Base::shutdownOverride();
133 void TabControl::onWidgetCreated(Widget* _widget)
135 Base::onWidgetCreated(_widget);
137 TabItem* child = _widget->castType<TabItem>(
false);
138 if (child !=
nullptr)
141 _getWidgetTemplate()->getAbsoluteLeft() - getAbsoluteLeft(),
142 _getWidgetTemplate()->getAbsoluteTop() - getAbsoluteTop(),
143 _getWidgetTemplate()->getWidth(),
144 _getWidgetTemplate()->getHeight());
145 child->setAlign(_getWidgetTemplate()->getAlign());
147 _insertItem(
ITEM_NONE, UString(), child, Any::Null);
151 TabItem* TabControl::insertItemAt(
size_t _index,
const UString& _name, Any _data)
155 Widget* widget = Base::baseCreateWidget(
157 TabItem::getClassTypeName(),
159 _getWidgetTemplate()->getCoord(),
160 _getWidgetTemplate()->getAlign(),
165 size_t lastIndex = mItemsInfo.size() - 1;
166 setItemNameAt(lastIndex, _name);
167 setItemDataAt(lastIndex, _data);
169 swapItems(_index ==
ITEM_NONE ? lastIndex : _index, lastIndex);
171 return widget->castType<TabItem>();
174 void TabControl::swapItems(
size_t _index1,
size_t _index2)
179 if (_index1 != _index2)
181 std::swap(mItemsInfo[_index1], mItemsInfo[_index2]);
186 void TabControl::setPosition(
const IntPoint& _point)
188 Base::setPosition(_point);
193 void TabControl::setSize(
const IntSize& _size)
195 Base::setSize(_size);
200 void TabControl::setCoord(
const IntCoord& _coord)
202 Base::setCoord(_coord);
207 void TabControl::notifyPressedButtonEvent(MyGUI::Widget* _sender)
209 if (_sender == mButtonLeft)
217 else if (_sender == mButtonRight)
219 if ((mStartIndex + 1) < mItemsInfo.size())
228 void TabControl::notifyPressedBarButtonEvent(MyGUI::Widget* _sender)
230 size_t select = *_sender->_getInternalData<
size_t>() + mStartIndex;
231 if (select == mIndexSelect)
233 beginToItemSelected();
236 size_t old = mIndexSelect;
237 mIndexSelect = select;
240 for (
size_t pos = 0; pos < mItemButton.size(); pos++)
242 Button* button = mItemButton[count]->castType<Button>();
243 if (button->getVisible())
245 button->setStateSelected((pos + mStartIndex) == mIndexSelect);
250 beginToItemSelected();
253 _forcePick(mItemsInfo[mIndexSelect].item);
255 _showItem(mItemsInfo[mIndexSelect].item,
true, mSmoothShow);
256 _showItem(mItemsInfo[old].item,
false, mSmoothShow);
258 eventTabChangeSelect(
this, mIndexSelect);
261 void TabControl::beginToItemAt(
size_t _index)
265 int widthBar = _getWidgetBar()->getWidth();
266 if (mHeaderPlace !=
nullptr)
268 widthBar = mHeaderPlace->getWidth();
269 if (mButtonShow && mControls !=
nullptr)
270 widthBar -= mControls->getWidth();
276 if (_index == mStartIndex)
278 if (_index < mStartIndex)
280 mStartIndex = _index;
287 for (
size_t pos = mStartIndex; pos <= _index; pos++)
289 width += mItemsInfo[pos].width;
294 while ((mStartIndex < _index) && (width > widthBar))
296 width -= mItemsInfo[mStartIndex].width;
305 void TabControl::setButtonDefaultWidth(
int _width)
307 mButtonDefaultWidth = _width;
308 if (mButtonDefaultWidth < 1)
309 mButtonDefaultWidth = 1;
310 setButtonAutoWidth(
false);
313 void TabControl::setButtonAutoWidth(
bool _auto)
315 mButtonAutoWidth = _auto;
317 for (
auto& info : mItemsInfo)
320 if (mButtonAutoWidth)
321 width = _getTextWidth(info.name);
323 width = mButtonDefaultWidth;
325 mWidthBar += width - info.width;
332 void TabControl::setButtonWidthAt(
size_t _index,
int _width)
338 if (mButtonAutoWidth)
339 _width = _getTextWidth(mItemsInfo[_index].name);
341 _width = mButtonDefaultWidth;
344 mWidthBar += _width - mItemsInfo[_index].width;
345 mItemsInfo[_index].width = _width;
350 void TabControl::setItemNameAt(
size_t _index,
const UString& _name)
353 mItemsInfo[_index].name = _name;
356 if (mButtonAutoWidth)
357 width = _getTextWidth(_name);
359 width = mButtonDefaultWidth;
361 mWidthBar += width - mItemsInfo[_index].width;
362 mItemsInfo[_index].width = width;
367 void TabControl::setIndexSelected(
size_t _index)
370 if (mIndexSelect == _index)
372 size_t old = mIndexSelect;
373 mIndexSelect = _index;
378 _forcePick(mItemsInfo[mIndexSelect].item);
380 _showItem(mItemsInfo[mIndexSelect].item,
true, mSmoothShow);
381 _showItem(mItemsInfo[old].item,
false, mSmoothShow);
383 beginToItemSelected();
386 void TabControl::actionWidgetHide(Widget* _widget, ControllerItem* _controller)
388 _widget->setVisible(
false);
389 _widget->setEnabled(
true);
392 void TabControl::_showItem(TabItem* _item,
bool _show,
bool _smooth)
396 ControllerManager::getInstance().removeItem(_item);
399 _item->setVisible(_show);
407 _item->setEnabled(
true);
409 ControllerManager::getInstance().addItem(_item, controller);
414 controller->eventPostAction +=
newDelegate(
this, &TabControl::actionWidgetHide);
415 ControllerManager::getInstance().addItem(_item, controller);
419 Button* TabControl::createButton()
421 Widget* parent =
this;
422 if (mWidgetBar !=
nullptr)
424 else if (mHeaderPlace !=
nullptr)
425 parent = mHeaderPlace;
427 return parent->createWidget<Button>(mButtonSkinName,
IntCoord(), Align::Left | Align::Top);
430 void TabControl::_createItemButton()
432 Button* button = createButton();
433 button->eventMouseButtonClick +=
newDelegate(
this, &TabControl::notifyPressedBarButtonEvent);
434 button->_setInternalData(mItemButton.size());
435 mItemButton.push_back(button);
438 int TabControl::_getTextWidth(
const UString& _text)
440 if (mItemButton.empty())
443 UString save = mItemButton[0]->getCaption();
444 mItemButton[0]->setCaption(_text);
446 ISubWidgetText* text = mItemButton[0]->getSubWidgetText();
450 mItemButton[0]->setCaption(save);
452 return size.width + mItemButton[0]->getWidth() - coord.width;
455 void TabControl::_notifyDeleteItem(TabItem* _sheet)
461 size_t index = getItemIndex(_sheet);
463 mWidthBar -= mItemsInfo[index].width;
464 mItemsInfo.erase(mItemsInfo.begin() + index);
466 if (mItemsInfo.empty())
470 if (index < mIndexSelect)
472 else if (index == mIndexSelect)
474 if (mIndexSelect == mItemsInfo.size())
476 mItemsInfo[mIndexSelect].item->setVisible(
true);
477 mItemsInfo[mIndexSelect].item->setAlpha(
ALPHA_MAX);
484 void TabControl::_insertItem(
size_t _index,
const UString& _name, TabItem* _sheet, Any _data)
487 _index = mItemsInfo.size();
489 int width = (mButtonAutoWidth ? _getTextWidth(_name) : mButtonDefaultWidth);
492 mItemsInfo.insert(mItemsInfo.begin() + _index, TabItemInfo(width, _name, _sheet, _data));
494 if (1 == mItemsInfo.size())
498 _sheet->setVisible(false);
499 if (_index <= mIndexSelect)
506 void TabControl::setItemDataAt(
size_t _index, Any _data)
509 mItemsInfo[_index].data = std::move(_data);
512 int TabControl::getButtonWidthAt(
size_t _index)
const
515 return mItemsInfo[_index].width;
518 const UString& TabControl::getItemNameAt(
size_t _index)
const
521 return mItemsInfo[_index].name;
524 TabItem* TabControl::getItemAt(
size_t _index)
const
527 return mItemsInfo[_index].item;
530 void TabControl::removeItemAt(
size_t _index)
533 this->_destroyChildWidget(mItemsInfo[_index].item);
536 void TabControl::removeAllItems()
538 while (!mItemsInfo.empty())
540 _destroyChildWidget(mItemsInfo.back().item);
544 ControllerFadeAlpha* TabControl::createControllerFadeAlpha(
float _alpha,
float _coef,
bool _enable)
546 ControllerItem* item = ControllerManager::getInstance().createItem(ControllerFadeAlpha::getClassTypeName());
547 ControllerFadeAlpha* controller = item->castType<ControllerFadeAlpha>();
549 controller->setAlpha(_alpha);
550 controller->setCoef(_coef);
551 controller->setEnabled(_enable);
556 size_t TabControl::getItemIndex(
const TabItem* _item)
const
558 for (
size_t pos = 0; pos < mItemsInfo.size(); pos++)
560 if (mItemsInfo[pos].item == _item)
563 MYGUI_EXCEPT(
"item (" << _item <<
") not found, source 'TabControl::getItemIndex'");
566 size_t TabControl::findItemIndex(
const TabItem* _item)
568 for (
size_t pos = 0; pos < mItemsInfo.size(); pos++)
570 if (mItemsInfo[pos].item == _item)
576 size_t TabControl::findItemIndexWith(
const UString& _name)
578 for (
size_t pos = 0; pos < mItemsInfo.size(); pos++)
580 if (mItemsInfo[pos].name == _name)
586 TabItem* TabControl::findItemWith(
const UString& _name)
588 for (
auto& info : mItemsInfo)
590 if (info.name == _name)
596 TabItem* TabControl::getItemSelected()
const
598 return getIndexSelected() !=
ITEM_NONE ? getItemAt(getIndexSelected()) : nullptr;
601 Widget* TabControl::_getWidgetTemplate()
603 return mItemTemplate ==
nullptr ? this : mItemTemplate;
606 Widget* TabControl::_getWidgetBar()
608 return mWidgetBar ==
nullptr ? this : mWidgetBar;
611 void TabControl::setPropertyOverride(std::string_view _key, std::string_view _value)
614 if (_key ==
"ButtonWidth")
618 else if (_key ==
"ButtonAutoWidth")
622 else if (_key ==
"SmoothShow")
625 else if (_key ==
"SelectItem")
630 Base::setPropertyOverride(_key, _value);
634 eventChangeProperty(
this, _key, _value);
637 size_t TabControl::getItemCount()
const
639 return mItemsInfo.size();
642 TabItem* TabControl::insertItem(TabItem* _to,
const UString& _name, Any _data)
644 return insertItemAt(getItemIndex(_to), _name, _data);
647 TabItem* TabControl::addItem(
const UString& _name, Any _data)
649 return insertItemAt(
ITEM_NONE, _name, _data);
652 void TabControl::removeItem(TabItem* _item)
654 removeItemAt(getItemIndex(_item));
657 size_t TabControl::getIndexSelected()
const
662 void TabControl::setItemSelected(TabItem* _item)
664 setIndexSelected(getItemIndex(_item));
667 void TabControl::setItemData(TabItem* _item, Any _data)
669 setItemDataAt(getItemIndex(_item), _data);
672 void TabControl::clearItemDataAt(
size_t _index)
674 setItemDataAt(_index, Any::Null);
677 void TabControl::clearItemData(TabItem* _item)
679 clearItemDataAt(getItemIndex(_item));
682 void TabControl::setItemName(TabItem* _item,
const UString& _name)
684 setItemNameAt(getItemIndex(_item), _name);
687 const UString& TabControl::getItemName(
const TabItem* _item)
const
689 return getItemNameAt(getItemIndex(_item));
692 void TabControl::beginToItem(
const TabItem* _item)
694 beginToItemAt(getItemIndex(_item));
697 void TabControl::beginToItemFirst()
703 void TabControl::beginToItemLast()
706 beginToItemAt(getItemCount() - 1);
709 void TabControl::beginToItemSelected()
712 beginToItemAt(getIndexSelected());
715 void TabControl::setButtonWidth(TabItem* _item,
int _width)
717 setButtonWidthAt(getItemIndex(_item), _width);
720 int TabControl::getButtonWidth(TabItem* _item)
const
722 return getButtonWidthAt(getItemIndex(_item));
725 int TabControl::getButtonDefaultWidth()
const
727 return mButtonDefaultWidth;
730 bool TabControl::getButtonAutoWidth()
const
732 return mButtonAutoWidth;
735 void TabControl::setSmoothShow(
bool _value)
737 mSmoothShow = _value;
740 bool TabControl::getSmoothShow()
const
745 size_t TabControl::_getItemCount()
const
747 return getItemCount();
750 void TabControl::_addItem(
const MyGUI::UString& _name)
755 void TabControl::_removeItemAt(
size_t _index)
757 removeItemAt(_index);
760 Widget* TabControl::_getItemAt(
size_t _index)
const
762 return getItemAt(_index);
765 void TabControl::_setItemNameAt(
size_t _index,
const UString& _name)
767 setItemNameAt(_index, _name);
770 const UString& TabControl::_getItemNameAt(
size_t _index)
const
772 return getItemNameAt(_index);
775 void TabControl::updateBar()
777 if (mHeaderPlace !=
nullptr)
783 void TabControl::updateBarOld()
785 if (_getWidgetBar()->getWidth() < 1)
788 if ((_getWidgetBar()->getWidth() < mWidthBar) && (1 < mItemsInfo.size()))
794 if (
nullptr != mButtonLeft)
795 mButtonLeft->setVisible(
true);
796 if (
nullptr != mButtonRight)
797 mButtonRight->setVisible(
true);
798 if (
nullptr != mButtonDecor)
799 mButtonDecor->setVisible(
true);
800 for (
auto& iter : mWidgetsPatch)
801 iter->setVisible(
true);
802 if (mWidgetBar !=
nullptr)
803 mWidgetBar->setSize(mWidgetBar->getWidth() - mOffsetTab, mWidgetBar->getHeight());
811 if (
nullptr != mButtonLeft)
812 mButtonLeft->setVisible(
false);
813 if (
nullptr != mButtonRight)
814 mButtonRight->setVisible(
false);
815 if (
nullptr != mButtonDecor)
816 mButtonDecor->setVisible(
false);
817 for (
auto& iter : mWidgetsPatch)
818 iter->setVisible(
false);
819 if (mWidgetBar !=
nullptr)
820 mWidgetBar->setSize(mWidgetBar->getWidth() + mOffsetTab, mWidgetBar->getHeight());
828 for (
size_t pos = mStartIndex; pos < mItemsInfo.size(); pos++)
829 width += mItemsInfo[pos].width;
832 while ((mStartIndex > 0) && ((width + mItemsInfo[mStartIndex - 1].width) <= _getWidgetBar()->getWidth()))
835 width += mItemsInfo[mStartIndex].width;
841 size_t pos = mStartIndex;
842 for (; pos < mItemsInfo.size(); pos++)
844 if (width > _getWidgetBar()->getWidth())
847 TabItemInfo& info = mItemsInfo[pos];
848 if ((width + info.width) > _getWidgetBar()->getWidth())
854 if (count >= mItemButton.size())
857 Button* button = mItemButton[count]->castType<Button>();
858 button->setVisible(
true);
860 button->setStateSelected(pos == mIndexSelect);
862 if (button->getCaption() != info.name)
863 button->setCaption(info.name);
864 IntCoord coord(width, 0, info.width, _getWidgetBar()->getHeight());
865 if (coord != button->getCoord())
866 button->setCoord(coord);
873 while (count < mItemButton.size())
875 mItemButton[count]->setVisible(
false);
880 if (pos == mItemsInfo.size())
884 if (mEmptyBarWidget !=
nullptr)
886 if (width < _getWidgetBar()->getWidth())
888 mEmptyBarWidget->setVisible(
true);
889 mEmptyBarWidget->setCoord(width, 0, _getWidgetBar()->getWidth() - width, _getWidgetBar()->getHeight());
893 mEmptyBarWidget->setVisible(
false);
898 if (mStartIndex == 0)
900 if (
nullptr != mButtonLeft)
901 mButtonLeft->setEnabled(
false);
905 if (
nullptr != mButtonLeft)
906 mButtonLeft->setEnabled(
true);
911 if (
nullptr != mButtonRight)
912 mButtonRight->setEnabled(
true);
916 if (
nullptr != mButtonRight)
917 mButtonRight->setEnabled(
false);
921 void TabControl::updateBarNew()
923 if (mHeaderPlace ==
nullptr)
926 if (mHeaderPlace->getWidth() < 1)
929 int widthControls = 0;
930 if (mControls !=
nullptr)
931 widthControls = mControls->getWidth();
933 if ((mHeaderPlace->getWidth() < mWidthBar) && (1 < mItemsInfo.size()) &&
934 (mHeaderPlace->getWidth() >= widthControls))
940 if (
nullptr != mControls)
941 mControls->setVisible(
true);
944 if (mControls !=
nullptr)
946 mHeaderPlace->getWidth() - mControls->getWidth(),
948 mControls->getWidth(),
949 mHeaderPlace->getHeight());
957 if (
nullptr != mControls)
958 mControls->setVisible(
false);
968 for (
size_t pos = mStartIndex; pos < mItemsInfo.size(); pos++)
969 width += mItemsInfo[pos].width;
972 while ((mStartIndex > 0) &&
973 ((width + mItemsInfo[mStartIndex - 1].width) <= (mHeaderPlace->getWidth() - widthControls)))
976 width += mItemsInfo[mStartIndex].width;
982 size_t pos = mStartIndex;
983 for (; pos < mItemsInfo.size(); pos++)
985 if (width > (mHeaderPlace->getWidth() - widthControls))
988 TabItemInfo& info = mItemsInfo[pos];
989 if ((width + info.width) > (mHeaderPlace->getWidth() - widthControls))
995 if (count >= mItemButton.size())
997 Button* button = mItemButton[count];
998 button->setVisible(
true);
1000 button->setStateSelected(pos == mIndexSelect);
1002 if (button->getCaption() != info.name)
1003 button->setCaption(info.name);
1004 IntCoord coord(width, 0, info.width, mHeaderPlace->getHeight());
1005 if (coord != button->getCoord())
1006 button->setCoord(coord);
1008 width += info.width;
1013 while (count < mItemButton.size())
1015 mItemButton[count]->setVisible(
false);
1020 if (pos == mItemsInfo.size())
1023 if (mEmpty !=
nullptr)
1025 mEmpty->setCoord(width, 0, mHeaderPlace->getWidth() - width - widthControls, mHeaderPlace->getHeight());
1029 if (mStartIndex == 0)
1031 if (
nullptr != mButtonLeft)
1032 mButtonLeft->setEnabled(
false);
1036 if (
nullptr != mButtonLeft)
1037 mButtonLeft->setEnabled(
true);
1042 if (
nullptr != mButtonRight)
1043 mButtonRight->setEnabled(
true);
1047 if (
nullptr != mButtonRight)
1048 mButtonRight->setEnabled(
false);
#define MYGUI_EXCEPT(dest)
#define MYGUI_ASSERT_RANGE_INSERT(index, size, owner)
#define MYGUI_ASSERT_RANGE(index, size, owner)
template MYGUI_EXPORT int parseValue< int >(std::string_view)
T parseValue(std::string_view value)
const float TAB_SPEED_FADE_COEF
constexpr float ALPHA_MAX
types::TPoint< int > IntPoint
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))