wxHaskell:初始帧大小太小

时间:2013-02-21 12:06:48

标签: haskell wxhaskell

在安装了WxHaskell和gtk2hs后,我正在玩两者来解决它们中的哪一个选择。对于WxHaskell,我正在处理WxHaskell at haskell.org的文档。以下第一个示例来自“快速入门”部分:

 -- 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]

禁止

 Debug: wxColour::Set - couldn't set to colour string 'MEDIUM GREY'
对于不同的图像文件格式,

和类似于以下行

 Debug: Adding duplicate image handler for 'PNG file'

代码编译良好并加载到GHCi中。但是,运行时出现的窗口 高度为零,只有窗口的顶部栏可见,而无需手动调整窗口大小以包含按钮。在编译和加载到GHCi时都会发生这种情况。在GHCi中,当执行main一秒和任何后续时间时,高度将是正确的。如果我关闭并重新启动一个GHCi会话,意志将是“平坦的”并且不包括第一次调用main时的按钮,但在任何后续调用中都是正确的。在编译代码并在GHCi外部运行时,窗口始终是平坦的。

这是一个错误还是教程已过时或我遗漏的其他内容?

2 个答案:

答案 0 :(得分:3)

根据您的评论,这可能不是您想要的,但仅供参考......

您可以设置最小尺寸,而不是设置尺寸:

set f [layout := minsize (sz 300 200) $ widget quit]

答案 1 :(得分:1)

你可以像在C ++中使用wxWidgets一样,即使用布局。

例如,您可以使用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 ()