Search code examples
haskellgtkpangogtk2hs

Drawing text on GTK's DrawingArea in Haskell


I have a DrawingArea onto which I can draw using primitives such as drawRectangle and drawLine. How do I draw text onto that area? I'm most interested in something that quickly outputs a single line of text.

Graphics.UI.Gtk.Gdk.Drawable.layoutLine seems to be what I want, but it wants a Graphics.Rendering.Pango.Layout.LayoutLine as input. How do I construct that LayoutLine?

Are there better alternatives than doing it this way?

Thanks!


Solution

  • I've found the way to do this with Pango.

    layout <- widgetCreateLayout drawAreaWidget stringToDraw
    

    Then you can use this newly-created layout with functions such as drawLayout and drawLayoutWithColors.