Merge branch 'wip/alice/menu-button' into 'main'

menubutton: Horizontally expand child

Closes #5883

See merge request GNOME/gtk!6084
This commit is contained in:
Matthias Clasen 2023-06-11 15:14:02 +00:00
commit 2349f13f45

View File

@ -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"
@ -1170,15 +1172,14 @@ gtk_menu_button_set_label (GtkMenuButton *menu_button,
g_object_notify_by_pspec (G_OBJECT (menu_button), menu_button_props[PROP_CHILD]);
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_widget_set_hexpand (box, FALSE);
label_widget = gtk_label_new (label);
gtk_label_set_xalign (GTK_LABEL (label_widget), 0);
gtk_label_set_use_underline (GTK_LABEL (label_widget),
gtk_button_get_use_underline (GTK_BUTTON (menu_button->button)));
gtk_label_set_ellipsize (GTK_LABEL (label_widget),
menu_button->can_shrink ? PANGO_ELLIPSIZE_END
: PANGO_ELLIPSIZE_NONE);
gtk_widget_set_hexpand (label_widget, TRUE);
gtk_widget_set_halign (label_widget, GTK_ALIGN_CENTER);
arrow = gtk_builtin_icon_new ("arrow");
menu_button->arrow_widget = arrow;
gtk_box_append (GTK_BOX (box), label_widget);
@ -1496,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);
@ -1512,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);