menubutton: Horizontally expand child
authorAlice Mikhaylenko <alexm@gnome.org>
Sat, 10 Jun 2023 20:02:15 +0000 (00:02 +0400)
committerAlice Mikhaylenko <alexm@gnome.org>
Sat, 10 Jun 2023 20:02:15 +0000 (00:02 +0400)
Set hexpand on the outer box so we don't propagate that expand.

Fixes https://gitlab.gnome.org/GNOME/gtk/-/issues/5883

gtk/gtkmenubutton.c

index e015d5421b0728770d01b988745b2dcda8cbbd82..eab3ad61ce08b97eff2d911c01eba22bf8f2a701 100644 (file)
 #include "config.h"
 
 #include "gtkactionable.h"
+#include "gtkbinlayout.h"
 #include "gtkbuildable.h"
 #include "gtkbuiltiniconprivate.h"
+#include "gtkgizmoprivate.h"
 #include "gtkimage.h"
 #include "gtkmain.h"
 #include "gtkmenubutton.h"
@@ -1495,7 +1497,7 @@ void
 gtk_menu_button_set_child (GtkMenuButton *menu_button,
                            GtkWidget     *child)
 {
-  GtkWidget *box, *arrow;
+  GtkWidget *box, *arrow, *inner_widget;
 
   g_return_if_fail (GTK_IS_MENU_BUTTON (menu_button));
   g_return_if_fail (child == NULL || menu_button->child == child || gtk_widget_get_parent (child) == NULL);
@@ -1511,13 +1513,26 @@ gtk_menu_button_set_child (GtkMenuButton *menu_button,
     g_object_notify_by_pspec (G_OBJECT (menu_button), menu_button_props[PROP_ICON_NAME]);
 
   box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
-  gtk_widget_set_halign (box, GTK_ALIGN_CENTER);
+  gtk_widget_set_hexpand (box, FALSE);
 
   arrow = gtk_builtin_icon_new ("arrow");
   menu_button->arrow_widget = arrow;
 
+  inner_widget = gtk_gizmo_new_with_role ("contents",
+                                          GTK_ACCESSIBLE_ROLE_GROUP,
+                                          NULL,
+                                          NULL,
+                                          NULL,
+                                          NULL,
+                                          (GtkGizmoFocusFunc)gtk_widget_focus_self,
+                                          (GtkGizmoGrabFocusFunc)gtk_widget_grab_focus_self);
+
+  gtk_widget_set_layout_manager (inner_widget, gtk_bin_layout_new ());
+  gtk_widget_set_hexpand (inner_widget, TRUE);
   if (child)
-    gtk_box_append (GTK_BOX (box), child);
+    gtk_widget_set_parent (child, inner_widget);
+
+  gtk_box_append (GTK_BOX (box), inner_widget);
   gtk_box_append (GTK_BOX (box), arrow);
   gtk_button_set_child (GTK_BUTTON (menu_button->button), box);