simple_example.anubis
5.87 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
The Anubis/Paradize Project.
A simple example of how to use widgets.
Copyright (c) Alain Prouté 2004-2005.
Authors: Alain Prouté
This file contains the simple example announced in 'widgets3/host_window.anubis'.
This very simple example illustrates the following features of the widget system:
- using state variables,
- making a tree of widgets,
- monitoring variables in order to be always up to date.
We propose to open a host window containing a table with two cells. In the first cell
we have a 'check box', reflecting the state of a variable of type 'Var(Bool)' (i.e. the
check box is checked when this variable contains 'true', and not checked when it
contains 'false'). The second cell contains a button. This button acts on the same
variable. Each time the button is clicked, the value of the variable is negated
(flip-flopped). Also the decoration of the button depends on the value of the
variable. In order to have this decoration always up to date, the button is registered
at the variable.
To test this program, compile this file:
anubis simple_example.anubis
and try the example:
simple_example
Remark that the variable is monitored by the check box and by the button, whose aspects
are updated automatically.
read tools/basis.anubis
read host_window.anubis
read widget.anubis
read tools.anubis
read table.anubis
read check_box.anubis
read button.anubis
read text.anubis
global define One
simple_example
(
List(String) args
) =
//
// (1) Create a set of parameters. This set of parameters contains colors and some others
// 'visual' parameters. (See 'widgets3/tools.anubis')
//
with my_parameters =
if create_default_parameters_set is
{
failure then alert,
success(s) then s
},
//
// (2) Create a state variable. (For dynamic variables, see 'predefined.anubis')
//
with my_variable = var((Bool)false), // initial value: 'false'
//
// (3) Create a tree of widgets. In this case, a table containing a check box and a button
// both acting on 'my_variable'. (For details on each sort of widget, see the corresponding
// file in this directory, i.e: 'widgets3/table.anubis' etc...)
//
with my_widgets = create_table(borders // make a table with visible borders
(
my_parameters, // use the colors in 'my_parameters'
2, // make inner edges 2 pixels wide
4 // make an outer edge 4 pixels wide
),
2, // put 2 pixels of vertical glue
2, // put 2 pixels of horizontal glue
[
[
//
// put an explanation
//
cell(
center,
left,
2, // span over 2 columns
1, // and 1 line
create_text("This is a simple example.\n"+
"Click either the button or the check box.\n"+
"Remark that they are linked to the same variable. ",
*font_v(my_parameters),
rgb(0,0,0),
4 // margin on 4 sides
)
),
],
[
//
// put a check box refering to 'my_variable' in the first cell
//
cell(
bottom,
left,
create_check_box(my_variable)),
//
// put a button flip-flopping 'my_variable' in the second cell
//
cell(
center,
center,
create_button(100, // width of button
25, // height of button
push_down(my_parameters), // style of button
(WidgetEventToolBox etb) |-> // action performed
my_variable // by button
<- not(*my_variable),
(One u) |-> // how to get the
center_text(my_parameters, // decoration of the button
if *my_variable
then "True"
else "False"),
[register(my_variable)])) // so that button is always
// up to date
]
]),
//
// (4) Open a host window containing this tree of widgets
//
forget(open_host_window("Simple example", // title of host window
my_widgets)). // content of host window