refactor + new transitions
This commit is contained in:
@@ -1139,9 +1139,10 @@ function UI.Device:sync()
|
||||
self.device.setCursorBlink(false)
|
||||
end
|
||||
|
||||
self.currentPage:render(self.device)
|
||||
if transitions then
|
||||
self:runTransitions(transitions)
|
||||
else
|
||||
self.currentPage:render(self.device)
|
||||
end
|
||||
|
||||
if self:getCursorBlink() then
|
||||
|
||||
31
sys/modules/opus/ui/components/MiniSlideOut.lua
Normal file
31
sys/modules/opus/ui/components/MiniSlideOut.lua
Normal file
@@ -0,0 +1,31 @@
|
||||
local class = require('opus.class')
|
||||
local UI = require('opus.ui')
|
||||
|
||||
UI.MiniSlideOut = class(UI.SlideOut)
|
||||
UI.MiniSlideOut.defaults = {
|
||||
UIElement = 'MiniSlideOut',
|
||||
noFill = true,
|
||||
backgroundColor = UI.colors.primary,
|
||||
height = 1,
|
||||
}
|
||||
function UI.MiniSlideOut:postInit()
|
||||
self.close_button = UI.Button {
|
||||
x = -1,
|
||||
backgroundColor = self.backgroundColor,
|
||||
backgroundFocusColor = self.backgroundColor,
|
||||
text = 'x',
|
||||
event = 'slide_hide',
|
||||
noPadding = true,
|
||||
}
|
||||
if self.label then
|
||||
self.label_text = UI.Text {
|
||||
x = 2,
|
||||
value = self.label,
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
function UI.MiniSlideOut:show(...)
|
||||
UI.SlideOut.show(self, ...)
|
||||
self:addTransition('slideLeft', { easing = 'outBounce' })
|
||||
end
|
||||
27
sys/modules/opus/ui/components/Question.lua
Normal file
27
sys/modules/opus/ui/components/Question.lua
Normal file
@@ -0,0 +1,27 @@
|
||||
local class = require('opus.class')
|
||||
local UI = require('opus.ui')
|
||||
|
||||
UI.Question = class(UI.MiniSlideOut)
|
||||
UI.Question.defaults = {
|
||||
UIElement = 'Question',
|
||||
accelerators = {
|
||||
y = 'question_yes',
|
||||
n = 'question_no',
|
||||
}
|
||||
}
|
||||
function UI.Question:postInit()
|
||||
local x = self.label and #self.label + 3 or 1
|
||||
|
||||
self.yes_button = UI.Button {
|
||||
x = x,
|
||||
text = 'Yes',
|
||||
backgroundColor = UI.colors.primary,
|
||||
event = 'question_yes',
|
||||
}
|
||||
self.no_button = UI.Button {
|
||||
x = x + 5,
|
||||
text = 'No',
|
||||
backgroundColor = UI.colors.primary,
|
||||
event = 'question_no',
|
||||
}
|
||||
end
|
||||
@@ -3,7 +3,7 @@ local Tween = require('opus.ui.tween')
|
||||
local Transition = { }
|
||||
|
||||
function Transition.slideLeft(args)
|
||||
local ticks = args.ticks or 8
|
||||
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)
|
||||
@@ -19,7 +19,7 @@ function Transition.slideLeft(args)
|
||||
end
|
||||
|
||||
function Transition.slideRight(args)
|
||||
local ticks = args.ticks or 8
|
||||
local ticks = args.ticks or 6
|
||||
local easing = args.easing or 'inCirc'
|
||||
local pos = { x = -args.canvas.width }
|
||||
local tween = Tween.new(ticks, pos, { x = 1 }, easing)
|
||||
@@ -50,4 +50,39 @@ function Transition.expandUp(args)
|
||||
end
|
||||
end
|
||||
|
||||
function Transition.shake(args)
|
||||
local ticks = args.ticks or 8
|
||||
local i = ticks
|
||||
|
||||
return function()
|
||||
i = -i
|
||||
args.canvas:move(args.canvas.x + i, args.canvas.y)
|
||||
if i > 0 then
|
||||
i = i - 2
|
||||
end
|
||||
return i ~= 0
|
||||
end
|
||||
end
|
||||
|
||||
function Transition.shuffle(args)
|
||||
local ticks = args.ticks or 4
|
||||
local easing = args.easing or 'linear'
|
||||
local t = { }
|
||||
|
||||
for _,child in pairs(args.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)
|
||||
end
|
||||
|
||||
return function()
|
||||
local finished
|
||||
for child, tween in pairs(t) do
|
||||
finished = tween:update(1)
|
||||
child:move(math.floor(child.x), math.floor(child.y))
|
||||
end
|
||||
return not finished
|
||||
end
|
||||
end
|
||||
|
||||
return Transition
|
||||
|
||||
Reference in New Issue
Block a user