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

Function MakeWindowNWidgetTree

src/widget.cpp:3429–3459  ·  view source on GitHub ↗

* Make a nested widget tree for a window from a parts array. Besides loading, it inserts a shading selection widget * between the title bar and the window body if the first widget in the parts array looks like a title bar (it is a horizontal * container with a caption widget) and has a shade box widget. * @param nwid_parts Span of nested widget parts. * @param[out] shade_select Pointer to the

Source from the content-addressed store, hash-verified

3427 * @ingroup NestedWidgetParts
3428 */
3429std::unique_ptr<NWidgetBase> MakeWindowNWidgetTree(std::span<const NWidgetPart> nwid_parts, NWidgetStacked **shade_select)
3430{
3431 auto nwid_begin = std::begin(nwid_parts);
3432 auto nwid_end = std::end(nwid_parts);
3433
3434 *shade_select = nullptr;
3435
3436 /* Read the first widget recursively from the array. */
3437 std::unique_ptr<NWidgetBase> nwid = nullptr;
3438 nwid_begin = MakeWidgetTree(nwid_begin, nwid_end, nwid);
3439 assert(nwid != nullptr);
3440
3441 NWidgetHorizontal *hor_cont = dynamic_cast<NWidgetHorizontal *>(nwid.get());
3442
3443 auto root = std::make_unique<NWidgetVertical>();
3444 root->Add(std::move(nwid));
3445 if (nwid_begin == nwid_end) return root; // There is no body at all.
3446
3447 if (hor_cont != nullptr && hor_cont->GetWidgetOfType(WWT_CAPTION) != nullptr && hor_cont->GetWidgetOfType(WWT_SHADEBOX) != nullptr) {
3448 /* If the first widget has a title bar and a shade box, silently add a shade selection widget in the tree. */
3449 auto shade_stack = std::make_unique<NWidgetStacked>(INVALID_WIDGET);
3450 *shade_select = shade_stack.get();
3451 /* Load the remaining parts into the shade stack. */
3452 shade_stack->Add(MakeNWidgets({nwid_begin, nwid_end}, std::make_unique<NWidgetVertical>()));
3453 root->Add(std::move(shade_stack));
3454 return root;
3455 }
3456
3457 /* Load the remaining parts into 'root'. */
3458 return MakeNWidgets({nwid_begin, nwid_end}, std::move(root));
3459}
3460
3461/**
3462 * Make a number of rows with button-like graphics, for enabling/disabling each company.

Callers 2

CreateNestedTreeMethod · 0.85

Calls 7

MakeWidgetTreeFunction · 0.85
MakeNWidgetsFunction · 0.85
GetWidgetOfTypeMethod · 0.80
beginFunction · 0.50
endFunction · 0.50
getMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected