css: Make palette value resolve used values
Separate out computed and used values for this type.
This commit is contained in:
@@ -69,25 +69,25 @@ lookup_symbolic_colors (GtkCssStyle *style,
|
||||
GdkRGBA *warning_out,
|
||||
GdkRGBA *error_out)
|
||||
{
|
||||
const GdkRGBA *lookup;
|
||||
GtkCssValue *lookup;
|
||||
|
||||
*color_out = *gtk_css_color_value_get_rgba (style->core->color);
|
||||
|
||||
lookup = gtk_css_palette_value_get_color (palette, "success");
|
||||
if (lookup)
|
||||
*success_out = *lookup;
|
||||
*success_out = *gtk_css_color_value_get_rgba (lookup);
|
||||
else
|
||||
*success_out = *color_out;
|
||||
|
||||
lookup = gtk_css_palette_value_get_color (palette, "warning");
|
||||
if (lookup)
|
||||
*warning_out = *lookup;
|
||||
*warning_out = *gtk_css_color_value_get_rgba (lookup);
|
||||
else
|
||||
*warning_out = *color_out;
|
||||
|
||||
lookup = gtk_css_palette_value_get_color (palette, "error");
|
||||
if (lookup)
|
||||
*error_out = *lookup;
|
||||
*error_out = *gtk_css_color_value_get_rgba (lookup);
|
||||
else
|
||||
*error_out = *color_out;
|
||||
}
|
||||
|
||||
@@ -323,6 +323,7 @@ gtk_css_palette_value_parse (GtkCssParser *parser)
|
||||
}
|
||||
|
||||
result->is_computed = result->is_computed && gtk_css_value_is_computed (color);
|
||||
result->contains_current_color = result->contains_current_color || gtk_css_value_contains_current_color (color);
|
||||
|
||||
g_ptr_array_add (names, ident);
|
||||
g_ptr_array_add (colors, color);
|
||||
@@ -336,7 +337,7 @@ gtk_css_palette_value_parse (GtkCssParser *parser)
|
||||
return result;
|
||||
}
|
||||
|
||||
const GdkRGBA *
|
||||
GtkCssValue *
|
||||
gtk_css_palette_value_get_color (GtkCssValue *value,
|
||||
const char *name)
|
||||
{
|
||||
@@ -347,8 +348,27 @@ gtk_css_palette_value_get_color (GtkCssValue *value,
|
||||
for (i = 0; i < value->n_colors; i ++)
|
||||
{
|
||||
if (strcmp (value->color_names[i], name) == 0)
|
||||
return gtk_css_color_value_get_rgba (value->color_values[i]);
|
||||
return value->color_values[i];
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GtkCssValue *
|
||||
gtk_css_palette_value_resolve (GtkCssValue *value,
|
||||
GtkCssValue *current_color)
|
||||
{
|
||||
GtkCssValue *result;
|
||||
|
||||
if (!gtk_css_value_contains_current_color (value))
|
||||
return gtk_css_value_ref (value);
|
||||
|
||||
result = gtk_css_palette_value_new_sized (value->n_colors);
|
||||
for (guint i = 0; i < value->n_colors; i++)
|
||||
{
|
||||
result->color_names[i] = g_strdup (value->color_names[i]);
|
||||
result->color_values[i] = gtk_css_color_value_resolve (value->color_values[i], NULL, current_color);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -30,8 +30,11 @@ GtkCssValue * gtk_css_palette_value_new_default (void);
|
||||
|
||||
GtkCssValue * gtk_css_palette_value_parse (GtkCssParser *parser);
|
||||
|
||||
const GdkRGBA * gtk_css_palette_value_get_color (GtkCssValue *value,
|
||||
GtkCssValue * gtk_css_palette_value_get_color (GtkCssValue *value,
|
||||
const char *color_name);
|
||||
|
||||
GtkCssValue * gtk_css_palette_value_resolve (GtkCssValue *value,
|
||||
GtkCssValue *current_color);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
||||
@@ -818,11 +818,11 @@ gtk_css_style_lookup_symbolic_colors (GtkCssStyle *style,
|
||||
|
||||
for (gsize i = 1; i < 4; i++)
|
||||
{
|
||||
const GdkRGBA *lookup;
|
||||
GtkCssValue *lookup;
|
||||
|
||||
lookup = gtk_css_palette_value_get_color (palette, names[i]);
|
||||
if (lookup)
|
||||
color_out[i] = *lookup;
|
||||
color_out[i] = *gtk_css_color_value_get_rgba (lookup);
|
||||
else
|
||||
color_out[i] = color_out[GTK_SYMBOLIC_COLOR_FOREGROUND];
|
||||
}
|
||||
|
||||
@@ -54,11 +54,14 @@ value_is_near (int prop,
|
||||
break;
|
||||
|
||||
case GTK_CSS_PROPERTY_ICON_PALETTE:
|
||||
return color_is_near (gtk_css_palette_value_get_color (value1, "error"),
|
||||
return value_is_near (GTK_CSS_PROPERTY_COLOR,
|
||||
gtk_css_palette_value_get_color (value1, "error"),
|
||||
gtk_css_palette_value_get_color (value2, "error")) &&
|
||||
color_is_near (gtk_css_palette_value_get_color (value1, "warning"),
|
||||
value_is_near (GTK_CSS_PROPERTY_COLOR,
|
||||
gtk_css_palette_value_get_color (value1, "warning"),
|
||||
gtk_css_palette_value_get_color (value2, "warning")) &&
|
||||
color_is_near (gtk_css_palette_value_get_color (value1, "test"),
|
||||
value_is_near (GTK_CSS_PROPERTY_COLOR,
|
||||
gtk_css_palette_value_get_color (value1, "test"),
|
||||
gtk_css_palette_value_get_color (value2, "test"));
|
||||
break;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user