diff options
Diffstat (limited to 'gtk/gtkconstraintsolverprivate.h')
-rw-r--r-- | gtk/gtkconstraintsolverprivate.h | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/gtk/gtkconstraintsolverprivate.h b/gtk/gtkconstraintsolverprivate.h index 807b0b08d6..69eed376c7 100644 --- a/gtk/gtkconstraintsolverprivate.h +++ b/gtk/gtkconstraintsolverprivate.h @@ -29,6 +29,37 @@ G_BEGIN_DECLS G_DECLARE_FINAL_TYPE (GtkConstraintSolver, gtk_constraint_solver, GTK, CONSTRAINT_SOLVER, GObject) +/* Symbolic weight thresholds + * + * Constraint weights live on a continuum, but we use thresholds for simplicity's + * sake, so we don't have to necessarily reason in terms of numeric values. + * + * The public API has a similar approach, where the symbolic constants are negative + * values, and positive values are explicit weights. We map those values into + * numeric values that the GtkConstraintSolver can plug into the linear equations + * tableau. + */ +#define GTK_CONSTRAINT_WEIGHT_REQUIRED (make_weight (1000, 1000, 1000, 1)) +#define GTK_CONSTRAINT_WEIGHT_STRONG (make_weight ( 1, 0, 0, 1)) +#define GTK_CONSTRAINT_WEIGHT_MEDIUM (make_weight ( 0, 1, 0, 1)) +#define GTK_CONSTRAINT_WEIGHT_WEAK (make_weight ( 0, 0, 1, 1)) + +G_GNUC_PURE +static inline double +make_weight (double a, + double b, + double c, + double w) +{ + double res = 0; + + res += CLAMP (a * w, 0, 1000) * 1000000; + res += CLAMP (b * w, 0, 1000) * 1000; + res += CLAMP (c * w, 0, 1000); + + return res; +} + GtkConstraintSolver * gtk_constraint_solver_new (void); |