All Manuals > CLIM 2.0 User Guide > 10 Panes and Gadgets

10.2 Layout Panes

This section describes the various layout panes provided by CLIM and the protocol that these panes obey.

The layout panes described in this section are all composite panes that are responsible for positioning their children according to various layout rules. Layout panes can be selected in the same way as other panes by using make-pane or make-instance. For convenience and readability of pane layouts, many of these panes also provide a macro that expands into a make-pane form, passing a list of the panes created in the body of the macro as the :contents argument. For example, you can express a layout of a vertical column of two label panes either as:

(make-instance 'vbox-pane 
               :contents (list
                          (make-instance 'label-pane :text "One") 
                          (make-instance 'label-pane :text "Two"))) 

or as:

(vertically () 
            (make-instance 'label-pane :text "One") 
            (make-instance 'label-pane :text "Two")) 

10.2.1 Layout Pane Options

:contents Option

Summary: All layout pane classes accept the :contents options, which specifies the child panes to be laid out.

:width
:max-width
:min-width
:height
:max-height
:min-height Options

Summary: These options control the space requirement parameters for laying out the pane. The :width and :height options specify the preferred horizontal and vertical sizes. The :max-width and :max-height options specify the maximum amount of space that may be consumed by the pane, and give CLIM's pane layout engine permission to grow the pane beyond the preferred size. The :min-width and :min-height options specify the minimum amount of space that may be consumed by the pane, and give CLIM's pane layout engine permission to shrink the pane below the preferred size.

If either the :max-width or the :min-width option is not supplied, it defaults to the value of the :width option. If either the :max-height or the :min-height option is not supplied, it defaults to the value of the :height option.

:max-width, :min-width, :max-height, and :min-height can also be specified as a relative size by supplying a list of the form (number :relative). In this case, the number indicates the number of device units that the pane is willing to stretch or shrink.

The values of these options are specified in the same way as the :x-spacing and :y-spacing options to formatting-table. (Note that :character and :line may only be used on those panes that display text, such as a clim-stream-pane or a label-pane.)

+fill+ Constant

Summary: Use this constant as a value to any of the relative size options. It indicates that pane's willingness to adjust an arbitrary amount in the specified direction.

:align-x
:align-y Options

Summary: The :align-x option is one of :right, :center, or :left. The :align-y option is one of :top, :center, or :bottom. These specify how child panes are aligned within the parent pane. These have the same semantics as for formatting-cell.

:x-spacing
:y-spacing
:spacing Options

Summary: These spacing options apply to hbox-pane, vbox-pane, table-pane, and indicate the amount of horizontal and vertical spacing (respectively) to leave between the items in boxes or rows and columns in table. The values of these options are specified in the same way as the :x-spacing and :y-spacing options to formatting-table. :spacing specifies both the x and y spacing at once.

10.2.2 Layout Pane Classes

hbox-pane Composite Pane

horizontally Macro

horizontally (&rest options &key spacing &allow-other-keys) &body contents

Summary: The hbox-pane class lays out all its child panes horizontally from left to right. The horizontally macro is a convenient interface for creating an hbox-pane.

contents is one or more forms that are the child panes. Each form in contents is of the form:

vbox-pane Composite Pane

vertically Macro

vertically (&rest options &key spacing &allow-other-keys) &body contents

Summary: The vbox-pane class lays out all of its child panes vertically, from top to bottom. The vertically macro serves as a convenient interface for creating an vbox-pane.

contents is as for horizontally.

table-pane Composite Pane

tabling Macro

tabling (&rest options) &body contents

Summary: This pane lays out its child panes in a two-dimensional table arrangement. Each column of the table is specified by an extra level of list in contents. For example:

(tabling ()
  ((make-pane 'label :text "Red")
   (make-pane 'label :text "Green")
   (make-pane 'label :text "Blue"))
  ((make-pane 'label :text "Intensity")
   (make-pane 'label :text "Hue")
   (make-pane 'label :text "Saturation")))

spacing-pane Composite Pane

spacing Macro

spacing (&rest options &key thickness &allow-other-keys) &body contents

Summary: This pane reserves some margin space around a single child pane. The space requirement keys that are passed in indicate the requirements for the surrounding space, not including the requirements of the child.

outlined-pane Composite Pane

outlining Macro

outlining (&rest options &key thickness &allow-other-keys) &body contents

Summary: This layout pane puts an outline of thickness thickness around its contents.

Use the :background option to control the ink used to draw the background.

bboard-pane Composite Pane

Summary: A pane that allows its children to be any size and lays them out wherever they want to be (for example, a desktop manager).

scroller-pane Composite Pane

scrolling Macro

scrolling (&rest options) &body contents

Summary: Creates a composite pane that allows the single child specified by contents to be scrolled. options may include a :scroll-bar option. The value of this option may be t (the default), which indicates that both horizontal and vertical scroll bars should be created; :vertical, which indicates that only a vertical scroll bar should be created; or :horizontal, which indicates that only a horizontal scroll bar should be created.

The pane created by the scrolling includes a scroller-pane that has as children the scroll bars and a viewport. The viewport of a pane is the area of the window's drawing plane that is currently visible to the user. The viewport has as its child the specified contents.

hrack-pane
vrack-pane Composite Panes

Summary: Similar to the hbox-pane and vbox-pane classes, except that these ensure that all children are the same size in the minor dimension. In other words, these panes are used to create stacks of same-sized items, such as menu items.

An hrack-pane is created when the :equalize-height option to horizontally is t. A vrack-pane is created when the :equalize-width option to vertically is t.

Note: hrack-pane and vrack-pane are available only in Liquid CL CLIM.

restraining-pane Composite Pane

restraining Macro

restraining (&rest options) &body contents

Summary: Wraps the contents with a pane that prevents changes to the space requirements for contents from causing re-layout of panes outside the restraining context. This prevents the size constraints of the child from propagating up beyond this point.

Note: restraining-pane and restraining are available only in Liquid CL CLIM.

10.2.3 Composite Pane Generic Functions

pane-viewport Generic Function

pane-viewport pane

Summary: Returns the pane's viewport, if one exists.

pane-viewport-region Generic Function

pane-viewport-region pane

Summary: If a viewport for the pane exists, the viewport's region is returned.

pane-scroller Generic Function

pane-scroller pane

Summary: Checks to see whether a pane has an associated scroller pane, and returns it if it does.

scroll-extent Generic Function

scroll-extent pane x y

Summary: If the pane argument has an associated viewport, it resets the viewport to display the portion of the underlying stream starting at (x, y).

10.2.4 The Layout Protocol

The layout protocol is triggered by layout-frame, which is called when a frame is adopted by a frame manager.

CLIM uses a two-pass algorithm to lay out a pane hierarchy. In the first pass (called space composition), the top-level pane is asked how much space it requires. This may in turn lead to the same question being asked recursively of all the panes in the hierarchy, with the answers being composed to produce the top-level pane's answer. Each pane answers the query by returning a space requirement (or space-requirement) object, which specifies the pane's desired width and height, as well as its willingness to shrink or grow along its width and height.

In the second pass (called space allocation), the frame manager attempts to obtain the required amount of space from the host window system. The top-level pane is allocated the space that is actually available. Each pane, in turn, allocates space recursively to each of its descendants in the hierarchy according to the pane's rules of composition.

For many types of panes, the application programmer can indicate the space requirements of the pane at creation time by using the space requirement options, as well as by calling the change-space-requirements function. Panes are used to display application-specific information, so the application can determine how much space should normally be given to them.

Other pane types automatically calculate their space needs based on the information they have to present. For example, the space requirement for a label pane is a function of the text to be displayed.

A composite pane calculates its space requirement based on the requirements of its children and its own particular rule for arranging them. For example, a pane that arranges its children in a vertical stack would return as its desired height the sum of the heights of its children. Note, however, that a composite pane is not required by the layout protocol to respect the space requests of its children; in fact, composite panes are not even required to ask their children.

Space requirements are expressed for each of the two dimensions as a preferred size, a minimum size below which the pane cannot be shrunk, and a maximum size above which the pane cannot be grown. (The minimum and maximum sizes can also be specified as relative amounts.) All sizes are specified as a real number indicating the number of device units (such as pixels).

space-requirement Protocol Class

Summary: The protocol class of all space requirement objects. There are one or more subclasses of space-requirement with implementation-dependent names that implement space requirements. The exact names of these classes is explicitly unspecified. If you want to create a new class that behaves like a space requirement, it should be a subclass of space-requirement. Subclasses of space-requirement must obey the space requirement protocol.

All the instantiable space requirement classes provided by CLIM are immutable.

make-space-requirement Function

make-space-requirement &key (width 0) (max-width 0) (min-width 0) (height 0) (max-height 0) (min-height 0)

Summary: Constructs a space requirement object with the given characteristics :width, :height, and so on.

space-requirement-width Function

space-requirement-width space-req

(setf space-requirement-width) Function

(setf space-requirement-width) size space-req

space-requirement-max-width Function

space-requirement-max-width space-req

(setf space-requirement-max-width) Function

(setf space-requirement-max-width) size space-req

space-requirement-min-width Function

space-requirement-min-width space-req

(setf space-requirement-min-width) Function

(setf space-requirement-min-width) size space-req

space-requirement-height Function

space-requirement-height space-req

(setf space-requirement-height) Function

(setf space-requirement-height) size space-req

space-requirement-max-height Function

space-requirement-max-height space-req

(setf space-requirement-max-height) Function

(setf space-requirement-max-height) size space-req

space-requirement-min-height Function

space-requirement-min-height space-req

(setf space-requirement-min-height) Function

(setf space-requirement-min-height) size space-req

Summary: These read or modify the components of the space requirement space-req.

space-requirement-components Generic Function

space-requirement-components space-req

Summary: Returns the components of the space requirement space-req as six values: the width, minimum width, maximum width, height, minimum height, and maximum height.

space-requirement-combine Function

space-requirement-combine function sr1 sr2

Summary: Returns a new space requirement, each component of which is the result of applying the function function to each of the components of the two space requirements sr1 and sr2.

function is a function of two arguments, both of which are real numbers. It has dynamic extent.

space-requirement+ Function

space-requirement+ sr1 sr2

Summary: Returns a new space requirement whose components are the sum of each of the components of the two space requirements sr1 and sr2.

space-requirement+* Function

space-requirement+* space-req &key width max-width min-width height max-height min-height

Summary: Returns a new space requirement whose components are the sum of each of the components of space-req added to the appropriate keyword argument (for example, the width component of space-req is added to width). This is intended to be a more efficient, spread version of space-requirement+.

change-space-requirements Generic Function

change-space-requirements pane &key resize-frame &rest space-req-keys

Summary: This function can be invoked to indicate that the space requirements for pane have changed. Any of the options that applied to the pane at creation time can be passed into this function as well.

resize-frame determines whether the frame should be resized to accommodate the new space requirement of the hierarchy. If resize-frame is t, then layout-frame will be invoked on the frame. If resize-frame is nil, then the frame may or may not get resized depending on the pane hierarchy and the :resize-frame option that was supplied to define-application-frame.

note-space-requirements-changed Generic Function

note-space-requirements-changed sheet pane

Summary: This function is invoked whenever pane's space requirements have changed. sheet must be the parent of pane. Invoking this function essentially means that compose-space will be reinvoked on pane, and it will reply with a space requirement that is not equal to the reply that was given on the last call to compose-space.

This function is automatically invoked by change-space-requirements in the cases that layout-frame isn't invoked. In the case that layout-frame is invoked, it isn't necessary to call note-space-requirements-changed, since a complete re-layout of the frame will be executed.

changing-space-requirements Macro

changing-space-requirements (&key resize-frame layout) &body body

Summary: This macro supports batching the invocation of the layout protocol by calls to change-space-requirements. Within the body, all calls to change-space-requirements change the internal structures of the pane and are recorded. When the body is exited, the layout protocol is invoked appropriately. body may have zero or more declarations as its first forms.

compose-space Generic Function

compose-space pane

Summary: During the space composition pass, a composite pane will typically ask each of its children how much space it requires by calling compose-space. They answer by returning space-requirement objects. The composite will then form its own space requirement by composing the space requirements of its children according to its own rules for laying out its children.

allocate-space Generic Function

allocate-space pane width height

Summary: During the space allocation pass, a composite pane will arrange its children within the available space and allocate space to them according to their space requirements and its own composition rules by calling allocate-space on each of the child panes. width and height are the width and height of pane in device units.


CLIM 2.0 User Guide - 01 Dec 2021 19:38:58