From 45f5f9d60539f70170fc3beeff66108fe2b253d8 Mon Sep 17 00:00:00 2001 From: Muse Date: Sat, 5 Dec 2026 22:27:38 +0000 Subject: [PATCH] XTachometer: place numerals by per-label radial extent The glyph box farthest corner in the radial direction must stay inside the tick ring (inner end r-10) with 4 px clearance, so a wide 4-digit label never crosses the dial rim (the Rust demo showed 6400/8000 clipped at the rim at 720x480). Single-digit labels move inward only ~4 px; verified by re-shoot. --- widgets/components/XTachometer/XTachometer.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/widgets/components/XTachometer/XTachometer.h b/widgets/components/XTachometer/XTachometer.h index bcc8728..7f14c0d 100644 --- a/widgets/components/XTachometer/XTachometer.h +++ b/widgets/components/XTachometer/XTachometer.h @@ -184,9 +184,16 @@ public: if (i % 2 == 0) { std::string lab = fmt0(max_ * f / 1000.0); - int lx = cx + (int)((r - 26) * std::cos(a)); - int ly = cy - (int)((r - 26) * std::sin(a)); int lw = xframe::font_text_width(numeral_font, lab); + // Numeral centre radius: the glyph box's farthest + // corner in the radial direction must stay inside the + // tick ring (inner end r-10) with 4 px clearance, so a + // wide label never crosses the dial rim. + double extent = (lw / 2.0) * std::fabs(std::cos(a)) + + (numeral_px / 2.0) * std::fabs(std::sin(a)); + double lr = std::max(8.0, r - 10.0 - extent - 4.0); + int lx = cx + (int)(lr * std::cos(a)); + int ly = cy - (int)(lr * std::sin(a)); // Numerals at/after the redline render in red. Srgb lab_color = (f >= red_frac) ? redline_color_ : Srgb{20, 20, 20}; xframe::draw_text_font(display_, window_, gc_, numeral_font,