-
Notifications
You must be signed in to change notification settings - Fork 1
/
notebook.nls
119 lines (104 loc) · 2.59 KB
/
notebook.nls
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
globals [ cells default-height default-width button-width current-output left-column center-column right-column margin]
to setup-notebook
; set left-column table:make
; set right-column table:make
; set center-column table:make
xw:clear-all
set default-height 100
set default-width 500
set button-width 50
set cells []
xw:create-tab "lsgui" [ xw:set-title "LevelSpaceGUI" ]
end
;; need a data structure for left hand column
;to append-cell
; let y-pos ifelse-value (not empty? cells) [
; [xw:y + xw:height] xw:of last cells
; ] [
; 0
; ]
; let id (length cells) / 2
; let key (word "input " id)
; xw:create-code-editor key [
; xw:set-width default-width
; xw:set-height default-height
; xw:set-x button-width
; xw:set-y y-pos
; ]
; let output-key (word "output " id)
; xw:create-text-area output-key [
; xw:set-width default-width
; xw:set-height 0
; xw:set-x button-width
; xw:set-y [ xw:y + xw:height ] xw:of key
; ]
; xw:create-button (word "run " id) [
; xw:set-label "Run"
; xw:set-commands (word "set current-output \"" output-key "\" run-cell \"" id "\"")
; xw:set-width button-width
; xw:set-y y-pos
; ]
; set cells (sentence cells key output-key)
;end
;to run-cell [ id ]
; let cell (word "input " id)
; set current-output (word "output " id)
; xw:ask current-output [
; xw:set-text ""
; resize-cell
; ]
; run [ xw:text ] xw:of cell
; if current-output = last cells [
; append-cell
; ]
;end
to echo [ val ]
xw:ask current-output [
ifelse empty? xw:text [
xw:set-text (word val)
] [
xw:set-text (word xw:text "\n" val)
]
resize-cell
]
end
to resize-cell
let approx-height 0
if not empty? xw:text[
let num-lines (1 + length xw:text - length remove "\n" xw:text)
if num-lines > 30 [
set num-lines 30
]
set approx-height 1.3 * xw:font-size * ( 2 + num-lines)
]
if approx-height != xw:height [
xw:set-height approx-height
redo-layout
]
end
to-report cell-for-button [ button ]
let id substring button (1 + position " " button) (length button)
report (word "input " id)
end
to-report cell-id
report substring xw:key (1 + position " " xw:key) length xw:key
end
to redo-layout
(foreach but-first cells but-last cells [
let previous ?2
let current ?1
xw:ask current [
xw:set-y [ xw:y + xw:height ] xw:of previous
if member? "input" xw:key [
xw:ask (word "run " cell-id) [
xw:set-y [ xw:y ] xw:of current
]
]
]
])
end
to remove-cell [ cell ]
set cells remove cell cells
xw:remove cell
redo-layout
end