mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Add DropDownIcon constructor to override dimension.
This avoids the need to construct a DropDownIcon and set the dimension after.pull/11530/head
parent
49532914dd
commit
8db7c79e79
|
@ -2354,9 +2354,7 @@ DropDownList GetRailTypeDropDownList(bool for_replacement, bool all_option)
|
||||||
list.push_back(std::make_unique<DropDownListStringItem>(rti->strings.replace_text, rt, !HasBit(avail_railtypes, rt)));
|
list.push_back(std::make_unique<DropDownListStringItem>(rti->strings.replace_text, rt, !HasBit(avail_railtypes, rt)));
|
||||||
} else {
|
} else {
|
||||||
StringID str = rti->max_speed > 0 ? STR_TOOLBAR_RAILTYPE_VELOCITY : STR_JUST_STRING;
|
StringID str = rti->max_speed > 0 ? STR_TOOLBAR_RAILTYPE_VELOCITY : STR_JUST_STRING;
|
||||||
auto iconitem = std::make_unique<DropDownListIconItem>(rti->gui_sprites.build_x_rail, PAL_NONE, str, rt, !HasBit(avail_railtypes, rt));
|
list.push_back(std::make_unique<DropDownListIconItem>(d, rti->gui_sprites.build_x_rail, PAL_NONE, str, rt, !HasBit(avail_railtypes, rt)));
|
||||||
iconitem->SetDimension(d);
|
|
||||||
list.push_back(std::move(iconitem));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1828,9 +1828,7 @@ DropDownList GetRoadTypeDropDownList(RoadTramTypes rtts, bool for_replacement, b
|
||||||
list.push_back(std::make_unique<DropDownListStringItem>(rti->strings.replace_text, rt, !HasBit(avail_roadtypes, rt)));
|
list.push_back(std::make_unique<DropDownListStringItem>(rti->strings.replace_text, rt, !HasBit(avail_roadtypes, rt)));
|
||||||
} else {
|
} else {
|
||||||
StringID str = rti->max_speed > 0 ? STR_TOOLBAR_RAILTYPE_VELOCITY : STR_JUST_STRING;
|
StringID str = rti->max_speed > 0 ? STR_TOOLBAR_RAILTYPE_VELOCITY : STR_JUST_STRING;
|
||||||
auto iconitem = std::make_unique<DropDownListIconItem>(rti->gui_sprites.build_x_road, PAL_NONE, str, rt, !HasBit(avail_roadtypes, rt));
|
list.push_back(std::make_unique<DropDownListIconItem>(d, rti->gui_sprites.build_x_road, PAL_NONE, str, rt, !HasBit(avail_roadtypes, rt)));
|
||||||
iconitem->SetDimension(d);
|
|
||||||
list.push_back(std::move(iconitem));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1869,9 +1867,7 @@ DropDownList GetScenRoadTypeDropDownList(RoadTramTypes rtts)
|
||||||
SetDParam(0, rti->strings.menu_text);
|
SetDParam(0, rti->strings.menu_text);
|
||||||
SetDParam(1, rti->max_speed / 2);
|
SetDParam(1, rti->max_speed / 2);
|
||||||
StringID str = rti->max_speed > 0 ? STR_TOOLBAR_RAILTYPE_VELOCITY : STR_JUST_STRING;
|
StringID str = rti->max_speed > 0 ? STR_TOOLBAR_RAILTYPE_VELOCITY : STR_JUST_STRING;
|
||||||
auto item = std::make_unique<DropDownListIconItem>(rti->gui_sprites.build_x_road, PAL_NONE, str, rt, !HasBit(avail_roadtypes, rt));
|
list.push_back(std::make_unique<DropDownListIconItem>(d, rti->gui_sprites.build_x_road, PAL_NONE, str, rt, !HasBit(avail_roadtypes, rt)));
|
||||||
item->SetDimension(d);
|
|
||||||
list.push_back(std::move(item));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (list.empty()) {
|
if (list.empty()) {
|
||||||
|
|
|
@ -149,6 +149,12 @@ public:
|
||||||
this->dbounds = this->dsprite;
|
this->dbounds = this->dsprite;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename... Args>
|
||||||
|
explicit DropDownIcon(const Dimension &dim, SpriteID sprite, PaletteID palette, Args&&... args) : TBase(std::forward<Args>(args)...), sprite(sprite), palette(palette), dbounds(dim)
|
||||||
|
{
|
||||||
|
this->dsprite = GetSpriteSize(this->sprite);
|
||||||
|
}
|
||||||
|
|
||||||
uint Height() const override { return std::max(this->dbounds.height, this->TBase::Height()); }
|
uint Height() const override { return std::max(this->dbounds.height, this->TBase::Height()); }
|
||||||
uint Width() const override { return this->dbounds.width + WidgetDimensions::scaled.hsep_normal + this->TBase::Width(); }
|
uint Width() const override { return this->dbounds.width + WidgetDimensions::scaled.hsep_normal + this->TBase::Width(); }
|
||||||
|
|
||||||
|
@ -159,15 +165,6 @@ public:
|
||||||
DrawSprite(this->sprite, this->palette, CenterBounds(ir.left, ir.right, this->dsprite.width), CenterBounds(r.top, r.bottom, this->dsprite.height));
|
DrawSprite(this->sprite, this->palette, CenterBounds(ir.left, ir.right, this->dsprite.width), CenterBounds(r.top, r.bottom, this->dsprite.height));
|
||||||
this->TBase::Draw(full, r.Indent(this->dbounds.width + WidgetDimensions::scaled.hsep_normal, rtl), sel, bg_colour);
|
this->TBase::Draw(full, r.Indent(this->dbounds.width + WidgetDimensions::scaled.hsep_normal, rtl), sel, bg_colour);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Override bounding box dimensions of sprite, to allow multiple options to have consistent spacing.
|
|
||||||
* @param dim New bounding box to assign.
|
|
||||||
*/
|
|
||||||
void SetDimension(const Dimension &dim)
|
|
||||||
{
|
|
||||||
this->dbounds = dim;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue