[gtk/wip/ebassi/constraint-layout: 50/69] constraint layout: Measure more correctly



commit dab8a8b5c5a2afb4edec7aa8fdc9adf8804d3470
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Jun 28 20:55:13 2019 +0000

    constraint layout: Measure more correctly
    
    Set up all constraints for minimum + natural
    width + height when measuring, regardless
    of the orientation we're measuring. Anything
    else will lead to incorrect answers when
    there are constraints that cut across
    dimensions.

 gtk/gtkconstraintlayout.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)
---
diff --git a/gtk/gtkconstraintlayout.c b/gtk/gtkconstraintlayout.c
index f2b65ff091..378e7840af 100644
--- a/gtk/gtkconstraintlayout.c
+++ b/gtk/gtkconstraintlayout.c
@@ -720,14 +720,12 @@ gtk_constraint_layout_measure (GtkLayoutManager *manager,
     {
       GtkConstraintVariable *width_var, *height_var;
       GtkConstraintRef *constraint;
-      int min_size = 0, nat_size = 0;
+      GtkRequisition min_req, nat_req;
 
       if (!gtk_widget_should_layout (child))
         continue;
 
-      gtk_widget_measure (child, orientation, -1,
-                          &min_size, &nat_size,
-                          NULL, NULL);
+      gtk_widget_get_preferred_size (child, &min_req, &nat_req);
 
       width_var = get_child_attribute (self, child, GTK_CONSTRAINT_ATTRIBUTE_WIDTH);
 
@@ -735,15 +733,15 @@ gtk_constraint_layout_measure (GtkLayoutManager *manager,
         gtk_constraint_solver_add_constraint (solver,
                                               width_var,
                                               GTK_CONSTRAINT_RELATION_GE,
-                                              gtk_constraint_expression_new (min_size),
+                                              gtk_constraint_expression_new (min_req.width),
                                               GTK_CONSTRAINT_WEIGHT_REQUIRED);
       g_ptr_array_add (size_constraints, constraint);
 
       constraint =
-        gtk_constraint_solver_add_constraint (solver,
+gtk_constraint_solver_add_constraint (solver,
                                               width_var,
                                               GTK_CONSTRAINT_RELATION_EQ,
-                                              gtk_constraint_expression_new (nat_size),
+                                              gtk_constraint_expression_new (nat_req.width),
                                               GTK_CONSTRAINT_WEIGHT_MEDIUM);
       g_ptr_array_add (size_constraints, constraint);
 
@@ -753,7 +751,7 @@ gtk_constraint_layout_measure (GtkLayoutManager *manager,
         gtk_constraint_solver_add_constraint (solver,
                                               height_var,
                                               GTK_CONSTRAINT_RELATION_GE,
-                                              gtk_constraint_expression_new (min_size),
+                                              gtk_constraint_expression_new (min_req.height),
                                               GTK_CONSTRAINT_WEIGHT_REQUIRED);
       g_ptr_array_add (size_constraints, constraint);
 
@@ -761,7 +759,7 @@ gtk_constraint_layout_measure (GtkLayoutManager *manager,
         gtk_constraint_solver_add_constraint (solver,
                                               height_var,
                                               GTK_CONSTRAINT_RELATION_EQ,
-                                              gtk_constraint_expression_new (nat_size),
+                                              gtk_constraint_expression_new (nat_req.height),
                                               GTK_CONSTRAINT_WEIGHT_MEDIUM);
       g_ptr_array_add (size_constraints, constraint);
     }


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