birthday widget: add expanded mode support
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
-- description = "Shows upcoming birthdays from the contacts"
|
-- description = "Shows upcoming birthdays from the contacts"
|
||||||
-- type = "widget"
|
-- type = "widget"
|
||||||
-- author = "Andrey Gavrilov"
|
-- author = "Andrey Gavrilov"
|
||||||
-- version = "1.1"
|
-- version = "1.2"
|
||||||
|
|
||||||
local prefs = require "prefs"
|
local prefs = require "prefs"
|
||||||
local fmt = require "fmt"
|
local fmt = require "fmt"
|
||||||
@@ -43,23 +43,40 @@ function redraw()
|
|||||||
table.sort(contacts,function(a,b) return a.begin < b.begin end)
|
table.sort(contacts,function(a,b) return a.begin < b.begin end)
|
||||||
events = {}
|
events = {}
|
||||||
local lines = {}
|
local lines = {}
|
||||||
|
local lines_exp = {}
|
||||||
|
prev_begin = contacts[1].begin
|
||||||
for i,v in ipairs(contacts) do
|
for i,v in ipairs(contacts) do
|
||||||
local fmt_out = fmt_line(v)
|
local fmt_out = fmt_line(v)
|
||||||
local insert = 0
|
local insert = 0
|
||||||
if #lines == 0 then
|
if #lines == 0 then
|
||||||
insert = 1
|
insert = 1
|
||||||
elseif not (fmt_out == lines[#lines]) then
|
elseif not (fmt_out == lines[#lines]) then
|
||||||
insert = 1
|
insert = 1
|
||||||
end
|
end
|
||||||
if insert == 1 then
|
if insert == 1 then
|
||||||
|
if #lines_exp >= prefs.count and prev_begin ~= v.begin then
|
||||||
|
break
|
||||||
|
end
|
||||||
table.insert(events, v)
|
table.insert(events, v)
|
||||||
table.insert(lines, fmt_out)
|
if #lines < prefs.count then
|
||||||
if #lines == prefs.count then
|
table.insert(lines, fmt_out)
|
||||||
break
|
|
||||||
end
|
end
|
||||||
|
table.insert(lines_exp, fmt_out)
|
||||||
|
prev_begin = v.begin
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
ui:show_lines(lines)
|
if ui.set_expandable then
|
||||||
|
if #lines_exp == #lines then
|
||||||
|
ui:set_expandable(false)
|
||||||
|
else
|
||||||
|
ui:set_expandable(true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if ui.is_expanded and ui:is_expanded() then
|
||||||
|
ui:show_lines(lines_exp)
|
||||||
|
else
|
||||||
|
ui:show_lines(lines)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function fmt_line(event)
|
function fmt_line(event)
|
||||||
|
|||||||
Reference in New Issue
Block a user