-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathracket-text.rkt
63 lines (51 loc) · 1.45 KB
/
racket-text.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
#lang racket/gui
(provide racket:text)
(require racket/class
racket/gui/easy
racket/gui/easy/operator
framework)
(define racket:text-view%
(class* racket:text% (view<%>)
(init-field @code action font width height)
(super-new)
(define/augment (on-change)
(when action
(action 'on-change (send this get-text))))
(define/public (dependencies)
(list @code))
(define/public (create parent)
(send this insert (obs-peek @code))
(define canvas (new editor-canvas%
[parent parent]
[min-width width]
[min-height height]
[editor this]))
canvas)
(define/public (update v what val)
(void))
(define/public (destroy v)
(void))))
(define (racket:text @code
[action #f]
#:font [font normal-control-font]
#:size [size '(400 400)])
(match-define (list width height) size)
(new racket:text-view%
[@code @code]
[action action]
[font font]
[width width]
[height height]))
(module+ main
(define @code
(@ "#lang racket
(define (foo x)
(add1 x))"))
(define (update target)
(λ (action text)
(:= target text)))
(render
(window #:title "test racket:text"
#:size '(800 400)
(racket:text @code
(update @code)))))