boxlayout: Don't always reserve height for baseline alignment
authorAntónio Fernandes <antoniof@gnome.org>
Fri, 2 Jun 2023 19:18:56 +0000 (20:18 +0100)
committerAntónio Fernandes <antoniof@gnome.org>
Fri, 2 Jun 2023 19:18:56 +0000 (20:18 +0100)
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

index a95a4ee3cbe956779a42b98d0a569631e7784f16..1555c17bc726a31537b25c02141572da59602b5f 100644 (file)
@@ -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);