From 3f7ab0a904aa1b2ef388ebc43076810bad9809a0 Mon Sep 17 00:00:00 2001 From: Michael Freno Date: Sat, 20 Sep 2025 09:16:52 -0400 Subject: [PATCH] fixed layout resizing --- FlexLove.lua | 3 ++- simple_resize_test.lua | 51 ++++++++++++++++++++++++++++++++++++ testing/test_font_resize.lua | 36 +++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 simple_resize_test.lua create mode 100644 testing/test_font_resize.lua diff --git a/FlexLove.lua b/FlexLove.lua index 4a1f326..881b890 100644 --- a/FlexLove.lua +++ b/FlexLove.lua @@ -1048,6 +1048,7 @@ function Element:update(dt) -- set pressed flag self._pressed = true elseif not love.mouse.isDown(1) and self._pressed then + Logger:debug("calling callback") self.callback(self) self._pressed = false end @@ -1083,7 +1084,7 @@ function Element:resize(newGameWidth, newGameHeight) self.y = self.y * ratioH -- Update children positions and sizes for _, child in ipairs(self.children) do - child:resize(ratioW, ratioH) + child:resize(newGameWidth, newGameHeight) end self:layoutChildren() diff --git a/simple_resize_test.lua b/simple_resize_test.lua new file mode 100644 index 0000000..a01646b --- /dev/null +++ b/simple_resize_test.lua @@ -0,0 +1,51 @@ +#!/usr/bin/env lua + +-- Load test framework and dependencies +package.path = package.path .. ";?.lua" +require("testing/loveStub") -- Required to mock LOVE functions +local FlexLove = require("FlexLove") +local Gui, enums = FlexLove.GUI, FlexLove.enums +local Positioning, FlexDirection, AlignItems = + enums.Positioning, enums.FlexDirection, enums.AlignItems + +-- Simple resize test +print("=== Simple Resize Test ===") + +-- Initial window size: 800x600 +love.window.setMode(800, 600) + +local parent = Gui.new({ + id = "parent", + x = 100, + y = 100, + w = 200, + h = 150, + positioning = Positioning.FLEX, + flexDirection = FlexDirection.HORIZONTAL, + alignItems = AlignItems.STRETCH, +}) + +local child = Gui.new({ + id = "child", + w = 100, + h = 80, + positioning = Positioning.FLEX, +}) + +parent:addChild(child) + +print("Before resize:") +print(" Parent: x=" .. parent.x .. ", y=" .. parent.y .. ", w=" .. parent.width .. ", h=" .. parent.height) +print(" Child: x=" .. child.x .. ", y=" .. child.y .. ", w=" .. child.width .. ", h=" .. child.height) + +-- Resize window to 1600x1200 (2x scale) +love.window.setMode(1600, 1200) +Gui.resize() + +print("After resize to 1600x1200:") +print(" Parent: x=" .. parent.x .. ", y=" .. parent.y .. ", w=" .. parent.width .. ", h=" .. parent.height) +print(" Child: x=" .. child.x .. ", y=" .. child.y .. ", w=" .. child.width .. ", h=" .. child.height) + +print("Expected child dimensions after 2x resize:") +print(" Child width: 200 (100 * 2)") +print(" Child height: 160 (80 * 2)") \ No newline at end of file diff --git a/testing/test_font_resize.lua b/testing/test_font_resize.lua new file mode 100644 index 0000000..9e39343 --- /dev/null +++ b/testing/test_font_resize.lua @@ -0,0 +1,36 @@ +-- Test current font behavior during resize +package.path = package.path .. ";?.lua" + +require("testing/loveStub") -- Required to mock LOVE functions +local FlexLove = require("FlexLove") +local Gui = FlexLove.GUI + +local function testCurrentFontBehavior() + print("=== Testing Current Font Behavior During Resize ===") + + Gui.destroy() -- Clean slate + + -- Create element with text and specific font size + local element = Gui.new({ + id = "textElement", + x = 100, y = 100, + w = 400, h = 200, + text = "Hello World", + textSize = 16 + }) + element.prevGameSize = { width = 800, height = 600 } + + print("Before resize:") + print(string.format("Element: %dx%d, textSize: %s", element.width, element.height, element.textSize or "nil")) + + -- Resize from 800x600 to 1200x900 (1.5x scale) + element:resize(1200, 900) + + print("\nAfter resize (1200x900):") + print(string.format("Element: %dx%d, textSize: %s", element.width, element.height, element.textSize or "nil")) + + print("\nExpected: Element should be 600x300, textSize should scale to 24 (16 * 1.5)") + print("Current: textSize doesn't scale - this is the issue we need to fix") +end + +testCurrentFontBehavior() \ No newline at end of file