2019-04-09 14:33:52 +00:00
|
|
|
|
/* gtkconstraint.c: Constraint between two widgets
|
|
|
|
|
* Copyright 2019 GNOME Foundation
|
|
|
|
|
*
|
|
|
|
|
* 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/>.
|
|
|
|
|
*
|
|
|
|
|
* Author: Emmanuele Bassi
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2021-02-23 15:12:45 +00:00
|
|
|
|
* GtkConstraint:
|
2019-04-09 14:33:52 +00:00
|
|
|
|
*
|
2021-02-28 17:56:12 +00:00
|
|
|
|
* `GtkConstraint` describes a constraint between attributes of two widgets,
|
|
|
|
|
* expressed as a linear equation.
|
2021-02-18 18:17:56 +00:00
|
|
|
|
*
|
2021-02-23 15:12:45 +00:00
|
|
|
|
* The typical equation for a constraint is:
|
2019-04-09 14:33:52 +00:00
|
|
|
|
*
|
2021-02-14 18:00:00 +00:00
|
|
|
|
* ```
|
2021-02-23 15:12:45 +00:00
|
|
|
|
* target.target_attr = source.source_attr × multiplier + constant
|
2021-02-14 18:00:00 +00:00
|
|
|
|
* ```
|
2019-04-09 14:33:52 +00:00
|
|
|
|
*
|
2021-02-14 18:00:00 +00:00
|
|
|
|
* Each `GtkConstraint` is part of a system that will be solved by a
|
|
|
|
|
* [class@Gtk.ConstraintLayout] in order to allocate and position each
|
|
|
|
|
* child widget or guide.
|
2019-04-09 14:33:52 +00:00
|
|
|
|
*
|
2021-02-14 18:00:00 +00:00
|
|
|
|
* The source and target, as well as their attributes, of a `GtkConstraint`
|
|
|
|
|
* instance are immutable after creation.
|
2019-04-09 14:33:52 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
|
|
#include "gtkconstraintprivate.h"
|
|
|
|
|
#include "gtkconstraintsolverprivate.h"
|
|
|
|
|
#include "gtkintl.h"
|
|
|
|
|
#include "gtktypebuiltins.h"
|
|
|
|
|
#include "gtkwidget.h"
|
|
|
|
|
|
|
|
|
|
enum {
|
2019-06-25 19:16:02 +00:00
|
|
|
|
PROP_TARGET = 1,
|
2019-04-09 14:33:52 +00:00
|
|
|
|
PROP_TARGET_ATTRIBUTE,
|
|
|
|
|
PROP_RELATION,
|
2019-06-25 19:16:02 +00:00
|
|
|
|
PROP_SOURCE,
|
2019-04-09 14:33:52 +00:00
|
|
|
|
PROP_SOURCE_ATTRIBUTE,
|
|
|
|
|
PROP_MULTIPLIER,
|
|
|
|
|
PROP_CONSTANT,
|
|
|
|
|
PROP_STRENGTH,
|
|
|
|
|
|
|
|
|
|
N_PROPERTIES
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static GParamSpec *obj_props[N_PROPERTIES];
|
|
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (GtkConstraint, gtk_constraint, G_TYPE_OBJECT)
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_constraint_set_property (GObject *gobject,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
const GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
|
|
|
|
{
|
|
|
|
|
GtkConstraint *self = GTK_CONSTRAINT (gobject);
|
|
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
|
{
|
2019-06-25 19:16:02 +00:00
|
|
|
|
case PROP_TARGET:
|
|
|
|
|
self->target = g_value_get_object (value);
|
2019-04-09 14:33:52 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PROP_TARGET_ATTRIBUTE:
|
|
|
|
|
self->target_attribute = g_value_get_enum (value);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PROP_RELATION:
|
|
|
|
|
self->relation = g_value_get_enum (value);
|
|
|
|
|
break;
|
|
|
|
|
|
2019-06-25 19:16:02 +00:00
|
|
|
|
case PROP_SOURCE:
|
|
|
|
|
self->source = g_value_get_object (value);
|
2019-04-09 14:33:52 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PROP_SOURCE_ATTRIBUTE:
|
|
|
|
|
self->source_attribute = g_value_get_enum (value);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PROP_MULTIPLIER:
|
|
|
|
|
self->multiplier = g_value_get_double (value);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PROP_CONSTANT:
|
|
|
|
|
self->constant = g_value_get_double (value);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PROP_STRENGTH:
|
|
|
|
|
self->strength = g_value_get_int (value);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_constraint_get_property (GObject *gobject,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
|
|
|
|
{
|
|
|
|
|
GtkConstraint *self = GTK_CONSTRAINT (gobject);
|
|
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
|
{
|
2019-06-25 19:16:02 +00:00
|
|
|
|
case PROP_TARGET:
|
|
|
|
|
g_value_set_object (value, self->target);
|
2019-04-09 14:33:52 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PROP_TARGET_ATTRIBUTE:
|
|
|
|
|
g_value_set_enum (value, self->target_attribute);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PROP_RELATION:
|
|
|
|
|
g_value_set_enum (value, self->relation);
|
|
|
|
|
break;
|
|
|
|
|
|
2019-06-25 19:16:02 +00:00
|
|
|
|
case PROP_SOURCE:
|
|
|
|
|
g_value_set_object (value, self->source);
|
2019-04-09 14:33:52 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PROP_SOURCE_ATTRIBUTE:
|
|
|
|
|
g_value_set_enum (value, self->source_attribute);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PROP_MULTIPLIER:
|
|
|
|
|
g_value_set_double (value, self->multiplier);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PROP_CONSTANT:
|
|
|
|
|
g_value_set_double (value, self->constant);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PROP_STRENGTH:
|
|
|
|
|
g_value_set_int (value, self->strength);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_constraint_finalize (GObject *gobject)
|
|
|
|
|
{
|
|
|
|
|
GtkConstraint *self = GTK_CONSTRAINT (gobject);
|
|
|
|
|
|
|
|
|
|
gtk_constraint_detach (self);
|
|
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_constraint_parent_class)->finalize (gobject);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_constraint_class_init (GtkConstraintClass *klass)
|
|
|
|
|
{
|
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
|
|
gobject_class->set_property = gtk_constraint_set_property;
|
|
|
|
|
gobject_class->get_property = gtk_constraint_get_property;
|
|
|
|
|
gobject_class->finalize = gtk_constraint_finalize;
|
|
|
|
|
|
|
|
|
|
/**
|
2021-02-23 15:12:45 +00:00
|
|
|
|
* GtkConstraint:target: (attributes org.gtk.Property.get=gtk_constraint_get_target)
|
2019-04-09 14:33:52 +00:00
|
|
|
|
*
|
2019-06-25 19:16:02 +00:00
|
|
|
|
* The target of the constraint.
|
2019-04-09 14:33:52 +00:00
|
|
|
|
*
|
2021-05-20 13:17:04 +00:00
|
|
|
|
* The constraint will set the [property@Gtk.Constraint:target-attribute]
|
|
|
|
|
* property of the target using the [property@Gtk.Constraint:source-attribute]
|
|
|
|
|
* property of the source widget.
|
2021-02-23 15:12:45 +00:00
|
|
|
|
*
|
|
|
|
|
*
|
2019-04-09 14:33:52 +00:00
|
|
|
|
*/
|
2019-06-25 19:16:02 +00:00
|
|
|
|
obj_props[PROP_TARGET] =
|
|
|
|
|
g_param_spec_object ("target",
|
|
|
|
|
P_("Target"),
|
|
|
|
|
P_("The target of the constraint"),
|
|
|
|
|
GTK_TYPE_CONSTRAINT_TARGET,
|
2019-04-09 14:33:52 +00:00
|
|
|
|
G_PARAM_READWRITE |
|
|
|
|
|
G_PARAM_STATIC_STRINGS |
|
|
|
|
|
G_PARAM_CONSTRUCT_ONLY);
|
2021-05-20 13:17:04 +00:00
|
|
|
|
|
2019-04-09 14:33:52 +00:00
|
|
|
|
/**
|
2021-02-23 15:12:45 +00:00
|
|
|
|
* GtkConstraint:target-attribute: (attributes org.gtk.Property.get=gtk_constraint_get_target_attribute)
|
2019-04-09 14:33:52 +00:00
|
|
|
|
*
|
2021-05-20 13:17:04 +00:00
|
|
|
|
* The attribute of the [property@Gtk.Constraint:target] set by the constraint.
|
2019-04-09 14:33:52 +00:00
|
|
|
|
*/
|
|
|
|
|
obj_props[PROP_TARGET_ATTRIBUTE] =
|
|
|
|
|
g_param_spec_enum ("target-attribute",
|
|
|
|
|
P_("Target Attribute"),
|
2019-06-25 19:16:02 +00:00
|
|
|
|
P_("The attribute of the target set by the constraint"),
|
2019-04-09 14:33:52 +00:00
|
|
|
|
GTK_TYPE_CONSTRAINT_ATTRIBUTE,
|
|
|
|
|
GTK_CONSTRAINT_ATTRIBUTE_NONE,
|
|
|
|
|
G_PARAM_READWRITE |
|
|
|
|
|
G_PARAM_STATIC_STRINGS |
|
|
|
|
|
G_PARAM_CONSTRUCT_ONLY);
|
2021-05-20 13:17:04 +00:00
|
|
|
|
|
2019-04-09 14:33:52 +00:00
|
|
|
|
/**
|
2021-02-23 15:12:45 +00:00
|
|
|
|
* GtkConstraint:relation: (attributes org.gtk.Property.get=gtk_constraint_get_relation)
|
2019-04-09 14:33:52 +00:00
|
|
|
|
*
|
2019-07-01 00:02:56 +00:00
|
|
|
|
* The order relation between the terms of the constraint.
|
2019-04-09 14:33:52 +00:00
|
|
|
|
*/
|
|
|
|
|
obj_props[PROP_RELATION] =
|
|
|
|
|
g_param_spec_enum ("relation",
|
|
|
|
|
P_("Relation"),
|
|
|
|
|
P_("The relation between the source and target attributes"),
|
|
|
|
|
GTK_TYPE_CONSTRAINT_RELATION,
|
|
|
|
|
GTK_CONSTRAINT_RELATION_EQ,
|
|
|
|
|
G_PARAM_READWRITE |
|
|
|
|
|
G_PARAM_STATIC_STRINGS |
|
|
|
|
|
G_PARAM_CONSTRUCT_ONLY);
|
2021-05-20 13:17:04 +00:00
|
|
|
|
|
2019-04-09 14:33:52 +00:00
|
|
|
|
/**
|
2021-02-23 15:12:45 +00:00
|
|
|
|
* GtkConstraint:source: (attributes org.gtk.Property.get=gtk_constraint_get_source)
|
2019-04-09 14:33:52 +00:00
|
|
|
|
*
|
2019-06-25 19:16:02 +00:00
|
|
|
|
* The source of the constraint.
|
2019-04-09 14:33:52 +00:00
|
|
|
|
*
|
2021-02-23 15:12:45 +00:00
|
|
|
|
* The constraint will set the [property@Gtk.Constraint:target-attribute]
|
2021-05-20 13:17:04 +00:00
|
|
|
|
* property of the target using the [property@Gtk.Constraint:source-attribute]
|
|
|
|
|
* property of the source.
|
2019-04-09 14:33:52 +00:00
|
|
|
|
*/
|
2019-06-25 19:16:02 +00:00
|
|
|
|
obj_props[PROP_SOURCE] =
|
|
|
|
|
g_param_spec_object ("source",
|
|
|
|
|
P_("Source"),
|
|
|
|
|
P_("The source of the constraint"),
|
|
|
|
|
GTK_TYPE_CONSTRAINT_TARGET,
|
2019-04-09 14:33:52 +00:00
|
|
|
|
G_PARAM_READWRITE |
|
|
|
|
|
G_PARAM_STATIC_STRINGS |
|
|
|
|
|
G_PARAM_CONSTRUCT_ONLY);
|
|
|
|
|
/**
|
2021-02-23 15:12:45 +00:00
|
|
|
|
* GtkConstraint:source-attribute: (attributes org.gtk.Property.get=gtk_constraint_get_source_attribute)
|
2019-04-09 14:33:52 +00:00
|
|
|
|
*
|
2021-02-23 15:12:45 +00:00
|
|
|
|
* The attribute of the [property@Gtk.Constraint:source] read by the
|
|
|
|
|
* constraint.
|
2019-04-09 14:33:52 +00:00
|
|
|
|
*/
|
|
|
|
|
obj_props[PROP_SOURCE_ATTRIBUTE] =
|
|
|
|
|
g_param_spec_enum ("source-attribute",
|
|
|
|
|
P_("Source Attribute"),
|
|
|
|
|
P_("The attribute of the source widget set by the constraint"),
|
|
|
|
|
GTK_TYPE_CONSTRAINT_ATTRIBUTE,
|
|
|
|
|
GTK_CONSTRAINT_ATTRIBUTE_NONE,
|
|
|
|
|
G_PARAM_READWRITE |
|
|
|
|
|
G_PARAM_STATIC_STRINGS |
|
|
|
|
|
G_PARAM_CONSTRUCT_ONLY);
|
2021-05-20 13:17:04 +00:00
|
|
|
|
|
2019-04-09 14:33:52 +00:00
|
|
|
|
/**
|
2021-02-23 15:12:45 +00:00
|
|
|
|
* GtkConstraint:multiplier: (attributes org.gtk.Property.get=gtk_constraint_get_multiplier)
|
2019-04-09 14:33:52 +00:00
|
|
|
|
*
|
2021-02-23 15:12:45 +00:00
|
|
|
|
* The multiplication factor to be applied to
|
|
|
|
|
* the [property@Gtk.Constraint:source-attribute].
|
2019-04-09 14:33:52 +00:00
|
|
|
|
*/
|
|
|
|
|
obj_props[PROP_MULTIPLIER] =
|
|
|
|
|
g_param_spec_double ("multiplier",
|
|
|
|
|
P_("Multiplier"),
|
|
|
|
|
P_("The multiplication factor to be applied to the source attribute"),
|
|
|
|
|
-G_MAXDOUBLE, G_MAXDOUBLE, 1.0,
|
|
|
|
|
G_PARAM_READWRITE |
|
|
|
|
|
G_PARAM_STATIC_STRINGS |
|
|
|
|
|
G_PARAM_CONSTRUCT_ONLY);
|
2021-05-20 13:17:04 +00:00
|
|
|
|
|
2019-04-09 14:33:52 +00:00
|
|
|
|
/**
|
2021-02-23 15:12:45 +00:00
|
|
|
|
* GtkConstraint:constant: (attributes org.gtk.Property.get=gtk_constraint_get_constant)
|
2019-04-09 14:33:52 +00:00
|
|
|
|
*
|
2021-02-23 15:12:45 +00:00
|
|
|
|
* The constant value to be added to the [property@Gtk.Constraint:source-attribute].
|
2019-04-09 14:33:52 +00:00
|
|
|
|
*/
|
|
|
|
|
obj_props[PROP_CONSTANT] =
|
|
|
|
|
g_param_spec_double ("constant",
|
|
|
|
|
P_("Constant"),
|
|
|
|
|
P_("The constant to be added to the source attribute"),
|
|
|
|
|
-G_MAXDOUBLE, G_MAXDOUBLE, 0.0,
|
|
|
|
|
G_PARAM_READWRITE |
|
|
|
|
|
G_PARAM_STATIC_STRINGS |
|
|
|
|
|
G_PARAM_CONSTRUCT_ONLY);
|
2021-05-20 13:17:04 +00:00
|
|
|
|
|
2019-04-09 14:33:52 +00:00
|
|
|
|
/**
|
2021-02-23 15:12:45 +00:00
|
|
|
|
* GtkConstraint:strength: (attributes org.gtk.Property.get=gtk_constraint_get_strength)
|
2019-04-09 14:33:52 +00:00
|
|
|
|
*
|
|
|
|
|
* The strength of the constraint.
|
|
|
|
|
*
|
|
|
|
|
* The strength can be expressed either using one of the symbolic values
|
2021-02-23 15:12:45 +00:00
|
|
|
|
* of the [enum@Gtk.ConstraintStrength] enumeration, or any positive integer
|
2019-04-09 14:33:52 +00:00
|
|
|
|
* value.
|
|
|
|
|
*/
|
|
|
|
|
obj_props[PROP_STRENGTH] =
|
|
|
|
|
g_param_spec_int ("strength",
|
|
|
|
|
P_("Strength"),
|
|
|
|
|
P_("The strength of the constraint"),
|
2019-07-01 11:39:24 +00:00
|
|
|
|
0, GTK_CONSTRAINT_STRENGTH_REQUIRED,
|
2019-04-09 14:33:52 +00:00
|
|
|
|
GTK_CONSTRAINT_STRENGTH_REQUIRED,
|
|
|
|
|
G_PARAM_READWRITE |
|
|
|
|
|
G_PARAM_STATIC_STRINGS |
|
|
|
|
|
G_PARAM_CONSTRUCT_ONLY);
|
|
|
|
|
|
|
|
|
|
g_object_class_install_properties (gobject_class, N_PROPERTIES, obj_props);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_constraint_init (GtkConstraint *self)
|
|
|
|
|
{
|
|
|
|
|
self->multiplier = 1.0;
|
|
|
|
|
self->constant = 0.0;
|
|
|
|
|
|
|
|
|
|
self->target_attribute = GTK_CONSTRAINT_ATTRIBUTE_NONE;
|
|
|
|
|
self->source_attribute = GTK_CONSTRAINT_ATTRIBUTE_NONE;
|
|
|
|
|
self->relation = GTK_CONSTRAINT_RELATION_EQ;
|
|
|
|
|
self->strength = GTK_CONSTRAINT_STRENGTH_REQUIRED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-02-23 15:12:45 +00:00
|
|
|
|
* gtk_constraint_new: (constructor)
|
|
|
|
|
* @target: (nullable) (type GtkConstraintTarget): the target of the constraint
|
|
|
|
|
* @target_attribute: the attribute of `target` to be set
|
|
|
|
|
* @relation: the relation equivalence between `target_attribute` and `source_attribute`
|
|
|
|
|
* @source: (nullable) (type GtkConstraintTarget): the source of the constraint
|
|
|
|
|
* @source_attribute: the attribute of `source` to be read
|
|
|
|
|
* @multiplier: a multiplication factor to be applied to `source_attribute`
|
|
|
|
|
* @constant: a constant factor to be added to `source_attribute`
|
2019-04-09 14:33:52 +00:00
|
|
|
|
* @strength: the strength of the constraint
|
|
|
|
|
*
|
2021-02-23 15:12:45 +00:00
|
|
|
|
* Creates a new constraint representing a relation between a layout
|
2019-06-25 19:16:02 +00:00
|
|
|
|
* attribute on a source and a layout attribute on a target.
|
2019-04-09 14:33:52 +00:00
|
|
|
|
*
|
2021-02-23 15:12:45 +00:00
|
|
|
|
* Returns: (transfer full): the newly created constraint
|
2019-04-09 14:33:52 +00:00
|
|
|
|
*/
|
|
|
|
|
GtkConstraint *
|
2019-06-27 17:26:19 +00:00
|
|
|
|
gtk_constraint_new (gpointer target,
|
2019-04-09 14:33:52 +00:00
|
|
|
|
GtkConstraintAttribute target_attribute,
|
|
|
|
|
GtkConstraintRelation relation,
|
2019-06-27 17:26:19 +00:00
|
|
|
|
gpointer source,
|
2019-04-09 14:33:52 +00:00
|
|
|
|
GtkConstraintAttribute source_attribute,
|
|
|
|
|
double multiplier,
|
|
|
|
|
double constant,
|
|
|
|
|
int strength)
|
|
|
|
|
{
|
2019-06-25 19:16:02 +00:00
|
|
|
|
g_return_val_if_fail (target == NULL || GTK_IS_CONSTRAINT_TARGET (target), NULL);
|
|
|
|
|
g_return_val_if_fail (source == NULL || GTK_IS_CONSTRAINT_TARGET (source), NULL);
|
2019-04-09 14:33:52 +00:00
|
|
|
|
|
|
|
|
|
return g_object_new (GTK_TYPE_CONSTRAINT,
|
2019-06-25 19:16:02 +00:00
|
|
|
|
"target", target,
|
2019-04-09 14:33:52 +00:00
|
|
|
|
"target-attribute", target_attribute,
|
|
|
|
|
"relation", relation,
|
2019-06-25 19:16:02 +00:00
|
|
|
|
"source", source,
|
2019-04-09 14:33:52 +00:00
|
|
|
|
"source-attribute", source_attribute,
|
|
|
|
|
"multiplier", multiplier,
|
|
|
|
|
"constant", constant,
|
|
|
|
|
"strength", strength,
|
|
|
|
|
NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-02-23 15:12:45 +00:00
|
|
|
|
* gtk_constraint_new_constant: (constructor)
|
|
|
|
|
* @target: (nullable) (type GtkConstraintTarget): a the target of the constraint
|
|
|
|
|
* @target_attribute: the attribute of `target` to be set
|
|
|
|
|
* @relation: the relation equivalence between `target_attribute` and `constant`
|
|
|
|
|
* @constant: a constant factor to be set on `target_attribute`
|
2019-04-09 14:33:52 +00:00
|
|
|
|
* @strength: the strength of the constraint
|
|
|
|
|
*
|
2021-02-23 15:12:45 +00:00
|
|
|
|
* Creates a new constraint representing a relation between a layout
|
2019-06-25 19:16:02 +00:00
|
|
|
|
* attribute on a target and a constant value.
|
2019-04-09 14:33:52 +00:00
|
|
|
|
*
|
2021-02-23 15:12:45 +00:00
|
|
|
|
* Returns: (transfer full): the newly created constraint
|
2019-04-09 14:33:52 +00:00
|
|
|
|
*/
|
|
|
|
|
GtkConstraint *
|
2019-06-27 17:26:19 +00:00
|
|
|
|
gtk_constraint_new_constant (gpointer target,
|
2019-04-09 14:33:52 +00:00
|
|
|
|
GtkConstraintAttribute target_attribute,
|
|
|
|
|
GtkConstraintRelation relation,
|
|
|
|
|
double constant,
|
|
|
|
|
int strength)
|
|
|
|
|
{
|
2019-06-25 19:16:02 +00:00
|
|
|
|
g_return_val_if_fail (target == NULL || GTK_IS_CONSTRAINT_TARGET (target), NULL);
|
2019-04-09 14:33:52 +00:00
|
|
|
|
|
|
|
|
|
return g_object_new (GTK_TYPE_CONSTRAINT,
|
2019-06-25 19:16:02 +00:00
|
|
|
|
"target", target,
|
2019-04-09 14:33:52 +00:00
|
|
|
|
"target-attribute", target_attribute,
|
|
|
|
|
"relation", relation,
|
|
|
|
|
"source-attribute", GTK_CONSTRAINT_ATTRIBUTE_NONE,
|
|
|
|
|
"constant", constant,
|
|
|
|
|
"strength", strength,
|
|
|
|
|
NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-01 00:02:56 +00:00
|
|
|
|
/**
|
2021-02-23 15:12:45 +00:00
|
|
|
|
* gtk_constraint_get_target: (attributes org.gtk.Method.get_property=target)
|
|
|
|
|
* @constraint: a `GtkConstraint`
|
2019-07-01 00:02:56 +00:00
|
|
|
|
*
|
2021-02-23 15:12:45 +00:00
|
|
|
|
* Retrieves the [iface@Gtk.ConstraintTarget] used as the target for
|
|
|
|
|
* the constraint.
|
2019-07-01 00:02:56 +00:00
|
|
|
|
*
|
2021-02-23 15:12:45 +00:00
|
|
|
|
* If the targe is set to `NULL` at creation, the constraint will use
|
|
|
|
|
* the widget using the [class@Gtk.ConstraintLayout] as the target.
|
2019-07-01 00:02:56 +00:00
|
|
|
|
*
|
2021-05-20 13:17:04 +00:00
|
|
|
|
* Returns: (transfer none) (nullable): a `GtkConstraintTarget`
|
2019-07-01 00:02:56 +00:00
|
|
|
|
*/
|
2019-06-25 19:16:02 +00:00
|
|
|
|
GtkConstraintTarget *
|
|
|
|
|
gtk_constraint_get_target (GtkConstraint *constraint)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (GTK_IS_CONSTRAINT (constraint), NULL);
|
|
|
|
|
|
|
|
|
|
return constraint->target;
|
2019-04-09 14:33:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-01 00:02:56 +00:00
|
|
|
|
/**
|
2021-02-23 15:12:45 +00:00
|
|
|
|
* gtk_constraint_get_target_attribute: (attributes org.gtk.Method.get_property=target-attribute)
|
|
|
|
|
* @constraint: a `GtkConstraint`
|
2019-07-01 00:02:56 +00:00
|
|
|
|
*
|
2021-02-23 15:12:45 +00:00
|
|
|
|
* Retrieves the attribute of the target to be set by the constraint.
|
2019-07-01 00:02:56 +00:00
|
|
|
|
*
|
|
|
|
|
* Returns: the target's attribute
|
|
|
|
|
*/
|
2019-04-09 14:33:52 +00:00
|
|
|
|
GtkConstraintAttribute
|
|
|
|
|
gtk_constraint_get_target_attribute (GtkConstraint *constraint)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (GTK_IS_CONSTRAINT (constraint), GTK_CONSTRAINT_ATTRIBUTE_NONE);
|
|
|
|
|
|
|
|
|
|
return constraint->target_attribute;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-01 00:02:56 +00:00
|
|
|
|
/**
|
2021-02-23 15:12:45 +00:00
|
|
|
|
* gtk_constraint_get_source: (attributes org.gtk.Method.get_property=source)
|
2021-05-20 13:17:04 +00:00
|
|
|
|
* @constraint: a `GtkConstraint`
|
2019-07-01 00:02:56 +00:00
|
|
|
|
*
|
2021-02-23 15:12:45 +00:00
|
|
|
|
* Retrieves the [iface@Gtk.ConstraintTarget] used as the source for the
|
|
|
|
|
* constraint.
|
2019-07-01 00:02:56 +00:00
|
|
|
|
*
|
2021-02-23 15:12:45 +00:00
|
|
|
|
* If the source is set to `NULL` at creation, the constraint will use
|
|
|
|
|
* the widget using the [class@Gtk.ConstraintLayout] as the source.
|
2019-07-01 00:02:56 +00:00
|
|
|
|
*
|
2021-02-23 15:12:45 +00:00
|
|
|
|
* Returns: (transfer none) (nullable): the source of the constraint
|
2019-07-01 00:02:56 +00:00
|
|
|
|
*/
|
2019-06-25 19:16:02 +00:00
|
|
|
|
GtkConstraintTarget *
|
|
|
|
|
gtk_constraint_get_source (GtkConstraint *constraint)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (GTK_IS_CONSTRAINT (constraint), NULL);
|
|
|
|
|
|
|
|
|
|
return constraint->source;
|
2019-04-09 14:33:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-01 00:02:56 +00:00
|
|
|
|
/**
|
2021-02-23 15:12:45 +00:00
|
|
|
|
* gtk_constraint_get_source_attribute: (attributes org.gtk.Method.get_property=source-attribute)
|
|
|
|
|
* @constraint: a `GtkConstraint`
|
2019-07-01 00:02:56 +00:00
|
|
|
|
*
|
2021-02-23 15:12:45 +00:00
|
|
|
|
* Retrieves the attribute of the source to be read by the constraint.
|
2019-07-01 00:02:56 +00:00
|
|
|
|
*
|
2021-02-23 15:12:45 +00:00
|
|
|
|
* Returns: the source's attribute
|
2019-07-01 00:02:56 +00:00
|
|
|
|
*/
|
2019-04-09 14:33:52 +00:00
|
|
|
|
GtkConstraintAttribute
|
|
|
|
|
gtk_constraint_get_source_attribute (GtkConstraint *constraint)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (GTK_IS_CONSTRAINT (constraint), GTK_CONSTRAINT_ATTRIBUTE_NONE);
|
|
|
|
|
|
|
|
|
|
return constraint->source_attribute;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-01 00:02:56 +00:00
|
|
|
|
/**
|
2021-02-23 15:12:45 +00:00
|
|
|
|
* gtk_constraint_get_relation: (attributes org.gtk.Method.get_property=relation)
|
|
|
|
|
* @constraint: a `GtkConstraint`
|
2019-07-01 00:02:56 +00:00
|
|
|
|
*
|
2021-02-23 15:12:45 +00:00
|
|
|
|
* The order relation between the terms of the constraint.
|
2019-07-01 00:02:56 +00:00
|
|
|
|
*
|
2021-02-23 15:12:45 +00:00
|
|
|
|
* Returns: a relation type
|
2019-07-01 00:02:56 +00:00
|
|
|
|
*/
|
2019-04-09 14:33:52 +00:00
|
|
|
|
GtkConstraintRelation
|
|
|
|
|
gtk_constraint_get_relation (GtkConstraint *constraint)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (GTK_IS_CONSTRAINT (constraint), GTK_CONSTRAINT_RELATION_EQ);
|
|
|
|
|
|
|
|
|
|
return constraint->relation;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-01 00:02:56 +00:00
|
|
|
|
/**
|
2021-02-23 15:12:45 +00:00
|
|
|
|
* gtk_constraint_get_multiplier: (attributes org.gtk.Method.get_property=multiplier)
|
|
|
|
|
* @constraint: a `GtkConstraint`
|
2019-07-01 00:02:56 +00:00
|
|
|
|
*
|
|
|
|
|
* Retrieves the multiplication factor applied to the source
|
|
|
|
|
* attribute's value.
|
|
|
|
|
*
|
|
|
|
|
* Returns: a multiplication factor
|
|
|
|
|
*/
|
2019-04-09 14:33:52 +00:00
|
|
|
|
double
|
|
|
|
|
gtk_constraint_get_multiplier (GtkConstraint *constraint)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (GTK_IS_CONSTRAINT (constraint), 1.0);
|
|
|
|
|
|
|
|
|
|
return constraint->multiplier;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-01 00:02:56 +00:00
|
|
|
|
/**
|
2021-02-23 15:12:45 +00:00
|
|
|
|
* gtk_constraint_get_constant: (attributes org.gtk.Method.get_property=constant)
|
|
|
|
|
* @constraint: a `GtkConstraint`
|
2019-07-01 00:02:56 +00:00
|
|
|
|
*
|
|
|
|
|
* Retrieves the constant factor added to the source attributes' value.
|
|
|
|
|
*
|
|
|
|
|
* Returns: a constant factor
|
|
|
|
|
*/
|
2019-04-09 14:33:52 +00:00
|
|
|
|
double
|
|
|
|
|
gtk_constraint_get_constant (GtkConstraint *constraint)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (GTK_IS_CONSTRAINT (constraint), 0.0);
|
|
|
|
|
|
|
|
|
|
return constraint->constant;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-01 00:02:56 +00:00
|
|
|
|
/**
|
2021-02-23 15:12:45 +00:00
|
|
|
|
* gtk_constraint_get_strength: (attributes org.gtk.Method.get_property=strength)
|
|
|
|
|
* @constraint: a `GtkConstraint`
|
2019-07-01 00:02:56 +00:00
|
|
|
|
*
|
|
|
|
|
* Retrieves the strength of the constraint.
|
|
|
|
|
*
|
2021-02-23 15:12:45 +00:00
|
|
|
|
* Returns: the strength value
|
2019-07-01 00:02:56 +00:00
|
|
|
|
*/
|
2019-04-09 14:33:52 +00:00
|
|
|
|
int
|
|
|
|
|
gtk_constraint_get_strength (GtkConstraint *constraint)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (GTK_IS_CONSTRAINT (constraint), GTK_CONSTRAINT_STRENGTH_REQUIRED);
|
|
|
|
|
|
|
|
|
|
return constraint->strength;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_constraint_is_required:
|
2021-02-23 15:12:45 +00:00
|
|
|
|
* @constraint: a `GtkConstraint`
|
2019-04-09 14:33:52 +00:00
|
|
|
|
*
|
2021-02-23 15:12:45 +00:00
|
|
|
|
* Checks whether the constraint is a required relation for solving the
|
2019-04-09 14:33:52 +00:00
|
|
|
|
* constraint layout.
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE if the constraint is required
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
gtk_constraint_is_required (GtkConstraint *constraint)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (GTK_IS_CONSTRAINT (constraint), FALSE);
|
|
|
|
|
|
|
|
|
|
return constraint->strength == GTK_CONSTRAINT_STRENGTH_REQUIRED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_constraint_is_attached:
|
2021-02-23 15:12:45 +00:00
|
|
|
|
* @constraint: a `GtkConstraint`
|
2019-04-09 14:33:52 +00:00
|
|
|
|
*
|
2021-02-23 15:12:45 +00:00
|
|
|
|
* Checks whether the constraint is attached to a [class@Gtk.ConstraintLayout],
|
2019-04-09 14:33:52 +00:00
|
|
|
|
* and it is contributing to the layout.
|
|
|
|
|
*
|
2021-02-23 15:12:45 +00:00
|
|
|
|
* Returns: `TRUE` if the constraint is attached
|
2019-04-09 14:33:52 +00:00
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
gtk_constraint_is_attached (GtkConstraint *constraint)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (GTK_IS_CONSTRAINT (constraint), FALSE);
|
|
|
|
|
|
|
|
|
|
return constraint->constraint_ref != NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_constraint_is_constant:
|
2021-02-23 15:12:45 +00:00
|
|
|
|
* @constraint: a `GtkConstraint`
|
2019-04-09 14:33:52 +00:00
|
|
|
|
*
|
2021-02-23 15:12:45 +00:00
|
|
|
|
* Checks whether the constraint describes a relation between an attribute
|
|
|
|
|
* on the [property@Gtk.Constraint:target] and a constant value.
|
2019-04-09 14:33:52 +00:00
|
|
|
|
*
|
2021-02-23 15:12:45 +00:00
|
|
|
|
* Returns: `TRUE` if the constraint is a constant relation
|
2019-04-09 14:33:52 +00:00
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
gtk_constraint_is_constant (GtkConstraint *constraint)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (GTK_IS_CONSTRAINT (constraint), FALSE);
|
|
|
|
|
|
2019-06-25 23:38:32 +00:00
|
|
|
|
return constraint->source == NULL &&
|
2019-04-09 14:33:52 +00:00
|
|
|
|
constraint->source_attribute == GTK_CONSTRAINT_ATTRIBUTE_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
gtk_constraint_attach (GtkConstraint *constraint,
|
|
|
|
|
GtkConstraintSolver *solver,
|
|
|
|
|
GtkConstraintRef *ref)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_CONSTRAINT (constraint));
|
|
|
|
|
g_return_if_fail (GTK_IS_CONSTRAINT_SOLVER (solver));
|
|
|
|
|
g_return_if_fail (ref != NULL);
|
|
|
|
|
|
|
|
|
|
constraint->constraint_ref = ref;
|
|
|
|
|
constraint->solver = solver;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
gtk_constraint_detach (GtkConstraint *constraint)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_CONSTRAINT (constraint));
|
|
|
|
|
|
|
|
|
|
if (constraint->constraint_ref == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
gtk_constraint_solver_remove_constraint (constraint->solver, constraint->constraint_ref);
|
|
|
|
|
constraint->constraint_ref = NULL;
|
|
|
|
|
constraint->solver = NULL;
|
|
|
|
|
}
|
2019-06-25 19:04:05 +00:00
|
|
|
|
|
|
|
|
|
typedef struct _GtkConstraintTargetInterface GtkConstraintTargetInterface;
|
|
|
|
|
|
|
|
|
|
struct _GtkConstraintTargetInterface
|
|
|
|
|
{
|
|
|
|
|
GTypeInterface g_iface;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
G_DEFINE_INTERFACE (GtkConstraintTarget, gtk_constraint_target, G_TYPE_OBJECT)
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_constraint_target_default_init (GtkConstraintTargetInterface *iface)
|
|
|
|
|
{
|
|
|
|
|
}
|