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.
This commit is contained in:
1 parent
9715773a2d
commit
7da1a1ef93
2 files changed
+27
-4
No files matched your search
@@ -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}));
|
||||
}
|
||||
|
||||
|
||||
@@ -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_));
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user