Container 可以在 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
I want draw on the background (like a rectangle or such) and then have it render the components on top of that. The components would be on top of what I drew. Is there a way to do this?
Here's an example of the concept. This only displays the rectangle. So... just need some way to tell it to go render the components, too.
{-# 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这并不是 gtk2hs 特有的。根据 http://developer.gnome.org/gtk/2.24 /GtkWidget.html#GtkWidget-expose-event 您需要在更新处理程序中
返回 False
,以便之后也会调用其他处理程序。当您在示例中更改此设置时,按钮将覆盖整个窗口,因此矩形被隐藏。但是,例如,使用
tableSetHomogeneous table True
您可以获得所需的效果。This is not particular to gtk2hs. According to http://developer.gnome.org/gtk/2.24/GtkWidget.html#GtkWidget-expose-event you need to
return False
in your update handler, so that other handlers are also called afterwards.When you change this in your example, the button will cover the whole window, so the rectangle is hidden. But, for example, with
tableSetHomogeneous table True
you get the desired effect.