1 #include <stdlib.h>
2 #include <clutter/clutter.h>
3
4 int
main(int argc,char * argv[])5 main (int argc, char *argv[])
6 {
7 ClutterActor *stage, *layer_a, *layer_b, *layer_c;
8
9 if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
10 return 1;
11
12 /* the main container */
13 stage = clutter_stage_new ();
14 clutter_actor_set_name (stage, "stage");
15 clutter_stage_set_title (CLUTTER_STAGE (stage), "Snap Constraint");
16 clutter_actor_set_background_color (stage, CLUTTER_COLOR_Aluminium1);
17 clutter_stage_set_user_resizable (CLUTTER_STAGE (stage), TRUE);
18 g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
19
20 /* first layer, with a fixed (100, 25) size */
21 layer_a = clutter_actor_new ();
22 clutter_actor_set_background_color (layer_a, CLUTTER_COLOR_ScarletRed);
23 clutter_actor_set_name (layer_a, "layerA");
24 clutter_actor_set_size (layer_a, 100.0, 25.0);
25 clutter_actor_add_child (stage, layer_a);
26
27 /* the first layer is anchored to the middle of the stage */
28 clutter_actor_add_constraint (layer_a, clutter_align_constraint_new (stage, CLUTTER_ALIGN_BOTH, 0.5));
29
30 /* second layer, with no implicit size */
31 layer_b = clutter_actor_new ();
32 clutter_actor_set_background_color (layer_b, CLUTTER_COLOR_DarkButter);
33 clutter_actor_set_name (layer_b, "layerB");
34 clutter_actor_add_child (stage, layer_b);
35
36 /* the second layer tracks the X coordinate and the width of
37 * the first layer
38 */
39 clutter_actor_add_constraint (layer_b, clutter_bind_constraint_new (layer_a, CLUTTER_BIND_X, 0.0));
40 clutter_actor_add_constraint (layer_b, clutter_bind_constraint_new (layer_a, CLUTTER_BIND_WIDTH, 0.0));
41
42 /* the second layer is snapped between the bottom edge of
43 * the first layer, and the bottom edge of the stage; a
44 * spacing of 10 pixels in each direction is added for padding
45 */
46 clutter_actor_add_constraint (layer_b,
47 clutter_snap_constraint_new (layer_a,
48 CLUTTER_SNAP_EDGE_TOP,
49 CLUTTER_SNAP_EDGE_BOTTOM,
50 10.0));
51
52 clutter_actor_add_constraint (layer_b,
53 clutter_snap_constraint_new (stage,
54 CLUTTER_SNAP_EDGE_BOTTOM,
55 CLUTTER_SNAP_EDGE_BOTTOM,
56 -10.0));
57
58 /* the third layer, with no implicit size */
59 layer_c = clutter_actor_new ();
60 clutter_actor_set_background_color (layer_c, CLUTTER_COLOR_LightChameleon);
61 clutter_actor_set_name (layer_c, "layerC");
62 clutter_actor_add_child (stage, layer_c);
63
64 /* as for the second layer, the third layer tracks the X
65 * coordinate and width of the first layer
66 */
67 clutter_actor_add_constraint (layer_c, clutter_bind_constraint_new (layer_a, CLUTTER_BIND_X, 0.0));
68 clutter_actor_add_constraint (layer_c, clutter_bind_constraint_new (layer_a, CLUTTER_BIND_WIDTH, 0.0));
69
70 /* the third layer is snapped between the top edge of the stage
71 * and the top edge of the first layer; again, a spacing of
72 * 10 pixels in each direction is added for padding
73 */
74 clutter_actor_add_constraint (layer_c,
75 clutter_snap_constraint_new (layer_a,
76 CLUTTER_SNAP_EDGE_BOTTOM,
77 CLUTTER_SNAP_EDGE_TOP,
78 -10.0));
79 clutter_actor_add_constraint (layer_c,
80 clutter_snap_constraint_new (stage,
81 CLUTTER_SNAP_EDGE_TOP,
82 CLUTTER_SNAP_EDGE_TOP,
83 10.0));
84
85 clutter_actor_show (stage);
86
87 clutter_main ();
88
89 return EXIT_SUCCESS;
90 }
91