[gtk/wip/ebassi/constraint-layout: 5/5] Add GtkConstraintLayout



commit 17fc78922f05230cc066d2e4b128bd84fcadf348
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Tue Apr 9 15:33:52 2019 +0100

    Add GtkConstraintLayout
    
    A layout manager using GtkConstraintSolver to measure and allocate
    children.

 gtk/gtkconstraint.c       | 178 ++++++++++++++++++++++++++++++++++++++++++++++
 gtk/gtkconstraint.h       |  88 +++++++++++++++++++++++
 gtk/gtkconstraintlayout.c |  53 ++++++++++++++
 gtk/gtkconstraintlayout.h |  49 +++++++++++++
 gtk/gtkenums.h            |  60 ++++++++++++++++
 5 files changed, 428 insertions(+)
---
diff --git a/gtk/gtkconstraint.c b/gtk/gtkconstraint.c
new file mode 100644
index 0000000000..4347eb1789
--- /dev/null
+++ b/gtk/gtkconstraint.c
@@ -0,0 +1,178 @@
+/* gtkconstraint.c: Constraint between two widgets
+ * Copyright 2019  GNOME Foundation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Emmanuele Bassi
+ */
+
+/**
+ * SECTION:gtkconstraint
+ * @Title: GtkConstraint
+ * @Short_description: The description of a constraint
+ *
+ * #GtkConstraint describes a constraint between an attribute on a widget
+ * and another attribute on another widget, expressed as a linear equation
+ * like:
+ *
+ * |[
+ *   target.attr1 = source.attr2 × multiplier + constant
+ * ]|
+ *
+ * Each #GtkConstraint is part of a system that will be solved by a
+ * #GtkConstraintLayout in order to allocate and position each child widget.
+ *
+ * The source and target widgets, as well as their attributes, of a
+ * #GtkConstraint instance are immutable after creation.
+ */
+
+#include "config.h"
+
+#include "gtkconstraint.h"
+#include "gtkconstrainttypesprivate.h"
+
+struct _GtkConstraint
+{
+  GObject parent_instance;
+
+  GtkConstraintAttribute target_attribute;
+  GtkConstraintAttribute source_attribute;
+
+  GtkWidget *target_widget;
+  GtkWidget *source_widget;
+
+  GtkConstraintRelation relation;
+
+  double multiplier;
+  double constant;
+
+  int strength;
+
+  /* A reference to the real constraint inside the
+   * GtkConstraintSolver, so we can remove it when
+   * finalizing the GtkConstraint instance
+   */
+  GtkConstraintRef *constraint_ref;
+};
+
+enum {
+  PROP_TARGET_WIDGET = 1,
+  PROP_TARGET_ATTRIBUTE,
+  PROP_RELATION,
+  PROP_SOURCE_WIDGET,
+  PROP_SOURCE_ATTRIBUTE,
+  PROP_MULTIPLIER,
+  PROP_CONSTANT,
+  PROP_STRENGTH,
+  PROP_ACTIVE,
+  PROP_ATTACHED,
+
+  N_PROPERTIES
+};
+
+static GParamSpec *obj_props[N_PROPERTIES];
+
+G_DEFINE_TYPE (GtkConstraint, gtk_constraint, G_TYPE_OBJECT)
+
+static void
+gtk_constraint_class_init (GtkConstraintClass *klass)
+{
+}
+
+static void
+gtk_constraint_init (GtkConstraint *self)
+{
+}
+
+GtkConstraint *
+gtk_constraint_new (GtkWidget              *target_widget,
+                    GtkConstraintAttribute  target_attribute,
+                    GtkConstraintRelation   relation,
+                    GtkWidget              *source_widget,
+                    GtkConstraintAttribute  source_attribute,
+                    double                  multiplier,
+                    double                  constant,
+                    int                     strength)
+{
+}
+
+GtkConstraint *
+gtk_constraint_new_constant (GtkWidget              *target_widget,
+                             GtkConstraintAttribute  target_attribute,
+                             GtkConstraintRelation   relation,
+                             double                  constant,
+                             int                     strength)
+{
+}
+
+GtkWidget *
+gtk_constraint_get_target_widget (GtkConstraint *constraint)
+{
+}
+
+GtkConstraintAttribute
+gtk_constraint_get_target_attribute (GtkConstraint *constraint)
+{
+}
+
+GtkWidget *
+gtk_constraint_get_source_widget (GtkConstraint *constraint)
+{
+}
+
+GtkConstraintAttribute
+gtk_constraint_get_source_attribute (GtkConstraint *constraint)
+{
+}
+
+GtkConstraintRelation
+gtk_constraint_get_relation (GtkConstraint *constraint)
+{
+}
+
+double
+gtk_constraint_get_multiplier (GtkConstraint *constraint)
+{
+}
+
+double
+gtk_constraint_get_constant (GtkConstraint *constraint)
+{
+}
+
+int
+gtk_constraint_get_strength (GtkConstraint *constraint)
+{
+}
+
+gboolean
+gtk_constraint_is_required (GtkConstraint *constraint)
+{
+}
+
+gboolean
+gtk_constraint_is_attached (GtkConstraint *constraint)
+{
+}
+
+void
+gtk_constraint_set_active (GtkConstraint *constraint,
+                           gboolean       is_active)
+{
+}
+
+gboolean
+gtk_constraint_get_active (GtkConstraint *constraint)
+{
+}
diff --git a/gtk/gtkconstraint.h b/gtk/gtkconstraint.h
new file mode 100644
index 0000000000..9d509aee9a
--- /dev/null
+++ b/gtk/gtkconstraint.h
@@ -0,0 +1,88 @@
+/* gtkconstraint.h: Constraint between two widgets
+ * Copyright 2019  GNOME Foundation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Emmanuele Bassi
+ */
+
+#pragma once
+
+#include <gtk/gtktypes.h>
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_CONSTRAINT (gtk_constraint_get_type ())
+
+/**
+ * GtkConstraint:
+ *
+ * An object describing the relation between two widget attributes.
+ *
+ * All relations are in the form:
+ *
+ * |[<!-- language=plain -->
+ *   target.attr_name = source.attr_name × multiplier + constant
+ * ]|
+ *
+ * A #GtkConstraint is immutable once it's created.
+ */
+GDK_AVAILABLE_IN_ALL
+G_DECLARE_FINAL_TYPE (GtkConstraint, gtk_constraint, GTK, CONSTRAINT, GObject)
+
+GDK_AVAILABLE_IN_ALL
+GtkConstraint *         gtk_constraint_new                      (GtkWidget              *target_widget,
+                                                                 GtkConstraintAttribute  target_attribute,
+                                                                 GtkConstraintRelation   relation,
+                                                                 GtkWidget              *source_widget,
+                                                                 GtkConstraintAttribute  source_attribute,
+                                                                 double                  multiplier,
+                                                                 double                  constant,
+                                                                 int                     strength);
+GDK_AVAILABLE_IN_ALL
+GtkConstraint *         gtk_constraint_new_constant             (GtkWidget              *target_widget,
+                                                                 GtkConstraintAttribute  target_attribute,
+                                                                 GtkConstraintRelation   relation,
+                                                                 double                  constant,
+                                                                 int                     strength);
+
+GDK_AVAILABLE_IN_ALL
+GtkWidget *             gtk_constraint_get_target_widget        (GtkConstraint          *constraint);
+GDK_AVAILABLE_IN_ALL
+GtkConstraintAttribute  gtk_constraint_get_target_attribute     (GtkConstraint          *constraint);
+GDK_AVAILABLE_IN_ALL
+GtkWidget *             gtk_constraint_get_source_widget        (GtkConstraint          *constraint);
+GDK_AVAILABLE_IN_ALL
+GtkConstraintAttribute  gtk_constraint_get_source_attribute     (GtkConstraint          *constraint);
+GDK_AVAILABLE_IN_ALL
+GtkConstraintRelation   gtk_constraint_get_relation             (GtkConstraint          *constraint);
+GDK_AVAILABLE_IN_ALL
+double                  gtk_constraint_get_multiplier           (GtkConstraint          *constraint);
+GDK_AVAILABLE_IN_ALL
+double                  gtk_constraint_get_constant             (GtkConstraint          *constraint);
+GDK_AVAILABLE_IN_ALL
+int                     gtk_constraint_get_strength             (GtkConstraint          *constraint);
+
+GDK_AVAILABLE_IN_ALL
+gboolean                gtk_constraint_is_required              (GtkConstraint          *constraint);
+GDK_AVAILABLE_IN_ALL
+gboolean                gtk_constraint_is_attached              (GtkConstraint          *constraint);
+
+GDK_AVAILABLE_IN_ALL
+void                    gtk_constraint_set_active               (GtkConstraint          *constraint,
+                                                                 gboolean                is_active);
+GDK_AVAILABLE_IN_ALL
+gboolean                gtk_constraint_get_active               (GtkConstraint          *constraint);
+
+G_END_DECLS
diff --git a/gtk/gtkconstraintlayout.c b/gtk/gtkconstraintlayout.c
new file mode 100644
index 0000000000..05ea58f877
--- /dev/null
+++ b/gtk/gtkconstraintlayout.c
@@ -0,0 +1,53 @@
+/* gtkconstraintlayout.c: Layout manager using constraints
+ * Copyright 2019  GNOME Foundation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Emmanuele Bassi
+ */
+
+/**
+ * SECTION: gtkconstraintlayout
+ * @Title: GtkConstraintLayout
+ * @Short_description: A layout manager using constraints
+ *
+ * GtkConstraintLayout is a layout manager that uses relations between
+ * widget attributes, expressed via #GtkConstraint instances, to measure
+ * and allocate widgets.
+ */
+
+#include "config.h"
+
+#include "gtkconstraintlayout.h"
+
+#include "gtkdebug.h"
+#include "gtkprivate.h"
+
+G_DEFINE_TYPE (GtkConstraintLayout, gtk_constraint_layout, GTK_TYPE_LAYOUT_MANAGER)
+
+static void
+gtk_constraint_layout_class_init (GtkConstraintLayoutClass *klass)
+{
+}
+
+static void
+gtk_constraint_layout_init (GtkConstraintLayout *self)
+{
+}
+
+GtkLayoutManager *
+gtk_constraint_layout_new (void)
+{
+  return g_object_new (GTK_TYPE_CONSTRAINT_LAYOUT, NULL);
+}
diff --git a/gtk/gtkconstraintlayout.h b/gtk/gtkconstraintlayout.h
new file mode 100644
index 0000000000..4f82ba48b9
--- /dev/null
+++ b/gtk/gtkconstraintlayout.h
@@ -0,0 +1,49 @@
+/* gtkconstraintlayout.h: Layout manager using constraints
+ * Copyright 2019  GNOME Foundation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Emmanuele Bassi
+ */
+#pragma once
+
+#include <gtk/gtklayoutmanager.h>
+#include <gtk/gtkconstraint.h>
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_CONSTRAINT_LAYOUT (gtk_constraint_layout_get_type ())
+#define GTK_TYPE_CONSTRAINT_LAYOUT_CHILD (gtk_constraint_layout_child_get_type ())
+
+/**
+ * GtkConstraintLayout:
+ *
+ * A layout manager using #GtkConstraint to describe
+ * relations between widgets.
+ */
+GDK_AVAILABLE_IN_ALL
+G_DECLARE_FINAL_TYPE (GtkConstraintLayout, gtk_constaint_layout, GTK, CONSTRAINT_LAYOUT, GtkLayoutManager)
+
+GDK_AVAILABLE_IN_ALL
+GtkLayoutManager *      gtk_constraint_layout_new       (void);
+
+/**
+ * GtkConstraintLayoutChild:
+ *
+ * A #GtkLayoutChild in a #GtkConstraintLayout.
+ */
+GDK_AVAILABLE_IN_ALL
+G_DECLARE_FINAL_TYPE (GtkConstraintLayoutChild, gtk_constraint_layout_child, GTK, CONSTRAINT_LAYOUT_CHILD, 
GtkLayoutChild)
+
+G_END_DECLS
diff --git a/gtk/gtkenums.h b/gtk/gtkenums.h
index c253fa6bba..41e9837124 100644
--- a/gtk/gtkenums.h
+++ b/gtk/gtkenums.h
@@ -1050,4 +1050,64 @@ typedef enum {
   GTK_CONSTRAINT_RELATION_GE = 1
 } GtkConstraintRelation;
 
