[gtk/wip/ebassi/constraint-layout: 60/69] constraint guide: Make strength tweakable
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/ebassi/constraint-layout: 60/69] constraint guide: Make strength tweakable
- Date: Sun, 30 Jun 2019 23:15:09 +0000 (UTC)
commit a9dfca04e4403b9e7b17e9550a7b837c1b232f2c
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Jun 29 14:18:23 2019 +0000
constraint guide: Make strength tweakable
The strength for the natural width can be used
as a tie-breaker to make instable systems behave
in a more predictable way. This can be seen
in the simple constraints demo in gtk-demo.
demos/gtk-demo/constraints.c | 1 +
gtk/gtkconstraintguide.c | 46 +++++++++++++++++++++++++++++++++++++++++++-
gtk/gtkconstraintguide.h | 8 ++++++++
3 files changed, 54 insertions(+), 1 deletion(-)
---
diff --git a/demos/gtk-demo/constraints.c b/demos/gtk-demo/constraints.c
index 9e2bf3577d..1b6b00b2f5 100644
--- a/demos/gtk-demo/constraints.c
+++ b/demos/gtk-demo/constraints.c
@@ -88,6 +88,7 @@ build_constraints (SimpleGrid *self,
gtk_constraint_guide_set_min_size (guide, 10, 10);
gtk_constraint_guide_set_nat_size (guide, 100, 10);
gtk_constraint_guide_set_max_size (guide, 200, 20);
+ gtk_constraint_guide_set_strength (guide, GTK_CONSTRAINT_STRENGTH_STRONG);
gtk_constraint_layout_add_guide (manager, guide);
gtk_constraint_layout_add_constraint (manager,
diff --git a/gtk/gtkconstraintguide.c b/gtk/gtkconstraintguide.c
index 60220c60f6..b6db1554b2 100644
--- a/gtk/gtkconstraintguide.c
+++ b/gtk/gtkconstraintguide.c
@@ -47,6 +47,8 @@ struct _GtkConstraintGuide
char *name;
+ int strength;
+
int values[LAST_VALUE];
GtkConstraintLayout *layout;
@@ -73,6 +75,7 @@ enum {
PROP_NAT_HEIGHT,
PROP_MAX_WIDTH,
PROP_MAX_HEIGHT,
+ PROP_STRENGTH,
PROP_NAME,
LAST_PROP
};
@@ -137,7 +140,7 @@ gtk_constraint_guide_update_constraint (GtkConstraintGuide *guide,
guide->constraints[index] =
gtk_constraint_solver_add_stay_variable (solver,
var,
- GTK_CONSTRAINT_WEIGHT_MEDIUM);
+ guide->strength);
}
else
{
@@ -232,6 +235,10 @@ gtk_constraint_guide_set_property (GObject *gobject,
}
break;
+ case PROP_STRENGTH:
+ gtk_constraint_guide_set_strength (self, g_value_get_enum (value));
+ break;
+
case PROP_NAME:
gtk_constraint_guide_set_name (self, g_value_get_string (value));
break;
@@ -261,6 +268,10 @@ gtk_constraint_guide_get_property (GObject *gobject,
g_value_set_int (value, self->values[prop_id - 1]);
break;
+ case PROP_STRENGTH:
+ g_value_set_int (value, self->strength);
+ break;
+
case PROP_NAME:
g_value_set_string (value, self->name);
break;
@@ -335,6 +346,15 @@ gtk_constraint_guide_class_init (GtkConstraintGuideClass *class)
G_PARAM_READWRITE|
G_PARAM_EXPLICIT_NOTIFY);
+ guide_props[PROP_STRENGTH] =
+ g_param_spec_enum ("strength",
+ "Strength",
+ "The strength to use for natural size",
+ GTK_TYPE_CONSTRAINT_STRENGTH,
+ GTK_CONSTRAINT_STRENGTH_MEDIUM,
+ G_PARAM_READWRITE|
+ G_PARAM_EXPLICIT_NOTIFY);
+
guide_props[PROP_NAME] =
g_param_spec_string ("name",
"Name",
@@ -538,3 +558,27 @@ gtk_constraint_guide_set_name (GtkConstraintGuide *guide,
guide->name = g_strdup (name);
g_object_notify_by_pspec (G_OBJECT (guide), guide_props[PROP_NAME]);
}
+
+GtkConstraintStrength
+gtk_constraint_guide_get_strength (GtkConstraintGuide *guide)
+{
+ g_return_val_if_fail (GTK_IS_CONSTRAINT_GUIDE (guide),
+ GTK_CONSTRAINT_STRENGTH_MEDIUM);
+
+ return guide->strength;
+}
+
+void
+gtk_constraint_guide_set_strength (GtkConstraintGuide *guide,
+ GtkConstraintStrength strength)
+{
+ g_return_if_fail (GTK_IS_CONSTRAINT_GUIDE (guide));
+
+ if (guide->strength == strength)
+ return;
+
+ guide->strength = strength;
+ g_object_notify_by_pspec (G_OBJECT (guide), guide_props[PROP_STRENGTH]);
+ gtk_constraint_guide_update_constraint (guide, NAT_WIDTH);
+ gtk_constraint_guide_update_constraint (guide, NAT_HEIGHT);
+}
diff --git a/gtk/gtkconstraintguide.h b/gtk/gtkconstraintguide.h
index 429085c1f9..1a489543f8 100644
--- a/gtk/gtkconstraintguide.h
+++ b/gtk/gtkconstraintguide.h
@@ -21,6 +21,7 @@
#include <gtk/gtktypes.h>
#include <gtk/gtkenums.h>
+#include <gtk/gtktypebuiltins.h>
G_BEGIN_DECLS
@@ -67,6 +68,13 @@ GDK_AVAILABLE_IN_ALL
void gtk_constraint_guide_get_max_size (GtkConstraintGuide *guide,
int *width,
int *height);
+
+GDK_AVAILABLE_IN_ALL
+GtkConstraintStrength gtk_constraint_guide_get_strength (GtkConstraintGuide *guide);
+GDK_AVAILABLE_IN_ALL
+void gtk_constraint_guide_set_strength (GtkConstraintGuide *guide,
+ GtkConstraintStrength strength);
+
GDK_AVAILABLE_IN_ALL
void gtk_constraint_guide_set_name (GtkConstraintGuide *guide,
const char *name);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]