From 5262d942c4c2c36529fbe704e7de165044e6dc99 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Tue, 31 Dec 2024 11:43:49 +0530 Subject: Add timing measurement for each section of screen --- src/Chelleport.hs | 2 +- src/Chelleport/View.hs | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/Chelleport.hs b/src/Chelleport.hs index 8cc02c7..6486b4a 100644 --- a/src/Chelleport.hs +++ b/src/Chelleport.hs @@ -24,7 +24,7 @@ run config = do runAppWithCtx :: (MonadIO m) => DrawContext -> AppM m x -> m x runAppWithCtx ctx = (`runReaderT` ctx) . runAppM --- TODO: Make event handling independent of state +-- TODO: Make event handling independent of state? eventHandler :: State -> SDL.Event -> Maybe AppAction eventHandler state event = case SDL.eventPayload event of diff --git a/src/Chelleport/View.hs b/src/Chelleport/View.hs index 314aa39..369b93d 100644 --- a/src/Chelleport/View.hs +++ b/src/Chelleport/View.hs @@ -27,13 +27,16 @@ getSearchText state (ModeSearchData {searchInputText, searchFilteredWords, searc renderSearchView :: (MonadDraw m) => State -> ModeSearchData -> m () renderSearchView state searchData@(ModeSearchData {searchFilteredWords, searchHighlightedIndex}) = do renderGridLines state + mapM_ highlightWord $ zip [0 ..] searchFilteredWords + drawSearchText + where + highlightWord (index, OCRMatch {matchStartX, matchStartY, matchEndX, matchEndY}) = do + setDrawColor $ if searchHighlightedIndex == index then colorAccent else colorLightGray + fillRectVertices (matchStartX, matchStartY) (matchEndX, matchEndY) - 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 - void $ drawText (w `div` 2, 5 + h `div` 2) searchingTextStyle (Text.pack $ getSearchText state searchData) + drawSearchText = do + (w, h) <- windowSize + void $ drawText (w `div` 2, 5 + h `div` 2) searchingTextStyle (Text.pack $ getSearchText state searchData) renderHintsView :: (MonadDraw m) => State -> ModeHintsData -> m () renderHintsView state (ModeHintsData {stateGrid, stateKeySequence, stateIsMatched}) = do -- cgit v1.3.1