mirror of
https://github.com/kepler155c/opus
synced 2025-01-03 20:30:28 +00:00
notifications anchor option
This commit is contained in:
parent
daa86d50b2
commit
ade354660f
@ -374,8 +374,11 @@ function Manager:mergeProperties(obj, args)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Manager:pullEvents(...)
|
function Manager:pullEvents(...)
|
||||||
Event.pullEvents(...)
|
local s, m = pcall(Event.pullEvents, ...)
|
||||||
self.term:reset()
|
self.term:reset()
|
||||||
|
if not s and m then
|
||||||
|
error(m, -1)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Manager:exitPullEvents()
|
function Manager:exitPullEvents()
|
||||||
|
@ -13,6 +13,7 @@ UI.Notification.defaults = {
|
|||||||
closeInd = '\215',
|
closeInd = '\215',
|
||||||
height = 3,
|
height = 3,
|
||||||
timeout = 3,
|
timeout = 3,
|
||||||
|
anchor = 'bottom',
|
||||||
}
|
}
|
||||||
function UI.Notification:draw()
|
function UI.Notification:draw()
|
||||||
end
|
end
|
||||||
@ -27,7 +28,7 @@ function UI.Notification:error(value, timeout)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function UI.Notification:info(value, timeout)
|
function UI.Notification:info(value, timeout)
|
||||||
self.backgroundColor = colors.gray
|
self.backgroundColor = colors.lightGray
|
||||||
self:display(value, timeout)
|
self:display(value, timeout)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -50,29 +51,34 @@ function UI.Notification:cancel()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function UI.Notification:display(value, timeout)
|
function UI.Notification:display(value, timeout)
|
||||||
|
self:cancel()
|
||||||
self.enabled = true
|
self.enabled = true
|
||||||
local lines = Util.wordWrap(value, self.width - 3)
|
local lines = Util.wordWrap(value, self.width - 3)
|
||||||
self.height = #lines
|
self.height = #lines
|
||||||
self.y = self.parent.height - self.height + 1
|
|
||||||
if self.canvas then
|
|
||||||
self.canvas:removeLayer()
|
|
||||||
end
|
|
||||||
|
|
||||||
self.canvas = self:addLayer(self.backgroundColor, self.textColor)
|
if self.anchor == 'bottom' then
|
||||||
self:addTransition('expandUp', { ticks = self.height })
|
self.y = self.parent.height - self.height + 1
|
||||||
|
self.canvas = self:addLayer(self.backgroundColor, self.textColor)
|
||||||
|
self:addTransition('expandUp', { ticks = self.height })
|
||||||
|
else
|
||||||
|
self.canvas = self:addLayer(self.backgroundColor, self.textColor)
|
||||||
|
self.y = 1
|
||||||
|
end
|
||||||
self.canvas:setVisible(true)
|
self.canvas:setVisible(true)
|
||||||
self:clear()
|
self:clear()
|
||||||
for k,v in pairs(lines) do
|
for k,v in pairs(lines) do
|
||||||
self:write(2, k, v)
|
self:write(2, k, v)
|
||||||
end
|
end
|
||||||
self:write(self.width, 1, self.closeInd)
|
|
||||||
|
|
||||||
timeout = timeout or self.timeout
|
timeout = timeout or self.timeout
|
||||||
if timeout > 0 then
|
if timeout > 0 then
|
||||||
self.timer = Event.onTimeout(timeout or self.timeout, function()
|
self.timer = Event.onTimeout(timeout, function()
|
||||||
self:cancel()
|
self:cancel()
|
||||||
self:sync()
|
self:sync()
|
||||||
end)
|
end)
|
||||||
|
else
|
||||||
|
self:write(self.width, 1, self.closeInd)
|
||||||
|
self:sync()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user