removing excessive comments

This commit is contained in:
Michael Freno
2025-11-13 00:48:50 -05:00
parent 225dff8f74
commit 6a14b277f9
4 changed files with 13 additions and 68 deletions

View File

@@ -61,7 +61,6 @@ function Animation.new(props)
self.transition = props.transition self.transition = props.transition
self.elapsed = 0 self.elapsed = 0
-- Set easing function (default to linear)
local easingName = props.easing or "linear" local easingName = props.easing or "linear"
self.easing = Easing[easingName] or Easing.linear self.easing = Easing[easingName] or Easing.linear
@@ -76,9 +75,9 @@ end
---@return boolean ---@return boolean
function Animation:update(dt) function Animation:update(dt)
self.elapsed = self.elapsed + dt self.elapsed = self.elapsed + dt
self._resultDirty = true -- Mark cached result as dirty self._resultDirty = true
if self.elapsed >= self.duration then if self.elapsed >= self.duration then
return true -- finished return true
else else
return false return false
end end
@@ -92,15 +91,13 @@ function Animation:interpolate()
end end
local t = math.min(self.elapsed / self.duration, 1) local t = math.min(self.elapsed / self.duration, 1)
t = self.easing(t) -- Apply easing function t = self.easing(t)
local result = self._cachedResult -- Reuse existing table local result = self._cachedResult -- Reuse existing table
-- Clear previous values
result.width = nil result.width = nil
result.height = nil result.height = nil
result.opacity = nil result.opacity = nil
-- Handle width and height if present
if self.start.width and self.final.width then if self.start.width and self.final.width then
result.width = self.start.width * (1 - t) + self.final.width * t result.width = self.start.width * (1 - t) + self.final.width * t
end end
@@ -109,31 +106,23 @@ function Animation:interpolate()
result.height = self.start.height * (1 - t) + self.final.height * t result.height = self.start.height * (1 - t) + self.final.height * t
end end
-- Handle other properties like opacity
if self.start.opacity and self.final.opacity then if self.start.opacity and self.final.opacity then
result.opacity = self.start.opacity * (1 - t) + self.final.opacity * t result.opacity = self.start.opacity * (1 - t) + self.final.opacity * t
end end
-- Apply transform if present
if self.transform then if self.transform then
for key, value in pairs(self.transform) do for key, value in pairs(self.transform) do
result[key] = value result[key] = value
end end
end end
self._resultDirty = false -- Mark as clean self._resultDirty = false
return result return result
end end
--- Apply animation to a GUI element
---@param element Element ---@param element Element
function Animation:apply(element) function Animation:apply(element)
if element.animation then
-- If there's an existing animation, we should probably stop it or replace it
element.animation = self element.animation = self
else
element.animation = self
end
end end
--- Create a simple fade animation --- Create a simple fade animation

View File

