theme loading fixed, need to fix application

This commit is contained in:
Michael Freno
2025-10-13 09:03:23 -04:00
parent f9da77401a
commit 4ecfb7f354
4 changed files with 193 additions and 66 deletions

View File

@@ -10,7 +10,7 @@ print("=== Base Scaling Demo ===\n")
-- Initialize with base scale (call this in love.load())
Gui.init({
baseScale = { width = 800, height = 600 }
baseScale = { width = 800, height = 600 },
})
print("Designing UI for 800x600 base resolution\n")
@@ -32,22 +32,36 @@ local button = Gui.new({
})
print("At 800x600 (base resolution):")
print(string.format(" Button: x=%d, y=%d, width=%d, height=%d, textSize=%d",
button.x, button.y, button.width, button.height, button.textSize))
print(string.format(" Padding: left=%d, top=%d (NOT scaled)",
button.padding.left, button.padding.top))
print(
string.format(
" Button: x=%d, y=%d, width=%d, height=%d, textSize=%d",
button.x,
button.y,
button.width,
button.height,
button.textSize
)
)
print(string.format(" Padding: left=%d, top=%d (NOT scaled)", button.padding.left, button.padding.top))
-- Simulate window resize to 1600x1200 (2x scale)
print("\nResizing window to 1600x1200...")
love.window.setMode(1600, 1200)
Gui.resize() -- This updates all elements
Gui.resize() -- This updates all elements
local sx, sy = Gui.getScaleFactors()
print(string.format("Scale factors: x=%.1f, y=%.1f", sx, sy))
print(string.format(" Button: x=%d, y=%d, width=%d, height=%d, textSize=%d",
button.x, button.y, button.width, button.height, button.textSize))
print(string.format(" Padding: left=%d, top=%d (NOT scaled)",
button.padding.left, button.padding.top))
print(
string.format(
" Button: x=%d, y=%d, width=%d, height=%d, textSize=%d",
button.x,
button.y,
button.width,
button.height,
button.textSize
)
)
print(string.format(" Padding: left=%d, top=%d (NOT scaled)", button.padding.left, button.padding.top))
-- Simulate window resize to 400x300 (0.5x scale)
print("\nResizing window to 400x300...")
@@ -56,21 +70,28 @@ Gui.resize()
sx, sy = Gui.getScaleFactors()
print(string.format("Scale factors: x=%.1f, y=%.1f", sx, sy))
print(string.format(" Button: x=%d, y=%d, width=%d, height=%d, textSize=%d",
button.x, button.y, button.width, button.height, button.textSize))
print(string.format(" Padding: left=%d, top=%d (NOT scaled)",
button.padding.left, button.padding.top))
print(
string.format(
" Button: x=%d, y=%d, width=%d, height=%d, textSize=%d",
button.x,
button.y,
button.width,
button.height,
button.textSize
)
)
print(string.format(" Padding: left=%d, top=%d (NOT scaled)", button.padding.left, button.padding.top))
print("\n=== Usage ===")
print("In your main.lua:")
print([[
function love.load()
local FlexLove = require("game.libs.FlexLove")
local FlexLove = require("libs.FlexLove")
local Gui = FlexLove.GUI
-- Initialize with your design resolution
Gui.init({ baseScale = { width = 800, height = 600 } })
-- Create UI using base resolution coordinates
-- Everything will scale automatically!
end

View File

@@ -1,21 +1,28 @@
-- Example: Setting theme in Gui.init()
-- NOTE: This should be called in love.load() after LÖVE graphics is initialized
local FlexLove = require("FlexLove")
local Gui = FlexLove.GUI
local Color = FlexLove.Color
local Theme = FlexLove.Theme
-- In love.load():
-- Initialize GUI with theme
Gui.init({
baseScale = { width = 1920, height = 1080 },
theme = "space" -- Load and activate the space theme
})
-- Alternative: Load theme manually if Gui.init() is called before love.load()
-- Theme.load("space")
-- Theme.setActive("space")
-- Now all elements can use the theme
local panel = Gui.new({
x = 100,
y = 100,
width = 400,
height = 300,
theme = "panel",
themeComponent = "panel",
padding = { top = 20, right = 20, bottom = 20, left = 20 },
})
@@ -28,7 +35,7 @@ local button1 = Gui.new({
text = "Normal Button",
textAlign = "center",
textColor = Color.new(1, 1, 1, 1),
theme = "button",
themeComponent = "button",
callback = function(element, event)
if event.type == "click" then
print("Button clicked!")
@@ -45,7 +52,7 @@ local button2 = Gui.new({
text = "Disabled",
textAlign = "center",
textColor = Color.new(0.6, 0.6, 0.6, 1),
theme = "button",
themeComponent = "button",
disabled = true, -- Shows disabled state
callback = function(element, event)
print("This won't fire!")
@@ -60,7 +67,7 @@ local input1 = Gui.new({
height = 40,
text = "Type here...",
textColor = Color.new(1, 1, 1, 1),
theme = "input",
themeComponent = "input",
})
local input2 = Gui.new({
@@ -71,7 +78,7 @@ local input2 = Gui.new({
height = 40,
text = "Active input",
textColor = Color.new(1, 1, 1, 1),
theme = "input",
themeComponent = "input",
active = true, -- Shows active/focused state
})
@@ -83,7 +90,7 @@ local input3 = Gui.new({
height = 40,
text = "Disabled input",
textColor = Color.new(0.6, 0.6, 0.6, 1),
theme = "input",
themeComponent = "input",
disabled = true, -- Shows disabled state
})