From 7c529cfc4b86e64d155c23405c46620f5bc5276e Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Fri, 19 Apr 2024 08:19:31 +0100 Subject: [PATCH] Fix #12433: Width of unit number display was too narrow. (#12534) Digit width was counted, but ignored the thousands separator. --- src/vehicle_gui.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 95f5e5168e..b208e50e43 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -1681,6 +1681,17 @@ uint GetVehicleListHeight(VehicleType type, uint divisor) return base + (rem == 0 ? 0 : divisor - rem); } +/** + * Get width required for the formatted unit number display. + * @param digits Number of digits required for unit number. + * @return Required width in pixels. + */ +static int GetUnitNumberWidth(int digits) +{ + SetDParamMaxDigits(0, digits); + return GetStringBoundingBox(STR_JUST_COMMA).width; +} + /** * Draw all the vehicle list items. * @param selected_vehicle The vehicle that is to be highlighted. @@ -1693,7 +1704,7 @@ void BaseVehicleListWindow::DrawVehicleListItems(VehicleID selected_vehicle, int bool rtl = _current_text_dir == TD_RTL; Dimension profit = GetSpriteSize(SPR_PROFIT_LOT); - int text_offset = std::max(profit.width, GetDigitWidth() * this->unitnumber_digits) + WidgetDimensions::scaled.hsep_normal; + int text_offset = std::max(profit.width, GetUnitNumberWidth(this->unitnumber_digits)) + WidgetDimensions::scaled.hsep_normal; Rect tr = ir.Indent(text_offset, rtl); bool show_orderlist = this->vli.vtype >= VEH_SHIP;