[gtk/wip/baedert/widget-add-style-class] widget: Add gtk_widget_{add, remove}_style_class
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/baedert/widget-add-style-class] widget: Add gtk_widget_{add, remove}_style_class
- Date: Wed, 29 Jan 2020 08:07:54 +0000 (UTC)
commit d6a643f21e8a751374a7ec05edf925c7910c038d
Author: Timm Bäder <mail baedert org>
Date: Wed Jan 29 08:33:41 2020 +0100
widget: Add gtk_widget_{add,remove}_style_class
As convenience for adding/remove a style class to a widget's css node,
This is a prerequisite for style contexts eventually going away.
docs/reference/gtk/gtk4-sections.txt | 2 ++
gtk/gtkwidget.c | 51 ++++++++++++++++++++++++++++++++++++
gtk/gtkwidget.h | 7 +++++
3 files changed, 60 insertions(+)
---
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index b4a737d2f0..5ecb63ba04 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -4409,6 +4409,8 @@ gtk_widget_insert_after
gtk_widget_set_layout_manager
gtk_widget_get_layout_manager
gtk_widget_should_layout
+gtk_widget_add_style_class
+gtk_widget_remove_style_class
<SUBSECTION>
gtk_widget_get_style_context
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index ba4f4b461c..962f87134a 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -13175,3 +13175,54 @@ gtk_widget_class_query_action (GtkWidgetClass *widget_class,
return FALSE;
}
+
+/**
+ * gtk_widget_add_style_class:
+ * @widget: a #GtkWidget
+ * @style_class: The style class to add to @widget, without
+ * the leading '.' used for notation of style classes
+ *
+ * Adds @style_class to @widget. After calling this function, @widget's
+ * style will match for @style_class, after the CSS matching rules.
+ */
+void
+gtk_widget_add_style_class (GtkWidget *widget,
+ const char *style_class)
+{
+ GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
+
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+ g_return_if_fail (style_class != NULL);
+ g_return_if_fail (style_class[0] != '\0');
+ g_return_if_fail (style_class[0] != '.');
+
+ gtk_css_node_add_class (priv->cssnode, g_quark_from_string (style_class));
+}
+
+/**
+ * gtk_widget_remove_style_class:
+ * @widget: a #GtkWidget
+ * @style_class: The style class to remove from @widget, without
+ * the leading '.' used for notation of style classes
+ *
+ * Removes @style_class from @widget. After this, the style of @widget
+ * will stop matching for @style_class.
+ */
+void
+gtk_widget_remove_style_class (GtkWidget *widget,
+ const char *style_class)
+{
+ GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
+ GQuark class_quark;
+
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+ g_return_if_fail (style_class != NULL);
+ g_return_if_fail (style_class[0] != '\0');
+ g_return_if_fail (style_class[0] != '.');
+
+ class_quark = g_quark_from_string (style_class);
+ if (!class_quark)
+ return;
+
+ gtk_css_node_remove_class (priv->cssnode, class_quark);
+}
diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h
index 1719f59487..9a5094b0dd 100644
--- a/gtk/gtkwidget.h
+++ b/gtk/gtkwidget.h
@@ -967,6 +967,13 @@ void gtk_widget_snapshot_child (GtkWidget *widget,
GtkSnapshot *snapshot);
GDK_AVAILABLE_IN_ALL
gboolean gtk_widget_should_layout (GtkWidget *widget);
+GDK_AVAILABLE_IN_ALL
+void gtk_widget_add_style_class (GtkWidget *widget,
+ const char *style_class);
+GDK_AVAILABLE_IN_ALL
+void gtk_widget_remove_style_class (GtkWidget *widget,
+ const char *style_class);
+
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]