mirror of
https://github.com/brl/mutter.git
synced 2024-12-27 13:22:15 +00:00
[units] Validate units against the ParamSpec
When declaring a property using ClutterParamSpecUnits we pass a default type to limit the type of units we accept as valid values for the property. This means that we need to add the unit type check as part of the validation process.
This commit is contained in:
parent
5ebb59e6b0
commit
876dc22633
@ -447,6 +447,29 @@ clutter_units_from_string (ClutterUnits *units,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static const gchar *
|
||||
clutter_unit_type_name (ClutterUnitType unit_type)
|
||||
{
|
||||
switch (unit_type)
|
||||
{
|
||||
case CLUTTER_UNIT_MM:
|
||||
return "mm";
|
||||
|
||||
case CLUTTER_UNIT_POINT:
|
||||
return "pt";
|
||||
|
||||
case CLUTTER_UNIT_EM:
|
||||
return "em";
|
||||
|
||||
case CLUTTER_UNIT_PIXEL:
|
||||
return "px";
|
||||
}
|
||||
|
||||
g_warning ("Invalid unit type %d", (int) unit_type);
|
||||
|
||||
return "<invalid>";
|
||||
}
|
||||
|
||||
/**
|
||||
* clutter_units_to_string:
|
||||
* @units: a #ClutterUnits
|
||||
@ -653,10 +676,25 @@ param_units_validate (GParamSpec *pspec,
|
||||
{
|
||||
ClutterParamSpecUnits *uspec = CLUTTER_PARAM_SPEC_UNITS (pspec);
|
||||
ClutterUnits *units = value->data[0].v_pointer;
|
||||
ClutterUnitType otype = units->unit_type;
|
||||
gfloat oval = units->value;
|
||||
|
||||
g_assert (CLUTTER_IS_PARAM_SPEC_UNITS (pspec));
|
||||
|
||||
if (otype != uspec->default_type)
|
||||
{
|
||||
gchar *str = clutter_units_to_string (units);
|
||||
|
||||
g_warning ("The units value of '%s' does not have the same unit "
|
||||
"type as declared by the ClutterParamSpecUnits of '%s'",
|
||||
str,
|
||||
clutter_unit_type_name (otype));
|
||||
|
||||
g_free (str);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
units->value = CLAMP (units->value,
|
||||
uspec->minimum,
|
||||
uspec->maximum);
|
||||
|
Loading…
Reference in New Issue
Block a user