working
This commit is contained in:
69
FlexLove.lua
69
FlexLove.lua
@@ -804,43 +804,14 @@ function Element:layoutChildren()
|
|||||||
for _, child in ipairs(line) do
|
for _, child in ipairs(line) do
|
||||||
-- Determine effective cross-axis alignment
|
-- Determine effective cross-axis alignment
|
||||||
local effectiveAlign = child.alignSelf
|
local effectiveAlign = child.alignSelf
|
||||||
if effectiveAlign == AlignSelf.AUTO then
|
if effectiveAlign == nil or effectiveAlign == AlignSelf.AUTO then
|
||||||
effectiveAlign = self.alignItems
|
effectiveAlign = self.alignItems
|
||||||
end
|
end
|
||||||
|
|
||||||
-- DEBUG: Print alignment info for last child
|
|
||||||
-- DEBUG: Output alignment information for troubleshooting
|
|
||||||
if child.debugId or (_ == #line) then
|
|
||||||
local debugPrefix = child.debugId and string.format("[%s]", child.debugId) or "[LAST_CHILD]"
|
|
||||||
print(
|
|
||||||
string.format(
|
|
||||||
"DEBUG %s: effectiveAlign='%s', alignSelf='%s', parent.alignItems='%s'",
|
|
||||||
debugPrefix,
|
|
||||||
tostring(effectiveAlign),
|
|
||||||
tostring(child.alignSelf),
|
|
||||||
tostring(self.alignItems)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
if self.flexDirection == FlexDirection.HORIZONTAL then
|
if self.flexDirection == FlexDirection.HORIZONTAL then
|
||||||
-- Horizontal layout: main axis is X, cross axis is Y
|
-- Horizontal layout: main axis is X, cross axis is Y
|
||||||
child.x = self.x + self.padding.left + currentMainPos
|
child.x = self.x + self.padding.left + currentMainPos
|
||||||
|
|
||||||
-- Apply cross-axis (vertical) alignment within the line
|
|
||||||
-- Additional DEBUG: Log detailed positioning for elements with debugId
|
|
||||||
if child.debugId then
|
|
||||||
print(
|
|
||||||
string.format(
|
|
||||||
"DEBUG [%s]: HORIZONTAL layout - lineHeight=%.2f, childHeight=%.2f, currentCrossPos=%.2f",
|
|
||||||
child.debugId,
|
|
||||||
lineHeight,
|
|
||||||
child.height or 0,
|
|
||||||
currentCrossPos
|
|
||||||
)
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
if effectiveAlign == AlignItems.FLEX_START then
|
if effectiveAlign == AlignItems.FLEX_START then
|
||||||
child.y = self.y + self.padding.top + currentCrossPos
|
child.y = self.y + self.padding.top + currentCrossPos
|
||||||
elseif effectiveAlign == AlignItems.CENTER then
|
elseif effectiveAlign == AlignItems.CENTER then
|
||||||
@@ -850,15 +821,6 @@ function Element:layoutChildren()
|
|||||||
elseif effectiveAlign == AlignItems.STRETCH then
|
elseif effectiveAlign == AlignItems.STRETCH then
|
||||||
child.height = lineHeight
|
child.height = lineHeight
|
||||||
child.y = self.y + self.padding.top + currentCrossPos
|
child.y = self.y + self.padding.top + currentCrossPos
|
||||||
else
|
|
||||||
-- Default fallback: treat as FLEX_START
|
|
||||||
print(
|
|
||||||
string.format(
|
|
||||||
"WARNING: Unknown effectiveAlign value '%s', defaulting to FLEX_START",
|
|
||||||
tostring(effectiveAlign)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
child.y = self.y + self.padding.top + currentCrossPos
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Final position DEBUG for elements with debugId
|
-- Final position DEBUG for elements with debugId
|
||||||
@@ -871,44 +833,15 @@ function Element:layoutChildren()
|
|||||||
-- Vertical layout: main axis is Y, cross axis is X
|
-- Vertical layout: main axis is Y, cross axis is X
|
||||||
child.y = self.y + self.padding.top + currentMainPos
|
child.y = self.y + self.padding.top + currentMainPos
|
||||||
|
|
||||||
-- Apply cross-axis (horizontal) alignment within the line
|
|
||||||
-- Additional DEBUG: Log detailed positioning for elements with debugId
|
|
||||||
if child.debugId then
|
|
||||||
print(
|
|
||||||
string.format(
|
|
||||||
"DEBUG [%s]: VERTICAL layout - lineHeight=%.2f, childWidth=%.2f, currentCrossPos=%.2f",
|
|
||||||
child.debugId,
|
|
||||||
lineHeight,
|
|
||||||
child.width or 0,
|
|
||||||
currentCrossPos
|
|
||||||
)
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
if effectiveAlign == AlignItems.FLEX_START then
|
if effectiveAlign == AlignItems.FLEX_START then
|
||||||
child.x = self.x + self.padding.left + currentCrossPos
|
child.x = self.x + self.padding.left + currentCrossPos
|
||||||
elseif effectiveAlign == AlignItems.CENTER then
|
elseif effectiveAlign == AlignItems.CENTER then
|
||||||
Logger:debug(lineHeight)
|
|
||||||
child.x = self.x + self.padding.left + currentCrossPos + ((lineHeight - (child.width or 0)) / 2)
|
child.x = self.x + self.padding.left + currentCrossPos + ((lineHeight - (child.width or 0)) / 2)
|
||||||
elseif effectiveAlign == AlignItems.FLEX_END then
|
elseif effectiveAlign == AlignItems.FLEX_END then
|
||||||
child.x = self.x + self.padding.left + currentCrossPos + lineHeight - (child.width or 0)
|
child.x = self.x + self.padding.left + currentCrossPos + lineHeight - (child.width or 0)
|
||||||
elseif effectiveAlign == AlignItems.STRETCH then
|
elseif effectiveAlign == AlignItems.STRETCH then
|
||||||
child.width = lineHeight
|
child.width = lineHeight
|
||||||
child.x = self.x + self.padding.left + currentCrossPos
|
child.x = self.x + self.padding.left + currentCrossPos
|
||||||
else
|
|
||||||
-- Default fallback: treat as FLEX_START
|
|
||||||
print(
|
|
||||||
string.format(
|
|
||||||
"WARNING: Unknown effectiveAlign value '%s', defaulting to FLEX_START",
|
|
||||||
tostring(effectiveAlign)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
child.x = self.x + self.padding.left + currentCrossPos
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Final position DEBUG for elements with debugId
|
|
||||||
if child.debugId then
|
|
||||||
print(string.format("DEBUG [%s]: Final X position: %.2f", child.debugId, child.x))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
currentMainPos = currentMainPos + (child.height or 0) + itemSpacing
|
currentMainPos = currentMainPos + (child.height or 0) + itemSpacing
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ function TestAbsolutePositioningBasic:testCreateElementWithAbsolutePositioning()
|
|||||||
y = 200,
|
y = 200,
|
||||||
w = 300,
|
w = 300,
|
||||||
h = 150,
|
h = 150,
|
||||||
positioning = Positioning.ABSOLUTE
|
positioning = Positioning.ABSOLUTE,
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Verify element was created with correct properties
|
-- Verify element was created with correct properties
|
||||||
@@ -48,7 +48,7 @@ function TestAbsolutePositioningBasic:testDefaultAbsolutePositioning()
|
|||||||
x = 50,
|
x = 50,
|
||||||
y = 75,
|
y = 75,
|
||||||
w = 200,
|
w = 200,
|
||||||
h = 100
|
h = 100,
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Default should be absolute positioning
|
-- Default should be absolute positioning
|
||||||
@@ -65,7 +65,7 @@ function TestAbsolutePositioningBasic:testZIndexHandling()
|
|||||||
w = 100,
|
w = 100,
|
||||||
h = 100,
|
h = 100,
|
||||||
z = 1,
|
z = 1,
|
||||||
positioning = Positioning.ABSOLUTE
|
positioning = Positioning.ABSOLUTE,
|
||||||
})
|
})
|
||||||
|
|
||||||
local elem2 = Gui.new({
|
local elem2 = Gui.new({
|
||||||
@@ -74,7 +74,7 @@ function TestAbsolutePositioningBasic:testZIndexHandling()
|
|||||||
w = 100,
|
w = 100,
|
||||||
h = 100,
|
h = 100,
|
||||||
z = 5,
|
z = 5,
|
||||||
positioning = Positioning.ABSOLUTE
|
positioning = Positioning.ABSOLUTE,
|
||||||
})
|
})
|
||||||
|
|
||||||
local elem3 = Gui.new({
|
local elem3 = Gui.new({
|
||||||
@@ -83,7 +83,7 @@ function TestAbsolutePositioningBasic:testZIndexHandling()
|
|||||||
w = 100,
|
w = 100,
|
||||||
h = 100,
|
h = 100,
|
||||||
z = 3,
|
z = 3,
|
||||||
positioning = Positioning.ABSOLUTE
|
positioning = Positioning.ABSOLUTE,
|
||||||
})
|
})
|
||||||
|
|
||||||
luaunit.assertEquals(elem1.z, 1)
|
luaunit.assertEquals(elem1.z, 1)
|
||||||
@@ -101,7 +101,7 @@ function TestAbsolutePositioningBasic:testDefaultZIndex()
|
|||||||
y = 20,
|
y = 20,
|
||||||
w = 50,
|
w = 50,
|
||||||
h = 50,
|
h = 50,
|
||||||
positioning = Positioning.ABSOLUTE
|
positioning = Positioning.ABSOLUTE,
|
||||||
})
|
})
|
||||||
|
|
||||||
luaunit.assertEquals(elem.z, 0)
|
luaunit.assertEquals(elem.z, 0)
|
||||||
@@ -114,7 +114,7 @@ function TestAbsolutePositioningBasic:testCoordinateIndependence()
|
|||||||
y = 100,
|
y = 100,
|
||||||
w = 50,
|
w = 50,
|
||||||
h = 50,
|
h = 50,
|
||||||
positioning = Positioning.ABSOLUTE
|
positioning = Positioning.ABSOLUTE,
|
||||||
})
|
})
|
||||||
|
|
||||||
local elem2 = Gui.new({
|
local elem2 = Gui.new({
|
||||||
@@ -122,7 +122,7 @@ function TestAbsolutePositioningBasic:testCoordinateIndependence()
|
|||||||
y = 200,
|
y = 200,
|
||||||
w = 50,
|
w = 50,
|
||||||
h = 50,
|
h = 50,
|
||||||
positioning = Positioning.ABSOLUTE
|
positioning = Positioning.ABSOLUTE,
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Elements should maintain their own coordinates
|
-- Elements should maintain their own coordinates
|
||||||
@@ -144,7 +144,7 @@ function TestAbsolutePositioningBasic:testAbsoluteWithParentIndependentCoordinat
|
|||||||
y = 50,
|
y = 50,
|
||||||
w = 200,
|
w = 200,
|
||||||
h = 200,
|
h = 200,
|
||||||
positioning = Positioning.ABSOLUTE
|
positioning = Positioning.ABSOLUTE,
|
||||||
})
|
})
|
||||||
|
|
||||||
local child = Gui.new({
|
local child = Gui.new({
|
||||||
@@ -153,7 +153,7 @@ function TestAbsolutePositioningBasic:testAbsoluteWithParentIndependentCoordinat
|
|||||||
y = 25,
|
y = 25,
|
||||||
w = 50,
|
w = 50,
|
||||||
h = 50,
|
h = 50,
|
||||||
positioning = Positioning.ABSOLUTE
|
positioning = Positioning.ABSOLUTE,
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Child should maintain its absolute coordinates (CSS absolute behavior)
|
-- Child should maintain its absolute coordinates (CSS absolute behavior)
|
||||||
@@ -177,7 +177,7 @@ function TestAbsolutePositioningBasic:testMultipleAbsoluteElementsNonInterferenc
|
|||||||
w = 30,
|
w = 30,
|
||||||
h = 40,
|
h = 40,
|
||||||
z = i,
|
z = i,
|
||||||
positioning = Positioning.ABSOLUTE
|
positioning = Positioning.ABSOLUTE,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -200,7 +200,7 @@ function TestAbsolutePositioningBasic:testNegativeCoordinates()
|
|||||||
y = -100,
|
y = -100,
|
||||||
w = 200,
|
w = 200,
|
||||||
h = 150,
|
h = 150,
|
||||||
positioning = Positioning.ABSOLUTE
|
positioning = Positioning.ABSOLUTE,
|
||||||
})
|
})
|
||||||
|
|
||||||
luaunit.assertEquals(elem.x, -50)
|
luaunit.assertEquals(elem.x, -50)
|
||||||
@@ -214,7 +214,7 @@ function TestAbsolutePositioningBasic:testZeroCoordinates()
|
|||||||
y = 0,
|
y = 0,
|
||||||
w = 100,
|
w = 100,
|
||||||
h = 100,
|
h = 100,
|
||||||
positioning = Positioning.ABSOLUTE
|
positioning = Positioning.ABSOLUTE,
|
||||||
})
|
})
|
||||||
|
|
||||||
luaunit.assertEquals(elem.x, 0)
|
luaunit.assertEquals(elem.x, 0)
|
||||||
@@ -226,7 +226,7 @@ function TestAbsolutePositioningBasic:testDefaultCoordinates()
|
|||||||
local elem = Gui.new({
|
local elem = Gui.new({
|
||||||
w = 100,
|
w = 100,
|
||||||
h = 100,
|
h = 100,
|
||||||
positioning = Positioning.ABSOLUTE
|
positioning = Positioning.ABSOLUTE,
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Default coordinates should be 0,0
|
-- Default coordinates should be 0,0
|
||||||
@@ -241,7 +241,7 @@ function TestAbsolutePositioningBasic:testElementBounds()
|
|||||||
y = 200,
|
y = 200,
|
||||||
w = 300,
|
w = 300,
|
||||||
h = 400,
|
h = 400,
|
||||||
positioning = Positioning.ABSOLUTE
|
positioning = Positioning.ABSOLUTE,
|
||||||
})
|
})
|
||||||
|
|
||||||
local bounds = elem:getBounds()
|
local bounds = elem:getBounds()
|
||||||
@@ -258,7 +258,7 @@ function TestAbsolutePositioningBasic:testParentChildRelationshipAbsolute()
|
|||||||
y = 100,
|
y = 100,
|
||||||
w = 300,
|
w = 300,
|
||||||
h = 300,
|
h = 300,
|
||||||
positioning = Positioning.ABSOLUTE
|
positioning = Positioning.ABSOLUTE,
|
||||||
})
|
})
|
||||||
|
|
||||||
local child = Gui.new({
|
local child = Gui.new({
|
||||||
@@ -267,7 +267,7 @@ function TestAbsolutePositioningBasic:testParentChildRelationshipAbsolute()
|
|||||||
y = 75,
|
y = 75,
|
||||||
w = 100,
|
w = 100,
|
||||||
h = 150,
|
h = 150,
|
||||||
positioning = Positioning.ABSOLUTE
|
positioning = Positioning.ABSOLUTE,
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Verify parent-child relationship
|
-- Verify parent-child relationship
|
||||||
@@ -285,8 +285,7 @@ function TestAbsolutePositioningBasic:testAbsoluteChildNoParentAutoSizeAffect()
|
|||||||
local parent = Gui.new({
|
local parent = Gui.new({
|
||||||
x = 0,
|
x = 0,
|
||||||
y = 0,
|
y = 0,
|
||||||
positioning = Positioning.ABSOLUTE
|
positioning = Positioning.ABSOLUTE,
|
||||||
-- No w/h specified, should auto-size
|
|
||||||
})
|
})
|
||||||
|
|
||||||
local originalParentWidth = parent.width
|
local originalParentWidth = parent.width
|
||||||
@@ -298,7 +297,7 @@ function TestAbsolutePositioningBasic:testAbsoluteChildNoParentAutoSizeAffect()
|
|||||||
y = 1000,
|
y = 1000,
|
||||||
w = 500,
|
w = 500,
|
||||||
h = 500,
|
h = 500,
|
||||||
positioning = Positioning.ABSOLUTE
|
positioning = Positioning.ABSOLUTE,
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Parent size should not be affected by absolute positioned child
|
-- Parent size should not be affected by absolute positioned child
|
||||||
@@ -315,14 +314,14 @@ function TestAbsolutePositioningBasic:testAbsoluteNoFlexParticipation()
|
|||||||
w = 400,
|
w = 400,
|
||||||
h = 200,
|
h = 200,
|
||||||
positioning = Positioning.FLEX,
|
positioning = Positioning.FLEX,
|
||||||
flexDirection = enums.FlexDirection.HORIZONTAL
|
flexDirection = enums.FlexDirection.HORIZONTAL,
|
||||||
})
|
})
|
||||||
|
|
||||||
local flexChild = Gui.new({
|
local flexChild = Gui.new({
|
||||||
parent = flexParent,
|
parent = flexParent,
|
||||||
w = 100,
|
w = 100,
|
||||||
h = 50,
|
h = 50,
|
||||||
positioning = Positioning.FLEX
|
positioning = Positioning.FLEX,
|
||||||
})
|
})
|
||||||
|
|
||||||
local absoluteChild = Gui.new({
|
local absoluteChild = Gui.new({
|
||||||
@@ -331,7 +330,7 @@ function TestAbsolutePositioningBasic:testAbsoluteNoFlexParticipation()
|
|||||||
y = 150,
|
y = 150,
|
||||||
w = 80,
|
w = 80,
|
||||||
h = 40,
|
h = 40,
|
||||||
positioning = Positioning.ABSOLUTE
|
positioning = Positioning.ABSOLUTE,
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Absolute child should maintain its coordinates
|
-- Absolute child should maintain its coordinates
|
||||||
@@ -351,7 +350,7 @@ function TestAbsolutePositioningBasic:testLargeCoordinateValues()
|
|||||||
w = 100,
|
w = 100,
|
||||||
h = 100,
|
h = 100,
|
||||||
z = 1000,
|
z = 1000,
|
||||||
positioning = Positioning.ABSOLUTE
|
positioning = Positioning.ABSOLUTE,
|
||||||
})
|
})
|
||||||
|
|
||||||
luaunit.assertEquals(elem.x, 9999)
|
luaunit.assertEquals(elem.x, 9999)
|
||||||
|
|||||||
Reference in New Issue
Block a user