OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
Defining Constraining Relationships

A single layout constraint is not enough to lay out a window.

For example, specifying that one window must be 10 pixels below another window does not tell you anything about the width or height of the window, the location of the left or right borders, or the location of the bottom border. It only tells you that one edge is located 10 pixels below another window.

A combination of layout constraints can fully define a window's location (though there are some exceptions). The class TLayoutMetrics uses four layout constraint structures–two TEdgeConstraint objects named X and Y, a TEdgeOrWidthConstraint named Width, and a TEdgeOrHeightConstraint named Height.

TLayoutMetrics is a fairly simple class. The constructor takes no parameters. The only thing it does is to set up each layout constraint member. For each layout constraint, the constructor

  • Zeroes out the value for the constraining window.
  • Sets the constraint's relationship to lmAsIs.
  • Sets units to lmLayoutUnits.
  • Sets the value to 0.

The only difference is with MyEdge, which indicates the edge of the window this constraint applies to. X is set to lmLeft, Y is set to lmTop, Width is set to lmWidth, and Height is set to lmHeight.

Once you have constructed a TLayoutMetrics object, you need to set the layout constraints for the window you want to lay out. You can use the functions described in Defining Constraints for setting each layout constraint.

X, Y, Width, and Height Labels

It is important to realize that the labels X, Y, Width, and Height are more labels of convenience than strict rules on how the constraints should be used. X can represent the X coordinate of the left edge, the right edge, or the center. You can combine this with the Width constraint-which can be lmCenter, lmRight, or lmWidth-to completely define the window's X-axis location and width. Using all the edge constraints is easy and is useful in situations where tiling is performed.

The simplest way is to assign an X coordinate to X and a width to width. But you could also set the edge for X to lmCenter and the edge for Width to lmRight. So Width does not really represent a width, but the X-coordinate of the window's right edge. If you know the X-coordinate of the right edge and the center, it's easy to calculate the X-coordinate of the left edge.

Indeterminate Constraints

You must be careful about how you specify your layout constraints. The constraints available in the TLayoutMetrics class give you the ability to fully describe a window. But they do not guarantee that the constraints you use fully describe a window. In cases where the constraints do not fully describe a window, the most likely result is an application crash.

Example

To better understand how constraints work together to describe a window, try building and running the example application LAYOUT in the directory EXAMPLES\OWL\CLASSES. This application has a number of child windows in a layout window. A dialog box you can access from the menu lets you change the constraints of each of the windows and then see the results as the windows are laid out. Be careful, though. If you specify a set of layout constraints that does not fully describe a window, the application will probably crash, or, if diagnostics are on, a check will occur.