diff options
| author | Akshay Nair <phenax5@gmail.com> | 2024-12-28 20:27:04 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2024-12-28 20:27:04 +0530 |
| commit | b305546950a6742f25023e2ffece423905e1bda8 (patch) | |
| tree | 279f16bc685d4d3ac90b947dbaa1bfd8ef17265f /src/Chelleport/View.hs | |
| parent | 568923344f0941b2771459dd8dbe935ac971a968 (diff) | |
| download | chelleport-b305546950a6742f25023e2ffece423905e1bda8.tar.gz chelleport-b305546950a6742f25023e2ffece423905e1bda8.zip | |
Refactor mode data type
Diffstat (limited to '')
| -rw-r--r-- | src/Chelleport/View.hs | 35 |
1 files changed, 15 insertions, 20 deletions
diff --git a/src/Chelleport/View.hs b/src/Chelleport/View.hs index 790b3f7..03c12d3 100644 --- a/src/Chelleport/View.hs +++ b/src/Chelleport/View.hs @@ -11,34 +11,29 @@ import Foreign.C (CInt) render :: (MonadDraw m) => State -> m () render state = case stateMode state of - ModeHints -> renderHintsView state - ModeSearch {searchFilteredWords, searchHighlightedIndex} -> - renderSearchView state searchFilteredWords searchHighlightedIndex + ModeHints _ -> renderHintsView state + ModeSearch modeSearchData -> renderSearchView state modeSearchData -getSearchText :: State -> String -getSearchText state = case stateMode state of - ModeHints -> "" - ModeSearch {searchInputText, searchFilteredWords, searchHighlightedIndex} -> +getSearchText :: State -> ModeSearchData -> String +getSearchText state (ModeSearchData {searchInputText, searchFilteredWords, searchHighlightedIndex}) = searchText + where searchText - where - searchText - | stateIsModeInitialized state = "Searching (" ++ matchCount ++ "): " ++ searchInputText - | otherwise = "Loading..." - matchCount - | isEmpty searchFilteredWords = "0/0" - | otherwise = show (searchHighlightedIndex + 1) ++ "/" ++ show (length searchFilteredWords) + | stateIsModeInitialized state = "Searching (" ++ matchCount ++ "): " ++ searchInputText + | otherwise = "Loading..." + matchCount + | isEmpty searchFilteredWords = "0/0" + | otherwise = show (searchHighlightedIndex + 1) ++ "/" ++ show (length searchFilteredWords) -renderSearchView :: (MonadDraw m) => State -> [OCRMatch] -> Int -> m () -renderSearchView state matches highlightedIndex = do +renderSearchView :: (MonadDraw m) => State -> ModeSearchData -> m () +renderSearchView state searchData@(ModeSearchData {searchFilteredWords, searchHighlightedIndex}) = do renderGridLines state - forM_ (zip [0 ..] matches) $ \(index, OCRMatch {matchStartX, matchStartY, matchEndX, matchEndY}) -> do - setDrawColor $ if highlightedIndex == index then colorAccent else colorLightGray + forM_ (zip [0 ..] searchFilteredWords) $ \(index, OCRMatch {matchStartX, matchStartY, matchEndX, matchEndY}) -> do + setDrawColor $ if searchHighlightedIndex == index then colorAccent else colorLightGray fillRectVertices (matchStartX, matchStartY) (matchEndX, matchEndY) (w, h) <- windowSize - drawText (w `div` 2, h `div` 2) colorAccent FontSM (Text.pack $ getSearchText state) - pure () + void $ drawText (w `div` 2, h `div` 2) colorWhite FontSM (Text.pack $ getSearchText state searchData) renderHintsView :: (MonadDraw m) => State -> m () renderHintsView state = do |
