Resources | Resources |



Constraint container

In a constraint container, widgets are laid out relative to the placement of other widgets and/or the container.

The constraint container is used to manage widgets in a complex and flexible layout by positioning them relative to the container itself, or relative to other objects held in the container. Objects are laid out in the order that the widgets appear in the container's widget stack, with the position of each object determined by the set of constraint elements. For each widget inserted into a constraint container, the application must specify a constraint element per dimension (top, bottom, left, and right). The constraint element can specify the position relative to the parent, previous widget, or its own extent.

The position and size of a widget is determined by the size of the parent container, and the position and size of all the other widgets in the container. As the size and shape of the constraint container changes, so do the size, shape, and position of each of the widgets it manages. Regardless of the size and shape of the container, the widgets it manages maintain consistent appearance relative to one another. Likewise, as objects are added or removed from the container, or as individual constraint points are modified, the dimensions and placement of other objects changes.

If a constraint point has been defined relative to the previous object, and that object is invisible, constraint container traverses the widget stack until it finds the first visible widget, and bases the constraint point on that widget's layout. The constraint container is described in greater detail in AEEConstraintContainer.h in the

Using constraint container

Widgets are inserted in a constraint container by calling IConstraintContainer_Insert(). The constraints used for inserting the widget are specified in WidgetConstraint data structure. For example:

WidgetConstraint      wc;

// Create Constraint Container
nErr = ISHELL_CreateInstance(pMe->m_pIShell, AEECLSID_CConstraintContainer, 

// Obtain the Constraint Container’s widget interface
if (AEE_SUCCESS == nErr) {
   nErr = IConstraintContainer_QueryInterface(pConstraintCont, AEEIID_IWidget, 

/* Set the container’s extent and create widget */

// Set widget constraint properties
wc.bVisible                 = TRUE;
wc.constraint.left.type     = CONSTRAINT_PARENT_LEFT;
wc.constraint.left.offset   = 0;
wc.constraint.right.type    = CONSTRAINT_PARENT_RIGHT;
wc.constraint.right.offset  = 20;      = CONSTRAINT_PARENT_TOP;    = 10;
wc.constraint.bottom.type   = WIDGET_SIZE_TO_FIT;
wc.constraint.bottom.offset = 0;

// Insert widget into Constraint Container
if (AEE_SUCCESS == nErr) {
   nErr = IConstraintContainer_Insert(pConstraintCont, pWidget, WIDGET_ZNORMAL, &wc);