aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-11-10 20:06:36 +0100
committerDanilo M. <danix@danix.xyz>2026-11-10 20:06:36 +0100
commitf61ef385b9543750da6ffbfad8a0e173ef84556b (patch)
treec132ea332b0d8a19112ee2ec78ec0146e80b0708
parent3dad5982a01ecbcadc37f4703047a25c94901a71 (diff)
downloaddeck-it-f61ef385b9543750da6ffbfad8a0e173ef84556b.tar.gz
deck-it-f61ef385b9543750da6ffbfad8a0e173ef84556b.zip
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 <noreply@anthropic.com>
-rw-r--r--static/dashboard.js11
-rw-r--r--static/deck.css6
2 files changed, 14 insertions, 3 deletions
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 = `
<svg class="dash-defs" width="0" height="0" aria-hidden="true"><defs>
<linearGradient id="hyline" gradientUnits="userSpaceOnUse" x1="0" y1="0" x2="120" y2="0"><stop offset="0" style="stop-color:var(--udt-border-1)"/>
@@ -264,6 +274,7 @@ export default {
const b = document.createElement("button");
b.innerHTML = `<i class="nf"></i>`;
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 () => {
diff --git a/static/deck.css b/static/deck.css
index b0608e1..0977279 100644
--- a/static/deck.css
+++ b/static/deck.css
@@ -727,9 +727,9 @@ select {
.dash-acts button { position: relative; display: grid; place-items: center; padding: 0; height: 100%; max-height: 64px; aspect-ratio: 1; border-radius: 16px; font-size: 1.7rem; line-height: 1;
background: var(--udt-surface0); border: 0; color: var(--udt-text); }
.dash-acts button.fail { color: var(--udt-red); }
-/* The Nerd Font glyphs draw past their advance; a 1em box drawn from its left
- edge centres what is drawn, not the advance. */
-.dash-acts button i { display: block; width: 1em; height: 1em; line-height: 1; text-align: left; font-style: normal; }
+/* The Nerd Font glyphs draw past their advance: dashboard.js shifts each by
+ the gap between its ink and its advance (inkShift). */
+.dash-acts button i { display: block; line-height: 1; font-style: normal; }
/* The same rotating three-hue gradient Hyprland draws on window borders,
read from ~/.cache/udt/udt-border.lua via /theme.css. */
.dash-acts button::before {