diff options
| author | Danilo M. <danix@danix.xyz> | 2026-09-16 19:37:39 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-09-16 19:37:39 +0200 |
| commit | 7ded492aef4f03c7eb5e1b554f52fcfdaed709d5 (patch) | |
| tree | 8ddbffb053ba9c9d23359f181b6613fd727792dc /widgets | |
| parent | 9acc4ebcd3308d05bac87f0bd6d6fdab7d60f0f2 (diff) | |
| download | conky-theme-udt-7ded492aef4f03c7eb5e1b554f52fcfdaed709d5.tar.gz conky-theme-udt-7ded492aef4f03c7eb5e1b554f52fcfdaed709d5.zip | |
feat: add the clock widget
Hour stacked over minute in Noto Sans Black, weekday in caps, date
slashed, following idea2.png. Colours are the palette's.
Numeral size derives from the cell rather than a constant, so the same
widget fills its cell on either monitor. The slashes take the dimmer
label colour so the numerals read first.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Diffstat (limited to 'widgets')
| -rw-r--r-- | widgets/clock.lua | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/widgets/clock.lua b/widgets/clock.lua new file mode 100644 index 0000000..10f1dd8 --- /dev/null +++ b/widgets/clock.lua @@ -0,0 +1,56 @@ +-- Clock: hour stacked over minute, weekday, slashed date. +-- +-- Shape follows idea2.png; every colour comes from the palette. + +local card = require 'lib.card' + +local M = {} + +function M.draw(cr, rect, colors) + local inner = card.card(cr, rect, colors) + + -- Numeral size is derived from the cell, not fixed, so the same widget fills + -- a 1x2 cell on either monitor instead of needing a per-screen constant. + -- Two stacked numerals plus the date block: allow 40% of the height each. + local size = math.min(inner.h * 0.40, inner.w * 0.95) + + card.font(cr, card.FONT_HEAVY, size, false) + card.rgba(cr, colors.body) + + -- Baselines. Cairo's y is the baseline, so the first sits one cap-height + -- down; 0.78 of the font size approximates cap height for Noto Sans and + -- avoids measuring every frame. + local x = inner.x + local y1 = inner.y + size * 0.78 + -- Tight leading, as in the mockup: the numerals nearly touch. + local y2 = y1 + size * 0.92 + + card.text(cr, x, y1, os.date('%H')) + card.text(cr, x, y2, os.date('%M')) + + -- Weekday, small caps. + card.font(cr, card.FONT_UI, 15, true) + card.rgba(cr, colors.body) + local wy = y2 + 34 + card.text(cr, x, wy, os.date('%A'):upper()) + + -- Date as "16 / SEP / 2026". The slashes take the dimmer label colour so the + -- numerals read first, which is what gives the mockup's date line its rhythm. + card.font(cr, card.FONT_UI, 14, true) + local dy = wy + 24 + local parts = { + { os.date('%d'), colors.value }, + { ' / ', colors.label }, + { os.date('%b'):upper(), colors.value }, + { ' / ', colors.label }, + { os.date('%Y'), colors.value }, + } + local dx = x + for _, p in ipairs(parts) do + card.rgba(cr, p[2]) + card.text(cr, dx, dy, p[1]) + dx = dx + card.measure(cr, p[1]) + end +end + +return M |
