Skip to content

Commit bfa31b5

Browse files
committed
Fix event handling in demo
1 parent bc4b74c commit bfa31b5

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

Main.hs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ main = do
3030

3131
loop :: Window -> IORef Bool -> IO ()
3232
loop w checked = do
33-
ev <- pollEventWithImGui
33+
quit <- pollEvents
3434

3535
openGL2NewFrame
3636
sdl2NewFrame w
@@ -85,11 +85,21 @@ loop w checked = do
8585

8686
glSwapWindow w
8787

88-
case ev of
89-
Nothing -> loop w checked
90-
Just Event{ eventPayload } -> case eventPayload of
91-
QuitEvent -> return ()
92-
_ -> loop w checked
88+
if quit then return () else loop w checked
89+
90+
where
91+
92+
pollEvents = do
93+
ev <- pollEventWithImGui
94+
95+
case ev of
96+
Nothing -> return False
97+
Just Event{ eventPayload } -> do
98+
let isQuit = case eventPayload of
99+
QuitEvent -> True
100+
_ -> False
101+
102+
(isQuit ||) <$> pollEvents
93103

94104

95105
whenTrue :: IO () -> Bool -> IO ()

0 commit comments

Comments
 (0)