From 97067ae40b13f80313cebbd94cc37ac8b56c5c2e Mon Sep 17 00:00:00 2001 From: Sophia Hadash Date: Sun, 26 Sep 2021 02:17:07 +0200 Subject: [PATCH] remove flexbox padding when item margins are set --- es-core/src/components/FlexboxComponent.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/es-core/src/components/FlexboxComponent.cpp b/es-core/src/components/FlexboxComponent.cpp index 8569ea358..b29159188 100644 --- a/es-core/src/components/FlexboxComponent.cpp +++ b/es-core/src/components/FlexboxComponent.cpp @@ -102,7 +102,7 @@ void FlexboxComponent::computeLayout() float anchorYStart = anchorY; // Compute total container size. - glm::vec2 totalSize = {mItemMargin.x, mItemMargin.y}; + glm::vec2 totalSize = {-mItemMargin.x, -mItemMargin.y}; if (mDirection == "row") { totalSize.x += (mItemMargin.x + mItemWidth) * mItemsPerLine; totalSize.y += (mItemMargin.y + maxItemSize.y) * nLines; @@ -121,8 +121,12 @@ void FlexboxComponent::computeLayout() float y = anchorY - anchorOriginY * size.y; // Apply item margin. - x += mItemMargin.x * (directionLine.x >= 0.0f ? 1.0f : -1.0f); - y += mItemMargin.y * (directionLine.y >= 0.0f ? 1.0f : -1.0f); + if ((mDirection == "row" && i % std::max(1, (int) mItemsPerLine) != 0) || + (mDirection == "column" && i >= (int) mItemsPerLine)) + x += mItemMargin.x * (directionLine.x >= 0.0f ? 1.0f : -1.0f); + if ((mDirection == "column" && i % std::max(1, (int) mItemsPerLine) != 0) || + (mDirection == "row" && i >= (int) mItemsPerLine)) + y += mItemMargin.y * (directionLine.y >= 0.0f ? 1.0f : -1.0f); // Apply alignment if (mAlign == ITEM_ALIGN_END) {