Update of /cvsroot/htoolkit/port/src/examples
In directory sc8-pr-cvs1:/tmp/cvs-serv30172/src/examples
Added Files:
ByeDemo.hs
Log Message:
added the goodbye demo for Port
--- NEW FILE: ByeDemo.hs ---
{--------------------------------------------------------------------------------
This program implements the "goodbye" demo as posted by John Meacham on
the Haskell GUI mailing list. The program is specified as:
I propose a simple program which pops up a window saying 'Hello World'
with a button saying 'Bye' which you click and it changes the message
to 'Goodbye'. if you click the button again the program exits.
--------------------------------------------------------------------------------}
module Main where
import Graphics.UI.Port
main = do demo -- setup gui
start -- start event loop
demo :: IO ()
demo
= do w <- createWindow
registerWindow w -- register for proper shutdown
registerWindowDismiss w (closeWindow w) -- close when the user dismisses the window
registerWindowPaint w (\can upd -> fillRect upd can) -- fill the background with some color
setWindowDomainSize w (Size 0 0) -- no scroll bars needed
setWindowViewSize w (Size 80 40) -- guess some size as Port has no layout manager
setWindowTitle w "Bye!"
l <- createLabel w
setLabelText l "Hello World!"
lsize <- getLabelRequestSize l -- get minimal size
moveResizeControl l (rectAt (Point 0 0) lsize) -- position in upperleft corner
b <- createButton w
setButtonText b "Bye"
bsize <- getButtonRequestSize b
moveResizeControl b (rectAt (Point 0 (sh lsize)) bsize) -- position under the label
registerButtonClick b (bye w l b) -- register event handler
showWindow w
where
bye w l b
= do setLabelText l "Goodbye"
registerButtonClick b (closeWindow w)
|