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