-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreactiveDialogue.hs
48 lines (35 loc) · 1.82 KB
/
reactiveDialogue.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
{-# LANGUAGE ScopedTypeVariables #-}
import Control.Monad
import Data.Maybe
import Data.List.Grouping (splitEvery)
import Graphics.UI.WX hiding (Event)
import Reactive.Banana
import Reactive.Banana.WX
main = start first
first = do
parentPad <- frame [text := "First window"]
firstButton <- button parentPad [ text := "First" ]
childPad <- dialog parentPad [text := "Second window"]
okButton <- button childPad [text := "Allright"]
noButton <- button childPad [text := "No way"]
set childPad [layout := row 20 $ map widget [okButton, noButton]]
let netDescription :: forall t. Frameworks t => Moment t ()
netDescription = do
event <- event0 firstButton command
let behav :: Behavior t Int
behav = stepper (-1) $ 1 <$ event
sink childPad [visible :== (>0) <$> behav]
happenings <- mapM (flip event0 command) [okButton
,noButton]
let userChoice :: Behavior t Bool
userChoice = stepper False
. foldl1 union
. zipWith (<$) [True, False]
$ happenings
test <- changes ((\ x y ->
show x ++ show y)
<$> behav
<*> userChoice)
reactimate' $ fmap (print) <$> test
network <- compile netDescription
actuate network