fix: center ruler labels vertically (short ticks + TextHeight centering)

After tying the ruler font to the ruler height, the labels (drawn at a
fixed H/2-1 top) sat below center because the taller font extended
downward. Shorten the ticks (major H*0.34, minor H*0.20) and center the
label in the area beneath them using TextHeight, so the digits are
vertically centered at any DPI. Applies to both the normal grid and the
FM-step grid branch.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-23 21:33:19 +03:00
co-authored by Claude Opus 4.8
parent fd85b532ee
commit 5c17fdcb7e
+13 -6
View File
@@ -162,6 +162,7 @@ var
FreqStart, FreqHz, GridLine, pixPerStep: Double; VfoX: Integer; FreqStart, FreqHz, GridLine, pixPerStep: Double; VfoX: Integer;
Lbl: string; TW: Integer; Lbl: string; TW: Integer;
N, labelMult: Integer; N, labelMult: Integer;
TickMaj, TickMin, LabelY: Integer;
begin begin
if FPbRuler = nil then Exit; if FPbRuler = nil then Exit;
W := FPbRuler.Width; H := FPbRuler.Height; W := FPbRuler.Width; H := FPbRuler.Height;
@@ -181,8 +182,14 @@ begin
// а не к point-size — иначе на Windows-масштабе 125/150/200% текст не совпадал с // а не к point-size — иначе на Windows-масштабе 125/150/200% текст не совпадал с
// высотой полосы (метки мелкие/обрезались). Теперь шрифт скейлится вместе с DPI. // высотой полосы (метки мелкие/обрезались). Теперь шрифт скейлится вместе с DPI.
C.Font.Name := 'Courier New'; C.Font.Style := []; C.Font.Name := 'Courier New'; C.Font.Style := [];
C.Font.Height := -Max(8, Round(H * 0.45)); C.Font.Height := -Max(8, Round(H * 0.42));
C.Brush.Style := bsClear; C.Brush.Style := bsClear;
// Короткие ticks сверху + метка по центру оставшейся области (по TextHeight),
// чтобы цифры стояли по центру, а не уезжали вниз.
TickMaj := Max(4, Round(H * 0.34));
TickMin := Max(2, Round(H * 0.20));
LabelY := TickMaj + ((H - TickMaj) - C.TextHeight('0')) div 2;
if LabelY < TickMaj then LabelY := TickMaj;
FreqStart := FCenterFreq - FSpanHz / 2; FreqStart := FCenterFreq - FSpanHz / 2;
if FFMGridStepHz > 0 then if FFMGridStepHz > 0 then
begin begin
@@ -201,14 +208,14 @@ begin
C.Pen.Color := FTheme.RulerBorder; C.Pen.Color := FTheme.RulerBorder;
if (N mod labelMult) = 0 then if (N mod labelMult) = 0 then
begin begin
C.MoveTo(X, 0); C.LineTo(X, H div 2); C.MoveTo(X, 0); C.LineTo(X, TickMaj);
Lbl := Format('%.3f', [GridLine / 1e6]); Lbl := Format('%.3f', [GridLine / 1e6]);
TW := C.TextWidth(Lbl); TW := C.TextWidth(Lbl);
C.Font.Color := FTheme.RulerText; C.Font.Color := FTheme.RulerText;
C.TextOut(X - TW div 2, H div 2 - 1, Lbl); C.TextOut(X - TW div 2, LabelY, Lbl);
end else end else
begin begin
C.MoveTo(X, 0); C.LineTo(X, H div 4); C.MoveTo(X, 0); C.LineTo(X, TickMin);
end; end;
end; end;
Inc(N); Inc(N);
@@ -220,12 +227,12 @@ begin
begin begin
X := ScaleX(i, 8, W); X := ScaleX(i, 8, W);
C.Pen.Color := FTheme.RulerBorder; C.Pen.Color := FTheme.RulerBorder;
C.MoveTo(X, 0); C.LineTo(X, H div 2); C.MoveTo(X, 0); C.LineTo(X, TickMaj);
FreqHz := FreqStart + i * FSpanHz / 8; FreqHz := FreqStart + i * FSpanHz / 8;
Lbl := Format('%.3f', [FreqHz / 1e6]); Lbl := Format('%.3f', [FreqHz / 1e6]);
TW := C.TextWidth(Lbl); TW := C.TextWidth(Lbl);
C.Font.Color := FTheme.RulerText; C.Font.Color := FTheme.RulerText;
C.TextOut(X - TW div 2, H div 2 - 1, Lbl); C.TextOut(X - TW div 2, LabelY, Lbl);
end; end;
end; end;
VfoX := Round((ActiveVfoFreq - FCenterFreq + FSpanHz/2) / FSpanHz * W); VfoX := Round((ActiveVfoFreq - FCenterFreq + FSpanHz/2) / FSpanHz * W);