constraint-editor: Deprecation cleanup

Drop all uses of deprecated API.
This commit is contained in:
Matthias Clasen 2023-08-03 18:16:16 -04:00
parent 26018107d6
commit b4ab398e0d
5 changed files with 241 additions and 162 deletions

View File

@ -483,6 +483,8 @@ constraint_editor_window_class_init (ConstraintEditorWindowClass *class)
GObjectClass *object_class = G_OBJECT_CLASS (class); GObjectClass *object_class = G_OBJECT_CLASS (class);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class); GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
g_type_ensure (CONSTRAINT_VIEW_TYPE);
object_class->dispose = constraint_editor_window_dispose; object_class->dispose = constraint_editor_window_dispose;
gtk_widget_class_set_template_from_resource (widget_class, gtk_widget_class_set_template_from_resource (widget_class,

View File

@ -20,8 +20,7 @@
#include "config.h" #include "config.h"
#include "constraint-editor.h" #include "constraint-editor.h"
#include "constraint-view.h"
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
struct _ConstraintEditor struct _ConstraintEditor
{ {
@ -66,7 +65,7 @@ static const char *
get_target_name (GtkConstraintTarget *target) get_target_name (GtkConstraintTarget *target)
{ {
if (target == NULL) if (target == NULL)
return "super"; return "Super";
else if (GTK_IS_WIDGET (target)) else if (GTK_IS_WIDGET (target))
return gtk_widget_get_name (GTK_WIDGET (target)); return gtk_widget_get_name (GTK_WIDGET (target));
else if (GTK_IS_CONSTRAINT_GUIDE (target)) else if (GTK_IS_CONSTRAINT_GUIDE (target))
@ -80,62 +79,29 @@ constraint_target_combo (GListModel *model,
GtkWidget *combo, GtkWidget *combo,
gboolean is_source) gboolean is_source)
{ {
GtkStringList *targets;
int i; int i;
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo), "super", "Super"); targets = gtk_string_list_new (NULL);
gtk_string_list_append (targets, "Super");
if (model) if (model)
{ {
for (i = 0; i < g_list_model_get_n_items (model); i++) for (i = 0; i < g_list_model_get_n_items (model); i++)
{ {
GObject *item = g_list_model_get_object (model, i); GObject *item = g_list_model_get_object (model, i);
const char *name;
if (GTK_IS_CONSTRAINT (item)) if (GTK_IS_CONSTRAINT (item))
continue; continue;
name = get_target_name (GTK_CONSTRAINT_TARGET (item)); gtk_string_list_append (targets, get_target_name (GTK_CONSTRAINT_TARGET (item)));
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo), name, name);
g_object_unref (item); g_object_unref (item);
} }
} }
}
static void gtk_drop_down_set_model (GTK_DROP_DOWN (combo), G_LIST_MODEL (targets));
constraint_attribute_combo (GtkWidget *combo, g_object_unref (targets);
gboolean is_source)
{
if (is_source)
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo), "none", "None");
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo), "left", "Left");
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo), "right", "Right");
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo), "top", "Top");
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo), "bottom", "Bottom");
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo), "start", "Start");
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo), "end", "End");
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo), "width", "Width");
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo), "height", "Height");
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo), "center-x", "Center X");
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo), "center-y", "Center Y");
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo), "baseline", "Baseline");
}
static void
constraint_relation_combo (GtkWidget *combo)
{
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo), "le", "");
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo), "eq", "=");
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo), "ge", "");
}
static void
constraint_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 gpointer static gpointer
@ -147,7 +113,7 @@ get_target (GListModel *model,
if (id == NULL) if (id == NULL)
return NULL; return NULL;
if (strcmp ("super", id) == 0) if (strcmp ("Super", id) == 0)
return NULL; return NULL;
for (i = 0; i < g_list_model_get_n_items (model); i++) for (i = 0; i < g_list_model_get_n_items (model); i++)
@ -171,16 +137,65 @@ get_target (GListModel *model,
return NULL; return NULL;
} }
static GtkConstraintAttribute static void
get_target_attr (const char *id) select_target (GtkDropDown *combo,
const char *target_name)
{ {
GtkConstraintAttribute attr; GListModel *model = gtk_drop_down_get_model (combo);
GEnumClass *class = g_type_class_ref (GTK_TYPE_CONSTRAINT_ATTRIBUTE);
GEnumValue *value = g_enum_get_value_by_nick (class, id);
attr = value->value;
g_type_class_unref (class);
return attr; for (unsigned int i = 0; i < g_list_model_get_n_items (model); i++)
{
GtkStringObject *s = g_list_model_get_item (model, i);
g_object_unref (s);
if (strcmp (target_name, gtk_string_object_get_string (s)) == 0)
{
gtk_drop_down_set_selected (GTK_DROP_DOWN (combo), i);
return;
}
}
}
static GtkConstraintAttribute
get_attr (unsigned int id)
{
switch (id)
{
case 0: return GTK_CONSTRAINT_ATTRIBUTE_NONE;
case 1: return GTK_CONSTRAINT_ATTRIBUTE_LEFT;
case 2: return GTK_CONSTRAINT_ATTRIBUTE_RIGHT;
case 3: return GTK_CONSTRAINT_ATTRIBUTE_TOP;
case 4: return GTK_CONSTRAINT_ATTRIBUTE_BOTTOM;
case 5: return GTK_CONSTRAINT_ATTRIBUTE_START;
case 6: return GTK_CONSTRAINT_ATTRIBUTE_END;
case 7: return GTK_CONSTRAINT_ATTRIBUTE_WIDTH;
case 8: return GTK_CONSTRAINT_ATTRIBUTE_HEIGHT;
case 9: return GTK_CONSTRAINT_ATTRIBUTE_CENTER_X;
case 10: return GTK_CONSTRAINT_ATTRIBUTE_CENTER_Y;
case 11: return GTK_CONSTRAINT_ATTRIBUTE_BASELINE;
default: g_assert_not_reached ();
}
}
static unsigned int
get_attr_id (GtkConstraintAttribute attr)
{
switch (attr)
{
case GTK_CONSTRAINT_ATTRIBUTE_NONE: return 0;
case GTK_CONSTRAINT_ATTRIBUTE_LEFT: return 1;
case GTK_CONSTRAINT_ATTRIBUTE_RIGHT: return 2;
case GTK_CONSTRAINT_ATTRIBUTE_TOP: return 3;
case GTK_CONSTRAINT_ATTRIBUTE_BOTTOM: return 4;
case GTK_CONSTRAINT_ATTRIBUTE_START: return 5;
case GTK_CONSTRAINT_ATTRIBUTE_END: return 6;
case GTK_CONSTRAINT_ATTRIBUTE_WIDTH: return 7;
case GTK_CONSTRAINT_ATTRIBUTE_HEIGHT: return 8;
case GTK_CONSTRAINT_ATTRIBUTE_CENTER_X: return 9;
case GTK_CONSTRAINT_ATTRIBUTE_CENTER_Y: return 10;
case GTK_CONSTRAINT_ATTRIBUTE_BASELINE: return 11;
default: g_assert_not_reached ();
}
} }
static const char * static const char *
@ -195,15 +210,27 @@ get_attr_nick (GtkConstraintAttribute attr)
} }
static GtkConstraintRelation static GtkConstraintRelation
get_relation (const char *id) get_relation (unsigned int id)
{ {
GtkConstraintRelation relation; switch (id)
GEnumClass *class = g_type_class_ref (GTK_TYPE_CONSTRAINT_RELATION); {
GEnumValue *value = g_enum_get_value_by_nick (class, id); case 0: return GTK_CONSTRAINT_RELATION_LE;
relation = value->value; case 1: return GTK_CONSTRAINT_RELATION_EQ;
g_type_class_unref (class); case 2: return GTK_CONSTRAINT_RELATION_GE;
default: g_assert_not_reached ();
}
}
return relation; static unsigned int
get_relation_id (GtkConstraintRelation relation)
{
switch (relation)
{
case GTK_CONSTRAINT_RELATION_LE: return 0;
case GTK_CONSTRAINT_RELATION_EQ: return 1;
case GTK_CONSTRAINT_RELATION_GE: return 2;
default: g_assert_not_reached ();
}
} }
static const char * static const char *
@ -234,15 +261,29 @@ get_relation_display_name (GtkConstraintRelation relation)
} }
static GtkConstraintStrength static GtkConstraintStrength
get_strength (const char *id) get_strength (unsigned int id)
{ {
GtkConstraintStrength strength; switch (id)
GEnumClass *class = g_type_class_ref (GTK_TYPE_CONSTRAINT_STRENGTH); {
GEnumValue *value = g_enum_get_value_by_nick (class, id); case 0: return GTK_CONSTRAINT_STRENGTH_WEAK;
strength = value->value; case 1: return GTK_CONSTRAINT_STRENGTH_MEDIUM;
g_type_class_unref (class); case 2: return GTK_CONSTRAINT_STRENGTH_STRONG;
case 3: return GTK_CONSTRAINT_STRENGTH_REQUIRED;
default: g_assert_not_reached ();
}
}
return strength; static unsigned int
get_strength_id (GtkConstraintStrength strength)
{
switch (strength)
{
case GTK_CONSTRAINT_STRENGTH_WEAK: return 0;
case GTK_CONSTRAINT_STRENGTH_MEDIUM: return 1;
case GTK_CONSTRAINT_STRENGTH_STRONG: return 2;
case GTK_CONSTRAINT_STRENGTH_REQUIRED: return 3;
default: g_assert_not_reached ();
}
} }
static const char * static const char *
@ -294,7 +335,7 @@ static void
create_constraint (GtkButton *button, create_constraint (GtkButton *button,
ConstraintEditor *editor) ConstraintEditor *editor)
{ {
const char *id; gpointer obj;
gpointer target; gpointer target;
GtkConstraintAttribute target_attr; GtkConstraintAttribute target_attr;
gpointer source; gpointer source;
@ -305,25 +346,27 @@ create_constraint (GtkButton *button,
int strength; int strength;
GtkConstraint *constraint; GtkConstraint *constraint;
id = gtk_combo_box_get_active_id (GTK_COMBO_BOX (editor->target)); obj = gtk_drop_down_get_selected_item (GTK_DROP_DOWN (editor->target));
target = get_target (editor->model, id); if (obj)
id = gtk_combo_box_get_active_id (GTK_COMBO_BOX (editor->target_attr)); target = get_target (editor->model, gtk_string_object_get_string (GTK_STRING_OBJECT (obj)));
target_attr = get_target_attr (id); else
target = NULL;
target_attr = get_attr (gtk_drop_down_get_selected (GTK_DROP_DOWN (editor->target_attr)));
id = gtk_combo_box_get_active_id (GTK_COMBO_BOX (editor->source)); obj = gtk_drop_down_get_selected_item (GTK_DROP_DOWN (editor->source));
source = get_target (editor->model, id); if (obj)
id = gtk_combo_box_get_active_id (GTK_COMBO_BOX (editor->source_attr)); source = get_target (editor->model, gtk_string_object_get_string (GTK_STRING_OBJECT (obj)));
source_attr = get_target_attr (id); else
source = NULL;
source_attr = get_attr (gtk_drop_down_get_selected (GTK_DROP_DOWN(editor->source_attr)));
id = gtk_combo_box_get_active_id (GTK_COMBO_BOX (editor->relation)); relation = get_relation (gtk_drop_down_get_selected (GTK_DROP_DOWN (editor->relation)));
relation = get_relation (id);
multiplier = g_ascii_strtod (gtk_editable_get_text (GTK_EDITABLE (editor->multiplier)), NULL); multiplier = g_ascii_strtod (gtk_editable_get_text (GTK_EDITABLE (editor->multiplier)), NULL);
constant = g_ascii_strtod (gtk_editable_get_text (GTK_EDITABLE (editor->constant)), NULL); constant = g_ascii_strtod (gtk_editable_get_text (GTK_EDITABLE (editor->constant)), NULL);
id = gtk_combo_box_get_active_id (GTK_COMBO_BOX (editor->strength)); strength = get_strength (gtk_drop_down_get_selected (GTK_DROP_DOWN (editor->strength)));
strength = get_strength (id);
constraint = gtk_constraint_new (target, target_attr, constraint = gtk_constraint_new (target, target_attr,
relation, relation,
@ -338,12 +381,9 @@ create_constraint (GtkButton *button,
static void static void
source_attr_changed (ConstraintEditor *editor) source_attr_changed (ConstraintEditor *editor)
{ {
const char *id; if (get_attr (gtk_drop_down_get_selected (GTK_DROP_DOWN (editor->source_attr))) == GTK_CONSTRAINT_ATTRIBUTE_NONE)
id = gtk_combo_box_get_active_id (GTK_COMBO_BOX (editor->source_attr));
if (strcmp (id, "none") == 0)
{ {
gtk_combo_box_set_active (GTK_COMBO_BOX (editor->source), -1); gtk_drop_down_set_selected (GTK_DROP_DOWN (editor->source), GTK_INVALID_LIST_POSITION);
gtk_editable_set_text (GTK_EDITABLE (editor->multiplier), ""); gtk_editable_set_text (GTK_EDITABLE (editor->multiplier), "");
gtk_widget_set_sensitive (editor->source, FALSE); gtk_widget_set_sensitive (editor->source, FALSE);
gtk_widget_set_sensitive (editor->multiplier, FALSE); gtk_widget_set_sensitive (editor->multiplier, FALSE);
@ -409,7 +449,7 @@ update_preview (ConstraintEditor *editor)
GString *str; GString *str;
const char *name; const char *name;
const char *attr; const char *attr;
char *relation; const char *relation;
const char *multiplier; const char *multiplier;
const char *constant; const char *constant;
double c, m; double c, m;
@ -419,23 +459,22 @@ update_preview (ConstraintEditor *editor)
str = g_string_new (""); str = g_string_new ("");
name = gtk_combo_box_get_active_id (GTK_COMBO_BOX (editor->target)); name = gtk_string_object_get_string (GTK_STRING_OBJECT (gtk_drop_down_get_selected_item (GTK_DROP_DOWN (editor->target))));
attr = gtk_combo_box_get_active_id (GTK_COMBO_BOX (editor->target_attr)); attr = get_attr_nick (get_attr (gtk_drop_down_get_selected ((GTK_DROP_DOWN (editor->target_attr)))));
relation = gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT (editor->relation)); relation = get_relation_nick (get_relation (gtk_drop_down_get_selected (GTK_DROP_DOWN (editor->relation))));
if (name == NULL) if (name == NULL)
name = "[ ]"; name = "[ ]";
g_string_append_printf (str, "%s.%s %s ", name, attr, relation); g_string_append_printf (str, "%s.%s %s ", name, attr, relation);
g_free (relation);
constant = gtk_editable_get_text (GTK_EDITABLE (editor->constant)); constant = gtk_editable_get_text (GTK_EDITABLE (editor->constant));
c = g_ascii_strtod (constant, NULL); c = g_ascii_strtod (constant, NULL);
attr = gtk_combo_box_get_active_id (GTK_COMBO_BOX (editor->source_attr)); attr = get_attr_nick (get_attr (gtk_drop_down_get_selected (GTK_DROP_DOWN (editor->source_attr))));
if (strcmp (attr, "none") != 0) if (strcmp (attr, "none") != 0)
{ {
name = gtk_combo_box_get_active_id (GTK_COMBO_BOX (editor->source)); name = gtk_string_object_get_string (GTK_STRING_OBJECT (gtk_drop_down_get_selected_item (GTK_DROP_DOWN (editor->source))));
multiplier = gtk_editable_get_text (GTK_EDITABLE (editor->multiplier)); multiplier = gtk_editable_get_text (GTK_EDITABLE (editor->multiplier));
m = g_ascii_strtod (multiplier, NULL); m = g_ascii_strtod (multiplier, NULL);
@ -463,12 +502,18 @@ update_preview (ConstraintEditor *editor)
static void static void
update_button (ConstraintEditor *editor) update_button (ConstraintEditor *editor)
{ {
const char *target = gtk_combo_box_get_active_id (GTK_COMBO_BOX (editor->target)); gpointer obj;
const char *source = gtk_combo_box_get_active_id (GTK_COMBO_BOX (editor->source)); const char *target;
const char *source_attr = gtk_combo_box_get_active_id (GTK_COMBO_BOX (editor->source_attr)); const char *source;
GtkConstraintAttribute source_attr = get_attr (gtk_drop_down_get_selected (GTK_DROP_DOWN (editor->source_attr)));
if (target && obj = gtk_drop_down_get_selected_item (GTK_DROP_DOWN (editor->target));
(source || (source_attr && get_target_attr (source_attr) == GTK_CONSTRAINT_ATTRIBUTE_NONE))) target = obj ? gtk_string_object_get_string (GTK_STRING_OBJECT (obj)) : NULL;
obj = gtk_drop_down_get_selected_item (GTK_DROP_DOWN (editor->source));
source = obj ? gtk_string_object_get_string (GTK_STRING_OBJECT (obj)) : NULL;
if (target && (source || (source_attr == GTK_CONSTRAINT_ATTRIBUTE_NONE)))
gtk_widget_set_sensitive (editor->button, TRUE); gtk_widget_set_sensitive (editor->button, TRUE);
else else
gtk_widget_set_sensitive (editor->button, FALSE); gtk_widget_set_sensitive (editor->button, FALSE);
@ -486,12 +531,7 @@ constraint_editor_constructed (GObject *object)
ConstraintEditor *editor = CONSTRAINT_EDITOR (object); ConstraintEditor *editor = CONSTRAINT_EDITOR (object);
constraint_target_combo (editor->model, editor->target, FALSE); constraint_target_combo (editor->model, editor->target, FALSE);
constraint_attribute_combo (editor->target_attr, FALSE);
constraint_relation_combo (editor->relation);
constraint_target_combo (editor->model, editor->source, TRUE); constraint_target_combo (editor->model, editor->source, TRUE);
constraint_attribute_combo (editor->source_attr, TRUE);
constraint_strength_combo (editor->strength);
if (editor->constraint) if (editor->constraint)
{ {
@ -499,30 +539,24 @@ constraint_editor_constructed (GObject *object)
GtkConstraintAttribute attr; GtkConstraintAttribute attr;
GtkConstraintRelation relation; GtkConstraintRelation relation;
GtkConstraintStrength strength; GtkConstraintStrength strength;
const char *nick;
char *val; char *val;
double multiplier; double multiplier;
double constant; double constant;
target = gtk_constraint_get_target (editor->constraint); target = gtk_constraint_get_target (editor->constraint);
nick = get_target_name (target); select_target (GTK_DROP_DOWN (editor->target), get_target_name (target));
gtk_combo_box_set_active_id (GTK_COMBO_BOX (editor->target), nick);
attr = gtk_constraint_get_target_attribute (editor->constraint); attr = gtk_constraint_get_target_attribute (editor->constraint);
nick = get_attr_nick (attr); gtk_drop_down_set_selected (GTK_DROP_DOWN (editor->target_attr), get_attr_id (attr));
gtk_combo_box_set_active_id (GTK_COMBO_BOX (editor->target_attr), nick);
target = gtk_constraint_get_source (editor->constraint); target = gtk_constraint_get_source (editor->constraint);
nick = get_target_name (target); select_target (GTK_DROP_DOWN (editor->source), get_target_name (target));
gtk_combo_box_set_active_id (GTK_COMBO_BOX (editor->source), nick);
attr = gtk_constraint_get_source_attribute (editor->constraint); attr = gtk_constraint_get_source_attribute (editor->constraint);
nick = get_attr_nick (attr); gtk_drop_down_set_selected (GTK_DROP_DOWN (editor->source_attr), get_attr_id (attr));
gtk_combo_box_set_active_id (GTK_COMBO_BOX (editor->source_attr), nick);
relation = gtk_constraint_get_relation (editor->constraint); relation = gtk_constraint_get_relation (editor->constraint);
nick = get_relation_nick (relation); gtk_drop_down_set_selected (GTK_DROP_DOWN (editor->relation), get_relation_id (relation));
gtk_combo_box_set_active_id (GTK_COMBO_BOX (editor->relation), nick);
multiplier = gtk_constraint_get_multiplier (editor->constraint); multiplier = gtk_constraint_get_multiplier (editor->constraint);
val = g_strdup_printf ("%g", multiplier); val = g_strdup_printf ("%g", multiplier);
@ -535,17 +569,16 @@ constraint_editor_constructed (GObject *object)
g_free (val); g_free (val);
strength = gtk_constraint_get_strength (editor->constraint); strength = gtk_constraint_get_strength (editor->constraint);
nick = get_strength_nick (strength); gtk_drop_down_set_selected (GTK_DROP_DOWN (editor->strength), get_strength_id (strength));
gtk_combo_box_set_active_id (GTK_COMBO_BOX (editor->strength), nick);
gtk_button_set_label (GTK_BUTTON (editor->button), "Apply"); gtk_button_set_label (GTK_BUTTON (editor->button), "Apply");
} }
else else
{ {
gtk_combo_box_set_active_id (GTK_COMBO_BOX (editor->target_attr), "left"); gtk_drop_down_set_selected (GTK_DROP_DOWN (editor->target_attr), get_attr_id (GTK_CONSTRAINT_ATTRIBUTE_LEFT));
gtk_combo_box_set_active_id (GTK_COMBO_BOX (editor->source_attr), "left"); gtk_drop_down_set_selected (GTK_DROP_DOWN (editor->source_attr), get_attr_id (GTK_CONSTRAINT_ATTRIBUTE_LEFT));
gtk_combo_box_set_active_id (GTK_COMBO_BOX (editor->relation), "eq"); gtk_drop_down_set_selected (GTK_DROP_DOWN (editor->relation), get_relation_id (GTK_CONSTRAINT_RELATION_EQ));
gtk_combo_box_set_active_id (GTK_COMBO_BOX (editor->strength), "required"); gtk_drop_down_set_selected (GTK_DROP_DOWN (editor->strength), get_strength_id (GTK_CONSTRAINT_STRENGTH_REQUIRED));
gtk_editable_set_text (GTK_EDITABLE (editor->multiplier), "1.0"); gtk_editable_set_text (GTK_EDITABLE (editor->multiplier), "1.0");
gtk_editable_set_text (GTK_EDITABLE (editor->constant), "0.0"); gtk_editable_set_text (GTK_EDITABLE (editor->constant), "0.0");

View File

@ -1,5 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<interface> <interface>
<object class="GtkStringList" id="targets">
<items>
<item>None</item>
<item>Left</item>
<item>Right</item>
<item>Top</item>
<item>Bottom</item>
<item>Start</item>
<item>End</item>
<item>Width</item>
<item>Height</item>
<item>Center X</item>
<item>Center Y</item>
<item>Baseline</item>
</items>
</object>
<template class="ConstraintEditor" parent="GtkWidget"> <template class="ConstraintEditor" parent="GtkWidget">
<child> <child>
<object class="GtkGrid" id="grid"> <object class="GtkGrid" id="grid">
@ -19,9 +35,9 @@
</object> </object>
</child> </child>
<child> <child>
<object class="GtkComboBoxText" id="target"> <object class="GtkDropDown" id="target">
<signal name="changed" handler="update_preview" swapped="yes"/> <signal name="notify::selected" handler="update_preview" swapped="yes"/>
<signal name="changed" handler="update_button" swapped="yes"/> <signal name="notify::selected" handler="update_button" swapped="yes"/>
<layout> <layout>
<property name="column">1</property> <property name="column">1</property>
<property name="row">1</property> <property name="row">1</property>
@ -29,8 +45,9 @@
</object> </object>
</child> </child>
<child> <child>
<object class="GtkComboBoxText" id="target_attr"> <object class="GtkDropDown" id="target_attr">
<signal name="changed" handler="update_preview" swapped="yes"/> <property name="model">targets</property>
<signal name="notify::selected" handler="update_preview" swapped="yes"/>
<layout> <layout>
<property name="column">2</property> <property name="column">2</property>
<property name="row">1</property> <property name="row">1</property>
@ -47,8 +64,17 @@
</object> </object>
</child> </child>
<child> <child>
<object class="GtkComboBoxText" id="relation"> <object class="GtkDropDown" id="relation">
<signal name="changed" handler="update_preview" swapped="yes"/> <signal name="notify::selected" handler="update_preview" swapped="yes"/>
<property name="model">
<object class="GtkStringList">
<items>
<item>≤</item>
<item>=</item>
<item>≥</item>
</items>
</object>
</property>
<layout> <layout>
<property name="column">1</property> <property name="column">1</property>
<property name="row">2</property> <property name="row">2</property>
@ -65,9 +91,9 @@
</object> </object>
</child> </child>
<child> <child>
<object class="GtkComboBoxText" id="source"> <object class="GtkDropDown" id="source">
<signal name="changed" handler="update_preview" swapped="yes"/> <signal name="notify::selected" handler="update_preview" swapped="yes"/>
<signal name="changed" handler="update_button" swapped="yes"/> <signal name="notify::selected" handler="update_button" swapped="yes"/>
<layout> <layout>
<property name="column">1</property> <property name="column">1</property>
<property name="row">3</property> <property name="row">3</property>
@ -75,10 +101,11 @@
</object> </object>
</child> </child>
<child> <child>
<object class="GtkComboBoxText" id="source_attr"> <object class="GtkDropDown" id="source_attr">
<signal name="changed" handler="update_preview" swapped="yes"/> <property name="model">targets</property>
<signal name="changed" handler="source_attr_changed" swapped="yes"/> <signal name="notify::selected" handler="update_preview" swapped="yes"/>
<signal name="changed" handler="update_button" swapped="yes"/> <signal name="notify::selected" handler="source_attr_changed" swapped="yes"/>
<signal name="notify::selected" handler="update_button" swapped="yes"/>
<layout> <layout>
<property name="column">2</property> <property name="column">2</property>
<property name="row">3</property> <property name="row">3</property>
@ -131,7 +158,17 @@
</object> </object>
</child> </child>
<child> <child>
<object class="GtkComboBoxText" id="strength"> <object class="GtkDropDown" id="strength">
<property name="model">
<object class="GtkStringList">
<items>
<item>Weak</item>
<item>Medium</item>
<item>Strong</item>
<item>Required</item>
</items>
</object>
</property>
<layout> <layout>
<property name="column">1</property> <property name="column">1</property>
<property name="row">6</property> <property name="row">6</property>

View File

@ -21,8 +21,6 @@
#include "guide-editor.h" #include "guide-editor.h"
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
struct _GuideEditor struct _GuideEditor
{ {
GtkWidget parent_instance; GtkWidget parent_instance;
@ -59,25 +57,30 @@ static guint signals[LAST_SIGNAL];
G_DEFINE_TYPE(GuideEditor, guide_editor, GTK_TYPE_WIDGET); G_DEFINE_TYPE(GuideEditor, guide_editor, GTK_TYPE_WIDGET);
static void static GtkConstraintStrength
guide_strength_combo (GtkWidget *combo) get_strength (unsigned int id)
{ {
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo), "weak", "Weak"); switch (id)
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo), "medium", "Medium"); {
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo), "strong", "Strong"); case 0: return GTK_CONSTRAINT_STRENGTH_WEAK;
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo), "required", "Required"); case 1: return GTK_CONSTRAINT_STRENGTH_MEDIUM;
case 2: return GTK_CONSTRAINT_STRENGTH_STRONG;
case 3: return GTK_CONSTRAINT_STRENGTH_REQUIRED;
default: g_assert_not_reached ();
}
} }
static GtkConstraintStrength static unsigned int
get_strength (const char *id) get_strength_id (GtkConstraintStrength strength)
{ {
GtkConstraintStrength strength; switch (strength)
GEnumClass *class = g_type_class_ref (GTK_TYPE_CONSTRAINT_STRENGTH); {
GEnumValue *value = g_enum_get_value_by_nick (class, id); case GTK_CONSTRAINT_STRENGTH_WEAK: return 0;
strength = value->value; case GTK_CONSTRAINT_STRENGTH_MEDIUM: return 1;
g_type_class_unref (class); case GTK_CONSTRAINT_STRENGTH_STRONG: return 2;
case GTK_CONSTRAINT_STRENGTH_REQUIRED: return 3;
return strength; default: g_assert_not_reached ();
}
} }
static const char * static const char *
@ -118,11 +121,11 @@ static void
create_guide (GtkButton *button, create_guide (GtkButton *button,
GuideEditor *editor) GuideEditor *editor)
{ {
const char *id;
int strength; int strength;
const char *name; const char *name;
int w, h; int w, h;
GtkConstraintGuide *guide; GtkConstraintGuide *guide;
unsigned int id;
if (editor->guide) if (editor->guide)
guide = g_object_ref (editor->guide); guide = g_object_ref (editor->guide);
@ -144,7 +147,7 @@ create_guide (GtkButton *button,
h = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (editor->max_height)); h = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (editor->max_height));
gtk_constraint_guide_set_max_size (guide, w, h); gtk_constraint_guide_set_max_size (guide, w, h);
id = gtk_combo_box_get_active_id (GTK_COMBO_BOX (editor->strength)); id = gtk_drop_down_get_selected (GTK_DROP_DOWN (editor->strength));
strength = get_strength (id); strength = get_strength (id);
gtk_constraint_guide_set_strength (guide, strength); gtk_constraint_guide_set_strength (guide, strength);
@ -191,14 +194,9 @@ guide_editor_constructed (GObject *object)
{ {
GuideEditor *editor = GUIDE_EDITOR (object); GuideEditor *editor = GUIDE_EDITOR (object);
guide_strength_combo (editor->strength);
g_signal_connect (editor->min_width, "input", G_CALLBACK (min_input), NULL); g_signal_connect (editor->min_width, "input", G_CALLBACK (min_input), NULL);
g_signal_connect (editor->min_height, "input", G_CALLBACK (min_input), NULL); g_signal_connect (editor->min_height, "input", G_CALLBACK (min_input), NULL);
g_signal_connect (editor->max_width, "input", G_CALLBACK (max_input), NULL); g_signal_connect (editor->max_width, "input", G_CALLBACK (max_input), NULL);
g_signal_connect (editor->max_height, "input", G_CALLBACK (max_input), NULL); g_signal_connect (editor->max_height, "input", G_CALLBACK (max_input), NULL);
if (editor->guide) if (editor->guide)
@ -224,8 +222,7 @@ guide_editor_constructed (GObject *object)
gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->max_height), h); gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->max_height), h);
strength = gtk_constraint_guide_get_strength (editor->guide); strength = gtk_constraint_guide_get_strength (editor->guide);
nick = get_strength_nick (strength); gtk_drop_down_set_selected (GTK_DROP_DOWN (editor->strength), get_strength_id (strength));
gtk_combo_box_set_active_id (GTK_COMBO_BOX (editor->strength), nick);
gtk_button_set_label (GTK_BUTTON (editor->button), "Apply"); gtk_button_set_label (GTK_BUTTON (editor->button), "Apply");
} }
@ -245,7 +242,7 @@ guide_editor_constructed (GObject *object)
gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->max_width), G_MAXINT); 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_spin_button_set_value (GTK_SPIN_BUTTON (editor->max_height), G_MAXINT);
gtk_combo_box_set_active_id (GTK_COMBO_BOX (editor->strength), "medium"); gtk_drop_down_set_selected (GTK_DROP_DOWN (editor->strength), get_strength_id (GTK_CONSTRAINT_STRENGTH_MEDIUM));
gtk_button_set_label (GTK_BUTTON (editor->button), "Create"); gtk_button_set_label (GTK_BUTTON (editor->button), "Create");
} }

View File

@ -167,7 +167,17 @@
</object> </object>
</child> </child>
<child> <child>
<object class="GtkComboBoxText" id="strength"> <object class="GtkDropDown" id="strength">
<property name="model">
<object class="GtkStringList">
<items>
<item>Weak</item>
<item>Medium</item>
<item>Strong</item>
<item>Required</item>
</items>
</object>
</property>
<layout> <layout>
<property name="column">1</property> <property name="column">1</property>
<property name="row">4</property> <property name="row">4</property>