[amtk] utils: add amtk_utils_get_shrinkable_menubar()



commit 2ec489224e65acff8d67dd21a3567ed6c9db2010
Author: Sébastien Wilmet <swilmet informatique-libre be>
Date:   Fri May 27 23:51:01 2022 +0200

    utils: add amtk_utils_get_shrinkable_menubar()
    
    The code comes from gnome-latex, and will be used there.

 amtk/amtk-utils.c | 39 +++++++++++++++++++++++++++++++++++++++
 amtk/amtk-utils.h |  3 +++
 2 files changed, 42 insertions(+)
---
diff --git a/amtk/amtk-utils.c b/amtk/amtk-utils.c
index e1ed7d9..66f9e8c 100644
--- a/amtk/amtk-utils.c
+++ b/amtk/amtk-utils.c
@@ -465,3 +465,42 @@ amtk_utils_create_gtk_action (GActionMap     *g_action_map,
                                                gtk_action_name);
 }
 G_GNUC_END_IGNORE_DEPRECATIONS
+
+/**
+ * amtk_utils_get_shrinkable_menubar:
+ * @menubar: a #GtkMenuBar.
+ *
+ * This function wraps @menubar into a container, to allow the menubar to shrink
+ * below its minimum width.
+ *
+ * A possible use-case: have two applications side-by-side on a single screen.
+ *
+ * Returns: (transfer floating): a new widget that contains @menubar.
+ * Since: 5.6
+ */
+GtkWidget *
+amtk_utils_get_shrinkable_menubar (GtkMenuBar *menubar)
+{
+       GtkWidget *viewport;
+       GtkWidget *hpaned;
+
+       /* Note, this solution might work with other kinds of widgets than a
+        * GtkMenuBar. But it would require more testing. If a more general
+        * solution is desirable, another function can be added.
+        */
+
+       g_return_val_if_fail (GTK_IS_MENU_BAR (menubar), NULL);
+
+       viewport = gtk_viewport_new (NULL, NULL);
+       gtk_widget_show (viewport);
+       gtk_viewport_set_shadow_type (GTK_VIEWPORT (viewport), GTK_SHADOW_NONE);
+
+       hpaned = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL);
+       gtk_widget_show (hpaned);
+
+       /* Packing */
+       gtk_container_add (GTK_CONTAINER (viewport), GTK_WIDGET (menubar));
+       gtk_paned_add1 (GTK_PANED (hpaned), viewport);
+
+       return hpaned;
+}
diff --git a/amtk/amtk-utils.h b/amtk/amtk-utils.h
index 8ceb964..ec1db80 100644
--- a/amtk/amtk-utils.h
+++ b/amtk/amtk-utils.h
@@ -43,6 +43,9 @@ void          amtk_utils_create_gtk_action                    (GActionMap     *g_action_map,
                                                                 const gchar    *gtk_action_name);
 G_GNUC_END_IGNORE_DEPRECATIONS
 
+G_MODULE_EXPORT
+GtkWidget *    amtk_utils_get_shrinkable_menubar               (GtkMenuBar *menubar);
+
 G_END_DECLS
 
 #endif /* AMTK_UTILS_H */


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