widget: adjust allocation even better

This fixes fallout from 3742fabae0 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.
This commit is contained in:
Benjamin Otte 2021-10-22 14:51:56 +02:00
parent 438bf8596e
commit 1606a41116

View 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,