From bb4ac915ff29b3da3967ef5e7dd1d0ecf971c443 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Sat, 22 Feb 2025 13:29:52 +0000 Subject: [PATCH] Fix 8f14894024: Badge widths were not updated on interface scale change. (#13630) Prepare GUI badge class lists in OnInit() method of Windows, so that they handle scaling changes. --- src/autoreplace_gui.cpp | 9 +++++++-- src/build_vehicle_gui.cpp | 8 +------- src/industry_gui.cpp | 4 +++- src/picker_gui.cpp | 7 +++++-- src/picker_gui.h | 1 + 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/autoreplace_gui.cpp b/src/autoreplace_gui.cpp index b92216acde..3ab2d06a41 100644 --- a/src/autoreplace_gui.cpp +++ b/src/autoreplace_gui.cpp @@ -84,6 +84,7 @@ class ReplaceVehicleWindow : public Window { bool reset_sel_engine; ///< Also reset #sel_engine while updating left and/or right and no valid engine selected. GroupID sel_group; ///< Group selected to replace. int details_height; ///< Minimal needed height of the details panels, in text lines (found so far). + VehicleType vehicle_type; ///< Type of vehicle in this window. uint8_t sort_criteria; ///< Criteria of sorting vehicles. bool descending_sort_order; ///< Order of sorting vehicles. bool show_hidden_engines; ///< Whether to show the hidden engines. @@ -267,6 +268,7 @@ class ReplaceVehicleWindow : public Window { public: ReplaceVehicleWindow(WindowDesc &desc, VehicleType vehicletype, GroupID id_g) : Window(desc) { + this->vehicle_type = vehicletype; this->sel_railtype = INVALID_RAILTYPE; this->sel_roadtype = INVALID_ROADTYPE; this->replace_engines = true; // start with locomotives (all other vehicles will not read this bool) @@ -278,8 +280,6 @@ public: this->sel_engine[1] = EngineID::Invalid(); this->show_hidden_engines = _engine_sort_show_hidden_engines[vehicletype]; - this->badge_classes = GUIBadgeClasses(static_cast(GSF_TRAINS + vehicletype)); - this->CreateNestedTree(); this->vscroll[0] = this->GetScrollbar(WID_RV_LEFT_SCROLLBAR); this->vscroll[1] = this->GetScrollbar(WID_RV_RIGHT_SCROLLBAR); @@ -295,6 +295,11 @@ public: this->sel_group = id_g; } + void OnInit() override + { + this->badge_classes = GUIBadgeClasses(static_cast(GSF_TRAINS + this->vehicle_type)); + } + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp index b1a6c9ca46..aefd82c5bb 100644 --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -1167,11 +1167,6 @@ struct BuildVehicleWindow : Window { } } - void BuildBadgeClasses() - { - this->badge_classes = GUIBadgeClasses(static_cast(GSF_TRAINS + this->vehicle_type)); - } - BuildVehicleWindow(WindowDesc &desc, TileIndex tile, VehicleType type) : Window(desc), vehicle_editbox(MAX_LENGTH_VEHICLE_NAME_CHARS * MAX_CHAR_LENGTH, MAX_LENGTH_VEHICLE_NAME_CHARS) { this->vehicle_type = type; @@ -1184,8 +1179,6 @@ struct BuildVehicleWindow : Window { this->descending_sort_order = _engine_sort_last_order[type]; this->show_hidden_engines = _engine_sort_show_hidden_engines[type]; - this->BuildBadgeClasses(); - this->UpdateFilterByTile(); this->CreateNestedTree(); @@ -1315,6 +1308,7 @@ struct BuildVehicleWindow : Window { void OnInit() override { + this->badge_classes = GUIBadgeClasses(static_cast(GSF_TRAINS + this->vehicle_type)); this->SetCargoFilterArray(); } diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index f777b9aebd..6b8f9d7460 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -311,7 +311,7 @@ class BuildIndustryWindow : public Window { bool enabled; ///< Availability state of the selected industry. Scrollbar *vscroll; Dimension legend; ///< Dimension of the legend 'blob'. - GUIBadgeClasses badge_classes{GSF_INDUSTRIES}; + GUIBadgeClasses badge_classes; /** The largest allowed minimum-width of the window, given in line heights */ static const int MAX_MINWIDTH_LINEHEIGHTS = 20; @@ -419,6 +419,8 @@ public: void OnInit() override { + this->badge_classes = GUIBadgeClasses{GSF_INDUSTRIES}; + /* Width of the legend blob -- slightly larger than the smallmap legend blob. */ this->legend.height = GetCharacterHeight(FS_SMALL); this->legend.width = this->legend.height * 9 / 6; diff --git a/src/picker_gui.cpp b/src/picker_gui.cpp index 67eeafb899..d83ec9d9a4 100644 --- a/src/picker_gui.cpp +++ b/src/picker_gui.cpp @@ -238,11 +238,14 @@ void PickerWindow::ConstructWindow() this->FinishInitNested(this->window_number); - this->badge_classes = GUIBadgeClasses(this->callbacks.GetFeature()); - this->InvalidateData(PICKER_INVALIDATION_ALL); } +void PickerWindow::OnInit() +{ + this->badge_classes = GUIBadgeClasses(this->callbacks.GetFeature()); +} + void PickerWindow::Close(int data) { this->callbacks.Close(data); diff --git a/src/picker_gui.h b/src/picker_gui.h index 4dabc59a50..dc27648185 100644 --- a/src/picker_gui.h +++ b/src/picker_gui.h @@ -179,6 +179,7 @@ public: bool has_type_picker = false; ///< Set if this window has a type picker 'component'. PickerWindow(WindowDesc &desc, Window *parent, int window_number, PickerCallbacks &callbacks); + void OnInit() override; void Close(int data = 0) override; void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override; void DrawWidget(const Rect &r, WidgetID widget) const override;