From: Alice Mikhaylenko Date: Sat, 10 Jun 2023 20:02:15 +0000 (+0400) Subject: menubutton: Horizontally expand child X-Git-Tag: archive/raspbian/4.12.3+ds-1+rpi1~1^2^2^2~22^2~1^2~156^2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=27599d688e066d983b3bf022d3dbb3e6f98655d7;p=gtk4.git menubutton: Horizontally expand child Set hexpand on the outer box so we don't propagate that expand. Fixes https://gitlab.gnome.org/GNOME/gtk/-/issues/5883 --- diff --git a/gtk/gtkmenubutton.c b/gtk/gtkmenubutton.c index e015d5421b..eab3ad61ce 100644 --- a/gtk/gtkmenubutton.c +++ b/gtk/gtkmenubutton.c @@ -88,8 +88,10 @@ #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);