constraint layout: Use stays for natural size

It makes more sense to treat the natural size
of both children and guides as stays, since
we want to meet these values as closely as we
can, under the circumstances.
This commit is contained in:
Matthias Clasen 2019-06-28 22:59:38 +00:00 committed by Emmanuele Bassi
parent 90f8dcc5e1
commit b1f0f4478e
2 changed files with 33 additions and 34 deletions

View File

@ -119,14 +119,6 @@ gtk_constraint_guide_update_constraint (GtkConstraintGuide *guide,
GTK_CONSTRAINT_RELATION_LE,
GTK_CONSTRAINT_RELATION_LE,
};
double weight[LAST_GUIDE_VALUE] = {
GTK_CONSTRAINT_WEIGHT_REQUIRED,
GTK_CONSTRAINT_WEIGHT_REQUIRED,
GTK_CONSTRAINT_WEIGHT_MEDIUM,
GTK_CONSTRAINT_WEIGHT_MEDIUM,
GTK_CONSTRAINT_WEIGHT_REQUIRED,
GTK_CONSTRAINT_WEIGHT_REQUIRED,
};
if (!guide->layout)
return;
@ -139,12 +131,23 @@ gtk_constraint_guide_update_constraint (GtkConstraintGuide *guide,
gtk_constraint_solver_remove_constraint (solver, guide->constraints[index]);
var = gtk_constraint_layout_get_attribute (guide->layout, attr[index], "guide", NULL, guide->bound_attributes);
guide->constraints[index] =
gtk_constraint_solver_add_constraint (solver,
var,
relation[index],
gtk_constraint_expression_new (guide->values[index]),
weight[index]);
if (relation[index] == GTK_CONSTRAINT_RELATION_EQ)
{
gtk_constraint_variable_set_value (var, guide->values[index]);
guide->constraints[index] =
gtk_constraint_solver_add_stay_variable (solver,
var,
GTK_CONSTRAINT_WEIGHT_MEDIUM);
}
else
{
guide->constraints[index] =
gtk_constraint_solver_add_constraint (solver,
var,
relation[index],
gtk_constraint_expression_new (guide->values[index]),
GTK_CONSTRAINT_WEIGHT_REQUIRED);
}
}
void

View File

@ -737,12 +737,11 @@ gtk_constraint_layout_measure (GtkLayoutManager *manager,
GTK_CONSTRAINT_WEIGHT_REQUIRED);
g_ptr_array_add (size_constraints, constraint);
gtk_constraint_variable_set_value (width_var, nat_req.width);
constraint =
gtk_constraint_solver_add_constraint (solver,
width_var,
GTK_CONSTRAINT_RELATION_EQ,
gtk_constraint_expression_new (nat_req.width),
GTK_CONSTRAINT_WEIGHT_MEDIUM);
gtk_constraint_solver_add_stay_variable (solver,
width_var,
GTK_CONSTRAINT_WEIGHT_MEDIUM);
g_ptr_array_add (size_constraints, constraint);
height_var = get_child_attribute (self, child, GTK_CONSTRAINT_ATTRIBUTE_HEIGHT);
@ -755,12 +754,11 @@ gtk_constraint_solver_add_constraint (solver,
GTK_CONSTRAINT_WEIGHT_REQUIRED);
g_ptr_array_add (size_constraints, constraint);
gtk_constraint_variable_set_value (height_var, nat_req.height);
constraint =
gtk_constraint_solver_add_constraint (solver,
height_var,
GTK_CONSTRAINT_RELATION_EQ,
gtk_constraint_expression_new (nat_req.height),
GTK_CONSTRAINT_WEIGHT_MEDIUM);
gtk_constraint_solver_add_stay_variable (solver,
height_var,
GTK_CONSTRAINT_WEIGHT_MEDIUM);
g_ptr_array_add (size_constraints, constraint);
}
@ -906,12 +904,11 @@ gtk_constraint_layout_allocate (GtkLayoutManager *manager,
GTK_CONSTRAINT_WEIGHT_REQUIRED);
g_ptr_array_add (size_constraints, constraint);
gtk_constraint_variable_set_value (width_var, nat_req.width);
constraint =
gtk_constraint_solver_add_constraint (solver,
width_var,
GTK_CONSTRAINT_RELATION_EQ,
gtk_constraint_expression_new (nat_req.width),
GTK_CONSTRAINT_WEIGHT_MEDIUM);
gtk_constraint_solver_add_stay_variable (solver,
width_var,
GTK_CONSTRAINT_WEIGHT_MEDIUM);
g_ptr_array_add (size_constraints, constraint);
height_var = get_child_attribute (self, child, GTK_CONSTRAINT_ATTRIBUTE_HEIGHT);
@ -924,12 +921,11 @@ gtk_constraint_solver_add_constraint (solver,
GTK_CONSTRAINT_WEIGHT_REQUIRED);
g_ptr_array_add (size_constraints, constraint);
gtk_constraint_variable_set_value (height_var, nat_req.height);
constraint =
gtk_constraint_solver_add_constraint (solver,
height_var,
GTK_CONSTRAINT_RELATION_EQ,
gtk_constraint_expression_new (nat_req.height),
GTK_CONSTRAINT_WEIGHT_MEDIUM);
gtk_constraint_solver_add_stay_variable (solver,
height_var,
GTK_CONSTRAINT_WEIGHT_MEDIUM);
g_ptr_array_add (size_constraints, constraint);
}