+/**
+ * GtkConstraintStrength:
+ * @GTK_CONSTRAINT_STRENGTH_REQUIRED: The constraint is required towards solving the layout
+ * @GTK_CONSTRAINT_STRENGTH_STRONG: A strong constraint
+ * @GTK_CONSTRAINT_STRENGTH_MEDIUM: A medium constraint
+ * @GTK_CONSTRAINT_STRENGTH_WEAK: A weak constraint
+ *
+ * The strength of a constraint, expressed as a symbolic constant.
+ *
+ * The strength of a #GtkConstraint can be expressed with any positive
+ * integer; the values of this enumeration can be used for readability.
+ */
+typedef enum {
+  GTK_CONSTRAINT_STRENGTH_REQUIRED = 0,
+  GTK_CONSTRAINT_STRENGTH_STRONG = -1,
+  GTK_CONSTRAINT_STRENGTH_MEDIUM = -2,
+  GTK_CONSTRAINT_STRENGTH_WEAK = -3
+} GtkConstraintStrength;
+
+/**
+ * GtkConstraintAttribute:
+ * @GTK_CONSTRAINT_ATTRIBUTE_INVALID: Invalid attribute, used for constant
+ *   relations
+ * @GTK_CONSTRAINT_ATTRIBUTE_LEFT: The left edge of a widget, regardless of
+ *   text direction
+ * @GTK_CONSTRAINT_ATTRIBUTE_RIGHT: The right edge of a widget, regardless
+ *   of text direction
+ * @GTK_CONSTRAINT_ATTRIBUTE_TOP: The top edge of a widget
+ * @GTK_CONSTRAINT_ATTRIBUTE_BOTTOM: The bottom edge of a widget
+ * @GTK_CONSTRAINT_ATTRIBUTE_START: The leading edge of a widget, depending
+ *   on text direction; equivalent to %GTK_CONSTRAINT_ATTRIBUTE_LEFT for LTR
+ *   languages, and %GTK_CONSTRAINT_ATTRIBUTE_RIGHT for RTL ones
+ * @GTK_CONSTRAINT_ATTRIBUTE_END: The trailing edge of a widget, depending
+ *   on text direction; equivalent to %GTK_CONSTRAINT_ATTRIBUTE_RIGHT for LTR
+ *   languages, and %GTK_CONSTRAINT_ATTRIBUTE_LEFT for RTL ones
+ * @GTK_CONSTRAINT_ATTRIBUTE_WIDTH: The width of a widget
+ * @GTK_CONSTRAINT_ATTRIBUTE_HEIGHT: The height of a widget
+ * @GTK_CONSTRAINT_ATTRIBUTE_CENTER_X: The center of a widget, on the
+ *   horizontal axis
+ * @GTK_CONSTRAINT_ATTRIBUTE_CENTER_Y: The center of a widget, on the
+ *   vertical axis
+ * @GTK_CONSTRAINT_ATTRIBUTE_BASELINE: The baseline of a widget
+ *
+ * The widget attributes that can be used when creating a #GtkConstraint.
+ */
+typedef enum {
+  GTK_CONSTRAINT_ATTRIBUTE_INVALID,
+  GTK_CONSTRAINT_ATTRIBUTE_LEFT,
+  GTK_CONSTRAINT_ATTRIBUTE_RIGHT,
+  GTK_CONSTRAINT_ATTRIBUTE_TOP,
+  GTK_CONSTRAINT_ATTRIBUTE_BOTTOM,
+  GTK_CONSTRAINT_ATTRIBUTE_START,
+  GTK_CONSTRAINT_ATTRIBUTE_END,
+  GTK_CONSTRAINT_ATTRIBUTE_WIDTH,
+  GTK_CONSTRAINT_ATTRIBUTE_HEIGHT,
+  GTK_CONSTRAINT_ATTRIBUTE_CENTER_X,
+  GTK_CONSTRAINT_ATTRIBUTE_CENTER_Y,
+  GTK_CONSTRAINT_ATTRIBUTE_BASELINE
+} GtkConstraintAttribute;
+
 #endif /* __GTK_ENUMS_H__ */


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