mirror of
https://github.com/OpenTTD/OpenTTD
synced 2025-12-10 15:02:06 +01:00
Codechange: Deduplicate DrawButtonDropdown. (#14646)
Use Rect methods to position components.
This commit is contained in:
@@ -745,21 +745,17 @@ void DrawCaption(const Rect &r, Colours colour, Owner owner, TextColour text_col
|
||||
*/
|
||||
static inline void DrawButtonDropdown(const Rect &r, Colours colour, bool clicked_button, bool clicked_dropdown, std::string_view str, StringAlignment align)
|
||||
{
|
||||
int dd_width = NWidgetLeaf::dropdown_dimension.width;
|
||||
bool rtl = _current_text_dir == TD_RTL;
|
||||
|
||||
if (_current_text_dir == TD_LTR) {
|
||||
DrawFrameRect(r.left, r.top, r.right - dd_width, r.bottom, colour, clicked_button ? FrameFlag::Lowered : FrameFlags{});
|
||||
DrawImageButtons(r.WithWidth(dd_width, true), WWT_DROPDOWN, colour, clicked_dropdown, SPR_ARROW_DOWN, SA_CENTER);
|
||||
Rect text = r.Indent(NWidgetLeaf::dropdown_dimension.width, !rtl);
|
||||
DrawFrameRect(text, colour, clicked_button ? FrameFlag::Lowered : FrameFlags{});
|
||||
if (!str.empty()) {
|
||||
DrawString(r.left + WidgetDimensions::scaled.dropdowntext.left, r.right - dd_width - WidgetDimensions::scaled.dropdowntext.right, CentreBounds(r.top, r.bottom, GetCharacterHeight(FS_NORMAL)), str, TC_BLACK, align);
|
||||
}
|
||||
} else {
|
||||
DrawFrameRect(r.left + dd_width, r.top, r.right, r.bottom, colour, clicked_button ? FrameFlag::Lowered : FrameFlags{});
|
||||
DrawImageButtons(r.WithWidth(dd_width, false), WWT_DROPDOWN, colour, clicked_dropdown, SPR_ARROW_DOWN, SA_CENTER);
|
||||
if (!str.empty()) {
|
||||
DrawString(r.left + dd_width + WidgetDimensions::scaled.dropdowntext.left, r.right - WidgetDimensions::scaled.dropdowntext.right, CentreBounds(r.top, r.bottom, GetCharacterHeight(FS_NORMAL)), str, TC_BLACK, align);
|
||||
}
|
||||
text = text.CentreTo(text.Width(), GetCharacterHeight(FS_NORMAL)).Shrink(WidgetDimensions::scaled.dropdowntext, RectPadding::zero);
|
||||
DrawString(text, str, TC_BLACK, align);
|
||||
}
|
||||
|
||||
Rect button = r.WithWidth(NWidgetLeaf::dropdown_dimension.width, !rtl);
|
||||
DrawImageButtons(button, WWT_DROPDOWN, colour, clicked_dropdown, SPR_ARROW_DOWN, SA_CENTER);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user