Fix: Mis-sized widgets due to missing widget fill. (#14370)

In most places where we calculate and set widget resize step we neglect
to set widget fill step to match. Initial widget sizing uses fill step
instead of resize step, which means the initial size may not be a
multiple of the resize step as intended. In particular this will cause
WWT_MATRIX to be misrendered.

Whether or not this matters depends on the widget type being resized and
the window layout, however for consistency always set fill step to the
same as resize step when calculating.
This commit is contained in:
Peter Nelson 2025-06-17 17:40:11 +01:00 committed by GitHub
parent 4144865c73
commit e4cf6ca0ba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
28 changed files with 45 additions and 50 deletions

View File

@ -142,7 +142,7 @@ struct AIConfigWindow : public Window {
case WID_AIC_LIST:
this->line_height = GetCharacterHeight(FS_NORMAL) + padding.height;
resize.height = this->line_height;
fill.height = resize.height = this->line_height;
size.height = 8 * this->line_height;
break;
}

View File

@ -311,7 +311,7 @@ public:
case WID_RV_LEFT_MATRIX:
case WID_RV_RIGHT_MATRIX:
resize.height = GetEngineListHeight(this->window_number);
fill.height = resize.height = GetEngineListHeight(this->window_number);
size.height = (this->window_number <= VEH_ROAD ? 8 : 4) * resize.height;
break;

View File

@ -205,7 +205,7 @@ public:
sprite_dim = maxdim(sprite_dim, GetScaledSpriteSize(bridge_data.spec->sprite));
text_dim = maxdim(text_dim, GetStringBoundingBox(GetBridgeSelectString(bridge_data)));
}
resize.height = std::max(sprite_dim.height, text_dim.height) + padding.height; // Max of both sizes + account for matrix edges.
fill.height = resize.height = std::max(sprite_dim.height, text_dim.height) + padding.height; // Max of both sizes + account for matrix edges.
this->icon_width = sprite_dim.width; // Width of bridge icon.
size.width = this->icon_width + WidgetDimensions::scaled.hsep_normal + text_dim.width + padding.width;

View File

