From: Axel S. <Axe...@in...> - 2010-09-19 08:27:08
|
Hi Vivian, On Sep 19, 2010, at 5:59, Vivian McPhail wrote: > Hi, > > I'd like to be able to create a new widget type in Haskell. Is this > possible? > We don't provide a way to construct new widgets. But you can take a DrawingArea and add some new attributes to it which is usually all that is needed. > The widget draws (using cairo) a graph to a drawArea inside a > container. I would like to have the widget store the graph data > structure so that it can be get/set'ted. Unfortunately I am unclear > as to how the Attribute system works with respect to defining new > attributes. Does each widget instance have some sort of unique ID? > No, it's simpler than that. An individual widget has an instance with an individual pointer. You can simply compare the handles to a widget using == . In order to store additional information inside a widget you use objectCreateAttribute (with unsafePerformIO) to add a new attribute to a widget, e.g.: myInt :: (Attr DrawingArea (Maybe Int)) myInt = unsafePerformIO $ objectCreateAttribute Then later you can access this integer using set and get as you would with any other attributes. If this integer has never been set on a particular instance, you get Nothing back. Hope this helps, Axel > Are there any examples I could be pointed to, or somewhere to > start? (I have seen how to derive a new widget in C++, but that > does not help). > > This is essentially the code that works at the moment, but the > canvas is not its own widget type: > > \begin{code} > plotNew :: Frame -> Figure () -> IO Plot > plotNew frame figure = do > canvas <- drawingAreaNew > containerAdd frame canvas > widgetModifyBg canvas StateNormal (Color 65535 65535 65535) > > -- unclear here > {- > newAttr (\this -> getFigureData this->uniqueID) > (\this fig -> setFigureData this->uniqueID fig) > -} > > on canvas exposeEvent $ tryEvent $ do s <- liftIO $ widgetGetSize > canvas > drw <- > liftIO $ widgetGetDrawWindow canvas > liftIO > $ renderWithDrawable drw (render figure s) > return canvas > \end{code} > > Thanks, > > Vivian > ------------------------------------------------------------------------------ > Start uncovering the many advantages of virtual appliances > and start using them to simplify application deployment and > accelerate your shift to cloud computing. > http://p.sf.net/sfu/novell-sfdev2dev_______________________________________________ > Gtk2hs-users mailing list > Gtk...@li... > https://lists.sourceforge.net/lists/listinfo/gtk2hs-users |