[libhandy] expander-row: Add the ability to add prefix widgets



commit 14979bb803d53f9ebb4a1bc3bb69538dbd6d027e
Author: vanadiae <vanadiae35 gmail com>
Date:   Fri Jun 26 19:18:35 2020 +0200

    expander-row: Add the ability to add prefix widgets
    
    The prefix widgets appear before any element in the row.
    
    Fixes https://gitlab.gnome.org/GNOME/libhandy/-/issues/297

 debian/libhandy-1-0.symbols |  1 +
 src/hdy-expander-row.c      | 43 ++++++++++++++++++++++++++++++++++++++++++-
 src/hdy-expander-row.h      |  2 ++
 3 files changed, 45 insertions(+), 1 deletion(-)
---
diff --git a/debian/libhandy-1-0.symbols b/debian/libhandy-1-0.symbols
index 6e3277cb..707fdb20 100644
--- a/debian/libhandy-1-0.symbols
+++ b/debian/libhandy-1-0.symbols
@@ -120,6 +120,7 @@ libhandy-1.so.0 libhandy-1-0 #MINVER#
  hdy_enum_value_object_new@LIBHANDY_1_0 0.0.6
  hdy_enum_value_row_name@LIBHANDY_1_0 0.0.6
  hdy_expander_row_add_action@LIBHANDY_1_0 0.81.0
+ hdy_expander_row_add_prefix@LIBHANDY_1_0 0.82.0
  hdy_expander_row_get_enable_expansion@LIBHANDY_1_0 0.0.6
  hdy_expander_row_get_expanded@LIBHANDY_1_0 0.0.9
  hdy_expander_row_get_icon_name@LIBHANDY_1_0 0.80.0
diff --git a/src/hdy-expander-row.c b/src/hdy-expander-row.c
index 7d96ea64..b6b6fbfe 100644
--- a/src/hdy-expander-row.c
+++ b/src/hdy-expander-row.c
@@ -20,7 +20,9 @@
  * all that the row contains.
  *
  * It also supports adding a child as an action widget by specifying “action” as
- * the “type” attribute of a &lt;child&gt; element.
+ * the “type” attribute of a &lt;child&gt; element. It also supports setting a
+ * child as a prefix widget by specifying “prefix” as the “type” attribute of a
+ * &lt;child&gt; element.
  *
  * # CSS nodes
  *
@@ -41,6 +43,7 @@ typedef struct
 {
   GtkBox *box;
   GtkBox *actions;
+  GtkBox *prefixes;
   GtkListBox *list;
   HdyActionRow *action_row;
   GtkSwitch *enable_switch;
@@ -191,6 +194,8 @@ hdy_expander_row_forall (GtkContainer *container,
                                                                  callback,
                                                                  callback_data);
   else {
+    if (priv->prefixes)
+      gtk_container_foreach (GTK_CONTAINER (priv->prefixes), callback, callback_data);
     if (priv->actions)
       gtk_container_foreach (GTK_CONTAINER (priv->actions), callback, callback_data);
     if (priv->list)
@@ -255,6 +260,8 @@ hdy_expander_row_remove (GtkContainer *container,
     GTK_CONTAINER_CLASS (hdy_expander_row_parent_class)->remove (container, child);
   else if (gtk_widget_get_parent (child) == GTK_WIDGET (priv->actions))
     gtk_container_remove (GTK_CONTAINER (priv->actions), child);
+  else if (gtk_widget_get_parent (child) == GTK_WIDGET (priv->prefixes))
+    gtk_container_remove (GTK_CONTAINER (priv->prefixes), child);
   else
     gtk_container_remove (GTK_CONTAINER (priv->list), child);
 }
@@ -396,6 +403,8 @@ hdy_expander_row_init (HdyExpanderRow *self)
 {
   HdyExpanderRowPrivate *priv = hdy_expander_row_get_instance_private (self);
 
+  priv->prefixes = NULL;
+
   gtk_widget_init_template (GTK_WIDGET (self));
 
   hdy_expander_row_set_enable_expansion (self, TRUE);
@@ -420,6 +429,8 @@ hdy_expander_row_buildable_add_child (GtkBuildable *buildable,
     gtk_container_add (GTK_CONTAINER (self), GTK_WIDGET (child));
   else if (type && strcmp (type, "action") == 0)
     hdy_expander_row_add_action (self, GTK_WIDGET (child));
+  else if (type && strcmp (type, "prefix") == 0)
+    hdy_expander_row_add_prefix (self, GTK_WIDGET (child));
   else
     GTK_BUILDER_WARN_INVALID_CHILD_TYPE (self, type);
 }
@@ -786,3 +797,33 @@ hdy_expander_row_add_action (HdyExpanderRow *self,
   gtk_box_pack_start (priv->actions, widget, FALSE, TRUE, 0);
   gtk_widget_show (GTK_WIDGET (priv->actions));
 }
+
+/**
+ * hdy_expander_row_add_prefix:
+ * @self: a #HdyExpanderRow
+ * @widget: the prefix widget
+ *
+ * Adds a prefix widget to @self.
+ *
+ * Since: 1.0
+ */
+void
+hdy_expander_row_add_prefix (HdyExpanderRow *self,
+                             GtkWidget      *widget)
+{
+  HdyExpanderRowPrivate *priv;
+
+  g_return_if_fail (HDY_IS_EXPANDER_ROW (self));
+  g_return_if_fail (GTK_IS_WIDGET (widget));
+
+  priv = hdy_expander_row_get_instance_private (self);
+
+  if (priv->prefixes == NULL) {
+    priv->prefixes = GTK_BOX (gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12));
+    gtk_widget_set_no_show_all (GTK_WIDGET (priv->prefixes), TRUE);
+    gtk_widget_set_can_focus (GTK_WIDGET (priv->prefixes), FALSE);
+    hdy_action_row_add_prefix (HDY_ACTION_ROW (priv->action_row), GTK_WIDGET (priv->prefixes));
+  }
+  gtk_box_pack_start (priv->prefixes, widget, FALSE, TRUE, 0);
+  gtk_widget_show (GTK_WIDGET (priv->prefixes));
+}
diff --git a/src/hdy-expander-row.h b/src/hdy-expander-row.h
index f2a64943..f56a6010 100644
--- a/src/hdy-expander-row.h
+++ b/src/hdy-expander-row.h
@@ -60,5 +60,7 @@ void     hdy_expander_row_set_show_enable_switch (HdyExpanderRow *self,
 
 void     hdy_expander_row_add_action (HdyExpanderRow *self,
                                       GtkWidget      *widget);
+void     hdy_expander_row_add_prefix (HdyExpanderRow *self,
+                                      GtkWidget      *widget);
 
 G_END_DECLS


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]