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.
pull/258/head
scrawl 8 years ago
parent 308ddabe90
commit c9d9461d3e

@ -422,4 +422,10 @@ namespace Gui
align();
}
Spacer::Spacer()
{
setUserString("HStretch", "true");
setUserString("VStretch", "true");
}
}

@ -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 )

@ -16,6 +16,7 @@ namespace Gui
{
MyGUI::FactoryManager::getInstance().registerFactory<Gui::MWList>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<Gui::HBox>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<Gui::Spacer>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<Gui::VBox>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<Gui::AutoSizedTextBox>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<Gui::AutoSizedEditBox>("Widget");

@ -10,9 +10,7 @@
</Widget>
<Widget type="HBox" position="0 235 580 24" align="Right Bottom">
<Widget type="Widget">
<UserString key="HStretch" value="true"/>
</Widget>
<Widget type="Spacer"/>
<Widget type="AutoSizedButton" skin="MW_Button" name="DisposeCorpseButton" align="Right Bottom">
<Property key="Caption" value="#{sDisposeofCorpse}"/>
<Property key="Visible" value="false"/>

Loading…
Cancel
Save