removing excessive comments
This commit is contained in:
@@ -61,7 +61,6 @@ function Animation.new(props)
|
||||
self.transition = props.transition
|
||||
self.elapsed = 0
|
||||
|
||||
-- Set easing function (default to linear)
|
||||
local easingName = props.easing or "linear"
|
||||
self.easing = Easing[easingName] or Easing.linear
|
||||
|
||||
@@ -76,9 +75,9 @@ end
|
||||
---@return boolean
|
||||
function Animation:update(dt)
|
||||
self.elapsed = self.elapsed + dt
|
||||
self._resultDirty = true -- Mark cached result as dirty
|
||||
self._resultDirty = true
|
||||
if self.elapsed >= self.duration then
|
||||
return true -- finished
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
@@ -92,15 +91,13 @@ function Animation:interpolate()
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
-- Clear previous values
|
||||
result.width = nil
|
||||
result.height = nil
|
||||
result.opacity = nil
|
||||
|
||||
-- Handle width and height if present
|
||||
if self.start.width and self.final.width then
|
||||
result.width = self.start.width * (1 - t) + self.final.width * t
|
||||
end
|
||||
@@ -109,31 +106,23 @@ function Animation:interpolate()
|
||||
result.height = self.start.height * (1 - t) + self.final.height * t
|
||||
end
|
||||
|
||||
-- Handle other properties like opacity
|
||||
if self.start.opacity and self.final.opacity then
|
||||
result.opacity = self.start.opacity * (1 - t) + self.final.opacity * t
|
||||
end
|
||||
|
||||
-- Apply transform if present
|
||||
if self.transform then
|
||||
for key, value in pairs(self.transform) do
|
||||
result[key] = value
|
||||
end
|
||||
end
|
||||
|
||||
self._resultDirty = false -- Mark as clean
|
||||
self._resultDirty = false
|
||||
return result
|
||||
end
|
||||
|
||||
--- Apply animation to a GUI element
|
||||
---@param element 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
|
||||
else
|
||||
element.animation = self
|
||||
end
|
||||
end
|
||||
|
||||
--- Create a simple fade animation
|
||||
|
||||
@@ -6,9 +6,9 @@ local MAX_CACHE_SIZE = 20
|
||||
|
||||
--- Build Gaussian blur shader with given parameters
|
||||
---@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 sigma number -- Gaussian sigma value
|
||||
---@param sigma number
|
||||
---@return love.Shader
|
||||
local function buildShader(taps, offset, offset_type, sigma)
|
||||
taps = math.floor(taps)
|
||||
@@ -17,7 +17,6 @@ local function buildShader(taps, offset, offset_type, sigma)
|
||||
|
||||
local steps = (taps + 1) / 2
|
||||
|
||||
-- Calculate gaussian function
|
||||
local g_offsets = {}
|
||||
local g_weights = {}
|
||||
for i = 1, steps, 1 do
|
||||
@@ -76,7 +75,6 @@ local function getCanvas(width, height)
|
||||
|
||||
local cache = canvasCache[key]
|
||||
|
||||
-- Try to reuse existing canvas
|
||||
for i, canvas in ipairs(cache) do
|
||||
if not canvas.inUse then
|
||||
canvas.inUse = true
|
||||
@@ -84,11 +82,9 @@ local function getCanvas(width, height)
|
||||
end
|
||||
end
|
||||
|
||||
-- Create new canvas if none available
|
||||
local canvas = love.graphics.newCanvas(width, height)
|
||||
table.insert(cache, { canvas = canvas, inUse = true })
|
||||
|
||||
-- Limit cache size
|
||||
if #cache > MAX_CACHE_SIZE then
|
||||
table.remove(cache, 1)
|
||||
end
|
||||
@@ -150,30 +146,24 @@ end
|
||||
---@param drawFunc function -- Function to draw content to be blurred
|
||||
function Blur.applyToRegion(blurInstance, intensity, x, y, width, height, drawFunc)
|
||||
if intensity <= 0 or width <= 0 or height <= 0 then
|
||||
-- No blur, just draw normally
|
||||
drawFunc()
|
||||
return
|
||||
end
|
||||
|
||||
-- Clamp intensity
|
||||
intensity = math.max(0, math.min(100, intensity))
|
||||
|
||||
-- Calculate blur passes based on intensity
|
||||
-- Intensity 0-100 maps to 0-5 passes
|
||||
local passes = math.ceil(intensity / 20)
|
||||
passes = math.max(1, math.min(5, passes))
|
||||
|
||||
-- Get canvases for ping-pong rendering
|
||||
local canvas1 = getCanvas(width, height)
|
||||
local canvas2 = getCanvas(width, height)
|
||||
|
||||
-- Save graphics state
|
||||
local prevCanvas = love.graphics.getCanvas()
|
||||
local prevShader = love.graphics.getShader()
|
||||
local prevColor = { love.graphics.getColor() }
|
||||
local prevBlendMode = love.graphics.getBlendMode()
|
||||
|
||||
-- Render content to first canvas
|
||||
love.graphics.setCanvas(canvas1)
|
||||
love.graphics.clear()
|
||||
love.graphics.push()
|
||||
@@ -182,36 +172,30 @@ function Blur.applyToRegion(blurInstance, intensity, x, y, width, height, drawFu
|
||||
drawFunc()
|
||||
love.graphics.pop()
|
||||
|
||||
-- Apply blur passes
|
||||
love.graphics.setShader(blurInstance.shader)
|
||||
love.graphics.setColor(1, 1, 1, 1)
|
||||
love.graphics.setBlendMode("alpha", "premultiplied")
|
||||
|
||||
for i = 1, passes do
|
||||
-- Horizontal pass
|
||||
love.graphics.setCanvas(canvas2)
|
||||
love.graphics.clear()
|
||||
blurInstance.shader:send("direction", { 1 / width, 0 })
|
||||
love.graphics.draw(canvas1, 0, 0)
|
||||
|
||||
-- Vertical pass
|
||||
love.graphics.setCanvas(canvas1)
|
||||
love.graphics.clear()
|
||||
blurInstance.shader:send("direction", { 0, 1 / height })
|
||||
love.graphics.draw(canvas2, 0, 0)
|
||||
end
|
||||
|
||||
-- Draw blurred result to screen
|
||||
love.graphics.setCanvas(prevCanvas)
|
||||
love.graphics.setShader()
|
||||
love.graphics.setBlendMode(prevBlendMode)
|
||||
love.graphics.draw(canvas1, x, y)
|
||||
|
||||
-- Restore graphics state
|
||||
love.graphics.setShader(prevShader)
|
||||
love.graphics.setColor(unpack(prevColor))
|
||||
|
||||
-- Release canvases back to cache
|
||||
releaseCanvas(canvas1)
|
||||
releaseCanvas(canvas2)
|
||||
end
|
||||
@@ -229,62 +213,50 @@ function Blur.applyBackdrop(blurInstance, intensity, x, y, width, height, backdr
|
||||
return
|
||||
end
|
||||
|
||||
-- Clamp intensity
|
||||
intensity = math.max(0, math.min(100, intensity))
|
||||
|
||||
-- Calculate blur passes based on intensity
|
||||
local passes = math.ceil(intensity / 20)
|
||||
passes = math.max(1, math.min(5, passes))
|
||||
|
||||
-- Get canvases for ping-pong rendering
|
||||
local canvas1 = getCanvas(width, height)
|
||||
local canvas2 = getCanvas(width, height)
|
||||
|
||||
-- Save graphics state
|
||||
local prevCanvas = love.graphics.getCanvas()
|
||||
local prevShader = love.graphics.getShader()
|
||||
local prevColor = { love.graphics.getColor() }
|
||||
local prevBlendMode = love.graphics.getBlendMode()
|
||||
|
||||
-- Extract the region from backdrop
|
||||
love.graphics.setCanvas(canvas1)
|
||||
love.graphics.clear()
|
||||
love.graphics.setColor(1, 1, 1, 1)
|
||||
love.graphics.setBlendMode("alpha", "premultiplied")
|
||||
|
||||
-- Create a quad for the region
|
||||
local backdropWidth, backdropHeight = backdropCanvas:getDimensions()
|
||||
local quad = love.graphics.newQuad(x, y, width, height, backdropWidth, backdropHeight)
|
||||
love.graphics.draw(backdropCanvas, quad, 0, 0)
|
||||
|
||||
-- Apply blur passes
|
||||
love.graphics.setShader(blurInstance.shader)
|
||||
|
||||
for i = 1, passes do
|
||||
-- Horizontal pass
|
||||
love.graphics.setCanvas(canvas2)
|
||||
love.graphics.clear()
|
||||
blurInstance.shader:send("direction", { 1 / width, 0 })
|
||||
love.graphics.draw(canvas1, 0, 0)
|
||||
|
||||
-- Vertical pass
|
||||
love.graphics.setCanvas(canvas1)
|
||||
love.graphics.clear()
|
||||
blurInstance.shader:send("direction", { 0, 1 / height })
|
||||
love.graphics.draw(canvas2, 0, 0)
|
||||
end
|
||||
|
||||
-- Draw blurred result to screen
|
||||
love.graphics.setCanvas(prevCanvas)
|
||||
love.graphics.setShader()
|
||||
love.graphics.setBlendMode(prevBlendMode)
|
||||
love.graphics.draw(canvas1, x, y)
|
||||
|
||||
-- Restore graphics state
|
||||
love.graphics.setShader(prevShader)
|
||||
love.graphics.setColor(unpack(prevColor))
|
||||
|
||||
-- Release canvases back to cache
|
||||
releaseCanvas(canvas1)
|
||||
releaseCanvas(canvas2)
|
||||
end
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
--- Standardized error message formatter
|
||||
---@param module string -- Module name (e.g., "Color", "Theme", "Units")
|
||||
---@param message string -- Error message
|
||||
---@return string -- Formatted error message
|
||||
---@param message string
|
||||
---@return string
|
||||
local function formatError(module, message)
|
||||
return string.format("[FlexLove.%s] %s", module, message)
|
||||
end
|
||||
|
||||
-- ====================
|
||||
-- Color System
|
||||
-- ====================
|
||||
|
||||
--- Utility class for color handling
|
||||
---@class Color
|
||||
---@field r number -- Red component (0-1)
|
||||
@@ -20,10 +16,10 @@ local Color = {}
|
||||
Color.__index = Color
|
||||
|
||||
--- Create a new color instance
|
||||
---@param r number? -- Default: 0
|
||||
---@param g number? -- Default: 0
|
||||
---@param b number? -- Default: 0
|
||||
---@param a number? -- Default: 1
|
||||
---@param r number?
|
||||
---@param g number?
|
||||
---@param b number?
|
||||
---@param a number?
|
||||
---@return Color
|
||||
function Color.new(r, g, b, a)
|
||||
local self = setmetatable({}, Color)
|
||||
|
||||
@@ -228,14 +228,12 @@ function Element.new(props)
|
||||
|
||||
self.userdata = props.userdata
|
||||
|
||||
-- Input event callbacks
|
||||
self.onFocus = props.onFocus
|
||||
self.onBlur = props.onBlur
|
||||
self.onTextInput = props.onTextInput
|
||||
self.onTextChange = props.onTextChange
|
||||
self.onEnter = props.onEnter
|
||||
|
||||
-- Initialize EventHandler for event processing
|
||||
self._eventHandler = EventHandler.new({
|
||||
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)
|
||||
self._stateId = self.id
|
||||
|
||||
-- Initialize ThemeManager for theme management
|
||||
self._themeManager = ThemeManager.new({
|
||||
theme = props.theme or Gui.defaultTheme,
|
||||
themeComponent = props.themeComponent or nil,
|
||||
@@ -279,10 +276,8 @@ function Element.new(props)
|
||||
-- Initialize contentAutoSizingMultiplier after theme is set
|
||||
-- Priority: element props > theme component > theme default
|
||||
if props.contentAutoSizingMultiplier then
|
||||
-- Explicitly set on element
|
||||
self.contentAutoSizingMultiplier = props.contentAutoSizingMultiplier
|
||||
else
|
||||
-- Try to source from theme via ThemeManager
|
||||
local multiplier = self._themeManager:getContentAutoSizingMultiplier()
|
||||
self.contentAutoSizingMultiplier = multiplier or { 1, 1 }
|
||||
end
|
||||
@@ -291,12 +286,10 @@ function Element.new(props)
|
||||
self.scaleCorners = self._themeManager.scaleCorners
|
||||
self.scalingAlgorithm = self._themeManager.scalingAlgorithm
|
||||
|
||||
-- Initialize blur properties
|
||||
self.contentBlur = props.contentBlur
|
||||
self.backdropBlur = props.backdropBlur
|
||||
self._blurInstance = nil
|
||||
|
||||
-- Initialize input control properties
|
||||
self.editable = props.editable or false
|
||||
self.multiline = props.multiline or false
|
||||
self.passwordMode = props.passwordMode or false
|
||||
@@ -316,7 +309,6 @@ function Element.new(props)
|
||||
self.placeholder = props.placeholder
|
||||
self.inputType = props.inputType or "text"
|
||||
|
||||
-- Text behavior properties
|
||||
self.textOverflow = props.textOverflow or "clip"
|
||||
self.scrollable = props.scrollable
|
||||
if self.scrollable == nil then
|
||||
@@ -330,12 +322,10 @@ function Element.new(props)
|
||||
end
|
||||
self.selectOnFocus = props.selectOnFocus or false
|
||||
|
||||
-- Cursor and selection properties
|
||||
self.cursorColor = props.cursorColor
|
||||
self.selectionColor = props.selectionColor
|
||||
self.cursorBlinkRate = props.cursorBlinkRate or 0.5
|
||||
|
||||
-- Initialize TextEditor for editable elements
|
||||
if self.editable then
|
||||
self._textEditor = TextEditor.new({
|
||||
editable = self.editable,
|
||||
@@ -635,7 +625,6 @@ function Element.new(props)
|
||||
local parentWidth = self.parent and self.parent.width or viewportWidth
|
||||
tempWidth = Units.resolve(value, unit, viewportWidth, viewportHeight, parentWidth)
|
||||
else
|
||||
-- Apply base scaling to pixel values
|
||||
tempWidth = Gui.baseScale and (widthProp * scaleX) or widthProp
|
||||
self.units.width = { value = widthProp, unit = "px" }
|
||||
end
|
||||
@@ -650,7 +639,6 @@ function Element.new(props)
|
||||
self.units.width = { value = 100, unit = "%" } -- Mark as parent-constrained
|
||||
self.autosizing.width = false -- Not truly autosizing, constrained by parent
|
||||
else
|
||||
-- Calculate auto-width without padding first
|
||||
tempWidth = self:calculateAutoWidth()
|
||||
self.width = tempWidth
|
||||
self.units.width = { value = nil, unit = "auto" } -- Mark as auto-sized
|
||||
|
||||
Reference in New Issue
Block a user