From 35b111893def885025441a99a90507811d74a3f9 Mon Sep 17 00:00:00 2001 From: Michael Freno Date: Wed, 17 Sep 2025 12:13:35 -0400 Subject: [PATCH] remove flex positioning requirement for resizing --- FlexLove.lua | 16 ++++++---------- testing/absolute-positioning.lua | 13 ++++--------- testing/align-self-tests.lua | 3 +-- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/FlexLove.lua b/FlexLove.lua index cb00ce9..fd5a7af 100644 --- a/FlexLove.lua +++ b/FlexLove.lua @@ -893,20 +893,16 @@ function Element:resize(newGameWidth, newGameHeight) local ratioW = newGameWidth / prevW local ratioH = newGameHeight / prevH -- Update element size - if self.positioning ~= Positioning.ABSOLUTE then - self.width = self.width * ratioW - self.height = self.height * ratioH - self.x = self.x * ratioW - self.y = self.y * ratioH - end + self.width = self.width * ratioW + self.height = self.height * ratioH + self.x = self.x * ratioW + self.y = self.y * ratioH -- Update children positions and sizes for _, child in ipairs(self.children) do child:resize(ratioW, ratioH) end - -- Re-layout children after resizing (only for non-absolute containers) - if self.positioning ~= Positioning.ABSOLUTE then - self:layoutChildren() - end + + self:layoutChildren() self.prevGameSize.width = newGameWidth self.prevGameSize.height = newGameHeight end diff --git a/testing/absolute-positioning.lua b/testing/absolute-positioning.lua index 4273115..f2998c3 100644 --- a/testing/absolute-positioning.lua +++ b/testing/absolute-positioning.lua @@ -153,18 +153,13 @@ function TestAbsolutePositioning:testAbsolutePositioningResizing() 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 window:resize(newWidth, newHeight) - -- The key test is that absolute positioning should work regardless of how we resize - -- The child's coordinates should be maintained as they are, and the parent should resize properly - luaunit.assertEquals(window.width, 400) - 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 + luaunit.assertEquals(window.width, 100) + luaunit.assertEquals(window.height, 75) + luaunit.assertEquals(child.positioning, enums.Positioning.ABSOLUTE) end function TestAbsolutePositioning:testAbsolutePositioningWithPaddingAndMargin() diff --git a/testing/align-self-tests.lua b/testing/align-self-tests.lua index 3fdb872..0f4c1ad 100644 --- a/testing/align-self-tests.lua +++ b/testing/align-self-tests.lua @@ -150,8 +150,6 @@ function TestAlignSelf:testCenterAlignSelf() -- Add a child with center align self local child = Gui.new({ parent = window, - x = 0, - y = 0, w = 50, h = 30, text = "Test Button", @@ -162,6 +160,7 @@ function TestAlignSelf:testCenterAlignSelf() window:layoutChildren() -- 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 end