css: Introduce the idea of dynamic values

Dynamic values are values that change their contents with the current
(monotonic) time.

This just introduces the GtkCssValue API for it.
This commit is contained in:
Benjamin Otte 2018-02-13 05:55:33 +01:00
parent 7f0ef81e11
commit 3322599e99
28 changed files with 154 additions and 4 deletions

View File

@ -323,6 +323,8 @@ static const GtkCssValueClass GTK_CSS_VALUE_ARRAY = {
gtk_css_value_array_compute,
gtk_css_value_array_equal,
gtk_css_value_array_transition,
NULL,
NULL,
gtk_css_value_array_print
};

View File

@ -157,6 +157,8 @@ static const GtkCssValueClass GTK_CSS_VALUE_BG_SIZE = {
gtk_css_value_bg_size_compute,
gtk_css_value_bg_size_equal,
gtk_css_value_bg_size_transition,
NULL,
NULL,
gtk_css_value_bg_size_print
};

View File

@ -144,6 +144,8 @@ static const GtkCssValueClass GTK_CSS_VALUE_BORDER = {
gtk_css_value_border_compute,
gtk_css_value_border_equal,
gtk_css_value_border_transition,
NULL,
NULL,
gtk_css_value_border_print
};

View File

@ -249,6 +249,8 @@ static const GtkCssNumberValueClass GTK_CSS_VALUE_CALC = {
gtk_css_value_calc_compute,
gtk_css_value_calc_equal,
gtk_css_number_value_transition,
NULL,
NULL,
gtk_css_value_calc_print
},
gtk_css_value_calc_get,

View File

@ -449,6 +449,8 @@ static const GtkCssValueClass GTK_CSS_VALUE_COLOR = {
gtk_css_value_color_compute,
gtk_css_value_color_equal,
gtk_css_value_color_transition,
NULL,
NULL,
gtk_css_value_color_print
};

View File

@ -103,6 +103,8 @@ static const GtkCssValueClass GTK_CSS_VALUE_CORNER = {
gtk_css_value_corner_compute,
gtk_css_value_corner_equal,
gtk_css_value_corner_transition,
NULL,
NULL,
gtk_css_value_corner_print
};

View File

@ -276,6 +276,8 @@ static const GtkCssNumberValueClass GTK_CSS_VALUE_DIMENSION = {
gtk_css_value_dimension_compute,
gtk_css_value_dimension_equal,
gtk_css_number_value_transition,
NULL,
NULL,
gtk_css_value_dimension_print
},
gtk_css_value_dimension_get,

View File

@ -139,6 +139,8 @@ static const GtkCssValueClass GTK_CSS_VALUE_EASE = {
gtk_css_value_ease_compute,
gtk_css_value_ease_equal,
gtk_css_value_ease_transition,
NULL,
NULL,
gtk_css_value_ease_print
};

View File

