aboutsummaryrefslogtreecommitdiff
path: root/src/Chelleport
diff options
context:
space:
mode:
Diffstat (limited to 'src/Chelleport')
-rw-r--r--src/Chelleport/Types.hs12
-rw-r--r--src/Chelleport/Utils.hs8
-rw-r--r--src/Chelleport/View.hs11
3 files changed, 24 insertions, 7 deletions
diff --git a/src/Chelleport/Types.hs b/src/Chelleport/Types.hs
index 9894e54..43d063f 100644
--- a/src/Chelleport/Types.hs
+++ b/src/Chelleport/Types.hs
@@ -22,12 +22,19 @@ data Mode
| ModeSearch
{ searchWords :: [OCRMatch],
searchFilteredWords :: [OCRMatch],
- searchInputText :: String
+ searchInputText :: String,
+ searchHighlightedIndex :: Int
}
deriving (Show, Eq)
defaultSearchMode :: Mode
-defaultSearchMode = ModeSearch {searchWords = [], searchFilteredWords = [], searchInputText = ""}
+defaultSearchMode =
+ ModeSearch
+ { searchWords = [],
+ searchFilteredWords = [],
+ searchInputText = "",
+ searchHighlightedIndex = 0
+ }
defaultHintsMode :: Mode
defaultHintsMode = ModeHints
@@ -69,6 +76,7 @@ data AppAction
| UpdateShiftState Bool
| UpdateRepetition Int
| SetMode Mode
+ | IncrementHighlightIndex Int
deriving (Show, Eq)
data DrawContext = DrawContext
diff --git a/src/Chelleport/Utils.hs b/src/Chelleport/Utils.hs
index c15a3e8..9423e5d 100644
--- a/src/Chelleport/Utils.hs
+++ b/src/Chelleport/Utils.hs
@@ -35,3 +35,11 @@ benchmark msg m = do
end <- systemNanoseconds <$> liftIO getSystemTime
Debug.traceM $ msg ++ " (ms): " ++ show (fromIntegral (end - start) / 1_000_000.0 :: Double)
pure result
+
+itemAt :: [a] -> Int -> Maybe a
+itemAt [] _ = Nothing
+itemAt (x : _) 0 = Just x
+itemAt (_ : xs) i = itemAt xs (i - 1)
+
+clamp :: (Integral a) => (a, a) -> a -> a
+clamp (low, high) n = max low (min high n)
diff --git a/src/Chelleport/View.hs b/src/Chelleport/View.hs
index 1a4f1f8..c2e0ff8 100644
--- a/src/Chelleport/View.hs
+++ b/src/Chelleport/View.hs
@@ -12,13 +12,14 @@ import Foreign.C (CInt)
render :: (MonadDraw m) => State -> m ()
render state = case stateMode state of
ModeHints -> renderHintsView state
- ModeSearch {searchFilteredWords} -> renderSearchView state searchFilteredWords
+ ModeSearch {searchFilteredWords, searchHighlightedIndex} ->
+ renderSearchView state searchFilteredWords searchHighlightedIndex
-renderSearchView :: (MonadDraw m) => State -> [OCRMatch] -> m ()
-renderSearchView state matches = do
+renderSearchView :: (MonadDraw m) => State -> [OCRMatch] -> Int -> m ()
+renderSearchView state matches highlightedIndex = do
renderGridLines state
- setDrawColor colorWhite
- forM_ matches $ \(OCRMatch {matchStartX, matchStartY, matchEndX, matchEndY}) -> do
+ forM_ (zip [0 ..] matches) $ \(index, OCRMatch {matchStartX, matchStartY, matchEndX, matchEndY}) -> do
+ setDrawColor $ if highlightedIndex == index then colorAccent else colorLightGray
fillRectVertices (matchStartX, matchStartY) (matchEndX, matchEndY)
renderHintsView :: (MonadDraw m) => State -> m ()