[gtk/deprecate-render] Add gtk_widget_get_style_color
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/deprecate-render] Add gtk_widget_get_style_color
- Date: Wed, 12 Oct 2022 18:54:03 +0000 (UTC)
commit 567920ac80d3e75f85765bc30a9a950a2f69d722
Author: Matthias Clasen <mclasen redhat com>
Date: Wed Oct 12 14:51:22 2022 -0400
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.
gtk/deprecated/gtkstylecontext.c | 2 +-
gtk/gtkwidget.c | 28 ++++++++++++++++++++++++++++
gtk/gtkwidget.h | 4 +++-
3 files changed, 32 insertions(+), 2 deletions(-)
---
diff --git a/gtk/deprecated/gtkstylecontext.c b/gtk/deprecated/gtkstylecontext.c
index 0f399a5a95..d8f113f369 100644
--- a/gtk/deprecated/gtkstylecontext.c
+++ b/gtk/deprecated/gtkstylecontext.c
@@ -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,
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 1aa14bf06b..e0e3c169ae 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -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`
diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h
index 5374160dcf..fce637a3fd 100644
--- a/gtk/gtkwidget.h
+++ b/gtk/gtkwidget.h
@@ -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);
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]