some more frantk demos for a talk
\begin{code}
module Main where
import FranTk

main :: IO ()
main = display $ withRootWindow [title "Demos"] $ do
 let mkb (s,d) = do g <- mkGUIL_ d;fillX $ mkButton [text s] g
 nabove $ map mkb demos
  where
   demos = [("helloworld - 1",test1),
	    ("helloworld - 2",test2),
            ("timer - 3",test3),
            ("bounce - 4",test4),
            ("counter - 5",test5),
            ("dynamic - 6",test6),
	    ("edit - 7",test7)]
\end{code}

\begin{code}
displayComponent :: Component -> GUI ()
displayComponent c = render $ mkWindow [title "tk"] $ c

test1 :: GUI ()
test1 = displayComponent (mkLabel [text "Hello world"])

test2 :: GUI ()
test2 = displayComponent (above hello hello)

hello :: Component
hello = mkLabel [text "Hello world"]
\end{code}

time varying demos

a counting label

\begin{code}
displayComponent' :: Component -> GUI ()
displayComponent' c = render $ do
 rm <- everyTick 1
 destroyL (mkL_ $ rm) $
  mkWindow [title "tk"] $ c

test3 :: GUI ()
test3 = do
     displayComponent' (mkLabel [textB (lift1 show time)])
\end{code}

a bouncing ball
we don't have time transforms so have to do it manually

\begin{code}
displayCComponent :: (Time -> CComponent) -> GUI ()
displayCComponent c = render $ do
 -- tick every half second
 rm <- everyTick 0.5
 --stop ticking when the window closes
 destroyL (mkL_ rm ) $
  mkWindow [title "tk"] $ do
   -- make a canvas
   mkCanvas [backgroundB black] $
      -- move everything down towards the center of the canvas
      moveXY 0 80 $ do
        t <- liftIO getFranTime
        c t

test4 :: GUI ()
test4 = displayCComponent $ \t ->
      -- make a ball following a wave motion
      moveXY ((time - lift0 t)* 30) (sin time * 80) $
        mkCOval (vector2XY 30 30) [fillColorB blue]
\end{code}


The counter with button and slider (from the user manual)
\begin{code}
test5 :: GUI ()
test5 = displayComponent component

component :: Component
component = 
    do m <- mkBVar 0;composite m
 where
  composite :: BVar Int -> Component
  composite m = above (label m) (slider m)

  label :: BVar Int -> Component
  label m = mkLabel [textB (lift1 change (bvarBehavior m))]

  change :: Int -> String
  change x = show (x * 2)

  slider :: BVar Int -> Component
  slider m = mkHScale [scaleValB (bvarBehavior m)] (input m)
\end{code}

A dynamic collection of counters

\begin{code}

test6 :: GUI ()
test6 = displayComponent components

components :: Component
components = do
 w <- mkWire
 count <- countE (event w)
 l <- mkListBVar' identify []
 let add = snapshotL_ count (appendListB l)
 let mk = fillX $ mkButton [text "Create"] (mergeL add (input w))
 let new :: Int -> Component
     new n = mkLabel [text ("counter: " ++ show n)] `above` component
 above mk (nabove $ fmap new $ collection l)
  
\end{code}

shared editor

\begin{code}
test7 :: GUI ()
test7 = displayComponent $ do
	 doc <- mkDocumentBVar emptyIDoc
         let edit = mkEdit [useDocBVar doc]
         beside edit edit
\end{code}
