You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.5 KiB
40 lines
1.5 KiB
-- This file is part of Reno desktop.
|
|
--
|
|
-- Reno desktop is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
|
--
|
|
-- Reno desktop is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
--
|
|
-- You should have received a copy of the GNU General Public License along with Reno desktop. If not, see <https://www.gnu.org/licenses/>.
|
|
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
|