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