Can a Container be both drawn on and have components visible in gtk2hs?

115 views Asked by At

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
1

There are 1 answers

0
Joachim Breitner On BEST ANSWER

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.