widget_test.anubis
7.62 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
The Anubis Project.
A Widget System (4th version).
A global test of this widget system.
Copyright (c) Alain Proute' 2005.
Authors: Alain Proute'
In order to run this test, compile this file and issue the command: 'widget_test'.
read tools/basis.anubis
read host_window.anubis
read widget.anubis
read space.anubis
read table.anubis
read image.anubis
read check_box.anubis
read variable_widget.anubis
read radio_button.anubis
read text.anubis
read scrollbar.anubis
read simple_window.anubis
read window.anubis
read tree_node.anubis
read button.anubis
read trace.anubis
-------------------------------
define Widget
tree_node
(
Widget main,
List(Widget) items
) =
tree_node(main,items,4,folded).
define WidgetHostWindowState -> Widget
root_widget_1
(
Widget im,
Var(Bool) bool_v,
Var(Widget) widget_v,
SystemFont font,
HostImage not_checked,
HostImage checked,
Var(Word32) domain_v,
Var(Word32) width_v,
Var(Word32) content_size_v,
Var(Word32) offset_v,
Var(Word32) window_size_v
) =
with stext = (String s) |-> text(s,font,rgb(0,0,0),2),
(WidgetHostWindowState hws) |->
table(
//nude,
borders(rgb(255,255,0),rgb(180,180,180),2,2),
2,
2,
[
/*
[
cell(space(10,100,rgb(0,0,200))),
cell(simple_window(var((Word32)200),
window_size_v,
var((Word32)0),
offset_v,
var((Word32)0),
var((Word32)0),
im,
(One u) |-> rgb(0,0,100))),
cell(scrollbar(vertical,
rgb(180,180,180),
(One u) |-> *domain_v,
*width_v,
content_size_v,
offset_v,
window_size_v))
],
[
cell(window(rgb(200,0,0),200,200,
table(borders(rgb(200,0,0),rgb(0,200,0),3,3),10,10,[[cell(im)]]),
resizable,both,(One u) |-> rgb(0,0,0))),
cell(center,center,2,1,text("Exemple de texte.\nSur deux lignes.",font,rgb(0,0,0),4)),
cell(table(nude,20,0,
[[cell(button(
(One u) |-> link("[link] "+
if *bool_v then "True" else "False",font,rgb(0,0,0),rgb(255,0,0)),
(One u) |-> blocking,
(One u) |-> bool_v <- not(*bool_v),
[register(bool_v)]))],
[cell(button(
(One u) |-> push_down(150,20,
center_text(
"[push down] "+
if *bool_v then "True" else "False",font,rgb(0,0,0)),
rgb(150,150,255)),
(One u) |-> blocking,
(One u) |-> bool_v <- not(*bool_v),
[register(bool_v)]))],
[cell(button(
(One u) |-> phantom(150,20,
center_text("[phantom] "+
if *bool_v then "True" else "False",font,rgb(0,0,0)),
rgb(150,255,150)),
(One u) |-> blocking,
(One u) |-> bool_v <- not(*bool_v),
[register(bool_v)]))]]
))
],
*/
[
cell(window(rgb(200,0,0),300,300,tree_node
(
stext("Documentation"),
[
tree_node(stext("Chapitre 1"),[]),
tree_node(stext("Chapitre 2"),
[
stext("Section 2.1"),
stext("Section 2.2"),
stext("Section 2.3")
]),
tree_node(stext("Chapitre 3"),[]),
tree_node(stext("Chapitre 4"),[])
]),
resizable,both,(One u) |-> rgb(255,200,255)))
/*
,
cell(check_box(bool_v,not_checked,checked)),
cell(variable(widget_v))
*/
]
]).
define WidgetHostWindowState -> Widget
root_widget_2
(
Var(Bool) bool_v,
Var(Word32) domain_v,
Var(Word32) width_v,
Var(Word32) content_size_v,
Var(Word32) offset_v,
Var(Word32) window_size_v
) =
(WidgetHostWindowState hws) |->
table(borders(rgb(255,255,0),rgb(180,180,180),2,2),40,40,
[
[
cell(check_box(bool_v))
],
[
cell(scrollbar(
horizontal,
rgb(180,180,180),
(One u) |-> *domain_v,
*width_v,
content_size_v,
offset_v,
window_size_v))
]
]).
define HostImage
load_jpg
(
String path
) =
if read_image_from_JPEG_file(path) is
{
cannot_open_file then alert,
decompress_error then alert,
ok(im) then to_host_image(im,1)
}.
global define One
widget_test
(
List(String) args
) =
with domain_v = var((Word32)200),
width_v = var((Word32)12),
content_size_v = var((Word32)1000),
offset_v = var((Word32)0),
window_size_v = var((Word32)200),
with bool_v = var((Bool)true),
n_v = var((Word32)10),
color_v = var((RGB)rgb(50,100,130)),
widget_v = var((Widget)space(5,40,*color_v)),
widget_ticket = register_monitor(widget_v,
(One u) |-> if *n_v = 0 then unique else
(sleep(10);
n_v <- *n_v-1;
if *color_v is rgb(r,g,b) then
color_v <- rgb(g,b,r);
widget_v <- space(5,40,*color_v))),
if image("images/cows.jpg") is
{
failure then print("Image './images/cows.jpg' not found.\n"),
success(im) then if load_system_font("helvetica_medium_r_10") is
{
failure then print("Cannot load system font.\n"),
success(font) then
forget(open_host_window(
root_widget_1(im,bool_v,widget_v,font,
load_jpg("images/not_checked.jpg"),
load_jpg("images/checked.jpg"),
domain_v,
width_v,
content_size_v,
offset_v,
window_size_v
),
100,
100,
"Widget Test 1"));
/*
forget(open_host_window(
root_widget_2(bool_v,
domain_v,
width_v,
content_size_v,
offset_v,
window_size_v
),
630,
100,
"Widget Test 2"));
*/
widget_v <- space(5,40,*color_v)
}
}.