SECLNRelative::SetConstraint
Sets a relative constraint
Defined in: RELATIVE.CPP
Syntax
SetConstraint(SECLayoutNode* pNodeFrom,ConstraintType constraintFrom,SECLayoutNode* pNodeTo,ConstraintType constraintTo,int nModifier,float fModifier)
SetConstraint(SECLayoutNode* pNodeFrom,ConstraintType constraintFrom,int nValue)
SetConstraint(SECLNRelativeConstraint* pConstraint)
Return Value
TRUE on success, FALSE on failure
Parameters
pNodeFrom
Node to which the constraint is applied
constraintFrom
Type of constraint applied to pNodeFrom
pNodeTo
Position pNodeFrom relative to this node. Use NULL for absolute position.
constraintTo
Constraint on pNodeTo to compare relative to pNodeFrom
nModifier
Modifier for additive relations
fModifier
Modifier for multiplicative relations
nValue
Absolute position value
pConstraint
Constraint object
Comments
This method is the primary interface for setting relative layout constraints. You can utilize the REL_* constants to simplify constraint type usage (see SECLNRelativeConstraint).
The first 2 overloads automatically construct a SECLNRelativeConstraint object and manage the allocated memory. If you need to customize or add your own constraints, you can derive a class from SECLNRelativeConstraint and utilize the third overload to merge into this node's constraint list (you will have to manually deallocate this memory).
Example
Constraints can be applied between 2 nodes in the layout, or to 1 node with
absolute positioning. Use the constraints to control left, right, top, bottom,
width, height, or centering configurations. Example usages:
(ordered as node from, constraint from, node to, constraint to, int modifier, float modifier)
A, REL_LEFT, B, REL_LEFT, 0, 0 Set left position of A equal to left pos of B
A, REL_LEFT, B, REL_RIGHT, 0, 0 Set left pos of A equal to right of B
The int modifier is used for additive manipulation of constraints
A, REL_LEFT, B, REL_LEFT, 10, 0 Set left pos of A equal to left of B, plus 10
A, REL_TOP, B, REL_BOTTOM, -20, 0 Set top of A equal to bottom of B, minus 20
The float modifier is used for multiplicative manipulation of constraints
A, REL_WIDTH, B, REL_WIDTH, 0, 0.5 Set the width of A equal to 0.5 times the width of B
A, REL_HEIGHT, B, REL_WIDTH, 0, 1.2 Set the height of A equal to 1.2 times the width of B
You can use BOTH the float and int modifiers in conjunction (mult gets precedence)
A, REL_WIDTH, B, REL_WIDTH, 10, 0.5 A(width) = (0.5 * B(width)) + 10
A, REL_LEFT, B, REL_WIDTH, -20, 0.1 A(left) = (0.1 * B(width)) + (-20)
If second node is NULL, use absolute positioning
A,REL_LEFT,NULL,<ignored>,25,<ignored> Position left of A at position 25
A,REL_WIDTH,NULL,<ignored>,30,<ignored> Set width of A to 30
Use the MOVE_* constraints to move an entire window without resizing
A, REL_MOVEL, B, REL_LEFT, 0,0 Move node A, align left with left side of B
A, REL_MOVEL, B, REL_RIGHT,0,0 Move node A, align left with right side of B
A, REL_MOVET, B, REL_WIDTH,0,0 Move node A, align top to position equal to width of B
A, REL_MOVER, B, REL_RIGHT,10,1.1 Move node A, align right to 1.1*right of B, plus 10
A, REL_MOVEL, NULL, 10, 0 Move node A, align left at position 10
See Also