aboutsummaryrefslogtreecommitdiff
path: root/src/Chelleport
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2024-12-28 22:19:52 +0530
committerAkshay Nair <phenax5@gmail.com>2024-12-28 22:19:52 +0530
commit1d617d9db665ee9df209777626752a19496387b4 (patch)
tree7771e99d818c5145c70e846dac3e964b653e6450 /src/Chelleport
parent1bd86a46dcf21a75656edd181f97035739fa238d (diff)
downloadchelleport-1d617d9db665ee9df209777626752a19496387b4.tar.gz
chelleport-1d617d9db665ee9df209777626752a19496387b4.zip
Add text align and center aligns search text
Diffstat (limited to 'src/Chelleport')
-rw-r--r--src/Chelleport/Config.hs4
-rw-r--r--src/Chelleport/Draw.hs8
-rw-r--r--src/Chelleport/Types.hs6
-rw-r--r--src/Chelleport/View.hs3
4 files changed, 14 insertions, 7 deletions
diff --git a/src/Chelleport/Config.hs b/src/Chelleport/Config.hs
index 398e3d6..ab94dce 100644
--- a/src/Chelleport/Config.hs
+++ b/src/Chelleport/Config.hs
@@ -5,10 +5,10 @@ import Foreign.C (CFloat)
import qualified SDL
searchingTextStyle :: TextStyle
-searchingTextStyle = TextStyle {textColor = colorWhite, textSize = FontSM}
+searchingTextStyle = TextStyle {textColor = colorWhite, textSize = FontSM, textAlign = AlignCenter}
hintLabelTextStyle :: TextStyle
-hintLabelTextStyle = TextStyle {textColor = colorWhite, textSize = FontLG}
+hintLabelTextStyle = TextStyle {textColor = colorWhite, textSize = FontLG, textAlign = AlignLeft}
colorWhite :: Color
colorWhite = SDL.V4 255 255 255 255
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)
diff --git a/src/Chelleport/Types.hs b/src/Chelleport/Types.hs
index 56e6d8c..4001de8 100644
--- a/src/Chelleport/Types.hs
+++ b/src/Chelleport/Types.hs
@@ -153,8 +153,12 @@ data Configuration = Configuration
instance Default Configuration where
def = Configuration {configMode = ModeHints def, configShowHelp = False}
+data TextAlign = AlignLeft | AlignCenter
+ deriving (Show, Eq)
+
data TextStyle = TextStyle
{ textColor :: Color,
- textSize :: FontSize
+ textSize :: FontSize,
+ textAlign :: TextAlign
}
deriving (Show, Eq)
diff --git a/src/Chelleport/View.hs b/src/Chelleport/View.hs
index 42c23a9..a1195c7 100644
--- a/src/Chelleport/View.hs
+++ b/src/Chelleport/View.hs
@@ -33,8 +33,7 @@ renderSearchView state searchData@(ModeSearchData {searchFilteredWords, searchHi
fillRectVertices (matchStartX, matchStartY) (matchEndX, matchEndY)
(w, h) <- windowSize
- let textStyle = TextStyle {textColor = colorWhite, textSize = FontSM}
- void $ drawText (w `div` 2, h `div` 2) textStyle (Text.pack $ getSearchText state searchData)
+ void $ drawText (w `div` 2, h `div` 2) searchingTextStyle (Text.pack $ getSearchText state searchData)
renderHintsView :: (MonadDraw m) => State -> ModeHintsData -> m ()
renderHintsView state (ModeHintsData {stateGrid, stateKeySequence, stateIsMatched}) = do