From 6b59c138b2252d4cc1609c3cd2bd1bf508b9202a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B3nio=20Fernandes?= Date: Fri, 2 Jun 2023 20:18:56 +0100 Subject: [PATCH] boxlayout: Don't always reserve height for baseline alignment Otherwise an horizontal box may have a larger minumum height than any of its children even though non of them is baseline-aligned. Fixes https://gitlab.gnome.org/GNOME/gtk/-/issues/5863 --- gtk/gtkboxlayout.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/gtk/gtkboxlayout.c b/gtk/gtkboxlayout.c index a95a4ee3cb..1555c17bc7 100644 --- a/gtk/gtkboxlayout.c +++ b/gtk/gtkboxlayout.c @@ -323,6 +323,7 @@ gtk_box_layout_compute_opposite_size (GtkBoxLayout *self, int largest_min_above = -1, largest_min_below = -1; int largest_nat_above = -1, largest_nat_below = -1; gboolean have_baseline = FALSE; + gboolean align_baseline = FALSE; for (child = gtk_widget_get_first_child (widget); child != NULL; @@ -350,6 +351,10 @@ gtk_box_layout_compute_opposite_size (GtkBoxLayout *self, if (child_min_baseline > -1) { have_baseline = TRUE; + if (gtk_widget_get_valign (child) == GTK_ALIGN_BASELINE_FILL || + gtk_widget_get_valign (child) == GTK_ALIGN_BASELINE_CENTER) + align_baseline = TRUE; + largest_min_above = MAX (largest_min_above, child_min_baseline); largest_min_below = MAX (largest_min_below, child_min - child_min_baseline); largest_nat_above = MAX (largest_nat_above, child_nat_baseline); @@ -358,7 +363,7 @@ gtk_box_layout_compute_opposite_size (GtkBoxLayout *self, } } - if (self->orientation == GTK_ORIENTATION_HORIZONTAL) + if (self->orientation == GTK_ORIENTATION_HORIZONTAL && align_baseline) { largest_min = MAX (largest_min, largest_min_above + largest_min_below); largest_nat = MAX (largest_nat, largest_nat_above + largest_nat_below);