@ -82,6 +82,8 @@ static const GtkCssValueClass GTK_CSS_VALUE_BORDER_STYLE = {
gtk_css_value_enum_compute,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
NULL,
NULL,
gtk_css_value_enum_print
};
@ -137,6 +139,8 @@ static const GtkCssValueClass GTK_CSS_VALUE_BLEND_MODE = {
gtk_css_value_enum_compute,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
NULL,
NULL,
gtk_css_value_enum_print
};
@ -285,6 +289,8 @@ static const GtkCssValueClass GTK_CSS_VALUE_FONT_SIZE = {
gtk_css_value_font_size_compute,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
NULL,
NULL,
gtk_css_value_enum_print
};
@ -339,6 +345,8 @@ static const GtkCssValueClass GTK_CSS_VALUE_FONT_STYLE = {
gtk_css_value_enum_compute,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
NULL,
NULL,
gtk_css_value_enum_print
};
@ -451,6 +459,8 @@ static const GtkCssValueClass GTK_CSS_VALUE_FONT_WEIGHT = {
gtk_css_value_font_weight_compute,
gtk_css_value_enum_equal,
gtk_css_value_font_weight_transition,
NULL,
NULL,
gtk_css_value_enum_print
};
@ -524,6 +534,8 @@ static const GtkCssValueClass GTK_CSS_VALUE_FONT_STRETCH = {
gtk_css_value_enum_compute,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
NULL,
NULL,
gtk_css_value_enum_print
};
@ -578,6 +590,8 @@ static const GtkCssValueClass GTK_CSS_VALUE_TEXT_DECORATION_LINE = {
gtk_css_value_enum_compute,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
NULL,
NULL,
gtk_css_value_enum_print
};
@ -626,6 +640,8 @@ static const GtkCssValueClass GTK_CSS_VALUE_TEXT_DECORATION_STYLE = {
gtk_css_value_enum_compute,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
NULL,
NULL,
gtk_css_value_enum_print
};
@ -674,6 +690,8 @@ static const GtkCssValueClass GTK_CSS_VALUE_AREA = {
gtk_css_value_enum_compute,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
NULL,
NULL,
gtk_css_value_enum_print
};
@ -728,6 +746,8 @@ static const GtkCssValueClass GTK_CSS_VALUE_DIRECTION = {
gtk_css_value_enum_compute,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
NULL,
NULL,
gtk_css_value_enum_print
};
@ -786,6 +806,8 @@ static const GtkCssValueClass GTK_CSS_VALUE_PLAY_STATE = {
gtk_css_value_enum_compute,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
NULL,
NULL,
gtk_css_value_enum_print
};
@ -839,6 +861,8 @@ static const GtkCssValueClass GTK_CSS_VALUE_FILL_MODE = {
gtk_css_value_enum_compute,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
NULL,
NULL,
gtk_css_value_enum_print
};
@ -894,6 +918,8 @@ static const GtkCssValueClass GTK_CSS_VALUE_ICON_STYLE = {
gtk_css_value_enum_compute,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
NULL,
NULL,
gtk_css_value_enum_print
};
@ -948,6 +974,8 @@ static const GtkCssValueClass GTK_CSS_VALUE_FONT_KERNING = {
gtk_css_value_enum_compute,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
NULL,
NULL,
gtk_css_value_enum_print
};
@ -1002,6 +1030,8 @@ static const GtkCssValueClass GTK_CSS_VALUE_FONT_VARIANT_POSITION = {
gtk_css_value_enum_compute,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
NULL,
NULL,
gtk_css_value_enum_print
};
@ -1056,6 +1086,8 @@ static const GtkCssValueClass GTK_CSS_VALUE_FONT_VARIANT_CAPS = {
gtk_css_value_enum_compute,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
NULL,
NULL,
gtk_css_value_enum_print
};
@ -1114,6 +1146,8 @@ static const GtkCssValueClass GTK_CSS_VALUE_FONT_VARIANT_ALTERNATE = {
gtk_css_value_enum_compute,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
NULL,
NULL,
gtk_css_value_enum_print
};
@ -1225,6 +1259,8 @@ static const GtkCssValueClass GTK_CSS_VALUE_FONT_VARIANT_LIGATURE = {
gtk_css_value_enum_compute,
gtk_css_value_flags_equal,
gtk_css_value_enum_transition,
NULL,
NULL,
gtk_css_font_variant_ligature_value_print
};
@ -1329,6 +1365,8 @@ static const GtkCssValueClass GTK_CSS_VALUE_FONT_VARIANT_NUMERIC = {
gtk_css_value_enum_compute,
gtk_css_value_flags_equal,
gtk_css_value_enum_transition,
NULL,
NULL,
gtk_css_font_variant_numeric_value_print
};
@ -1430,6 +1468,8 @@ static const GtkCssValueClass GTK_CSS_VALUE_FONT_VARIANT_EAST_ASIAN = {
gtk_css_value_enum_compute,
gtk_css_value_flags_equal,
gtk_css_value_enum_transition,
NULL,
NULL,
gtk_css_font_variant_east_asian_value_print
};

View File

@ -697,6 +697,8 @@ static const GtkCssValueClass GTK_CSS_VALUE_FILTER = {
gtk_css_value_filter_compute,
gtk_css_value_filter_equal,
gtk_css_value_filter_transition,
NULL,
NULL,
gtk_css_value_filter_print
};

View File

@ -181,6 +181,8 @@ static const GtkCssValueClass GTK_CSS_VALUE_FONT_FEATURES = {
gtk_css_value_font_features_compute,
gtk_css_value_font_features_equal,
gtk_css_value_font_features_transition,
NULL,
NULL,
gtk_css_value_font_features_print
};

View File

@ -180,6 +180,8 @@ static const GtkCssValueClass GTK_CSS_VALUE_FONT_VARIATIONS = {
gtk_css_value_font_variations_compute,
gtk_css_value_font_variations_equal,
gtk_css_value_font_variations_transition,
NULL,
NULL,
gtk_css_value_font_variations_print
};

