From 99a8e0305e1765bde7c2b5bb4b3ebfd74d8e1091 Mon Sep 17 00:00:00 2001 From: MichalPelka Date: Wed, 2 Dec 2026 00:58:27 +0100 Subject: [PATCH] Keep compass ruler label inside the window The ruler label was drawn 6 px below a bar placed 10 px from the bottom edge with a 14 px font, so its lower part fell off-screen. Lay out the widget from the bottom edge up and center the label under the bar. Fixes #672 Co-Authored-By: Claude Opus 5.5 --- raylib_widgets/src/CompassRuler.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/raylib_widgets/src/CompassRuler.cpp b/raylib_widgets/src/CompassRuler.cpp index 058e7bbf..9d9e09aa 100644 --- a/raylib_widgets/src/CompassRuler.cpp +++ b/raylib_widgets/src/CompassRuler.cpp @@ -13,7 +13,12 @@ namespace raylib_widgets { const float compassSize = 200.0f; const float originX = compassSize * 0.5f; - const float originY = static_cast(GetScreenHeight()) - bottomInset - compassSize * 0.5f; + // Lay out from the bottom edge up so the ruler label stays inside the window. + const int labelFontSize = 14; + const float labelMargin = 4.0f; + const float labelGap = 6.0f; + const float rulerY = static_cast(GetScreenHeight()) - bottomInset - labelMargin - labelFontSize - labelGap; + const float originY = rulerY - compassSize * 0.45f; const float axisPixelLength = compassSize * 0.35f; struct Axis @@ -53,11 +58,10 @@ namespace raylib_widgets else snprintf(label, sizeof(label), "<1 [cm]"); - float rulerY = originY + compassSize * 0.45f; DrawLineEx(Vector2{ originX - 40.f, rulerY }, Vector2{ originX + 40.f, rulerY }, 2.f, rulerColor); DrawLineEx(Vector2{ originX - 40.f, rulerY - 5.f }, Vector2{ originX - 40.f, rulerY + 5.f }, 2.f, rulerColor); DrawLineEx(Vector2{ originX + 40.f, rulerY - 5.f }, Vector2{ originX + 40.f, rulerY + 5.f }, 2.f, rulerColor); - DrawText(label, (int)originX - 20, (int)rulerY + 6, 14, rulerColor); + DrawText(label, (int)(originX - MeasureText(label, labelFontSize) * 0.5f), (int)(rulerY + labelGap), labelFontSize, rulerColor); } } // namespace raylib_widgets