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,23 +508,27 @@ 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
if freeSpace > 0 then
local spaceAroundEach = freeSpace / #line local spaceAroundEach = freeSpace / #line
startPos = spaceAroundEach / 2 startPos = spaceAroundEach / 2
itemSpacing = self.gap + spaceAroundEach itemSpacing = self.gap + spaceAroundEach
end
elseif self.justifyContent == self._JustifyContent.SPACE_EVENLY then elseif self.justifyContent == self._JustifyContent.SPACE_EVENLY then
if freeSpace > 0 then
local spaceBetween = freeSpace / (#line + 1) local spaceBetween = freeSpace / (#line + 1)
startPos = spaceBetween startPos = spaceBetween
itemSpacing = self.gap + spaceBetween itemSpacing = self.gap + spaceBetween
end end
end
-- Position children in this line -- Position children in this line
local currentMainPos = startPos local currentMainPos = startPos