remove flexbox padding when item margins are set

This commit is contained in:
Sophia Hadash 2021-09-26 02:17:07 +02:00
parent c08bdda008
commit 97067ae40b

View file

@ -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) {