aboutsummaryrefslogtreecommitdiffstats
path: root/static/dashboard.js
diff options
context:
space:
mode:
Diffstat (limited to 'static/dashboard.js')
-rw-r--r--static/dashboard.js11
1 files changed, 11 insertions, 0 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 () => {