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);
mLegacySystemInfo->setSize(mSize.x, mLegacySystemInfo->getFont()->getLetterHeight() * 2.2f);
mLegacySystemInfo->setPosition(0.0f, std::round(mPrimary->getPosition().y) +
std::round(mPrimary->getSize().y));
mLegacySystemInfo->setPosition(0.0f,
std::floor(mPrimary->getPosition().y) + mPrimary->getSize().y);
mLegacySystemInfo->setBackgroundColor(0xDDDDDDD8);
mLegacySystemInfo->setRenderBackground(true);
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.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 clipRectPosY {static_cast<int>(std::ceil(trans[3].y))};
const int clipRectSizeX {static_cast<int>(std::ceil(dim.x))};
const int clipRectSizeY {static_cast<int>(std::ceil(dim.y))};
const int clipRectPosX {static_cast<int>(std::floor(trans[3].x))};
const int clipRectPosY {static_cast<int>(std::floor(trans[3].y))};
const int clipRectSizeX {static_cast<int>(std::round(dim.x))};
const int clipRectSizeY {static_cast<int>(std::ceil(dim.y) + 1.0f)};
mRenderer->pushClipRect(glm::ivec2 {clipRectPosX, clipRectPosY},
glm::ivec2 {clipRectSizeX, clipRectSizeY});
@ -423,6 +423,7 @@ float ComponentList::getRowHeight(const ComponentListRow& row) const
height = row.elements.at(i).component->getSize().y;
}
// We round down to avoid separator single-pixel alignment issues.
return std::floor(height);
}

View file

@ -211,7 +211,11 @@ void HelpComponent::updateGrid()
std::vector<std::shared_ptr<TextComponent>> labels;
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.
bool isDimmed {mWindow->isBackgroundDimmed()};
@ -244,8 +248,8 @@ void HelpComponent::updateGrid()
mGrid->setSize(width, height);
for (unsigned int i = 0; i < icons.size(); ++i) {
const int col = i * 4;
for (size_t i = 0; i < icons.size(); ++i) {
const size_t col {i * 4};
mGrid->setColWidthPerc(col, icons.at(i)->getSize().x / width);
mGrid->setColWidthPerc(col + 1,
(mStyle.iconTextSpacing * mRenderer->getScreenWidth()) / width);
@ -256,7 +260,6 @@ void HelpComponent::updateGrid()
}
mGrid->setPosition({mStyle.position.x, mStyle.position.y, 0.0f});
mGrid->setOrigin(mStyle.origin);
}

View file

@ -11,9 +11,8 @@
#include "Settings.h"
#include "components/ButtonComponent.h"
#define BUTTON_GRID_VERT_PADDING std::round(Font::get(FONT_SIZE_MEDIUM)->getLetterHeight() * 0.915f)
#define BUTTON_GRID_HORIZ_PADDING \
std::round(Font::get(FONT_SIZE_MEDIUM)->getLetterHeight() * 0.283f)
#define BUTTON_GRID_VERT_PADDING Font::get(FONT_SIZE_MEDIUM)->getLetterHeight() * 0.915f
#define BUTTON_GRID_HORIZ_PADDING Font::get(FONT_SIZE_MEDIUM)->getLetterHeight() * 0.283f
#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
{
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()
@ -186,7 +185,7 @@ std::shared_ptr<ComponentGrid> makeButtonGrid(
std::shared_ptr<ImageComponent> makeArrow()
{
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");
return bracket;
}

View file

@ -86,11 +86,11 @@ public:
mText.getFont()->getHeight());
// 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,
(mSize.y - mText.getSize().y) / 2.0f);
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

View file

@ -97,11 +97,8 @@ void SliderComponent::render(const glm::mat4& parentTrans)
if (mTextCache)
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.
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);
// Render knob.
@ -154,7 +151,7 @@ void SliderComponent::onValueChanged()
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 {
mSize.x - mKnob.getSize().x -
@ -175,11 +172,11 @@ void SliderComponent::onValueChanged()
barHeight = 1;
// 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);
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);
setSize(getSize().x, getSize().y - 1.0f);
}