diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index 21ed7f702..6dc19944f 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -66,26 +66,6 @@ namespace MWGui getWidget(itemView, "ItemView"); setWidgets(containerWidget, itemView); - // adjust size of buttons to fit text - int curX = 0; - mFilterAll->setSize( mFilterAll->getTextSize().width + 24, mFilterAll->getSize().height ); - curX += mFilterAll->getTextSize().width + 24 + 4; - - mFilterWeapon->setPosition(curX, mFilterWeapon->getPosition().top); - mFilterWeapon->setSize( mFilterWeapon->getTextSize().width + 24, mFilterWeapon->getSize().height ); - curX += mFilterWeapon->getTextSize().width + 24 + 4; - - mFilterApparel->setPosition(curX, mFilterApparel->getPosition().top); - mFilterApparel->setSize( mFilterApparel->getTextSize().width + 24, mFilterApparel->getSize().height ); - curX += mFilterApparel->getTextSize().width + 24 + 4; - - mFilterMagic->setPosition(curX, mFilterMagic->getPosition().top); - mFilterMagic->setSize( mFilterMagic->getTextSize().width + 24, mFilterMagic->getSize().height ); - curX += mFilterMagic->getTextSize().width + 24 + 4; - - mFilterMisc->setPosition(curX, mFilterMisc->getPosition().top); - mFilterMisc->setSize( mFilterMisc->getTextSize().width + 24, mFilterMisc->getSize().height ); - mFilterAll->eventMouseButtonClick += MyGUI::newDelegate(this, &InventoryWindow::onFilterChanged); mFilterWeapon->eventMouseButtonClick += MyGUI::newDelegate(this, &InventoryWindow::onFilterChanged); mFilterApparel->eventMouseButtonClick += MyGUI::newDelegate(this, &InventoryWindow::onFilterChanged); diff --git a/apps/openmw/mwgui/widgets.cpp b/apps/openmw/mwgui/widgets.cpp index 40ee1c7ad..66488adf0 100644 --- a/apps/openmw/mwgui/widgets.cpp +++ b/apps/openmw/mwgui/widgets.cpp @@ -789,3 +789,165 @@ void MWDynamicStat::initialiseOverride() assignWidget(mBarWidget, "Bar"); assignWidget(mBarTextWidget, "BarText"); } + + + + +// --------------------------------------------------------------------------------------------------------------------- + + +void AutoSizedWidget::notifySizeChange (MyGUI::Widget* w) +{ + if (w->getParent () != 0) + { + Box* b = dynamic_cast(w->getParent()); + if (b) + b->notifyChildrenSizeChanged (); + } +} + + +MyGUI::IntSize AutoSizedTextBox::getRequestedSize() +{ + return getTextSize(); +} + +void AutoSizedTextBox::setCaption(const MyGUI::UString& _value) +{ + TextBox::setCaption(_value); + + notifySizeChange (this); +} + + +MyGUI::IntSize AutoSizedButton::getRequestedSize() +{ + return getTextSize() + MyGUI::IntSize(24,0); +} + +void AutoSizedButton::setCaption(const MyGUI::UString& _value) +{ + Button::setCaption(_value); + + notifySizeChange (this); +} + + +Box::Box() + : mSpacing(4) +{ + +} + +void Box::setPropertyOverride(const std::string& _key, const std::string& _value) +{ + if (_key == "Spacing") + { + mSpacing = MyGUI::utility::parseValue(_value); + } +} + +void Box::notifyChildrenSizeChanged () +{ + align(); +} + + +void HBox::align () +{ + unsigned int count = getChildCount (); + size_t h_stretched_count = 0; + int total_width = 0; + std::vector< std::pair > sizes; + + for (unsigned int i = 0; i < count; ++i) + { + MyGUI::Widget* w = getChildAt(i); + bool hstretch = w->getUserString ("HStretch") == "true"; + h_stretched_count += hstretch; + AutoSizedWidget* aw = dynamic_cast(w); + if (aw) + { + sizes.push_back(std::make_pair(aw->getRequestedSize (), hstretch)); + total_width += aw->getRequestedSize ().width; + if (i != count-1) + total_width += mSpacing; + } + else + sizes.push_back (std::make_pair(MyGUI::IntSize(0,0), hstretch)); + } + + int curX = 0; + for (unsigned int i = 0; i < count; ++i) + { + MyGUI::Widget* w = getChildAt(i); + MyGUI::IntCoord widgetCoord; + widgetCoord.left = curX; + widgetCoord.top = 0; /// \todo + int width = sizes[i].second ? sizes[i].first.width + (getSize().width - total_width)/h_stretched_count + : sizes[i].first.width; + widgetCoord.width = width; + widgetCoord.height = getSize().height; /// \todo + w->setCoord(widgetCoord); + curX += width; + + if (i != count-1) + curX += mSpacing; + } +} + +void HBox::setSize (const MyGUI::IntSize& _value) +{ + MyGUI::Widget::setSize (_value); + align(); +} + +MyGUI::IntSize HBox::getRequestedSize () +{ + MyGUI::IntSize size(0,0); + for (unsigned int i = 0; i < getChildCount (); ++i) + { + AutoSizedWidget* w = dynamic_cast(getChildAt(i)); + if (w) + { + MyGUI::IntSize requested = w->getRequestedSize (); + size.height = std::max(size.height, requested.height); + size.width = size.width + requested.width; + if (i != getChildCount()-1) + size.width += mSpacing; + } + } + return size; +} + + + + +void VBox::align () +{ + +} + +void VBox::setSize (const MyGUI::IntSize& _value) +{ + MyGUI::Widget::setSize (_value); + align(); +} + +MyGUI::IntSize VBox::getRequestedSize () +{ + MyGUI::IntSize size(0,0); + for (unsigned int i = 0; i < getChildCount (); ++i) + { + AutoSizedWidget* w = dynamic_cast(getChildAt(i)); + if (w) + { + MyGUI::IntSize requested = w->getRequestedSize (); + size.width = std::max(size.width, requested.width); + size.height = size.height + requested.height; + if (i != getChildCount()-1) + size.height += mSpacing; + } + } + return size; +} diff --git a/apps/openmw/mwgui/widgets.hpp b/apps/openmw/mwgui/widgets.hpp index d085b54cb..d7cc4afcf 100644 --- a/apps/openmw/mwgui/widgets.hpp +++ b/apps/openmw/mwgui/widgets.hpp @@ -299,6 +299,85 @@ namespace MWGui MyGUI::TextBox* mBarTextWidget; }; typedef MWDynamicStat* MWDynamicStatPtr; + + + + + + // --------------------------------------------------------------------------------------------------------------------- + + + + class AutoSizedWidget + { + public: + virtual MyGUI::IntSize getRequestedSize() = 0; + + protected: + void notifySizeChange(MyGUI::Widget* w); + }; + + class AutoSizedTextBox : public AutoSizedWidget, public MyGUI::TextBox + { + MYGUI_RTTI_DERIVED( AutoSizedTextBox ) + + public: + virtual MyGUI::IntSize getRequestedSize(); + virtual void setCaption(const MyGUI::UString& _value); + }; + + class AutoSizedButton : public AutoSizedWidget, public MyGUI::Button + { + MYGUI_RTTI_DERIVED( AutoSizedButton ) + + public: + virtual MyGUI::IntSize getRequestedSize(); + virtual void setCaption(const MyGUI::UString& _value); + }; + + /** + * @brief A container widget that automatically sizes its children + * @note the box being an AutoSizedWidget as well allows to put boxes inside a box + */ + class Box : public AutoSizedWidget + { + public: + Box(); + + void notifyChildrenSizeChanged(); + + protected: + virtual void align() = 0; + + virtual void setPropertyOverride(const std::string& _key, const std::string& _value); + + + int mSpacing; // how much space to put between elements + }; + + class HBox : public Box, public MyGUI::Widget + { + MYGUI_RTTI_DERIVED( HBox ) + + public: + virtual void setSize (const MyGUI::IntSize &_value); + + protected: + virtual void align(); + virtual MyGUI::IntSize getRequestedSize(); + }; + + class VBox : public Box, public MyGUI::Widget + { + MYGUI_RTTI_DERIVED( VBox) + + public: + virtual void setSize (const MyGUI::IntSize &_value); + + protected: + virtual void align(); + virtual MyGUI::IntSize getRequestedSize(); + }; } } diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index faaa41783..82406fe34 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -102,6 +102,10 @@ WindowManager::WindowManager( MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Widget"); + MyGUI::FactoryManager::getInstance().registerFactory("Widget"); + MyGUI::FactoryManager::getInstance().registerFactory("Widget"); + MyGUI::FactoryManager::getInstance().registerFactory("Widget"); + MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::LanguageManager::getInstance().eventRequestTag = MyGUI::newDelegate(this, &WindowManager::onRetrieveTag); diff --git a/files/mygui/openmw_inventory_window.layout b/files/mygui/openmw_inventory_window.layout index b38e15fc7..1ffabe3b6 100644 --- a/files/mygui/openmw_inventory_window.layout +++ b/files/mygui/openmw_inventory_window.layout @@ -30,20 +30,20 @@ - - + + - + - + - + - + diff --git a/files/mygui/openmw_settings_window.layout b/files/mygui/openmw_settings_window.layout index c8eae518f..077dbac2d 100644 --- a/files/mygui/openmw_settings_window.layout +++ b/files/mygui/openmw_settings_window.layout @@ -43,14 +43,18 @@ - - - + + + + + - - - + + + + +