From bd58694678fc2f6cdd6b6727677c8370ea62493b Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Sun, 18 Dec 2011 22:14:36 +0000 Subject: [PATCH] actor: Add replace_child() method A simple method that atomically replaces a child actor with another one. --- clutter/clutter-actor.c | 30 ++++++++++++++++++++++++++++++ clutter/clutter-actor.h | 3 +++ 2 files changed, 33 insertions(+) diff --git a/clutter/clutter-actor.c b/clutter/clutter-actor.c index 7643339af..f9e2487d8 100644 --- a/clutter/clutter-actor.c +++ b/clutter/clutter-actor.c @@ -10015,6 +10015,36 @@ clutter_actor_remove_child (ClutterActor *self, clutter_actor_remove_child_internal (self, child, TRUE, TRUE); } +/** + * clutter_actor_replace_child: + * @self: a #ClutterActor + * @old_child: the child of @self to replace + * @new_child: the #ClutterActor to replace @old_child + * + * Replaces @old_child with @new_child in the list of children of @self. + * + * Since: 1.10 + */ +void +clutter_actor_replace_child (ClutterActor *self, + ClutterActor *old_child, + ClutterActor *new_child) +{ + g_return_if_fail (CLUTTER_IS_ACTOR (self)); + g_return_if_fail (CLUTTER_IS_ACTOR (old_child)); + g_return_if_fail (old_child->priv->parent == self); + g_return_if_fail (CLUTTER_IS_ACTOR (new_child)); + g_return_if_fail (old_child != new_child); + g_return_if_fail (new_child != self); + g_return_if_fail (new_child->priv->parent == NULL); + + clutter_actor_add_child_internal (self, new_child, + insert_child_above, + old_child, + TRUE, TRUE); + clutter_actor_remove_child_internal (self, old_child, TRUE, TRUE); +} + /** * clutter_actor_unparent: * @self: a #ClutterActor diff --git a/clutter/clutter-actor.h b/clutter/clutter-actor.h index 54aadaa1d..feb1f6483 100644 --- a/clutter/clutter-actor.h +++ b/clutter/clutter-actor.h @@ -461,6 +461,9 @@ void clutter_actor_insert_child_above (ClutterActor void clutter_actor_insert_child_below (ClutterActor *self, ClutterActor *child, ClutterActor *sibling); +void clutter_actor_replace_child (ClutterActor *self, + ClutterActor *old_child, + ClutterActor *new_child); void clutter_actor_remove_child (ClutterActor *self, ClutterActor *child); GList * clutter_actor_get_children (ClutterActor *self);