Fixed multiple minor pixel alignment issues.

This commit is contained in:
Leon Styhre 2022-10-25 00:43:27 +02:00
parent 84f019680d
commit 3de8275db6
6 changed files with 24 additions and 24 deletions

View file

@ -1183,8 +1183,8 @@ void SystemView::legacyApplyTheme(const std::shared_ptr<ThemeData>& theme)
mPrimary->applyTheme(theme, "system", "textlist_gamelist", ThemeFlags::ALL); mPrimary->applyTheme(theme, "system", "textlist_gamelist", ThemeFlags::ALL);
mLegacySystemInfo->setSize(mSize.x, mLegacySystemInfo->getFont()->getLetterHeight() * 2.2f); mLegacySystemInfo->setSize(mSize.x, mLegacySystemInfo->getFont()->getLetterHeight() * 2.2f);
mLegacySystemInfo->setPosition(0.0f, std::round(mPrimary->getPosition().y) + mLegacySystemInfo->setPosition(0.0f,
std::round(mPrimary->getSize().y)); std::floor(mPrimary->getPosition().y) + mPrimary->getSize().y);
mLegacySystemInfo->setBackgroundColor(0xDDDDDDD8); mLegacySystemInfo->setBackgroundColor(0xDDDDDDD8);
mLegacySystemInfo->setRenderBackground(true); mLegacySystemInfo->setRenderBackground(true);
mLegacySystemInfo->setFont( mLegacySystemInfo->setFont(

View file

@ -290,10 +290,10 @@ void ComponentList::render(const glm::mat4& parentTrans)
dim.x = (trans[0].x * dim.x + trans[3].x) - trans[3].x; dim.x = (trans[0].x * dim.x + trans[3].x) - trans[3].x;
dim.y = (trans[1].y * dim.y + trans[3].y) - trans[3].y; dim.y = (trans[1].y * dim.y + trans[3].y) - trans[3].y;
const int clipRectPosX {static_cast<int>(std::ceil(trans[3].x))}; const int clipRectPosX {static_cast<int>(std::floor(trans[3].x))};
const int clipRectPosY {static_cast<int>(std::ceil(trans[3].y))}; const int clipRectPosY {static_cast<int>(std::floor(trans[3].y))};
const int clipRectSizeX {static_cast<int>(std::ceil(dim.x))}; const int clipRectSizeX {static_cast<int>(std::round(dim.x))};
const int clipRectSizeY {static_cast<int>(std::ceil(dim.y))}; const int clipRectSizeY {static_cast<int>(std::ceil(dim.y) + 1.0f)};
mRenderer->pushClipRect(glm::ivec2 {clipRectPosX, clipRectPosY}, mRenderer->pushClipRect(glm::ivec2 {clipRectPosX, clipRectPosY},
glm::ivec2 {clipRectSizeX, clipRectSizeY}); glm::ivec2 {clipRectSizeX, clipRectSizeY});
@ -423,6 +423,7 @@ float ComponentList::getRowHeight(const ComponentListRow& row) const
height = row.elements.at(i).component->getSize().y; height = row.elements.at(i).component->getSize().y;
} }
// We round down to avoid separator single-pixel alignment issues.
return std::floor(height); return std::floor(height);
} }

View file

@ -211,7 +211,11 @@ void HelpComponent::updateGrid()
std::vector<std::shared_ptr<TextComponent>> labels; std::vector<std::shared_ptr<TextComponent>> labels;
float width {0.0f}; float width {0.0f};
const float height {std::round(font->getLetterHeight() * 1.25f)}; float height {std::round(font->getLetterHeight() * 1.25f)};
// Make sure both text and icons have either odd or equal sizes to avoid alignment issues.
if (static_cast<int>(font->getHeight()) % 2 != static_cast<int>(height) % 2)
--height;
// State variable indicating whether the GUI is dimmed. // State variable indicating whether the GUI is dimmed.
bool isDimmed {mWindow->isBackgroundDimmed()}; bool isDimmed {mWindow->isBackgroundDimmed()};
@ -244,8 +248,8 @@ void HelpComponent::updateGrid()
mGrid->setSize(width, height); mGrid->setSize(width, height);
for (unsigned int i = 0; i < icons.size(); ++i) { for (size_t i = 0; i < icons.size(); ++i) {
const int col = i * 4; const size_t col {i * 4};
mGrid->setColWidthPerc(col, icons.at(i)->getSize().x / width); mGrid->setColWidthPerc(col, icons.at(i)->getSize().x / width);
mGrid->setColWidthPerc(col + 1, mGrid->setColWidthPerc(col + 1,
(mStyle.iconTextSpacing * mRenderer->getScreenWidth()) / width); (mStyle.iconTextSpacing * mRenderer->getScreenWidth()) / width);
@ -256,7 +260,6 @@ void HelpComponent::updateGrid()
} }
mGrid->setPosition({mStyle.position.x, mStyle.position.y, 0.0f}); mGrid->setPosition({mStyle.position.x, mStyle.position.y, 0.0f});
mGrid->setOrigin(mStyle.origin); mGrid->setOrigin(mStyle.origin);
} }

View file

