InteractiveMessageBox: lay out buttons horizontally if button width does not exceed message width (Fixes #1812)

Also fix some layout bugs.
This commit is contained in:
scrawl 2014-08-16 17:31:36 +02:00
parent bb33b4e005
commit 322480862b

View file

@ -197,9 +197,9 @@ namespace MWGui
WindowModal::open(); WindowModal::open();
int textPadding = 10; // padding between text-widget and main-widget int textPadding = 10; // padding between text-widget and main-widget
int textButtonPadding = 20; // padding between the text-widget und the button-widget int textButtonPadding = 10; // padding between the text-widget und the button-widget
int buttonLeftPadding = 10; // padding between the buttons if horizontal int buttonLeftPadding = 10; // padding between the buttons if horizontal
int buttonTopPadding = 5; // ^-- if vertical int buttonTopPadding = 10; // ^-- if vertical
int buttonPadding = 5; // padding between button label and button itself int buttonPadding = 5; // padding between button label and button itself
int buttonMainPadding = 10; // padding between buttons and bottom of the main widget int buttonMainPadding = 10; // padding between buttons and bottom of the main widget
@ -219,6 +219,7 @@ namespace MWGui
int biggestButtonWidth = 0; int biggestButtonWidth = 0;
int buttonWidth = 0; int buttonWidth = 0;
int buttonsWidth = 0; int buttonsWidth = 0;
int buttonsHeight = 0;
int buttonHeight = 0; int buttonHeight = 0;
MyGUI::IntCoord dummyCoord(0, 0, 0, 0); MyGUI::IntCoord dummyCoord(0, 0, 0, 0);
@ -236,37 +237,41 @@ namespace MWGui
mButtons.push_back(button); mButtons.push_back(button);
buttonWidth = button->getTextSize().width + 2*buttonPadding + buttonLeftPadding; if (buttonsWidth != 0)
buttonsWidth += buttonLeftPadding;
buttonWidth = button->getTextSize().width + 2*buttonPadding;
buttonsWidth += buttonWidth; buttonsWidth += buttonWidth;
buttonHeight = button->getTextSize().height + 2*buttonPadding + buttonTopPadding;
buttonHeight = button->getTextSize().height + 2*buttonPadding;
if (buttonsHeight != 0)
buttonsHeight += buttonTopPadding;
buttonsHeight += buttonHeight;
if(buttonWidth > biggestButtonWidth) if(buttonWidth > biggestButtonWidth)
{ {
biggestButtonWidth = buttonWidth; biggestButtonWidth = buttonWidth;
} }
} }
buttonsWidth += buttonLeftPadding;
MyGUI::IntSize mainWidgetSize; MyGUI::IntSize mainWidgetSize;
if(buttonsWidth < fixedWidth) if(buttonsWidth < textSize.width)
{ {
// on one line // on one line
if(textSize.width + 2*textPadding < buttonsWidth) mainWidgetSize.width = textSize.width + 3*textPadding;
{ mainWidgetSize.height = textPadding + textSize.height + textButtonPadding + buttonHeight + buttonMainPadding;
mainWidgetSize.width = buttonsWidth;
} MyGUI::IntSize realSize = mainWidgetSize +
else // To account for borders
{ (mMainWidget->getSize() - mMainWidget->getClientWidget()->getSize());
mainWidgetSize.width = textSize.width + 3*textPadding;
}
mainWidgetSize.height = textSize.height + textButtonPadding + buttonHeight + buttonMainPadding;
MyGUI::IntPoint absPos; MyGUI::IntPoint absPos;
absPos.left = (gameWindowSize.width - mainWidgetSize.width)/2; absPos.left = (gameWindowSize.width - realSize.width)/2;
absPos.top = (gameWindowSize.height - mainWidgetSize.height)/2; absPos.top = (gameWindowSize.height - realSize.height)/2;
mMainWidget->setPosition(absPos); mMainWidget->setPosition(absPos);
mMainWidget->setSize(mainWidgetSize); mMainWidget->setSize(realSize);
MyGUI::IntCoord messageWidgetCoord; MyGUI::IntCoord messageWidgetCoord;
messageWidgetCoord.left = (mainWidgetSize.width - textSize.width)/2; messageWidgetCoord.left = (mainWidgetSize.width - textSize.width)/2;
@ -277,13 +282,13 @@ namespace MWGui
MyGUI::IntCoord buttonCord; MyGUI::IntCoord buttonCord;
MyGUI::IntSize buttonSize(0, buttonHeight); MyGUI::IntSize buttonSize(0, buttonHeight);
int left = (mainWidgetSize.width - buttonsWidth)/2 + buttonPadding; int left = (mainWidgetSize.width - buttonsWidth)/2;
std::vector<MyGUI::Button*>::const_iterator button; std::vector<MyGUI::Button*>::const_iterator button;
for(button = mButtons.begin(); button != mButtons.end(); ++button) for(button = mButtons.begin(); button != mButtons.end(); ++button)
{ {
buttonCord.left = left; buttonCord.left = left;
buttonCord.top = textSize.height + textButtonPadding; buttonCord.top = messageWidgetCoord.top + textSize.height + textButtonPadding;
buttonSize.width = (*button)->getTextSize().width + 2*buttonPadding; buttonSize.width = (*button)->getTextSize().width + 2*buttonPadding;
buttonSize.height = (*button)->getTextSize().height + 2*buttonPadding; buttonSize.height = (*button)->getTextSize().height + 2*buttonPadding;
@ -298,7 +303,7 @@ namespace MWGui
{ {
// among each other // among each other
if(biggestButtonWidth > textSize.width) { if(biggestButtonWidth > textSize.width) {
mainWidgetSize.width = biggestButtonWidth + buttonTopPadding; mainWidgetSize.width = biggestButtonWidth + buttonTopPadding*2;
} }
else { else {
mainWidgetSize.width = textSize.width + 3*textPadding; mainWidgetSize.width = textSize.width + 3*textPadding;
@ -307,7 +312,7 @@ namespace MWGui
MyGUI::IntCoord buttonCord; MyGUI::IntCoord buttonCord;
MyGUI::IntSize buttonSize(0, buttonHeight); MyGUI::IntSize buttonSize(0, buttonHeight);
int top = textButtonPadding + buttonTopPadding + textSize.height; int top = textPadding + textSize.height + textButtonPadding;
std::vector<MyGUI::Button*>::const_iterator button; std::vector<MyGUI::Button*>::const_iterator button;
for(button = mButtons.begin(); button != mButtons.end(); ++button) for(button = mButtons.begin(); button != mButtons.end(); ++button)
@ -316,16 +321,18 @@ namespace MWGui
buttonSize.height = (*button)->getTextSize().height + buttonPadding*2; buttonSize.height = (*button)->getTextSize().height + buttonPadding*2;
buttonCord.top = top; buttonCord.top = top;
buttonCord.left = (mainWidgetSize.width - buttonSize.width)/2 - 5; // FIXME: -5 is not so nice :/ buttonCord.left = (mainWidgetSize.width - buttonSize.width)/2;
(*button)->setCoord(buttonCord); (*button)->setCoord(buttonCord);
(*button)->setSize(buttonSize); (*button)->setSize(buttonSize);
top += buttonSize.height + 2*buttonTopPadding; top += buttonSize.height + buttonTopPadding;
} }
mainWidgetSize.height = top + buttonMainPadding; mainWidgetSize.height = textPadding + textSize.height + textButtonPadding + buttonsHeight + buttonMainPadding;
mMainWidget->setSize(mainWidgetSize); mMainWidget->setSize(mainWidgetSize +
// To account for borders
(mMainWidget->getSize() - mMainWidget->getClientWidget()->getSize()));
MyGUI::IntPoint absPos; MyGUI::IntPoint absPos;
absPos.left = (gameWindowSize.width - mainWidgetSize.width)/2; absPos.left = (gameWindowSize.width - mainWidgetSize.width)/2;