Update readme example (#103)

Fixes #68
This commit is contained in:
Alexander Bondarenko
2021-09-14 15:41:38 +03:00
committed by GitHub
parent 76ce7bb569
commit b4bc36ca89
2 changed files with 37 additions and 17 deletions

View File

@ -45,10 +45,7 @@ main = do
mainLoop :: Window -> IO ()
mainLoop window = do
-- Process the event loop
untilNothingM pollEventWithImGui
mainLoop window = unlessQuit do
-- Tell ImGui we're starting a new frame
openGL2NewFrame
sdl2NewFrame
@ -78,4 +75,17 @@ mainLoop window = do
mainLoop window
where
untilNothingM m = m >>= maybe (return ()) (\_ -> untilNothingM m)
-- Process the event loop
unlessQuit action = do
shouldQuit <- checkEvents
if shouldQuit then pure () else action
checkEvents = do
pollEventWithImGui >>= \case
Nothing ->
return False
Just event ->
(isQuit event ||) <$> checkEvents
isQuit event =
SDL.eventPayload event == SDL.QuitEvent