From f61ef385b9543750da6ffbfad8a0e173ef84556b Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Tue, 10 Nov 2026 20:06:36 +0100 Subject: fix(dashboard): centre the action icons by their measured ink A fixed 1em box overshot the other way. Each glyph is measured with canvas measureText once the font is loaded, and shifted by half the gap between its drawn width and its advance. Co-Authored-By: Claude Opus 5.5 --- static/dashboard.js | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'static/dashboard.js') diff --git a/static/dashboard.js b/static/dashboard.js index 5559218..390c802 100644 --- a/static/dashboard.js +++ b/static/dashboard.js @@ -90,6 +90,16 @@ function marquee(el) { } } +// A Nerd Font glyph is drawn wider than its advance, so centring the advance +// leaves the drawing off centre; shift it by the difference, measured. +function inkShift(el) { + const cs = getComputedStyle(el); + const ctx = (inkShift.ctx ??= document.createElement("canvas").getContext("2d")); + ctx.font = `${cs.fontSize} ${cs.fontFamily}`; + const m = ctx.measureText(el.textContent); + el.style.transform = `translateX(${(m.width - m.actualBoundingBoxRight + m.actualBoundingBoxLeft) / 2}px)`; +} + const SKELETON = ` `; b.firstChild.textContent = a.icon; + document.fonts.ready.then(() => inkShift(b.firstChild)); b.title = a.label; b.setAttribute("aria-label", a.label); b.onclick = async () => { -- cgit v1.2.3