mirror of
https://git.vladimir.cc/vladimir/ewsdr.git
synced 2026-08-25 17:27:32 +00:00
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:
+13
-6
@@ -162,6 +162,7 @@ var
|
||||
FreqStart, FreqHz, GridLine, pixPerStep: Double; VfoX: Integer;
|
||||
Lbl: string; TW: Integer;
|
||||
N, labelMult: Integer;
|
||||
TickMaj, TickMin, LabelY: Integer;
|
||||
begin
|
||||
if FPbRuler = nil then Exit;
|
||||
W := FPbRuler.Width; H := FPbRuler.Height;
|
||||
@@ -181,8 +182,14 @@ begin
|
||||
// а не к point-size — иначе на Windows-масштабе 125/150/200% текст не совпадал с
|
||||
// высотой полосы (метки мелкие/обрезались). Теперь шрифт скейлится вместе с DPI.
|
||||
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;
|
||||
// Короткие 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;
|
||||
if FFMGridStepHz > 0 then
|
||||
begin
|
||||
@@ -201,14 +208,14 @@ begin
|
||||
C.Pen.Color := FTheme.RulerBorder;
|
||||
if (N mod labelMult) = 0 then
|
||||
begin
|
||||
C.MoveTo(X, 0); C.LineTo(X, H div 2);
|
||||
C.MoveTo(X, 0); C.LineTo(X, TickMaj);
|
||||
Lbl := Format('%.3f', [GridLine / 1e6]);
|
||||
TW := C.TextWidth(Lbl);
|
||||
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
|
||||
begin
|
||||
C.MoveTo(X, 0); C.LineTo(X, H div 4);
|
||||
C.MoveTo(X, 0); C.LineTo(X, TickMin);
|
||||
end;
|
||||
end;
|
||||
Inc(N);
|
||||
@@ -220,12 +227,12 @@ begin
|
||||
begin
|
||||
X := ScaleX(i, 8, W);
|
||||
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;
|
||||
Lbl := Format('%.3f', [FreqHz / 1e6]);
|
||||
TW := C.TextWidth(Lbl);
|
||||
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;
|
||||
VfoX := Round((ActiveVfoFreq - FCenterFreq + FSpanHz/2) / FSpanHz * W);
|
||||
|
||||
Reference in New Issue
Block a user