justifySelf

This commit is contained in:
Michael Freno
2025-09-17 20:21:34 -04:00
parent 757819e4a3
commit 7f4a783863

View File

@@ -641,6 +641,50 @@ function Element:layoutChildren()
end
end
-- Apply justifySelf alignment to main axis (for vertical flexDirection, this is y-axis)
local effectiveJustifySelf = child.justifySelf
if child.justifySelf == JustifySelf.AUTO then
effectiveJustifySelf = self.justifyContent
end
if effectiveJustifySelf == JustifySelf.FLEX_START then
-- Keep the current Y position (already set by spacing logic)
elseif effectiveJustifySelf == JustifySelf.CENTER then
-- Center along the main axis (y-axis for vertical flex direction)
local childHeight = child.height or 0
local availableSpace = self.height - (self.margin.top or 0) - (self.margin.bottom or 0)
local totalChildHeight = 0
for _, c in ipairs(self.children) do
if c.positioning ~= Positioning.ABSOLUTE then
totalChildHeight = totalChildHeight + (c.height or 0)
end
end
local freeSpace = availableSpace - totalChildHeight - (self.gap * (#self.children - 1))
if freeSpace > 0 then
child.y = self.y + (self.margin.top or 0) + freeSpace / 2
end
elseif effectiveJustifySelf == JustifySelf.FLEX_END then
-- Position at the end of main axis (y-axis for vertical flex direction)
local childHeight = child.height or 0
local availableSpace = self.height - (self.margin.top or 0) - (self.margin.bottom or 0)
local totalChildHeight = 0
for _, c in ipairs(self.children) do
if c.positioning ~= Positioning.ABSOLUTE then
totalChildHeight = totalChildHeight + (c.height or 0)
end
end
local freeSpace = availableSpace - totalChildHeight - (self.gap * (#self.children - 1))
if freeSpace > 0 then
child.y = self.y + (self.margin.top or 0) + freeSpace
end
elseif effectiveJustifySelf == JustifySelf.SPACE_AROUND then
-- This would be handled by the justifyContent logic already, so we'll keep existing behavior
elseif effectiveJustifySelf == JustifySelf.SPACE_EVENLY then
-- This would be handled by the justifyContent logic already, so we'll keep existing behavior
elseif effectiveJustifySelf == JustifySelf.SPACE_BETWEEN then
-- This would be handled by the justifyContent logic already, so we'll keep existing behavior
end
currentPos = currentPos + (child.height or 0) + self.gap + (self.margin.top or 0) + (self.margin.bottom or 0)
else
-- Horizontal layout: position relative to parent origin
@@ -667,6 +711,50 @@ function Element:layoutChildren()
end
end
-- Apply justifySelf alignment to main axis (for horizontal flexDirection, this is x-axis)
local effectiveJustifySelf = child.justifySelf
if child.justifySelf == JustifySelf.AUTO then
effectiveJustifySelf = self.justifyContent
end
if effectiveJustifySelf == JustifySelf.FLEX_START then
-- Keep the current X position (already set by spacing logic)
elseif effectiveJustifySelf == JustifySelf.CENTER then
-- Center along the main axis (x-axis for horizontal flex direction)
local childWidth = child.width or 0
local availableSpace = self.width - (self.margin.left or 0) - (self.margin.right or 0)
local totalChildWidth = 0
for _, c in ipairs(self.children) do
if c.positioning ~= Positioning.ABSOLUTE then
totalChildWidth = totalChildWidth + (c.width or 0)
end
end
local freeSpace = availableSpace - totalChildWidth - (self.gap * (#self.children - 1))
if freeSpace > 0 then
child.x = self.x + (self.margin.left or 0) + freeSpace / 2
end
elseif effectiveJustifySelf == JustifySelf.FLEX_END then
-- Position at the end of main axis (x-axis for horizontal flex direction)
local childWidth = child.width or 0
local availableSpace = self.width - (self.margin.left or 0) - (self.margin.right or 0)
local totalChildWidth = 0
for _, c in ipairs(self.children) do
if c.positioning ~= Positioning.ABSOLUTE then
totalChildWidth = totalChildWidth + (c.width or 0)
end
end
local freeSpace = availableSpace - totalChildWidth - (self.gap * (#self.children - 1))
if freeSpace > 0 then
child.x = self.x + (self.margin.left or 0) + freeSpace
end
elseif effectiveJustifySelf == JustifySelf.SPACE_AROUND then
-- This would be handled by the justifyContent logic already, so we'll keep existing behavior
elseif effectiveJustifySelf == JustifySelf.SPACE_EVENLY then
-- This would be handled by the justifyContent logic already, so we'll keep existing behavior
elseif effectiveJustifySelf == JustifySelf.SPACE_BETWEEN then
-- This would be handled by the justifyContent logic already, so we'll keep existing behavior
end
currentPos = currentPos + (child.width or 0) + self.gap + (self.margin.left or 0) + (self.margin.right or 0)
end
::continue::