mirror of https://github.com/kepler155c/opus
refactor + new transitions
This commit is contained in:
parent
7659b81d49
commit
8fe6e0806c
|
@ -89,6 +89,10 @@ local Browser = UI.Page {
|
|||
{ key = 'totalSize', width = 6 },
|
||||
},
|
||||
},
|
||||
question = UI.Question {
|
||||
y = -2, x = -19,
|
||||
label = 'Delete',
|
||||
},
|
||||
notification = UI.Notification { },
|
||||
associations = UI.SlideOut {
|
||||
menuBar = UI.MenuBar {
|
||||
|
@ -434,28 +438,25 @@ function Browser:eventHandler(event)
|
|||
|
||||
elseif event.type == 'delete' then
|
||||
if self:hasMarked() then
|
||||
local width = self.statusBar:getColumnWidth('status')
|
||||
self.statusBar:setColumnWidth('status', UI.term.width)
|
||||
self.statusBar:setValue('status', 'Delete marked? (y/n)')
|
||||
self.statusBar:draw()
|
||||
self.statusBar:sync()
|
||||
local _, ch = os.pullEvent('char')
|
||||
if ch == 'y' or ch == 'Y' then
|
||||
for _,m in pairs(marked) do
|
||||
pcall(function()
|
||||
fs.delete(m.fullName)
|
||||
end)
|
||||
end
|
||||
end
|
||||
marked = { }
|
||||
self.statusBar:setColumnWidth('status', width)
|
||||
self.statusBar:setValue('status', '/' .. self.dir.name)
|
||||
self:updateDirectory(self.dir)
|
||||
|
||||
self.statusBar:draw()
|
||||
self.grid:draw()
|
||||
self:setFocus(self.grid)
|
||||
self.question:show()
|
||||
end
|
||||
return true
|
||||
|
||||
elseif event.type == 'question_yes' then
|
||||
for _,m in pairs(marked) do
|
||||
pcall(fs.delete, m.fullName)
|
||||
end
|
||||
marked = { }
|
||||
self:updateDirectory(self.dir)
|
||||
|
||||
self.question:hide()
|
||||
self.statusBar:draw()
|
||||
self.grid:draw()
|
||||
self:setFocus(self.grid)
|
||||
|
||||
elseif event.type == 'question_no' then
|
||||
self.question:hide()
|
||||
self:setFocus(self.grid)
|
||||
|
||||
elseif event.type == 'copy' or event.type == 'cut' then
|
||||
if self:hasMarked() then
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue