The :panes
and :layouts
keywords can take a number of panes and layouts, each specified one after the other. By listing several panes, menus, and so on, complicated interfaces can be constructed quickly.
To see how simply this is done, let us add an editor pane to our interface. We need this to display the text contained in the file chosen with the Open File button.
The editor pane needs a layout. It could be added to the row-layout already built, or another layout could be made for it. Then, the two layouts would have to be put inside a third to contain them (see Laying Out CAPI Panes).
The first thing to do is add the editor pane to the panes description. The old panes description read:
(:panes
(page-up push-button
:text "Page Up")
(page-down push-button
:text "Page Down")
(open-file push-button
:text "Open File"))
The new one includes an editor pane named viewer
.
(:panes
(page-up push-button
:text "Page Up")
(page-down push-button
:text "Page Down")
(open-file push-button
:text "Open File")
(viewer editor-pane
:title "File:"
:text "No file selected."
:visible-min-height '(:character 8)
:reader viewer-pane))
This specifies the editor pane, with a stipulation that it must be at least 8 characters high. This allows you to see a worthwhile amount of the file being viewed in the pane.
Note the use of :reader
, which defines a reader method for the interface which returns the editor pane. Similarly, you can also specify writers or accessors. If you omit accessor methods, it is still possible to access panes and other elements in an interface instance using with-slots
.
The interface also needs a layout containing the editor pane along with the buttons. The old layouts description read:
(:layouts
(row-of-buttons row-layout
'(page-up page-down open-file)))
(:layouts
(main-layout column-layout
'(row-of-buttons viewer))
(row-of-buttons row-layout
'(page-up page-down open-file))
)
This encapsulates the new pane viewer
into a column-layout called main-layout
. This is used as the default layout, specified by setting the :layout
initarg to main-layout
in the :default-initargs
section. If there is no default layout specified, uses the first one listed.
By putting the layout of buttons and the editor pane in a column layout, their relative position has been controlled: the buttons appear in a row above the editor pane.
The code for the new interface is now as follows:
(define-interface demo ()
()
(:panes
(page-up push-button
:text "Page Up")
(page-down push-button
:text "Page Down")
(open-file push-button
:text "Open File")
(viewer editor-pane
:title "File:"
:text "No file selected."
:visible-min-height '(:character 8)
:reader viewer-pane))
(:layouts
(main-layout column-layout
'(row-of-buttons viewer))
(row-of-buttons row-layout
'(page-up page-down open-file)))
(:default-initargs :title "Demo"))
Displaying an instance of the interface by entering the line of code below produces the window in A CAPI interface with editor pane:
(display (make-instance 'demo))
Figure 11.2 A CAPI interface with editor pane
To add menus to your interface you must first specify the menus themselves, and then a menu bar of which they will be a part.
Let us add some menus that duplicate the proposed functionality for the buttons. We will add:
The extra code needed in the define-interface call is this:
(:menus
(file-menu "File"
("Open"))
(page-menu "Page"
("Page Up" "Page Down")))
(:menu-bar file-menu page-menu)
Menu definitions give a slot name for the menu, followed by the title of the menu, a list of menu item descriptions, and then, optionally, a list of keyword arguments for the menu.
In this instance the menu item descriptions are just strings naming each item, but you may wish to supply initialization arguments for an item — in which case you would enclose the name and those arguments in a list.
The menu bar definition simply names all the menus that will be on the bar, in the order that they will appear. By default, of course, the environment may add menus of its own to an interface — for example the Works menu in the LispWorks IDE in multiple menu bar mode.
The code for the new interface is:
(define-interface demo ()
()
(:panes
(page-up push-button
:text "Page Up")
(page-down push-button
:text "Page Down")
(open-file push-button
:text "Open File")
(viewer editor-pane
:title "File:"
:text "No file selected."
:visible-min-height '(:character 8)
:reader viewer-pane))
(:layouts
(main-layout column-layout
'(row-of-buttons viewer))
(row-of-buttons row-layout
'(page-up page-down open-file)))
(:menus
(file-menu "File"
("Open"))
(page-menu "Page"
("Page Up" "Page Down")))
(:menu-bar file-menu page-menu)
(:default-initargs :title "Demo"))
Figure 11.3 A CAPI interface with menu items
The menus contain the items specified — try it out to be sure.
CAPI User Guide and Reference Manual (Windows version) - 3 Aug 2017