actor: Make Actor.add_child and Container.add_actor idempotent

And make sure that overriding Container and calling
clutter_actor_add_child() will result in the same sequence of operations
as the current set_parent()+queue_relayout()+signal_emit pattern.

Existing containers can continue using:

        clutter_actor_set_parent (child, CLUTTER_ACTOR (container));
        clutter_actor_queue_relayout (CLUTTER_ACTOR (container));
        g_signal_emit_by_name (container, "actor-added", child);

and newly written containers overriding Container.add() can simply call:

        clutter_actor_add_child (CLUTTER_ACTOR (container), child);

instead.
This commit is contained in:
Emmanuele Bassi
2011-12-02 11:51:15 +00:00
committed by Emmanuele Bassi
parent 2894587b22
commit ef3dc2d1ba
2 changed files with 100 additions and 44 deletions

View File

@ -218,17 +218,17 @@ basic_layout (TestConformSimpleFixture *fixture,
flower[0] = clutter_rectangle_new_with_color (CLUTTER_COLOR_Red);
clutter_actor_set_size (flower[0], 100, 100);
clutter_actor_set_name (flower[0], "Red Flower");
clutter_container_add_actor (CLUTTER_CONTAINER (vase), flower[0]);
clutter_actor_add_child (vase, flower[0]);
flower[1] = clutter_rectangle_new_with_color (CLUTTER_COLOR_Yellow);
clutter_actor_set_size (flower[1], 100, 100);
clutter_actor_set_name (flower[1], "Yellow Flower");
clutter_container_add_actor (CLUTTER_CONTAINER (vase), flower[1]);
clutter_actor_add_child (vase, flower[1]);
flower[2] = clutter_rectangle_new_with_color (CLUTTER_COLOR_Green);
clutter_actor_set_size (flower[2], 100, 100);
clutter_actor_set_name (flower[2], "Green Flower");
clutter_container_add_actor (CLUTTER_CONTAINER (vase), flower[2]);
clutter_actor_add_child (vase, flower[2]);
clutter_actor_show_all (stage);
@ -258,21 +258,21 @@ margin_layout (TestConformSimpleFixture *fixture,
flower[0] = clutter_rectangle_new_with_color (CLUTTER_COLOR_Red);
clutter_actor_set_size (flower[0], 100, 100);
clutter_actor_set_name (flower[0], "Red Flower");
clutter_container_add_actor (CLUTTER_CONTAINER (vase), flower[0]);
clutter_actor_add_child (vase, flower[0]);
flower[1] = clutter_rectangle_new_with_color (CLUTTER_COLOR_Yellow);
clutter_actor_set_size (flower[1], 100, 100);
clutter_actor_set_name (flower[1], "Yellow Flower");
clutter_actor_set_margin_right (flower[1], 6);
clutter_actor_set_margin_left (flower[1], 6);
clutter_container_add_actor (CLUTTER_CONTAINER (vase), flower[1]);
clutter_actor_add_child (vase, flower[1]);
flower[2] = clutter_rectangle_new_with_color (CLUTTER_COLOR_Green);
clutter_actor_set_size (flower[2], 100, 100);
clutter_actor_set_name (flower[2], "Green Flower");
clutter_actor_set_margin_top (flower[2], 6);
clutter_actor_set_margin_bottom (flower[2], 6);
clutter_container_add_actor (CLUTTER_CONTAINER (vase), flower[2]);
clutter_actor_add_child (vase, flower[2]);
clutter_actor_show_all (stage);