module main(main) where import CGA.SpinBox import CGA.Window main = cgaBegin $ do myInt <- newMVar MyInt 4 [] --The initial value of int variable doOnChange myInt (do a <- getVal myInt putStr (show a) ) --This shows myInt on the screen whenever it is changed -- The following two lines put the MyInt interface in a window interface <- make_interface myInt window <- newWindow [ title := "spinbox test", addChild := interface ] class Object a where make_interface :: MVar a -> Widget b doOnChange- :: MVar a -> (IO ()) -> IO () data MyInt = MyInt Int [(IO())] getVal :: MVar MyInt -> IO( Int ) getVal theint = MyInt a _ <- readMVar theint return a setVal :: MVar MyInt -> Int -> IO () setVal theint t = do modifyMVar theint (\(MyInt _ b) -> return (MyInt t b)) MyInt _ callbackList <- readMVar theint sequence_ callbackList return () instance Object Int where make_interface theint = do i <- getVal theint widget <- SpinBox [ value := i, onSpinChange := (setVal i) ] doOnChange theint (do a <- getVal theint set widget [ value := a ] return () --Just in case ) doOnChange theint callback = do modifyMVar theint (\(MyInt a b) -> return (MyInt a (callback:b)))