widget: adjust allocation even better
authorBenjamin Otte <otte@redhat.com>
Fri, 22 Oct 2021 12:51:56 +0000 (14:51 +0200)
committerBenjamin Otte <otte@redhat.com>
Fri, 22 Oct 2021 15:51:40 +0000 (17:51 +0200)
This fixes fallout from 3742fabae040d914e6ae58edf31170a54a980f21 where
we would no longer allocate widgets to their natural size when
align flags where used.

GtkPicture wants to be allocated at 100% in that case, so a picture with
a 100x100 image inside a 200x200 window should be allocated 100x100.

The new adjustment code now does the following (for width-for-height
instead of height-for-width, swap width and height in the following):

1. query the minimum width for the allocated height
2. query the natural width
3. compute the maximum of (1) and (2)
4. set the widget width to the minimum of (3) and the allocated
   width.
5. compute the natural height for (4)
6. set the widget height to the minimum of (5) and the allocated height.

gtk/gtkwidget.c

index 6360fa16c7c7a8efbeb8c9433cda49a5d0196d2f..7f0ab9faa300c405a5ca476e9f87b2e0fbfb8492 100644 (file)
@@ -3848,7 +3848,11 @@ gtk_widget_adjust_size_allocation (GtkWidget     *widget,
     {
       gtk_widget_measure (widget, GTK_ORIENTATION_HORIZONTAL,
                           allocation->height + priv->margin.top + priv->margin.bottom,
-                          &min_width, &natural_width, NULL, NULL);
+                          &min_width, NULL, NULL, NULL);
+      gtk_widget_measure (widget, GTK_ORIENTATION_HORIZONTAL,
+                          -1,
+                          NULL, &natural_width, NULL, NULL);
+      natural_width = MAX (min_width, natural_width);
       adjust_for_align (effective_align (priv->halign, _gtk_widget_get_direction (widget)),
                         natural_width - priv->margin.left - priv->margin.right,
                         &allocation->x,
@@ -3865,7 +3869,11 @@ gtk_widget_adjust_size_allocation (GtkWidget     *widget,
     {
       gtk_widget_measure (widget, GTK_ORIENTATION_VERTICAL,
                           allocation->width + priv->margin.left + priv->margin.right,
-                          &min_height, &natural_height, NULL, NULL);
+                          &min_height, NULL, NULL, NULL);
+      gtk_widget_measure (widget, GTK_ORIENTATION_VERTICAL,
+                          -1,
+                          NULL, &natural_height, NULL, NULL);
+      natural_height = MAX (min_height, natural_height);
       adjust_for_align (priv->valign,
                         natural_height - priv->margin.top - priv->margin.bottom,
                         &allocation->y,