{"size": 3139, "ext": "scrbl", "max_stars_repo_path": "htdp-doc/teachpack/htdp/scribblings/gui.scrbl", "max_stars_repo_name": "bdeket/htdp", "max_stars_repo_stars_event_min_datetime": "2015-01-14T20:28:41.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T04:04:26.000Z", "max_issues_repo_path": "htdp-doc/teachpack/htdp/scribblings/gui.scrbl", "max_issues_repo_name": "bdeket/htdp", "max_issues_repo_issues_event_min_datetime": "2015-01-14T19:50:21.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-19T21:38:00.000Z", "max_forks_repo_path": "htdp-doc/teachpack/htdp/scribblings/gui.scrbl", "max_forks_repo_name": "bdeket/htdp", "max_forks_repo_forks_event_min_datetime": "2015-01-14T19:11:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T05:11:39.000Z"}
{"max_stars_count": 85, "max_issues_count": 132, "max_forks_count": 81, "avg_line_length": 33.752688172, "max_line_length": 108, "alphanum_fraction": 0.7126473399}
#lang scribble/doc

@(require scribble/manual "shared.rkt"
          (for-label racket teachpack/htdp/gui))

@teachpack["gui"]{Simple Graphical User Interfaces}

@;declare-exporting[teachpack/htdp/gui]
@defmodule[#:require-form beginner-require htdp/gui]

The teachpack provides functions for creating and manipulating graphical
user interfaces. We recommend using @racketmodname[2htdp/universe] instead. 

@deftech{Window} A @tech{Window} is a data representation of a visible
window on your computer screen.

@deftech{GUI-ITEM} A @tech{GUI-Item} is a data representation of an active
component of a window on your computer screen.

@defproc[(create-window [g (listof (listof (unsyntax @tech{GUI-ITEM})))])  Window]{
Creates a window from the ``matrix'' of gui items @racket[g].}

@defproc[(window? [x any/c]) boolean?]{Is the given value a window?}

@defproc[(show-window [w Window]) true]{Shows @racket[w].}

@defproc[(hide-window [w window]) true]{Hides @racket[w].}

@defproc[(make-button [label string>][callback (-> event%  boolean)])  (unsyntax @tech{GUI-ITEM})]{Creates a
button with @racket[label] and @racket[callback] function. The latter
receives an argument that it may safely ignore.}

@defproc[(make-message [msg string?]) (unsyntax @tech{GUI-ITEM})]{Creates a message item from @racket[msg].}

@defproc[(draw-message [g (unsyntax @tech{GUI-ITEM})][m string?])  true]{Displays @racket[m]
in message item @racket[g] and erases the current message.}

@defproc[(make-text [txt string?]) (unsyntax @tech{GUI-ITEM})]{Creates an text editor (with
label @racket[txt]) that allows users to enter text.}

@defproc[(text-contents [g (unsyntax @tech{GUI-ITEM})])  string?]{
Determines the current contents of a text @tech{GUI-ITEM}.}

@defproc[(make-choice [choices (listof string?)]) (unsyntax @tech{GUI-ITEM})]{
Creates a choice menu from @racket[choices] that permits users to choose
from some alternatives.}

@defproc[(choice-index [g (unsyntax @tech{GUI-ITEM})]) natural-number/c]{Determines the
choice that is currently selected in a choice @tech{GUI-ITEM}; the result
is the 0-based index in the choice menu}

Example 1:
@(begin
#reader scribble/comment-reader
(racketblock
> (define w
    (create-window
      (list (list (make-button "QUIT" (lambda (e) (hide-window w)))))))
;; A button appears on the screen.
;; Click on the button and it will disappear.
> (show-window w)
;; The window disappears. 
))

Example 2:
@(begin
#reader scribble/comment-reader
(racketblock
;; 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)))))))
))
