widget_demo.anubis
4.25 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
The Anubis Project.
A Widget System (4th version).
A tutorial/demo for this widget system.
Copyright (c) Alain Proute' 2005.
Authors: Alain Proute'
Olivier Duvernois
read tools.anubis
read host_window.anubis
read widget.anubis
read tree_node.anubis
read table.anubis
read text.anubis
read window.anubis
read variable_widget.anubis
read space.anubis
read button.anubis
define String the_title = "Démo/Tutoriel sur les Widgets".
type Content:...
type Item:
item (String title,
Content).
type Content:
empty,
widget (Widget),
items (List(Item)).
type Parms:
parms
(
SystemFont normal_font,
RGB text_color,
SystemFont title_font,
RGB title_color,
Var(Widget) content_v
).
define Widget
text
(
Parms p,
String t
) =
text(t,normal_font(p),text_color(p),4).
define Item item_introduction (Parms p) =
item("Introduction",
widget(text(p,"Introduction au système de widgets."))).
define Item item_space (Parms p) =
item("Espaces",
widget(text(p,"Les espaces."))).
define Item item_table (Parms p) =
item("Tables",
empty).
define Item item_text (Parms p) =
item("Textes",
empty).
define Item root_item (Parms p) =
item("Démo/Tutoriel sur les Widgets",
items
[
item_introduction(p),
item_space(p),
item_table(p),
item_text(p)
]).
define Widget
index_link
(
Parms p,
String t,
Content c,
) =
with f = normal_font(p),
width = printed_text_width(f,t),
black = rgb(0,0,0),
button((One u) |-> link(t,f,black,rgb(200,0,0)),
(One u) |-> blocking,
if c is
{
empty then (One u) |-> unique,
widget(w) then (One u) |-> content_v(p) <- w,
items(l) then (One u) |-> unique
},
[ ]
).
define Widget
make_index
(
Parms p,
Item i
) =
if i is item(title,content) then
tree_node(index_link(p,title,content),
if content is
{
empty then [],
widget(_) then [],
items(l) then map((Item j) |-> make_index(p,j),l)
},
2,unfolded).
define WidgetHostWindowState -> Widget
the_root_widget
(
Parms p
) =
with grey = rgb(180,180,200),
bgc = (One u) |-> rgb(255,255,200),
height_v = var((Word32)450),
(WidgetHostWindowState hws) |->
table(borders(grey,grey,2,1),
0,0,
[
[
cell(center,center,2,1,none,
text(the_title,title_font(p),title_color(p),10))
],
[
cell(window(grey,var(250),height_v,make_index(p,root_item(p)),resizable,both,bgc)),
cell(window(grey,var(600),height_v,variable(content_v(p)),resizable,both,bgc))
]
]).
global define One
widget_demo
(
List(String) args
) =
if load_system_font("helvetica_medium_r_10") is
{
failure then print("Cannot load system font helvetica_medium_r_10.\n"),
success(hmr10) then
if load_system_font("helvetica_bold_r_18") is
{
failure then print("Cannot load system font helvetica_medium_r_18.\n"),
success(hmr18) then
with normal_font = hmr10,
text_color = rgb(0,0,0),
with p = parms(normal_font,
text_color,
hmr18,
rgb(180,0,0),
var((Widget)text("Introduction au système de Widgets avec démonstration.",
normal_font,text_color,4))),
forget(open_host_window
(
the_root_widget(p),
the_title
))}}.