Codechange: Use std::unique_ptr for all NWidgets.

This commit is contained in:
Peter Nelson
2023-12-30 07:36:22 +00:00
committed by Peter Nelson
parent 9a3934ae23
commit 7124b4eef1
15 changed files with 200 additions and 212 deletions

View File

@@ -454,54 +454,54 @@ void LinkGraphOverlay::SetCompanyMask(CompanyMask company_mask)
}
/** Make a number of rows with buttons for each company for the linkgraph legend window. */
NWidgetBase *MakeCompanyButtonRowsLinkGraphGUI()
std::unique_ptr<NWidgetBase> MakeCompanyButtonRowsLinkGraphGUI()
{
return MakeCompanyButtonRows(WID_LGL_COMPANY_FIRST, WID_LGL_COMPANY_LAST, COLOUR_GREY, 3, STR_NULL);
}
NWidgetBase *MakeSaturationLegendLinkGraphGUI()
std::unique_ptr<NWidgetBase> MakeSaturationLegendLinkGraphGUI()
{
NWidgetVertical *panel = new NWidgetVertical(NC_EQUALSIZE);
auto panel = std::make_unique<NWidgetVertical>(NC_EQUALSIZE);
for (uint i = 0; i < lengthof(LinkGraphOverlay::LINK_COLOURS[0]); ++i) {
NWidgetBackground * wid = new NWidgetBackground(WWT_PANEL, COLOUR_DARK_GREEN, i + WID_LGL_SATURATION_FIRST);
auto wid = std::make_unique<NWidgetBackground>(WWT_PANEL, COLOUR_DARK_GREEN, i + WID_LGL_SATURATION_FIRST);
wid->SetMinimalSize(50, 0);
wid->SetMinimalTextLines(1, 0, FS_SMALL);
wid->SetFill(1, 1);
wid->SetResize(0, 0);
panel->Add(wid);
panel->Add(std::move(wid));
}
return panel;
}
NWidgetBase *MakeCargoesLegendLinkGraphGUI()
std::unique_ptr<NWidgetBase> MakeCargoesLegendLinkGraphGUI()
{
uint num_cargo = static_cast<uint>(_sorted_cargo_specs.size());
static const uint ENTRIES_PER_COL = 5;
NWidgetHorizontal *panel = new NWidgetHorizontal(NC_EQUALSIZE);
NWidgetVertical *col = nullptr;
auto panel = std::make_unique<NWidgetHorizontal>(NC_EQUALSIZE);
std::unique_ptr<NWidgetVertical> col = nullptr;
for (uint i = 0; i < num_cargo; ++i) {
if (i % ENTRIES_PER_COL == 0) {
if (col != nullptr) panel->Add(col);
col = new NWidgetVertical(NC_EQUALSIZE);
if (col != nullptr) panel->Add(std::move(col));
col = std::make_unique<NWidgetVertical>(NC_EQUALSIZE);
}
NWidgetBackground * wid = new NWidgetBackground(WWT_PANEL, COLOUR_GREY, i + WID_LGL_CARGO_FIRST);
auto wid = std::make_unique<NWidgetBackground>(WWT_PANEL, COLOUR_GREY, i + WID_LGL_CARGO_FIRST);
wid->SetMinimalSize(25, 0);
wid->SetMinimalTextLines(1, 0, FS_SMALL);
wid->SetFill(1, 1);
wid->SetResize(0, 0);
col->Add(wid);
col->Add(std::move(wid));
}
/* Fill up last row */
for (uint i = num_cargo; i < Ceil(num_cargo, ENTRIES_PER_COL); ++i) {
NWidgetSpacer *spc = new NWidgetSpacer(25, 0);
auto spc = std::make_unique<NWidgetSpacer>(25, 0);
spc->SetMinimalTextLines(1, 0, FS_SMALL);
spc->SetFill(1, 1);
spc->SetResize(0, 0);
col->Add(spc);
col->Add(std::move(spc));
}
/* If there are no cargo specs defined, then col won't have been created so don't add it. */
if (col != nullptr) panel->Add(col);
if (col != nullptr) panel->Add(std::move(col));
return panel;
}