GTK中的小部件间距

时间:2014-05-27 02:30:02

标签: haskell gtk

我很难通过GTK将小部件正确放置到空间,我正在尝试创建一个在窗口的大部分区域显示TextView的简单窗口,并在顶部有一个小小的条形图几个按钮。我在想这样的事情:

------------------------------
-                            -
------------------------------
-                            -
-                            -
-                            -
-                            -
-                            -
------------------------------

但是GTK实际上给了我更多这样的东西:

-----------------------------
-                           -
-                           -
-                           -
-----------------------------
-                           -
-                           -
-                           -
-----------------------------

我不希望各自的盒子分成两半。我该如何修复我的代码?

import Graphics.UI.Gtk

main :: IO ()
main = do
    initGUI
    window    <- windowNew
    windowBox <- vBoxNew True 2
    menuBox   <- hBoxNew True 2
    buttonOne <- buttonNewWithLabel "Button 1"
    buttonTwo <- buttonNewWithLabel "Button 2"
    textBuf   <- textBufferNew Nothing
    textView  <- textViewNewWithBuffer textBuf

    textBufferSetText textBuf "some text"

    boxPackStart menuBox buttonOne PackNatural 0
    boxPackStart menuBox buttonTwo PackNatural 0
    boxPackStart windowBox menuBox PackNatural 0
    boxPackStart windowBox textView PackGrow 0
    set window [containerChild := windowBox]
    widgetShowAll window
    mainGUI

1 个答案:

答案 0 :(得分:3)

正在创建“windowBox”,同构设置为True。只需将此设置为False即可得到所需的结果:

windowBox <- vBoxNew False 2

请参阅:http://hackage.haskell.org/package/gtk-0.12.3/docs/Graphics-UI-Gtk-Layout-VBox.html