diff options
author | Matthias Clasen <mclasen@redhat.com> | 2019-07-02 22:40:47 +0000 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2019-07-02 22:41:07 +0000 |
commit | a0a3e6ffaa1f62529bd45a1f17df9365060ad53c (patch) | |
tree | 45be121ee00ff14eb0ff477ab945c0848eca0a27 | |
parent | bc1f2ded846d8396670ab9249a470a460ead9f85 (diff) | |
download | gtk+-constraint-editor-fun.tar.gz |
constraint editor: Various minor fixesconstraint-editor-fun
-rw-r--r-- | demos/constraint-editor/constraint-editor.c | 42 | ||||
-rw-r--r-- | demos/constraint-editor/constraint-view.c | 1 |
2 files changed, 35 insertions, 8 deletions
diff --git a/demos/constraint-editor/constraint-editor.c b/demos/constraint-editor/constraint-editor.c index 62af6e356f..6942c0e984 100644 --- a/demos/constraint-editor/constraint-editor.c +++ b/demos/constraint-editor/constraint-editor.c @@ -212,6 +212,19 @@ get_relation_nick (GtkConstraintRelation relation) return nick; } +static const char * +get_relation_to_string (GtkConstraintRelation relation) +{ + switch (relation) + { + case GTK_CONSTRAINT_RELATION_LE: return "≤"; + case GTK_CONSTRAINT_RELATION_EQ: return "="; + case GTK_CONSTRAINT_RELATION_GE: return "≥"; + default: + g_assert_not_reached (); + } +} + static GtkConstraintStrength get_strength (const char *id) { @@ -290,9 +303,17 @@ create_constraint (GtkButton *button, target_attr = get_target_attr (id); id = gtk_combo_box_get_active_id (GTK_COMBO_BOX (editor->source)); - source = get_target (editor->model, id); - id = gtk_combo_box_get_active_id (GTK_COMBO_BOX (editor->source_attr)); - source_attr = get_target_attr (id); + if (id != NULL) + { + source = get_target (editor->model, id); + id = gtk_combo_box_get_active_id (GTK_COMBO_BOX (editor->source_attr)); + source_attr = get_target_attr (id); + } + else + { + source = NULL; + source_attr = GTK_CONSTRAINT_ATTRIBUTE_NONE; + } id = gtk_combo_box_get_active_id (GTK_COMBO_BOX (editor->relation)); relation = get_relation (id); @@ -347,7 +368,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_to_string (gtk_constraint_get_relation (constraint)); if (name == NULL) name = "[ ]"; @@ -408,14 +429,20 @@ update_preview (ConstraintEditor *editor) g_free (relation); constant = gtk_editable_get_text (GTK_EDITABLE (editor->constant)); - c = g_ascii_strtod (constant, NULL); + if (constant[0] != '\0') + c = g_ascii_strtod (constant, NULL); + else + c = 0.0; attr = gtk_combo_box_get_active_id (GTK_COMBO_BOX (editor->source_attr)); if (strcmp (attr, "none") != 0) { name = gtk_combo_box_get_active_id (GTK_COMBO_BOX (editor->source)); multiplier = gtk_editable_get_text (GTK_EDITABLE (editor->multiplier)); - m = g_ascii_strtod (multiplier, NULL); + if (multiplier[0] != '\0') + m = g_ascii_strtod (multiplier, NULL); + else + m = 1.0; if (name == NULL) name = "[ ]"; @@ -441,8 +468,7 @@ 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) + if (gtk_combo_box_get_active_id (GTK_COMBO_BOX (editor->target)) != NULL) gtk_widget_set_sensitive (editor->button, TRUE); else gtk_widget_set_sensitive (editor->button, FALSE); diff --git a/demos/constraint-editor/constraint-view.c b/demos/constraint-editor/constraint-view.c index fb0b7e45d7..3b3807e34b 100644 --- a/demos/constraint-editor/constraint-view.c +++ b/demos/constraint-editor/constraint-view.c @@ -219,6 +219,7 @@ constraint_view_add_child (ConstraintView *view, frame = gtk_frame_new (NULL); gtk_style_context_add_class (gtk_widget_get_style_context (frame), "child"); gtk_widget_set_name (frame, name); + gtk_widget_set_size_request (frame, 100, 25); label = gtk_label_new (name); gtk_container_add (GTK_CONTAINER (frame), label); g_object_bind_property (frame, "name", |