Examples

Reorganize Views in Landscape Mode

When the screen is rotated, you may need to rearrange not just the widths of views, but their relative positions. FIGURE 6.8 shows the Calculator application in both portrait and landscape modes.

FIGURE 6.8 : Calculator application in portrait and landscape modes.


The calculator application appears to be constructed of two views which are either one above the other or side-by-side. We'll create an application which operates similarly (see FIGURE 6.9). A QuickTime movie of this example is available, as is the completed project for different platforms (Mac OS, Windows 3.1 or Windows 95/NT).

FIGURE 6.9 : Application with top-to-bottom or side-by-side views.


The solution to this is to add a viewSetupFormScript to view2 which changes its viewJustify slot as it opens:

func()
begin
   inherited:?viewSetupFormScript();

   local parentBounds := :Parent():LocalBox();
   if parentBounds.right > parentBounds.bottom
      then begin
      // landscape mode
      self.viewJustify := vjParentTopV +
         vjSiblingRightH;
   end else begin
      // portrait mode
      self.viewJustify := vjSiblingBottomV +
         vjParentLeftH;
   end;
end
The code checks to see whether it is located within a view which is wide or tall. If it is wide, then the justification is right-justified to its sibling; if it is tall, then the justification is bottom-justified to its sibling.

Note that there is no explicit check to see whether the Newton is in rotated mode or not. Instead, we check what actually matters: is the view we are in wider than it is tall?


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

Last modified: 1 DEC 1996