| 408 | } |
| 409 | |
| 410 | void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override |
| 411 | { |
| 412 | switch (widget) { |
| 413 | case WID_DPI_MATRIX_WIDGET: { |
| 414 | Dimension count = GetStringBoundingBox(GetString(STR_JUST_COMMA, GetParamMaxDigits(4)), FS_SMALL); |
| 415 | Dimension d{}; |
| 416 | for (const auto &indtype : this->list) { |
| 417 | d = maxdim(d, GetStringBoundingBox(GetIndustrySpec(indtype)->name)); |
| 418 | } |
| 419 | fill.height = resize.height = std::max<uint>({this->legend.height, d.height, count.height}) + padding.height; |
| 420 | d.width += this->badge_classes.GetTotalColumnsWidth() + this->legend.width + WidgetDimensions::scaled.hsep_wide + WidgetDimensions::scaled.hsep_normal + count.width + padding.width; |
| 421 | d.height = 5 * resize.height; |
| 422 | size = maxdim(size, d); |
| 423 | break; |
| 424 | } |
| 425 | |
| 426 | case WID_DPI_INFOPANEL: { |
| 427 | /* Extra line for cost outside of editor. */ |
| 428 | int height = 2 + (_game_mode == GM_EDITOR ? 0 : 1); |
| 429 | uint extra_lines_req = 0; |
| 430 | uint extra_lines_prd = 0; |
| 431 | uint extra_lines_newgrf = 0; |
| 432 | uint max_minwidth = GetCharacterHeight(FS_NORMAL) * MAX_MINWIDTH_LINEHEIGHTS; |
| 433 | Dimension d = {0, 0}; |
| 434 | for (const auto &indtype : this->list) { |
| 435 | const IndustrySpec *indsp = GetIndustrySpec(indtype); |
| 436 | CargoSuffix cargo_suffix[std::tuple_size_v<decltype(indsp->accepts_cargo)>]; |
| 437 | |
| 438 | /* Measure the accepted cargoes, if any. */ |
| 439 | GetAllCargoSuffixes(CARGOSUFFIX_IN, CST_FUND, nullptr, indtype, indsp, indsp->accepts_cargo, cargo_suffix); |
| 440 | std::string cargostring = this->MakeCargoListString(indsp->accepts_cargo, cargo_suffix, STR_INDUSTRY_VIEW_REQUIRES_N_CARGO); |
| 441 | Dimension strdim = GetStringBoundingBox(cargostring); |
| 442 | if (strdim.width > max_minwidth) { |
| 443 | extra_lines_req = std::max(extra_lines_req, strdim.width / max_minwidth + 1); |
| 444 | strdim.width = max_minwidth; |
| 445 | } |
| 446 | d = maxdim(d, strdim); |
| 447 | |
| 448 | /* Measure the produced cargoes, if any. */ |
| 449 | GetAllCargoSuffixes(CARGOSUFFIX_OUT, CST_FUND, nullptr, indtype, indsp, indsp->produced_cargo, cargo_suffix); |
| 450 | cargostring = this->MakeCargoListString(indsp->produced_cargo, cargo_suffix, STR_INDUSTRY_VIEW_PRODUCES_N_CARGO); |
| 451 | strdim = GetStringBoundingBox(cargostring); |
| 452 | if (strdim.width > max_minwidth) { |
| 453 | extra_lines_prd = std::max(extra_lines_prd, strdim.width / max_minwidth + 1); |
| 454 | strdim.width = max_minwidth; |
| 455 | } |
| 456 | d = maxdim(d, strdim); |
| 457 | |
| 458 | if (indsp->grf_prop.HasGrfFile()) { |
| 459 | /* Reserve a few extra lines for text from an industry NewGRF. */ |
| 460 | extra_lines_newgrf = 4; |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | /* Set it to something more sane :) */ |
| 465 | height += extra_lines_prd + extra_lines_req + extra_lines_newgrf; |
| 466 | size.height = height * GetCharacterHeight(FS_NORMAL) + padding.height; |
| 467 | size.width = d.width + padding.width; |
nothing calls this directly
no test coverage detected