[previous] [up] [next]     [index]
Next: Containees Up: Windowing Toolbox Overview Previous: Core Windowing Classes

Geometry Management

MrEd's geometry management makes it easy to design windows that look right on all platforms, despite different graphical representations of GUI elements. Geometry management is based on containers; each container arranges its children based on simple constraints, such as the current size of a frame and the natural size of a button.

The built-in container classes include horizontal panels (and panes), which align their children in a row, and vertical panels (and panes), which align their children in a column. By nesting horizontal and vertical containers, a programmer can achieve most any layout. For example, we can construct a dialog with the following shape:

tex2html_wrap66455

with the following program:

  ; Create a dialog 
  (define dialog (make-object dialog% "Example"))

; Add a text field to the dialog (with a dummy callback procedure) (make-object text-field% "Your name" dialog void) ; Note: MzScheme's void procedure accepts any number of arguments

; Add a horizontal panel to the dialog (define panel (make-object horizontal-panel% dialog))

; Add Cancel and Ok buttons to the horizontal panel (make-object button% "Cancel" panel void) (make-object button% "Ok" panel void)

; Change the panel's alignment to center the buttons (send panel set-alignment 'center 'center)

; Show the dialog (send dialog show #t)

Each container arranges its children using the natural size of each child, which usually depends on instantiation parameters of the child, such as the label on a button or the number of choices in a radio box. In the above example, the dialog stretches horizontally to match the minimum width of the text field, and it strteches vertically to match the total height of the field and the buttons. The dialog then stretches the horizontal panel to fill the bottom half of the dialog. Finally, the horizontal panel uses the sum of the buttons' minimum widths to center them horizontally.

As the example demonstrates, a stretchable container grows to fill its environment, and it distributes extra space among its strechable children. By default, panels are stretchable in both directions, whereas buttons are not stretchable in either direction. The programmer can change whether an individual GUI element is stretchable.

The following subsections describe the container system in detail, first discussing the attributes of a containee in Containees, and then describing the attributes of a container in Containers. In addition to the built-in vertical and horizontal containers, programmers can define new types of containers as discussed in the final subsection, Defining New Types of Containers.




[previous] [up] [next]     [index]
Next: Containees Up: Windowing Toolbox Overview Previous: Core Windowing Classes

PLT