@@ -6,9 +6,9 @@ local MAX_CACHE_SIZE = 20
--- Build Gaussian blur shader with given parameters --- Build Gaussian blur shader with given parameters
---@param taps number -- Number of samples (must be odd, >= 3) ---@param taps number -- Number of samples (must be odd, >= 3)
---@param offset number -- Offset multiplier for sampling ---@param offset number
---@param offset_type string -- "weighted" or "center" ---@param offset_type string -- "weighted" or "center"
---@param sigma number -- Gaussian sigma value ---@param sigma number
---@return love.Shader ---@return love.Shader
local function buildShader(taps, offset, offset_type, sigma) local function buildShader(taps, offset, offset_type, sigma)
taps = math.floor(taps) taps = math.floor(taps)
@@ -17,7 +17,6 @@ local function buildShader(taps, offset, offset_type, sigma)
local steps = (taps + 1) / 2 local steps = (taps + 1) / 2
-- Calculate gaussian function
local g_offsets = {} local g_offsets = {}
local g_weights = {} local g_weights = {}
for i = 1, steps, 1 do for i = 1, steps, 1 do
@@ -76,7 +75,6 @@ local function getCanvas(width, height)
local cache = canvasCache[key] local cache = canvasCache[key]
-- Try to reuse existing canvas
for i, canvas in ipairs(cache) do for i, canvas in ipairs(cache) do
if not canvas.inUse then if not canvas.inUse then
canvas.inUse = true canvas.inUse = true
@@ -84,11 +82,9 @@ local function getCanvas(width, height)
end end
end end
-- Create new canvas if none available
local canvas = love.graphics.newCanvas(width, height) local canvas = love.graphics.newCanvas(width, height)
table.insert(cache, { canvas = canvas, inUse = true }) table.insert(cache, { canvas = canvas, inUse = true })
-- Limit cache size
if #cache > MAX_CACHE_SIZE then if #cache > MAX_CACHE_SIZE then
table.remove(cache, 1) table.remove(cache, 1)
end end
@@ -150,30 +146,24 @@ end
---@param drawFunc function -- Function to draw content to be blurred ---@param drawFunc function -- Function to draw content to be blurred
function Blur.applyToRegion(blurInstance, intensity, x, y, width, height, drawFunc) function Blur.applyToRegion(blurInstance, intensity, x, y, width, height, drawFunc)
if intensity <= 0 or width <= 0 or height <= 0 then if intensity <= 0 or width <= 0 or height <= 0 then
-- No blur, just draw normally
drawFunc() drawFunc()
return return
end end
-- Clamp intensity
intensity = math.max(0, math.min(100, intensity)) intensity = math.max(0, math.min(100, intensity))
-- Calculate blur passes based on intensity
-- Intensity 0-100 maps to 0-5 passes -- Intensity 0-100 maps to 0-5 passes
local passes = math.ceil(intensity / 20) local passes = math.ceil(intensity / 20)
passes = math.max(1, math.min(5, passes)) passes = math.max(1, math.min(5, passes))
-- Get canvases for ping-pong rendering
local canvas1 = getCanvas(width, height) local canvas1 = getCanvas(width, height)
local canvas2 = getCanvas(width, height) local canvas2 = getCanvas(width, height)
-- Save graphics state
local prevCanvas = love.graphics.getCanvas() local prevCanvas = love.graphics.getCanvas()
local prevShader = love.graphics.getShader() local prevShader = love.graphics.getShader()
local prevColor = { love.graphics.getColor() } local prevColor = { love.graphics.getColor() }
local prevBlendMode = love.graphics.getBlendMode() local prevBlendMode = love.graphics.getBlendMode()
-- Render content to first canvas
love.graphics.setCanvas(canvas1) love.graphics.setCanvas(canvas1)
love.graphics.clear() love.graphics.clear()
love.graphics.push() love.graphics.push()
@@ -182,36 +172,30 @@ function Blur.applyToRegion(blurInstance, intensity, x, y, width, height, drawFu
drawFunc() drawFunc()
love.graphics.pop() love.graphics.pop()
-- Apply blur passes
love.graphics.setShader(blurInstance.shader) love.graphics.setShader(blurInstance.shader)
love.graphics.setColor(1, 1, 1, 1) love.graphics.setColor(1, 1, 1, 1)
love.graphics.setBlendMode("alpha", "premultiplied") love.graphics.setBlendMode("alpha", "premultiplied")
for i = 1, passes do for i = 1, passes do
-- Horizontal pass
love.graphics.setCanvas(canvas2) love.graphics.setCanvas(canvas2)
love.graphics.clear() love.graphics.clear()
blurInstance.shader:send("direction", { 1 / width, 0 }) blurInstance.shader:send("direction", { 1 / width, 0 })
love.graphics.draw(canvas1, 0, 0) love.graphics.draw(canvas1, 0, 0)
-- Vertical pass
love.graphics.setCanvas(canvas1) love.graphics.setCanvas(canvas1)
love.graphics.clear() love.graphics.clear()
blurInstance.shader:send("direction", { 0, 1 / height }) blurInstance.shader:send("direction", { 0, 1 / height })
love.graphics.draw(canvas2, 0, 0) love.graphics.draw(canvas2, 0, 0)
end end
-- Draw blurred result to screen
love.graphics.setCanvas(prevCanvas) love.graphics.setCanvas(prevCanvas)
love.graphics.setShader() love.graphics.setShader()
love.graphics.setBlendMode(prevBlendMode) love.graphics.setBlendMode(prevBlendMode)
love.graphics.draw(canvas1, x, y) love.graphics.draw(canvas1, x, y)
-- Restore graphics state
love.graphics.setShader(prevShader) love.graphics.setShader(prevShader)
love.graphics.setColor(unpack(prevColor)) love.graphics.setColor(unpack(prevColor))
-- Release canvases back to cache
releaseCanvas(canvas1) releaseCanvas(canvas1)
releaseCanvas(canvas2) releaseCanvas(canvas2)
end end
@@ -229,62 +213,50 @@ function Blur.applyBackdrop(blurInstance, intensity, x, y, width, height, backdr
return return
end end
-- Clamp intensity
intensity = math.max(0, math.min(100, intensity)) intensity = math.max(0, math.min(100, intensity))
-- Calculate blur passes based on intensity
local passes = math.ceil(intensity / 20) local passes = math.ceil(intensity / 20)
passes = math.max(1, math.min(5, passes)) passes = math.max(1, math.min(5, passes))
-- Get canvases for ping-pong rendering
local canvas1 = getCanvas(width, height) local canvas1 = getCanvas(width, height)
local canvas2 = getCanvas(width, height) local canvas2 = getCanvas(width, height)
-- Save graphics state
local prevCanvas = love.graphics.getCanvas() local prevCanvas = love.graphics.getCanvas()
local prevShader = love.graphics.getShader() local prevShader = love.graphics.getShader()
local prevColor = { love.graphics.getColor() } local prevColor = { love.graphics.getColor() }
local prevBlendMode = love.graphics.getBlendMode() local prevBlendMode = love.graphics.getBlendMode()
-- Extract the region from backdrop
love.graphics.setCanvas(canvas1) love.graphics.setCanvas(canvas1)
love.graphics.clear() love.graphics.clear()
love.graphics.setColor(1, 1, 1, 1) love.graphics.setColor(1, 1, 1, 1)
love.graphics.setBlendMode("alpha", "premultiplied") love.graphics.setBlendMode("alpha", "premultiplied")
-- Create a quad for the region
local backdropWidth, backdropHeight = backdropCanvas:getDimensions() local backdropWidth, backdropHeight = backdropCanvas:getDimensions()
local quad = love.graphics.newQuad(x, y, width, height, backdropWidth, backdropHeight) local quad = love.graphics.newQuad(x, y, width, height, backdropWidth, backdropHeight)
love.graphics.draw(backdropCanvas, quad, 0, 0) love.graphics.draw(backdropCanvas, quad, 0, 0)
-- Apply blur passes
love.graphics.setShader(blurInstance.shader) love.graphics.setShader(blurInstance.shader)
for i = 1, passes do for i = 1, passes do
-- Horizontal pass
love.graphics.setCanvas(canvas2) love.graphics.setCanvas(canvas2)
love.graphics.clear() love.graphics.clear()
blurInstance.shader:send("direction", { 1 / width, 0 }) blurInstance.shader:send("direction", { 1 / width, 0 })
love.graphics.draw(canvas1, 0, 0) love.graphics.draw(canvas1, 0, 0)
-- Vertical pass
love.graphics.setCanvas(canvas1) love.graphics.setCanvas(canvas1)
love.graphics.clear() love.graphics.clear()
blurInstance.shader:send("direction", { 0, 1 / height }) blurInstance.shader:send("direction", { 0, 1 / height })
love.graphics.draw(canvas2, 0, 0) love.graphics.draw(canvas2, 0, 0)
end end
-- Draw blurred result to screen
love.graphics.setCanvas(prevCanvas) love.graphics.setCanvas(prevCanvas)
love.graphics.setShader() love.graphics.setShader()
love.graphics.setBlendMode(prevBlendMode) love.graphics.setBlendMode(prevBlendMode)
love.graphics.draw(canvas1, x, y) love.graphics.draw(canvas1, x, y)
-- Restore graphics state
love.graphics.setShader(prevShader) love.graphics.setShader(prevShader)
love.graphics.setColor(unpack(prevColor)) love.graphics.setColor(unpack(prevColor))
-- Release canvases back to cache
releaseCanvas(canvas1) releaseCanvas(canvas1)
releaseCanvas(canvas2) releaseCanvas(canvas2)
end end

View File

@@ -1,15 +1,11 @@
--- Standardized error message formatter --- Standardized error message formatter
---@param module string -- Module name (e.g., "Color", "Theme", "Units") ---@param module string -- Module name (e.g., "Color", "Theme", "Units")
---@param message string -- Error message ---@param message string
---@return string -- Formatted error message ---@return string
local function formatError(module, message) local function formatError(module, message)
return string.format("[FlexLove.%s] %s", module, message) return string.format("[FlexLove.%s] %s", module, message)
end end
-- ====================
-- Color System
-- ====================
--- Utility class for color handling --- Utility class for color handling
---@class Color ---@class Color
---@field r number -- Red component (0-1) ---@field r number -- Red component (0-1)
@@ -20,10 +16,10 @@ local Color = {}
Color.__index = Color Color.__index = Color
--- Create a new color instance --- Create a new color instance
---@param r number? -- Default: 0 ---@param r number?
---@param g number? -- Default: 0 ---@param g number?
---@param b number? -- Default: 0 ---@param b number?
---@param a number? -- Default: 1 ---@param a number?
---@return Color ---@return Color
function Color.new(r, g, b, a) function Color.new(r, g, b, a)
local self = setmetatable({}, Color) local self = setmetatable({}, Color)

View File

@@ -228,14 +228,12 @@ function Element.new(props)
self.userdata = props.userdata self.userdata = props.userdata
-- Input event callbacks
self.onFocus = props.onFocus self.onFocus = props.onFocus
self.onBlur = props.onBlur self.onBlur = props.onBlur
self.onTextInput = props.onTextInput self.onTextInput = props.onTextInput
self.onTextChange = props.onTextChange self.onTextChange = props.onTextChange
self.onEnter = props.onEnter self.onEnter = props.onEnter
-- Initialize EventHandler for event processing
self._eventHandler = EventHandler.new({ self._eventHandler = EventHandler.new({
onEvent = self.onEvent, onEvent = self.onEvent,
}, { }, {
@@ -247,7 +245,6 @@ function Element.new(props)
-- Initialize state manager ID for immediate mode (use self.id which may be auto-generated) -- Initialize state manager ID for immediate mode (use self.id which may be auto-generated)
self._stateId = self.id self._stateId = self.id
-- Initialize ThemeManager for theme management
self._themeManager = ThemeManager.new({ self._themeManager = ThemeManager.new({
theme = props.theme or Gui.defaultTheme, theme = props.theme or Gui.defaultTheme,
themeComponent = props.themeComponent or nil, themeComponent = props.themeComponent or nil,
@@ -279,10 +276,8 @@ function Element.new(props)
-- Initialize contentAutoSizingMultiplier after theme is set -- Initialize contentAutoSizingMultiplier after theme is set
-- Priority: element props > theme component > theme default -- Priority: element props > theme component > theme default
if props.contentAutoSizingMultiplier then if props.contentAutoSizingMultiplier then
-- Explicitly set on element
self.contentAutoSizingMultiplier = props.contentAutoSizingMultiplier self.contentAutoSizingMultiplier = props.contentAutoSizingMultiplier
else else
-- Try to source from theme via ThemeManager
local multiplier = self._themeManager:getContentAutoSizingMultiplier() local multiplier = self._themeManager:getContentAutoSizingMultiplier()
self.contentAutoSizingMultiplier = multiplier or { 1, 1 } self.contentAutoSizingMultiplier = multiplier or { 1, 1 }
end end
@@ -291,12 +286,10 @@ function Element.new(props)
self.scaleCorners = self._themeManager.scaleCorners self.scaleCorners = self._themeManager.scaleCorners
self.scalingAlgorithm = self._themeManager.scalingAlgorithm self.scalingAlgorithm = self._themeManager.scalingAlgorithm
-- Initialize blur properties
self.contentBlur = props.contentBlur self.contentBlur = props.contentBlur
self.backdropBlur = props.backdropBlur self.backdropBlur = props.backdropBlur
self._blurInstance = nil self._blurInstance = nil
-- Initialize input control properties
self.editable = props.editable or false self.editable = props.editable or false
self.multiline = props.multiline or false self.multiline = props.multiline or false
self.passwordMode = props.passwordMode or false self.passwordMode = props.passwordMode or false
@@ -316,7 +309,6 @@ function Element.new(props)
self.placeholder = props.placeholder self.placeholder = props.placeholder
self.inputType = props.inputType or "text" self.inputType = props.inputType or "text"
-- Text behavior properties
self.textOverflow = props.textOverflow or "clip" self.textOverflow = props.textOverflow or "clip"
self.scrollable = props.scrollable self.scrollable = props.scrollable
if self.scrollable == nil then if self.scrollable == nil then
@@ -330,12 +322,10 @@ function Element.new(props)
end end
self.selectOnFocus = props.selectOnFocus or false self.selectOnFocus = props.selectOnFocus or false
-- Cursor and selection properties
self.cursorColor = props.cursorColor self.cursorColor = props.cursorColor
self.selectionColor = props.selectionColor self.selectionColor = props.selectionColor
self.cursorBlinkRate = props.cursorBlinkRate or 0.5 self.cursorBlinkRate = props.cursorBlinkRate or 0.5
-- Initialize TextEditor for editable elements
if self.editable then if self.editable then
self._textEditor = TextEditor.new({ self._textEditor = TextEditor.new({
editable = self.editable, editable = self.editable,
@@ -635,7 +625,6 @@ function Element.new(props)
local parentWidth = self.parent and self.parent.width or viewportWidth local parentWidth = self.parent and self.parent.width or viewportWidth
tempWidth = Units.resolve(value, unit, viewportWidth, viewportHeight, parentWidth) tempWidth = Units.resolve(value, unit, viewportWidth, viewportHeight, parentWidth)
else else
-- Apply base scaling to pixel values
tempWidth = Gui.baseScale and (widthProp * scaleX) or widthProp tempWidth = Gui.baseScale and (widthProp * scaleX) or widthProp
self.units.width = { value = widthProp, unit = "px" } self.units.width = { value = widthProp, unit = "px" }
end end
@@ -650,7 +639,6 @@ function Element.new(props)
self.units.width = { value = 100, unit = "%" } -- Mark as parent-constrained self.units.width = { value = 100, unit = "%" } -- Mark as parent-constrained
self.autosizing.width = false -- Not truly autosizing, constrained by parent self.autosizing.width = false -- Not truly autosizing, constrained by parent
else else
-- Calculate auto-width without padding first
tempWidth = self:calculateAutoWidth() tempWidth = self:calculateAutoWidth()
self.width = tempWidth self.width = tempWidth
self.units.width = { value = nil, unit = "auto" } -- Mark as auto-sized self.units.width = { value = nil, unit = "auto" } -- Mark as auto-sized