alignment fixes
This commit is contained in:
55
FlexLove.lua
55
FlexLove.lua
@@ -636,7 +636,7 @@ function Element:layoutChildren()
|
|||||||
if self.flexDirection == FlexDirection.VERTICAL then
|
if self.flexDirection == FlexDirection.VERTICAL then
|
||||||
child.x = (self.width - (child.width or 0)) / 2
|
child.x = (self.width - (child.width or 0)) / 2
|
||||||
else
|
else
|
||||||
child.y = (self.height - (child.height or 0)) / 2
|
child.y = self.y + (self.height - (child.height or 0)) / 2 + self.y
|
||||||
end
|
end
|
||||||
elseif effectiveAlignSelf == AlignSelf.FLEX_END then
|
elseif effectiveAlignSelf == AlignSelf.FLEX_END then
|
||||||
if self.flexDirection == FlexDirection.VERTICAL then
|
if self.flexDirection == FlexDirection.VERTICAL then
|
||||||
@@ -646,40 +646,43 @@ function Element:layoutChildren()
|
|||||||
end
|
end
|
||||||
elseif effectiveAlignSelf == AlignSelf.STRETCH then
|
elseif effectiveAlignSelf == AlignSelf.STRETCH then
|
||||||
if self.flexDirection == FlexDirection.VERTICAL then
|
if self.flexDirection == FlexDirection.VERTICAL then
|
||||||
child.width = self.width
|
-- Only set width if not already stretched by alignItems
|
||||||
|
if child.width ~= self.width then
|
||||||
|
child.width = self.width
|
||||||
|
end
|
||||||
else
|
else
|
||||||
child.height = self.height
|
-- Only set height if not already stretched by alignItems
|
||||||
|
if child.height ~= self.height then
|
||||||
|
child.height = self.height
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
currentPos = currentPos + (child.height or 0) + self.gap + (self.margin.top or 0) + (self.margin.bottom or 0)
|
currentPos = currentPos + (child.height or 0) + self.gap + (self.margin.top or 0) + (self.margin.bottom or 0)
|
||||||
else
|
else
|
||||||
child.x = currentPos + (self.margin.left or 0)
|
child.x = currentPos + (self.margin.left or 0)
|
||||||
child.y = self.margin.top or 0
|
-- Start with margin
|
||||||
|
child.y = self.margin.top or 0
|
||||||
|
|
||||||
-- Apply alignment to horizontal axis (alignItems)
|
-- Determine effective alignment - alignSelf takes precedence over alignItems
|
||||||
if self.alignItems == AlignItems.FLEX_START then
|
local effectiveAlign = child.alignSelf
|
||||||
--nothing, currentPos is all
|
if effectiveAlign == AlignSelf.AUTO then
|
||||||
elseif self.alignItems == AlignItems.CENTER then
|
effectiveAlign = self.alignItems
|
||||||
child.y = (self.height - (child.height or 0)) / 2
|
end
|
||||||
elseif self.alignItems == AlignItems.FLEX_END then
|
|
||||||
child.y = self.height - (child.height or 0)
|
|
||||||
elseif self.alignItems == AlignItems.STRETCH then
|
|
||||||
child.height = self.height
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Apply self alignment to horizontal axis (alignSelf)
|
-- Apply alignment
|
||||||
if child.alignSelf == AlignSelf.FLEX_START then
|
if effectiveAlign == AlignItems.FLEX_START then
|
||||||
-- nothing, currentPos is all - position should be at the beginning of cross axis
|
-- Keep the margin.top position
|
||||||
-- For HORIZONTAL flex, this means Y = 0
|
elseif effectiveAlign == AlignItems.CENTER then
|
||||||
child.y = 0
|
child.y = (self.height - (child.height or 0)) / 2
|
||||||
elseif child.alignSelf == AlignSelf.CENTER then
|
elseif effectiveAlign == AlignItems.FLEX_END then
|
||||||
child.y = (self.height - (child.height or 0)) / 2
|
child.y = self.height - (child.height or 0)
|
||||||
elseif child.alignSelf == AlignSelf.FLEX_END then
|
elseif effectiveAlign == AlignItems.STRETCH then
|
||||||
child.y = self.height - (child.height or 0)
|
-- Only set height if not already stretched
|
||||||
elseif child.alignSelf == AlignSelf.STRETCH then
|
if child.height ~= self.height then
|
||||||
child.height = self.height
|
child.height = self.height
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
currentPos = currentPos + (child.width or 0) + self.gap + (self.margin.left or 0) + (self.margin.right or 0)
|
currentPos = currentPos + (child.width or 0) + self.gap + (self.margin.left or 0) + (self.margin.right or 0)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user