@ -11,9 +11,8 @@
#include "Settings.h" #include "Settings.h"
#include "components/ButtonComponent.h" #include "components/ButtonComponent.h"
#define BUTTON_GRID_VERT_PADDING std::round(Font::get(FONT_SIZE_MEDIUM)->getLetterHeight() * 0.915f) #define BUTTON_GRID_VERT_PADDING Font::get(FONT_SIZE_MEDIUM)->getLetterHeight() * 0.915f
#define BUTTON_GRID_HORIZ_PADDING \ #define BUTTON_GRID_HORIZ_PADDING Font::get(FONT_SIZE_MEDIUM)->getLetterHeight() * 0.283f
std::round(Font::get(FONT_SIZE_MEDIUM)->getLetterHeight() * 0.283f)
#define TITLE_HEIGHT (mTitle->getFont()->getLetterHeight() + Renderer::getScreenHeight() * 0.0637f) #define TITLE_HEIGHT (mTitle->getFont()->getLetterHeight() + Renderer::getScreenHeight() * 0.0637f)
@ -86,7 +85,7 @@ void MenuComponent::setTitle(std::string title, const std::shared_ptr<Font>& fon
float MenuComponent::getButtonGridHeight() const float MenuComponent::getButtonGridHeight() const
{ {
return (mButtonGrid ? mButtonGrid->getSize().y : return (mButtonGrid ? mButtonGrid->getSize().y :
Font::get(FONT_SIZE_MEDIUM)->getHeight() + BUTTON_GRID_VERT_PADDING); Font::get(FONT_SIZE_MEDIUM)->getSize() * 1.5f + BUTTON_GRID_VERT_PADDING);
} }
void MenuComponent::updateSize() void MenuComponent::updateSize()
@ -186,7 +185,7 @@ std::shared_ptr<ComponentGrid> makeButtonGrid(
std::shared_ptr<ImageComponent> makeArrow() std::shared_ptr<ImageComponent> makeArrow()
{ {
auto bracket = std::make_shared<ImageComponent>(); auto bracket = std::make_shared<ImageComponent>();
bracket->setResize(0, std::round(Font::get(FONT_SIZE_MEDIUM)->getLetterHeight())); bracket->setResize(0, Font::get(FONT_SIZE_MEDIUM)->getLetterHeight());
bracket->setImage(":/graphics/arrow.svg"); bracket->setImage(":/graphics/arrow.svg");
return bracket; return bracket;
} }

View file

@ -86,11 +86,11 @@ public:
mText.getFont()->getHeight()); mText.getFont()->getHeight());
// Position. // Position.
mLeftArrow.setPosition(0.0f, std::round((mSize.y - mLeftArrow.getSize().y) / 2.0f)); mLeftArrow.setPosition(0.0f, (mSize.y - mLeftArrow.getSize().y) / 2.0f);
mText.setPosition(mLeftArrow.getPosition().x + mLeftArrow.getSize().x, mText.setPosition(mLeftArrow.getPosition().x + mLeftArrow.getSize().x,
(mSize.y - mText.getSize().y) / 2.0f); (mSize.y - mText.getSize().y) / 2.0f);
mRightArrow.setPosition(mText.getPosition().x + mText.getSize().x, mRightArrow.setPosition(mText.getPosition().x + mText.getSize().x,
std::round((mSize.y - mRightArrow.getSize().y) / 2.0f)); (mSize.y - mRightArrow.getSize().y) / 2.0f);
} }
bool input(InputConfig* config, Input input) override bool input(InputConfig* config, Input input) override

View file

@ -97,11 +97,8 @@ void SliderComponent::render(const glm::mat4& parentTrans)
if (mTextCache) if (mTextCache)
mFont->renderTextCache(mTextCache.get()); mFont->renderTextCache(mTextCache.get());
const float barPosY {mBarHeight == 1.0f ? std::floor(mSize.y / 2.0f - mBarHeight / 2.0f) :
std::round(mSize.y / 2.0f - mBarHeight / 2.0f)};
// Render bar. // Render bar.
mRenderer->drawRect(mKnob.getSize().x / 2.0f, barPosY, width, mBarHeight, 0x777777FF, mRenderer->drawRect(mKnob.getSize().x / 2.0f, mSize.y / 2.0f, width, mBarHeight, 0x777777FF,
0x777777FF); 0x777777FF);
// Render knob. // Render knob.
@ -154,7 +151,7 @@ void SliderComponent::onValueChanged()
mTextCache->metrics.size.x = textSize.x; // Fudge the width. mTextCache->metrics.size.x = textSize.x; // Fudge the width.
} }
mKnob.setResize(0.0f, std::round(mSize.y * 0.7f)); mKnob.setResize(0.0f, mSize.y * 0.7f);
float barLength { float barLength {
mSize.x - mKnob.getSize().x - mSize.x - mKnob.getSize().x -
@ -175,11 +172,11 @@ void SliderComponent::onValueChanged()
barHeight = 1; barHeight = 1;
// Resize the knob one pixel if necessary to keep the bar centered. // Resize the knob one pixel if necessary to keep the bar centered.
if (barHeight % 2 == 0 && static_cast<int>(mKnob.getSize().y) % 2 != 0) { if (barHeight % 2 == 0 && static_cast<int>(std::round(mKnob.getSize().y)) % 2 != 0) {
mKnob.setResize(mKnob.getSize().x - 1.0f, mKnob.getSize().y - 1.0f); mKnob.setResize(mKnob.getSize().x - 1.0f, mKnob.getSize().y - 1.0f);
setSize(getSize().x, getSize().y - 1.0f); setSize(getSize().x, getSize().y - 1.0f);
} }
else if (barHeight == 1 && static_cast<int>(mKnob.getSize().y) % 2 == 0) { else if (barHeight == 1 && static_cast<int>(std::round(mKnob.getSize().y)) % 2 == 0) {
mKnob.setResize(mKnob.getSize().x - 1.0f, mKnob.getSize().y - 1); mKnob.setResize(mKnob.getSize().x - 1.0f, mKnob.getSize().y - 1);
setSize(getSize().x, getSize().y - 1.0f); setSize(getSize().x, getSize().y - 1.0f);
} }