Latest revision as of 10:17, 1 January 2009
 1 A Short Guide
It is helpful to a get a grip on three basic concepts: Widgets, Layout and Events.
 1.1 Widgets
Widgets are the basic components of any GUIs. They include buttons, radio boxes, frames and what not. There are essentially two kinds of widgets: windows and controls. Windows are widgets that contain other widgets. Note: what you might normally think of as a window, i.e. that big thing with the close, minimise, maximise buttons on your OS in wxHaskell is a special kind of window called a "frame".
We define windows by calling some function (for example, frame) with a list of attributes. Here is a example which creates a frame with the title bar "Hello!":
hello = do f <- frame [text := "Hello!"]
The more interesting widgets are controls such a buttons and check boxes. We define controls almost the same way as windows, by calling some function (for example, button) with a window and a list of attributes:
hello = do f <- frame [text := "Hello!"] quit <- button f [text := "Quit"]
The relevant documentation:
* http://wxhaskell.sourceforge.net/doc/Graphics-UI-WX-Controls.html * http://wxhaskell.sourceforge.net/doc/Graphics-UI-WX-Window.html
 1.2 Layout
Layout means telling wxHaskell how to arrange your widgets with respect to each other. It is something you would normally do after you have defined all your widgets.
We won't go into much detail here because the Haddock-generated documentation is very helpful here, but here is a trivial example of layout where all we do is stick the quit button in the frame. Notice how layout is just an attribute of the frame widget.
hello = do f <- frame [text := "Hello!"] quit <- button f [text := "Quit"] set f [layout := widget quit]
 1.2.1 Scrolled windows
Widgets (for example, listboxes) will automatically create scrolled windows for you. You only need to deal with them if you are working with bitmaps.
 1.2.2 XRC
How do you use XRC-Files with wxHaskell? Is it possible?
- I also very much would like to know this. Anyone?
- There isn't a way, but it sounds like it might be a fun library to build
 1.3 Events
Events are what joins your widgets to the rest of your code. Whenever a user manipulates a widget (e.g. presses a button), an event is triggered. If you set the appropriate attributes, you can cause these events to call some piece of Haskell code. In the following example, we set the "on command" attribute to close the frame f.
hello = do f <- frame [text := "Hello!"] quit <- button f [text := "Quit", on command := close f] set f [layout := widget quit]
 1.3.1 Idle Event
Use idle event for automation.