Implementing Container Actors

You can create container actors that arrange child actors by implementing the Container interface in your actor. You may use the G_DEFINE_TYPE_WITH_CODE macro to specify that the type is derived from clutter.Actor and also implements the clutter.Container 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));

ClutterActor virtual functions to implement

If your container should control the position or size of its children then it should implement the clutter.Actor'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 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 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 (REQUEST_HEIGHT_FOR_WIDTH) or width for height 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. actor.get_preferred_size() checks this property and then calls either actor.get_preferred_width() or actor.get_preferred_height() in the correct sequence.

You should implement the paint() function, usually calling actor.paint() on the child actors. All containers should also implement the pick() function, calling actor.pick() on each child actor.

See the Custom Actor section for more details these virtual functions.

ClutterContainer virtual functions to implement

Your container implementation should also implement some of the clutter.Container 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 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().