[tepl] InfoBar: add a TeplInfoBarLocation param to add_content_widget()



commit 0937f340de5e0415354fcfc9f83111433c64c7aa
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Wed Nov 11 13:01:07 2020 +0100

    InfoBar: add a TeplInfoBarLocation param to add_content_widget()
    
    It will be useful for the TeplProgressInfoBar, to add the GtkProgressBar
    *below* the icon. And it will probably be useful for other purposes as
    well, and with an enum it's extensible.

 docs/reference/api-breaks.xml |  7 +++++++
 tepl/tepl-info-bar.c          | 38 ++++++++++++++++++++++++++------------
 tepl/tepl-info-bar.h          |  5 +++--
 tests/test-tab.c              |  3 ++-
 4 files changed, 38 insertions(+), 15 deletions(-)
---
diff --git a/docs/reference/api-breaks.xml b/docs/reference/api-breaks.xml
index 2e1159b..feeee1d 100644
--- a/docs/reference/api-breaks.xml
+++ b/docs/reference/api-breaks.xml
@@ -184,6 +184,13 @@
           <link 
linkend="tepl-info-bar-set-icon-from-message-type">tepl_info_bar_set_icon_from_message_type()</link>.
         </para>
       </listitem>
+      <listitem>
+        <para>
+          A <code>location</code> parameter has been added to the
+          <link linkend="tepl-info-bar-add-content-widget">tepl_info_bar_add_content_widget()</link>
+          function.
+        </para>
+      </listitem>
     </itemizedlist>
   </chapter>
 </part>
diff --git a/tepl/tepl-info-bar.c b/tepl/tepl-info-bar.c
index ec03f82..9f3622f 100644
--- a/tepl/tepl-info-bar.c
+++ b/tepl/tepl-info-bar.c
@@ -540,26 +540,40 @@ tepl_info_bar_add_secondary_message (TeplInfoBar *info_bar,
 /**
  * tepl_info_bar_add_content_widget:
  * @info_bar: a #TeplInfoBar.
- * @content: a #GtkWidget.
+ * @widget: a #GtkWidget.
+ * @location: a #TeplInfoBarLocation.
  *
- * Adds @content to @info_bar.
+ * Adds @widget to @info_bar at @location.
  *
- * #TeplInfoBar has an internal container, to be able to add the icon and add
- * primary or secondary messages. The internal container is added to the content
- * area, as returned by gtk_info_bar_get_content_area(). So if you use a
- * #TeplInfoBar and you need to add a custom #GtkWidget, it is better to use
- * this function instead of adding the #GtkWidget directly to the content area.
+ * As described in #TeplInfoBarLocation, a #TeplInfoBar has internal containers
+ * for the content area. So if you need to add a custom #GtkWidget, it is better
+ * to use this function instead of adding the #GtkWidget directly to the content
+ * area.
  *
- * Since: 2.0
+ * Since: 6.0
  */
 void
-tepl_info_bar_add_content_widget (TeplInfoBar *info_bar,
-                                 GtkWidget   *content)
+tepl_info_bar_add_content_widget (TeplInfoBar         *info_bar,
+                                 GtkWidget           *widget,
+                                 TeplInfoBarLocation  location)
 {
        g_return_if_fail (TEPL_IS_INFO_BAR (info_bar));
-       g_return_if_fail (GTK_IS_WIDGET (content));
+       g_return_if_fail (GTK_IS_WIDGET (widget));
+
+       switch (location)
+       {
+               case TEPL_INFO_BAR_LOCATION_ALONGSIDE_ICON:
+                       gtk_container_add (GTK_CONTAINER (info_bar->priv->vgrid_alongside_icon), widget);
+                       break;
 
-       gtk_container_add (GTK_CONTAINER (info_bar->priv->vgrid_alongside_icon), content);
+               case TEPL_INFO_BAR_LOCATION_BELOW_ICON:
+                       gtk_container_add (GTK_CONTAINER (info_bar->priv->vgrid_main), widget);
+                       break;
+
+               default:
+                       g_warn_if_reached ();
+                       break;
+       }
 }
 
 /**
diff --git a/tepl/tepl-info-bar.h b/tepl/tepl-info-bar.h
index 147d948..17c0d71 100644
--- a/tepl/tepl-info-bar.h
+++ b/tepl/tepl-info-bar.h
@@ -99,8 +99,9 @@ void                  tepl_info_bar_add_secondary_message             (TeplInfoBar 
*info_bar,
                                                                         const gchar *secondary_msg);
 
 _TEPL_EXTERN
-void                   tepl_info_bar_add_content_widget                (TeplInfoBar *info_bar,
-                                                                        GtkWidget   *content);
+void                   tepl_info_bar_add_content_widget                (TeplInfoBar         *info_bar,
+                                                                        GtkWidget           *widget,
+                                                                        TeplInfoBarLocation  location);
 
 _TEPL_EXTERN
 gboolean               tepl_info_bar_get_handle_close_response         (TeplInfoBar *info_bar);
diff --git a/tests/test-tab.c b/tests/test-tab.c
index 8086d5b..65836c8 100644
--- a/tests/test-tab.c
+++ b/tests/test-tab.c
@@ -27,7 +27,8 @@ basic_cb (GtkButton *button,
 
        entry = gtk_entry_new ();
        gtk_widget_show (entry);
-       tepl_info_bar_add_content_widget (info_bar, entry);
+       tepl_info_bar_add_content_widget (info_bar, entry, TEPL_INFO_BAR_LOCATION_ALONGSIDE_ICON);
+       //tepl_info_bar_add_content_widget (info_bar, entry, TEPL_INFO_BAR_LOCATION_BELOW_ICON);
 
        tepl_info_bar_setup_close_button (info_bar);
 


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