fix right align

Signed-off-by: Sophia Hadash <sophiahadash@gmail.com>
This commit is contained in:
shadash 2021-10-15 21:28:12 +02:00 committed by Sophia Hadash
parent d0ccc8a13d
commit c68f78f3d1

View file

@ -166,10 +166,9 @@ void FlexboxComponent::computeLayout()
image.second.setSize(image.second.getSize().x, maxItemSize.y);
}
// TODO: Doesn't work correctly.
// Apply overall container alignment.
if (mAlignment == "right")
x += (mSize.x - size.x * grid.x) - mItemMargin.x;
x += (mSize.x - maxItemSize.x * grid.x - (grid.x - 1) * mItemMargin.x);
// Store final item position.
image.second.setPosition(x, y);
@ -193,5 +192,22 @@ void FlexboxComponent::computeLayout()
}
}
// Apply right-align
if (mAlignment == "right") {
unsigned int n = mItemsPerLine - (--i + 1) % std::max(1, static_cast<int>(mItemsPerLine));
i = 0;
unsigned int line = 1;
for (auto& image : mImages) {
if (!image.second.isVisible())
continue;
if (line == mLines)
image.second.setPosition(image.second.getPosition().x +
(maxItemSize.x + mItemMargin.x) * n,
image.second.getPosition().y);
if ((i++ + 1) % std::max(1, static_cast<int>(mItemsPerLine)) == 0)
line++;
}
}
mLayoutValid = true;
}