:right-sidebar: True Constraint =================================================================== .. currentmodule:: gi.repository.Gtk .. class:: Constraint(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.GObject.Object` ``GtkConstraint`` describes a constraint between attributes of two widgets, expressed as a linear equation. The typical equation for a constraint is: .. code-block:: :dedent: target.target_attr = source.source_attr × multiplier + constant Each ``GtkConstraint`` is part of a system that will be solved by a :obj:`~gi.repository.Gtk.ConstraintLayout` in order to allocate and position each child widget or guide. The source and target, as well as their attributes, of a ``GtkConstraint`` instance are immutable after creation. Constructors ------------ .. rst-class:: interim-class .. class:: Constraint :no-index: .. classmethod:: new(target: ~gi.repository.Gtk.ConstraintTarget | None, target_attribute: ~gi.repository.Gtk.ConstraintAttribute, relation: ~gi.repository.Gtk.ConstraintRelation, source: ~gi.repository.Gtk.ConstraintTarget | None, source_attribute: ~gi.repository.Gtk.ConstraintAttribute, multiplier: float, constant: float, strength: int) -> ~gi.repository.Gtk.Constraint Creates a new constraint representing a relation between a layout attribute on a source and a layout attribute on a target. :param target: the target of the constraint :param target_attribute: the attribute of ``target`` to be set :param relation: the relation equivalence between ``target_attribute`` and ``source_attribute`` :param source: the source of the constraint :param source_attribute: the attribute of ``source`` to be read :param multiplier: a multiplication factor to be applied to ``source_attribute`` :param constant: a constant factor to be added to ``source_attribute`` :param strength: the strength of the constraint .. classmethod:: new_constant(target: ~gi.repository.Gtk.ConstraintTarget | None, target_attribute: ~gi.repository.Gtk.ConstraintAttribute, relation: ~gi.repository.Gtk.ConstraintRelation, constant: float, strength: int) -> ~gi.repository.Gtk.Constraint Creates a new constraint representing a relation between a layout attribute on a target and a constant value. :param target: a the target of the constraint :param target_attribute: the attribute of ``target`` to be set :param relation: the relation equivalence between ``target_attribute`` and ``constant`` :param constant: a constant factor to be set on ``target_attribute`` :param strength: the strength of the constraint Methods ------- .. rst-class:: interim-class .. class:: Constraint :no-index: .. method:: get_constant() -> float Retrieves the constant factor added to the source attributes' value. .. method:: get_multiplier() -> float Retrieves the multiplication factor applied to the source attribute's value. .. method:: get_relation() -> ~gi.repository.Gtk.ConstraintRelation The order relation between the terms of the constraint. .. method:: get_source() -> ~gi.repository.Gtk.ConstraintTarget | None Retrieves the :obj:`~gi.repository.Gtk.ConstraintTarget` used as the source for the constraint. If the source is set to ``NULL`` at creation, the constraint will use the widget using the :obj:`~gi.repository.Gtk.ConstraintLayout` as the source. .. method:: get_source_attribute() -> ~gi.repository.Gtk.ConstraintAttribute Retrieves the attribute of the source to be read by the constraint. .. method:: get_strength() -> int Retrieves the strength of the constraint. .. method:: get_target() -> ~gi.repository.Gtk.ConstraintTarget | None Retrieves the :obj:`~gi.repository.Gtk.ConstraintTarget` used as the target for the constraint. If the targe is set to ``NULL`` at creation, the constraint will use the widget using the :obj:`~gi.repository.Gtk.ConstraintLayout` as the target. .. method:: get_target_attribute() -> ~gi.repository.Gtk.ConstraintAttribute Retrieves the attribute of the target to be set by the constraint. .. method:: is_attached() -> bool Checks whether the constraint is attached to a :obj:`~gi.repository.Gtk.ConstraintLayout`, and it is contributing to the layout. .. method:: is_constant() -> bool Checks whether the constraint describes a relation between an attribute on the :obj:`~gi.repository.Gtk.Constraint.props.target` and a constant value. .. method:: is_required() -> bool Checks whether the constraint is a required relation for solving the constraint layout. Properties ---------- .. rst-class:: interim-class .. class:: Constraint :no-index: .. attribute:: props.constant :type: float The constant value to be added to the :obj:`~gi.repository.Gtk.Constraint.props.source_attribute`. .. attribute:: props.multiplier :type: float The multiplication factor to be applied to the :obj:`~gi.repository.Gtk.Constraint.props.source_attribute`. .. attribute:: props.relation :type: ~gi.repository.Gtk.ConstraintRelation The order relation between the terms of the constraint. .. attribute:: props.source :type: ~gi.repository.Gtk.ConstraintTarget The source of the constraint. The constraint will set the :obj:`~gi.repository.Gtk.Constraint.props.target_attribute` property of the target using the :obj:`~gi.repository.Gtk.Constraint.props.source_attribute` property of the source. .. attribute:: props.source_attribute :type: ~gi.repository.Gtk.ConstraintAttribute The attribute of the :obj:`~gi.repository.Gtk.Constraint.props.source` read by the constraint. .. attribute:: props.strength :type: int The strength of the constraint. The strength can be expressed either using one of the symbolic values of the :obj:`~gi.repository.Gtk.ConstraintStrength` enumeration, or any positive integer value. .. attribute:: props.target :type: ~gi.repository.Gtk.ConstraintTarget The target of the constraint. The constraint will set the :obj:`~gi.repository.Gtk.Constraint.props.target_attribute` property of the target using the :obj:`~gi.repository.Gtk.Constraint.props.source_attribute` property of the source widget. .. attribute:: props.target_attribute :type: ~gi.repository.Gtk.ConstraintAttribute The attribute of the :obj:`~gi.repository.Gtk.Constraint.props.target` set by the constraint.