From de461712a1e5ae5ba2790ed855bbaf784056330e Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Tue, 17 Nov 2020 21:52:15 -0500 Subject: [PATCH 1/4] constraint-editor: Improve display of constraints No need to go for ALGOL60 style operators when we have Unicode. --- demos/constraint-editor/constraint-editor.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/demos/constraint-editor/constraint-editor.c b/demos/constraint-editor/constraint-editor.c index 62af6e356f..ffbc6a15b0 100644 --- a/demos/constraint-editor/constraint-editor.c +++ b/demos/constraint-editor/constraint-editor.c @@ -212,6 +212,22 @@ get_relation_nick (GtkConstraintRelation relation) return nick; } +static const char * +get_relation_display_name (GtkConstraintRelation relation) +{ + switch (relation) + { + case GTK_CONSTRAINT_RELATION_LE: + return "≤"; + case GTK_CONSTRAINT_RELATION_EQ: + return "="; + case GTK_CONSTRAINT_RELATION_GE: + return "≥"; + default: + return "?"; + } +} + static GtkConstraintStrength get_strength (const char *id) { @@ -347,7 +363,7 @@ constraint_editor_constraint_to_string (GtkConstraint *constraint) name = get_target_name (gtk_constraint_get_target (constraint)); attr = get_attr_nick (gtk_constraint_get_target_attribute (constraint)); - relation = get_relation_nick (gtk_constraint_get_relation (constraint)); + relation = get_relation_display_name (gtk_constraint_get_relation (constraint)); if (name == NULL) name = "[ ]"; From 76b8676955ffa1b346c3c367acbb8b9cdc0f7f63 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Tue, 17 Nov 2020 23:11:16 -0500 Subject: [PATCH 2/4] constraintlayout: Fix parsing of constant constraints We were inadvertently turning constant constraints into constraints against super, due to confusion between target and source attribute. --- gtk/gtkconstraintlayout.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/gtk/gtkconstraintlayout.c b/gtk/gtkconstraintlayout.c index e5d6037962..92fbfcc416 100644 --- a/gtk/gtkconstraintlayout.c +++ b/gtk/gtkconstraintlayout.c @@ -1431,18 +1431,18 @@ constraint_data_to_constraint (const ConstraintData *data, else strength = GTK_CONSTRAINT_STRENGTH_REQUIRED; - if (source != NULL && source_attr != GTK_CONSTRAINT_ATTRIBUTE_NONE) + if (source == NULL && source_attr == GTK_CONSTRAINT_ATTRIBUTE_NONE) + return gtk_constraint_new_constant (target, target_attr, + relation, + data->constant, + strength); + else return gtk_constraint_new (target, target_attr, relation, source, source_attr, data->multiplier, data->constant, strength); - - return gtk_constraint_new_constant (target, target_attr, - relation, - data->constant, - strength); } static GtkConstraintGuide * From 831ebe3ef26ee9069edc8f6162353273eb4dbc43 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Tue, 17 Nov 2020 23:14:29 -0500 Subject: [PATCH 3/4] constraint-editor: Fix saving of constraints g_file_replace_contents take a gsize, so passing -1 for string length does not work here. --- demos/constraint-editor/constraint-editor-window.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demos/constraint-editor/constraint-editor-window.c b/demos/constraint-editor/constraint-editor-window.c index ba25a806ec..2ec0f4cd67 100644 --- a/demos/constraint-editor/constraint-editor-window.c +++ b/demos/constraint-editor/constraint-editor-window.c @@ -300,7 +300,7 @@ save_response_cb (GtkNativeDialog *dialog, model = constraint_view_get_model (CONSTRAINT_VIEW (self->view)); text = serialize_model (model); file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog)); - g_file_replace_contents (file, text, -1, + g_file_replace_contents (file, text, strlen (text), NULL, FALSE, G_FILE_CREATE_NONE, NULL, From 36ef94b002ace20f4a8665b2f15b59f98983add7 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Tue, 17 Nov 2020 23:15:51 -0500 Subject: [PATCH 4/4] constraint-editor: Fix creating constant constraints We were not making the button sensitive in the case of a constant constraint, and we were not properly creating constant constraints either. --- .../constraint-editor-window.c | 20 ++++++++++++++----- demos/constraint-editor/constraint-editor.c | 12 +++++++++-- demos/constraint-editor/constraint-editor.ui | 1 + 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/demos/constraint-editor/constraint-editor-window.c b/demos/constraint-editor/constraint-editor-window.c index 2ec0f4cd67..ca18e27cf8 100644 --- a/demos/constraint-editor/constraint-editor-window.c +++ b/demos/constraint-editor/constraint-editor-window.c @@ -36,7 +36,7 @@ struct _ConstraintEditorWindow G_DEFINE_TYPE(ConstraintEditorWindow, constraint_editor_window, GTK_TYPE_APPLICATION_WINDOW); static GtkConstraintTarget * -find_target (GListModel *model, +find_target (GListModel *model, GtkConstraintTarget *orig) { const char *name; @@ -163,20 +163,30 @@ constraint_editor_window_load (ConstraintEditorWindow *self, GtkConstraint *clone; GtkConstraintTarget *target; GtkConstraintTarget *source; + GtkConstraintAttribute source_attr; item = g_list_model_get_item (list, i); constraint = GTK_CONSTRAINT (item); target = gtk_constraint_get_target (constraint); source = gtk_constraint_get_source (constraint); - clone = gtk_constraint_new (find_target (constraint_view_get_model (CONSTRAINT_VIEW (self->view)), target), + source_attr = gtk_constraint_get_source_attribute (constraint); + + if (source == NULL && source_attr == GTK_CONSTRAINT_ATTRIBUTE_NONE) + clone = gtk_constraint_new_constant (find_target (constraint_view_get_model (CONSTRAINT_VIEW (self->view)), target), gtk_constraint_get_target_attribute (constraint), gtk_constraint_get_relation (constraint), - find_target (constraint_view_get_model (CONSTRAINT_VIEW (self->view)), source), - gtk_constraint_get_target_attribute (constraint), - gtk_constraint_get_multiplier (constraint), gtk_constraint_get_constant (constraint), gtk_constraint_get_strength (constraint)); + else + clone = gtk_constraint_new (find_target (constraint_view_get_model (CONSTRAINT_VIEW (self->view)), target), + gtk_constraint_get_target_attribute (constraint), + gtk_constraint_get_relation (constraint), + find_target (constraint_view_get_model (CONSTRAINT_VIEW (self->view)), source), + source_attr, + gtk_constraint_get_multiplier (constraint), + gtk_constraint_get_constant (constraint), + gtk_constraint_get_strength (constraint)); constraint_view_add_constraint (CONSTRAINT_VIEW (self->view), clone); diff --git a/demos/constraint-editor/constraint-editor.c b/demos/constraint-editor/constraint-editor.c index ffbc6a15b0..6f897b2d8a 100644 --- a/demos/constraint-editor/constraint-editor.c +++ b/demos/constraint-editor/constraint-editor.c @@ -142,6 +142,9 @@ get_target (GListModel *model, { int i; + if (id == NULL) + return NULL; + if (strcmp ("super", id) == 0) return NULL; @@ -347,6 +350,7 @@ source_attr_changed (ConstraintEditor *editor) { gtk_widget_set_sensitive (editor->source, TRUE); gtk_widget_set_sensitive (editor->multiplier, TRUE); + gtk_editable_set_text (GTK_EDITABLE (editor->multiplier), "1"); } } @@ -457,8 +461,12 @@ update_preview (ConstraintEditor *editor) static void update_button (ConstraintEditor *editor) { - if (gtk_combo_box_get_active_id (GTK_COMBO_BOX (editor->target)) != NULL && - gtk_combo_box_get_active_id (GTK_COMBO_BOX (editor->source)) != NULL) + const char *target = gtk_combo_box_get_active_id (GTK_COMBO_BOX (editor->target)); + const char *source = gtk_combo_box_get_active_id (GTK_COMBO_BOX (editor->source)); + const char *source_attr = gtk_combo_box_get_active_id (GTK_COMBO_BOX (editor->source_attr)); + + if (target && + (source || (source_attr && get_target_attr (source_attr) == GTK_CONSTRAINT_ATTRIBUTE_NONE))) gtk_widget_set_sensitive (editor->button, TRUE); else gtk_widget_set_sensitive (editor->button, FALSE); diff --git a/demos/constraint-editor/constraint-editor.ui b/demos/constraint-editor/constraint-editor.ui index d7c0d0e25b..d201aae350 100644 --- a/demos/constraint-editor/constraint-editor.ui +++ b/demos/constraint-editor/constraint-editor.ui @@ -78,6 +78,7 @@ + 2 3