Re: GTK+ canvas?

Havoc Pennington <hp redhat com> writes:

> It depends on the goals of a "canvas" right - you're thinking of it as
> "drawing area plus hit testing" while it can be thought of as solving
> a wider set of problems.

> In particular I think of it as a more flexible sort of widget system
> more like HTML or Flash or XAML, in which the existing more rigid
> gtkwidget/gtkcontainer framework could be embedded.

I think retained mode is interesting when the objects have two

  - Does the object contain state that the application doesn't *care*

  - Is the object generic enough that many applications would need it

This is generally true for gtk+ widgets. For example GtkButton
contains the state "is the mouse cursor inside me?" which is entirely
uninteresting to applications. If gtk+ was completely immediate mode
in the sense I described, applications would need to maintain this
piece of information for every button it used, which is clearly
undesirable. Also GtkButton is clearly generic enough to be useful in
basically all applications.

Other pieces of state are more interesting: whether a checkbox is
checked or not is interesting to the application (I'll bet tons of
applications maintain a separate copy of the 'checked' bit for many of
their checkboxes).

Information such as 'what text does the GtkTextView contain' is very
clearly interesting to the application. GTK+ recognizes this by having
GtkTextBuffer separate from GtkTextView. But GtkTextView is less
generic; for example it is not useful as the main widget of a word

In the Inkscape example, all of the state pertaining to the shape is
interesting to the application. And a "shape" item would almost
certainly not be useful across applications.

So I'd be careful about only having a retained mode 'canvas'; you risk
ending up having to write tons and tons of special purpose 'canvas
items', not matter how flexible you make the canvas. 

On the other hand, if all you have is immediate mode you might end up
having to write the same recursive layout code over and over.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]