From 7da1a1ef932cc6e721ba79436269c001d237e342 Mon Sep 17 00:00:00 2001 From: Muse Date: Sat, 5 Dec 2026 21:32:51 +0000 Subject: [PATCH] Follow-up: tach title placement + vertical-bar peak shrink-to-fit - XTachometer: the "RPM" title baseline now hangs below the top numeral's bottom edge instead of a fixed cy - r*0.55, so it cannot collide with the neighbouring numerals on small dials (found in the Python demo at r=73, where 3200/RPM/4800 jammed). - XVerticalBar: the "peak N" label shrinks 14px -> 11px when the bar is too narrow for it to fit inside the frame. --- widgets/components/XTachometer/XTachometer.h | 8 +++++-- .../components/XVerticalBar/XVerticalBar.h | 23 +++++++++++++++++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/widgets/components/XTachometer/XTachometer.h b/widgets/components/XTachometer/XTachometer.h index fdf14de..bcc8728 100644 --- a/widgets/components/XTachometer/XTachometer.h +++ b/widgets/components/XTachometer/XTachometer.h @@ -197,12 +197,16 @@ public: } // "RPM" title: bold, centred inside the dial below the top - // numerals (not a tiny top-left corner label). + // numerals (not a tiny top-left corner label). Its baseline + // hangs below the top numeral's bottom edge, so it cannot + // collide with the neighbouring numerals on small dials. if (!text_.empty()) { int tw = xframe::font_text_width(title_font, text_); + int title_base = cy - (r - 22) + (int)(numeral_px * 0.75) + + title_font->ascent + 4; xframe::draw_text_font(display_, window_, gc_, title_font, - cx - tw / 2, cy - (int)(r * 0.55), text_, + cx - tw / 2, title_base, text_, col(Srgb{20, 20, 20})); } diff --git a/widgets/components/XVerticalBar/XVerticalBar.h b/widgets/components/XVerticalBar/XVerticalBar.h index 25f72eb..df0c300 100644 --- a/widgets/components/XVerticalBar/XVerticalBar.h +++ b/widgets/components/XVerticalBar/XVerticalBar.h @@ -185,8 +185,27 @@ public: XDrawLine(display_, window_, gc_, bx - 4, py, bx + bw + 4, py); xf::set_line_width(display_, gc_, 1); std::string pk = "peak " + fmt0(peak_); - xframe::draw_text_font(display_, window_, gc_, bold_font, - bx + bw - xframe::font_text_width(bold_font, pk) - 4, + // Shrink to fit when the bar is narrow: the label must + // stay inside the frame (right-aligned at the bar's right + // edge minus 4px), never spill past the scale labels. + int pk_px = 14; + XFontStruct* pk_font = bold_font; + int avail_w = (bx + bw - 4) - (x1_ + 8); + for (int try_px = 14; try_px >= 11; --try_px) + { + XFontStruct* f = xframe::scaled_font(display_, try_px, true); + if (xframe::font_text_width(f, pk) <= avail_w) + { + pk_px = try_px; + pk_font = f; + break; + } + pk_px = try_px; + pk_font = f; + } + (void)pk_px; + xframe::draw_text_font(display_, window_, gc_, pk_font, + bx + bw - xframe::font_text_width(pk_font, pk) - 4, py - 6, pk, col(peak_color_)); }