All Manuals > CAPI User Guide and Reference Manual > 9 Adding Toolbars

9.2 Creating a toolbar with several buttons

Let us create three more buttons:

(setf file-buttons
      (loop for image in file-images
            collect
            (make-instance 'toolbar-button
                           :image image
                           :name image
                           :text
                           (string-capitalize
                            (substitute #\Space #\-
                                        (string image))))))

and then include them along with the print button defined in 9.1 Creating a toolbar button:

(display
 (make-instance
  'interface
  :toolbar-items (append file-buttons (list print-button))))

Remember that each instance of a toolbar button must not be used in more than one place at a time.

It is possible to include to include toolbar buttons which are not initially displayed, but which are available for the user to add. For the details, see 9.6 Modifying toolbars.

9.2.1 Grouping toolbar buttons

The toolbar-component class lets you group related buttons together in a toolbar. This allows similar buttons to:

Toolbar components are actually choices similar to button panels. By default, their interaction is :single-selection.

We can amend our example using toolbar components to group the file buttons separately from the print button:

(display
 (make-instance
  'interface
  :toolbar-items (list
                  (make-instance 'toolbar-component
                                 :items file-buttons)
                  (make-instance 'toolbar-component
                                 :items (list print-button)))
  :visible-min-width 200))

9.2.2 Implicitly-created buttons

A toolbar-component may contain arbitrary Lisp objects as items. For each such object, a toolbar button is automatically created, using the appropriate elements of the component's images, names, texts and tooltips lists.

(display
 (make-instance
  'interface
  :toolbar-items
  (list (make-instance 'toolbar-component
                       :items file-images
                       :images file-images
                       :names file-images
                       :texts
                       (mapcar 'string-capitalize file-images)
                       :tooltips
                       (mapcar 'string-downcase file-images)
                       :selection-callback
                       (lambda (data interface)
                          (display-message "callback data ~S" data))
                       ))))

Rather than selection-callback above, you could supply callbacks to specify callback functions for each button.


CAPI User Guide and Reference Manual (Unix version) - 01 Dec 2021 19:32:36