MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / UpdateWidgetSize

Method UpdateWidgetSize

src/airport_gui.cpp:325–384  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

323 }
324
325 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
326 {
327 switch (widget) {
328 case WID_AP_CLASS_DROPDOWN: {
329 Dimension d = {0, 0};
330 for (const auto &cls : AirportClass::Classes()) {
331 d = maxdim(d, GetStringBoundingBox(cls.name));
332 }
333 d.width += padding.width;
334 d.height += padding.height;
335 size = maxdim(size, d);
336 break;
337 }
338
339 case WID_AP_AIRPORT_LIST: {
340 for (int i = 0; i < NUM_AIRPORTS; i++) {
341 const AirportSpec *as = AirportSpec::Get(i);
342 if (!as->enabled) continue;
343
344 size.width = std::max(size.width, GetStringBoundingBox(as->name).width + padding.width);
345 }
346
347 this->line_height = GetCharacterHeight(FS_NORMAL) + padding.height;
348 size.height = 5 * this->line_height;
349 break;
350 }
351
352 case WID_AP_AIRPORT_SPRITE:
353 for (int i = 0; i < NUM_AIRPORTS; i++) {
354 const AirportSpec *as = AirportSpec::Get(i);
355 if (!as->enabled) continue;
356 for (uint8_t layout = 0; layout < static_cast<uint8_t>(as->layouts.size()); layout++) {
357 SpriteID sprite = GetCustomAirportSprite(as, layout);
358 if (sprite != 0) {
359 Dimension d = GetSpriteSize(sprite);
360 d.width += WidgetDimensions::scaled.framerect.Horizontal();
361 d.height += WidgetDimensions::scaled.framerect.Vertical();
362 size = maxdim(d, size);
363 }
364 }
365 }
366 break;
367
368 case WID_AP_EXTRA_TEXT:
369 for (int i = NEW_AIRPORT_OFFSET; i < NUM_AIRPORTS; i++) {
370 const AirportSpec *as = AirportSpec::Get(i);
371 if (!as->enabled) continue;
372 for (uint8_t layout = 0; layout < static_cast<uint8_t>(as->layouts.size()); layout++) {
373 StringID string = GetAirportTextCallback(as, layout, CBID_AIRPORT_ADDITIONAL_TEXT);
374 if (string == STR_UNDEFINED) continue;
375
376 Dimension d = GetStringMultiLineBoundingBox(string, size);
377 size = maxdim(d, size);
378 }
379 }
380 break;
381
382 default: break;

Callers

nothing calls this directly

Calls 10

maxdimFunction · 0.85
GetStringBoundingBoxFunction · 0.85
GetCharacterHeightFunction · 0.85
GetCustomAirportSpriteFunction · 0.85
GetSpriteSizeFunction · 0.85
GetAirportTextCallbackFunction · 0.85
HorizontalMethod · 0.80
VerticalMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected