Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GUI: Account for the scroll bar size in ScrollContainerWidget objects #4569

Merged
merged 2 commits into from
May 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions backends/keymapper/remap-widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void RemapWidget::reflowActionWidgets() {
int spacing = g_gui.xmlEval()->getVar("Globals.KeyMapper.Spacing");
int keyButtonWidth = g_gui.xmlEval()->getVar("Globals.KeyMapper.ButtonWidth");
int resetButtonWidth = g_gui.xmlEval()->getVar("Globals.KeyMapper.ResetWidth");
int labelWidth = widgetsBoss()->getWidth() - (spacing + keyButtonWidth + spacing);
int labelWidth = getWidth() - (spacing + keyButtonWidth + spacing);
labelWidth = MAX(0, labelWidth);

uint textYOff = (buttonHeight - kLineHeight) / 2;
Expand All @@ -121,7 +121,7 @@ void RemapWidget::reflowActionWidgets() {

// Insert a keymap separator
uint descriptionX = 2 * spacing + keyButtonWidth;
uint resetX = widgetsBoss()->getWidth() - spacing - resetButtonWidth;
uint resetX = getWidth() - spacing - resetButtonWidth;

KeymapTitleRow keymapTitle = _keymapSeparators[row.keymap];
if (keymapTitle.descriptionText) {
Expand Down
6 changes: 6 additions & 0 deletions gui/ThemeEval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ ThemeEval &ThemeEval::addWidget(const Common::String &name, const Common::String
typeH == -1 ? h : typeH,
typeAlign == Graphics::kTextAlignInvalid ? align : typeAlign,
getVar("Globals.TabWidget.Tab.Height", 0));
else if (type == "ScrollContainerWidget")
widget = new ThemeLayoutScrollContainerWidget(_curLayout.top(), name,
typeW == -1 ? w : typeW,
typeH == -1 ? h : typeH,
typeAlign == Graphics::kTextAlignInvalid ? align : typeAlign,
getVar("Globals.Scrollbar.Width", 0));
else
widget = new ThemeLayoutWidget(_curLayout.top(), name,
typeW == -1 ? w : typeW,
Expand Down
35 changes: 35 additions & 0 deletions gui/ThemeLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class ThemeLayout {
kLayoutHorizontal,
kLayoutWidget,
kLayoutTabWidget,
kLayoutScrollContainerWidget,
kLayoutSpace
};

Expand Down Expand Up @@ -285,6 +286,40 @@ class ThemeLayoutTabWidget : public ThemeLayoutWidget {
}
};

class ThemeLayoutScrollContainerWidget : public ThemeLayoutWidget {
int _scrollWidth;

public:
ThemeLayoutScrollContainerWidget(ThemeLayout *p, const Common::String &name, int16 w, int16 h, Graphics::TextAlign align, int scrollWidth):
ThemeLayoutWidget(p, name, w, h, align, p->getUseRTL()) {
_scrollWidth = scrollWidth;
}

void reflowLayout(Widget *widgetChain) override {
for (uint i = 0; i < _children.size(); ++i) {
_children[i]->reflowLayout(widgetChain);
}
}

bool getWidgetData(const Common::String &name, int16 &x, int16 &y, int16 &w, int16 &h, bool &useRTL) override {
if (ThemeLayoutWidget::getWidgetData(name, x, y, w, h, useRTL)) {
w -= _scrollWidth;
return true;
}

return false;
}

protected:
LayoutType getLayoutType() const override { return kLayoutScrollContainerWidget; }

ThemeLayout *makeClone(ThemeLayout *newParent) override {
ThemeLayoutScrollContainerWidget *n = new ThemeLayoutScrollContainerWidget(*this);
n->_parent = newParent;
return n;
}
};

class ThemeLayoutSpacing : public ThemeLayout {
public:
ThemeLayoutSpacing(ThemeLayout *p, int size) : ThemeLayout(p) {
Expand Down
25 changes: 19 additions & 6 deletions gui/themes/common/highres_layout.stx
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,9 @@

<dialog name = 'GlobalOptions_Graphics' overlays = 'Dialog.GlobalOptions.TabWidget'>
<layout type = 'vertical' padding = '0, 0, 0, 0'>
<widget name = 'Container'/>
<widget name = 'Container'
type = 'ScrollContainerWidget'
/>
</layout>
</dialog>
<dialog name = 'GlobalOptions_Graphics_Container' overlays = 'GlobalOptions_Graphics.Container'>
Expand Down Expand Up @@ -778,7 +780,9 @@

<dialog name = 'GlobalOptions_Misc' overlays = 'Dialog.GlobalOptions.TabWidget'>
<layout type = 'vertical' padding = '0, 0, 0, 0'>
<widget name = 'Container'/>
<widget name = 'Container'
type = 'ScrollContainerWidget'
/>
</layout>
</dialog>

Expand Down Expand Up @@ -868,7 +872,9 @@

<dialog name = 'GlobalOptions_Cloud' overlays = 'Dialog.GlobalOptions.TabWidget'>
<layout type = 'vertical' padding = '0, 0, 0, 0'>
<widget name = 'Container'/>
<widget name = 'Container'
type = 'ScrollContainerWidget'
/>
</layout>
</dialog>

Expand Down Expand Up @@ -1275,13 +1281,17 @@

<dialog name = 'GameOptions_Achievements' overlays = 'Dialog.GameOptions.TabWidget'>
<layout type = 'vertical' padding = '0, 0, 0, 0'>
<widget name = 'Container'/>
<widget name = 'Container'
type = 'ScrollContainerWidget'
/>
</layout>
</dialog>

<dialog name = 'GameOptions_Graphics' overlays = 'Dialog.GameOptions.TabWidget'>
<layout type = 'vertical' padding = '0, 0, 0, 0'>
<widget name = 'Container'/>
<widget name = 'Container'
type = 'ScrollContainerWidget'
/>
</layout>
</dialog>
<dialog name = 'GameOptions_Graphics_Container' overlays = 'GameOptions_Graphics.Container'>
Expand Down Expand Up @@ -1569,7 +1579,9 @@

<dialog name = 'GlobalConfig_Achievements' overlays = 'Dialog.GlobalConfig.TabWidget'>
<layout type = 'vertical' padding = '0, 0, 0, 0'>
<widget name = 'Container'/>
<widget name = 'Container'
type = 'ScrollContainerWidget'
/>
</layout>
</dialog>

Expand Down Expand Up @@ -2118,6 +2130,7 @@
<dialog name = 'UnknownGameDialog' overlays = 'Dialog.Launcher.GameList' shading = 'dim'>
<layout type = 'vertical' padding = '8, 8, 8, 0'>
<widget name = 'TextContainer'
type = 'ScrollContainerWidget'
/>
<layout type = 'horizontal' padding = '0, 0, 16, 16'>
<space/>
Expand Down
25 changes: 19 additions & 6 deletions gui/themes/common/lowres_layout.stx
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,9 @@

<dialog name = 'GlobalOptions_Graphics' overlays = 'Dialog.GlobalOptions.TabWidget'>
<layout type = 'vertical' padding = '0, 0, 0, 0'>
<widget name = 'Container'/>
<widget name = 'Container'
type = 'ScrollContainerWidget'
/>
</layout>
</dialog>
<dialog name = 'GlobalOptions_Graphics_Container' overlays = 'GlobalOptions_Graphics.Container'>
Expand Down Expand Up @@ -716,7 +718,9 @@

<dialog name = 'GlobalOptions_Misc' overlays = 'Dialog.GlobalOptions.TabWidget'>
<layout type = 'vertical' padding = '0, 0, 0, 0'>
<widget name = 'Container'/>
<widget name = 'Container'
type = 'ScrollContainerWidget'
/>
</layout>
</dialog>

Expand Down Expand Up @@ -816,7 +820,9 @@

<dialog name = 'GlobalOptions_Cloud' overlays = 'Dialog.GlobalOptions.TabWidget'>
<layout type = 'vertical' padding = '0, 0, 0, 0'>
<widget name = 'Container'/>
<widget name = 'Container'
type = 'ScrollContainerWidget'
/>
</layout>
</dialog>

Expand Down Expand Up @@ -1206,13 +1212,17 @@

<dialog name = 'GameOptions_Achievements' overlays = 'Dialog.GameOptions.TabWidget'>
<layout type = 'vertical' padding = '0, 0, 0, 0'>
<widget name = 'Container'/>
<widget name = 'Container'
type = 'ScrollContainerWidget'
/>
</layout>
</dialog>

<dialog name = 'GameOptions_Graphics' overlays = 'Dialog.GameOptions.TabWidget'>
<layout type = 'vertical' padding = '0, 0, 0, 0'>
<widget name = 'Container'/>
<widget name = 'Container'
type = 'ScrollContainerWidget'
/>
</layout>
</dialog>
<dialog name = 'GameOptions_Graphics_Container' overlays = 'GameOptions_Graphics.Container'>
Expand Down Expand Up @@ -1509,7 +1519,9 @@

<dialog name = 'GlobalConfig_Achievements' overlays = 'Dialog.GlobalConfig.TabWidget'>
<layout type = 'vertical' padding = '0, 0, 0, 0'>
<widget name = 'Container'/>
<widget name = 'Container'
type = 'ScrollContainerWidget'
/>
</layout>
</dialog>

Expand Down Expand Up @@ -2037,6 +2049,7 @@
<dialog name = 'UnknownGameDialog' overlays = 'screen' inset = '8' shading = 'dim'>
<layout type = 'vertical' padding = '8, 8, 8, 0'>
<widget name = 'TextContainer'
type = 'ScrollContainerWidget'
/>
<layout type = 'horizontal' padding = '0, 0, 8, 8'>
<space/>
Expand Down
25 changes: 19 additions & 6 deletions gui/themes/scummclassic/classic_layout.stx
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,9 @@

<dialog name = 'GlobalOptions_Graphics' overlays = 'Dialog.GlobalOptions.TabWidget'>
<layout type = 'vertical' padding = '0, 0, 0, 0'>
<widget name = 'Container'/>
<widget name = 'Container'
type = 'ScrollContainerWidget'
/>
</layout>
</dialog>
<dialog name = 'GlobalOptions_Graphics_Container' overlays = 'GlobalOptions_Graphics.Container'>
Expand Down Expand Up @@ -630,7 +632,9 @@

<dialog name = 'GlobalOptions_Misc' overlays = 'Dialog.GlobalOptions.TabWidget'>
<layout type = 'vertical' padding = '0, 0, 0, 0'>
<widget name = 'Container'/>
<widget name = 'Container'
type = 'ScrollContainerWidget'
/>
</layout>
</dialog>

Expand Down Expand Up @@ -720,7 +724,9 @@

<dialog name = 'GlobalOptions_Cloud' overlays = 'Dialog.GlobalOptions.TabWidget'>
<layout type = 'vertical' padding = '0, 0, 0, 0'>
<widget name = 'Container'/>
<widget name = 'Container'
type = 'ScrollContainerWidget'
/>
</layout>
</dialog>

Expand Down Expand Up @@ -1112,13 +1118,17 @@

<dialog name = 'GameOptions_Achievements' overlays = 'Dialog.GameOptions.TabWidget'>
<layout type = 'vertical' padding = '0, 0, 0, 0'>
<widget name = 'Container'/>
<widget name = 'Container'
type = 'ScrollContainerWidget'
/>
</layout>
</dialog>

<dialog name = 'GameOptions_Graphics' overlays = 'Dialog.GameOptions.TabWidget'>
<layout type = 'vertical' padding = '0, 0, 0, 0'>
<widget name = 'Container'/>
<widget name = 'Container'
type = 'ScrollContainerWidget'
/>
</layout>
</dialog>
<dialog name = 'GameOptions_Graphics_Container' overlays = 'GameOptions_Graphics.Container'>
Expand Down Expand Up @@ -1406,7 +1416,9 @@

<dialog name = 'GlobalConfig_Achievements' overlays = 'Dialog.GlobalConfig.TabWidget'>
<layout type = 'vertical' padding = '0, 0, 0, 0'>
<widget name = 'Container'/>
<widget name = 'Container'
type = 'ScrollContainerWidget'
/>
</layout>
</dialog>

Expand Down Expand Up @@ -1953,6 +1965,7 @@
<dialog name = 'UnknownGameDialog' overlays = 'Dialog.Launcher.GameList' shading = 'dim'>
<layout type = 'vertical' padding = '8, 8, 8, 0'>
<widget name = 'TextContainer'
type = 'ScrollContainerWidget'
/>
<layout type = 'horizontal' padding = '0, 0, 16, 16'>
<space/>
Expand Down
25 changes: 19 additions & 6 deletions gui/themes/scummclassic/classic_layout_lowres.stx
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,9 @@

<dialog name = 'GlobalOptions_Graphics' overlays = 'Dialog.GlobalOptions.TabWidget'>
<layout type = 'vertical' padding = '0, 0, 0, 0'>
<widget name = 'Container'/>
<widget name = 'Container'
type = 'ScrollContainerWidget'
/>
</layout>
</dialog>
<dialog name = 'GlobalOptions_Graphics_Container' overlays = 'GlobalOptions_Graphics.Container'>
Expand Down Expand Up @@ -638,7 +640,9 @@

<dialog name = 'GlobalOptions_Misc' overlays = 'Dialog.GlobalOptions.TabWidget'>
<layout type = 'vertical' padding = '0, 0, 0, 0'>
<widget name = 'Container'/>
<widget name = 'Container'
type = 'ScrollContainerWidget'
/>
</layout>
</dialog>

Expand Down Expand Up @@ -738,7 +742,9 @@

<dialog name = 'GlobalOptions_Cloud' overlays = 'Dialog.GlobalOptions.TabWidget'>
<layout type = 'vertical' padding = '0, 0, 0, 0'>
<widget name = 'Container'/>
<widget name = 'Container'
type = 'ScrollContainerWidget'
/>
</layout>
</dialog>

Expand Down Expand Up @@ -1127,13 +1133,17 @@

<dialog name = 'GameOptions_Achievements' overlays = 'Dialog.GameOptions.TabWidget'>
<layout type = 'vertical' padding = '0, 0, 0, 0'>
<widget name = 'Container'/>
<widget name = 'Container'
type = 'ScrollContainerWidget'
/>
</layout>
</dialog>

<dialog name = 'GameOptions_Graphics' overlays = 'Dialog.GameOptions.TabWidget'>
<layout type = 'vertical' padding = '0, 0, 0, 0'>
<widget name = 'Container'/>
<widget name = 'Container'
type = 'ScrollContainerWidget'
/>
</layout>
</dialog>
<dialog name = 'GameOptions_Graphics_Container' overlays = 'GameOptions_Graphics.Container'>
Expand Down Expand Up @@ -1429,7 +1439,9 @@

<dialog name = 'GlobalConfig_Achievements' overlays = 'Dialog.GlobalConfig.TabWidget'>
<layout type = 'vertical' padding = '0, 0, 0, 0'>
<widget name = 'Container'/>
<widget name = 'Container'
type = 'ScrollContainerWidget'
/>
</layout>
</dialog>

Expand Down Expand Up @@ -1936,6 +1948,7 @@
<dialog name = 'UnknownGameDialog' overlays = 'screen' inset = '8' shading = 'dim'>
<layout type = 'vertical' padding = '8, 8, 8, 0'>
<widget name = 'TextContainer'
type = 'ScrollContainerWidget'
/>
<layout type = 'horizontal' padding = '0, 0, 8, 8'>
<space/>
Expand Down
2 changes: 1 addition & 1 deletion gui/widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ void Widget::draw() {
Widget *Widget::findWidgetInChain(Widget *w, int x, int y) {
while (w) {
// Stop as soon as we find a widget that contains the point (x,y)
if (x >= w->_x && x < w->_x + w->_w && y >= w->_y && y < w->_y + w->getHeight())
if (x >= w->_x && x < w->_x + w->getWidth() && y >= w->_y && y < w->_y + w->getHeight())
break;
w = w->_next;
}
Expand Down
Loading