[layout, tests] Use variants for child packing in Box

There are three potential variants to add a child inside a Box
with a BinLayout:

  - clutter_box_pack(), a variadic argument function which
    allows passing arbitrary LayoutMeta properties and values;

  - clutter_bin_layout_add(), which uses the backpointer to
    the container from the LayoutManager and sets the layout
    properties directly without GValue (de)marshalling

  - clutter_container_add_actor() and
    clutter_bin_layout_set_alignment(), similar to the
    clutter_bin_layout_add() function above, but split in two

The test-box interactive test should exercise all three variants.
This commit is contained in:
Emmanuele Bassi 2009-09-16 15:55:30 +01:00
parent 431a63d04a
commit 8b2088a917

View File

@ -117,10 +117,13 @@ test_box_main (int argc, char *argv[])
clutter_actor_set_name (box, "box"); clutter_actor_set_name (box, "box");
rect = make_background (&bg_color, 200, 200); rect = make_background (&bg_color, 200, 200);
/* first method: use clutter_box_pack() */
clutter_box_pack (CLUTTER_BOX (box), rect, clutter_box_pack (CLUTTER_BOX (box), rect,
"x-align", CLUTTER_BIN_ALIGNMENT_FILL, "x-align", CLUTTER_BIN_ALIGNMENT_FILL,
"y-align", CLUTTER_BIN_ALIGNMENT_FILL, "y-align", CLUTTER_BIN_ALIGNMENT_FILL,
NULL); NULL);
clutter_actor_lower_bottom (rect); clutter_actor_lower_bottom (rect);
clutter_actor_set_name (rect, "background"); clutter_actor_set_name (rect, "background");
@ -135,10 +138,12 @@ test_box_main (int argc, char *argv[])
g_error ("Unable to create texture: %s", error->message); g_error ("Unable to create texture: %s", error->message);
clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (tex), TRUE); clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (tex), TRUE);
clutter_box_pack (CLUTTER_BOX (box), tex,
"x-align", CLUTTER_BIN_ALIGNMENT_CENTER, /* second method: use clutter_bin_layout_add() */
"y-align", CLUTTER_BIN_ALIGNMENT_CENTER, clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (layout), tex,
NULL); CLUTTER_BIN_ALIGNMENT_CENTER,
CLUTTER_BIN_ALIGNMENT_CENTER);
clutter_actor_raise (tex, rect); clutter_actor_raise (tex, rect);
clutter_actor_set_width (tex, 175); clutter_actor_set_width (tex, 175);
clutter_actor_set_name (tex, "texture"); clutter_actor_set_name (tex, "texture");
@ -150,10 +155,13 @@ test_box_main (int argc, char *argv[])
224); 224);
rect = clutter_rectangle_new_with_color (color); rect = clutter_rectangle_new_with_color (color);
clutter_box_pack (CLUTTER_BOX (box), rect,
"x-align", CLUTTER_BIN_ALIGNMENT_END, /* third method: container_add() and set_alignment() */
"y-align", CLUTTER_BIN_ALIGNMENT_END, clutter_container_add_actor (CLUTTER_CONTAINER (box), rect);
NULL); clutter_bin_layout_set_alignment (CLUTTER_BIN_LAYOUT (layout), rect,
CLUTTER_BIN_ALIGNMENT_END,
CLUTTER_BIN_ALIGNMENT_END);
clutter_actor_set_size (rect, 50, 50); clutter_actor_set_size (rect, 50, 50);
clutter_actor_set_opacity (rect, 0); clutter_actor_set_opacity (rect, 0);
clutter_actor_raise_top (rect); clutter_actor_raise_top (rect);