diff options
author | Bastien Bouclet | 2019-12-28 10:43:58 +0100 |
---|---|---|
committer | Bastien Bouclet | 2020-01-04 10:56:25 +0100 |
commit | c0d8b6d9fc73abc8de4575686e0776e3468d37b2 (patch) | |
tree | 156e4305363210c7a52a2d90985d71e1cd22a4ce /gui/widget.cpp | |
parent | 303ee2694f4e85d3d9796068e33d2d48ca100e8a (diff) | |
download | scummvm-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/widget.cpp')
-rw-r--r-- | gui/widget.cpp | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/gui/widget.cpp b/gui/widget.cpp index bbb8b06ee6..17098df6ea 100644 --- a/gui/widget.cpp +++ b/gui/widget.cpp @@ -45,6 +45,7 @@ Widget::Widget(GuiObject *boss, int x, int y, int w, int h, const char *tooltip) Widget::Widget(GuiObject *boss, const Common::String &name, const char *tooltip) : GuiObject(name), _type(0), _boss(boss), _tooltip(tooltip), _id(0), _flags(0), _hasFocus(false), _state(ThemeEngine::kStateDisabled) { + reflowLayout(); init(); } @@ -341,6 +342,13 @@ ButtonWidget::ButtonWidget(GuiObject *boss, const Common::String &name, const Co _type = kButtonWidget; } +void ButtonWidget::getMinSize(int &minWidth, int &minHeight) { + const Graphics::Font &font = g_gui.getFont(_font); + + minWidth = font.getStringWidth(_label); + minHeight = font.getFontHeight(); +} + void ButtonWidget::handleMouseUp(int x, int y, int button, int clickCount) { if (isEnabled() && _duringPress && x >= 0 && x < _w && y >= 0 && y < _h) { setUnpressedState(); @@ -476,6 +484,14 @@ void DropdownButtonWidget::reflowLayout() { reset(); } +void DropdownButtonWidget::getMinSize(int &minWidth, int &minHeight) { + ButtonWidget::getMinSize(minWidth, minHeight); + + if (minWidth >= 0) { + minWidth += _dropdownWidth * 2; + } +} + void DropdownButtonWidget::appendEntry(const Common::String &label, uint32 cmd) { Entry e; e.label = label; @@ -838,12 +854,16 @@ void GraphicsWidget::drawWidget() { #pragma mark - -ContainerWidget::ContainerWidget(GuiObject *boss, int x, int y, int w, int h) : Widget(boss, x, y, w, h) { +ContainerWidget::ContainerWidget(GuiObject *boss, int x, int y, int w, int h) : + Widget(boss, x, y, w, h), + _backgroundType(ThemeEngine::kWidgetBackgroundBorder) { setFlags(WIDGET_ENABLED | WIDGET_CLEARBG); _type = kContainerWidget; } -ContainerWidget::ContainerWidget(GuiObject *boss, const Common::String &name) : Widget(boss, name) { +ContainerWidget::ContainerWidget(GuiObject *boss, const Common::String &name) : + Widget(boss, name), + _backgroundType(ThemeEngine::kWidgetBackgroundBorder) { setFlags(WIDGET_ENABLED | WIDGET_CLEARBG); _type = kContainerWidget; } @@ -875,9 +895,12 @@ void ContainerWidget::removeWidget(Widget *widget) { Widget::removeWidget(widget); } +void ContainerWidget::setBackgroundType(ThemeEngine::WidgetBackground backgroundType) { + _backgroundType = backgroundType; +} + void ContainerWidget::drawWidget() { - g_gui.theme()->drawWidgetBackground(Common::Rect(_x, _y, _x + _w, _y + _h), 0, - ThemeEngine::kWidgetBackgroundBorder); + g_gui.theme()->drawWidgetBackground(Common::Rect(_x, _y, _x + _w, _y + _h), 0, _backgroundType); } } // End of namespace GUI |