37 lines
970 B
Lua
37 lines
970 B
Lua
|
local awful = require("awful")
|
||
|
local wibox = require("wibox")
|
||
|
|
||
|
return function(widget,list,max_elements)
|
||
|
if not tostring(widget):match("wibox.layout") then
|
||
|
error("Cannot attach pager to widget that isn't a layout")
|
||
|
end
|
||
|
local new_pager = {
|
||
|
page = widget,
|
||
|
list = list,
|
||
|
index = 0,
|
||
|
max = max_elements
|
||
|
}
|
||
|
function new_pager:update()
|
||
|
self.page:reset()
|
||
|
for i = 1+(self.max*self.index),self.max+(self.max*self.index) do
|
||
|
if self.list[i] then
|
||
|
self.page:add(self.list[i])
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
function new_pager:next()
|
||
|
if #list >= (self.index+1)*self.max then
|
||
|
self.index = self.index + 1
|
||
|
new_pager:update()
|
||
|
end
|
||
|
end
|
||
|
function new_pager:prev()
|
||
|
if self.index > 0 then
|
||
|
self.index = self.index - 1
|
||
|
new_pager:update()
|
||
|
end
|
||
|
end
|
||
|
new_pager:update()
|
||
|
return new_pager
|
||
|
end
|