diff options
| author | Akshay Nair <phenax5@gmail.com> | 2024-12-28 22:19:52 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2024-12-28 22:19:52 +0530 |
| commit | 1d617d9db665ee9df209777626752a19496387b4 (patch) | |
| tree | 7771e99d818c5145c70e846dac3e964b653e6450 /src/Chelleport/Draw.hs | |
| parent | 1bd86a46dcf21a75656edd181f97035739fa238d (diff) | |
| download | chelleport-1d617d9db665ee9df209777626752a19496387b4.tar.gz chelleport-1d617d9db665ee9df209777626752a19496387b4.zip | |
Add text align and center aligns search text
Diffstat (limited to 'src/Chelleport/Draw.hs')
| -rw-r--r-- | src/Chelleport/Draw.hs | 8 |
1 files changed, 6 insertions, 2 deletions
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) |
