From c68f78f3d16ca6da4479afaba7c179072a60e905 Mon Sep 17 00:00:00 2001 From: shadash Date: Fri, 15 Oct 2021 21:28:12 +0200 Subject: [PATCH] fix right align Signed-off-by: Sophia Hadash --- es-core/src/components/FlexboxComponent.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/es-core/src/components/FlexboxComponent.cpp b/es-core/src/components/FlexboxComponent.cpp index f9b81abd9..f448fbc16 100644 --- a/es-core/src/components/FlexboxComponent.cpp +++ b/es-core/src/components/FlexboxComponent.cpp @@ -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(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(mItemsPerLine)) == 0) + line++; + } + } + mLayoutValid = true; }