From b5b701ce1c7e95390544eb9083a65cd843832385 Mon Sep 17 00:00:00 2001 From: Evgeny Date: Mon, 20 Jan 2025 18:32:31 +0800 Subject: [PATCH] birthday widget: add expanded mode support --- community/birthdays-widget.lua | 43 ++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/community/birthdays-widget.lua b/community/birthdays-widget.lua index 2f5ed08..f3d0afe 100644 --- a/community/birthdays-widget.lua +++ b/community/birthdays-widget.lua @@ -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,23 +43,40 @@ 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 - if #lines == 0 then - insert = 1 - elseif not (fmt_out == lines[#lines]) then - insert = 1 - end - if insert == 1 then + local fmt_out = fmt_line(v) + local insert = 0 + if #lines == 0 then + insert = 1 + elseif not (fmt_out == lines[#lines]) then + insert = 1 + end + if insert == 1 then + if #lines_exp >= prefs.count and prev_begin ~= v.begin then + break + end table.insert(events, v) - table.insert(lines, fmt_out) - if #lines == prefs.count then - break + if #lines < prefs.count then + table.insert(lines, fmt_out) end + table.insert(lines_exp, fmt_out) + prev_begin = v.begin 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 function fmt_line(event)