-
Notifications
You must be signed in to change notification settings - Fork 70
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
Gloss GUI events not responding #264
Comments
I'm not really familiar with Gloss, so I can't give a good answer. Your code is a bit confusing, e.g. It looks like the |
This pattern wasn't clear. Hope it is right. This works.
|
@mohanr I'm afraid I'm struggling to understand exactly what your question is, but I'm going to interpret it as "how do I integrate main :: IO ()
main = do
-- Create an AddHandler that notifies us when gloss Events occur
(eventAddHandler, notifyEvent) <- newAddHandler
-- Create another AddHandler for when we want rendering to happen
(renderAddHandler, render) <- newAddHandler
picRef <- newIORef blank
actuate =<< compile (game picRef eventAddHandler renderAddHandler)
Gloss.playIO
(InWindow "Functional Reactive" (320, 240) (800, 200))
white
30
()
(\() -> render >> readIORef picRef)
(\ev _ -> notifyEvent ev)
(\_ () -> pure ())
game :: IORef Picture -> AddHandler Gloss.Event -> AddHandler () -> MomentIO ()
game picRef eventAddHandler renderAddHandler = do
onEvent <- fromAddHandler eventAddHandler
onSample <- fromAddHandler sampleAddHandler
-- Here we accumulate gloss events into a new world satte
worldState <- accumB .. ..
-- Whenever 'onRender' fires
reactimate $ writeIORef picRef . drawWorld <$> worldState <@ onRender |
@mohanr Was my response above helpful? Can we close this issue, or are you still stuck? |
I have these 'inlined' questions as now I do this. Am I complicating this ? It works though but the new Picture is just very simple.
|
I was looking for guidance to use Gloss GUI events and react based on keystrokes. But here it is not clear how one would wait for a Gloss GUI event and react. Can I look at other examples ?
Since this example is using loops I couldn't use it for my Gloss GUI.
Is this example the recommended way ? It is hidden in the documentation.
The code that compiles is this. It works only the first time when
eventLoop
fires an event. But KeyBoard events etc. are required to react.Update :
Removed unused code.
Primarily I was trying to use this code to trap events and fire
reactive-banana
events. Maybe that isn't possible.If I remove the additional
eventHandler
then using onlysources
I can triggerreactive-banana
events ? Somehow Icouldn't make it compile.
The text was updated successfully, but these errors were encountered: