aboutsummaryrefslogtreecommitdiff
path: root/gui/ThemeEval.cpp
diff options
context:
space:
mode:
authorBastien Bouclet2019-12-28 10:43:58 +0100
committerBastien Bouclet2020-01-04 10:56:25 +0100
commitc0d8b6d9fc73abc8de4575686e0776e3468d37b2 (patch)
tree156e4305363210c7a52a2d90985d71e1cd22a4ce /gui/ThemeEval.cpp
parent303ee2694f4e85d3d9796068e33d2d48ca100e8a (diff)
downloadscummvm-rg350-c0d8b6d9fc73abc8de4575686e0776e3468d37b2.tar.gz
scummvm-rg350-c0d8b6d9fc73abc8de4575686e0776e3468d37b2.tar.bz2
scummvm-rg350-c0d8b6d9fc73abc8de4575686e0776e3468d37b2.zip
GUI: Introduce dynamic layouts
Prior to this change, a GUI layout was only affected by the screen size. Now, a layout can additionally be influenced by the GUI dialog and widgets that uses it. This capability is leveraged to implement the following features: * Layout elements that are not bound to a GUI widget do not take space. This means that dialogs where the widgets shown depend on for example a feature being enabled at configure time no longer have blank spaces. * Widgets can define a minimal required size for their contents not to be cut. For now this is only used for buttons so their width is always sufficient for their caption not to be cut. This mechanism could be applied to other widget types in the future.
Diffstat (limited to 'gui/ThemeEval.cpp')
-rw-r--r--gui/ThemeEval.cpp35
1 files changed, 16 insertions, 19 deletions
diff --git a/gui/ThemeEval.cpp b/gui/ThemeEval.cpp
index 5255587089..66b5db5fb7 100644
--- a/gui/ThemeEval.cpp
+++ b/gui/ThemeEval.cpp
@@ -105,30 +105,18 @@ void ThemeEval::addWidget(const Common::String &name, int w, int h, const Common
typeAlign == Graphics::kTextAlignInvalid ? align : typeAlign);
_curLayout.top()->addChild(widget);
- setVar(_curDialog + "." + name + ".Enabled", enabled ? 1 : 0);
+ setVar("Dialog." + _curDialog + "." + name + ".Enabled", enabled ? 1 : 0);
}
void ThemeEval::addDialog(const Common::String &name, const Common::String &overlays, bool enabled, int inset) {
- int16 x, y;
- uint16 w, h;
+ Common::String var = "Dialog." + name;
- ThemeLayout *layout = 0;
-
- if (overlays == "screen") {
- layout = new ThemeLayoutMain(inset, inset, g_system->getOverlayWidth() - 2 * inset, g_system->getOverlayHeight() - 2 * inset);
- } else if (overlays == "screen_center") {
- layout = new ThemeLayoutMain(-1, -1, -1, -1);
- } else if (getWidgetData(overlays, x, y, w, h)) {
- layout = new ThemeLayoutMain(x + inset, y + inset, w - 2 * inset, h - 2 * inset);
- }
-
- if (!layout)
- error("Error when loading dialog position for '%s'", overlays.c_str());
+ ThemeLayout *layout = new ThemeLayoutMain(name, overlays, enabled, inset);
- if (_layouts.contains(name))
- delete _layouts[name];
+ if (_layouts.contains(var))
+ delete _layouts[var];
- _layouts[name] = layout;
+ _layouts[var] = layout;
layout->setPadding(
getVar("Globals.Padding.Left", 0),
@@ -139,7 +127,7 @@ void ThemeEval::addDialog(const Common::String &name, const Common::String &over
_curLayout.push(layout);
_curDialog = name;
- setVar(name + ".Enabled", enabled ? 1 : 0);
+ setVar(var + ".Enabled", enabled ? 1 : 0);
}
void ThemeEval::addLayout(ThemeLayout::LayoutType type, int spacing, bool center) {
@@ -168,6 +156,15 @@ void ThemeEval::addSpace(int size) {
_curLayout.top()->addChild(space);
}
+void ThemeEval::reflowDialogLayout(const Common::String &name, Widget *widgetChain) {
+ if (!_layouts.contains("Dialog." + name)) {
+ warning("No layout found for dialog '%s'", name.c_str());
+ return;
+ }
+
+ _layouts["Dialog." + name]->reflowLayout(widgetChain);
+}
+
bool ThemeEval::addImportedLayout(const Common::String &name) {
if (!_layouts.contains(name))
return false;