Ratio Justification

Child in Top-Left Sixteenth of Parent

FIGURE 5.26 shows a parent view whose width is 200 and whose height is 100. It has one child which takes up the top one-quarter and left one-quarter. The easiest way to accomplish this is to use parentTop/parentLeft justification:

viewJustify
parentTop, parentLeft, topRatio, leftRatio, rightRatio, bottomRatio

viewBounds
{top: 0, left: 0, bottom: 25, right: 25}

Each of the viewBounds slots are treated as percentages (due to the four ratio justifications) of the parent width/height. Therefore, the viewBounds are interpreted as ranging from 0% to 25% horizontally (and vertically) of the parent's width (height). Strictly speaking, the topRatio and leftRatio are unnecessary since 0 interpreted as a percentage is still 0. Nonetheless, it is probably clearer to always set both left and right (or both top and bottom) ratios.

FIGURE 5.26 : A parent view with a child taking up its top 25% and left 25%.


A less clear way to accomplish the same result is to use parentBottom/parentRight justification:

viewJustify
parentBottom, parentRight, topRatio, leftRatio, rightRatio, bottomRatio

viewBounds
{top: -100, left: -100,
bottom: -75, right: -75}

Here the percentages are -100% top and left, and -75% bottom and right. Since the parent height is 100, -100% of the height is -100 and -75% of the height is -75. Using -100 parentBottom justification means that the top of the child view starts at 0. The bottom of the view ends at 25. Similarly, the left of the child view starts at 0 and the right ends at 50.

Yet another way is to use full justification:

viewJustify
parentFull (horizontal and vertical), topRatio, leftRatio, rightRatio, bottomRatio

viewBounds
{top: 0, left: 0, bottom: -75, right: -75}

Finally, probably the most confusing uses center justification (we'll make it 24% in each direction rather than 25% because otherwise we'd need fractional bounds, which can't be specified):

viewJustify
parentCenter (horizontal and vertical), topRatio, leftRatio, rightRatio, bottomRatio

viewBounds
{top: -38, left: -38, bottom: -14, right: -14}


An online version of Programming for the Newton using Macintosh, 2nd ed. ©1996, 1994, Julie McKeehan and Neil Rhodes.

Last modified: 1 DEC 1996