[gtk/wip/ebassi/constraint-layout: 104/105] Fix the opposite size measurement in GtkConstraintLayout



commit cb11ba4ca082856505f628cca978b2f49fcc2b16
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Thu Jun 27 17:34:29 2019 +0100

    Fix the opposite size measurement in GtkConstraintLayout
    
    We cannot use the given "for size" when querying our children, because
    the constraint layout has no idea about the opposite size of its
    children until the layout is complete.
    
    Additionally, we should only suggest an opposite size for the layout if
    we have one, instead of suggesting a weak zero size.

 gtk/gtkconstraintlayout.c | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)
---
diff --git a/gtk/gtkconstraintlayout.c b/gtk/gtkconstraintlayout.c
index a111dbe591..54056bf73c 100644
--- a/gtk/gtkconstraintlayout.c
+++ b/gtk/gtkconstraintlayout.c
@@ -693,7 +693,7 @@ gtk_constraint_layout_measure (GtkLayoutManager *manager,
 
       child_info = GTK_CONSTRAINT_LAYOUT_CHILD (gtk_layout_manager_get_layout_child (manager, child));
 
-      gtk_widget_measure (child, orientation, for_size,
+      gtk_widget_measure (child, orientation, -1,
                           &min_size, &nat_size,
                           NULL, NULL);
 
@@ -769,15 +769,15 @@ gtk_constraint_layout_measure (GtkLayoutManager *manager,
    * natural state of the system. Once we get the value out, we can
    * remove these constraints
    */
-  gtk_constraint_solver_add_edit_variable (solver, size, GTK_CONSTRAINT_WEIGHT_WEAK + 1);
-  gtk_constraint_solver_add_edit_variable (solver, opposite_size, GTK_CONSTRAINT_WEIGHT_WEAK + 2);
-
-  gtk_constraint_solver_begin_edit (solver);
-
-  gtk_constraint_solver_suggest_value (solver, size, 0.0);
-  gtk_constraint_solver_suggest_value (solver, opposite_size, for_size >= 0 ? for_size : 0.0);
-
-  gtk_constraint_solver_resolve (solver);
+  if (for_size > 0)
+    {
+      gtk_constraint_solver_add_edit_variable (solver, opposite_size, GTK_CONSTRAINT_WEIGHT_MEDIUM * 2.0);
+      gtk_constraint_solver_begin_edit (solver);
+      gtk_constraint_solver_suggest_value (solver, opposite_size, for_size);
+      gtk_constraint_solver_resolve (solver);
+      gtk_constraint_solver_remove_edit_variable (solver, opposite_size);
+      gtk_constraint_solver_end_edit (solver);
+    }
 
   GTK_NOTE (LAYOUT,
             g_print ("layout %p preferred %s size: %.3f (for opposite size: %d)\n",
@@ -788,11 +788,6 @@ gtk_constraint_layout_measure (GtkLayoutManager *manager,
 
   value = gtk_constraint_variable_get_value (size);
 
-  gtk_constraint_solver_remove_edit_variable (solver, size);
-  gtk_constraint_solver_remove_edit_variable (solver, opposite_size);
-
-  gtk_constraint_solver_end_edit (solver);
-
   for (guint i = 0; i < size_constraints->len; i++)
     {
       GtkConstraintRef *ref = g_ptr_array_index (size_constraints, i);


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