The following example shows how to define and to apply a VA constraint for the DesignComposer.
Assumed we have a vertically sequence of objects. What we want to do is to center the objects horizontally among each other.
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.
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;
{
...
}
}
Screenshots below show the new constraint at work:
|
without Constraint |
with Constraint |
The first picture shows a result without centering, the second one the same problem solved using centering.