Constraint#
Superclasses: Object
GtkConstraint
describes a constraint between attributes of two widgets,expressed as a linear equation.
The typical equation for a constraint is:
target.target_attr = source.source_attr × multiplier + constant
Each GtkConstraint
is part of a system that will be solved by a
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#
- class Constraint
- classmethod new(target: ConstraintTarget | None, target_attribute: ConstraintAttribute, relation: ConstraintRelation, source: ConstraintTarget | None, source_attribute: ConstraintAttribute, multiplier: float, constant: float, strength: int) Constraint #
Creates a new constraint representing a relation between a layout attribute on a source and a layout attribute on a target.
- Parameters:
target – the target of the constraint
target_attribute – the attribute of
target
to be setrelation – the relation equivalence between
target_attribute
andsource_attribute
source – the source of the constraint
source_attribute – the attribute of
source
to be readmultiplier – a multiplication factor to be applied to
source_attribute
constant – a constant factor to be added to
source_attribute
strength – the strength of the constraint
- classmethod new_constant(target: ConstraintTarget | None, target_attribute: ConstraintAttribute, relation: ConstraintRelation, constant: float, strength: int) Constraint #
Creates a new constraint representing a relation between a layout attribute on a target and a constant value.
- Parameters:
target – a the target of the constraint
target_attribute – the attribute of
target
to be setrelation – the relation equivalence between
target_attribute
andconstant
constant – a constant factor to be set on
target_attribute
strength – the strength of the constraint
Methods#
- class Constraint
-
- get_multiplier() float #
Retrieves the multiplication factor applied to the source attribute’s value.
- get_relation() ConstraintRelation #
The order relation between the terms of the constraint.
- get_source() ConstraintTarget | None #
Retrieves the
ConstraintTarget
used as the source for the constraint.If the source is set to
NULL
at creation, the constraint will use the widget using theConstraintLayout
as the source.
- get_source_attribute() ConstraintAttribute #
Retrieves the attribute of the source to be read by the constraint.
- get_target() ConstraintTarget | None #
Retrieves the
ConstraintTarget
used as the target for the constraint.If the targe is set to
NULL
at creation, the constraint will use the widget using theConstraintLayout
as the target.
- get_target_attribute() ConstraintAttribute #
Retrieves the attribute of the target to be set by the constraint.
- is_attached() bool #
Checks whether the constraint is attached to a
ConstraintLayout
, and it is contributing to the layout.
Properties#
- class Constraint
-
- props.relation: ConstraintRelation#
The type of the None singleton.
- props.source: ConstraintTarget#
The type of the None singleton.
- props.source_attribute: ConstraintAttribute#
The type of the None singleton.
- props.target: ConstraintTarget#
The type of the None singleton.
- props.target_attribute: ConstraintAttribute#
The type of the None singleton.