All Manuals > Common Lisp Interface Manager 2.0 User's Guide > Chapter 12 Menus and Dialogs > 12.4 Examples of Menus and Dialogs in CLIM

NextPrevUpTopContentsIndex

12.4.5 Using menu-choose

The simplest use of menu-choose is when each item is not a list. In that case, the entire item will be printed and is also the value to be returned.

 
(clim:menu-choose '("One" "Two" "Seventeen")) 

If you want to return a value that is different from what was printed, the simplest method is as follows. Each item is a list; the first element is what will be printed, the remainder of the list is treated as a plist --the :value property will be returned. (Note nil is returned if you click on Seventeen since it has no :value .)

(clim:menu-choose
 '(("One" :value 1 :documentation "the loneliest number")      
   ("Two" :value 2 :documentation "for tea")   
   ("Seventeen" 
    :documentation "teen magazine"))) 

The list of items you pass to menu-choose can serve other purposes in your application, so you might not want to put the printed appearance in the first element. You can supply a :printer function that will be called on the item to produce its printed appearance.

(clim:menu-choose '(1 2 17)      
                  :printer #'(lambda (item stream)
                               (format stream "~R" item))) 

The items in the menu need not be printed textually:

(clim:menu-choose
  '(circle square triangle) 
  :printer
  #'(lambda (item stream)        
      (case item                 
        (circle (clim:draw-circle* stream 0 0 10)) 
        (square (clim:draw-polygon* stream '(-8 -8 -8 8 8 8 8 -8)))
        (triangle (clim:draw-polygon* stream '(10 8 0 -10 -10 8))))))

The :item-list option of the list form of menu item can be used to describe a set of hierarchical menus.

(clim:menu-choose 
  '(("Class: Osteichthyes" :documentation "Bony fishes" 
     :style (nil :italic nil)) 
    ("Class: Chondrichthyes" 
     :documentation "Cartilaginous fishes" 
     :style (nil :italic nil) 
      :item-list (("Order: Squaliformes" :documentation "Sharks")                  
               ("Order: Rajiformes" :documentation "Rays"))) 
    ("Class: Mammalia" :documentation "Mammals" :style (nil :italic nil) 
     :item-list 
     (("Order Rodentia" :item-list ("Family Sciuridae" 
                                   "Family Muridae"
                                   "Family Cricetidae"
                                   ("..." :value nil))) 
      ("Order Carnivora" :item-list ("Family: Felidae" 
                                    "Family: Canidae" 
                                    "Family: Ursidae" 
                                    ("..." :value nil)))           
      ("..." :value nil)))
 ("..." :value nil)) ) 

Common Lisp Interface Manager 2.0 User's Guide - 7 Aug 2017

NextPrevUpTopContentsIndex