diff options
author | Thierry Crozat | 2018-05-28 22:03:20 +0100 |
---|---|---|
committer | Thierry Crozat | 2018-05-28 22:21:10 +0100 |
commit | 42cd3e9596e7004060518081b694a3e59efd6496 (patch) | |
tree | 3e5a77336650fc066673f122523f94719dbf52cd | |
parent | 567abfcefb598164ae4ba6142865869548a1d2ea (diff) | |
download | scummvm-rg350-42cd3e9596e7004060518081b694a3e59efd6496.tar.gz scummvm-rg350-42cd3e9596e7004060518081b694a3e59efd6496.tar.bz2 scummvm-rg350-42cd3e9596e7004060518081b694a3e59efd6496.zip |
GUI: Use ScrollContainerWidget in unknown game dialog
This should fix issues when the text to display in the dialog is
too big to fit on the screen.
-rw-r--r-- | gui/unknown-game-dialog.cpp | 32 | ||||
-rw-r--r-- | gui/unknown-game-dialog.h | 5 |
2 files changed, 28 insertions, 9 deletions
diff --git a/gui/unknown-game-dialog.cpp b/gui/unknown-game-dialog.cpp index 01526d21ea..80446c5bcb 100644 --- a/gui/unknown-game-dialog.cpp +++ b/gui/unknown-game-dialog.cpp @@ -30,13 +30,15 @@ #include "gui/message.h" #include "gui/ThemeEval.h" #include "gui/widgets/popup.h" +#include "gui/widgets/scrollcontainer.h" namespace GUI { enum { kCopyToClipboard = 'cpcl', kOpenBugtrackerURL = 'ourl', - kClose = 'clse' + kClose = 'clse', + kScrollContainerReflow = 'SCRf' }; UnknownGameDialog::UnknownGameDialog(const DetectionResults &detectionResults) : @@ -59,16 +61,22 @@ UnknownGameDialog::UnknownGameDialog(const DetectionResults &detectionResults) : #endif const int screenW = g_system->getOverlayWidth(); + const int screenH = g_system->getOverlayHeight(); int buttonWidth = g_gui.xmlEval()->getVar("Globals.Button.Width", 0); int buttonHeight = g_gui.xmlEval()->getVar("Globals.Button.Height", 0); // Calculate the size the dialog needs + // We use a ScrollContainer to display the text, with a 2 * 8 pixels margin to the dialog border, + // the scrollbar, and 2 * 10 margin for the text in the container. + // We also keep 2 * 10 pixels between the screen border and the dialog. + int scrollbarWidth = g_gui.xmlEval()->getVar("Globals.Scrollbar.Width", 0); Common::Array<Common::String> lines; - int maxlineWidth = g_gui.getFont().wordWrapText(reportTranslated, screenW - 2 * 20, lines); + int maxlineWidth = g_gui.getFont().wordWrapText(reportTranslated, screenW - 2 * 20 - 16 - scrollbarWidth, lines); + int lineCount = lines.size() + 1; - _h = 3 * kLineHeight + lineCount * kLineHeight; + _h = MIN(screenH - 20, lineCount * kLineHeight + kLineHeight + buttonHeight + 24); // Buttons int closeButtonWidth = MAX(buttonWidth, g_gui.getFont().getStringWidth(_("Close")) + 10); @@ -80,7 +88,7 @@ UnknownGameDialog::UnknownGameDialog(const DetectionResults &detectionResults) : if (g_system->hasFeature(OSystem::kFeatureOpenUrl)) totalButtonWidth += 10 + openBugtrackerURLButtonWidth; - _w = MAX(MAX(maxlineWidth, 0), totalButtonWidth) + 20; + _w = MAX(MAX(maxlineWidth, 0) + 16 + scrollbarWidth, totalButtonWidth) + 20; int buttonPos = _w - closeButtonWidth - 10; new ButtonWidget(this, buttonPos, _h - buttonHeight - 8, buttonWidth, buttonHeight, _("Close"), 0, kClose); @@ -107,10 +115,14 @@ UnknownGameDialog::UnknownGameDialog(const DetectionResults &detectionResults) : #endif // Each line is represented by one static text item. - // TODO: Use a ScrollContainer widget instead of truncated text. - uint y = 10; - for (uint i = 0; i < lines.size(); i++) { - new StaticTextWidget(this, 10, y, _w, kLineHeight, lines[i], Graphics::kTextAlignLeft); + // Use a ScrollContainer for the report in case we have a lot of lines. + int containerHeight = _h - kLineHeight - buttonHeight - 8; + ScrollContainerWidget *container = new ScrollContainerWidget(this, 8, 8, _w - 16, containerHeight, kScrollContainerReflow); + container->setTarget(this); + uint y = 8; + for (uint i = 0; i < lines.size() ; i++) { + StaticTextWidget *widget = new StaticTextWidget(container, 10, y, _w - 36 - scrollbarWidth, kLineHeight, lines[i], Graphics::kTextAlignLeft); + _textWidgets.push_back(widget); y += kLineHeight; } } @@ -160,6 +172,10 @@ void UnknownGameDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 case kOpenBugtrackerURL: g_system->openUrl(generateBugtrackerURL()); break; + case kScrollContainerReflow: + for (uint i = 0; i < _textWidgets.size() ; i++) + _textWidgets[i]->setVisible(true); + break; } } diff --git a/gui/unknown-game-dialog.h b/gui/unknown-game-dialog.h index f7f9d5c118..79a1acfd39 100644 --- a/gui/unknown-game-dialog.h +++ b/gui/unknown-game-dialog.h @@ -24,11 +24,13 @@ #define GUI_UNKNOWN_GAME_DIALOG_H #include "gui/dialog.h" - +#include "common/array.h" #include "engines/game.h" namespace GUI { +class StaticTextWidget; + class UnknownGameDialog : public Dialog { public: UnknownGameDialog(const DetectionResults &detectionResults); @@ -41,6 +43,7 @@ private: Common::String generateBugtrackerURL(); const DetectionResults &_detectionResults; + Common::Array<GUI::StaticTextWidget *> _textWidgets; }; } // End of namespace GUI |