mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2025-01-18 23:15:38 +00:00
Fixed some rounding issues and the right-alignment in FlexboxComponent.
This commit is contained in:
parent
8fd05fcd77
commit
af1d1b3109
|
@ -122,7 +122,7 @@ void FlexboxComponent::computeLayout()
|
||||||
newSize = sizeMaxX.x * sizeMaxX.y >= sizeMaxY.x * sizeMaxY.y ? sizeMaxX : sizeMaxY;
|
newSize = sizeMaxX.x * sizeMaxX.y >= sizeMaxY.x * sizeMaxY.y ? sizeMaxX : sizeMaxY;
|
||||||
|
|
||||||
if (image.second.getSize() != newSize)
|
if (image.second.getSize() != newSize)
|
||||||
image.second.setResize(newSize.x, newSize.y);
|
image.second.setResize(std::round(newSize.x), std::round(newSize.y));
|
||||||
|
|
||||||
// In case maxItemSize needs to be updated.
|
// In case maxItemSize needs to be updated.
|
||||||
if (newSize.x != sizeChange.x)
|
if (newSize.x != sizeChange.x)
|
||||||
|
@ -132,9 +132,9 @@ void FlexboxComponent::computeLayout()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (maxItemSize.x != sizeChange.x)
|
if (maxItemSize.x != sizeChange.x)
|
||||||
maxItemSize.x = sizeChange.x;
|
maxItemSize.x = std::round(sizeChange.x);
|
||||||
if (maxItemSize.y != sizeChange.y)
|
if (maxItemSize.y != sizeChange.y)
|
||||||
maxItemSize.y = sizeChange.y;
|
maxItemSize.y = std::round(sizeChange.y);
|
||||||
|
|
||||||
// Pre-compute layout parameters.
|
// Pre-compute layout parameters.
|
||||||
float anchorXStart{anchorX};
|
float anchorXStart{anchorX};
|
||||||
|
@ -192,22 +192,19 @@ void FlexboxComponent::computeLayout()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply right-align
|
// Apply right-align to the images on the last row, if needed.
|
||||||
if (mAlignment == "right") {
|
if (mAlignment == "right") {
|
||||||
unsigned int m = i % std::max(1, static_cast<int>(mItemsPerLine));
|
std::vector<ImageComponent*> imagesToAlign;
|
||||||
unsigned int n = m > 0 ? mItemsPerLine - m : m;
|
|
||||||
i = 0;
|
|
||||||
unsigned int line = 1;
|
|
||||||
for (auto& image : mImages) {
|
for (auto& image : mImages) {
|
||||||
if (!image.second.isVisible())
|
if (!image.second.isVisible())
|
||||||
continue;
|
continue;
|
||||||
if (line == mLines)
|
// Only include images on the last row.
|
||||||
image.second.setPosition(
|
if (image.second.getPosition().y == anchorY)
|
||||||
image.second.getPosition().x +
|
imagesToAlign.push_back(&image.second);
|
||||||
floorf((maxItemSize.x + mItemMargin.x) * static_cast<float>(n)),
|
}
|
||||||
image.second.getPosition().y);
|
for (auto& moveImage : imagesToAlign) {
|
||||||
if ((i++ + 1) % std::max(1, static_cast<int>(mItemsPerLine)) == 0)
|
float offset = (maxItemSize.x + mItemMargin.x) * (grid.x - imagesToAlign.size());
|
||||||
line++;
|
moveImage->setPosition(moveImage->getPosition().x + offset, moveImage->getPosition().y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue