Add gtk_widget_get_style_color

There is a widespread need to access the CSS foreground
color for custom drawing in snapshot functions, so make
it available after gtk_style_context_get_color was
deprecated with a new widget api.
This commit is contained in:
Matthias Clasen 2022-10-12 14:51:22 -04:00
parent f42fe500c9
commit 5627542d7c
3 changed files with 32 additions and 2 deletions

View File

@ -824,7 +824,7 @@ gtk_style_context_lookup_color (GtkStyleContext *context,
*
* Gets the foreground color for a given state.
*
* Deprecated: 4.10: This api will be removed in GTK 5
* Deprecated: 4.10: Use [method@Gtk.Widget.get_style_color] instead
*/
void
gtk_style_context_get_color (GtkStyleContext *context,

View File

@ -35,6 +35,7 @@
#include "gtkconstraint.h"
#include "gtkcssboxesprivate.h"
#include "gtkcssfiltervalueprivate.h"
#include "gtkcsscolorvalueprivate.h"
#include "gtkcsstransformvalueprivate.h"
#include "gtkcsspositionvalueprivate.h"
#include "gtkcssfontvariationsvalueprivate.h"
@ -12869,6 +12870,33 @@ gtk_widget_set_css_classes (GtkWidget *widget,
g_object_notify_by_pspec (G_OBJECT (widget), widget_props[PROP_CSS_CLASSES]);
}
/**
* gtk_widget_get_css_style:
* @widget: a `GtkWidget`
* @color: (out): return location for the color
*
* Gets the current foreground color for the widgets
* CSS style.
*
* This function should only be used in snapshot
* implementations that need need to do custom
* drawing with the foreground color.
*
* Since: 4.10
*/
void
gtk_widget_get_style_color (GtkWidget *widget,
GdkRGBA *color)
{
GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
GtkCssStyle *style;
g_return_if_fail (GTK_IS_WIDGET (widget));
style = gtk_css_node_get_style (priv->cssnode);
*color = *gtk_css_color_value_get_rgba (style->core->color);
}
/*< private >
* gtk_widget_update_orientation:
* @widget: a `GtkWidget` implementing `GtkOrientable`

View File

@ -928,7 +928,9 @@ GDK_AVAILABLE_IN_ALL
void gtk_widget_set_css_classes (GtkWidget *widget,
const char **classes);
GDK_AVAILABLE_IN_4_10
void gtk_widget_get_style_color (GtkWidget *widget,
GdkRGBA *rgba);
/**