-
Notifications
You must be signed in to change notification settings - Fork 0
/
gui.rkt
65 lines (53 loc) · 1.89 KB
/
gui.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#lang racket/gui
(provide
gui%)
(define (make-window-chat parent)
(new editor-canvas%
[parent parent]
[enabled #f]
[label "chat"]
[editor (new text%)]))
(define (make-window-general parent)
(define text (new text%))
(define editor-canvas (new editor-canvas%
[parent parent]
[enabled #f]
[style '(no-border)]
[min-width 600]))
(send editor-canvas set-editor text)
editor-canvas)
(define gui%
(class object%
(define frame null)
(define window-general null)
(define window-chat null)
(define prompt null)
(define on-send null)
(super-new)
(define (on-textbox-changed t e)
(and (eq? (send e get-event-type) 'text-field-enter)
(let ([msg (send t get-value)])
(on-send msg)
(send (send window-general get-editor) insert msg)
(send t set-value ""))))
(define/public (run)
(set! frame (new frame%
[label "rbat"]
[width 900]
[height 600]))
(define message-window (new horizontal-pane% [parent frame]))
(set! window-general (make-window-general message-window))
(define right-pane (new vertical-panel%
[parent message-window]))
(set! window-chat (make-window-chat right-pane))
(set! prompt (new text-field%
[parent frame]
[label ">"]
[callback on-textbox-changed]))
(send frame show #t))
(define/public (send-to-window window content)
(case window
[("chat") (send (send window-chat get-editor) insert content)]
[else (send (send window-general get-editor) insert content)]))
(define/public (set-on-send callback)
(set! on-send callback))))