49 mButtonDefaultWidth(1),
51 mButtonAutoWidth(true),
58 Base::_initialise(_style, _coord, _align, _info, _parent, _croppedParent, _creator, _name);
60 initialiseWidgetSkin(_info);
73 initialiseWidgetSkin(_info);
80 if (!properties.empty())
82 MapString::const_iterator iter = properties.find(
"OffsetBar");
85 iter = properties.find(
"ButtonSkin");
86 if (iter != properties.end()) mButtonSkinName = iter->second;
87 iter = properties.find(
"EmptyBarSkin");
88 if (iter != properties.end()) mEmptySkinName = iter->second;
93 if (*(*iter)->_getInternalData<std::string>() ==
"Bar")
98 else if (*(*iter)->_getInternalData<std::string>() ==
"Left")
101 mButtonLeft = (*iter)->
castType<Button>();
105 else if (*(*iter)->_getInternalData<std::string>() ==
"Right")
108 mButtonRight = (*iter)->
castType<Button>();
112 else if (*(*iter)->_getInternalData<std::string>() ==
"List")
115 mButtonList = (*iter)->
castType<Button>();
119 else if (*(*iter)->_getInternalData<std::string>() ==
"ButtonDecor")
122 mButtonDecor = *iter;
125 else if (*(*iter)->_getInternalData<std::string>() ==
"ShowPatch")
127 mWidgetsPatch.push_back((*iter));
128 (*iter)->setVisible(
false);
130 else if ((*(*iter)->_getInternalData<std::string>() ==
"Sheet") || (*(*iter)->_getInternalData<std::string>() ==
"TabItem"))
133 mItemTemplate = (*iter);
146 void Tab::shutdownWidgetSkin()
148 mWidgetsPatch.clear();
149 mWidgetBar =
nullptr;
150 mButtonLeft =
nullptr;
151 mButtonRight =
nullptr;
152 mButtonList =
nullptr;
153 mButtonDecor =
nullptr;
154 mItemTemplate =
nullptr;
155 mEmptyBarWidget =
nullptr;
206 if (_getWidgetBar()->
getWidth() < 1)
return;
208 if ((_getWidgetBar()->
getWidth() < mWidthBar) && (1 < mItemsInfo.size()))
213 if (
nullptr != mButtonLeft) mButtonLeft->
setVisible(
true);
214 if (
nullptr != mButtonRight) mButtonRight->
setVisible(
true);
215 if (
nullptr != mButtonList) mButtonList->
setVisible(
true);
216 if (
nullptr != mButtonDecor) mButtonDecor->
setVisible(
true);
217 for (VectorWidgetPtr::iterator iter=mWidgetsPatch.begin(); iter!=mWidgetsPatch.end(); ++iter) (*iter)->setVisible(
true);
218 if (mWidgetBar !=
nullptr)
227 if (
nullptr != mButtonLeft) mButtonLeft->
setVisible(
false);
228 if (
nullptr != mButtonRight) mButtonRight->
setVisible(
false);
229 if (
nullptr != mButtonList) mButtonList->
setVisible(
false);
230 if (
nullptr != mButtonDecor) mButtonDecor->
setVisible(
false);
231 for (VectorWidgetPtr::iterator iter=mWidgetsPatch.begin(); iter!=mWidgetsPatch.end(); ++iter) (*iter)->setVisible(
false);
232 if (mWidgetBar !=
nullptr)
242 for (
size_t pos=mStartIndex; pos<mItemsInfo.size(); pos++) width += mItemsInfo[pos].width;
245 while ((mStartIndex > 0) && ((width + mItemsInfo[mStartIndex-1].width) <= _getWidgetBar()->
getWidth()))
248 width += mItemsInfo[mStartIndex].width;
255 size_t pos=mStartIndex;
256 for (; pos<mItemsInfo.size(); pos++)
259 if (width > _getWidgetBar()->
getWidth())
break;
272 Button* button = mItemButton[count]->castType<
Button>();
290 while (count < mItemButton.size())
292 mItemButton[count]->setVisible(
false);
297 if (pos == mItemsInfo.size()) right =
false;
300 if (width < _getWidgetBar()->
getWidth())
311 if (mStartIndex == 0)
313 if (
nullptr != mButtonLeft) mButtonLeft->
setEnabled(
false);
317 if (
nullptr != mButtonLeft) mButtonLeft->
setEnabled(
true);
322 if (
nullptr != mButtonRight) mButtonRight->
setEnabled(
true);
326 if (
nullptr != mButtonRight) mButtonRight->
setEnabled(
false);
333 if (_sender == mButtonLeft)
341 else if (_sender == mButtonRight)
343 if ((mStartIndex+1) < mItemsInfo.size())
350 else if (_sender == mButtonList)
359 if (select == mIndexSelect)
365 size_t old = mIndexSelect;
366 mIndexSelect = select;
369 for (
size_t pos=0; pos<mItemButton.size(); pos++)
371 Button* button = mItemButton[count]->castType<
Button>();
386 _showItem(mItemsInfo[mIndexSelect].item,
true, mSmoothShow);
387 _showItem(mItemsInfo[old].item,
false, mSmoothShow);
397 if (_getWidgetBar()->
getWidth() < 1)
return;
399 if (_index == mStartIndex)
return;
400 else if (_index < mStartIndex)
402 mStartIndex = _index;
409 for (
size_t pos=mStartIndex; pos<=_index; pos++)
411 width += mItemsInfo[pos].width;
416 while ((mStartIndex < _index) && (width > _getWidgetBar()->
getWidth()))
418 width -= mItemsInfo[mStartIndex].width;
429 mButtonDefaultWidth = _width;
430 if (mButtonDefaultWidth < 1) mButtonDefaultWidth = 1;
436 mButtonAutoWidth = _auto;
438 for (
size_t pos=0; pos<mItemsInfo.size(); pos++)
441 if (mButtonAutoWidth) width =
_getTextWidth(mItemsInfo[pos].name);
442 else width = mButtonDefaultWidth;
444 mWidthBar += width - mItemsInfo[pos].width;
445 mItemsInfo[pos].width = width;
457 if (mButtonAutoWidth) _width =
_getTextWidth(mItemsInfo[_index].name);
458 else _width = mButtonDefaultWidth;
461 mWidthBar += _width - mItemsInfo[_index].width;
462 mItemsInfo[_index].width = _width;
470 mItemsInfo[_index].name = _name;
474 else width = mButtonDefaultWidth;
476 mWidthBar += width - mItemsInfo[_index].width;
477 mItemsInfo[_index].width = width;
485 if (mIndexSelect == _index)
return;
486 size_t old = mIndexSelect;
487 mIndexSelect = _index;
491 if (mSmoothShow)
_forcePeek(mItemsInfo[mIndexSelect].item);
493 _showItem(mItemsInfo[mIndexSelect].item,
true, mSmoothShow);
494 _showItem(mItemsInfo[old].item,
false, mSmoothShow);
499 void Tab::actionWidgetHide(
Widget* _widget)
535 mItemButton.push_back(button);
542 UString save = mItemButton[0]->getCaption();
543 mItemButton[0]->setCaption(_text);
549 mItemButton[0]->setCaption(save);
551 return size.
width + mItemButton[0]->getWidth() - coord.
width;
557 if (mShutdown)
return;
561 mWidthBar -= mItemsInfo[index].width;
562 mItemsInfo.erase(mItemsInfo.begin() + index);
564 if (0 == mItemsInfo.size()) mIndexSelect =
ITEM_NONE;
567 if (index < mIndexSelect) mIndexSelect --;
568 else if (index == mIndexSelect)
570 if (mIndexSelect == mItemsInfo.size()) mIndexSelect --;
571 mItemsInfo[mIndexSelect].item->setVisible(
true);
572 mItemsInfo[mIndexSelect].item->setAlpha(
ALPHA_MAX);
581 if (_index ==
ITEM_NONE) _index = mItemsInfo.size();
584 int width = (mButtonAutoWidth ?
_getTextWidth(_name) : mButtonDefaultWidth);
587 mItemsInfo.insert(mItemsInfo.begin() + _index,
TabItemInfo(width, _name, _sheet, _data));
590 if (1 == mItemsInfo.size()) mIndexSelect = 0;
594 if (_index <= mIndexSelect) mIndexSelect ++;
603 mItemsInfo[_index].data = _data;
609 return mItemsInfo[_index].width;
615 return mItemsInfo[_index].name;
621 return mItemsInfo[_index].item;
632 while (mItemsInfo.size() > 0)
638 ControllerFadeAlpha* Tab::createControllerFadeAlpha(
float _alpha,
float _coef,
bool _enable)
652 for (
size_t pos=0; pos<mItemsInfo.size(); pos++)
654 if (mItemsInfo[pos].item == _item)
return pos;
656 MYGUI_EXCEPT(
"item (" << _item <<
") not found, source 'Tab::getItemIndex'");
661 for (
size_t pos=0; pos<mItemsInfo.size(); pos++)
663 if (mItemsInfo[pos].item == _item)
return pos;
670 for (
size_t pos=0; pos<mItemsInfo.size(); pos++)
672 if (mItemsInfo[pos].name == _name)
return pos;
679 for (
size_t pos=0; pos<mItemsInfo.size(); pos++)
681 if (mItemsInfo[pos].name == _name)
return mItemsInfo[pos].item;
694 else if (_key ==
"Tab_ButtonAutoWidth")
setButtonAutoWidth(utility::parseValue<bool>(_value));
695 else if (_key ==
"Tab_SmoothShow")
setSmoothShow(utility::parseValue<bool>(_value));
696 else if (_key ==
"Tab_AddItem")
addItem(_value);
697 else if (_key ==
"Tab_SelectItem")
setIndexSelected(utility::parseValue<size_t>(_value));
699 #ifndef MYGUI_DONT_USE_OBSOLETE
700 else if (_key ==
"Tab_AddSheet")
702 MYGUI_LOG(Warning,
"Tab_AddSheet is obsolete, use Tab_AddItem");
705 else if (_key ==
"Tab_SelectSheet")
707 MYGUI_LOG(Warning,
"Tab_SelectSheet is obsolete, use Tab_SelectItem");
710 #endif // MYGUI_DONT_USE_OBSOLETE
720 Widget* Tab::_getWidgetTemplate()
722 return mItemTemplate ==
nullptr ?
this : mItemTemplate;
725 Widget* Tab::_getWidgetBar()
727 return mWidgetBar ==
nullptr ?
this : mWidgetBar;