You can create container actors that arrange child actors by implementing the
ClutterContainer interface in your actor. You may use the G_DEFINE_TYPE_WITH_CODE
macro to specify that the type is derived from ClutterActor
and also implements the ClutterContainer interface. For instance:
static void clutter_container_iface_init (ClutterContainerIface *iface);
G_DEFINE_TYPE_WITH_CODE (ExampleContainer, example_container, CLUTTER_TYPE_ACTOR,
G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_CONTAINER,
clutter_container_iface_init));
If your container should control the position or size of its children then
it should implement the ClutterActor's
allocate(), get_preferred_width() and
get_preferred_height() virtual functions.
For instance, your allocate() implementation should
use the provided allocation to layout its child actors, by calling
clutter_actor_allocate() on each child actor with appropriate
allocations.
Your get_preferred_width() and
get_preferred_height() implementations should
return the size desired by your container, by providing both the minimum and
natural size as output parameters. Depending on your
container, this might be dependent on the child actors. By calling
clutter_actor_get_preferred_size() you can discover the preferred
height and width of a child actor.
Your actor should implement one of two geometry management modes - either height
for width (CLUTTER_REQUEST_HEIGHT_FOR_WIDTH) or width for height
CLUTTER_REQUEST_WIDTH_FOR_HEIGHT) and should set its
request-mode property to indicate which one it uses. For instance, in
height-for-width mode, the parent actor first asks for the preferred height and then asks for
a preferred width appropriate for that height. clutter_actor_get_preferred_size()
checks this property and then calls either clutter_actor_get_preferred_width()
or clutter_actor_get_preferred_height() in the correct sequence.
You should implement the paint() function, usually
calling clutter_actor_paint() on the child actors. All
containers should also implement the pick() function, calling
clutter_actor_pick() on each child actor.
See the Custom Actor section for more details these virtual functions.
Your container implementation should also implement some of the
ClutterContainer virtual functions so that the container's
children will be affected appropriately when functions are called on the container.
For instance, your add() and
remove() implementions should manage your container's
internal list of child actors and might need to trigger repositioning or
resizing of the child actors by calling
clutter_actor_queue_relayout().
Your foreach implementation would simply call the
provided callback on your container's list of child actors. Note that your container
could actually contain additional actors that are not considered to be child
actors for the purposes of add(), remove(), and foreach().