aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--widgets/clock.lua56
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