创建GUI需要做的基本工作是什么?我了解GUI的基本组件,但不知从何处开始。我是一个自学者,正在阅读《如何设计程序》(HtDP)。在书的结尾,作者建议程序员需要了解GUI和CGI计算机网络的知识。关于最后两个方面的信息很容易找到。但是好像很少有书籍谈到如何创建GUI。我猜想这可能是因为在计算机程序设计过程中它太“底层”,很少有人关注。
创建GUI需要做的基本工作是什么?我了解GUI的基本组件,但不知从何处开始。我是一个自学者,正在阅读《如何设计程序》(HtDP)。在书的结尾,作者建议程序员需要了解GUI和CGI计算机网络的知识。关于最后两个方面的信息很容易找到。但是好像很少有书籍谈到如何创建GUI。我猜想这可能是因为在计算机程序设计过程中它太“底层”,很少有人关注。
DrRacket(目前版本为DrScheme)GUI编程的文档在这里:http://docs.racket-lang.org/gui/index.html
由于您正在阅读HTDP,因此现在这可能是最适合您的选择。
此外,如果您想从理论角度了解GUI并学习它,您应该学习各种GUI模式,例如MVC、Model2、MVVM等。我不知道任何在Lisp中实现这些模式的GUI框架,因此进行这样的项目可能是一次有趣的学习经历...
#lang racket
(require racket/gui/base
2htdp/image
(only-in mrlib/image-core render-image))
;; The state of our program is a number.
(define state 0)
;; On a timer tick, increment the state, and refresh the canvas.
;; tick!: -> void
(define (tick!)
(set! state (add1 state))
(send THE-CANVAS refresh))
;; When a canvas paints itself, use the following:
;; paint: canvas% dc<%> -> void
(define (paint! a-canvas my-drawing-context)
(define my-new-scene (text (format "I see: ~a" state) 20 'black))
;; Note: we force the canvas to be of a particular width and height here:
(send a-canvas min-client-width (image-width my-new-scene))
(send a-canvas min-client-height (image-height my-new-scene))
(render-image my-new-scene my-drawing-context 0 0))
;; Here, we initialize our graphical application. We create a window frame...
;; THE-FRAME: frame%
(define THE-FRAME (new (class frame%
(super-new)
;; When we close the frame, shut down everything.
(define/augment (on-close)
(custodian-shutdown-all (current-custodian))))
[label "Example"]))
;; and add a canvas into it.
;; THE-CANVAS: canvas%
(define THE-CANVAS (new (class canvas%
(super-new)
;; We define a key handler. Let's have it so it
;; resets the counter on a key press
(define/override (on-char key-event)
(when (eq? (send key-event get-key-code) 'release)
(set! state 0)
(send THE-CANVAS refresh))))
[parent THE-FRAME]
[paint-callback paint!]))
;; We get the frame to show on screen:
(send THE-FRAME show #t)
;; Finally, we set up a timer that will call tick! on every second.
(define THE-TIMER (new timer%
[notify-callback tick!]
[interval 1000]))