This section introduces the architecture of the canvas,
including the arrangement of items into hierarchical
groups, and the many coordinate systems involved in using
the canvas.
Canvas items are arranged in a tree structure. You can
group items together, to be moved as a unit; canvas
architect Federico Mena Quintero likes to use a circuit
diagram editor as an example. You might group together
the shapes representing each logic gate, so you could
manipulate the logic gate as a unit. You could also
collect several logic gates into a single component; that
is, groups can contain subgroups. Within each group, the
canvas maintains a stacking order; objects higher in the
stacking order obscure objects lower in the stacking
order.
To implement this, the canvas comes with a special kind
of canvas item called
GnomeCanvasGroup. As the name suggests, a canvas
group groups a number canvas items together so you can
manipulate the child items as a single item. A GnomeCanvasGroup is invisible;
to render itself, it simply recurses its children,
rendering each of them in turn. When you create a new
GnomeCanvas, a default
group called the "root" is created for you. All canvas
items are added somewhere below the root group. The
canvas widget only deals with the root canvas item
directly; all other canvas items are managed by their
parent group.
An accessor function is provided to access the root
canvas group, shown in
Figure 1.
Items must always be part of a group; there is no such
thing as an "orphan" canvas item. When you create an
item, you must specify its canvas group. It is also
possible to reparent items after creation. However, items
are permanently bound to the
GnomeCanvas they were created on; it is not
permitted to reparent an item to a group on a different
canvas.