generic_editor_example.anubis
4.18 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
The Anubis/Paradize Project.
A example of use of the generic editor widget.
Copyright (c) Alain Prouté 2004-2005.
Authors: Alain Prouté
Olivier Duvernois
read widgets3/host_window.anubis
read widgets3/generic_editor.anubis
read widgets3/table.anubis
In this file we construct a simple albeit significant example if use of the generic
editor (which is defined in 'generic_editor.anubis'). Study this example if you want
to use the generic editor, because it contains important hints not described in
'generic_editor.anubis'.
First of all we need to decide which kind of data we want to edit. In order to show how
to handle such situation, we choose a type 'Datum1' of data which is cross recursive
with another one.
type Datum2:...
type Datum1:
a,
b(Datum1,Datum2).
type Datum2:
c,
d(Datum1,Datum1,Datum1).
Actually, these types will not be used here (but they should probably be used in a
realistic situation) because, as explained in 'generic_editor.anubis', we need to
represent 'incomplete data' or 'extended data'. Hence, we also define:
type ExDatum2:...
type ExDatum1:
missing(List(ExDatum1)),
a,
b(ExDatum1,ExDatum2).
type ExDatum2:
missing(List(ExDatum2)),
c,
d(ExDatum1,ExDatum1,ExDatum1).
Notice that the new types just mimic the previous ones, and that they have an extra
alternative for representing missing data. The unique component of this extra
alternative is a list of proposals for the missing datum.
Now, we must define the functions 'to_editable', transforming data of types 'ExDatum1'
and 'ExDatum2' into editables. Of course, these two functions need to be cross
recursive.
define Editable(ExDatum2)
to_editable
(
ExDatum2 d
).
define Editable(ExDatum1)
to_editable
(
ExDatum1 d
) =
if d is
{
missing(l) then
with area_rect = rect(0,-10,10,0),
create_editable
(
(Int32 x, Int32 y, Int32 margin) |-> unique,
(One u) |-> [area_rect],
(Int32 mx, Int32 my) |->
if belongs(mx,my,area_rect)
then [area_rect]
else [],
(WidgetDrawToolBox dtb, Int32 margin) |->
),
a then
b(d1,d2) then
}.
define Editable(ExDatum2)
to_editable
(
ExDatum2 d
) =
if d is
{
missing(l) then
c then
b(d1,d2,d3) then
}.
define Editable(String)
to_editable
(
String s
) =
with get_area = (One u) |-> (List(WidgetRectangle))[rect(10,0,30,30),rect(0,40,100,80)],
red = rgb(255,0,0),
create_editable(
(Int32 x,Int32 y,Int32 margin) |-> unique,
get_area,
(Int32 mx, Int32 my) |->
with area = get_area(unique),
if belongs(mx,my,area)
then area
else [],
(WidgetDrawToolBox dtb, Int32 margin) |->
draw(dtb)(rect(15,5,25,25),red);
draw(dtb)(rect(5,45,95,75),red),
(EditableEvent(String) e) |-> not_handled([]),
(One u) |-> "gaga"
).
define Widget
the_editor
(
WidgetParameters parms
) =
create_table(borders(parms,2,2),2,2,
[[ cell(center,center,
create_generic_editor(parms,
"",
to_editable,
var(undo)))
]]).
global define One
try_generic_editor
(
List(String) args
) =
with parms = create_default_parameters_set,
forget(open_host_window(100,100,
"Generic Editor Example",
the_editor(parms))).