Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use State monad for pure state operation #252

Merged
merged 9 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions daemon/app/ghc-specter-daemon/Handler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import Control.Concurrent.STM
)
import Control.Monad (when)
import Control.Monad.IO.Class (liftIO)
import Control.Monad.Trans.Class (lift)
import Control.Monad.Trans.Reader (ask)
import Control.Monad.Trans.State.Strict (get)
import Data.Bits ((.|.))
import Data.Text (Text)
import Foreign.Marshal.Utils (toBool)
Expand All @@ -30,7 +32,6 @@ import ImGui qualified
import ImGui.Enum (ImGuiInputFlags_ (..), ImGuiKey (..))
import Util.Render
( ImRender (..),
ImRenderState (..),
SharedState (..),
fromGlobalCoords,
)
Expand All @@ -42,7 +43,7 @@ sendToControl shared uev =
handleMove :: Text -> ImRender UserEvent ()
handleMove scene_id = do
renderState <- ImRender ask
let shared = renderState.currSharedState
shared <- ImRender $ lift get
when (shared.sharedIsMouseMoved) $ do
case shared.sharedMousePos of
Nothing -> pure ()
Expand All @@ -58,7 +59,7 @@ handleMove scene_id = do
handleClick :: Text -> ImRender UserEvent ()
handleClick scene_id = do
renderState <- ImRender ask
let shared = renderState.currSharedState
shared <- ImRender $ lift get
when (shared.sharedIsClicked) $ do
case shared.sharedMousePos of
Nothing -> pure ()
Expand All @@ -84,8 +85,8 @@ handleScrollOrZoom scene_id = do
liftIO $ ImGui.setItemKeyOwner key_wheel flags

renderState <- ImRender ask
let shared = renderState.currSharedState
(wheelX, wheelY) = shared.sharedMouseWheel
shared <- ImRender $ lift get
let (wheelX, wheelY) = shared.sharedMouseWheel
eps = 1e-3
isCtrlDown = shared.sharedCtrlDown
case shared.sharedMousePos of
Expand Down
Loading