[gtk/wip/otte/center-center-center: 4/5] widget: adjust allocation even better




commit 1606a411162c87a2de4bfdf686bd2b6e972b36e2
Author: Benjamin Otte <otte redhat com>
Date:   Fri Oct 22 14:51:56 2021 +0200

    widget: adjust allocation even better
    
    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 | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 6360fa16c7..7f0ab9faa3 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -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,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]