Developer

API Reference

Constraint

Brew Release
Brew MP 1.0.2
See Also
Description
This data type defines constraint elements for each coordinate of an object -- top, bottom, left and right -- thereby allowing the position and size of that object to be fully determined in terms relative to other objects or itself. To illustrate a very basic example, consider an widget whose position and size is entirely determined by the dimensions of the display. Regardless of the device, the desire is to always place this object centered on the display, inset by 4 pixels on all sides, like so
                                        +------------------+
                                        |    display #2    |
                                        |  +------------+  |
   +----------------------------+       |  |            |  |
   |         display #1         |       |  |            |  |
   |  +----------------------+  |       |  |            |  |
   |  |                      |  |       |  |            |  |
   |  |                      |  |       |  |            |  |
   |  |                      |  |       |  |            |  |
   |  |        widget        |  |       |  |   widget   |  |
   |  |                      |  |       |  |            |  |
   |  |                      |  |       |  |            |  |
   |  |                      |  |       |  |            |  |
   |  +----------------------+  |       |  |            |  |
   |                            |       |  |            |  |
   +----------------------------+       |  |            |  |
                                        |  +------------+  |
                                        |                  |
                                        +------------------+


To accomplish this, the application would create a constraint container with the exact dimensions of the device display, then create the widget and specify constraints on all four sides relative to the parent container, in the following manner:
       Widget Coordinate       type                       offset
       -----------------       ----                       ------
             top               CONSTRAINT_PARENT_TOP         4
             bottom            CONSTRAINT_PARENT_BOTTOM     -4
             left              CONSTRAINT_PARENT_LEFT        4
             right             CONSTRAINT_PARENT_RIGHT      -4


The collection of all four constraint coordinates together define the Constraint data structure.
Members
  • left:    Defines how the left coordinate of the object should be constrained by
                another object or itself.
  • right:   Defines how the right coordinate of the object should be constrained by
                another object or itself.
  • top:     Defines how the top coordinate of the object should be constrained by
                another object or itself.
  • bottom:  Defines how the bottom coordinate of the object should be constrained by
                another object or itself.
    
Definition
   typedef struct {
      ConstraintElem left;
      ConstraintElem right;
      ConstraintElem top;
      ConstraintElem bottom;
   } Constraint;
Comment
To indicate that a particular constraint coordinate should be ignored, the 'type' field of a ConstraintElem should be set to WIDGET_KEEP_EXTENT. For example, a radio button may have constraints defined for its left, right and top bounds, but the bottom coordinate would be determined by the existing height of the widget.
  • Follow