1
我想繪製背景(像矩形或類似的東西),然後讓它在上面渲染組件。組件將在我繪製的頂部。有沒有辦法做到這一點?一個容器既可以被繪製,也可以在gtk2hs中顯示組件?
這是一個概念的例子。這隻顯示矩形。所以......只需要一些方法來告訴它去渲染組件。
{-# LANGUAGE PackageImports #-}
import Graphics.UI.Gtk
import Graphics.UI.Gtk.Gdk.EventM
import Graphics.UI.Gtk.Gdk.GC
import "mtl" Control.Monad.Trans(liftIO)
main = do
initGUI
window <- windowNew
window `onDestroy` mainQuit
windowSetDefaultSize window 800 600
windowSetPosition window WinPosCenter
table <- tableNew 3 3 False
button <- buttonNewWithLabel "Test Button"
tableAttachDefaults table button 1 2 1 2
containerAdd window table
table `on` exposeEvent $ update
widgetShowAll table
widgetShowAll window
mainGUI
update = do
win <- eventWindow
liftIO $ do
gc <- gcNew win
drawRectangle win gc False 10 10 90 90
return True