From 29c3f08b694ad8b9723b947aef76ce37ae49559a Mon Sep 17 00:00:00 2001 From: Michael Bernardi Date: Mon, 26 Jun 2023 03:21:54 +0200 Subject: [PATCH] Add a window method to resize dropdowns --- src/openrct2-ui/windows/RideList.cpp | 5 +++++ src/openrct2/interface/Window.cpp | 19 +++++++++++++++++-- src/openrct2/interface/Window.h | 1 + src/openrct2/interface/Window_internal.h | 1 + 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/openrct2-ui/windows/RideList.cpp b/src/openrct2-ui/windows/RideList.cpp index 35d9ba4f5d..18cbb513e0 100644 --- a/src/openrct2-ui/windows/RideList.cpp +++ b/src/openrct2-ui/windows/RideList.cpp @@ -205,6 +205,11 @@ public: height = min_height; } + widgets[WIDX_SORT].left = width - 60; + widgets[WIDX_SORT].right = width - 60 + 54; + + ResizeDropdown(WIDX_CURRENT_INFORMATION_TYPE, { 150, 46 }, { width - 216, DROPDOWN_HEIGHT }); + // Refreshing the list can be a very intensive operation // owing to its use of ride_has_any_track_elements(). // This makes sure it's only refreshed every 64 ticks. diff --git a/src/openrct2/interface/Window.cpp b/src/openrct2/interface/Window.cpp index 3dad889911..3ef1cca9bb 100644 --- a/src/openrct2/interface/Window.cpp +++ b/src/openrct2/interface/Window.cpp @@ -2158,7 +2158,7 @@ void WindowBase::ResizeSpinner(WidgetIndex widgetIndex, const ScreenCoordsXY& or widgets[widgetIndex].right = right; widgets[widgetIndex].bottom = bottom; - widgets[widgetIndex + 1].left = right - size.height; + widgets[widgetIndex + 1].left = right - size.height; // subtract height to maintain aspect ratio widgets[widgetIndex + 1].top = origin.y + 1; widgets[widgetIndex + 1].right = right - 1; widgets[widgetIndex + 1].bottom = bottom - 1; @@ -2167,4 +2167,19 @@ void WindowBase::ResizeSpinner(WidgetIndex widgetIndex, const ScreenCoordsXY& or widgets[widgetIndex + 2].top = origin.y + 1; widgets[widgetIndex + 2].right = right - size.height - 1; widgets[widgetIndex + 2].bottom = bottom - 1; -} \ No newline at end of file +} + +void WindowBase::ResizeDropdown(WidgetIndex widgetIndex, const ScreenCoordsXY& origin, const ScreenSize& size) +{ + auto right = origin.x + size.width - 1; + auto bottom = origin.y + size.height - 1; + widgets[widgetIndex].left = origin.x; + widgets[widgetIndex].top = origin.y; + widgets[widgetIndex].right = right; + widgets[widgetIndex].bottom = bottom; + + widgets[widgetIndex + 1].left = right - size.height + 1; // subtract height to maintain aspect ratio + widgets[widgetIndex + 1].top = origin.y + 1; + widgets[widgetIndex + 1].right = right - 1; + widgets[widgetIndex + 1].bottom = bottom - 1; +} diff --git a/src/openrct2/interface/Window.h b/src/openrct2/interface/Window.h index 0fa0decf16..95d38b9046 100644 --- a/src/openrct2/interface/Window.h +++ b/src/openrct2/interface/Window.h @@ -45,6 +45,7 @@ constexpr uint8_t CloseButtonWidth = 10; #define TABLE_CELL_HEIGHT 12 #define BUTTON_FACE_HEIGHT 12 #define SPINNER_HEIGHT 12 +#define DROPDOWN_HEIGHT 12 #define TEXT_INPUT_SIZE 1024 #define TOP_TOOLBAR_HEIGHT 27 diff --git a/src/openrct2/interface/Window_internal.h b/src/openrct2/interface/Window_internal.h index b903c900b0..f2b43bd02a 100644 --- a/src/openrct2/interface/Window_internal.h +++ b/src/openrct2/interface/Window_internal.h @@ -172,6 +172,7 @@ struct WindowBase void ResizeFrameWithPage(); void ResizeSpinner(WidgetIndex widgetIndex, const ScreenCoordsXY& origin, const ScreenSize& size); + void ResizeDropdown(WidgetIndex widgetIndex, const ScreenCoordsXY& origin, const ScreenSize& size); }; #ifdef __WARN_SUGGEST_FINAL_METHODS__