use layout() where appropriate and cleanup

This commit is contained in:
kepler155c@gmail.com
2020-04-09 16:08:54 -06:00
parent 8fe6e0806c
commit cd6ef0da50
14 changed files with 140 additions and 151 deletions

View File

@@ -2,61 +2,61 @@ local Tween = require('opus.ui.tween')
local Transition = { }
function Transition.slideLeft(args)
function Transition.slideLeft(canvas, args)
local ticks = args.ticks or 6
local easing = args.easing or 'inCirc'
local pos = { x = args.ex }
local tween = Tween.new(ticks, pos, { x = args.x }, easing)
local pos = { x = canvas.ex }
local tween = Tween.new(ticks, pos, { x = canvas.x }, easing)
args.canvas:move(pos.x, args.canvas.y)
canvas:move(pos.x, canvas.y)
return function()
local finished = tween:update(1)
args.canvas:move(math.floor(pos.x), args.canvas.y)
args.canvas:dirty(true)
canvas:move(math.floor(pos.x), canvas.y)
canvas:dirty(true)
return not finished
end
end
function Transition.slideRight(args)
function Transition.slideRight(canvas, args)
local ticks = args.ticks or 6
local easing = args.easing or 'inCirc'
local pos = { x = -args.canvas.width }
local pos = { x = -canvas.width }
local tween = Tween.new(ticks, pos, { x = 1 }, easing)
args.canvas:move(pos.x, args.canvas.y)
canvas:move(pos.x, canvas.y)
return function()
local finished = tween:update(1)
args.canvas:move(math.floor(pos.x), args.canvas.y)
args.canvas:dirty(true)
canvas:move(math.floor(pos.x), canvas.y)
canvas:dirty(true)
return not finished
end
end
function Transition.expandUp(args)
function Transition.expandUp(canvas, args)
local ticks = args.ticks or 3
local easing = args.easing or 'linear'
local pos = { y = args.ey + 1 }
local tween = Tween.new(ticks, pos, { y = args.y }, easing)
local pos = { y = canvas.ey + 1 }
local tween = Tween.new(ticks, pos, { y = canvas.y }, easing)
args.canvas:move(args.x, pos.y)
canvas:move(canvas.x, pos.y)
return function()
local finished = tween:update(1)
args.canvas:move(args.x, math.floor(pos.y))
args.canvas.parent:dirty(true)
canvas:move(canvas.x, math.floor(pos.y))
canvas.parent:dirty(true)
return not finished
end
end
function Transition.shake(args)
function Transition.shake(canvas, args)
local ticks = args.ticks or 8
local i = ticks
return function()
i = -i
args.canvas:move(args.canvas.x + i, args.canvas.y)
canvas:move(canvas.x + i, canvas.y)
if i > 0 then
i = i - 2
end
@@ -64,15 +64,15 @@ function Transition.shake(args)
end
end
function Transition.shuffle(args)
function Transition.shuffle(canvas, args)
local ticks = args.ticks or 4
local easing = args.easing or 'linear'
local t = { }
for _,child in pairs(args.canvas.children) do
for _,child in pairs(canvas.children) do
t[child] = Tween.new(ticks, child, { x = child.x, y = child.y }, easing)
child.x = math.random(1, args.canvas.parent.width)
child.y = math.random(1, args.canvas.parent.height)
child.x = math.random(1, canvas.parent.width)
child.y = math.random(1, canvas.parent.height)
end
return function()