Common Lisp Interface Manager 2.0 User's Guide > Chapter 17 Formatted Output > 17.1 Formatting Tables in CLIM > 17.1.3 Examples of Formatting Tables

NextPrevUpTopContentsIndex

17.1.3.5 Formatting a Table of a Sequence of Items

The example4 function shows how you can use formatting-item-list to format a table of a sequence of items when the exact arrangement of the items and the table is not important. Note that you use formatting-cell inside the body of formatting-item-list to output each item. You do not use formatting-column or formatting-row , because CLIM figures out the number of columns and rows automatically (or obeys a constraint given in a keyword argument).

(defun example4 (&optional (items *alphabet*) 
                           &key (stream *standard-output*) n-columns n-rows
                           y-spacing x-spacing 
                           max-width max-height) 
  (clim:formatting-item-list 
   (stream :y-spacing y-spacing 
           :x-spacing x-spacing 
           :n-columns n-columns :n-rows n-rows 
           :max-width max-width :max-height max-height) 
   (do () 
       ((null items)) 
     (clim:formatting-cell (stream)
                           (format stream "~A" (pop items)))))) 

Evaluating (example4 :stream *my-window*) shows this table:

     A B C D
     E F G H
     I J K L
     M N O P
     Q R S T
     U V W X
     Y Z
Figure 29. Example4 Table

You can easily add a constraint specifying the number of columns.

Evaluating (example4 :stream *my-stream* :n-columns 8) gives this:

     A B C D E F G H
     I J K L M N O P
     Q R S T U V W X
     Y Z
Figure 30. Example4 Table Reformatted

Common Lisp Interface Manager 2.0 User's Guide - 22 Dec 2009

NextPrevUpTopContentsIndex