diff options
| author | Danilo M. <danix@danix.xyz> | 2026-09-17 10:05:14 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-09-17 10:05:14 +0200 |
| commit | 4e133cddd6ef7735eee264f90a4b69e814c2dea7 (patch) | |
| tree | 0ab0843c6e63901e1cd67aca6104b3a46ff05dda | |
| parent | c9ff9b2f5434ff09b02a3ab33eada2d8721d242f (diff) | |
| download | conky-theme-udt-4e133cddd6ef7735eee264f90a4b69e814c2dea7.tar.gz conky-theme-udt-4e133cddd6ef7735eee264f90a4b69e814c2dea7.zip | |
feat: centre the clock numerals
Horizontally centred in the card; the weekday and date stay against the
left edge at the bottom.
Each line is centred on its own ink width via measure(), not advance():
ink is what centring wants, and Oswald is proportional, so 10 and 05 are
not the same width and a shared measurement would leave one of them
visibly off-centre.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
| -rw-r--r-- | widgets/clock.lua | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/widgets/clock.lua b/widgets/clock.lua index b7c80d9..01f6012 100644 --- a/widgets/clock.lua +++ b/widgets/clock.lua @@ -43,8 +43,15 @@ function M.draw(cr, rect, colors) -- 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')) + -- Centred horizontally: measure(), not advance(), because ink width is what + -- centring wants. Oswald is condensed, so '10' and '03' differ in width and + -- each line is centred on its own measurement rather than a shared one. + local function centred(s, baseline) + local w = card.measure(cr, s) + card.text(cr, inner.x + (inner.w - w) / 2, baseline, s) + end + centred(os.date('%H'), y1) + centred(os.date('%M'), y2) -- Weekday and date sit against the bottom edge, not at a fixed drop from the -- numerals. That is what puts the slack of a tall cell in the middle of the |
