[gtk/matthiasc/for-master: 2/6] Add another constraints demo




commit 051336fa26ef90a246ee01301fad21a2bf48dd73
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Oct 30 00:22:47 2020 -0400

    Add another constraints demo
    
    This one attempts to use constraints in a ui file.
    It doesn't work.

 demos/gtk-demo/constraints.ui     | 113 ++++++++++++++++++++++++++++++++++++++
 demos/gtk-demo/constraints4.c     |  56 +++++++++++++++++++
 demos/gtk-demo/demo.gresource.xml |   4 ++
 demos/gtk-demo/meson.build        |   1 +
 4 files changed, 174 insertions(+)
---
diff --git a/demos/gtk-demo/constraints.ui b/demos/gtk-demo/constraints.ui
new file mode 100644
index 0000000000..37a58ba87f
--- /dev/null
+++ b/demos/gtk-demo/constraints.ui
@@ -0,0 +1,113 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <object class="GtkWindow" id="window1">
+    <property name="title" translatable="yes">Constraints</property>
+    <child>
+      <object class="ConstraintsGrid">
+        <property name="layout-manager">
+          <object class="GtkConstraintLayout">
+            <constraints>
+              <guide name="space"
+                     min-width="10" min-height="10"
+                     nat-width="100" nat-height="10"
+                     max-width="200" max-height="20"
+                     strength="strong"/>
+              <constraint target="button1" target-attribute="start"
+                          relation="ge"
+                          constant="0"
+                          strength="required"/>
+              <constraint target="button1" target-attribute="top"
+                          relation="ge"
+                          constant="0"
+                          strength="required"/>
+              <constraint target="button1" target-attribute="width"
+                          relation="le"
+                          constant="200"
+                          strength="required"/>
+              <constraint target="super" target-attribute="start"
+                          relation="eq"
+                          source="button1" source-attribute="start"
+                          constant="-8"
+                          strength="required"/>
+              <constraint target="button1" target-attribute="width"
+                          relation="eq"
+                          source="button2" source-attribute="width"
+                          strength="required"/>
+              <constraint target="button1" target-attribute="end"
+                          relation="eq"
+                          source="space" source-attribute="start"
+                          strength="required"/>
+              <constraint target="space" target-attribute="end"
+                          relation="eq"
+                          source="button2" source-attribute="start"
+                          strength="required"/>
+              <constraint target="button2" target-attribute="end"
+                          relation="eq"
+                          source="super" source-attribute="end"
+                          constant="-8"
+                          strength="required"/>
+              <constraint target="super" target-attribute="start"
+                          relation="eq"
+                          source="button3" source-attribute="start"
+                          constant="-8"
+                          strength="required"/>
+              <constraint target="button3" target-attribute="end"
+                          relation="eq"
+                          source="super" source-attribute="end"
+                          constant="-8"
+                          strength="required"/>
+              <constraint target="super" target-attribute="top"
+                          relation="eq"
+                          source="button1" source-attribute="top"
+                          constant="-8"
+                          strength="required"/>
+              <constraint target="super" target-attribute="top"
+                          relation="eq"
+                          source="button2" source-attribute="top"
+                          constant="-8"
+                          strength="required"/>
+              <constraint target="button1" target-attribute="bottom"
+                          relation="eq"
+                          source="button3" source-attribute="top"
+                          constant="-12"
+                          strength="required"/>
+              <constraint target="button2" target-attribute="bottom"
+                          relation="eq"
+                          source="button3" source-attribute="top"
+                          constant="-12"
+                          strength="required"/>
+              <constraint target="button3" target-attribute="height"
+                          relation="eq"
+                          source="button1" source-attribute="height"
+                          strength="required"/>
+              <constraint target="button3" target-attribute="height"
+                          relation="eq"
+                          source="button2" source-attribute="height"
+                          strength="required"/>
+              <constraint target="button3" target-attribute="bottom"
+                          relation="eq"
+                          source="super" source-attribute="bottom"
+                          constant="-8"
+                          strength="required"/>
+            </constraints>
+          </object>
+        </property>
+        <child>
+          <object class="GtkButton" id="button1">
+            <property name="label">Child 1</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkButton" id="button2">
+            <property name="label">Child 2</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkButton" id="button3">
+            <property name="label">Child 3</property>
+          </object>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>
diff --git a/demos/gtk-demo/constraints4.c b/demos/gtk-demo/constraints4.c
new file mode 100644
index 0000000000..012bc5a107
--- /dev/null
+++ b/demos/gtk-demo/constraints4.c
@@ -0,0 +1,56 @@
+/* Constraints/Builder
+ *
+ * GtkConstraintLayout allows defining constraints using a
+ * compact syntax called Visual Format Language, or VFL.
+ */
+
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+
+G_DECLARE_FINAL_TYPE (ConstraintsGrid, constraints_grid, CONSTRAINTS, GRID, GtkWidget)
+
+struct _ConstraintsGrid
+{
+  GtkWidget parent_instance;
+};
+
+G_DEFINE_TYPE (ConstraintsGrid, constraints_grid, GTK_TYPE_WIDGET)
+
+static void
+constraints_grid_init (ConstraintsGrid *grid)
+{
+}
+
+static void
+constraints_grid_class_init (ConstraintsGridClass *klass)
+{
+}
+
+GtkWidget *
+do_constraints4 (GtkWidget *do_widget)
+{
+ static GtkWidget *window;
+
+ if (!window)
+   {
+     GtkBuilder *builder;
+
+     g_type_ensure (constraints_grid_get_type ());
+
+     builder = gtk_builder_new_from_resource ("/constraints4/constraints.ui");
+
+     window = GTK_WIDGET (gtk_builder_get_object (builder, "window1"));
+     gtk_window_set_display (GTK_WINDOW (window),
+                             gtk_widget_get_display (do_widget));
+     g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
+
+     g_object_unref (builder);
+   }
+
+ if (!gtk_widget_get_visible (window))
+   gtk_widget_show (window);
+ else
+   gtk_window_destroy (GTK_WINDOW (window));
+
+ return window;
+}
diff --git a/demos/gtk-demo/demo.gresource.xml b/demos/gtk-demo/demo.gresource.xml
index bcb2ebc3b5..89d88edaa3 100644
--- a/demos/gtk-demo/demo.gresource.xml
+++ b/demos/gtk-demo/demo.gresource.xml
@@ -18,6 +18,9 @@
     <file>demoimage.c</file>
     <file>demoimage.h</file>
   </gresource>
+  <gresource prefix="/constraints4">
+    <file>constraints.ui</file>
+  </gresource>
   <gresource prefix="/css_accordion">
     <file>css_accordion.css</file>
     <file>reset.css</file>
@@ -242,6 +245,7 @@
     <file>constraints.c</file>
     <file>constraints2.c</file>
     <file>constraints3.c</file>
+    <file>constraints4.c</file>
     <file>css_accordion.c</file>
     <file>css_basics.c</file>
     <file>css_blendmodes.c</file>
diff --git a/demos/gtk-demo/meson.build b/demos/gtk-demo/meson.build
index 2d1efc4170..39070bb925 100644
--- a/demos/gtk-demo/meson.build
+++ b/demos/gtk-demo/meson.build
@@ -9,6 +9,7 @@ demos = files([
   'constraints.c',
   'constraints2.c',
   'constraints3.c',
+  'constraints4.c',
   'css_accordion.c',
   'css_basics.c',
   'css_blendmodes.c',


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