Improved GUI consistency when running on high resolution devices.

This commit is contained in:
Leon Styhre 2021-01-13 19:45:56 +01:00
parent 11bf8046d8
commit ce16c8e3ec
5 changed files with 23 additions and 17 deletions

View file

@ -55,8 +55,9 @@ void ButtonComponent::setText(const std::string& text, const std::string& helpTe
mTextCache = std::unique_ptr<TextCache>(mFont->buildTextCache(mText, 0, 0, getCurTextColor()));
float minWidth = mFont->sizeText("DELETE").x() + 12;
setSize(std::max(mTextCache->metrics.size.x() + 12, minWidth), mTextCache->metrics.size.y());
float minWidth = mFont->sizeText("DELETE").x() + (12 * Renderer::getScreenWidthModifier());
setSize(std::max(mTextCache->metrics.size.x() + (12 * Renderer::getScreenWidthModifier()),
minWidth), mTextCache->metrics.size.y());
updateHelpPrompts();
}

View file

@ -8,7 +8,7 @@
#include "components/ComponentList.h"
#define TOTAL_HORIZONTAL_PADDING_PX 20
#define TOTAL_HORIZONTAL_PADDING_PX 20.0f
ComponentList::ComponentList(Window* window) : IList<ComponentListRow,
void*>(window, LIST_SCROLL_STYLE_SLOW, LIST_NEVER_LOOP)
@ -291,7 +291,8 @@ void ComponentList::render(const Transform4x4f& parentTrans)
// Draw separators.
float y = 0;
for (unsigned int i = 0; i < mEntries.size(); i++) {
Renderer::drawRect(0.0f, y, mSize.x(), 1.0f, 0xC6C7C6FF, 0xC6C7C6FF, false, opacity, trans);
Renderer::drawRect(0.0f, y, mSize.x(), 1.0f * Renderer::getScreenHeightModifier(),
0xC6C7C6FF, 0xC6C7C6FF, false, opacity, trans);
y += getRowHeight(mEntries.at(i).data);
}
@ -329,7 +330,7 @@ void ComponentList::updateElementPosition(const ComponentListRow& row)
// Assumes updateElementSize has already been called.
float rowHeight = getRowHeight(row);
float x = TOTAL_HORIZONTAL_PADDING_PX / 2;
float x = (TOTAL_HORIZONTAL_PADDING_PX * Renderer::getScreenWidthModifier()) / 2;
for (unsigned int i = 0; i < row.elements.size(); i++) {
const auto comp = row.elements.at(i).component;
@ -341,7 +342,7 @@ void ComponentList::updateElementPosition(const ComponentListRow& row)
void ComponentList::updateElementSize(const ComponentListRow& row)
{
float width = mSize.x() - TOTAL_HORIZONTAL_PADDING_PX;
float width = mSize.x() - (TOTAL_HORIZONTAL_PADDING_PX * Renderer::getScreenWidthModifier());
std::vector< std::shared_ptr<GuiComponent> > resizeVec;
for (auto it = row.elements.cbegin(); it != row.elements.cend(); it++) {

View file

@ -90,7 +90,8 @@ void HelpComponent::updateGrid()
Utils::String::toUpper(it->second), font, mStyle.textColor);
labels.push_back(lbl);
width += icon->getSize().x() + lbl->getSize().x() + ICON_TEXT_SPACING + ENTRY_SPACING;
width += icon->getSize().x() + lbl->getSize().x() +
((ICON_TEXT_SPACING + ENTRY_SPACING) * Renderer::getScreenWidthModifier());
}
mGrid->setSize(width, height);
@ -98,7 +99,8 @@ void HelpComponent::updateGrid()
for (unsigned int i = 0; i < icons.size(); i++) {
const int col = i*4;
mGrid->setColWidthPerc(col, icons.at(i)->getSize().x() / width);
mGrid->setColWidthPerc(col + 1, ICON_TEXT_SPACING / width);
mGrid->setColWidthPerc(col + 1, (ICON_TEXT_SPACING *
Renderer::getScreenWidthModifier()) / width);
mGrid->setColWidthPerc(col + 2, labels.at(i)->getSize().x() / width);
mGrid->setEntry(icons.at(i), Vector2i(col, 0), false, false);

View file

@ -11,8 +11,8 @@
#include "components/ButtonComponent.h"
#include "Settings.h"
#define BUTTON_GRID_VERT_PADDING 32
#define BUTTON_GRID_HORIZ_PADDING 10
#define BUTTON_GRID_VERT_PADDING 32.0f
#define BUTTON_GRID_HORIZ_PADDING 10.0f
#define TITLE_HEIGHT (mTitle->getFont()->getLetterHeight() + TITLE_VERT_PADDING)
@ -74,8 +74,9 @@ void MenuComponent::setTitle(std::string title, const std::shared_ptr<Font>& fon
float MenuComponent::getButtonGridHeight() const
{
return (mButtonGrid ? mButtonGrid->getSize().y()
: Font::get(FONT_SIZE_MEDIUM)->getHeight() + BUTTON_GRID_VERT_PADDING);
return (mButtonGrid ? mButtonGrid->getSize().y() :
Font::get(FONT_SIZE_MEDIUM)->getHeight() +
(BUTTON_GRID_VERT_PADDING * Renderer::getScreenHeightModifier()));
}
void MenuComponent::updateSize()
@ -144,18 +145,19 @@ std::shared_ptr<ComponentGrid> makeButtonGrid(Window* window,
std::shared_ptr<ComponentGrid> buttonGrid = std::make_shared<ComponentGrid>
(window, Vector2i(static_cast<int>(buttons.size()), 2));
// Initialize to padding.
float buttonGridWidth = static_cast<float>(BUTTON_GRID_HORIZ_PADDING) * buttons.size();
// Initialize to padding.
float buttonGridWidth = BUTTON_GRID_HORIZ_PADDING *
Renderer::getScreenWidthModifier() * buttons.size();
for (int i = 0; i < static_cast<int>(buttons.size()); i++) {
buttonGrid->setEntry(buttons.at(i), Vector2i(i, 0), true, false);
buttonGridWidth += buttons.at(i)->getSize().x();
}
for (unsigned int i = 0; i < buttons.size(); i++)
buttonGrid->setColWidthPerc(i, (buttons.at(i)->getSize().x() +
BUTTON_GRID_HORIZ_PADDING) / buttonGridWidth);
BUTTON_GRID_HORIZ_PADDING * Renderer::getScreenWidthModifier()) / buttonGridWidth);
buttonGrid->setSize(buttonGridWidth, buttons.at(0)->getSize().y() +
BUTTON_GRID_VERT_PADDING + 2);
(BUTTON_GRID_VERT_PADDING * Renderer::getScreenHeightModifier()) + 2);
// Spacer row to deal with dropshadow to make buttons look centered.
buttonGrid->setRowHeightPerc(1, 2 / buttonGrid->getSize().y());

View file

@ -26,7 +26,7 @@ ScrollableContainer::ScrollableContainer(
{
// Set the modifier to get equivalent scrolling speed regardless of screen resolution.
// 1080p is the reference.
mResolutionModifier = static_cast<float>(Renderer::getScreenWidth()) / 1920.0f;
mResolutionModifier = Renderer::getScreenWidthModifier();
mAutoScrollResetDelayConstant = AUTO_SCROLL_RESET_DELAY;
mAutoScrollDelayConstant = AUTO_SCROLL_DELAY;