From 1d617d9db665ee9df209777626752a19496387b4 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Sat, 28 Dec 2024 22:19:52 +0530 Subject: Add text align and center aligns search text --- src/Chelleport/Draw.hs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/Chelleport/Draw.hs') diff --git a/src/Chelleport/Draw.hs b/src/Chelleport/Draw.hs index 2d3a77c..1fa8b31 100644 --- a/src/Chelleport/Draw.hs +++ b/src/Chelleport/Draw.hs @@ -33,7 +33,7 @@ instance (MonadIO m) => MonadDraw (AppM m) where let rect = SDL.Rectangle (SDL.P $ SDL.V2 x y) (SDL.V2 w h) SDL.fillRect renderer (Just rect) - drawText (x, y) (TextStyle {textColor, textSize}) text = do + drawText (x, y) (TextStyle {textColor, textSize, textAlign}) text = do DrawContext {ctxRenderer = renderer, ctxFontSmall, ctxFontLarge} <- ask let font = case textSize of FontSM -> ctxFontSmall @@ -47,9 +47,13 @@ instance (MonadIO m) => MonadDraw (AppM m) where let textWidth = SDL.textureWidth textureInfo let textHeight = SDL.textureHeight textureInfo + let (left, top) = case textAlign of + AlignLeft -> (x, y) + AlignCenter -> (x - textWidth `div` 2, y) + -- Render the texture SDL.copy renderer texture Nothing $ - Just (SDL.Rectangle (SDL.P $ SDL.V2 x y) (SDL.V2 textWidth textHeight)) + Just (SDL.Rectangle (SDL.P $ SDL.V2 left top) (SDL.V2 textWidth textHeight)) SDL.destroyTexture texture pure (textWidth, textHeight) -- cgit v1.3.1