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.
This commit is contained in:
PeterN 2021-05-08 21:01:16 +01:00 committed by GitHub
parent b9ab3bd6b3
commit 330a305c99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 20 additions and 8 deletions

View File

@ -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),

View File

@ -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(),

View File

@ -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(),

View File

@ -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),

View File

@ -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),

View File

@ -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};