Codechange: Add DropDownIcon constructor to override dimension.

This avoids the need to construct a DropDownIcon and set the dimension after.
This commit is contained in:
Peter Nelson
2023-11-25 19:41:21 +00:00
committed by Peter Nelson
parent 49532914dd
commit 8db7c79e79
3 changed files with 9 additions and 18 deletions

View File

@@ -149,6 +149,12 @@ public:
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 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));
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;
}
};
/**