From c9d9461d3e84b60024d0800bd23413c41f82ee73 Mon Sep 17 00:00:00 2001 From: scrawl <720642+scrawl@users.noreply.github.com> Date: Mon, 31 Jul 2017 16:13:50 +0200 Subject: [PATCH] Add Spacer class derived from AutoSizedWidget Using a normal widget as a spacer with HStretch/VStretch may not work properly because for widgets not derived from AutoSizedWidget, the HBox/VBox treat the widget's current size as the requested minimum size. This leads the layout to break when resized more than once. The new class sets HStretch and VStretch to true by default to save some typing. --- components/widgets/box.cpp | 6 ++++++ components/widgets/box.hpp | 9 +++++++++ components/widgets/widgets.cpp | 1 + files/mygui/openmw_container_window.layout | 4 +--- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/components/widgets/box.cpp b/components/widgets/box.cpp index 0ac2ff7fd..0ce8ce951 100644 --- a/components/widgets/box.cpp +++ b/components/widgets/box.cpp @@ -422,4 +422,10 @@ namespace Gui align(); } + Spacer::Spacer() + { + setUserString("HStretch", "true"); + setUserString("VStretch", "true"); + } + } diff --git a/components/widgets/box.hpp b/components/widgets/box.hpp index ccdc5784b..70f73ce42 100644 --- a/components/widgets/box.hpp +++ b/components/widgets/box.hpp @@ -81,6 +81,15 @@ namespace Gui bool mAutoResize; // auto resize the box so that it exactly fits all elements }; + class Spacer : public AutoSizedWidget, public MyGUI::Widget + { + MYGUI_RTTI_DERIVED( Spacer ) + public: + Spacer(); + + virtual MyGUI::IntSize getRequestedSize() { return MyGUI::IntSize(0,0); } + }; + class HBox : public Box, public MyGUI::Widget { MYGUI_RTTI_DERIVED( HBox ) diff --git a/components/widgets/widgets.cpp b/components/widgets/widgets.cpp index 3b6361cf8..92f2084df 100644 --- a/components/widgets/widgets.cpp +++ b/components/widgets/widgets.cpp @@ -16,6 +16,7 @@ namespace Gui { 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"); diff --git a/files/mygui/openmw_container_window.layout b/files/mygui/openmw_container_window.layout index 87651b0f2..6bb585e50 100644 --- a/files/mygui/openmw_container_window.layout +++ b/files/mygui/openmw_container_window.layout @@ -10,9 +10,7 @@ - - - +