From 8fe6e0806c8c20007c613eb896f2848ee0ff1292 Mon Sep 17 00:00:00 2001 From: "kepler155c@gmail.com" Date: Mon, 6 Apr 2020 00:12:46 -0600 Subject: [PATCH] refactor + new transitions --- sys/apps/Files.lua | 43 ++++++++++--------- sys/modules/opus/ui.lua | 3 +- .../opus/ui/components/MiniSlideOut.lua | 31 +++++++++++++ sys/modules/opus/ui/components/Question.lua | 27 ++++++++++++ sys/modules/opus/ui/transition.lua | 39 ++++++++++++++++- 5 files changed, 119 insertions(+), 24 deletions(-) create mode 100644 sys/modules/opus/ui/components/MiniSlideOut.lua create mode 100644 sys/modules/opus/ui/components/Question.lua diff --git a/sys/apps/Files.lua b/sys/apps/Files.lua index 8f3144e..7626dee 100644 --- a/sys/apps/Files.lua +++ b/sys/apps/Files.lua @@ -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 diff --git a/sys/modules/opus/ui.lua b/sys/modules/opus/ui.lua index 6ec8aff..1386adf 100644 --- a/sys/modules/opus/ui.lua +++ b/sys/modules/opus/ui.lua @@ -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 diff --git a/sys/modules/opus/ui/components/MiniSlideOut.lua b/sys/modules/opus/ui/components/MiniSlideOut.lua new file mode 100644 index 0000000..a9e226c --- /dev/null +++ b/sys/modules/opus/ui/components/MiniSlideOut.lua @@ -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 diff --git a/sys/modules/opus/ui/components/Question.lua b/sys/modules/opus/ui/components/Question.lua new file mode 100644 index 0000000..f15f151 --- /dev/null +++ b/sys/modules/opus/ui/components/Question.lua @@ -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 diff --git a/sys/modules/opus/ui/transition.lua b/sys/modules/opus/ui/transition.lua index 9311e21..0cd6245 100644 --- a/sys/modules/opus/ui/transition.lua +++ b/sys/modules/opus/ui/transition.lua @@ -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