Use more space for dropdowns when using Enlarged UI

This commit is contained in:
Gymnasiast 2024-04-20 17:02:58 +02:00
parent 79006f3922
commit 9242d87466
No known key found for this signature in database
GPG Key ID: DBFFF47AB2CA3EDD
1 changed files with 18 additions and 3 deletions

View File

@ -7,6 +7,8 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include "openrct2/config/Config.h"
#include <bitset>
#include <iterator>
#include <openrct2-ui/interface/Dropdown.h>
@ -27,6 +29,7 @@ namespace OpenRCT2::Ui::Windows
constexpr int32_t DROPDOWN_TEXT_MAX_ROWS = 32;
constexpr int32_t DROPDOWN_ITEM_HEIGHT = 12;
constexpr int32_t DROPDOWN_ITEM_HEIGHT_TOUCH = 24;
static constexpr std::array<uint8_t, 57> _appropriateImageDropdownItemsPerRow = {
1, 1, 1, 1, 2, 2, 3, 3, 4, 3, // 10
@ -86,6 +89,16 @@ namespace OpenRCT2::Ui::Windows
InputSetState(InputState::DropdownActive);
}
static int32_t GetDefaultRowHeight()
{
return gConfigInterface.EnlargedUi ? DROPDOWN_ITEM_HEIGHT_TOUCH : DROPDOWN_ITEM_HEIGHT;
}
static int32_t GetAdditionalRowPadding()
{
return gConfigInterface.EnlargedUi ? 6 : 0;
}
void OnDraw(DrawPixelInfo& dpi) override
{
DrawWidgets(dpi);
@ -154,8 +167,9 @@ namespace OpenRCT2::Ui::Windows
colour = NOT_TRANSLUCENT(colours[0]) | COLOUR_FLAG_INSET;
// Draw item string
auto yOffset = GetAdditionalRowPadding();
Formatter ft(reinterpret_cast<uint8_t*>(&gDropdownItems[i].Args));
DrawTextEllipsised(dpi, screenCoords, width - 5, item, ft, { colour });
DrawTextEllipsised(dpi, { screenCoords.x, screenCoords.y + yOffset }, width - 5, item, ft, { colour });
}
}
}
@ -167,7 +181,7 @@ namespace OpenRCT2::Ui::Windows
{
// Set and calculate num items, rows and columns
ItemWidth = itemWidth;
ItemHeight = (txtFlags & Dropdown::Flag::CustomHeight) ? customHeight : DROPDOWN_ITEM_HEIGHT;
ItemHeight = (txtFlags & Dropdown::Flag::CustomHeight) ? customHeight : GetDefaultRowHeight();
gDropdownNumItems = static_cast<int32_t>(numItems);
// There must always be at least one column to prevent dividing by zero
if (gDropdownNumItems == 0)
@ -493,9 +507,10 @@ static constexpr colour_t kColoursDropdownOrder[] = {
}
// Show dropdown
auto squareSize = DropdownWindow::GetDefaultRowHeight();
WindowDropdownShowImage(
w->windowPos.x + widget->left, w->windowPos.y + widget->top, widget->height() + 1, dropdownColour,
Dropdown::Flag::StayOpen, numColours, 12, 12,
Dropdown::Flag::StayOpen, numColours, squareSize, squareSize,
DropdownGetAppropriateImageDropdownItemsPerRow(static_cast<uint32_t>(numColours)));
gDropdownIsColour = true;