Skip to content

Commit

Permalink
Use more space for dropdowns in touch mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Gymnasiast committed Apr 20, 2024
1 parent 73be7b0 commit a2dcbbe
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/openrct2-ui/windows/Dropdown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/

#include "openrct2/config/Config.h"

#include <algorithm>
#include <bitset>
#include <iterator>
Expand All @@ -28,6 +30,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
Expand Down Expand Up @@ -87,6 +90,16 @@ namespace OpenRCT2::Ui::Windows
InputSetState(InputState::DropdownActive);
}

static int32_t GetDefaultRowHeight()
{
return gConfigInterface.TouchMode ? DROPDOWN_ITEM_HEIGHT_TOUCH : DROPDOWN_ITEM_HEIGHT;
}

static int32_t GetAdditionalRowPadding()
{
return gConfigInterface.TouchMode ? 6 : 0;
}

void OnDraw(DrawPixelInfo& dpi) override
{
DrawWidgets(dpi);
Expand Down Expand Up @@ -155,8 +168,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 });
}
}
}
Expand All @@ -168,7 +182,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)
Expand Down Expand Up @@ -494,9 +508,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;
Expand Down

0 comments on commit a2dcbbe

Please sign in to comment.