css: Implement transitions for numbers of different units

We now can transition from 10px to 100%.

Note that this requires a teensy tiny hack in
gtk_css_value_transition(), but so be it.
This commit is contained in:
Benjamin Otte 2016-02-13 04:47:51 +01:00
parent 0cda3ba3e8
commit 93eec3e52f
5 changed files with 28 additions and 27 deletions

View File

@ -150,15 +150,6 @@ gtk_css_value_calc_equal (const GtkCssValue *value1,
return TRUE;
}
static GtkCssValue *
gtk_css_value_calc_transition (GtkCssValue *start,
GtkCssValue *end,
guint property_id,
double progress)
{
return NULL;
}
static void
gtk_css_value_calc_print (const GtkCssValue *value,
GString *string)
@ -257,7 +248,7 @@ static const GtkCssNumberValueClass GTK_CSS_VALUE_CALC = {
gtk_css_value_calc_free,
gtk_css_value_calc_compute,
gtk_css_value_calc_equal,
gtk_css_value_calc_transition,
gtk_css_number_value_transition,
gtk_css_value_calc_print
},
gtk_css_value_calc_get,

View File

@ -167,21 +167,6 @@ gtk_css_value_dimension_equal (const GtkCssValue *number1,
number1->value == number2->value;
}
static GtkCssValue *
gtk_css_value_dimension_transition (GtkCssValue *start,
GtkCssValue *end,
guint property_id,
double progress)
{
/* FIXME: This needs to be supported at least for percentages,
* but for that we kinda need to support calc(5px + 50%) */
if (start->unit != end->unit)
return NULL;
return gtk_css_dimension_value_new (start->value + (end->value - start->value) * progress,
start->unit);
}
static void
gtk_css_value_dimension_print (const GtkCssValue *number,
GString *string)
@ -290,7 +275,7 @@ static const GtkCssNumberValueClass GTK_CSS_VALUE_DIMENSION = {
gtk_css_value_dimension_free,
gtk_css_value_dimension_compute,
gtk_css_value_dimension_equal,
gtk_css_value_dimension_transition,
gtk_css_number_value_transition,
gtk_css_value_dimension_print
},
gtk_css_value_dimension_get,

View File

@ -106,6 +106,25 @@ _gtk_css_number_value_new (double value,
return gtk_css_dimension_value_new (value, unit);
}
GtkCssValue *
gtk_css_number_value_transition (GtkCssValue *start,
GtkCssValue *end,
guint property_id,
double progress)
{
GtkCssValue *result, *mul_start, *mul_end;
mul_start = gtk_css_number_value_multiply (start, 1 - progress);
mul_end = gtk_css_number_value_multiply (end, progress);
result = gtk_css_number_value_add (mul_start, mul_end);
_gtk_css_value_unref (mul_start);
_gtk_css_value_unref (mul_end);
return result;
}
gboolean
gtk_css_number_value_can_parse (GtkCssParser *parser)
{

View File

@ -54,6 +54,10 @@ struct _GtkCssNumberValueClass {
GtkCssValue * _gtk_css_number_value_new (double value,
GtkCssUnit unit);
GtkCssValue * gtk_css_number_value_transition (GtkCssValue *start,
GtkCssValue *end,
guint property_id,
double progress);
gboolean gtk_css_number_value_can_parse (GtkCssParser *parser);
GtkCssValue * _gtk_css_number_value_parse (GtkCssParser *parser,
GtkCssNumberParseFlags flags);

View File

@ -136,7 +136,9 @@ _gtk_css_value_transition (GtkCssValue *start,
gtk_internal_return_val_if_fail (start != NULL, FALSE);
gtk_internal_return_val_if_fail (end != NULL, FALSE);
if (start->class != end->class)
/* We compare functions here instead of classes so that number
* values can all transition to each other */
if (start->class->transition != end->class->transition)
return NULL;
return start->class->transition (start, end, property_id, progress);