Correct alignment of elements in TextPrompt

This commit is contained in:
Simon Robertshaw 2012-07-24 17:41:41 +01:00
parent d50d45ecff
commit dceefed030
2 changed files with 30 additions and 15 deletions

View File

@ -8,6 +8,7 @@
#include "TextPrompt.h" #include "TextPrompt.h"
#include "interface/Label.h" #include "interface/Label.h"
#include "interface/Button.h" #include "interface/Button.h"
#include "Style.h"
class CloseAction: public ui::ButtonAction class CloseAction: public ui::ButtonAction
{ {
@ -25,34 +26,48 @@ public:
}; };
TextPrompt::TextPrompt(std::string title, std::string message, bool multiline, TextDialogueCallback * callback_): TextPrompt::TextPrompt(std::string title, std::string message, bool multiline, TextDialogueCallback * callback_):
ui::Window(ui::Point(-1, -1), ui::Point(200, 75)), ui::Window(ui::Point(-1, -1), ui::Point(200, 80)),
callback(callback_) callback(callback_)
{ {
ui::Label * titleLabel = new ui::Label(ui::Point(2, 1), ui::Point(Size.X-4, 16), title); ui::Label * titleLabel = new ui::Label(ui::Point(4, 5), ui::Point(Size.X-8, 18), title);
titleLabel->SetTextColour(ui::Colour(220, 220, 50)); titleLabel->SetTextColour(style::Colour::WarningTitle);
titleLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; titleLabel->Appearance.VerticalAlign = ui::Appearance::AlignBottom; titleLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
titleLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
AddComponent(titleLabel); AddComponent(titleLabel);
ui::Label * messageLabel = new ui::Label(ui::Point(4, 18), ui::Point(Size.X-8, 60), message); ui::Label * messageLabel = new ui::Label(ui::Point(4, 25), ui::Point(Size.X-8, 16), message);
messageLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; messageLabel->Appearance.VerticalAlign = ui::Appearance::AlignTop; messageLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; messageLabel->Appearance.VerticalAlign = ui::Appearance::AlignTop;
AddComponent(messageLabel); AddComponent(messageLabel);
ui::Button * cancelButton = new ui::Button(ui::Point(0, Size.Y-16), ui::Point(Size.X-50, 16), "Cancel"); textField = new ui::Textbox(ui::Point(4, 45 ), ui::Point(Size.X-8, 16), "", "Reason");
cancelButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; cancelButton->Appearance.VerticalAlign = ui::Appearance::AlignBottom; if(multiline)
{
textField->SetMultiline(true);
textField->Size.Y = 60;
Size.Y += 45;
textField->Appearance.VerticalAlign = ui::Appearance::AlignTop;
}
else
{
textField->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
}
textField->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
AddComponent(textField);
ui::Button * cancelButton = new ui::Button(ui::Point(0, Size.Y-16), ui::Point((Size.X/2)+1, 16), "Cancel");
cancelButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
cancelButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
cancelButton->Appearance.BorderInactive = ui::Colour(200, 200, 200); cancelButton->Appearance.BorderInactive = ui::Colour(200, 200, 200);
cancelButton->SetActionCallback(new CloseAction(this, ResultCancel)); cancelButton->SetActionCallback(new CloseAction(this, ResultCancel));
AddComponent(cancelButton); AddComponent(cancelButton);
ui::Button * okayButton = new ui::Button(ui::Point(Size.X-50, Size.Y-16), ui::Point(50, 16), "Okay"); ui::Button * okayButton = new ui::Button(ui::Point(Size.X/2, Size.Y-16), ui::Point(Size.X/2, 16), "Okay");
okayButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; okayButton->Appearance.VerticalAlign = ui::Appearance::AlignBottom; okayButton->Appearance.HorizontalAlign = ui::Appearance::AlignRight;
okayButton->Appearance.TextInactive = ui::Colour(220, 220, 50); okayButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
okayButton->Appearance.TextInactive = style::Colour::WarningTitle;
okayButton->SetActionCallback(new CloseAction(this, ResultOkay)); okayButton->SetActionCallback(new CloseAction(this, ResultOkay));
AddComponent(okayButton); AddComponent(okayButton);
textField = new ui::Textbox(ui::Point(4, 32), ui::Point(Size.X-8, 16), "");
textField->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; textField->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
AddComponent(textField);
ui::Engine::Ref().ShowWindow(this); ui::Engine::Ref().ShowWindow(this);
} }

View File

@ -1285,11 +1285,11 @@ void GameView::OnDraw()
fpsInfo << "Snapshot " << SNAPSHOT_ID << ". "; fpsInfo << "Snapshot " << SNAPSHOT_ID << ". ";
#endif #endif
fpsInfo << "FPS: " << std::fixed << ui::Engine::Ref().GetFps(); fpsInfo << "FPS: " << std::fixed << ui::Engine::Ref().GetFps();
#endif
textWidth = Graphics::textwidth((char*)fpsInfo.str().c_str()); textWidth = Graphics::textwidth((char*)fpsInfo.str().c_str());
g->fillrect(12, 12, textWidth+8, 15, 0, 0, 0, 255*0.5); g->fillrect(12, 12, textWidth+8, 15, 0, 0, 0, 255*0.5);
g->drawtext(16, 16, (const char*)fpsInfo.str().c_str(), 32, 216, 255, 255*0.75); g->drawtext(16, 16, (const char*)fpsInfo.str().c_str(), 32, 216, 255, 255*0.75);
#endif
//Tooltips //Tooltips
if(infoTipPresence) if(infoTipPresence)