From 26a11a4b7f32a6fc2d131e4c78fe1ca40cc6ac8a Mon Sep 17 00:00:00 2001 From: jussi Date: Thu, 10 Mar 2022 17:53:43 +0200 Subject: Measure text. --- examples/window/main.lua | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'examples/window') diff --git a/examples/window/main.lua b/examples/window/main.lua index ec25dd3..44d9fa7 100644 --- a/examples/window/main.lua +++ b/examples/window/main.lua @@ -1,5 +1,7 @@ local textColor = BLACK local textPos = { 192, 200 } +local imageFont = -1 +local text = "Congrats! You created your first window!" function init() RL_SetWindowTitle( "First window" ) @@ -7,8 +9,11 @@ end function process( delta ) if RL_IsKeyPressed( KEY_ENTER ) then + local textSize = RL_MeasureText( 0, text, 20, 2 ) + local winSize = RL_GetWindowSize() + textColor = BLUE - textPos = { 230, 230 } + textPos = { winSize[1] / 2 - textSize[1] / 2, winSize[2] / 2 - textSize[2] / 2 } end if RL_IsKeyPressed( KEY_SPACE ) then @@ -19,5 +24,5 @@ end function draw() RL_ClearBackground( RAYWHITE ) - RL_DrawText( 0, "Congrats! You created your first window!", textPos, 20, 2, textColor ) + RL_DrawText( 0, text, textPos, 20, 2, textColor ) end -- cgit v1.2.3