From 60565da8f975e344d398f4caf116534b01e389b8 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Thu, 7 Dec 2023 16:10:09 +0000 Subject: [PATCH] Codechange: Add specific WidgetDimension for dropdown list window. (#11554) This avoids contorting fullbevel dimensions. --- src/widget.cpp | 2 ++ src/widgets/dropdown.cpp | 16 ++++++++-------- src/window_gui.h | 1 + 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/widget.cpp b/src/widget.cpp index ba7bca4e62..5c5f3929db 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -150,6 +150,7 @@ const WidgetDimensions WidgetDimensions::unscaled = { {WD_CLOSEBOX_LEFT, WD_CLOSEBOX_TOP, WD_CLOSEBOX_RIGHT, WD_CLOSEBOX_BOTTOM}, ///< closebox {WD_CAPTIONTEXT_LEFT, WD_CAPTIONTEXT_TOP, WD_CAPTIONTEXT_RIGHT, WD_CAPTIONTEXT_BOTTOM}, ///< captiontext {WD_DROPDOWNTEXT_LEFT, WD_DROPDOWNTEXT_TOP, WD_DROPDOWNTEXT_RIGHT, WD_DROPDOWNTEXT_BOTTOM}, ///< dropdowntext + {WD_BEVEL_LEFT, WD_BEVEL_TOP * 2, WD_BEVEL_RIGHT, WD_BEVEL_BOTTOM * 2}, ///< dropdownmenu {20, 10, 20, 10}, ///< modalpopup {3, 3, 3, 3}, ///< picker {10, 8, 10, 8}, ///< sparse window padding @@ -224,6 +225,7 @@ void SetupWidgetDimensions() WidgetDimensions::scaled.closebox = ScaleGUITrad(WidgetDimensions::unscaled.closebox); WidgetDimensions::scaled.captiontext = ScaleGUITrad(WidgetDimensions::unscaled.captiontext); WidgetDimensions::scaled.dropdowntext = ScaleGUITrad(WidgetDimensions::unscaled.dropdowntext); + WidgetDimensions::scaled.dropdownlist = ScaleGUITrad(WidgetDimensions::unscaled.dropdownlist); WidgetDimensions::scaled.modalpopup = ScaleGUITrad(WidgetDimensions::unscaled.modalpopup); WidgetDimensions::scaled.vsep_normal = ScaleGUITrad(WidgetDimensions::unscaled.vsep_normal); diff --git a/src/widgets/dropdown.cpp b/src/widgets/dropdown.cpp index ba898ff715..784e75f0da 100644 --- a/src/widgets/dropdown.cpp +++ b/src/widgets/dropdown.cpp @@ -75,7 +75,7 @@ struct DropdownWindow : Window { uint items_width = size.width - (scroll ? NWidgetScrollbar::GetVerticalDimension().width : 0); NWidgetCore *nwi = this->GetWidget(WID_DM_ITEMS); - nwi->SetMinimalSizeAbsolute(items_width, size.height + WidgetDimensions::scaled.fullbevel.Vertical() * 2); + nwi->SetMinimalSizeAbsolute(items_width, size.height + WidgetDimensions::scaled.dropdownlist.Vertical()); nwi->colour = wi_colour; nwi = this->GetWidget(WID_DM_SCROLL); @@ -142,8 +142,8 @@ struct DropdownWindow : Window { { if (GetWidgetFromPos(this, _cursor.pos.x - this->left, _cursor.pos.y - this->top) < 0) return false; - const Rect &r = this->GetWidget(WID_DM_ITEMS)->GetCurrentRect().Shrink(WidgetDimensions::scaled.fullbevel); - int y = _cursor.pos.y - this->top - r.top - WidgetDimensions::scaled.fullbevel.top; + const Rect &r = this->GetWidget(WID_DM_ITEMS)->GetCurrentRect().Shrink(WidgetDimensions::scaled.dropdownlist); + int y = _cursor.pos.y - this->top - r.top; int pos = this->vscroll->GetPosition(); for (const auto &item : this->list) { @@ -170,7 +170,7 @@ struct DropdownWindow : Window { Colours colour = this->GetWidget(widget)->colour; - Rect ir = r.Shrink(WidgetDimensions::scaled.fullbevel).Shrink(RectPadding::zero, WidgetDimensions::scaled.fullbevel); + Rect ir = r.Shrink(WidgetDimensions::scaled.dropdownlist); int y = ir.top; int pos = this->vscroll->GetPosition(); for (const auto &item : this->list) { @@ -292,7 +292,7 @@ void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, int button /* Get the height and width required for the list. */ Dimension dim = GetDropDownListDimension(list); - dim.width += WidgetDimensions::scaled.fullbevel.Horizontal(); + dim.width += WidgetDimensions::scaled.dropdownlist.Horizontal(); /* Scrollbar needed? */ bool scroll = false; @@ -301,12 +301,12 @@ void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, int button bool above = false; /* Available height below (or above, if the dropdown is placed above the widget). */ - uint available_height = std::max(GetMainViewBottom() - top - (int)WidgetDimensions::scaled.fullbevel.Vertical() * 2, 0); + uint available_height = std::max(GetMainViewBottom() - top - (int)WidgetDimensions::scaled.dropdownlist.Vertical(), 0); /* If the dropdown doesn't fully fit below the widget... */ if (dim.height > available_height) { - uint available_height_above = std::max(w->top + wi_rect.top - GetMainViewTop() - (int)WidgetDimensions::scaled.fullbevel.Vertical() * 2, 0); + uint available_height_above = std::max(w->top + wi_rect.top - GetMainViewTop() - (int)WidgetDimensions::scaled.dropdownlist.Vertical(), 0); /* Put the dropdown above if there is more available space. */ if (available_height_above > available_height) { @@ -329,7 +329,7 @@ void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, int button /* Set the top position if needed. */ if (above) { - top = w->top + wi_rect.top - dim.height - WidgetDimensions::scaled.fullbevel.Vertical() * 2; + top = w->top + wi_rect.top - dim.height - WidgetDimensions::scaled.dropdownlist.Vertical(); } } diff --git a/src/window_gui.h b/src/window_gui.h index 0ef439dbfb..16d5a4e1eb 100644 --- a/src/window_gui.h +++ b/src/window_gui.h @@ -49,6 +49,7 @@ struct WidgetDimensions { RectPadding closebox; RectPadding captiontext; ///< Offsets of text within a caption. RectPadding dropdowntext; ///< Offsets of text within a dropdown widget. + RectPadding dropdownlist; ///< Offsets used by a dropdown list itself. RectPadding modalpopup; ///< Padding for a modal popup. RectPadding picker; ///< Padding for a picker (dock, station, etc) window. RectPadding sparse; ///< Padding used for 'sparse' widget window, usually containing multiple frames.