summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2019-06-30 23:01:08 +0000
committerMatthias Clasen <mclasen@redhat.com>2019-06-30 23:02:26 +0000
commit0bd3173549f92fc2a3319c5dfefa5bf6e713b3b3 (patch)
tree3febf414e4d7d4c9d4eaaa5aad23ca99ecf66c3b
parent7ddaef4cf2be180e43451c896fc03cd31899592c (diff)
downloadgtk+-constraint-editor.tar.gz
forgotten filesconstraint-editor
-rw-r--r--demos/constraint-editor/guide-editor.c316
-rw-r--r--demos/constraint-editor/guide-editor.h28
-rw-r--r--demos/constraint-editor/guide-editor.ui188
3 files changed, 532 insertions, 0 deletions
diff --git a/demos/constraint-editor/guide-editor.c b/demos/constraint-editor/guide-editor.c
new file mode 100644
index 0000000000..36633fdbdd
--- /dev/null
+++ b/demos/constraint-editor/guide-editor.c
@@ -0,0 +1,316 @@
+/*
+ * Copyright © 2019 Red Hat, Inc.
+ *
+ * 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/>.
+ *
+ * Authors: Matthias Clasen
+ */
+
+#include "config.h"
+
+#include "guide-editor.h"
+
+struct _GuideEditor
+{
+ GtkWidget parent_instance;
+
+ GtkWidget *grid;
+ GtkWidget *name;
+ GtkWidget *min_width;
+ GtkWidget *min_height;
+ GtkWidget *nat_width;
+ GtkWidget *nat_height;
+ GtkWidget *max_width;
+ GtkWidget *max_height;
+ GtkWidget *strength;
+ GtkWidget *button;
+
+ GtkConstraintGuide *guide;
+
+ gboolean constructed;
+};
+
+enum {
+ PROP_GUIDE = 1,
+ LAST_PROP
+};
+
+static GParamSpec *pspecs[LAST_PROP];
+
+enum {
+ DONE,
+ LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL];
+
+G_DEFINE_TYPE(GuideEditor, guide_editor, GTK_TYPE_WIDGET);
+
+static void
+guide_strength_combo (GtkWidget *combo)
+{
+ gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo), "weak", "Weak");
+ gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo), "medium", "Medium");
+ gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo), "strong", "Strong");
+ gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo), "required", "Required");
+}
+
+static GtkConstraintStrength
+get_strength (const char *id)
+{
+ GtkConstraintStrength strength;
+ GEnumClass *class = g_type_class_ref (GTK_TYPE_CONSTRAINT_STRENGTH);
+ GEnumValue *value = g_enum_get_value_by_nick (class, id);
+ strength = value->value;
+ g_type_class_unref (class);
+
+ return strength;
+}
+
+const char *
+get_strength_nick (GtkConstraintStrength strength)
+{
+ GEnumClass *class = g_type_class_ref (GTK_TYPE_CONSTRAINT_STRENGTH);
+ GEnumValue *value = g_enum_get_value (class, strength);
+ const char *nick = value->value_nick;
+ g_type_class_unref (class);
+
+ return nick;
+}
+
+static void
+create_guide (GtkButton *button,
+ GuideEditor *editor)
+{
+#if 0
+ const char *id;
+ int strength;
+#endif
+ const char *name;
+ int w, h;
+ GtkConstraintGuide *guide;
+
+ //guide = gtk_constraint_guide_new ();
+ if (editor->guide)
+ guide = g_object_ref (editor->guide);
+ else
+ guide = g_object_new (GTK_TYPE_CONSTRAINT_GUIDE, NULL);
+
+ name = gtk_editable_get_text (GTK_EDITABLE (editor->name));
+ g_object_set_data_full (G_OBJECT (guide), "name", g_strdup (name), g_free);
+
+ w = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (editor->min_width));
+ h = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (editor->min_height));
+ //gtk_constraint_guide_set_min_size (guide, w, h);
+ g_object_set (guide, "min-width", w, "min-height", h, NULL);
+
+ w = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (editor->nat_width));
+ h = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (editor->nat_height));
+ //gtk_constraint_guide_set_nat_size (guide, w, h);
+ g_object_set (guide, "nat-width", w, "nat-height", h, NULL);
+
+#if 0
+ w = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (editor->max_width));
+ h = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (editor->max_height));
+ gtk_constraint_guide_set_max_size (guide, w, h);
+
+ id = gtk_combo_box_get_active_id (GTK_COMBO_BOX (editor->strength));
+ strength = get_strength (id);
+ gtk_constraint_guide_set_strength (guide, strength);
+#endif
+
+ g_signal_emit (editor, signals[DONE], 0, guide);
+ g_object_unref (guide);
+}
+
+static void
+guide_editor_init (GuideEditor *editor)
+{
+ gtk_widget_init_template (GTK_WIDGET (editor));
+}
+
+static int guide_counter;
+
+static void
+guide_editor_constructed (GObject *object)
+{
+ GuideEditor *editor = GUIDE_EDITOR (object);
+
+ guide_strength_combo (editor->strength);
+
+ gtk_widget_set_sensitive (editor->max_width, FALSE);
+ gtk_widget_set_sensitive (editor->max_height, FALSE);
+ gtk_widget_set_sensitive (editor->strength, FALSE);
+
+ if (editor->guide)
+ {
+#if 0
+ GtkConstaintStrength strength;
+#endif
+ const char *nick;
+ int w, h;
+
+ nick = (char *)g_object_get_data (G_OBJECT (editor->guide), "name");
+ gtk_editable_set_text (GTK_EDITABLE (editor->name), nick);
+
+ //gtk_constaint_guide_get_min_size (editor->guide, &w, &h);
+ g_object_get (editor->guide, "min-width", &w, "min-height", &h, NULL);
+ gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->min_width), w);
+ gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->min_height), h);
+
+ //gtk_constaint_guide_get_nat_size (editor->guide, &w, &h);
+ g_object_get (editor->guide, "nat-width", &w, "nat-height", &h, NULL);
+ gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->nat_width), w);
+ gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->nat_height), h);
+
+#if 0
+ gtk_constaint_guide_get_max_size (editor->guide, &w, &h);
+ gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->max_width), w);
+ gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->max_height), h);
+
+ strength = gtk_guide_get_strength (editor->guide);
+ nick = get_strength_nick (strength);
+ gtk_combo_box_set_active_id (GTK_COMBO_BOX (editor->strength), nick);
+#endif
+
+ gtk_button_set_label (GTK_BUTTON (editor->button), "Apply");
+ }
+ else
+ {
+ char *name;
+
+ guide_counter++;
+ name = g_strdup_printf ("Guide %d", guide_counter);
+ gtk_editable_set_text (GTK_EDITABLE (editor->name), name);
+ g_free (name);
+
+ gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->min_width), 0.0);
+ gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->min_height), 0.0);
+ gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->nat_width), 0.0);
+ gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->nat_height), 0.0);
+#if 0
+ gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->max_width), G_MAXINT);
+ gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->max_height), G_MAXINT);
+
+ gtk_combo_box_set_active_id (GTK_COMBO_BOX (editor->strength), "medium");
+#endif
+
+ gtk_button_set_label (GTK_BUTTON (editor->button), "Create");
+ }
+
+ editor->constructed = TRUE;
+}
+
+static void
+guide_editor_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GuideEditor *self = GUIDE_EDITOR (object);
+
+ switch (property_id)
+ {
+ case PROP_GUIDE:
+ self->guide = g_value_dup_object (value);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+}
+
+static void
+guide_editor_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GuideEditor *self = GUIDE_EDITOR (object);
+
+ switch (property_id)
+ {
+ case PROP_GUIDE:
+ g_value_set_object (value, self->guide);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+}
+
+static void
+guide_editor_dispose (GObject *object)
+{
+ GuideEditor *self = (GuideEditor *)object;
+
+ g_clear_pointer (&self->grid, gtk_widget_unparent);
+ g_clear_object (&self->guide);
+
+ G_OBJECT_CLASS (guide_editor_parent_class)->dispose (object);
+}
+
+static void
+guide_editor_class_init (GuideEditorClass *class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
+
+ object_class->constructed = guide_editor_constructed;
+ object_class->dispose = guide_editor_dispose;
+ object_class->set_property = guide_editor_set_property;
+ object_class->get_property = guide_editor_get_property;
+
+ pspecs[PROP_GUIDE] =
+ g_param_spec_object ("guide", "guide", "guide",
+ GTK_TYPE_CONSTRAINT_GUIDE,
+ G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY);
+
+ g_object_class_install_properties (object_class, LAST_PROP, pspecs);
+
+ signals[DONE] =
+ g_signal_new ("done",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ NULL,
+ G_TYPE_NONE, 1, GTK_TYPE_CONSTRAINT_GUIDE);
+
+ gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
+
+ gtk_widget_class_set_template_from_resource (widget_class,
+ "/org/gtk/gtk4/constraint-editor/guide-editor.ui");
+
+ gtk_widget_class_bind_template_child (widget_class, GuideEditor, grid);
+ gtk_widget_class_bind_template_child (widget_class, GuideEditor, name);
+ gtk_widget_class_bind_template_child (widget_class, GuideEditor, min_width);
+ gtk_widget_class_bind_template_child (widget_class, GuideEditor, min_height);
+ gtk_widget_class_bind_template_child (widget_class, GuideEditor, nat_width);
+ gtk_widget_class_bind_template_child (widget_class, GuideEditor, nat_height);
+ gtk_widget_class_bind_template_child (widget_class, GuideEditor, max_width);
+ gtk_widget_class_bind_template_child (widget_class, GuideEditor, max_height);
+ gtk_widget_class_bind_template_child (widget_class, GuideEditor, strength);
+ gtk_widget_class_bind_template_child (widget_class, GuideEditor, button);
+
+ gtk_widget_class_bind_template_callback (widget_class, create_guide);
+}
+
+GuideEditor *
+guide_editor_new (GtkConstraintGuide *guide)
+{
+ return g_object_new (GUIDE_EDITOR_TYPE,
+ "guide", guide,
+ NULL);
+}
diff --git a/demos/constraint-editor/guide-editor.h b/demos/constraint-editor/guide-editor.h
new file mode 100644
index 0000000000..d11cb4f3db
--- /dev/null
+++ b/demos/constraint-editor/guide-editor.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright © 2019 Red Hat, Inc
+ *
+ * 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/>.
+ *
+ * Authors: Matthias Clasen
+ */
+
+#pragma once
+
+#include <gtk/gtk.h>
+
+#define GUIDE_EDITOR_TYPE (guide_editor_get_type ())
+
+G_DECLARE_FINAL_TYPE (GuideEditor, guide_editor, GUIDE, EDITOR, GtkWidget)
+
+GuideEditor * guide_editor_new (GtkConstraintGuide *guide);
diff --git a/demos/constraint-editor/guide-editor.ui b/demos/constraint-editor/guide-editor.ui
new file mode 100644
index 0000000000..a788de10bf
--- /dev/null
+++ b/demos/constraint-editor/guide-editor.ui
@@ -0,0 +1,188 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <object class="GtkAdjustment" id="min_width_adj">
+ <property name="lower">0</property>
+ <property name="upper">2147483647</property>
+ <property name="step-increment">1</property>
+ <property name="page-increment">10</property>
+ <property name="page-size">0</property>
+ </object>
+ <object class="GtkAdjustment" id="min_height_adj">
+ <property name="lower">0</property>
+ <property name="upper">2147483647</property>
+ <property name="step-increment">1</property>
+ <property name="page-increment">10</property>
+ <property name="page-size">0</property>
+ </object>
+ <object class="GtkAdjustment" id="nat_width_adj">
+ <property name="lower">0</property>
+ <property name="upper">2147483647</property>
+ <property name="step-increment">1</property>
+ <property name="page-increment">10</property>
+ <property name="page-size">0</property>
+ </object>
+ <object class="GtkAdjustment" id="nat_height_adj">
+ <property name="lower">0</property>
+ <property name="upper">2147483647</property>
+ <property name="step-increment">1</property>
+ <property name="page-increment">10</property>
+ <property name="page-size">0</property>
+ </object>
+ <object class="GtkAdjustment" id="max_width_adj">
+ <property name="lower">0</property>
+ <property name="upper">2147483647</property>
+ <property name="step-increment">1</property>
+ <property name="page-increment">10</property>
+ <property name="page-size">0</property>
+ </object>
+ <object class="GtkAdjustment" id="max_height_adj">
+ <property name="lower">0</property>
+ <property name="upper">2147483647</property>
+ <property name="step-increment">1</property>
+ <property name="page-increment">10</property>
+ <property name="page-size">0</property>
+ </object>
+ <template class="GuideEditor" parent="GtkWidget">
+ <child>
+ <object class="GtkGrid" id="grid">
+ <property name="margin">20</property>
+ <property name="row-spacing">10</property>
+ <property name="column-spacing">10</property>
+ <child>
+ <object class="GtkLabel">
+ <property name="label">Name</property>
+ <layout>
+ <property name="left-attach">0</property>
+ <property name="top-attach">0</property>
+ </layout>
+ </object>
+ </child>
+ <child>
+ <object class="GtkEntry" id="name">
+ <property name="max-width-chars">20</property>
+ <layout>
+ <property name="left-attach">1</property>
+ <property name="top-attach">0</property>
+ <property name="column-span">2</property>
+ </layout>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel">
+ <property name="label">Min Size</property>
+ <layout>
+ <property name="left-attach">0</property>
+ <property name="top-attach">1</property>
+ </layout>
+ </object>
+ </child>
+ <child>
+ <object class="GtkSpinButton" id="min_width">
+ <property name="adjustment">min_width_adj</property>
+ <property name="max-width-chars">5</property>
+ <layout>
+ <property name="left-attach">1</property>
+ <property name="top-attach">1</property>
+ </layout>
+ </object>
+ </child>
+ <child>
+ <object class="GtkSpinButton" id="min_height">
+ <property name="adjustment">min_height_adj</property>
+ <property name="max-width-chars">5</property>
+ <layout>
+ <property name="left-attach">2</property>
+ <property name="top-attach">1</property>
+ </layout>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel">
+ <property name="label">Nat Size</property>
+ <layout>
+ <property name="left-attach">0</property>
+ <property name="top-attach">2</property>
+ </layout>
+ </object>
+ </child>
+ <child>
+ <object class="GtkSpinButton" id="nat_width">
+ <property name="adjustment">nat_width_adj</property>
+ <property name="max-width-chars">5</property>
+ <layout>
+ <property name="left-attach">1</property>
+ <property name="top-attach">2</property>
+ </layout>
+ </object>
+ </child>
+ <child>
+ <object class="GtkSpinButton" id="nat_height">
+ <property name="adjustment">nat_height_adj</property>
+ <property name="max-width-chars">5</property>
+ <layout>
+ <property name="left-attach">2</property>
+ <property name="top-attach">2</property>
+ </layout>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel">
+ <property name="label">Max Size</property>
+ <layout>
+ <property name="left-attach">0</property>
+ <property name="top-attach">3</property>
+ </layout>
+ </object>
+ </child>
+ <child>
+ <object class="GtkSpinButton" id="max_width">
+ <property name="adjustment">max_width_adj</property>
+ <property name="max-width-chars">5</property>
+ <layout>
+ <property name="left-attach">1</property>
+ <property name="top-attach">3</property>
+ </layout>
+ </object>
+ </child>
+ <child>
+ <object class="GtkSpinButton" id="max_height">
+ <property name="adjustment">max_height_adj</property>
+ <property name="max-width-chars">5</property>
+ <layout>
+ <property name="left-attach">2</property>
+ <property name="top-attach">3</property>
+ </layout>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel">
+ <property name="label">Strength</property>
+ <layout>
+ <property name="left-attach">0</property>
+ <property name="top-attach">4</property>
+ </layout>
+ </object>
+ </child>
+ <child>
+ <object class="GtkComboBoxText" id="strength">
+ <layout>
+ <property name="left-attach">1</property>
+ <property name="top-attach">4</property>
+ <property name="column-span">2</property>
+ </layout>
+ </object>
+ </child>
+ <child>
+ <object class="GtkButton" id="button">
+ <property name="label">Create</property>
+ <signal name="clicked" handler="create_guide"/>
+ <layout>
+ <property name="left-attach">2</property>
+ <property name="top-attach">5</property>
+ </layout>
+ </object>
+ </child>
+ </object>
+ </child>
+ </template>
+</interface>