fixing layout issues

This commit is contained in:
Michael Freno
2026-01-05 11:01:40 -05:00
parent 32cc418449
commit 8c43b45344

View File

@@ -508,22 +508,26 @@ function LayoutEngine:layoutChildren()
if self.justifyContent == self._JustifyContent.FLEX_START then if self.justifyContent == self._JustifyContent.FLEX_START then
startPos = 0 startPos = 0
elseif self.justifyContent == self._JustifyContent.CENTER then elseif self.justifyContent == self._JustifyContent.CENTER then
startPos = freeSpace / 2 startPos = math.max(0, freeSpace / 2)
elseif self.justifyContent == self._JustifyContent.FLEX_END then elseif self.justifyContent == self._JustifyContent.FLEX_END then
startPos = freeSpace startPos = math.max(0, freeSpace)
elseif self.justifyContent == self._JustifyContent.SPACE_BETWEEN then elseif self.justifyContent == self._JustifyContent.SPACE_BETWEEN then
startPos = 0 startPos = 0
if #line > 1 then if #line > 1 and freeSpace > 0 then
itemSpacing = self.gap + (freeSpace / (#line - 1)) itemSpacing = self.gap + (freeSpace / (#line - 1))
end end
elseif self.justifyContent == self._JustifyContent.SPACE_AROUND then elseif self.justifyContent == self._JustifyContent.SPACE_AROUND then
local spaceAroundEach = freeSpace / #line if freeSpace > 0 then
startPos = spaceAroundEach / 2 local spaceAroundEach = freeSpace / #line
itemSpacing = self.gap + spaceAroundEach startPos = spaceAroundEach / 2
itemSpacing = self.gap + spaceAroundEach
end
elseif self.justifyContent == self._JustifyContent.SPACE_EVENLY then elseif self.justifyContent == self._JustifyContent.SPACE_EVENLY then
local spaceBetween = freeSpace / (#line + 1) if freeSpace > 0 then
startPos = spaceBetween local spaceBetween = freeSpace / (#line + 1)
itemSpacing = self.gap + spaceBetween startPos = spaceBetween
itemSpacing = self.gap + spaceBetween
end
end end
-- Position children in this line -- Position children in this line