WxGeneric-0.2.0: examples/Examples.hs
{-# LANGUAGE FlexibleContexts, FlexibleInstances
, MultiParamTypeClasses, TemplateHaskell, UndecidableInstances #-}
-- Why is UndecidableInstances neccesary? as derive requires it.
-- Otherwise we get "Constraint is no smaller than the instance head"-error.
-- This is a general problem with using SYB.
module Examples where
import Graphics.UI.WxGeneric
import Graphics.UI.XTC
import Graphics.UI.WX
import Graphics.UI.WXCore
import Graphics.UI.SybWidget.MySYB
data MyTree = Branch { left :: MyTree, right :: MyTree }
| Leaf Int Double
deriving Show
$(derive [''MyTree])
instance WxGen MyTree
data Person = Person { name :: String, age :: Int, children :: [Person] } deriving Show
-- data Person = Person { name :: String, children :: [String], age :: Int }
$(derive [''Person])
instance WxGen Person
main = listTest
someTree = Leaf 5 5.2
x :: Int
x = 17
tree = start $
do f <- frame []
p <- panel f []
en <- genericWidget p someTree
set en [ on change := get en widgetValue >>= print ]
b1 <- button p [ text := "&Make simple tree"
, on command := set en [ widgetValue := someTree ] ]
b2 <- button p [ text := "&Show tree"
, on command := get en widgetValue >>= print ]
set f [ layout := container p $ column 10 [ fill $ widget en
, row 10 [ glue, widget b1, widget b2 ]
] ]
tree' = start $
do f <- frame []
-- p <- panel f []
scWin <- scrolledWindow f [ scrollRate := sz 10 10, virtualSize := sz 500 500, fullRepaintOnResize := False ]
scrolledWindowEnableScrolling scWin True True
b1 <- button f [ text := "&Do stuff"
, on command := set scWin [ virtualSize := sz 1000 1000 ] ]
en <- genericWidget scWin someTree
set scWin [ layout := fill $ widget en ]
set f [ layout := column 1 [ hfill $ hrule 1
, fill (widget scWin)
, widget b1
] ]
person = start $
do f <- frame []
p <- panel f []
-- en <- genericWidget p (Person "Bob" [] 17)
en <- genericWidget p (Person "Bob" 17 [])
set f [ layout := container p $ fill $ widget en ]
anyInt = start $
do f <- frame []
intEntry <- genericWidget f x
set intEntry [ on change := get intEntry widgetValue >>= print ]
set f [ layout := widget intEntry ]
mai3 = start $
do f <- frame []
p <- panel f []
en <- textEntry p []
set f [ layout := widget p ] -- must also have fill
set p [ layout := fill $ widget en ]
enum = start $
do f <- frame []
myEnum <- genericWidget f Enum1
set myEnum [ on change := get myEnum widgetValue >>= print ]
set f [ layout := widget myEnum ]
listTest = start $
do f <- frame []
p <- panel f []
listWid <- genericWidget p [1::Int, 2, 8]
set listWid [ on change := get listWid widgetValue >>= print ]
set f [ layout := container p $ fill $ widget listWid ]
data MyEnum = Enum1 | Enum2 | Enum3 deriving Show
$(derive [''MyEnum])
instance WxGen MyEnum