Creating a VA Constraint

The following example shows how to define and to apply a VA constraint for the DesignComposer.

Task

Assumed we have a vertically sequence of objects. What we want to do is to center the objects horizontally among each other.

Writing a VA Constraint

This task could be solved by a binary VA constraint. It could be expressed in DCL this way:

VAConstraint hCenterRel(designobj target,designobj source)
{
	math xNew;
	xNew = x(source) + (w(source)-w(target))/2;
	if ( xNew < 0 ) {
		setx(target,0);
	}
	else {
		setx(target,xNew);
	}
}

The constraint gets two object instances target and source as arguments. target is the object whose coordinates should be checked - and modified when required.

Activating the VA Constraint

What we have to do is to notify a design command (or more) to apply this constraint to all layout objects found in its container.

design sequence() {
	pattern first:
		...
		constraints = hCenterRel;
	{
		...
	}
}

Result

Screenshots below show the new constraint at work:

result without centering

without Constraint

result with centering

with Constraint

The first picture shows a result without centering, the second one the same problem solved using centering.