aboutsummaryrefslogtreecommitdiff
path: root/gui/widgets
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/widgets
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/widgets')
-rw-r--r--gui/widgets/list.cpp10
-rw-r--r--gui/widgets/scrollcontainer.cpp8
-rw-r--r--gui/widgets/scrollcontainer.h3
-rw-r--r--gui/widgets/tab.cpp7
-rw-r--r--gui/widgets/tab.h3
5 files changed, 18 insertions, 13 deletions
diff --git a/gui/widgets/list.cpp b/gui/widgets/list.cpp
index 3ef365ba5c..9144282e65 100644
--- a/gui/widgets/list.cpp
+++ b/gui/widgets/list.cpp
@@ -36,10 +36,7 @@ namespace GUI {
ListWidget::ListWidget(Dialog *boss, const String &name, const char *tooltip, uint32 cmd)
: EditableWidget(boss, name, tooltip), _cmd(cmd) {
- _scrollBar = NULL;
-
- // This ensures that _entriesPerPage is properly initialized.
- reflowLayout();
+ _entriesPerPage = 0;
_scrollBar = new ScrollBarWidget(this, _w - _scrollBarWidth, 0, _scrollBarWidth, _h);
_scrollBar->setTarget(this);
@@ -69,10 +66,7 @@ ListWidget::ListWidget(Dialog *boss, const String &name, const char *tooltip, ui
ListWidget::ListWidget(Dialog *boss, int x, int y, int w, int h, const char *tooltip, uint32 cmd)
: EditableWidget(boss, x, y, w, h, tooltip), _cmd(cmd) {
- _scrollBar = NULL;
-
- // This ensures that _entriesPerPage is properly initialized.
- reflowLayout();
+ _entriesPerPage = 0;
_scrollBar = new ScrollBarWidget(this, _w - _scrollBarWidth, 0, _scrollBarWidth, _h);
_scrollBar->setTarget(this);
diff --git a/gui/widgets/scrollcontainer.cpp b/gui/widgets/scrollcontainer.cpp
index c136c57a81..e0680e123b 100644
--- a/gui/widgets/scrollcontainer.cpp
+++ b/gui/widgets/scrollcontainer.cpp
@@ -33,8 +33,8 @@ ScrollContainerWidget::ScrollContainerWidget(GuiObject *boss, int x, int y, int
init();
}
-ScrollContainerWidget::ScrollContainerWidget(GuiObject *boss, const Common::String &name, uint32 reflowCmd)
- : Widget(boss, name), CommandSender(nullptr), _reflowCmd(reflowCmd) {
+ScrollContainerWidget::ScrollContainerWidget(GuiObject *boss, const Common::String &name, const Common::String &dialogName, uint32 reflowCmd)
+ : Widget(boss, name), CommandSender(nullptr), _reflowCmd(reflowCmd), _dialogName(dialogName) {
init();
}
@@ -119,6 +119,10 @@ void ScrollContainerWidget::handleCommand(CommandSender *sender, uint32 cmd, uin
void ScrollContainerWidget::reflowLayout() {
Widget::reflowLayout();
+ if (!_dialogName.empty()) {
+ g_gui.xmlEval()->reflowDialogLayout(_dialogName, _firstWidget);
+ }
+
//reflow layout of inner widgets
Widget *ptr = _firstWidget;
while (ptr) {
diff --git a/gui/widgets/scrollcontainer.h b/gui/widgets/scrollcontainer.h
index c034cab4fd..fd8db765a3 100644
--- a/gui/widgets/scrollcontainer.h
+++ b/gui/widgets/scrollcontainer.h
@@ -35,12 +35,13 @@ class ScrollContainerWidget: public Widget, public CommandSender {
uint16 _limitH;
uint32 _reflowCmd;
ThemeEngine::DialogBackground _backgroundType;
+ Common::String _dialogName;
void recalc();
public:
ScrollContainerWidget(GuiObject *boss, int x, int y, int w, int h, uint32 reflowCmd = 0);
- ScrollContainerWidget(GuiObject *boss, const Common::String &name, uint32 reflowCmd = 0);
+ ScrollContainerWidget(GuiObject *boss, const Common::String &name, const Common::String &dialogName, uint32 reflowCmd = 0);
~ScrollContainerWidget() override;
void init();
diff --git a/gui/widgets/tab.cpp b/gui/widgets/tab.cpp
index d373bc9222..1ca61565aa 100644
--- a/gui/widgets/tab.cpp
+++ b/gui/widgets/tab.cpp
@@ -104,10 +104,11 @@ uint16 TabWidget::getHeight() const {
return _h + _tabHeight;
}
-int TabWidget::addTab(const String &title) {
+int TabWidget::addTab(const String &title, const String &dialogName) {
// Add a new tab page
Tab newTab;
newTab.title = title;
+ newTab.dialogName = dialogName;
newTab.firstWidget = 0;
// Determine the new tab width
@@ -300,6 +301,10 @@ void TabWidget::reflowLayout() {
_tabs[_activeTab].firstWidget = _firstWidget;
for (uint i = 0; i < _tabs.size(); ++i) {
+ if (!_tabs[i].dialogName.empty()) {
+ g_gui.xmlEval()->reflowDialogLayout(_tabs[i].dialogName, _tabs[i].firstWidget);
+ }
+
Widget *w = _tabs[i].firstWidget;
while (w) {
w->reflowLayout();
diff --git a/gui/widgets/tab.h b/gui/widgets/tab.h
index 8411509bd0..1aa9ded031 100644
--- a/gui/widgets/tab.h
+++ b/gui/widgets/tab.h
@@ -38,6 +38,7 @@ class TabWidget : public Widget {
typedef Common::String String;
struct Tab {
String title;
+ String dialogName;
Widget *firstWidget;
int _tabWidth;
};
@@ -73,7 +74,7 @@ public:
* Add a new tab with the given title. Returns a unique ID which can be used
* to identify the tab (to remove it / activate it etc.).
*/
- int addTab(const String &title);
+ int addTab(const String &title, const String &dialogName);
/**
* Remove the tab with the given tab ID. Disposes all child widgets of that tab.