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

Method SetupSmallestSize

src/widget.cpp:1355–1394  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1353}
1354
1355void NWidgetStacked::SetupSmallestSize(Window *w)
1356{
1357 /* Zero size plane selected */
1358 if (this->shown_plane >= SZSP_BEGIN) {
1359 Dimension size = {0, 0};
1360 Dimension padding = {0, 0};
1361 Dimension fill = {(this->shown_plane == SZSP_HORIZONTAL), (this->shown_plane == SZSP_VERTICAL)};
1362 Dimension resize = {(this->shown_plane == SZSP_HORIZONTAL), (this->shown_plane == SZSP_VERTICAL)};
1363 /* Here we're primarily interested in the value of resize */
1364 if (this->index >= 0) w->UpdateWidgetSize(this->index, size, padding, fill, resize);
1365
1366 this->smallest_x = size.width;
1367 this->smallest_y = size.height;
1368 this->fill_x = fill.width;
1369 this->fill_y = fill.height;
1370 this->resize_x = resize.width;
1371 this->resize_y = resize.height;
1372 this->ApplyAspectRatio();
1373 return;
1374 }
1375
1376 /* First sweep, recurse down and compute minimal size and filling. */
1377 this->smallest_x = 0;
1378 this->smallest_y = 0;
1379 this->fill_x = this->IsEmpty() ? 0 : 1;
1380 this->fill_y = this->IsEmpty() ? 0 : 1;
1381 this->resize_x = this->IsEmpty() ? 0 : 1;
1382 this->resize_y = this->IsEmpty() ? 0 : 1;
1383 for (const auto &child_wid : this->children) {
1384 child_wid->SetupSmallestSize(w);
1385
1386 this->smallest_x = std::max(this->smallest_x, child_wid->smallest_x + child_wid->padding.Horizontal());
1387 this->smallest_y = std::max(this->smallest_y, child_wid->smallest_y + child_wid->padding.Vertical());
1388 this->fill_x = std::lcm(this->fill_x, child_wid->fill_x);
1389 this->fill_y = std::lcm(this->fill_y, child_wid->fill_y);
1390 this->resize_x = std::lcm(this->resize_x, child_wid->resize_x);
1391 this->resize_y = std::lcm(this->resize_y, child_wid->resize_y);
1392 this->ApplyAspectRatio();
1393 }
1394}
1395
1396void NWidgetStacked::AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl)
1397{

Callers 2

ReInitMethod · 0.45
InitializeDataMethod · 0.45

Calls 15

GetStringForWidgetFunction · 0.85
GetStringBoundingBoxFunction · 0.85
maxdimFunction · 0.85
NOT_REACHEDFunction · 0.85
GetScaledSpriteSizeFunction · 0.85
ApplyAspectRatioMethod · 0.80
HorizontalMethod · 0.80
VerticalMethod · 0.80
GetVerticalStepSizeMethod · 0.80
TestMethod · 0.80
GetHorizontalStepSizeMethod · 0.80

Tested by

no test coverage detected