summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeterN <peter1138@openttd.org>2021-05-08 21:01:16 +0100
committerGitHub <noreply@github.com>2021-05-08 21:01:16 +0100
commit330a305c99766b2e62541a8956a00b2cbe7bbbe1 (patch)
tree1f95cc246dcbcd7b93466eec91100594a80dd15e
parentb9ab3bd6b3f28b682bf5e155bf35d7cbb8b8224a (diff)
downloadopenttd-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.
-rw-r--r--src/industry_gui.cpp2
-rw-r--r--src/news_gui.cpp2
-rw-r--r--src/town_gui.cpp4
-rw-r--r--src/vehicle_gui.cpp2
-rw-r--r--src/waypoint_gui.cpp2
-rw-r--r--src/widget.cpp16
6 files changed, 20 insertions, 8 deletions
diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp
index 147d4dc77..4e6c61ee2 100644
--- a/src/industry_gui.cpp
+++ b/src/industry_gui.cpp
@@ -1186,7 +1186,7 @@ static const NWidgetPart _nested_industry_view_widgets[] = {
EndContainer(),
NWidget(WWT_PANEL, COLOUR_CREAM),
NWidget(WWT_INSET, COLOUR_CREAM), SetPadding(2, 2, 2, 2),
- NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_IV_VIEWPORT), SetMinimalSize(254, 86), SetFill(1, 0), SetPadding(1, 1, 1, 1), SetResize(1, 1),
+ NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_IV_VIEWPORT), SetMinimalSize(254, 86), SetFill(1, 0), SetResize(1, 1),
EndContainer(),
EndContainer(),
NWidget(WWT_PANEL, COLOUR_CREAM, WID_IV_INFO), SetMinimalSize(260, 2), SetResize(1, 0),
diff --git a/src/news_gui.cpp b/src/news_gui.cpp
index 8d0531682..d3ddd463f 100644
--- a/src/news_gui.cpp
+++ b/src/news_gui.cpp
@@ -192,7 +192,7 @@ static const NWidgetPart _nested_small_news_widgets[] = {
/* Main part */
NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE, WID_N_HEADLINE),
NWidget(WWT_INSET, COLOUR_LIGHT_BLUE, WID_N_INSET), SetPadding(2, 2, 2, 2),
- NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_N_VIEWPORT), SetPadding(1, 1, 1, 1), SetMinimalSize(274, 47), SetFill(1, 0),
+ NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_N_VIEWPORT), SetMinimalSize(274, 47), SetFill(1, 0),
EndContainer(),
NWidget(WWT_EMPTY, COLOUR_WHITE, WID_N_MESSAGE), SetMinimalSize(275, 20), SetFill(1, 0), SetPadding(0, 5, 0, 5),
EndContainer(),
diff --git a/src/town_gui.cpp b/src/town_gui.cpp
index 22f8b757f..bd5893561 100644
--- a/src/town_gui.cpp
+++ b/src/town_gui.cpp
@@ -576,7 +576,7 @@ static const NWidgetPart _nested_town_game_view_widgets[] = {
EndContainer(),
NWidget(WWT_PANEL, COLOUR_BROWN),
NWidget(WWT_INSET, COLOUR_BROWN), SetPadding(2, 2, 2, 2),
- NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_TV_VIEWPORT), SetMinimalSize(254, 86), SetFill(1, 0), SetResize(1, 1), SetPadding(1, 1, 1, 1),
+ NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_TV_VIEWPORT), SetMinimalSize(254, 86), SetFill(1, 0), SetResize(1, 1),
EndContainer(),
EndContainer(),
NWidget(WWT_PANEL, COLOUR_BROWN, WID_TV_INFO), SetMinimalSize(260, 32), SetResize(1, 0), SetFill(1, 0), EndContainer(),
@@ -606,7 +606,7 @@ static const NWidgetPart _nested_town_editor_view_widgets[] = {
EndContainer(),
NWidget(WWT_PANEL, COLOUR_BROWN),
NWidget(WWT_INSET, COLOUR_BROWN), SetPadding(2, 2, 2, 2),
- NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_TV_VIEWPORT), SetMinimalSize(254, 86), SetFill(1, 1), SetResize(1, 1), SetPadding(1, 1, 1, 1),
+ NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_TV_VIEWPORT), SetMinimalSize(254, 86), SetFill(1, 1), SetResize(1, 1),
EndContainer(),
EndContainer(),
NWidget(WWT_PANEL, COLOUR_BROWN, WID_TV_INFO), SetMinimalSize(260, 32), SetResize(1, 0), SetFill(1, 0), EndContainer(),
diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp
index c6f2ee52a..006664491 100644
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -2485,7 +2485,7 @@ static const NWidgetPart _nested_vehicle_view_widgets[] = {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_PANEL, COLOUR_GREY),
NWidget(WWT_INSET, COLOUR_GREY), SetPadding(2, 2, 2, 2),
- NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_VV_VIEWPORT), SetMinimalSize(226, 84), SetResize(1, 1), SetPadding(1, 1, 1, 1),
+ NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_VV_VIEWPORT), SetMinimalSize(226, 84), SetResize(1, 1),
EndContainer(),
EndContainer(),
NWidget(NWID_VERTICAL),
diff --git a/src/waypoint_gui.cpp b/src/waypoint_gui.cpp
index 701fb736a..40c3401b0 100644
--- a/src/waypoint_gui.cpp
+++ b/src/waypoint_gui.cpp
@@ -155,7 +155,7 @@ static const NWidgetPart _nested_waypoint_view_widgets[] = {
EndContainer(),
NWidget(WWT_PANEL, COLOUR_GREY),
NWidget(WWT_INSET, COLOUR_GREY), SetPadding(2, 2, 2, 2),
- NWidget(NWID_VIEWPORT, COLOUR_GREY, WID_W_VIEWPORT), SetMinimalSize(256, 88), SetPadding(1, 1, 1, 1), SetResize(1, 1),
+ NWidget(NWID_VIEWPORT, COLOUR_GREY, WID_W_VIEWPORT), SetMinimalSize(256, 88), SetResize(1, 1),
EndContainer(),
EndContainer(),
NWidget(NWID_HORIZONTAL),
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};