diff options
author | PeterN <peter1138@openttd.org> | 2021-05-08 21:01:16 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-08 21:01:16 +0100 |
commit | 330a305c99766b2e62541a8956a00b2cbe7bbbe1 (patch) | |
tree | 1f95cc246dcbcd7b93466eec91100594a80dd15e /src/widget.cpp | |
parent | b9ab3bd6b3f28b682bf5e155bf35d7cbb8b8224a (diff) | |
download | openttd-330a305c99766b2e62541a8956a00b2cbe7bbbe1.tar.xz |
Fix: Apply unscaled padding to Viewport inside WWT_INSET. (#9219)
Since pixel dimensions in SetPadding() are scaled by GUI size, padding for inset viewports was excessive.
Instead, automatically apply padding for WWT_INSET at widget level. This applies to all widgets inside a WWT_INSET, which in all instances is a NWID_VIEWPORT.
Diffstat (limited to 'src/widget.cpp')
-rw-r--r-- | src/widget.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/widget.cpp b/src/widget.cpp index aaa00d4d7..638aa05fe 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -1904,8 +1904,11 @@ void NWidgetBackground::SetupSmallestSize(Window *w, bool init_array) this->resize_x = this->child->resize_x; this->resize_y = this->child->resize_y; - /* Account for the size of the frame's text if that exists */ - if (w != nullptr && this->type == WWT_FRAME) { + /* Don't apply automatic padding if there is no child widget. */ + if (w == nullptr) return; + + if (this->type == WWT_FRAME) { + /* Account for the size of the frame's text if that exists */ this->child->padding_left = WD_FRAMETEXT_LEFT; this->child->padding_right = WD_FRAMETEXT_RIGHT; this->child->padding_top = std::max((int)WD_FRAMETEXT_TOP, this->widget_data != STR_NULL ? FONT_HEIGHT_NORMAL + WD_FRAMETEXT_TOP / 2 : 0); @@ -1916,6 +1919,15 @@ void NWidgetBackground::SetupSmallestSize(Window *w, bool init_array) if (this->index >= 0) w->SetStringParameters(this->index); this->smallest_x = std::max(this->smallest_x, GetStringBoundingBox(this->widget_data).width + WD_FRAMETEXT_LEFT + WD_FRAMETEXT_RIGHT); + } else if (this->type == WWT_INSET) { + /* Apply automatic padding for bevel thickness. */ + this->child->padding_left = WD_BEVEL_LEFT; + this->child->padding_right = WD_BEVEL_RIGHT; + this->child->padding_top = WD_BEVEL_TOP; + this->child->padding_bottom = WD_BEVEL_BOTTOM; + + this->smallest_x += this->child->padding_left + this->child->padding_right; + this->smallest_y += this->child->padding_top + this->child->padding_bottom; } } else { Dimension d = {this->min_x, this->min_y}; |