MyGUI_TabControl.cpp
Go to the documentation of this file.
/*
* This source file is part of MyGUI. For the latest info, see http://mygui.info/
* Distributed under the MIT License
* (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
*/
#include "MyGUI_Precompiled.h"
#include "MyGUI_TabControl.h"
#include "MyGUI_ControllerManager.h"
#include "MyGUI_WidgetManager.h"
#include "MyGUI_Button.h"
#include "MyGUI_TabItem.h"
#include "MyGUI_ResourceSkin.h"
namespace MyGUI
{
const float TAB_SPEED_FADE_COEF = 5.0f;
void TabControl::initialiseOverride()
{
Base::initialiseOverride();
if (isUserString("ButtonSkin"))
mButtonSkinName = getUserString("ButtonSkin");
// OBSOLETE
if (isUserString("OffsetBar"))
mOffsetTab = utility::parseValue<int>(getUserString("OffsetBar"));
// OBSOLETE
if (isUserString("EmptyBarSkin"))
mEmptySkinName = getUserString("EmptyBarSkin");
// OBSOLETE
assignWidget(mWidgetBar, "Bar");
if (mWidgetBar != nullptr)
{
mWidgetBar->setSize(mWidgetBar->getWidth() - mOffsetTab, mWidgetBar->getHeight());
}
assignWidget(mButtonLeft, "Left");
if (mButtonLeft != nullptr)
{
mButtonLeft->eventMouseButtonClick += newDelegate(this, &TabControl::notifyPressedButtonEvent);
}
assignWidget(mButtonRight, "Right");
if (mButtonRight != nullptr)
{
mButtonRight->eventMouseButtonClick += newDelegate(this, &TabControl::notifyPressedButtonEvent);
}
// OBSOLETE
assignWidget(mButtonDecor, "ButtonDecor");
if (mButtonDecor != nullptr)
{
mButtonDecor->setVisible(false);
}
assignWidget(mItemTemplate, "TabItem");
if (mItemTemplate != nullptr)
{
mItemTemplate->setVisible(false);
}
#ifndef MYGUI_DONT_USE_OBSOLETE
if (mItemTemplate == nullptr)
{
assignWidget(mItemTemplate, "Sheet");
if (mItemTemplate != nullptr)
{
mItemTemplate->setVisible(false);
}
}
#endif // MYGUI_DONT_USE_OBSOLETE
// OBSOLETE
Widget* showPatch = nullptr;
assignWidget(showPatch, "ShowPatch");
if (showPatch != nullptr)
{
mWidgetsPatch.push_back(showPatch);
showPatch->setVisible(false);
}
assignWidget(mHeaderPlace, "HeaderPlace");
assignWidget(mControls, "Controls");
assignWidget(mEmpty, "Empty");
if (mEmpty == nullptr)
{
// создаем виджет, носитель скина пустоты бара
// OBSOLETE
mEmptyBarWidget =
_getWidgetBar()->createWidget<Widget>(mEmptySkinName, IntCoord(), Align::Left | Align::Top);
}
updateBar();
// FIXME добавленно, так как шетдаун вызывается и при смене скина
mShutdown = false;
}
void TabControl::shutdownOverride()
{
mWidgetsPatch.clear();
mWidgetBar = nullptr;
mButtonLeft = nullptr;
mButtonRight = nullptr;
mButtonDecor = nullptr;
mItemTemplate = nullptr;
mEmptyBarWidget = nullptr;
mHeaderPlace = nullptr;
mControls = nullptr;
mEmpty = nullptr;
// FIXME перенесенно из деструктора, может косячить при смене скина
mShutdown = true;
Base::shutdownOverride();
}
void TabControl::onWidgetCreated(Widget* _widget)
{
Base::onWidgetCreated(_widget);
TabItem* child = _widget->castType<TabItem>(false);
if (child != nullptr)
{
child->setCoord(
_getWidgetTemplate()->getAbsoluteLeft() - getAbsoluteLeft(),
_getWidgetTemplate()->getAbsoluteTop() - getAbsoluteTop(),
_getWidgetTemplate()->getWidth(),
_getWidgetTemplate()->getHeight());
child->setAlign(_getWidgetTemplate()->getAlign());
_insertItem(ITEM_NONE, UString(), child, Any::Null);
}
}
TabItem* TabControl::insertItemAt(size_t _index, const UString& _name, Any _data)
{
MYGUI_ASSERT_RANGE_INSERT(_index, mItemsInfo.size(), "TabControl::insertItem");
Widget* widget = Base::baseCreateWidget(
WidgetStyle::Child,
TabItem::getClassTypeName(),
"Default",
_getWidgetTemplate()->getCoord(),
_getWidgetTemplate()->getAlign(),
std::string_view{},
std::string_view{},
false);
size_t lastIndex = mItemsInfo.size() - 1;
setItemNameAt(lastIndex, _name);
setItemDataAt(lastIndex, _data);
swapItems(_index == ITEM_NONE ? lastIndex : _index, lastIndex);
return widget->castType<TabItem>();
}
void TabControl::swapItems(size_t _index1, size_t _index2)
{
MYGUI_ASSERT_RANGE(_index1, mItemsInfo.size(), "TabControl::swapItems");
MYGUI_ASSERT_RANGE(_index2, mItemsInfo.size(), "TabControl::swapItems");
if (_index1 != _index2)
{
std::swap(mItemsInfo[_index1], mItemsInfo[_index2]);
updateBar();
}
}
void TabControl::setPosition(const IntPoint& _point)
{
Base::setPosition(_point);
updateBar();
}
void TabControl::setSize(const IntSize& _size)
{
Base::setSize(_size);
updateBar();
}
void TabControl::setCoord(const IntCoord& _coord)
{
Base::setCoord(_coord);
updateBar();
}
void TabControl::notifyPressedButtonEvent(MyGUI::Widget* _sender)
{
if (_sender == mButtonLeft)
{
if (mStartIndex > 0)
{
mStartIndex--;
updateBar();
}
}
else if (_sender == mButtonRight)
{
if ((mStartIndex + 1) < mItemsInfo.size())
{
mStartIndex++;
// в updateBar() будет подкорректированно если что
updateBar();
}
}
}
void TabControl::notifyPressedBarButtonEvent(MyGUI::Widget* _sender)
{
size_t select = *_sender->_getInternalData<size_t>() + mStartIndex;
// щелкнули по той же кнопке
if (select == mIndexSelect)
{
// стараемся показать выделенную кнопку
beginToItemSelected();
return;
}
size_t old = mIndexSelect;
mIndexSelect = select;
size_t count = 0;
for (size_t pos = 0; pos < mItemButton.size(); pos++)
{
Button* button = mItemButton[count]->castType<Button>();
if (button->getVisible())
{
// корректируем нажатость кнопки
button->setStateSelected((pos + mStartIndex) == mIndexSelect);
}
count++;
}
// стараемся показать выделенную кнопку
beginToItemSelected();
// поднимаем страницу для пикинга
_forcePick(mItemsInfo[mIndexSelect].item);
_showItem(mItemsInfo[mIndexSelect].item, true, mSmoothShow);
_showItem(mItemsInfo[old].item, false, mSmoothShow);
eventTabChangeSelect(this, mIndexSelect);
}
void TabControl::beginToItemAt(size_t _index)
{
MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "TabControl::beginToItemAt");
// подстраховка
if (_getWidgetBar()->getWidth() < 1)
return;
if (_index == mStartIndex)
return;
if (_index < mStartIndex)
{
mStartIndex = _index;
updateBar();
}
else
{
// длинна бара от старт индекса до нужной включительно
int width = 0;
for (size_t pos = mStartIndex; pos <= _index; pos++)
{
width += mItemsInfo[pos].width;
}
// уменьшем старт индекс пока не появиться нужная
bool change = false;
while ((mStartIndex < _index) && (width > _getWidgetBar()->getWidth()))
{
width -= mItemsInfo[mStartIndex].width;
mStartIndex++;
change = true;
}
if (change)
updateBar();
}
}
void TabControl::setButtonDefaultWidth(int _width)
{
mButtonDefaultWidth = _width;
if (mButtonDefaultWidth < 1)
mButtonDefaultWidth = 1;
setButtonAutoWidth(false);
}
void TabControl::setButtonAutoWidth(bool _auto)
{
mButtonAutoWidth = _auto;
for (auto& info : mItemsInfo)
{
int width;
if (mButtonAutoWidth)
width = _getTextWidth(info.name);
else
width = mButtonDefaultWidth;
mWidthBar += width - info.width;
info.width = width;
}
updateBar();
}
void TabControl::setButtonWidthAt(size_t _index, int _width)
{
MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "TabControl::setButtonWidthAt");
if (_width <= 0)
{
if (mButtonAutoWidth)
_width = _getTextWidth(mItemsInfo[_index].name);
else
_width = mButtonDefaultWidth;
}
mWidthBar += _width - mItemsInfo[_index].width;
mItemsInfo[_index].width = _width;
updateBar();
}
void TabControl::setItemNameAt(size_t _index, const UString& _name)
{
MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "TabControl::setItemNameAt");
mItemsInfo[_index].name = _name;
int width;
if (mButtonAutoWidth)
width = _getTextWidth(_name);
else
width = mButtonDefaultWidth;
mWidthBar += width - mItemsInfo[_index].width;
mItemsInfo[_index].width = width;
updateBar();
}
void TabControl::setIndexSelected(size_t _index)
{
MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "TabControl::setIndexSelected");
if (mIndexSelect == _index)
return;
size_t old = mIndexSelect;
mIndexSelect = _index;
updateBar();
// поднимаем страницу для пикинга
if (mSmoothShow)
_forcePick(mItemsInfo[mIndexSelect].item);
_showItem(mItemsInfo[mIndexSelect].item, true, mSmoothShow);
_showItem(mItemsInfo[old].item, false, mSmoothShow);
beginToItemSelected();
}
void TabControl::actionWidgetHide(Widget* _widget, ControllerItem* _controller)
{
_widget->setVisible(false);
_widget->setEnabled(true);
}
void TabControl::_showItem(TabItem* _item, bool _show, bool _smooth)
{
if (!_smooth)
{
ControllerManager::getInstance().removeItem(_item);
_item->setAlpha(ALPHA_MAX);
_item->setVisible(_show);
return;
}
if (_show)
{
// enable _item in case actionWidgetHide was skipped due to rapid click
_item->setEnabled(true);
ControllerFadeAlpha* controller = createControllerFadeAlpha(ALPHA_MAX, TAB_SPEED_FADE_COEF, true);
ControllerManager::getInstance().addItem(_item, controller);
}
else
{
ControllerFadeAlpha* controller = createControllerFadeAlpha(ALPHA_MIN, TAB_SPEED_FADE_COEF, false);
controller->eventPostAction += newDelegate(this, &TabControl::actionWidgetHide);
ControllerManager::getInstance().addItem(_item, controller);
}
}
Button* TabControl::createButton()
{
Widget* parent = this;
if (mWidgetBar != nullptr)
parent = mWidgetBar;
else if (mHeaderPlace != nullptr)
parent = mHeaderPlace;
return parent->createWidget<Button>(mButtonSkinName, IntCoord(), Align::Left | Align::Top);
}
void TabControl::_createItemButton()
{
Button* button = createButton();
button->eventMouseButtonClick += newDelegate(this, &TabControl::notifyPressedBarButtonEvent);
button->_setInternalData(mItemButton.size()); // порядковый номер
mItemButton.push_back(button);
}
int TabControl::_getTextWidth(const UString& _text)
{
if (mItemButton.empty())
_createItemButton();
UString save = mItemButton[0]->getCaption();
mItemButton[0]->setCaption(_text);
ISubWidgetText* text = mItemButton[0]->getSubWidgetText();
const IntSize& size = text ? text->getTextSize() : IntSize();
const IntCoord& coord = text ? text->getCoord() : IntCoord();
mItemButton[0]->setCaption(save);
return size.width + mItemButton[0]->getWidth() - coord.width;
}
void TabControl::_notifyDeleteItem(TabItem* _sheet)
{
// общий шутдаун виджета
if (mShutdown)
return;
size_t index = getItemIndex(_sheet);
mWidthBar -= mItemsInfo[index].width;
mItemsInfo.erase(mItemsInfo.begin() + index);
if (mItemsInfo.empty())
mIndexSelect = ITEM_NONE;
else
{
if (index < mIndexSelect)
mIndexSelect--;
else if (index == mIndexSelect)
{
if (mIndexSelect == mItemsInfo.size())
mIndexSelect--;
mItemsInfo[mIndexSelect].item->setVisible(true);
mItemsInfo[mIndexSelect].item->setAlpha(ALPHA_MAX);
}
}
updateBar();
}
void TabControl::_insertItem(size_t _index, const UString& _name, TabItem* _sheet, Any _data)
{
if (_index == ITEM_NONE)
_index = mItemsInfo.size();
// добавляем инфу о вкладке
int width = (mButtonAutoWidth ? _getTextWidth(_name) : mButtonDefaultWidth);
mWidthBar += width;
mItemsInfo.insert(mItemsInfo.begin() + _index, TabItemInfo(width, _name, _sheet, _data));
// первая вкладка
if (1 == mItemsInfo.size())
mIndexSelect = 0;
else
{
_sheet->setVisible(false);
if (_index <= mIndexSelect)
mIndexSelect++;
}
updateBar();
}
void TabControl::setItemDataAt(size_t _index, Any _data)
{
MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "TabControl::setItemDataAt");
mItemsInfo[_index].data = std::move(_data);
}
int TabControl::getButtonWidthAt(size_t _index) const
{
MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "TabControl::getButtonWidthAt");
return mItemsInfo[_index].width;
}
const UString& TabControl::getItemNameAt(size_t _index) const
{
MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "TabControl::getItemNameAt");
return mItemsInfo[_index].name;
}
TabItem* TabControl::getItemAt(size_t _index) const
{
MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "TabControl::getItemAt");
return mItemsInfo[_index].item;
}
void TabControl::removeItemAt(size_t _index)
{
MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "TabControl::removeItemAt");
this->_destroyChildWidget(mItemsInfo[_index].item);
}
void TabControl::removeAllItems()
{
while (!mItemsInfo.empty())
{
_destroyChildWidget(mItemsInfo.back().item);
}
}
ControllerFadeAlpha* TabControl::createControllerFadeAlpha(float _alpha, float _coef, bool _enable)
{
ControllerItem* item = ControllerManager::getInstance().createItem(ControllerFadeAlpha::getClassTypeName());
ControllerFadeAlpha* controller = item->castType<ControllerFadeAlpha>();
controller->setAlpha(_alpha);
controller->setCoef(_coef);
controller->setEnabled(_enable);
return controller;
}
size_t TabControl::getItemIndex(const TabItem* _item) const
{
for (size_t pos = 0; pos < mItemsInfo.size(); pos++)
{
if (mItemsInfo[pos].item == _item)
return pos;
}
MYGUI_EXCEPT("item (" << _item << ") not found, source 'TabControl::getItemIndex'");
}
size_t TabControl::findItemIndex(const TabItem* _item)
{
for (size_t pos = 0; pos < mItemsInfo.size(); pos++)
{
if (mItemsInfo[pos].item == _item)
return pos;
}
return ITEM_NONE;
}
size_t TabControl::findItemIndexWith(const UString& _name)
{
for (size_t pos = 0; pos < mItemsInfo.size(); pos++)
{
if (mItemsInfo[pos].name == _name)
return pos;
}
return ITEM_NONE;
}
TabItem* TabControl::findItemWith(const UString& _name)
{
for (auto& info : mItemsInfo)
{
if (info.name == _name)
return info.item;
}
return nullptr;
}
TabItem* TabControl::getItemSelected() const
{
return getIndexSelected() != ITEM_NONE ? getItemAt(getIndexSelected()) : nullptr;
}
Widget* TabControl::_getWidgetTemplate()
{
return mItemTemplate == nullptr ? this : mItemTemplate;
}
Widget* TabControl::_getWidgetBar()
{
return mWidgetBar == nullptr ? this : mWidgetBar;
}
void TabControl::setPropertyOverride(std::string_view _key, std::string_view _value)
{
if (_key == "ButtonWidth")
setButtonDefaultWidth(utility::parseValue<int>(_value));
else if (_key == "ButtonAutoWidth")
setButtonAutoWidth(utility::parseValue<bool>(_value));
else if (_key == "SmoothShow")
setSmoothShow(utility::parseValue<bool>(_value));
// не коментировать
else if (_key == "SelectItem")
setIndexSelected(utility::parseValue<size_t>(_value));
else
{
Base::setPropertyOverride(_key, _value);
return;
}
eventChangeProperty(this, _key, _value);
}
size_t TabControl::getItemCount() const
{
return mItemsInfo.size();
}
TabItem* TabControl::insertItem(TabItem* _to, const UString& _name, Any _data)
{
return insertItemAt(getItemIndex(_to), _name, _data);
}
TabItem* TabControl::addItem(const UString& _name, Any _data)
{
return insertItemAt(ITEM_NONE, _name, _data);
}
void TabControl::removeItem(TabItem* _item)
{
removeItemAt(getItemIndex(_item));
}
size_t TabControl::getIndexSelected() const
{
return mIndexSelect;
}
void TabControl::setItemSelected(TabItem* _item)
{
setIndexSelected(getItemIndex(_item));
}
void TabControl::setItemData(TabItem* _item, Any _data)
{
setItemDataAt(getItemIndex(_item), _data);
}
void TabControl::clearItemDataAt(size_t _index)
{
setItemDataAt(_index, Any::Null);
}
void TabControl::clearItemData(TabItem* _item)
{
clearItemDataAt(getItemIndex(_item));
}
void TabControl::setItemName(TabItem* _item, const UString& _name)
{
setItemNameAt(getItemIndex(_item), _name);
}
const UString& TabControl::getItemName(const TabItem* _item) const
{
return getItemNameAt(getItemIndex(_item));
}
void TabControl::beginToItem(const TabItem* _item)
{
beginToItemAt(getItemIndex(_item));
}
void TabControl::beginToItemFirst()
{
if (getItemCount())
beginToItemAt(0);
}
void TabControl::beginToItemLast()
{
if (getItemCount())
beginToItemAt(getItemCount() - 1);
}
void TabControl::beginToItemSelected()
{
if (getIndexSelected() != ITEM_NONE)
beginToItemAt(getIndexSelected());
}
void TabControl::setButtonWidth(TabItem* _item, int _width)
{
setButtonWidthAt(getItemIndex(_item), _width);
}
int TabControl::getButtonWidth(TabItem* _item) const
{
return getButtonWidthAt(getItemIndex(_item));
}
int TabControl::getButtonDefaultWidth() const
{
return mButtonDefaultWidth;
}
bool TabControl::getButtonAutoWidth() const
{
return mButtonAutoWidth;
}
void TabControl::setSmoothShow(bool _value)
{
mSmoothShow = _value;
}
bool TabControl::getSmoothShow() const
{
return mSmoothShow;
}
size_t TabControl::_getItemCount() const
{
return getItemCount();
}
void TabControl::_addItem(const MyGUI::UString& _name)
{
addItem(_name);
}
void TabControl::_removeItemAt(size_t _index)
{
removeItemAt(_index);
}
Widget* TabControl::_getItemAt(size_t _index) const
{
return getItemAt(_index);
}
void TabControl::_setItemNameAt(size_t _index, const UString& _name)
{
setItemNameAt(_index, _name);
}
const UString& TabControl::_getItemNameAt(size_t _index) const
{
return getItemNameAt(_index);
}
void TabControl::updateBar()
{
if (mHeaderPlace != nullptr)
updateBarNew();
else
updateBarOld();
}
void TabControl::updateBarOld()
{
// подстраховка
if (_getWidgetBar()->getWidth() < 1)
return;
if ((_getWidgetBar()->getWidth() < mWidthBar) && (1 < mItemsInfo.size()))
{
if (!mButtonShow)
{
mButtonShow = true;
if (nullptr != mButtonLeft)
mButtonLeft->setVisible(true);
if (nullptr != mButtonRight)
mButtonRight->setVisible(true);
if (nullptr != mButtonDecor)
mButtonDecor->setVisible(true);
for (auto& iter : mWidgetsPatch)
iter->setVisible(true);
if (mWidgetBar != nullptr)
mWidgetBar->setSize(mWidgetBar->getWidth() - mOffsetTab, mWidgetBar->getHeight());
}
}
else
{
if (mButtonShow)
{
mButtonShow = false;
if (nullptr != mButtonLeft)
mButtonLeft->setVisible(false);
if (nullptr != mButtonRight)
mButtonRight->setVisible(false);
if (nullptr != mButtonDecor)
mButtonDecor->setVisible(false);
for (auto& iter : mWidgetsPatch)
iter->setVisible(false);
if (mWidgetBar != nullptr)
mWidgetBar->setSize(mWidgetBar->getWidth() + mOffsetTab, mWidgetBar->getHeight());
}
}
// проверяем правильность стартового индекса
if (mStartIndex > 0)
{
// считаем длинну видимых кнопок
int width = 0;
for (size_t pos = mStartIndex; pos < mItemsInfo.size(); pos++)
width += mItemsInfo[pos].width;
// уменьшаем индекс до тех пор пока кнопка до индекста полностью не влезет в бар
while ((mStartIndex > 0) && ((width + mItemsInfo[mStartIndex - 1].width) <= _getWidgetBar()->getWidth()))
{
mStartIndex--;
width += mItemsInfo[mStartIndex].width;
}
}
// проверяем и обновляем бар
int width = 0;
size_t count = 0;
size_t pos = mStartIndex;
for (; pos < mItemsInfo.size(); pos++)
{
// текущая кнопка не влазиет
if (width > _getWidgetBar()->getWidth())
break;
// следующая не влазиет
TabItemInfo& info = mItemsInfo[pos];
if ((width + info.width) > _getWidgetBar()->getWidth())
{
break;
}
// проверяем физическое наличие кнопки
if (count >= mItemButton.size())
_createItemButton();
// если кнопка не соответствует, то изменяем ее
Button* button = mItemButton[count]->castType<Button>();
button->setVisible(true);
// корректируем нажатость кнопки
button->setStateSelected(pos == mIndexSelect);
if (button->getCaption() != info.name)
button->setCaption(info.name);
// положение кнопки
IntCoord coord(width, 0, info.width, _getWidgetBar()->getHeight());
if (coord != button->getCoord())
button->setCoord(coord);
width += info.width;
count++;
}
// скрываем кнопки что были созданны, но не видны
while (count < mItemButton.size())
{
mItemButton[count]->setVisible(false);
count++;
}
bool right = true;
if (pos == mItemsInfo.size())
right = false;
// в редакторе падает почему то, хотя этот скин создается всегда
if (mEmptyBarWidget != nullptr)
{
// корректируем виджет для пустоты
if (width < _getWidgetBar()->getWidth())
{
mEmptyBarWidget->setVisible(true);
mEmptyBarWidget->setCoord(width, 0, _getWidgetBar()->getWidth() - width, _getWidgetBar()->getHeight());
}
else
{
mEmptyBarWidget->setVisible(false);
}
}
// корректируем доступность стрелок
if (mStartIndex == 0)
{
if (nullptr != mButtonLeft)
mButtonLeft->setEnabled(false);
}
else
{
if (nullptr != mButtonLeft)
mButtonLeft->setEnabled(true);
}
if (right)
{
if (nullptr != mButtonRight)
mButtonRight->setEnabled(true);
}
else
{
if (nullptr != mButtonRight)
mButtonRight->setEnabled(false);
}
}
void TabControl::updateBarNew()
{
if (mHeaderPlace == nullptr)
return;
// подстраховка
if (mHeaderPlace->getWidth() < 1)
return;
int widthControls = 0;
if (mControls != nullptr)
widthControls = mControls->getWidth();
if ((mHeaderPlace->getWidth() < mWidthBar) && (1 < mItemsInfo.size()) &&
(mHeaderPlace->getWidth() >= widthControls))
{
if (!mButtonShow)
{
mButtonShow = true;
if (nullptr != mControls)
mControls->setVisible(true);
}
if (mControls != nullptr)
mControls->setCoord(
mHeaderPlace->getWidth() - mControls->getWidth(),
0,
mControls->getWidth(),
mHeaderPlace->getHeight());
}
else
{
if (mButtonShow)
{
mButtonShow = false;
if (nullptr != mControls)
mControls->setVisible(false);
}
widthControls = 0;
}
// проверяем правильность стартового индекса
if (mStartIndex > 0)
{
// считаем длинну видимых кнопок
int width = 0;
for (size_t pos = mStartIndex; pos < mItemsInfo.size(); pos++)
width += mItemsInfo[pos].width;
// уменьшаем индекс до тех пор пока кнопка до индекста полностью не влезет в бар
while ((mStartIndex > 0) &&
((width + mItemsInfo[mStartIndex - 1].width) <= (mHeaderPlace->getWidth() - widthControls)))
{
mStartIndex--;
width += mItemsInfo[mStartIndex].width;
}
}
// проверяем и обновляем бар
int width = 0;
size_t count = 0;
size_t pos = mStartIndex;
for (; pos < mItemsInfo.size(); pos++)
{
// текущая кнопка не влазиет
if (width > (mHeaderPlace->getWidth() - widthControls))
break;
// следующая не влазиет
TabItemInfo& info = mItemsInfo[pos];
if ((width + info.width) > (mHeaderPlace->getWidth() - widthControls))
{
break;
}
// проверяем физическое наличие кнопки
if (count >= mItemButton.size())
_createItemButton();
// если кнопка не соответствует, то изменяем ее
Button* button = mItemButton[count];
button->setVisible(true);
// корректируем нажатость кнопки
button->setStateSelected(pos == mIndexSelect);
if (button->getCaption() != info.name)
button->setCaption(info.name);
// положение кнопки
IntCoord coord(width, 0, info.width, mHeaderPlace->getHeight());
if (coord != button->getCoord())
button->setCoord(coord);
width += info.width;
count++;
}
// скрываем кнопки что были созданны, но не видны
while (count < mItemButton.size())
{
mItemButton[count]->setVisible(false);
count++;
}
bool right = true;
if (pos == mItemsInfo.size())
right = false;
if (mEmpty != nullptr)
{
// корректируем виджет для пустоты
mEmpty->setCoord(width, 0, mHeaderPlace->getWidth() - width - widthControls, mHeaderPlace->getHeight());
}
// корректируем доступность стрелок
if (mStartIndex == 0)
{
if (nullptr != mButtonLeft)
mButtonLeft->setEnabled(false);
}
else
{
if (nullptr != mButtonLeft)
mButtonLeft->setEnabled(true);
}
if (right)
{
if (nullptr != mButtonRight)
mButtonRight->setEnabled(true);
}
else
{
if (nullptr != mButtonRight)
mButtonRight->setEnabled(false);
}
}
} // namespace MyGUI
MyGUI_Button.h
MyGUI_ControllerManager.h
MYGUI_EXCEPT
#define MYGUI_EXCEPT(dest)
Definition MyGUI_Diagnostic.h:21
MYGUI_ASSERT_RANGE_INSERT
#define MYGUI_ASSERT_RANGE_INSERT(index, size, owner)
Definition MyGUI_Diagnostic.h:50
MYGUI_ASSERT_RANGE
#define MYGUI_ASSERT_RANGE(index, size, owner)
Definition MyGUI_Diagnostic.h:44
MyGUI_Precompiled.h
MyGUI_ResourceSkin.h
MyGUI_TabControl.h
MyGUI_TabItem.h
MyGUI_WidgetManager.h
MyGUI::Any
Definition MyGUI_Any.h:56
MyGUI::Any::Null
static const Any Null
Definition MyGUI_Any.h:58
MyGUI::Button
widget description should be here.
Definition MyGUI_Button.h:20
MyGUI::Button::setStateSelected
void setStateSelected(bool _check)
Set button selected state.
Definition MyGUI_Button.cpp:119
MyGUI::ControllerFadeAlpha
Definition MyGUI_ControllerFadeAlpha.h:19
MyGUI::ControllerFadeAlpha::getClassTypeName
static std::string_view getClassTypeName()
Definition MyGUI_ControllerFadeAlpha.h:20
MyGUI::ControllerFadeAlpha::setAlpha
void setAlpha(float _value)
Definition MyGUI_ControllerFadeAlpha.cpp:83
MyGUI::ControllerFadeAlpha::setCoef
void setCoef(float _value)
Definition MyGUI_ControllerFadeAlpha.cpp:88
MyGUI::ControllerFadeAlpha::setEnabled
void setEnabled(bool _value)
Definition MyGUI_ControllerFadeAlpha.cpp:93
MyGUI::ControllerItem
Definition MyGUI_ControllerItem.h:26
MyGUI::ControllerItem::eventPostAction
EventPairAddParameter< EventHandle_WidgetPtr, EventHandle_WidgetPtrControllerItemPtr > eventPostAction
Definition MyGUI_ControllerItem.h:53
MyGUI::ControllerManager::createItem
ControllerItem * createItem(std::string_view _type)
Definition MyGUI_ControllerManager.cpp:71
MyGUI::ControllerManager::getInstance
static ControllerManager & getInstance()
MyGUI::ControllerManager::removeItem
void removeItem(Widget *_widget)
Definition MyGUI_ControllerManager.cpp:102
MyGUI::ControllerManager::addItem
void addItem(Widget *_widget, ControllerItem *_item)
Definition MyGUI_ControllerManager.cpp:77
MyGUI::ICroppedRectangle::getAbsoluteLeft
int getAbsoluteLeft() const
Definition MyGUI_ICroppedRectangle.h:82
MyGUI::ICroppedRectangle::getWidth
int getWidth() const
Definition MyGUI_ICroppedRectangle.h:113
MyGUI::ICroppedRectangle::getHeight
int getHeight() const
Definition MyGUI_ICroppedRectangle.h:118
MyGUI::ICroppedRectangle::getCoord
const IntCoord & getCoord() const
Definition MyGUI_ICroppedRectangle.h:56
MyGUI::ICroppedRectangle::getAbsoluteTop
int getAbsoluteTop() const
Definition MyGUI_ICroppedRectangle.h:87
MyGUI::IObject::castType
Type * castType(bool _throw=true)
Definition MyGUI_IObject.h:18
MyGUI::ISubWidgetText
Definition MyGUI_ISubWidgetText.h:19
MyGUI::ISubWidgetText::getTextSize
virtual IntSize getTextSize() const
Definition MyGUI_ISubWidgetText.h:122
MyGUI::TabControl::eventTabChangeSelect
EventPair< EventHandle_WidgetSizeT, EventHandle_TabPtrSizeT > eventTabChangeSelect
Definition MyGUI_TabControl.h:218
MyGUI::TabControl::setItemNameAt
void setItemNameAt(size_t _index, const UString &_name)
Replace an item name at a specified position.
Definition MyGUI_TabControl.cpp:347
MyGUI::TabControl::_getTextWidth
int _getTextWidth(const UString &_text)
Definition MyGUI_TabControl.cpp:435
MyGUI::TabControl::_notifyDeleteItem
void _notifyDeleteItem(TabItem *_sheet)
Definition MyGUI_TabControl.cpp:452
MyGUI::TabControl::getIndexSelected
size_t getIndexSelected() const
Get index of selected item (ITEM_NONE if none selected).
Definition MyGUI_TabControl.cpp:657
MyGUI::TabControl::_setItemNameAt
void _setItemNameAt(size_t _index, const UString &_name) override
Definition MyGUI_TabControl.cpp:765
MyGUI::TabControl::findItemIndex
size_t findItemIndex(const TabItem *_item)
Search item, returns the position of the first occurrence in array or ITEM_NONE if item not found.
Definition MyGUI_TabControl.cpp:565
MyGUI::TabControl::updateBar
void updateBar()
Definition MyGUI_TabControl.cpp:775
MyGUI::TabControl::swapItems
void swapItems(size_t _index1, size_t _index2)
Definition MyGUI_TabControl.cpp:174
MyGUI::TabControl::setButtonWidth
void setButtonWidth(TabItem *_item, int _width=DEFAULT_WIDTH)
Set button width.
Definition MyGUI_TabControl.cpp:715
MyGUI::TabControl::getButtonDefaultWidth
int getButtonDefaultWidth() const
Definition MyGUI_TabControl.cpp:725
MyGUI::TabControl::beginToItemSelected
void beginToItemSelected()
Move all elements so selected becomes visible.
Definition MyGUI_TabControl.cpp:709
MyGUI::TabControl::setButtonDefaultWidth
void setButtonDefaultWidth(int _width)
Definition MyGUI_TabControl.cpp:302
MyGUI::TabControl::clearItemDataAt
void clearItemDataAt(size_t _index)
Clear an item data at a specified position.
Definition MyGUI_TabControl.cpp:672
MyGUI::TabControl::setItemDataAt
void setItemDataAt(size_t _index, Any _data)
Replace an item data at a specified position.
Definition MyGUI_TabControl.cpp:505
MyGUI::TabControl::beginToItemFirst
void beginToItemFirst()
Move all elements so first becomes visible.
Definition MyGUI_TabControl.cpp:697
MyGUI::TabControl::beginToItemLast
void beginToItemLast()
Move all elements so last becomes visible.
Definition MyGUI_TabControl.cpp:703
MyGUI::TabControl::onWidgetCreated
void onWidgetCreated(Widget *_widget) override
Definition MyGUI_TabControl.cpp:133
MyGUI::TabControl::removeAllItems
void removeAllItems()
Remove all items.
Definition MyGUI_TabControl.cpp:535
MyGUI::TabControl::setSmoothShow
void setSmoothShow(bool _value)
Definition MyGUI_TabControl.cpp:735
MyGUI::TabControl::_insertItem
void _insertItem(size_t _index, const UString &_name, TabItem *_sheet, Any _data)
Definition MyGUI_TabControl.cpp:481
MyGUI::TabControl::setSize
void setSize(const IntSize &_size) override
Definition MyGUI_TabControl.cpp:193
MyGUI::TabControl::getItemCount
size_t getItemCount() const
Get number of items.
Definition MyGUI_TabControl.cpp:637
MyGUI::TabControl::beginToItem
void beginToItem(const TabItem *_item)
Move all elements so specified becomes visible.
Definition MyGUI_TabControl.cpp:692
MyGUI::TabControl::findItemIndexWith
size_t findItemIndexWith(const UString &_name)
Search item, returns the position of the first occurrence in array or ITEM_NONE if item not found.
Definition MyGUI_TabControl.cpp:575
MyGUI::TabControl::setItemSelected
void setItemSelected(TabItem *_item)
Select item.
Definition MyGUI_TabControl.cpp:662
MyGUI::TabControl::TabItem
friend class TabItem
Definition MyGUI_TabControl.h:30
MyGUI::TabControl::setButtonWidthAt
void setButtonWidthAt(size_t _index, int _width=DEFAULT_WIDTH)
Set button width at a specified position.
Definition MyGUI_TabControl.cpp:329
MyGUI::TabControl::findItemWith
TabItem * findItemWith(const UString &_name)
Search item, returns the item of the first occurrence in array or nullptr if item not found.
Definition MyGUI_TabControl.cpp:585
MyGUI::TabControl::getItemSelected
TabItem * getItemSelected() const
Get selected item (nullptr if none selected).
Definition MyGUI_TabControl.cpp:595
MyGUI::TabControl::setButtonAutoWidth
void setButtonAutoWidth(bool _auto)
Definition MyGUI_TabControl.cpp:310
MyGUI::TabControl::_getItemCount
size_t _getItemCount() const override
Definition MyGUI_TabControl.cpp:745
MyGUI::TabControl::insertItem
TabItem * insertItem(TabItem *_to, const UString &_name, Any _data=Any::Null)
Insert an item into a array.
Definition MyGUI_TabControl.cpp:642
MyGUI::TabControl::shutdownOverride
void shutdownOverride() override
Definition MyGUI_TabControl.cpp:113
MyGUI::TabControl::setCoord
void setCoord(const IntCoord &_coord) override
Definition MyGUI_TabControl.cpp:200
MyGUI::TabControl::_addItem
void _addItem(const MyGUI::UString &_name) override
Definition MyGUI_TabControl.cpp:750
MyGUI::TabControl::setIndexSelected
void setIndexSelected(size_t _index)
Select specified _index.
Definition MyGUI_TabControl.cpp:364
MyGUI::TabControl::setItemName
void setItemName(TabItem *_item, const UString &_name)
Replace an item name.
Definition MyGUI_TabControl.cpp:682
MyGUI::TabControl::_removeItemAt
void _removeItemAt(size_t _index) override
Definition MyGUI_TabControl.cpp:755
MyGUI::TabControl::_showItem
void _showItem(TabItem *_item, bool _show, bool _smooth)
Definition MyGUI_TabControl.cpp:389
MyGUI::TabControl::getItemIndex
size_t getItemIndex(const TabItem *_item) const
Get item index.
Definition MyGUI_TabControl.cpp:555
MyGUI::TabControl::getButtonWidth
int getButtonWidth(TabItem *_item) const
Get button width.
Definition MyGUI_TabControl.cpp:720
MyGUI::TabControl::_getItemAt
Widget * _getItemAt(size_t _index) const override
Definition MyGUI_TabControl.cpp:760
MyGUI::TabControl::removeItemAt
void removeItemAt(size_t _index)
Remove item at a specified position.
Definition MyGUI_TabControl.cpp:529
MyGUI::TabControl::beginToItemAt
void beginToItemAt(size_t _index)
Move all elements so specified becomes visible.
Definition MyGUI_TabControl.cpp:265
MyGUI::TabControl::clearItemData
void clearItemData(TabItem *_item)
Clear an item data.
Definition MyGUI_TabControl.cpp:677
MyGUI::TabControl::notifyPressedBarButtonEvent
void notifyPressedBarButtonEvent(MyGUI::Widget *_sender)
Definition MyGUI_TabControl.cpp:228
MyGUI::TabControl::setPosition
void setPosition(const IntPoint &_point) override
Definition MyGUI_TabControl.cpp:186
MyGUI::TabControl::getItemNameAt
const UString & getItemNameAt(size_t _index) const
Get item name from specified position.
Definition MyGUI_TabControl.cpp:517
MyGUI::TabControl::setItemData
void setItemData(TabItem *_item, Any _data)
Replace an item data.
Definition MyGUI_TabControl.cpp:667
MyGUI::TabControl::getSmoothShow
bool getSmoothShow() const
Definition MyGUI_TabControl.cpp:740
MyGUI::TabControl::removeItem
void removeItem(TabItem *_item)
Remove item.
Definition MyGUI_TabControl.cpp:652
MyGUI::TabControl::_getItemNameAt
const UString & _getItemNameAt(size_t _index) const override
Definition MyGUI_TabControl.cpp:770
MyGUI::TabControl::addItem
TabItem * addItem(const UString &_name, Any _data=Any::Null)
Add an item to the end of a array.
Definition MyGUI_TabControl.cpp:647
MyGUI::TabControl::getButtonWidthAt
int getButtonWidthAt(size_t _index) const
Get button width at a specified position.
Definition MyGUI_TabControl.cpp:511
MyGUI::TabControl::getButtonAutoWidth
bool getButtonAutoWidth() const
Definition MyGUI_TabControl.cpp:730
MyGUI::TabControl::_createItemButton
void _createItemButton()
Definition MyGUI_TabControl.cpp:427
MyGUI::TabControl::getItemAt
TabItem * getItemAt(size_t _index) const
Get item from specified position.
Definition MyGUI_TabControl.cpp:523
MyGUI::TabControl::getItemName
const UString & getItemName(const TabItem *_item) const
Get item name.
Definition MyGUI_TabControl.cpp:687
MyGUI::TabControl::initialiseOverride
void initialiseOverride() override
Definition MyGUI_TabControl.cpp:20
MyGUI::TabControl::insertItemAt
TabItem * insertItemAt(size_t _index, const UString &_name, Any _data=Any::Null)
Insert an item into a array at a specified position.
Definition MyGUI_TabControl.cpp:151
MyGUI::TabControl::notifyPressedButtonEvent
void notifyPressedButtonEvent(MyGUI::Widget *_sender)
Definition MyGUI_TabControl.cpp:207
MyGUI::TabControl::setPropertyOverride
void setPropertyOverride(std::string_view _key, std::string_view _value) override
Definition MyGUI_TabControl.cpp:610
MyGUI::TabItem::getClassTypeName
static std::string_view getClassTypeName()
Definition MyGUI_TabItem.h:22
MyGUI::UString
A UTF-16 string with implicit conversion to/from std::string and std::wstring.
Definition MyGUI_UString.h:144
MyGUI::UserData::isUserString
bool isUserString(std::string_view _key) const
Definition MyGUI_WidgetUserData.cpp:44
MyGUI::UserData::getUserString
std::string_view getUserString(std::string_view _key) const
Definition MyGUI_WidgetUserData.cpp:20
MyGUI::UserData::_setInternalData
void _setInternalData(Any _data)
Definition MyGUI_WidgetUserData.cpp:59
MyGUI::UserData::_getInternalData
ValueType * _getInternalData(bool _throw=true) const
Definition MyGUI_WidgetUserData.h:54
MyGUI::Widget
widget description should be here.
Definition MyGUI_Widget.h:40
MyGUI::Widget::setAlpha
void setAlpha(float _alpha)
Definition MyGUI_Widget.cpp:466
MyGUI::Widget::setSize
void setSize(const IntSize &_size) override
Definition MyGUI_Widget.cpp:693
MyGUI::Widget::_destroyChildWidget
void _destroyChildWidget(Widget *_widget)
Definition MyGUI_Widget.cpp:411
MyGUI::Widget::eventChangeProperty
EventHandle_WidgetStringString eventChangeProperty
Definition MyGUI_Widget.h:324
MyGUI::Widget::setVisible
virtual void setVisible(bool _value)
Definition MyGUI_Widget.cpp:1022
MyGUI::Widget::setEnabled
virtual void setEnabled(bool _value)
Definition MyGUI_Widget.cpp:1049
MyGUI::Widget::getVisible
bool getVisible() const
Definition MyGUI_Widget.cpp:1327
MyGUI::Widget::getAlign
Align getAlign() const
Definition MyGUI_Widget.cpp:1332
MyGUI::Widget::setAlign
virtual void setAlign(Align _value)
Definition MyGUI_Widget.cpp:775
MyGUI::Widget::assignWidget
void assignWidget(T *&_widget, std::string_view _name)
Definition MyGUI_Widget.h:413
MyGUI::Widget::createWidget
T * createWidget(std::string_view _skin, const IntCoord &_coord, Align _align, std::string_view _name={})
Definition MyGUI_Widget.h:94
MyGUI::Widget::_forcePick
void _forcePick(Widget *_widget)
Definition MyGUI_Widget.cpp:547
MyGUI::Widget::baseCreateWidget
Widget * baseCreateWidget(WidgetStyle _style, std::string_view _type, std::string_view _skin, const IntCoord &_coord, Align _align, std::string_view _layer, std::string_view _name, bool _template)
Definition MyGUI_Widget.cpp:293
MyGUI::Widget::setCoord
void setCoord(const IntCoord &_coord) override
Definition MyGUI_Widget.cpp:730
MyGUI::WidgetInput::eventMouseButtonClick
EventHandle_WidgetVoid eventMouseButtonClick
Definition MyGUI_WidgetInput.h:168
MyGUI::utility::parseValue
T parseValue(std::string_view _value)
Definition MyGUI_StringUtility.h:60
MyGUI
Definition MyGUI_ActionController.h:15
MyGUI::TAB_SPEED_FADE_COEF
const float TAB_SPEED_FADE_COEF
Definition MyGUI_TabControl.cpp:18
MyGUI::ALPHA_MAX
constexpr float ALPHA_MAX
Definition MyGUI_Macros.h:20
MyGUI::IntPoint
types::TPoint< int > IntPoint
Definition MyGUI_Types.h:27
MyGUI::ALPHA_MIN
constexpr float ALPHA_MIN
Definition MyGUI_Macros.h:21
MyGUI::ITEM_NONE
constexpr size_t ITEM_NONE
Definition MyGUI_Macros.h:19
MyGUI::IntCoord
types::TCoord< int > IntCoord
Definition MyGUI_Types.h:36
MyGUI::IntSize
types::TSize< int > IntSize
Definition MyGUI_Types.h:30
MyGUI::newDelegate
delegates::DelegateFunction< Args... > * newDelegate(void(*_func)(Args... args))
Definition MyGUI_Delegate.h:100
MyGUI::Align::Left
@ Left
Definition MyGUI_Align.h:27
MyGUI::Align::Top
@ Top
Definition MyGUI_Align.h:31
MyGUI::TabControl::TabItemInfo
Definition MyGUI_TabControl.h:36
MyGUI::WidgetStyle::Child
@ Child
Definition MyGUI_WidgetStyle.h:22
MyGUI::types::TCoord::width
T width
Definition MyGUI_TCoord.h:22
MyGUI::types::TSize::width
T width
Definition MyGUI_TSize.h:19