Changeset - r25421:fdfa2939ff58
[Not reviewed]
master
0 6 0
PeterN - 4 years ago 2021-05-08 20:01:16
peter1138@openttd.org
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.
6 files changed with 20 insertions and 8 deletions:
0 comments (0 inline, 0 general)
src/industry_gui.cpp
Show inline comments
 
@@ -1186,7 +1186,7 @@ static const NWidgetPart _nested_industr
 
	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),
src/news_gui.cpp
Show inline comments
 
@@ -192,7 +192,7 @@ static const NWidgetPart _nested_small_n
 
	/* 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(),
src/town_gui.cpp
Show inline comments
 
@@ -576,7 +576,7 @@ static const NWidgetPart _nested_town_ga
 
	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_ed
 
	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(),
src/vehicle_gui.cpp
Show inline comments
 
@@ -2485,7 +2485,7 @@ static const NWidgetPart _nested_vehicle
 
	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),
src/waypoint_gui.cpp
Show inline comments
 
@@ -155,7 +155,7 @@ static const NWidgetPart _nested_waypoin
 
	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),
src/widget.cpp
Show inline comments
 
@@ -1904,8 +1904,11 @@ void NWidgetBackground::SetupSmallestSiz
 
		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::SetupSmallestSiz
 

	
 
			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};
0 comments (0 inline, 0 general)