View File

@ -115,6 +115,8 @@ static const GtkCssValueClass GTK_CSS_VALUE_ICON_THEME = {
gtk_css_value_icon_theme_compute,
gtk_css_value_icon_theme_equal,
gtk_css_value_icon_theme_transition,
NULL,
NULL,
gtk_css_value_icon_theme_print
};

View File

@ -96,6 +96,8 @@ static const GtkCssValueClass GTK_CSS_VALUE_IMAGE = {
gtk_css_value_image_compute,
gtk_css_value_image_equal,
gtk_css_value_image_transition,
NULL,
NULL,
gtk_css_value_image_print
};

View File

@ -82,6 +82,8 @@ static const GtkCssValueClass GTK_CSS_VALUE_INHERIT = {
gtk_css_value_inherit_compute,
gtk_css_value_inherit_equal,
gtk_css_value_inherit_transition,
NULL,
NULL,
gtk_css_value_inherit_print
};

View File

@ -106,6 +106,8 @@ static const GtkCssValueClass GTK_CSS_VALUE_INITIAL = {
gtk_css_value_initial_compute,
gtk_css_value_initial_equal,
gtk_css_value_initial_transition,
NULL,
NULL,
gtk_css_value_initial_print
};

View File

@ -178,6 +178,8 @@ static const GtkCssValueClass GTK_CSS_VALUE_PALETTE = {
gtk_css_value_palette_compute,
gtk_css_value_palette_equal,
gtk_css_value_palette_transition,
NULL,
NULL,
gtk_css_value_palette_print
};

View File

@ -154,6 +154,8 @@ static const GtkCssValueClass GTK_CSS_VALUE_POSITION = {
gtk_css_value_position_compute,
gtk_css_value_position_equal,
gtk_css_value_position_transition,
NULL,
NULL,
gtk_css_value_position_print
};

View File

@ -117,6 +117,8 @@ static const GtkCssValueClass GTK_CSS_VALUE_BACKGROUND_REPEAT = {
gtk_css_value_repeat_compute,
gtk_css_value_repeat_equal,
gtk_css_value_repeat_transition,
NULL,
NULL,
gtk_css_value_background_repeat_print
};
@ -125,6 +127,8 @@ static const GtkCssValueClass GTK_CSS_VALUE_BORDER_REPEAT = {
gtk_css_value_repeat_compute,
gtk_css_value_repeat_equal,
gtk_css_value_repeat_transition,
NULL,
NULL,
gtk_css_value_border_repeat_print
};
/* BACKGROUND REPEAT */

View File

@ -102,6 +102,8 @@ static const GtkCssValueClass GTK_CSS_VALUE_RGBA = {
gtk_css_value_rgba_compute,
gtk_css_value_rgba_equal,
gtk_css_value_rgba_transition,
NULL,
NULL,
gtk_css_value_rgba_print
};

View File

@ -204,6 +204,8 @@ static const GtkCssValueClass GTK_CSS_VALUE_SHADOWS = {
gtk_css_value_shadows_compute,
gtk_css_value_shadows_equal,
gtk_css_value_shadows_transition,
NULL,
NULL,
gtk_css_value_shadows_print
};

View File

@ -159,6 +159,8 @@ static const GtkCssValueClass GTK_CSS_VALUE_SHADOW = {
gtk_css_value_shadow_compute,
gtk_css_value_shadow_equal,
gtk_css_value_shadow_transition,
NULL,
NULL,
gtk_css_value_shadow_print
};

View File

@ -121,6 +121,8 @@ static const GtkCssValueClass GTK_CSS_VALUE_STRING = {
gtk_css_value_string_compute,
gtk_css_value_string_equal,
gtk_css_value_string_transition,
NULL,
NULL,
gtk_css_value_string_print
};
@ -129,6 +131,8 @@ static const GtkCssValueClass GTK_CSS_VALUE_IDENT = {
gtk_css_value_string_compute,
gtk_css_value_string_equal,
gtk_css_value_string_transition,
NULL,
NULL,
gtk_css_value_ident_print
};

View File

@ -707,6 +707,8 @@ static const GtkCssValueClass GTK_CSS_VALUE_TRANSFORM = {
gtk_css_value_transform_compute,
gtk_css_value_transform_equal,
gtk_css_value_transform_transition,
NULL,
NULL,
gtk_css_value_transform_print
};

View File

