diff options
| -rw-r--r-- | README.md | 4 | ||||
| -rw-r--r-- | widgets/immich.lua | 23 |
2 files changed, 22 insertions, 5 deletions
@@ -197,7 +197,9 @@ guessed at. ### Memories Today's "N years ago" photos from an Immich server, one at a time, rotating -every 30 seconds. The big value is how many years ago; under the photo, when it +every 30 seconds. The big value is how many years ago, marked "Y ago" the way a temperature +carries its degree sign, over a "3/5" counter when there are several; under +the photo, when it was taken (the camera's local time) and where, as city and country, or coordinates when Immich has no place name for them. diff --git a/widgets/immich.lua b/widgets/immich.lua index 17e0b02..a9caca7 100644 --- a/widgets/immich.lua +++ b/widgets/immich.lua @@ -60,6 +60,7 @@ function M.draw(cr, rect, colors) local inner = card.card(cr, rect, colors) local function clamp(v, lo, hi) return math.max(lo, math.min(hi, v)) end local LABEL_F, BIG_F, ROW_F, SUB_F = 0.30, 1.0, 0.32, 0.26 + local UNIT_F, AGO_F = 0.40, 0.24 -- the "Y" beside the big value, "ago" under it local photos = data.immich_parse(data.slurp(DIR .. 'index.txt') or '') if not photos then @@ -80,8 +81,7 @@ function M.draw(cr, rect, colors) local ago = p.year and (tonumber(os.date('%Y')) - p.year) or nil local big = ago and tostring(ago) or '--' - local sub = (ago == 1 and 'year ago' or 'years ago') - .. (n > 1 and string.format(' %d/%d', i, n) or '') + local sub = n > 1 and string.format('%d/%d', i, n) or '' local t = p.taken local taken = t and string.format('%02d/%02d/%04d %02d:%02d', t[3], t[2], t[1], t[4], t[5]) or '--' @@ -92,7 +92,7 @@ function M.draw(cr, rect, colors) -- the whole card's type every time a long place name comes round. local groups = { { { card.title_str(card.ICON.immich, 'MEMORIES'), card.FONT_MONO, LABEL_F }, - { big, card.FONT_HEAVY, BIG_F } }, + { big, card.FONT_HEAVY, BIG_F }, { 'ago', card.FONT_UI, AGO_F } }, { { sub, card.FONT_UI, SUB_F } }, { { 'TAKEN ', card.FONT_MONO, ROW_F }, { taken, card.FONT_MONO, ROW_F } }, } @@ -100,9 +100,24 @@ function M.draw(cr, rect, colors) card.fit_unit(cr, inner.w * 0.96, groups, 100)), 10, 72) local label_size, row_size = S * LABEL_F, S * ROW_F + -- The big value carries its unit the way a temperature carries its degree + -- sign: a small "Y" top-right of the digits, "ago" under it on the + -- baseline, both right-aligned in a column against the card edge. + local right, base = inner.x + inner.w, inner.y + S * BIG_F + card.font(cr, card.FONT_UI, S * AGO_F, false) + local col_w = card.measure(cr, 'ago') + card.rgba(cr, colors.label, 0.65) + card.text_right(cr, right, base, 'ago') + card.font(cr, card.FONT_HEAVY, S * UNIT_F, false) + local unit_w, unit_h = card.measure(cr, 'Y') + col_w = math.max(col_w, unit_w) + card.font(cr, card.FONT_HEAVY, S * BIG_F, false) + local _, big_h = card.measure(cr, big) card.rgba(cr, colors.body) - card.text_right(cr, inner.x + inner.w, inner.y + S * BIG_F, big) + card.text_right(cr, right - col_w - S * 0.08, base, big) + card.font(cr, card.FONT_HEAVY, S * UNIT_F, false) + card.text_right(cr, right, base - big_h + unit_h, 'Y') card.font(cr, card.FONT_MONO, label_size, false) card.title(cr, inner.x, inner.y + label_size, card.ICON.immich, 'MEMORIES', colors) |
