View layout

View layout, the process of analyzing and negotiating the position and size of views on the screen, is something you must implement as appropriate for your view subclass. The View System provides a few simple interface hooks for layout. You need to understand the underlying concepts before you can use the interfaces effectively.

Bounds and allocated area

The View System uses two distinct notions of a view's size: bounds and allocated area. The bounds of a view represent its "natural size" in its own coordinate system. A view's bounds are unaffected by how the view's parent transforms the view for display purposes. A view's allocated area is the space that the view's parent allocates for displaying the view.

To help illustrate the distinction between bounds and allocated area, Figure 30 shows a "slide viewer" view that presents images in one of three fixed, square spaces. The images are contained in child views. The fixed squares are the allocated areas for the child views.


If a child view's bounds are square, the child view naturally fits into the allocated area. This retains the width-to-height ratio, or aspect ratio, of the child view's bounds.

However, suppose you want to display an image whose bounds are not square, such as the line graph shown in Figure 31. Because the allocated area in this example is a fixed square, it is not possible to retain the aspect ratio of the child when rendering the child in the allocated area. The parent needs a layout policy to determine how to resolve the conflict between bounds and allocated area.


The View System provides no generic mechanism for resolving conflicts between the bounds of a child view and the allocated area in the parent view. Your implementation for the parent class determines how to resolve the conflict. Typically, the parent uses one of three approaches:

In every case, the parent determines the final result. Because the parent view owns its children, a child cannot set its own allocated area (unless the parent provides an explicit mechanism for doing so).


[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker