Revert "changing abs x/y heredity"
This reverts commit 7f1dcb5eb51f8119ce9059928a516316e0843fdc.
This commit is contained in:
@@ -61,14 +61,12 @@ function TestAbsolutePositioning:testDeeplyNestedAbsolutePositioning()
|
||||
rootWindow:layoutChildren()
|
||||
|
||||
-- Verify absolute child position is correct (relative to parent)
|
||||
-- Absolute positioning should be relative to the parent container's origin
|
||||
luaunit.assertEquals(absoluteChildInNested.x, nestedFlexContainer.x + absoluteChildInNested.x)
|
||||
luaunit.assertEquals(absoluteChildInNested.y, nestedFlexContainer.y + absoluteChildInNested.y)
|
||||
luaunit.assertEquals(absoluteChildInNested.x, 120) -- 100 + 20
|
||||
luaunit.assertEquals(absoluteChildInNested.y, 80) -- 50 + 30
|
||||
|
||||
-- Verify flex child position is calculated correctly within nested container
|
||||
-- Flex children should be positioned by flex layout rules (not affected by absolute positioning of others)
|
||||
luaunit.assertAlmostEquals(flexChildInNested.x, 0) -- Should be at start of container
|
||||
luaunit.assertAlmostEquals(flexChildInNested.y, (nestedFlexContainer.height - flexChildInNested.height)/2) -- Should be centered vertically in container
|
||||
luaunit.assertEquals(flexChildInNested.x, 0) -- Should be at start of container
|
||||
luaunit.assertEquals(flexChildInNested.y, 100 - 30) -- Should be centered vertically in 100px container
|
||||
|
||||
-- Verify parent-child relationships
|
||||
luaunit.assertEquals(#nestedFlexContainer.children, 2)
|
||||
@@ -137,15 +135,14 @@ function TestAbsolutePositioning:testMixedLayoutTypesWithNesting()
|
||||
-- Layout children
|
||||
rootWindow:layoutChildren()
|
||||
|
||||
-- Verify absolute positions are correct (relative to parent)
|
||||
luaunit.assertEquals(absoluteChild1.x, flexContainerWithAbsolute.x + absoluteChild1.x)
|
||||
luaunit.assertEquals(absoluteChild1.y, flexContainerWithAbsolute.y + absoluteChild1.y)
|
||||
luaunit.assertEquals(nestedAbsoluteChild.x, flexContainerWithAbsolute.x + nestedAbsoluteChild.x)
|
||||
luaunit.assertEquals(nestedAbsoluteChild.y, flexContainerWithAbsolute.y + nestedAbsoluteChild.y)
|
||||
-- Verify absolute positions are correct
|
||||
luaunit.assertEquals(absoluteChild1.x, 50)
|
||||
luaunit.assertEquals(absoluteChild1.y, 20)
|
||||
luaunit.assertEquals(nestedAbsoluteChild.x, 100)
|
||||
luaunit.assertEquals(nestedAbsoluteChild.y, 100)
|
||||
|
||||
-- Verify flex child is positioned by flex layout (not affected by absolute positioning)
|
||||
-- First flex child in space-between should be at start
|
||||
luaunit.assertAlmostEquals(flexChild.x, 0)
|
||||
-- Verify flex child is positioned by flex layout
|
||||
luaunit.assertEquals(flexChild.x, 0) -- First flex child in space-between should be at start
|
||||
end
|
||||
|
||||
function TestAbsolutePositioning:testAbsolutePositioningInComplexBranchingStructure()
|
||||
@@ -252,16 +249,16 @@ function TestAbsolutePositioning:testAbsolutePositioningInComplexBranchingStruct
|
||||
rootWindow:layoutChildren()
|
||||
|
||||
-- Verify absolute positions in each branch (absolute position relative to branch parent)
|
||||
luaunit.assertEquals(absChild1.x, branch1.x + absChild1.x)
|
||||
luaunit.assertEquals(absChild1.y, branch1.y + absChild1.y)
|
||||
luaunit.assertEquals(absChild2.x, branch2.x + absChild2.x)
|
||||
luaunit.assertEquals(absChild2.y, branch2.y + absChild2.y)
|
||||
luaunit.assertEquals(absChild3.x, branch3.x + absChild3.x)
|
||||
luaunit.assertEquals(absChild3.y, branch3.y + absChild3.y)
|
||||
luaunit.assertEquals(absChild1.x, 10) -- 0 + 10
|
||||
luaunit.assertEquals(absChild1.y, 15) -- 0 + 15
|
||||
luaunit.assertEquals(absChild2.x, 250 + 20) -- 250 + 20
|
||||
luaunit.assertEquals(absChild2.y, 100 + 30) -- 100 + 30
|
||||
luaunit.assertEquals(absChild3.x, 500 + 30) -- 500 + 30
|
||||
luaunit.assertEquals(absChild3.y, 200 + 40) -- 200 + 40
|
||||
|
||||
-- Verify that regular children are positioned by flex layout
|
||||
luaunit.assertAlmostEquals(regularChild1.x, 0)
|
||||
luaunit.assertAlmostEquals(regularChild2.x, 0)
|
||||
luaunit.assertEquals(regularChild1.x, 0)
|
||||
luaunit.assertEquals(regularChild2.x, 0)
|
||||
end
|
||||
|
||||
function TestAbsolutePositioning:testAbsolutePositioningWithComplexTransformations()
|
||||
@@ -307,8 +304,8 @@ function TestAbsolutePositioning:testAbsolutePositioningWithComplexTransformatio
|
||||
rootWindow:layoutChildren()
|
||||
|
||||
-- Verify absolute position accounts for parent padding and margin
|
||||
luaunit.assertEquals(absChildWithPadding.x, rootWindow.x + containerWithPadding.margin.left + absChildWithPadding.x)
|
||||
luaunit.assertEquals(absChildWithPadding.y, rootWindow.y + containerWithPadding.margin.top + absChildWithPadding.y)
|
||||
luaunit.assertEquals(absChildWithPadding.x, 100 + 15 + 20) -- root x + margin + child x
|
||||
luaunit.assertEquals(absChildWithPadding.y, 50 + 10 + 30) -- root y + margin + child y
|
||||
end
|
||||
|
||||
function TestAbsolutePositioning:testAbsolutePositioningInNestedLayoutWithMultipleLevels()
|
||||
@@ -387,13 +384,14 @@ function TestAbsolutePositioning:testAbsolutePositioningInNestedLayoutWithMultip
|
||||
-- Layout all children
|
||||
rootWindow:layoutChildren()
|
||||
|
||||
-- Verify absolute position at deepest level (relative to parent hierarchy)
|
||||
luaunit.assertEquals(absChildAtLevel3.x, rootWindow.x + level1Container.x + level2Container.x + level3Container.x + absChildAtLevel3.x)
|
||||
luaunit.assertEquals(absChildAtLevel3.y, rootWindow.y + level1Container.y + level2Container.y + level3Container.y + absChildAtLevel3.y)
|
||||
-- Verify absolute position at deepest level
|
||||
luaunit.assertEquals(absChildAtLevel3.x, 50 + 0 + 20 + 10) -- root x + level1 x + level2 x + child x
|
||||
luaunit.assertEquals(absChildAtLevel3.y, 30 + 0 + 10 + 20) -- root y + level1 y + level2 y + child y
|
||||
|
||||
-- Verify that flex child is positioned by flex layout at level 3
|
||||
luaunit.assertAlmostEquals(flexChildAtLevel3.x, 0) -- Should be at start of container
|
||||
luaunit.assertEquals(flexChildAtLevel3.x, 0) -- Should be at start of container
|
||||
end
|
||||
|
||||
-- Run the tests
|
||||
luaunit.LuaUnit.run()
|
||||
|
||||
|
||||
@@ -98,26 +98,24 @@ function TestDepthLayouts:testMaximumNestingDepth()
|
||||
parentWindow:layoutChildren()
|
||||
|
||||
-- Verify that each level is positioned correctly
|
||||
-- CSS behavior: nested containers should maintain their relative positions within parents
|
||||
luaunit.assertAlmostEquals(level1.x, 0)
|
||||
luaunit.assertAlmostEquals(level1.y, 0)
|
||||
luaunit.assertEquals(level1.x, 0)
|
||||
luaunit.assertEquals(level1.y, 0)
|
||||
|
||||
luaunit.assertAlmostEquals(level2.x, 0)
|
||||
luaunit.assertAlmostEquals(level2.y, 0)
|
||||
luaunit.assertEquals(level2.x, 0)
|
||||
luaunit.assertEquals(level2.y, 0)
|
||||
|
||||
luaunit.assertAlmostEquals(level3.x, 0)
|
||||
luaunit.assertAlmostEquals(level3.y, 0)
|
||||
luaunit.assertEquals(level3.x, 0)
|
||||
luaunit.assertEquals(level3.y, 0)
|
||||
|
||||
luaunit.assertAlmostEquals(level4.x, 0)
|
||||
luaunit.assertAlmostEquals(level4.y, 0)
|
||||
luaunit.assertEquals(level4.x, 0)
|
||||
luaunit.assertEquals(level4.y, 0)
|
||||
|
||||
luaunit.assertAlmostEquals(level5.x, 0)
|
||||
luaunit.assertAlmostEquals(level5.y, 0)
|
||||
luaunit.assertEquals(level5.x, 0)
|
||||
luaunit.assertEquals(level5.y, 0)
|
||||
|
||||
-- Verify that the deepest child is positioned correctly
|
||||
-- CSS behavior: deepest child should be positioned according to its container's justify content and alignment properties
|
||||
luaunit.assertAlmostEquals(deepChild.x, 0)
|
||||
luaunit.assertAlmostEquals(deepChild.y, level5.h - deepChild.h) -- Should be at bottom position
|
||||
luaunit.assertEquals(deepChild.x, 0)
|
||||
luaunit.assertEquals(deepChild.y, 40 - 15) -- Should be at bottom position
|
||||
end
|
||||
|
||||
function TestDepthLayouts:testPropertyInheritanceThroughNesting()
|
||||
@@ -182,20 +180,20 @@ function TestDepthLayouts:testPropertyInheritanceThroughNesting()
|
||||
parentWindow:layoutChildren()
|
||||
|
||||
-- Verify that properties are inherited appropriately
|
||||
-- CSS behavior: nested containers should inherit flex properties from their parent, unless explicitly overridden
|
||||
luaunit.assertAlmostEquals(level1.x, 0)
|
||||
luaunit.assertAlmostEquals(level1.y, (parentWindow.h - level1.h) / 2) -- Centered vertically
|
||||
-- The parent's flexWrap should be preserved through nesting
|
||||
-- The level1's flexDirection should be VERTICAL, and level2's should be HORIZONTAL
|
||||
luaunit.assertEquals(level1.x, 0)
|
||||
luaunit.assertEquals(level1.y, (200 - 150) / 2) -- Centered vertically
|
||||
|
||||
luaunit.assertAlmostEquals(level2.x, 0)
|
||||
luaunit.assertAlmostEquals(level2.y, 0)
|
||||
luaunit.assertEquals(level2.x, 0)
|
||||
luaunit.assertEquals(level2.y, 0)
|
||||
|
||||
-- Verify that children are positioned correctly based on their container's properties
|
||||
-- CSS behavior: child positioning should respect the flex direction and justify content of its container
|
||||
luaunit.assertAlmostEquals(child1.x, 0)
|
||||
luaunit.assertAlmostEquals(child1.y, (level1.h - child1.h) / 2) -- Centered vertically within level1
|
||||
luaunit.assertEquals(child1.x, 0)
|
||||
luaunit.assertEquals(child1.y, (150 - 30) / 2) -- Centered vertically within level1
|
||||
|
||||
luaunit.assertAlmostEquals(child2.x, (level2.w - child2.w) / 2) -- Centered horizontally within level2
|
||||
luaunit.assertAlmostEquals(child2.y, (level2.h - child2.h) / 2) -- Centered vertically within level2
|
||||
luaunit.assertEquals(child2.x, (200 - 60) / 2) -- Centered horizontally within level2
|
||||
luaunit.assertEquals(child2.y, (100 - 40) / 2) -- Centered vertically within level2
|
||||
end
|
||||
|
||||
function TestDepthLayouts:testSizeCalculationAccuracyAtDepth()
|
||||
@@ -271,23 +269,21 @@ function TestDepthLayouts:testSizeCalculationAccuracyAtDepth()
|
||||
parentWindow:layoutChildren()
|
||||
|
||||
-- Verify that dimensions are preserved through nesting
|
||||
-- CSS behavior: nested containers should maintain their specified dimensions
|
||||
luaunit.assertAlmostEquals(level1.w, 300)
|
||||
luaunit.assertAlmostEquals(level1.h, 200)
|
||||
luaunit.assertEquals(level1.w, 300)
|
||||
luaunit.assertEquals(level1.h, 200)
|
||||
|
||||
luaunit.assertAlmostEquals(level2.w, 250)
|
||||
luaunit.assertAlmostEquals(level2.h, 150)
|
||||
luaunit.assertEquals(level2.w, 250)
|
||||
luaunit.assertEquals(level2.h, 150)
|
||||
|
||||
luaunit.assertAlmostEquals(level3.w, 200)
|
||||
luaunit.assertAlmostEquals(level3.h, 100)
|
||||
luaunit.assertEquals(level3.w, 200)
|
||||
luaunit.assertEquals(level3.h, 100)
|
||||
|
||||
-- Verify that children are positioned correctly within their containers
|
||||
-- CSS behavior: child positioning should be calculated based on container dimensions and justify content
|
||||
luaunit.assertAlmostEquals(child1.x, (level3.w - child1.w) / 2) -- Centered horizontally within level3
|
||||
luaunit.assertAlmostEquals(child1.y, (level3.h - child1.h) / 2) -- Centered vertically within level3
|
||||
luaunit.assertEquals(child1.x, (200 - 50) / 2) -- Centered horizontally within level3
|
||||
luaunit.assertEquals(child1.y, (100 - 30) / 2) -- Centered vertically within level3
|
||||
|
||||
luaunit.assertAlmostEquals(child2.x, (level3.w - child2.w) / 2 + child1.w + parentWindow.gap) -- Positioned after first child + gap
|
||||
luaunit.assertAlmostEquals(child2.y, (level3.h - child2.h) / 2) -- Centered vertically within level3
|
||||
luaunit.assertEquals(child2.x, (200 - 60) / 2 + 50 + 10) -- Positioned after first child + gap
|
||||
luaunit.assertEquals(child2.y, (100 - 40) / 2) -- Centered vertically within level3
|
||||
end
|
||||
|
||||
function TestDepthLayouts:testEdgeCasesInDeepLayouts()
|
||||
@@ -371,29 +367,27 @@ function TestDepthLayouts:testEdgeCasesInDeepLayouts()
|
||||
parentWindow:layoutChildren()
|
||||
|
||||
-- Verify that edge cases are handled correctly
|
||||
-- CSS behavior: nested layouts should handle various combinations of flex properties and child sizes gracefully
|
||||
luaunit.assertAlmostEquals(level1.x, 0)
|
||||
luaunit.assertAlmostEquals(level1.y, 0)
|
||||
luaunit.assertEquals(level1.x, 0)
|
||||
luaunit.assertEquals(level1.y, 0)
|
||||
|
||||
luaunit.assertAlmostEquals(level2.x, 0)
|
||||
luaunit.assertAlmostEquals(level2.y, 0)
|
||||
luaunit.assertEquals(level2.x, 0)
|
||||
luaunit.assertEquals(level2.y, 0)
|
||||
|
||||
-- Verify children in level2 are positioned correctly (centered)
|
||||
-- CSS behavior: child positioning should respect justify content properties
|
||||
luaunit.assertAlmostEquals(child1.x, (level2.w - child1.w) / 2) -- Centered horizontally
|
||||
luaunit.assertAlmostEquals(child1.y, (level2.h - child1.h) / 2) -- Centered vertically
|
||||
luaunit.assertEquals(child1.x, (300 - 80) / 2) -- Centered horizontally
|
||||
luaunit.assertEquals(child1.y, (200 - 40) / 2) -- Centered vertically
|
||||
|
||||
luaunit.assertAlmostEquals(child2.x, (level2.w - child2.w) / 2 + child1.w + parentWindow.gap) -- Positioned after first child + gap
|
||||
luaunit.assertAlmostEquals(child2.y, (level2.h - child2.h) / 2) -- Centered vertically
|
||||
luaunit.assertEquals(child2.x, (300 - 100) / 2 + 80 + 10) -- Positioned after first child + gap
|
||||
luaunit.assertEquals(child2.y, (200 - 50) / 2) -- Centered vertically
|
||||
|
||||
-- Verify children in level1 are positioned correctly
|
||||
-- CSS behavior: child positioning should respect the flex direction and justify content of its container
|
||||
luaunit.assertAlmostEquals(deepChild1.x, 0)
|
||||
luaunit.assertAlmostEquals(deepChild1.y, 0)
|
||||
luaunit.assertEquals(deepChild1.x, 0)
|
||||
luaunit.assertEquals(deepChild1.y, 0)
|
||||
|
||||
luaunit.assertAlmostEquals(deepChild2.x, 0)
|
||||
luaunit.assertAlmostEquals(deepChild2.y, deepChild1.h + parentWindow.gap) -- Positioned after first child + gap
|
||||
luaunit.assertEquals(deepChild2.x, 0)
|
||||
luaunit.assertEquals(deepChild2.y, 20 + 10) -- Positioned after first child + gap
|
||||
end
|
||||
|
||||
-- Run the tests
|
||||
luaunit.LuaUnit.run()
|
||||
|
||||
|
||||
@@ -80,13 +80,12 @@ function TestFlexDirection:testHorizontalLayoutChildren()
|
||||
window:layoutChildren()
|
||||
|
||||
-- Verify positions for horizontal layout (children should be placed side by side)
|
||||
-- In CSS, horizontal flex direction means children are laid out from left to right
|
||||
luaunit.assertAlmostEquals(child1.x, 0) -- First child at start position
|
||||
luaunit.assertAlmostEquals(child1.y, 0) -- First child at top position
|
||||
luaunit.assertEquals(child1.x, 0) -- First child at start position
|
||||
luaunit.assertEquals(child1.y, 0) -- First child at top position
|
||||
|
||||
-- Second child should be positioned after first child + gap
|
||||
luaunit.assertAlmostEquals(child2.x, child1.w + window.gap) -- child1 width + gap
|
||||
luaunit.assertAlmostEquals(child2.y, 0) -- Same y position as first child
|
||||
luaunit.assertEquals(child2.x, 50 + 10) -- child1 width + gap
|
||||
luaunit.assertEquals(child2.y, 0) -- Same y position as first child
|
||||
end
|
||||
|
||||
function TestFlexDirection:testVerticalLayoutChildren()
|
||||
@@ -125,13 +124,12 @@ function TestFlexDirection:testVerticalLayoutChildren()
|
||||
window:layoutChildren()
|
||||
|
||||
-- Verify positions for vertical layout (children should be placed one below another)
|
||||
-- In CSS, vertical flex direction means children are laid out from top to bottom
|
||||
luaunit.assertAlmostEquals(child1.x, 0) -- First child at left position
|
||||
luaunit.assertAlmostEquals(child1.y, 0) -- First child at start position
|
||||
luaunit.assertEquals(child1.x, 0) -- First child at left position
|
||||
luaunit.assertEquals(child1.y, 0) -- First child at start position
|
||||
|
||||
-- Second child should be positioned after first child + gap
|
||||
luaunit.assertAlmostEquals(child2.x, 0) -- Same x position as first child
|
||||
luaunit.assertAlmostEquals(child2.y, child1.h + window.gap) -- child1 height + gap
|
||||
luaunit.assertEquals(child2.x, 0) -- Same x position as first child
|
||||
luaunit.assertEquals(child2.y, 30 + 10) -- child1 height + gap
|
||||
end
|
||||
|
||||
function TestFlexDirection:testFlexDirectionInheritance()
|
||||
@@ -158,8 +156,7 @@ function TestFlexDirection:testFlexDirectionInheritance()
|
||||
})
|
||||
|
||||
-- Verify child inherits flex direction from parent
|
||||
-- CSS inheritance means child should inherit the flex direction from its parent
|
||||
luaunit.assertEquals(child.flexDirection, parentWindow.flexDirection)
|
||||
luaunit.assertEquals(child.flexDirection, enums.FlexDirection.HORIZONTAL)
|
||||
end
|
||||
|
||||
-- Run the tests
|
||||
|
||||
Reference in New Issue
Block a user