remove flex positioning requirement for resizing
This commit is contained in:
@@ -893,20 +893,16 @@ function Element:resize(newGameWidth, newGameHeight)
|
|||||||
local ratioW = newGameWidth / prevW
|
local ratioW = newGameWidth / prevW
|
||||||
local ratioH = newGameHeight / prevH
|
local ratioH = newGameHeight / prevH
|
||||||
-- Update element size
|
-- Update element size
|
||||||
if self.positioning ~= Positioning.ABSOLUTE then
|
|
||||||
self.width = self.width * ratioW
|
self.width = self.width * ratioW
|
||||||
self.height = self.height * ratioH
|
self.height = self.height * ratioH
|
||||||
self.x = self.x * ratioW
|
self.x = self.x * ratioW
|
||||||
self.y = self.y * ratioH
|
self.y = self.y * ratioH
|
||||||
end
|
|
||||||
-- Update children positions and sizes
|
-- Update children positions and sizes
|
||||||
for _, child in ipairs(self.children) do
|
for _, child in ipairs(self.children) do
|
||||||
child:resize(ratioW, ratioH)
|
child:resize(ratioW, ratioH)
|
||||||
end
|
end
|
||||||
-- Re-layout children after resizing (only for non-absolute containers)
|
|
||||||
if self.positioning ~= Positioning.ABSOLUTE then
|
|
||||||
self:layoutChildren()
|
self:layoutChildren()
|
||||||
end
|
|
||||||
self.prevGameSize.width = newGameWidth
|
self.prevGameSize.width = newGameWidth
|
||||||
self.prevGameSize.height = newGameHeight
|
self.prevGameSize.height = newGameHeight
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -153,18 +153,13 @@ function TestAbsolutePositioning:testAbsolutePositioningResizing()
|
|||||||
text = "Test Button",
|
text = "Test Button",
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Resize the window (from 200x150 to 400x300)
|
-- Resize the window from 800x600 (set in stub) to 400x300
|
||||||
local newWidth, newHeight = 400, 300
|
local newWidth, newHeight = 400, 300
|
||||||
window:resize(newWidth, newHeight)
|
window:resize(newWidth, newHeight)
|
||||||
|
|
||||||
-- The key test is that absolute positioning should work regardless of how we resize
|
luaunit.assertEquals(window.width, 100)
|
||||||
-- The child's coordinates should be maintained as they are, and the parent should resize properly
|
luaunit.assertEquals(window.height, 75)
|
||||||
luaunit.assertEquals(window.width, 400)
|
luaunit.assertEquals(child.positioning, enums.Positioning.ABSOLUTE)
|
||||||
luaunit.assertEquals(window.height, 300)
|
|
||||||
luaunit.assertEquals(child.positioning, enums.Positioning.ABSOLUTE) -- Child should still be absolute
|
|
||||||
|
|
||||||
-- We can't easily test exact coordinate values because the resize behavior is complex,
|
|
||||||
-- but we can verify that the child still exists and maintains its properties
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function TestAbsolutePositioning:testAbsolutePositioningWithPaddingAndMargin()
|
function TestAbsolutePositioning:testAbsolutePositioningWithPaddingAndMargin()
|
||||||
|
|||||||
@@ -150,8 +150,6 @@ function TestAlignSelf:testCenterAlignSelf()
|
|||||||
-- Add a child with center align self
|
-- Add a child with center align self
|
||||||
local child = Gui.new({
|
local child = Gui.new({
|
||||||
parent = window,
|
parent = window,
|
||||||
x = 0,
|
|
||||||
y = 0,
|
|
||||||
w = 50,
|
w = 50,
|
||||||
h = 30,
|
h = 30,
|
||||||
text = "Test Button",
|
text = "Test Button",
|
||||||
@@ -162,6 +160,7 @@ function TestAlignSelf:testCenterAlignSelf()
|
|||||||
window:layoutChildren()
|
window:layoutChildren()
|
||||||
|
|
||||||
-- With center, child should be centered along cross axis
|
-- With center, child should be centered along cross axis
|
||||||
|
luaunit.assertEquals(child.x, 0)
|
||||||
luaunit.assertEquals(child.y, (200 - 30) / 2) -- Should be centered vertically
|
luaunit.assertEquals(child.y, (200 - 30) / 2) -- Should be centered vertically
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user