-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathanimation.lua
71 lines (57 loc) · 2.36 KB
/
animation.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
--- Jammin'! animations.
-- "Jammimations."
local wibox = require("wibox")
local timer = require("gears.timer")
local animation = {}
animation.__index = animation
--- A few old variants...
-- local frames = {'⣸', '⣴', '⣦', '⣇', '⡏', '⠟', '⠻', '⢹'}; local play_box_period = 0.2; local pause_glyph = '⣿';
local frames = {'⢸', '⣰', '⣤', '⣆', '⡇', '⠏', '⠛', '⠹'}; local period = 0.2; local pause_glyph = '⣿';
-- local frames = {'⠁', '⠂', '⠄', '⡈', '⡐', '⡠', '⣁', '⣂', '⣌', '⣔', '⣥', '⣮', '⣷', '⣿', '⣶', '⣤', '⣀', ' '}; local play_box_period = 0.2; local pause_glyph = '⣿'
-- local frames = {'⣀', '⡠', '⡠', '⠔', '⠔', '⠔', '⠊', '⠊', '⠊', '⠊', '⠉', '⠉', '⠉', '⠉', '⠉', '⠉', '⠑', '⠑', '⠑', '⠑', '⠢', '⠢', '⠢', '⢄', '⢄'}; local play_box_period = 0.03; local pause_glyph = '⣀';
-- local frames = {' ⣸', '⢀⣰', '⣀⣠', '⣄⣀', '⣆⡀', '⣇ ', '⡏ ', '⠏⠁', '⠋⠉', '⠉⠙', '⠈⠹', ' ⢹'}; local play_box_period = 0.16; local pause_glyph = '⣿⣿';
-- local frames = {' ⡱', '⢀⡰', '⢄⡠', '⢆⡀', '⢎ ', '⠎⠁', '⠊⠑', '⠈⠱'};
-- local period = 0.16667;
-- local pause_glyph = '⢾⡷';
local function default_markup_fmt(s)
return string.format('<span color="white">%s</span>', s)
end
function animation:start()
self.timer:again()
end
function animation:stop()
if self.timer.started then
self.timer:stop()
end
self:set_markup(self.pause_glyph)
end
function animation:set_markup(s)
self.widget:set_markup(self.markup_fmt(s))
end
function animation.new(args)
args = args or {}
local self = setmetatable({}, animation)
self.frames = args.frames or frames
self.pause_glyph = args.pause_glyph or pause_glyph
self.markup_fmt = args.markup_fmt or default_markup_fmt
local period = args.period or period
self.widget = wibox.widget{
forced_width = args.fixed_width,
widget = wibox.widget.textbox
};
self.index = 1
local function animate()
self:set_markup(self.frames[self.index])
self.index = (self.index % #self.frames) + 1
return true
end
self.timer = timer.start_new(period, animate)
self:stop()
return self
end
setmetatable(animation, {
__call = function(cls, ...)
return cls.new(...)
end
})
return animation