[units] Add binding-friendly initializers

We should follow the convention for boxed types initializers of:

  <type_name>_from_<another_type> (boxed, value)

For ClutterUnits as well; so:

  clutter_units_pixels -> clutter_units_from_pixels
  clutter_units_em     -> clutter_units_from_em
  ...

We should still keep the short-hand version as a macro, though.
This commit is contained in:
Emmanuele Bassi 2009-07-28 13:43:52 +01:00
parent 57baa2f0bc
commit a5d6b23308
4 changed files with 59 additions and 47 deletions

View File

@ -132,7 +132,7 @@ units_em_to_pixels (const gchar *font_name,
}
/**
* clutter_units_mm:
* clutter_units_from_mm:
* @units: a #ClutterUnits
* @mm: millimeters
*
@ -141,8 +141,8 @@ units_em_to_pixels (const gchar *font_name,
* Since: 1.0
*/
void
clutter_units_mm (ClutterUnits *units,
gfloat mm)
clutter_units_from_mm (ClutterUnits *units,
gfloat mm)
{
g_return_if_fail (units != NULL);
@ -153,7 +153,7 @@ clutter_units_mm (ClutterUnits *units,
}
/**
* clutter_units_pt:
* clutter_units_from_pt:
* @units: a #ClutterUnits
* @pt: typographic points
*
@ -162,8 +162,8 @@ clutter_units_mm (ClutterUnits *units,
* Since: 1.0
*/
void
clutter_units_pt (ClutterUnits *units,
gfloat pt)
clutter_units_from_pt (ClutterUnits *units,
gfloat pt)
{
g_return_if_fail (units != NULL);
@ -174,7 +174,7 @@ clutter_units_pt (ClutterUnits *units,
}
/**
* clutter_units_em:
* clutter_units_from_em:
* @units: a #ClutterUnits
* @em: em
*
@ -184,8 +184,8 @@ clutter_units_pt (ClutterUnits *units,
* Since: 1.0
*/
void
clutter_units_em (ClutterUnits *units,
gfloat em)
clutter_units_from_em (ClutterUnits *units,
gfloat em)
{
g_return_if_fail (units != NULL);
@ -196,7 +196,7 @@ clutter_units_em (ClutterUnits *units,
}
/**
* clutter_units_em_for_font:
* clutter_units_from_em_for_font:
* @units: a #ClutterUnits
* @font_name: the font name and size
* @em: em
@ -206,9 +206,9 @@ clutter_units_em (ClutterUnits *units,
* Since: 1.0
*/
void
clutter_units_em_for_font (ClutterUnits *units,
const gchar *font_name,
gfloat em)
clutter_units_from_em_for_font (ClutterUnits *units,
const gchar *font_name,
gfloat em)
{
g_return_if_fail (units != NULL);
@ -219,7 +219,7 @@ clutter_units_em_for_font (ClutterUnits *units,
}
/**
* clutter_units_pixels:
* clutter_units_from_pixels:
* @units: a #ClutterUnits
* @px: pixels
*
@ -228,8 +228,8 @@ clutter_units_em_for_font (ClutterUnits *units,
* Since: 1.0
*/
void
clutter_units_pixels (ClutterUnits *units,
gint px)
clutter_units_from_pixels (ClutterUnits *units,
gint px)
{
g_return_if_fail (units != NULL);
@ -550,7 +550,7 @@ static void
clutter_value_transform_int_units (const GValue *src,
GValue *dest)
{
clutter_units_pixels (dest->data[0].v_pointer, src->data[0].v_int);
clutter_units_from_pixels (dest->data[0].v_pointer, src->data[0].v_int);
}
/* units to float */
@ -566,7 +566,7 @@ static void
clutter_value_transform_float_units (const GValue *src,
GValue *dest)
{
clutter_units_pixels (dest->data[0].v_pointer, src->data[0].v_float);
clutter_units_from_pixels (dest->data[0].v_pointer, src->data[0].v_float);
}
/* units to string */

View File

@ -83,30 +83,37 @@ struct _ClutterUnits
gint64 __padding_2;
};
GType clutter_units_get_type (void) G_GNUC_CONST;
ClutterUnitType clutter_units_get_unit_type (const ClutterUnits *units);
gfloat clutter_units_get_unit_value (const ClutterUnits *units);
GType clutter_units_get_type (void) G_GNUC_CONST;
ClutterUnitType clutter_units_get_unit_type (const ClutterUnits *units);
gfloat clutter_units_get_unit_value (const ClutterUnits *units);
ClutterUnits * clutter_units_copy (const ClutterUnits *units);
void clutter_units_free (ClutterUnits *units);
ClutterUnits * clutter_units_copy (const ClutterUnits *units);
void clutter_units_free (ClutterUnits *units);
void clutter_units_pixels (ClutterUnits *units,
gint px);
void clutter_units_em (ClutterUnits *units,
gfloat em);
void clutter_units_em_for_font (ClutterUnits *units,
const gchar *font_name,
gfloat em);
void clutter_units_mm (ClutterUnits *units,
gfloat mm);
void clutter_units_pt (ClutterUnits *units,
gfloat pt);
void clutter_units_from_pixels (ClutterUnits *units,
gint px);
void clutter_units_from_em (ClutterUnits *units,
gfloat em);
void clutter_units_from_em_for_font (ClutterUnits *units,
const gchar *font_name,
gfloat em);
void clutter_units_from_mm (ClutterUnits *units,
gfloat mm);
void clutter_units_from_pt (ClutterUnits *units,
gfloat pt);
gfloat clutter_units_to_pixels (ClutterUnits *units);
gfloat clutter_units_to_pixels (ClutterUnits *units);
gchar * clutter_units_to_string (const ClutterUnits *units);
gboolean clutter_units_from_string (ClutterUnits *units,
const gchar *str);
gboolean clutter_units_from_string (ClutterUnits *units,
const gchar *str);
gchar * clutter_units_to_string (const ClutterUnits *units);
/* shorthands for the constructors */
#define clutter_units_pixels clutter_units_from_pixels
#define clutter_units_em clutter_units_from_em
#define clutter_units_em_for_font clutter_units_from_em_for_font
#define clutter_units_mm clutter_units_from_mm
#define clutter_units_pt clutter_units_from_pt
#define CLUTTER_TYPE_UNITS (clutter_units_get_type ())
#define CLUTTER_TYPE_PARAM_UNITS (clutter_param_units_get_type ())

View File

@ -29,11 +29,11 @@ clutter_media_get_type
<TITLE>Unit conversion</TITLE>
ClutterUnitType
ClutterUnits
clutter_units_mm
clutter_units_pt
clutter_units_em
clutter_units_em_for_font
clutter_units_pixels
clutter_units_from_mm
clutter_units_from_pt
clutter_units_from_em
clutter_units_from_em_for_font
clutter_units_from_pixels
clutter_units_to_pixels
clutter_units_copy
clutter_units_free
@ -56,6 +56,11 @@ CLUTTER_PARAM_SPEC_UNITS
CLUTTER_IS_PARAM_SPEC_UNITS
clutter_units_get_type
clutter_param_units_get_type
clutter_units_em
clutter_units_em_for_font
clutter_units_mm
clutter_units_pixels
clutter_units_pt
</SECTION>
<SECTION>

View File

@ -9,12 +9,12 @@ test_units_constructors (TestConformSimpleFixture *fixture,
{
ClutterUnits units;
clutter_units_pixels (&units, 100);
clutter_units_from_pixels (&units, 100);
g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_PIXEL);
g_assert_cmpfloat (clutter_units_get_unit_value (&units), ==, 100.0);
g_assert_cmpfloat (clutter_units_to_pixels (&units), ==, 100.0);
clutter_units_em (&units, 5.0);
clutter_units_from_em (&units, 5.0);
g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_EM);
g_assert_cmpfloat (clutter_units_get_unit_value (&units), ==, 5.0);
g_assert_cmpfloat (clutter_units_to_pixels (&units), !=, 5.0);
@ -37,12 +37,12 @@ test_units_string (TestConformSimpleFixture *fixture,
g_assert (clutter_units_from_string (&units, "1 pony") == FALSE);
clutter_units_pt (&units, 24.0);
clutter_units_from_pt (&units, 24.0);
string = clutter_units_to_string (&units);
g_assert_cmpstr (string, ==, "24.0 pt");
g_free (string);
clutter_units_em (&units, 3.0);
clutter_units_from_em (&units, 3.0);
string = clutter_units_to_string (&units);
g_assert_cmpstr (string, ==, "3.00 em");