fleshing out
This commit is contained in:
70
FlexLove.lua
70
FlexLove.lua
@@ -159,6 +159,8 @@ end
|
|||||||
---@field start table{width:number,height:number}
|
---@field start table{width:number,height:number}
|
||||||
---@field final table{width:number,height:number}
|
---@field final table{width:number,height:number}
|
||||||
---@field elapsed number
|
---@field elapsed number
|
||||||
|
---@field transform table?
|
||||||
|
---@field transition table?
|
||||||
local Animation = {}
|
local Animation = {}
|
||||||
Animation.__index = Animation
|
Animation.__index = Animation
|
||||||
|
|
||||||
@@ -166,6 +168,8 @@ Animation.__index = Animation
|
|||||||
---@field duration number
|
---@field duration number
|
||||||
---@field start table{width:number,height:number}
|
---@field start table{width:number,height:number}
|
||||||
---@field final table{width:number,height:number}
|
---@field final table{width:number,height:number}
|
||||||
|
---@field transform table?
|
||||||
|
---@field transition table?
|
||||||
local AnimationProps = {}
|
local AnimationProps = {}
|
||||||
|
|
||||||
---@param props AnimationProps
|
---@param props AnimationProps
|
||||||
@@ -174,6 +178,8 @@ function Animation.new(props)
|
|||||||
self.duration = props.duration
|
self.duration = props.duration
|
||||||
self.start = props.start
|
self.start = props.start
|
||||||
self.final = props.final
|
self.final = props.final
|
||||||
|
self.transform = props.transform
|
||||||
|
self.transition = props.transition
|
||||||
self.elapsed = 0
|
self.elapsed = 0
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
@@ -189,10 +195,60 @@ end
|
|||||||
|
|
||||||
function Animation:interpolate()
|
function Animation:interpolate()
|
||||||
local t = math.min(self.elapsed / self.duration, 1)
|
local t = math.min(self.elapsed / self.duration, 1)
|
||||||
return {
|
local result = {
|
||||||
width = self.start.width * (1 - t) + self.final.width * t,
|
width = self.start.width * (1 - t) + self.final.width * t,
|
||||||
height = self.start.height * (1 - t) + self.final.height * t,
|
height = self.start.height * (1 - t) + self.final.height * t,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-- Apply transform if present
|
||||||
|
if self.transform then
|
||||||
|
for key, value in pairs(self.transform) do
|
||||||
|
result[key] = value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Apply animation to a GUI element
|
||||||
|
---@param element Window|Button
|
||||||
|
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
|
||||||
|
---@param duration number
|
||||||
|
---@param fromOpacity number
|
||||||
|
---@param toOpacity number
|
||||||
|
---@return Animation
|
||||||
|
function Animation.fade(duration, fromOpacity, toOpacity)
|
||||||
|
return Animation.new({
|
||||||
|
duration = duration,
|
||||||
|
start = { opacity = fromOpacity },
|
||||||
|
final = { opacity = toOpacity },
|
||||||
|
transform = {},
|
||||||
|
transition = {}
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Create a simple scale animation
|
||||||
|
---@param duration number
|
||||||
|
---@param fromScale table{width:number,height:number}
|
||||||
|
---@param toScale table{width:number,height:number}
|
||||||
|
---@return Animation
|
||||||
|
function Animation.scale(duration, fromScale, toScale)
|
||||||
|
return Animation.new({
|
||||||
|
duration = duration,
|
||||||
|
start = { width = fromScale.width, height = fromScale.height },
|
||||||
|
final = { width = toScale.width, height = toScale.height },
|
||||||
|
transform = {},
|
||||||
|
transition = {}
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
local FONT_CACHE = {}
|
local FONT_CACHE = {}
|
||||||
@@ -252,6 +308,8 @@ end
|
|||||||
---@field alignItems AlignItems -- default: start
|
---@field alignItems AlignItems -- default: start
|
||||||
---@field alignContent AlignContent -- default: start
|
---@field alignContent AlignContent -- default: start
|
||||||
---@field textSize number?
|
---@field textSize number?
|
||||||
|
---@field transform table
|
||||||
|
---@field transition table
|
||||||
local Window = {}
|
local Window = {}
|
||||||
Window.__index = Window
|
Window.__index = Window
|
||||||
|
|
||||||
@@ -360,6 +418,10 @@ function Window.new(props)
|
|||||||
|
|
||||||
self.z = props.z or 0
|
self.z = props.z or 0
|
||||||
|
|
||||||
|
-- Add transform and transition properties
|
||||||
|
self.transform = props.transform or {}
|
||||||
|
self.transition = props.transition or {}
|
||||||
|
|
||||||
if not props.parent then
|
if not props.parent then
|
||||||
table.insert(Gui.topWindows, self)
|
table.insert(Gui.topWindows, self)
|
||||||
end
|
end
|
||||||
@@ -690,6 +752,8 @@ end
|
|||||||
---@field _touchPressed boolean
|
---@field _touchPressed boolean
|
||||||
---@field positioning Positioning --default: ABSOLUTE (checks parent first)
|
---@field positioning Positioning --default: ABSOLUTE (checks parent first)
|
||||||
---@field textSize number?
|
---@field textSize number?
|
||||||
|
---@field transform table
|
||||||
|
---@field transition table
|
||||||
local Button = {}
|
local Button = {}
|
||||||
Button.__index = Button
|
Button.__index = Button
|
||||||
|
|
||||||
@@ -750,6 +814,10 @@ function Button.new(props)
|
|||||||
self._pressed = false
|
self._pressed = false
|
||||||
self._touchPressed = false
|
self._touchPressed = false
|
||||||
|
|
||||||
|
-- Add transform and transition properties
|
||||||
|
self.transform = props.transform or {}
|
||||||
|
self.transition = props.transition or {}
|
||||||
|
|
||||||
props.parent:addChild(self)
|
props.parent:addChild(self)
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user