[units] Rework Units into logical distance value

Units as they have been implemented since Clutter 0.4 have always been
misdefined as "logical distance unit", while they were just pixels with
fractionary bits.

Units should be reworked to be opaque structures to hold a value and
its unit type, that can be then converted into pixels when Clutter needs
to paint or compute size requisitions and perform allocations.

The previous API should be completely removed to avoid collisions, and
a new type:

        ClutterUnits

should be added; the ability to install GObject properties using
ClutterUnits should be maintained.
This commit is contained in:
Emmanuele Bassi
2009-06-03 11:12:09 +01:00
parent 1580ffb884
commit 0d5e17ecd1
9 changed files with 714 additions and 593 deletions

View File

@@ -90,18 +90,20 @@ test_text_field_main (gint argc,
ClutterColor entry_color = {0x33, 0xff, 0x33, 0xff};
ClutterColor label_color = {0xff, 0xff, 0xff, 0xff};
ClutterColor background_color = {0x00, 0x00, 0x00, 0xff};
ClutterUnits h_padding, v_padding;
gfloat width, height;
gfloat h_padding, v_padding;
clutter_init (&argc, &argv);
stage = clutter_stage_get_default ();
clutter_stage_set_color (CLUTTER_STAGE (stage), &background_color);
h_padding = clutter_units_em_for_font (FONT, 2.0); /* 2em */
v_padding = clutter_units_em_for_font (FONT, 3.0); /* 3em */
clutter_units_em_for_font (&h_padding, FONT, 2.0); /* 2em */
clutter_units_em_for_font (&v_padding, FONT, 3.0); /* 3em */
g_print ("padding: h:%.2f px, v:%.2f px\n", h_padding, v_padding);
g_print ("padding: h:%.2f px, v:%.2f px\n",
clutter_units_to_pixels (&h_padding),
clutter_units_to_pixels (&v_padding));
text = create_label (&label_color, "<b>Input field:</b> ");
clutter_actor_set_position (text, 10, 10);
@@ -111,17 +113,21 @@ test_text_field_main (gint argc,
height = clutter_actor_get_height (text);
text = create_entry (&entry_color, "<i>some</i> text", 0, 0);
clutter_actor_set_position (text, 10 + width + h_padding, 10);
clutter_actor_set_position (text,
width + 10 + clutter_units_to_pixels (&h_padding),
10);
clutter_container_add_actor (CLUTTER_CONTAINER (stage), text);
text = create_label (&label_color, "<i>A very long password field</i>: ");
clutter_actor_set_position (text, 10, height + v_padding);
clutter_actor_set_position (text,
10,
height + 10 + clutter_units_to_pixels (&v_padding));
clutter_container_add_actor (CLUTTER_CONTAINER (stage), text);
text = create_entry (&entry_color, "password", '*', 8);
clutter_actor_set_position (text,
width + 10 + h_padding,
height + 10 + v_padding);
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);