@ -86,6 +86,8 @@ static const GtkCssValueClass GTK_CSS_VALUE_UNSET = {
gtk_css_value_unset_compute,
gtk_css_value_unset_equal,
gtk_css_value_unset_transition,
NULL,
NULL,
gtk_css_value_unset_print
};

View File

@ -44,7 +44,7 @@ _gtk_css_value_alloc (const GtkCssValueClass *klass,
}
GtkCssValue *
_gtk_css_value_ref (GtkCssValue *value)
gtk_css_value_ref (GtkCssValue *value)
{
gtk_internal_return_val_if_fail (value != NULL, NULL);
@ -54,7 +54,7 @@ _gtk_css_value_ref (GtkCssValue *value)
}
void
_gtk_css_value_unref (GtkCssValue *value)
gtk_css_value_unref (GtkCssValue *value)
{
if (value == NULL)
return;
@ -175,3 +175,51 @@ _gtk_css_value_print (const GtkCssValue *value,
value->class->print (value, string);
}
/**
* gtk_css_value_is_dynamic:
* @value: a #GtkCssValue
*
* A "dynamic" value has a different value at different times. This means that
* the value needs to be animated when time is progressing.
*
* Examples of dynamic values are animated images, such as videos or dynamic shaders.
*
* Use gtk_css_value_get_dynamic_value() to get the value for a given timestamp.
*
* Returns %TRUE if the value is dynamic
*/
gboolean
gtk_css_value_is_dynamic (GtkCssValue *value)
{
gtk_internal_return_val_if_fail (value != NULL, FALSE);
if (!value->class->is_dynamic)
return FALSE;
return value->class->is_dynamic (value);
}
/**
* gtk_css_value_get_dynamic_value:
* @value: a #GtkCssValue
* @monotonic_time: the timestamp for which to get the dynamic value
*
* Gets the dynamic value for a given timestamp. If @monotonic_time is 0,
* the default value is returned.
*
* See gtk_css_value_is_dynamic() for details about dynamic values.
*
* Returns: (transfer full): The dynamic value for @value at the given
* timestamp
**/
GtkCssValue *
gtk_css_value_get_dynamic_value (GtkCssValue *value,
gint64 monotonic_time)
{
gtk_internal_return_val_if_fail (value != NULL, NULL);
if (!value->class->get_dynamic_value)
return gtk_css_value_ref (value);
return value->class->get_dynamic_value (value, monotonic_time);
}

View File

@ -51,6 +51,9 @@ struct _GtkCssValueClass {
GtkCssValue *end,
guint property_id,
double progress);
gboolean (* is_dynamic) (GtkCssValue *value);
GtkCssValue * (* get_dynamic_value) (GtkCssValue *value,
gint64 monotonic_time);
void (* print) (const GtkCssValue *value,
GString *string);
};
@ -61,8 +64,10 @@ GtkCssValue *_gtk_css_value_alloc (const GtkCssValueClass
gsize size);
#define _gtk_css_value_new(_name, _klass) ((_name *) _gtk_css_value_alloc ((_klass), sizeof (_name)))
GtkCssValue *_gtk_css_value_ref (GtkCssValue *value);
void _gtk_css_value_unref (GtkCssValue *value);
#define _gtk_css_value_ref gtk_css_value_ref
GtkCssValue * gtk_css_value_ref (GtkCssValue *value);
#define _gtk_css_value_unref gtk_css_value_unref
void gtk_css_value_unref (GtkCssValue *value);
GtkCssValue *_gtk_css_value_compute (GtkCssValue *value,
guint property_id,
@ -77,6 +82,9 @@ GtkCssValue *_gtk_css_value_transition (GtkCssValue
GtkCssValue *end,
guint property_id,
double progress);
gboolean gtk_css_value_is_dynamic (GtkCssValue *value);
GtkCssValue * gtk_css_value_get_dynamic_value (GtkCssValue *value,
gint64 monotonic_time);
char * _gtk_css_value_to_string (const GtkCssValue *value);
void _gtk_css_value_print (const GtkCssValue *value,

View File

@ -253,6 +253,8 @@ static const GtkCssNumberValueClass GTK_CSS_VALUE_WIN32_SIZE = {
gtk_css_value_win32_size_compute,
gtk_css_value_win32_size_equal,
gtk_css_number_value_transition,
NULL,
NULL,
gtk_css_value_win32_size_print
},
gtk_css_value_win32_size_get,