78 lines
2.4 KiB
Plaintext
78 lines
2.4 KiB
Plaintext
{ (define LIBNAME "GUI")
|
|
(include "head.tinc") }
|
|
|
|
<p>The teachpack <code>gui.ss</code> provides the following operations:
|
|
<menu>
|
|
<li> <code>{(idx show-window)} : window -> true</code>
|
|
<br>to show the window
|
|
|
|
<li> <code>{(idx hide-window)} : window -> true</code>
|
|
<br>to hide the window
|
|
|
|
<li> <code>{(idx create-window)} : (listof (listof gui-item)) -> window</code>
|
|
<br>to add gui-items to a window and to show the window
|
|
<br>each list of gui-items defines one row of gui items in the window
|
|
|
|
<li> <code>{(idx make-button)} : str (event% -> boolean) -> gui-item</code>
|
|
<br>to create a button with label and call-back function
|
|
|
|
<li> <code>{(idx make-message)} : str -> gui-item</code>
|
|
<br>to create an item that displays a message
|
|
|
|
<li> <code>{(idx draw-message)} : gui-item[message%] stri -> true</code>
|
|
<br>to display a message in a message item
|
|
<br>it erases the current message
|
|
|
|
<li> <code>{(idx make-text)} : str -> gui-item</code>
|
|
<br>to create an item (with label) that allows users to enter text
|
|
|
|
<li> <code>{(idx text-contents)} : gui-item[text%] -> str</code>
|
|
<br>to determine the contents of a text field
|
|
|
|
<li> <code>{(idx make-choice)} : (listof str) -> gui-item</code>
|
|
<br>to create a choice menu that permits users to choose from some
|
|
string alternatives
|
|
|
|
<li> <code>{(idx choice-index)} : gui-item[choice%] -> num</code>
|
|
<br>to determine which choice is currently selected in a choice-item
|
|
<br>the result is the 0-based index in the choice menu
|
|
</menu>
|
|
|
|
<p>Example 1:
|
|
<pre>
|
|
> (define w (create-window (list (list (make-button "QUIT" (lambda (e) (hide-window w)))))))
|
|
</pre>
|
|
A button appears on the screen. Click on the button and it will disappear.
|
|
<pre>
|
|
> (show-window w)
|
|
</pre>
|
|
The frame reappears.
|
|
|
|
<p>Example 2:
|
|
<pre>
|
|
; text1 : GUI-ITEM
|
|
(define text1
|
|
(make-text "Please enter your name"))
|
|
|
|
; msg1 : GUI-ITEM
|
|
(define msg1
|
|
(make-message (string-append "Hello, World" (make-string 33 #\SPACE))))
|
|
|
|
; Event -> true
|
|
; draws the current contents of text1 into msg1, prepended with "Hello, "
|
|
(define (respond e)
|
|
(draw-message msg1 (string-append "Hello, " (text-contents text1))))
|
|
|
|
; set up window with three "lines": a text field, a message, and two buttons
|
|
; fill in text and click OKAY
|
|
(define w
|
|
(create-window
|
|
(list
|
|
(list text1)
|
|
(list msg1)
|
|
(list (make-button "OKAY" respond)
|
|
(make-button "QUIT" (lambda (e) (hide-window w)))))))
|
|
</pre>
|
|
|
|
{(include "foot.tinc")}
|