summaryrefslogtreecommitdiff
path: root/src/widgets
diff options
context:
space:
mode:
authorPeterN <peter1138@openttd.org>2021-04-28 22:32:43 +0100
committerGitHub <noreply@github.com>2021-04-28 22:32:43 +0100
commitae7f07de74a8d242dce8a67eaece26be9d06f064 (patch)
tree0c2328a04f87b10b5e31ab992abdd8bab9668dd9 /src/widgets
parent96dc0d04ecb12ee83909782b9a2c39f336de7d9a (diff)
downloadopenttd-ae7f07de74a8d242dce8a67eaece26be9d06f064.tar.xz
Fix: Incorrect vertical alignment of icon and text in DropDownListIconItem. (#9133)
This happens if the bounding dimensions are changed so that each item is the same size, as happens on the railtype/roadtype dropdown lists, as the vertical offset was calculated before this dimension is changed.
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/dropdown.cpp12
-rw-r--r--src/widgets/dropdown_type.h1
2 files changed, 3 insertions, 10 deletions
diff --git a/src/widgets/dropdown.cpp b/src/widgets/dropdown.cpp
index 97c755e4b..6b1debb9d 100644
--- a/src/widgets/dropdown.cpp
+++ b/src/widgets/dropdown.cpp
@@ -72,13 +72,7 @@ StringID DropDownListCharStringItem::String() const
DropDownListIconItem::DropDownListIconItem(SpriteID sprite, PaletteID pal, StringID string, int result, bool masked) : DropDownListParamStringItem(string, result, masked), sprite(sprite), pal(pal)
{
this->dim = GetSpriteSize(sprite);
- if (this->dim.height < (uint)FONT_HEIGHT_NORMAL) {
- this->sprite_y = (FONT_HEIGHT_NORMAL - dim.height) / 2;
- this->text_y = 0;
- } else {
- this->sprite_y = 0;
- this->text_y = (dim.height - FONT_HEIGHT_NORMAL) / 2;
- }
+ this->sprite_y = dim.height;
}
uint DropDownListIconItem::Height(uint width) const
@@ -94,8 +88,8 @@ uint DropDownListIconItem::Width() const
void DropDownListIconItem::Draw(int left, int right, int top, int bottom, bool sel, Colours bg_colour) const
{
bool rtl = _current_text_dir == TD_RTL;
- DrawSprite(this->sprite, this->pal, rtl ? right - this->dim.width - WD_FRAMERECT_RIGHT : left + WD_FRAMERECT_LEFT, top + this->sprite_y);
- DrawString(left + WD_FRAMERECT_LEFT + (rtl ? 0 : (this->dim.width + WD_FRAMERECT_LEFT)), right - WD_FRAMERECT_RIGHT - (rtl ? (this->dim.width + WD_FRAMERECT_RIGHT) : 0), top + this->text_y, this->String(), sel ? TC_WHITE : TC_BLACK);
+ DrawSprite(this->sprite, this->pal, rtl ? right - this->dim.width - WD_FRAMERECT_RIGHT : left + WD_FRAMERECT_LEFT, CenterBounds(top, bottom, this->sprite_y));
+ DrawString(left + WD_FRAMERECT_LEFT + (rtl ? 0 : (this->dim.width + WD_FRAMERECT_LEFT)), right - WD_FRAMERECT_RIGHT - (rtl ? (this->dim.width + WD_FRAMERECT_RIGHT) : 0), CenterBounds(top, bottom, FONT_HEIGHT_NORMAL), this->String(), sel ? TC_WHITE : TC_BLACK);
}
void DropDownListIconItem::SetDimension(Dimension d)
diff --git a/src/widgets/dropdown_type.h b/src/widgets/dropdown_type.h
index a1f240e96..5dfa9ed58 100644
--- a/src/widgets/dropdown_type.h
+++ b/src/widgets/dropdown_type.h
@@ -84,7 +84,6 @@ class DropDownListIconItem : public DropDownListParamStringItem {
PaletteID pal;
Dimension dim;
uint sprite_y;
- uint text_y;
public:
DropDownListIconItem(SpriteID sprite, PaletteID pal, StringID string, int result, bool masked);