API: gtk: Add gtk_symbolic_color_to_string()
See future commits for why this is useful. Or try to debug some color problem.
This commit is contained in:
@ -5728,6 +5728,7 @@ gtk_symbolic_color_new_mix
|
||||
gtk_symbolic_color_ref
|
||||
gtk_symbolic_color_unref
|
||||
gtk_symbolic_color_resolve
|
||||
gtk_symbolic_color_to_string
|
||||
|
||||
<SUBSECTION Standard>
|
||||
GTK_TYPE_SYMBOLIC_COLOR
|
||||
|
||||
@ -2548,6 +2548,7 @@ gtk_symbolic_color_new_name
|
||||
gtk_symbolic_color_new_shade
|
||||
gtk_symbolic_color_ref
|
||||
gtk_symbolic_color_resolve
|
||||
gtk_symbolic_color_to_string
|
||||
gtk_symbolic_color_unref
|
||||
gtk_table_attach
|
||||
gtk_table_attach_defaults
|
||||
|
||||
@ -560,3 +560,70 @@ gtk_symbolic_color_resolve (GtkSymbolicColor *color,
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_symbolic_color_to_string:
|
||||
* @color: color to convert to a string
|
||||
*
|
||||
* Converts the given @color to a string representation. This is useful
|
||||
* both for debugging and for serialization of strings. The format of
|
||||
* the string may change between different versions of GTK, but it is
|
||||
* guaranteed that the GTK css parser is able to read the string and
|
||||
* create the same symbolic color from it.
|
||||
*
|
||||
* Returns: a new string representing @color
|
||||
**/
|
||||
char *
|
||||
gtk_symbolic_color_to_string (GtkSymbolicColor *color)
|
||||
{
|
||||
char *s;
|
||||
|
||||
g_return_val_if_fail (color != NULL, NULL);
|
||||
|
||||
switch (color->type)
|
||||
{
|
||||
case COLOR_TYPE_LITERAL:
|
||||
s = gdk_rgba_to_string (&color->color);
|
||||
break;
|
||||
case COLOR_TYPE_NAME:
|
||||
s = g_strconcat ("@", color->name, NULL);
|
||||
break;
|
||||
case COLOR_TYPE_SHADE:
|
||||
{
|
||||
char *color_string = gtk_symbolic_color_to_string (color->shade.color);
|
||||
char factor[G_ASCII_DTOSTR_BUF_SIZE];
|
||||
|
||||
g_ascii_dtostr (factor, sizeof (factor), color->shade.factor);
|
||||
s = g_strdup_printf ("shade (%s, %s)", color_string, factor);
|
||||
g_free (color_string);
|
||||
}
|
||||
break;
|
||||
case COLOR_TYPE_ALPHA:
|
||||
{
|
||||
char *color_string = gtk_symbolic_color_to_string (color->shade.color);
|
||||
char factor[G_ASCII_DTOSTR_BUF_SIZE];
|
||||
|
||||
g_ascii_dtostr (factor, sizeof (factor), color->alpha.factor);
|
||||
s = g_strdup_printf ("alpha (%s, %s)", color_string, factor);
|
||||
g_free (color_string);
|
||||
}
|
||||
break;
|
||||
case COLOR_TYPE_MIX:
|
||||
{
|
||||
char *color_string1 = gtk_symbolic_color_to_string (color->mix.color1);
|
||||
char *color_string2 = gtk_symbolic_color_to_string (color->mix.color2);
|
||||
char factor[G_ASCII_DTOSTR_BUF_SIZE];
|
||||
|
||||
g_ascii_dtostr (factor, sizeof (factor), color->mix.factor);
|
||||
s = g_strdup_printf ("mix (%s, %s, %s)", color_string1, color_string2, factor);
|
||||
g_free (color_string1);
|
||||
g_free (color_string2);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
|
||||
return s;
|
||||
|
||||
}
|
||||
|
||||
@ -46,6 +46,8 @@ GtkSymbolicColor * gtk_symbolic_color_new_mix (GtkSymbolicColor *color1,
|
||||
GtkSymbolicColor * gtk_symbolic_color_ref (GtkSymbolicColor *color);
|
||||
void gtk_symbolic_color_unref (GtkSymbolicColor *color);
|
||||
|
||||
char * gtk_symbolic_color_to_string (GtkSymbolicColor *color);
|
||||
|
||||
gboolean gtk_symbolic_color_resolve (GtkSymbolicColor *color,
|
||||
GtkStyleProperties *props,
|
||||
GdkRGBA *resolved_color);
|
||||
|
||||
Reference in New Issue
Block a user