Reputation:
After having installed WxHaskell and gtk2hs I am playing around with both to work out which of them to choose. For WxHaskell I am working through the documentation at WxHaskell at haskell.org. The following first example is from the "Quick Start" section:
-- Copied from www.haskell.org/haskellwiki/WxHaskell/Quick_start
module Main where
import Graphics.UI.WX
main :: IO ()
main
= start hello
hello :: IO ()
hello
= do f <- frame [text := "Hello!"]
quit <- button f [text := "Quit", on command := close f]
set f [layout := widget quit]
Barring
Debug: wxColour::Set - couldn't set to colour string 'MEDIUM GREY'
and lines similar to the following for different image file formats
Debug: Adding duplicate image handler for 'PNG file'
the code compiles fine and loads fine into GHCi. However, the appearing window when running has a height that is zero, only the top bar of the window is visible without manually resizing the window to include the button. This happens both when compiling and loading into GHCi. In GHCi, the height will be correct when executing main a second and any following time. If I close and restart a GHCi session, the will aagin be "flat" and not include the button on the first call to main , but correct on any following calls. When compiling the code and running outside GHCi the window is always flat.
Is this a bug or is the tutorial out of date or something else I am missing ?
Upvotes: 1
Views: 764
Reputation: 11913
You can do this the same way you would do using wxWidgets in C++, i.e. with layouts.
For instance, you can use a box sizer:
module Main where
import Data.Bits
import Graphics.UI.WX
import Graphics.UI.WXCore.WxcDefs
import Graphics.UI.WXCore.Frame
import Graphics.UI.WXCore.WxcClassesAL
import Graphics.UI.WXCore.WxcClassesMZ
import Graphics.UI.WXCore.WxcTypes
main :: IO ()
main = start simple
simple :: IO ()
simple = do
hbox <- boxSizerCreate wxHORIZONTAL
window <- frame [text := "Title"]
quitButton <- button window [text := "Quit", on command := close window]
exitButton <- button window [text := "Exit", on command := close window]
windowSetSizer window hbox
sizerAddWindow hbox exitButton 1 (wxEXPAND .|. wxALL) 5 ptrNull
sizerAddWindow hbox quitButton 1 (wxEXPAND .|. wxALL) 5 ptrNull
frameCenter window
return ()
Upvotes: 1
Reputation: 14103
From your comments above, this probably isn't what you want, but for reference...
Instead of setting a size you could set a minimum size:
set f [layout := minsize (sz 300 200) $ widget quit]
Upvotes: 3