reactive-banana-wx 0.3.0.1 → 0.4.0.0
raw patch · 5 files changed
+80/−20 lines, 5 filesdep ~reactive-banananew-component:exe:TwoCountersPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: reactive-banana
API changes (from Hackage documentation)
+ Reactive.Banana.WX: behavior :: w -> Attr w a -> NetworkDescription (Behavior a)
- Reactive.Banana.WX: (:==) :: (Attr w a) -> (a, Event a) -> Prop' w
+ Reactive.Banana.WX: (:==) :: (Attr w a) -> Discrete a -> Prop' w
Files
- Makefile +8/−5
- reactive-banana-wx.cabal +6/−6
- src/Counter.hs +5/−5
- src/Reactive/Banana/WX.hs +10/−4
- src/TwoCounters.hs +51/−0
Makefile view
@@ -4,15 +4,18 @@ OBJ=dist/build COMPILE=ghc --make -outputdir $(OBJ) -i$(OBJ) -L$(OBJ) -isrc -i../reactive-banana/src +all: TwoCounters Counter+ Counter : src/Counter.hs src/Reactive/Banana/WX.hs- $(COMPILE) -o $@ $<+ $(COMPILE) -o $@ src/Counter.hs macosx-app $@ --all: Counter+TwoCounters : src/TwoCounters.hs src/Reactive/Banana/WX.hs+ $(COMPILE) -o $@ src/TwoCounters.hs+ macosx-app $@ clean: rm -rf $(APPS) $(OBJ)/*.o $(OBJ)/*.hi *.app *.exe *.manifest -open: Counter- open Counter.app+open: all+ open TwoCounters.app
reactive-banana-wx.cabal view
@@ -1,5 +1,5 @@ Name: reactive-banana-wx-Version: 0.3.0.1+Version: 0.4.0.0 Synopsis: Examples for the reactive-banana library, using wxHaskell. Description: This library provides some GUI examples for the @reactive-banana@ library,@@ -20,7 +20,7 @@ Library hs-source-dirs: src build-depends: base >= 4.2 && < 4.4,- reactive-banana >= 0.3.0.0 && < 0.4,+ reactive-banana >= 0.4.0.0 && < 0.5, wx==0.12.*, wxcore==0.12.* extensions: ExistentialQuantification exposed-modules: Reactive.Banana.WX@@ -33,7 +33,7 @@ Executable Counter hs-source-dirs: src main-is: Counter.hs- build-depends: base >= 4.2 && < 4.4,- reactive-banana >= 0.3.0.0 && < 0.4,- wx==0.12.*, wxcore==0.12.*- extensions: ExistentialQuantification++Executable TwoCounters+ hs-source-dirs: src+ main-is: TwoCounters.hs
src/Counter.hs view
@@ -1,5 +1,5 @@ {------------------------------------------------------------------------------ reactive-banan-wx+ reactive-banana-wx Example: Counter ------------------------------------------------------------------------------}@@ -27,9 +27,9 @@ edown <- event0 bdown command let- counter :: Event Int- counter = accumE 0 $ ((+1) <$ eup) `union` (subtract 1 <$ edown)+ counter :: Discrete Int+ counter = accumD 0 $ ((+1) <$ eup) `union` (subtract 1 <$ edown) - sink output [text :== ("0", show <$> counter)]+ sink output [text :== show <$> counter] - run network+ actuate network
src/Reactive/Banana/WX.hs view
@@ -28,16 +28,22 @@ event0 :: w -> WX.Event w (IO ()) -> NetworkDescription (Event ()) event0 widget e = event1 widget $ WX.mapEvent const (\_ e -> e ()) e +-- | Behavior form an attribute+behavior :: w -> WX.Attr w a -> NetworkDescription (Behavior a)+behavior widget attr = fromPoll . liftIO $ WX.get widget attr -data Prop' w = forall a. (WX.Attr w a) :== (a, Event a) +data Prop' w = forall a. (WX.Attr w a) :== Discrete a++infixr 0 :==+ -- | "Animate" a property with a stream of events sink :: w -> [Prop' w] -> NetworkDescription () sink widget props = mapM_ sink1 props where- sink1 (attr :== (x,ex)) = do- liftIO $ WX.set widget [attr := x]- reactimate $ (\x -> WX.set widget [attr := x]) <$> ex+ sink1 (attr :== x) = do+ liftIO $ WX.set widget [attr := initial x]+ reactimate $ (\x -> WX.set widget [attr := x]) <$> changes x
+ src/TwoCounters.hs view
@@ -0,0 +1,51 @@+{-----------------------------------------------------------------------------+ reactive-banana-wx+ + Example: Two Counters.+------------------------------------------------------------------------------}+module Main where++import Control.Monad+import Graphics.UI.WX hiding (Event)+import Reactive.Banana+import Reactive.Banana.WX++{-----------------------------------------------------------------------------+ Main+------------------------------------------------------------------------------}+main = start $ do+ f <- frame [text := "Two Counters"]+ bup <- button f [text := "Up"]+ bdown <- button f [text := "Down"]+ bswitch <- button f [text := "Switch Counters"]+ out1 <- staticText f []+ out2 <- staticText f []+ + set f [layout := margin 10 $+ column 5 [row 5 [widget bup, widget bdown, widget bswitch],+ grid 5 5 [[label "First Counter:" , widget out1]+ ,[label "Second Counter:", widget out2]]]]+ + network <- compile $ do+ eup <- event0 bup command+ edown <- event0 bdown command+ eswitch <- event0 bswitch command+ + let+ -- do we act on the left button?+ firstcounter :: Behavior Bool+ firstcounter = accumB True $ not <$ eswitch+ + -- joined state of the two counters+ counters :: Discrete (Int, Int)+ counters = accumD (0,0) $+ union ((increment <$> firstcounter) `apply` eup)+ ((decrement <$> firstcounter) `apply` edown)+ + increment left _ (x,y) = if left then (x+1,y) else (x,y+1)+ decrement left _ (x,y) = if left then (x-1,y) else (x,y-1)+ + sink out1 [text :== show . fst <$> counters]+ sink out2 [text :== show . snd <$> counters]+ + actuate network