test-text-field: Clean up

Use a Table layout manager, and clean up a bit this test case.
This commit is contained in:
Emmanuele Bassi 2010-12-20 17:59:35 +00:00
parent 21a12b966d
commit ec5e910cd3

View File

@ -14,8 +14,15 @@ on_entry_paint (ClutterActor *actor,
clutter_actor_box_get_size (&allocation, &width, &height); clutter_actor_box_get_size (&allocation, &width, &height);
cogl_set_source_color4ub (255, 255, 255, 24); cogl_set_source_color4ub (255, 255, 255, 24);
#if 0
/* this spills over to the next actor in the paint cycle, and retains
* the same source color
*/
cogl_path_round_rectangle (0, 0, width, height, 4.0, 1.0); cogl_path_round_rectangle (0, 0, width, height, 4.0, 1.0);
cogl_path_stroke (); cogl_path_stroke ();
#else
cogl_rectangle (0, 0, width, height);
#endif
} }
static void static void
@ -213,8 +220,6 @@ create_label (const ClutterColor *color,
{ {
ClutterActor *retval = clutter_text_new (); ClutterActor *retval = clutter_text_new ();
clutter_actor_set_width (retval, 200);
clutter_text_set_color (CLUTTER_TEXT (retval), color); clutter_text_set_color (CLUTTER_TEXT (retval), color);
clutter_text_set_markup (CLUTTER_TEXT (retval), text); clutter_text_set_markup (CLUTTER_TEXT (retval), text);
clutter_text_set_editable (CLUTTER_TEXT (retval), FALSE); clutter_text_set_editable (CLUTTER_TEXT (retval), FALSE);
@ -234,7 +239,6 @@ create_entry (const ClutterColor *color,
ClutterActor *retval = clutter_text_new_full (NULL, text, color); ClutterActor *retval = clutter_text_new_full (NULL, text, color);
ClutterColor selection = { 0, }; ClutterColor selection = { 0, };
clutter_actor_set_width (retval, 200);
clutter_actor_set_reactive (retval, TRUE); clutter_actor_set_reactive (retval, TRUE);
clutter_color_darken (color, &selection); clutter_color_darken (color, &selection);
@ -265,49 +269,61 @@ test_text_field_main (gint argc,
gchar **argv) gchar **argv)
{ {
ClutterActor *stage; ClutterActor *stage;
ClutterActor *text; ClutterActor *box;
ClutterColor entry_color = {0x33, 0xff, 0x33, 0xff}; ClutterLayoutManager *table;
ClutterColor label_color = {0xff, 0xff, 0xff, 0xff};
ClutterColor background_color = {0x00, 0x00, 0x00, 0xff};
ClutterUnits h_padding, v_padding;
gfloat width, height;
clutter_init (&argc, &argv); clutter_init (&argc, &argv);
stage = clutter_stage_get_default (); stage = clutter_stage_new ();
clutter_stage_set_color (CLUTTER_STAGE (stage), &background_color); clutter_stage_set_title (CLUTTER_STAGE (stage), "Text Fields");
clutter_stage_set_color (CLUTTER_STAGE (stage), CLUTTER_COLOR_Black);
g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
clutter_units_em_for_font (&h_padding, NULL, 2.0); /* 2em */ table = clutter_table_layout_new ();
clutter_units_em_for_font (&v_padding, NULL, 3.0); /* 3em */ clutter_table_layout_set_column_spacing (CLUTTER_TABLE_LAYOUT (table), 6);
clutter_table_layout_set_row_spacing (CLUTTER_TABLE_LAYOUT (table), 6);
g_print ("padding: h:%.2f px, v:%.2f px\n", box = clutter_box_new (table);
clutter_units_to_pixels (&h_padding), clutter_container_add_actor (CLUTTER_CONTAINER (stage), box);
clutter_units_to_pixels (&v_padding)); clutter_actor_add_constraint (box, clutter_bind_constraint_new (stage, CLUTTER_BIND_WIDTH, -24.0));
clutter_actor_add_constraint (box, clutter_bind_constraint_new (stage, CLUTTER_BIND_HEIGHT, -24.0));
clutter_actor_set_position (box, 12, 12);
text = create_label (&label_color, "<b>Input field:</b> "); clutter_box_pack (CLUTTER_BOX (box),
clutter_actor_set_position (text, 10, 10); create_label (CLUTTER_COLOR_White, "<b>Input field:</b>"),
clutter_container_add_actor (CLUTTER_CONTAINER (stage), text); "row", 0,
"column", 0,
"x-expand", TRUE,
"x-align", CLUTTER_TABLE_ALIGNMENT_END,
"y-expand", FALSE,
NULL);
width = clutter_actor_get_width (text); clutter_box_pack (CLUTTER_BOX (box),
height = clutter_actor_get_height (text); create_entry (CLUTTER_COLOR_LightGray, "<i>some</i> text", 0, 0),
"row", 0,
"column", 1,
"x-expand", TRUE,
"x-fill", TRUE,
"y-expand", FALSE,
NULL);
text = create_entry (&entry_color, "<i>some</i> text", 0, 0); clutter_box_pack (CLUTTER_BOX (box),
clutter_actor_set_position (text, create_label (CLUTTER_COLOR_White, "<b>A very long password field:</b>"),
width + 10 + clutter_units_to_pixels (&h_padding), "row", 1,
10); "column", 0,
clutter_container_add_actor (CLUTTER_CONTAINER (stage), text); "x-expand", TRUE,
"x-align", CLUTTER_TABLE_ALIGNMENT_END,
"y-expand", FALSE,
NULL);
text = create_label (&label_color, "<i>A very long password field</i>: "); clutter_box_pack (CLUTTER_BOX (box),
clutter_actor_set_position (text, create_entry (CLUTTER_COLOR_LightGray, "password", '*', 8),
10, "row", 1,
height + 10 + clutter_units_to_pixels (&v_padding)); "column", 1,
clutter_container_add_actor (CLUTTER_CONTAINER (stage), text); "x-expand", TRUE,
"x-fill", TRUE,
text = create_entry (&entry_color, "password", '*', 8); "y-expand", FALSE,
clutter_actor_set_position (text, NULL);
width + 10 + clutter_units_to_pixels (&h_padding),
height + 10 + clutter_units_to_pixels (&v_padding));
clutter_container_add_actor (CLUTTER_CONTAINER (stage), text);
clutter_actor_show (stage); clutter_actor_show (stage);