@ -1773,7 +1773,7 @@ struct BuildVehicleWindow : Window {
{
switch (widget) {
case WID_BV_LIST:
resize.height = GetEngineListHeight(this->vehicle_type);
fill.height = resize.height = GetEngineListHeight(this->vehicle_type);
size.height = 3 * resize.height;
size.width = std::max(size.width, this->badge_classes.GetTotalColumnsWidth() + GetVehicleImageCellSize(this->vehicle_type, EIT_PURCHASE).extend_left + GetVehicleImageCellSize(this->vehicle_type, EIT_PURCHASE).extend_right + 165) + padding.width;
break;

View File

@ -761,7 +761,7 @@ public:
size.height = 5 * this->line_height;
resize.width = 1;
resize.height = this->line_height;
fill.height = resize.height = this->line_height;
break;
}
@ -1937,7 +1937,7 @@ struct CompanyInfrastructureWindow : Window
size.width = max_label_width + WidgetDimensions::scaled.hsep_wide + this->count_width + WidgetDimensions::scaled.hsep_wide + this->cost_width;
size.width = std::max(size.width, max_header_width) + WidgetDimensions::scaled.framerect.Horizontal();
resize.height = GetCharacterHeight(FS_NORMAL);
fill.height = resize.height = GetCharacterHeight(FS_NORMAL);
}
void DrawWidget(const Rect &r, WidgetID widget) const override

View File

@ -621,7 +621,7 @@ public:
break;
case WID_SL_DRIVES_DIRECTORIES_LIST:
resize.height = GetCharacterHeight(FS_NORMAL);
fill.height = resize.height = GetCharacterHeight(FS_NORMAL);
size.height = resize.height * 10 + padding.height;
break;
case WID_SL_SORT_BYNAME:

View File

@ -531,7 +531,7 @@ struct FramerateWindow : Window {
size.width = 0;
size.height = GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal + MIN_ELEMENTS * GetCharacterHeight(FS_NORMAL);
resize.width = 0;
resize.height = GetCharacterHeight(FS_NORMAL);
fill.height = resize.height = GetCharacterHeight(FS_NORMAL);
for (PerformanceElement e : DISPLAY_ORDER_PFE) {
if (_pf_data[e].num_valid == 0) continue;
Dimension line_size;
@ -553,7 +553,7 @@ struct FramerateWindow : Window {
size.width = std::max(size.width, item_size.width);
size.height += GetCharacterHeight(FS_NORMAL) * MIN_ELEMENTS + WidgetDimensions::scaled.vsep_normal;
resize.width = 0;
resize.height = GetCharacterHeight(FS_NORMAL);
fill.height = resize.height = GetCharacterHeight(FS_NORMAL);
break;
}
}

View File

@ -141,7 +141,7 @@ struct GSConfigWindow : public Window {
case WID_GSC_SETTINGS:
this->line_height = std::max(SETTING_BUTTON_HEIGHT, GetCharacterHeight(FS_NORMAL)) + padding.height;
resize.width = 1;
resize.height = this->line_height;
fill.height = resize.height = this->line_height;
size.height = 5 * this->line_height;
break;

View File

@ -172,7 +172,7 @@ struct GoalListWindow : public Window {
Dimension d = GetStringBoundingBox(STR_GOALS_NONE);
resize.width = 1;
resize.height = d.height;
fill.height = resize.height = d.height;
d.height *= 5;
d.width += WidgetDimensions::scaled.framerect.Horizontal();

View File

@ -1163,7 +1163,7 @@ struct BaseCargoGraphWindow : BaseGraphWindow {
this->line_height = size.height;
size.height = this->line_height * 11; /* Default number of cargo types in most climates. */
resize.width = 0;
resize.height = this->line_height;
fill.height = resize.height = this->line_height;
}
void DrawWidget(const Rect &r, WidgetID widget) const override

View File

@ -430,8 +430,7 @@ public:
switch (widget) {
case WID_GL_LIST_GROUP:
size.width = this->ComputeGroupInfoSize();
resize.height = this->tiny_step_height;
fill.height = this->tiny_step_height;
fill.height = resize.height = this->tiny_step_height;
break;
case WID_GL_ALL_VEHICLES:
@ -450,7 +449,7 @@ public:
case WID_GL_LIST_VEHICLE:
this->ComputeGroupInfoSize();
resize.height = GetVehicleListHeight(this->vli.vtype, this->tiny_step_height);
fill.height = resize.height = GetVehicleListHeight(this->vli.vtype, this->tiny_step_height);
size.height = 4 * resize.height;
break;

View File

@ -444,7 +444,7 @@ public:
for (const auto &indtype : this->list) {
d = maxdim(d, GetStringBoundingBox(GetIndustrySpec(indtype)->name));
}
resize.height = std::max<uint>({this->legend.height, d.height, count.height}) + padding.height;
fill.height = resize.height = std::max<uint>({this->legend.height, d.height, count.height}) + padding.height;
d.width += this->badge_classes.GetTotalColumnsWidth() + this->legend.width + WidgetDimensions::scaled.hsep_wide + WidgetDimensions::scaled.hsep_normal + count.width + padding.width;
d.height = 5 * resize.height;
size = maxdim(size, d);
@ -1780,7 +1780,7 @@ public:
case WID_ID_INDUSTRY_LIST: {
Dimension d = GetStringBoundingBox(STR_INDUSTRY_DIRECTORY_NONE);
resize.height = d.height;
fill.height = resize.height = d.height;
d.height *= 5;
d.width += padding.width;
d.height += padding.height;
@ -2644,7 +2644,7 @@ struct IndustryCargoesWindow : public Window {
{
switch (widget) {
case WID_IC_PANEL:
resize.height = CargoesField::normal_height;
fill.height = resize.height = CargoesField::normal_height;
size.width = CargoesField::industry_width * 3 + CargoesField::cargo_field_width * 2 + WidgetDimensions::scaled.frametext.Horizontal();
size.height = CargoesField::small_height + 2 * resize.height + WidgetDimensions::scaled.frametext.Vertical();
break;

View File

@ -596,7 +596,7 @@ public:
}
case WID_NCL_MATRIX:
resize.height = std::max(this->checkbox_size.height, (uint)GetCharacterHeight(FS_NORMAL)) + padding.height;
fill.height = resize.height = std::max(this->checkbox_size.height, (uint)GetCharacterHeight(FS_NORMAL)) + padding.height;
size.height = 10 * resize.height;
break;
}

View File

@ -476,8 +476,7 @@ public:
{
switch (widget) {
case WID_NG_MATRIX:
resize.height = std::max(GetSpriteSize(SPR_BLOT).height, (uint)GetCharacterHeight(FS_NORMAL)) + padding.height;
fill.height = resize.height;
fill.height = resize.height = std::max(GetSpriteSize(SPR_BLOT).height, (uint)GetCharacterHeight(FS_NORMAL)) + padding.height;
size.height = 12 * resize.height;
break;
@ -1656,8 +1655,7 @@ public:
this->line_height = std::max(height, (uint)GetCharacterHeight(FS_NORMAL)) + padding.height;
resize.width = 1;
resize.height = this->line_height;
fill.height = this->line_height;
fill.height = resize.height = this->line_height;
size.height = std::max(size.height, 5 * this->line_height);
break;
}

View File

@ -359,7 +359,7 @@ struct NewGRFInspectWindow : Window {
}
case WID_NGRFI_MAINPANEL:
resize.height = std::max(11, GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal);
fill.height = resize.height = std::max(11, GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal);
resize.width = 1;
size.height = 5 * resize.height + WidgetDimensions::scaled.frametext.Vertical();
@ -888,9 +888,8 @@ struct SpriteAlignerWindow : Window {
d = maxdim(d, GetStringBoundingBox(GetString(STR_SPRITE_ALIGNER_SPRITE, spritefile->GetSimplifiedFilename(), GetParamMaxDigits(6))));
}
size.width = d.width + padding.width;
resize.height = GetCharacterHeight(FS_NORMAL) + padding.height;
fill.height = resize.height = GetCharacterHeight(FS_NORMAL) + padding.height;
resize.width = 1;
fill.height = resize.height;
break;
}

View File

@ -224,7 +224,7 @@ struct NewGRFParametersWindow : public Window {
this->line_height = std::max(SETTING_BUTTON_HEIGHT, GetCharacterHeight(FS_NORMAL)) + padding.height;
resize.width = 1;
resize.height = this->line_height;
fill.height = resize.height = this->line_height;
size.height = 5 * this->line_height;
break;
@ -730,7 +730,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
case WID_NS_FILE_LIST:
{
Dimension d = maxdim(GetScaledSpriteSize(SPR_SQUARE), GetScaledSpriteSize(SPR_WARNING_SIGN));
resize.height = std::max<uint>(d.height + 2U, GetCharacterHeight(FS_NORMAL));
fill.height = resize.height = std::max<uint>(d.height + 2U, GetCharacterHeight(FS_NORMAL));
size.height = std::max(size.height, padding.height + 6 * resize.height);
break;
}
@ -738,7 +738,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
case WID_NS_AVAIL_LIST:
{
Dimension d = maxdim(GetScaledSpriteSize(SPR_SQUARE), GetScaledSpriteSize(SPR_WARNING_SIGN));
resize.height = std::max<uint>(d.height + 2U, GetCharacterHeight(FS_NORMAL));
fill.height = resize.height = std::max<uint>(d.height + 2U, GetCharacterHeight(FS_NORMAL));
size.height = std::max(size.height, padding.height + 8 * resize.height);
break;
}
@ -2041,12 +2041,11 @@ struct SavePresetWindow : public Window {
{
switch (widget) {
case WID_SVP_PRESET_LIST: {
resize.height = GetCharacterHeight(FS_NORMAL);
fill.height = resize.height = GetCharacterHeight(FS_NORMAL);
size.height = 0;
for (uint i = 0; i < this->presets.size(); i++) {
Dimension d = GetStringBoundingBox(this->presets[i]);
size.width = std::max(size.width, d.width + padding.width);
resize.height = std::max(resize.height, d.height);
}
size.height = ClampU((uint)this->presets.size(), 5, 20) * resize.height + padding.height;
break;

View File

@ -1214,7 +1214,7 @@ struct MessageHistoryWindow : Window {
{
if (widget == WID_MH_BACKGROUND) {
this->line_height = GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal;
resize.height = this->line_height;
fill.height = resize.height = this->line_height;
/* Months are off-by-one, so it's actually 8. Not using
* month 12 because the 1 is usually less wide. */

View File

@ -822,7 +822,7 @@ public:
{
switch (widget) {
case WID_O_ORDER_LIST:
resize.height = GetCharacterHeight(FS_NORMAL);
fill.height = resize.height = GetCharacterHeight(FS_NORMAL);
size.height = 6 * resize.height + padding.height;
break;

View File

@ -268,7 +268,7 @@ void PickerWindow::UpdateWidgetSize(WidgetID widget, Dimension &size, const Dime
switch (widget) {
/* Class picker */
case WID_PW_CLASS_LIST:
resize.height = GetCharacterHeight(FS_NORMAL) + padding.height;
fill.height = resize.height = GetCharacterHeight(FS_NORMAL) + padding.height;
size.height = 5 * resize.height;
break;

View File

@ -112,7 +112,7 @@ struct ScriptListWindow : public Window {
this->line_height = GetCharacterHeight(FS_NORMAL) + padding.height;
resize.width = 1;
resize.height = this->line_height;
fill.height = resize.height = this->line_height;
size.height = 5 * this->line_height;
}
@ -345,7 +345,7 @@ struct ScriptSettingsWindow : public Window {
this->line_height = std::max(SETTING_BUTTON_HEIGHT, GetCharacterHeight(FS_NORMAL)) + padding.height;
resize.width = 1;
resize.height = this->line_height;
fill.height = resize.height = this->line_height;
size.height = 5 * this->line_height;
}
@ -789,7 +789,7 @@ struct ScriptDebugWindow : public Window {
void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
{
if (widget == WID_SCRD_LOG_PANEL) {
resize.height = GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal;
fill.height = resize.height = GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal;
size.height = 14 * resize.height + WidgetDimensions::scaled.framerect.Vertical();
}
}

View File

@ -856,7 +856,7 @@ struct GameOptionsWindow : Window {
}
case WID_GO_OPTIONSPANEL:
resize.height = SETTING_HEIGHT = std::max({(int)_setting_circle_size.height, SETTING_BUTTON_HEIGHT, GetCharacterHeight(FS_NORMAL)}) + WidgetDimensions::scaled.vsep_normal;
fill.height = resize.height = SETTING_HEIGHT = std::max({(int)_setting_circle_size.height, SETTING_BUTTON_HEIGHT, GetCharacterHeight(FS_NORMAL)}) + WidgetDimensions::scaled.vsep_normal;
resize.width = 1;
size.height = 8 * resize.height + WidgetDimensions::scaled.framerect.Vertical();

View File

@ -258,7 +258,7 @@ struct SignListWindow : Window, SignList {
case WID_SIL_LIST: {
Dimension spr_dim = GetSpriteSize(SPR_COMPANY_ICON);
this->text_offset = WidgetDimensions::scaled.frametext.left + spr_dim.width + 2; // 2 pixels space between icon and the sign text.
resize.height = std::max<uint>(GetCharacterHeight(FS_NORMAL), spr_dim.height + 2);
fill.height = resize.height = std::max<uint>(GetCharacterHeight(FS_NORMAL), spr_dim.height + 2);
Dimension d = {(uint)(this->text_offset + WidgetDimensions::scaled.frametext.right), padding.height + 5 * resize.height};
size = maxdim(size, d);
break;

View File

@ -469,7 +469,7 @@ public:
}
case WID_STL_LIST:
resize.height = std::max(GetCharacterHeight(FS_NORMAL), GetCharacterHeight(FS_SMALL) + ScaleGUITrad(3));
fill.height = resize.height = std::max(GetCharacterHeight(FS_NORMAL), GetCharacterHeight(FS_SMALL) + ScaleGUITrad(3));
size.height = padding.height + 5 * resize.height;
/* Determine appropriate width for mini station rating graph */
@ -1416,7 +1416,7 @@ struct StationViewWindow : public Window {
{
switch (widget) {
case WID_SV_WAITING:
resize.height = GetCharacterHeight(FS_NORMAL);
fill.height = resize.height = GetCharacterHeight(FS_NORMAL);
size.height = 4 * resize.height + padding.height;
this->expand_shrink_width = std::max(GetStringBoundingBox("-").width, GetStringBoundingBox("+").width);
break;
@ -2325,7 +2325,7 @@ struct SelectStationWindow : Window {
: GetString(STR_STATION_LIST_STATION, st->index, st->facilities)));
}
resize.height = d.height;
fill.height = resize.height = d.height;
d.height *= 5;
d.width += padding.width;
d.height += padding.height;

View File

@ -136,7 +136,7 @@ struct SubsidyListWindow : Window {
if (widget != WID_SUL_PANEL) return;
Dimension d = maxdim(GetStringBoundingBox(STR_SUBSIDIES_OFFERED_TITLE), GetStringBoundingBox(STR_SUBSIDIES_SUBSIDISED_TITLE));
resize.height = GetCharacterHeight(FS_NORMAL);
fill.height = resize.height = GetCharacterHeight(FS_NORMAL);
d.height *= 5;
d.width += WidgetDimensions::scaled.framerect.Horizontal();

View File

@ -124,7 +124,7 @@ void TextfileWindow::ReflowContent()
switch (widget) {
case WID_TF_BACKGROUND:
resize.width = GetCharacterHeight(FS_MONO); // Width is not available here as the font may not be loaded yet.
resize.height = GetCharacterHeight(FS_MONO);
fill.height = resize.height = GetCharacterHeight(FS_MONO);
size.height = 4 * resize.height + WidgetDimensions::scaled.frametext.Vertical(); // At least 4 lines are visible.
size.width = std::max(200u, size.width); // At least 200 pixels wide.

View File

@ -242,7 +242,7 @@ struct TimetableWindow : Window {
case WID_VT_ARRIVAL_DEPARTURE_SELECTION:
case WID_VT_TIMETABLE_PANEL:
resize.height = GetCharacterHeight(FS_NORMAL);
fill.height = resize.height = GetCharacterHeight(FS_NORMAL);
size.height = 8 * resize.height + padding.height;
break;

View File

@ -271,7 +271,7 @@ public:
break;
case WID_TA_RATING_INFO:
resize.height = std::max({this->icon_size.height + WidgetDimensions::scaled.vsep_normal, this->exclusive_size.height + WidgetDimensions::scaled.vsep_normal, (uint)GetCharacterHeight(FS_NORMAL)});
fill.height = resize.height = std::max({this->icon_size.height + WidgetDimensions::scaled.vsep_normal, this->exclusive_size.height + WidgetDimensions::scaled.vsep_normal, (uint)GetCharacterHeight(FS_NORMAL)});
size.height = 9 * resize.height + padding.height;
break;
}
@ -902,7 +902,7 @@ public:
Dimension icon_size = GetSpriteSize(SPR_TOWN_RATING_GOOD);
d.width += icon_size.width + 2;
d.height = std::max(d.height, icon_size.height);
resize.height = d.height;
fill.height = resize.height = d.height;
d.height *= 5;
d.width += padding.width;
d.height += padding.height;

View File

@ -977,7 +977,7 @@ struct RefitWindow : public Window {
{
switch (widget) {
case WID_VR_MATRIX:
resize.height = GetCharacterHeight(FS_NORMAL) + padding.height;
fill.height = resize.height = GetCharacterHeight(FS_NORMAL) + padding.height;
size.height = resize.height * 8;
break;
@ -1947,7 +1947,7 @@ public:
{
switch (widget) {
case WID_VL_LIST:
resize.height = GetVehicleListHeight(this->vli.vtype, 1);
fill.height = resize.height = GetVehicleListHeight(this->vli.vtype, 1);
switch (this->vli.vtype) {
case VEH_TRAIN:
@ -2503,7 +2503,7 @@ struct VehicleDetailsWindow : Window {
}
case WID_VD_MATRIX:
resize.height = std::max<uint>(ScaleGUITrad(14), GetCharacterHeight(FS_NORMAL) + padding.height);
fill.height = resize.height = std::max<uint>(ScaleGUITrad(14), GetCharacterHeight(FS_NORMAL) + padding.height);
size.height = 4 * resize.height;
break;