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; }