Clutter::Container(3pm)
NAME
Clutter::Container - An interface for implementing container actors
DESCRIPTION
Clutter::Container is an interface for Clutter::Actors that provides a
common API for adding, removing and iterating over children.
By implementing the Clutter::Container interface with the usual
Glib::Object subclassing methods it is possible to use the
Clutter::Container API for managing children.
HIERARCHY
Glib::Interface
+----Clutter::Container
METHODS
- $container->add ($actor, ...)
- o ... (list) list of actors
- Adds a list of actors to container
- list = $container->child_get ($child, ...)
- o $child (Clutter::Actor)
- o ... (list) list of property names
- Returns a list of values of properties of the child
- list = $container->child_get_property ($child, ...)
- o $child (Clutter::Actor)
- o ... (list)
- childmeta = $container->get_child_meta ($actor)
- o $actor (Clutter::Actor)
- Retrieves the Clutter::ChildMeta instance for actor
- string = $container->get_child_meta_type
- Retrieves the ChildMeta type used by container
- $container->set_child_meta_type ($type_name)
- o $type_name (string)
- Sets the ChildMeta type used by container. This type can only be set
once and only if the container implementation does not have any
ChildMeta type set already. If you try to set the ChildMeta type on an instance with a type already set, this function will croak. - May croak with a Glib::Error in $@ on failure.
- $container->child_set ($child, ...)
- o $child (Clutter::Actor)
- o ... (list) list of property names
- Sets a list of properties of the child
- $container->child_set_property ($child, ...)
- o $child (Clutter::Actor)
- o ... (list)
- actors = $container->get_children actor or undef = $container->find_child_by_name ($name)
- o $name (string)
- $container->foreach ($callback, $callback_data=undef)
- o $callback (scalar)
- o $callback_data (scalar)
- $container->lower_child ($actor, $sibling)
- o $actor (Clutter::Actor)
- o $sibling (Clutter::Actor)
- $container->raise_child ($actor, $sibling)
- o $actor (Clutter::Actor)
- o $sibling (Clutter::Actor)
- $container->remove ($actor, ...)
- o ... (list) list of actors
- Removes a list of actors from container
CHILD PROPERTIES
Clutter::Container allows the management of properties that exist only
when an actor is contained inside a container.
For instance, it is possible to add a property like padding to a child
actor when inside a container; such property might only be useful when
adding any actor to a specific container implementation, and might be
desirable not to have it inside the actor class itself.
- In order to create child properties for a container it is needed to
subclass the Clutter::ChildMeta object class using the usual
Glib::Object mechanisms, like: - package My::ChildMeta;
- use Glib::Object::Subclass
'Clutter::ChildMeta',
properties => [...]; - The Clutter::ChildMeta class is the class that stores and handles the
child properties. A ChildMeta instance also stores references to the
container that handles it, and to the actor it is wrapping. - The container implementation should set the package name of the
ChildMeta subclass it will use; the most convenient place is inside the INIT_INSTANCE sub:
sub INIT_INSTANCE {my ($self) = @_;# instance set up$self->set_child_meta_type('My::ChildMeta');} - This is enough to start using the Clutter::Container::child_set() and
Clutter::Container::child_get() methods to store and retrieve values
for the properties specified inside the ChildMeta subclass, like:
$container->child_set($child, 'padding', [ 0, 10, 0, 10 ]); - When the child is removed from the container, the ChildMeta instance
bound to it will simply disappear. - It is also possible to exercise a higher degree of control on the
creation and destruction of the ChildMeta instances by using the
CREATE_CHILD_META, GET_CHILD_META and DESTROY_CHILD_META functions.
CREATING A CUSTOM CONTAINER ACTOR
- package MyContainer;
use Clutter;
use Glib::Object::Subclass - 'Clutter::Actor',
interfaces => [ qw( Clutter::Container ) ]; - Virtual Methods
- In order to create a Clutter::Container actor, an implementation of the following methods is required:
- ADD ($container, $actor)
o $container (Clutter::Container)
o $actor (Clutter::Actor)Called to add actor to container. The implementation should queue a relayout of container and emit the ::actor-added signal once the actor has been added.For instance:
push @{$self->{children}}, $actor;
$actor->set_parent($self);$self->queue_relayout();
$self->signal_emit('actor-added', $actor);REMOVE ($container, $actor)o $container (Clutter::Container)
o $actor (Clutter::Actor)Called to remove actor from container. The implementation should emit the ::actor-removed signal once the actor has been removed.RAISE ($container, $child, $$ssiibblliinngg)o $container (Clutter::Container)
o $child (Clutter::Actor)
o $sibling (Clutter::Actor)Called when raising child above sibling. If sibling is undefined, then child should be raised above every other child of container.LOWER ($container, $child, $$ssiibblliinngg)o $container (Clutter::Container)
o $child (Clutter::Actor)
o $sibling (Clutter::Actor)Called when lowering child below sibling. If sibling is undefined, then child should be lowered below every other child of container.SORT_DEPTH_ORDER ($container)o $container (Clutter::Container)Called when resorting the list of children depending on their
depth. - FOREACH ($container, $function, $$ddaattaa) FOREACH_WITH_INTERNALS ($container, $function, $$ddaattaa)
- o $container (Clutter::Container)
o $function (code reference)
o $data (scalar) data to pass to the function - Called when iterating over every child of container. For each child
the function must be called with the actor and the passed data, for
instance:
foreach my $child (@{$container->{children}}) {&$function ($child, $data);} - This function will also be called by the get_children method.
- The difference between FOREACH and FOREACH_WITH_INTERNALS is that
the latter should iterate over every child of the container,
including the actors that are internal to it -- that is, the actors that have not been added using the Clutter::Container API but that are direct responsability of the container itself. - If your container actor has no internal children, you can choose to implement only the FOREACH method.
- CREATE_CHILD_META ($container, $actor)
- o $container (Clutter::Container)
o $actor (Clutter::Actor) - Called when creating a new Clutter::ChildMeta instance wrapping
actor inside container. This function should be overridden only if the metadata class used to implement child properties needs special code or needs to be stored inside a different data structure within container. - For instance:
sub CREATE_CHILD_META {my ($self, $child) = @_;my $meta = My::ChildMeta->new(container => $self,
actor => $child,);# store the ChildMeta into a hash using the
# actor itself as the key
$self->{meta}->{$child} = $meta;} - When overriding the CREATE_CHILD_META, the GET_CHILD_META and the DESTROY_CHILD_META methods should be overridden as well.
- This function is called before Clutter::Container::ADD_ACTOR.
- DESTROY_CHILD_META ($container, $actor)
- o $container (Clutter::Container)
o $actor (Clutter::Actor) - Called when destroying a Clutter::ChildMeta instance for actor.
- For instance:
sub DESTROY_CHILD_META {my ($self, $child) = @_;delete $self->{meta}->{$child};} - This function is called before Clutter::Actor::REMOVE_ACTOR
- childmeta = GET_CHILD_META ($container, $actor)
- o $container (Clutter::Container)
o $actor (Clutter::Actor) - Called when retrieving a Clutter::ChildMeta instance for actor.
- For instance:
sub GET_CHILD_META {my ($self, $child) = @_;return $self->{meta}->{$child};}
SIGNALS
actor-added (Clutter::Container, Clutter::Actor) actor-removed (Clutter::Container, Clutter::Actor) child-notify (Clutter::Container, Clutter::Actor, Glib::ParamSpec)
SEE ALSO
Clutter, Glib::Interface
COPYRIGHT
Copyright (C) 2006, 2007, 2008 OpenedHand Ltd
Copyright (C) 2009 Intel Corporation
This module is free software; you can redistribute it and/or modify it
under the terms of either:
o the GNU Lesser General Public Library version 2.1; or
o the Artistic License, version 2.0.
- See Clutter for the full copyright notice.