check_box.anubis
1.67 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
This is the 'check box' widget.
read tools/basis.anubis
read widget.anubis
public define Widget
create_check_box
(
Var(Bool) v
).
--- That's all for the public part ! --------------------------------------------------
public define Widget
create_check_box
(
Var(Bool) v
) =
with black = rgb(0,0,0),
white = rgb(255,255,255),
size = (Int32)12,
create_widget(
/* positionning childs */
(WidgetPositionToolBox ptb) |-> unique,
/* getting size */
(One u) |-> (size,size),
/* redrawing the check box */
(WidgetDrawToolBox dtb) |->
draw(dtb)(rect(0,0,size,1),black);
draw(dtb)(rect(0,1,1,size-1),black);
draw(dtb)(rect(size-1,1,size,size-1),black);
draw(dtb)(rect(0,size-1,size,size),black);
draw(dtb)(rect(1,1,size-1,size-1),white);
if *v
then draw(dtb)(rect(3,3,size-3,size-3),black)
else unique,
/* duplicate */
(One u) |-> create_check_box(v),
/* Change size */
(Int32 w, Int32 h) |-> unique,
/* check box event handling */
(WidgetEventToolBox etb, WidgetNormalEvent e) |->
if e is
{
mouse_gone then handled([]),
mouse_move(ks,x,y) then handled([]),
mouse_click(ks,mc,x,y) then if mc is left_down
then v <- not(*v); handled([rect(3,3,size-3,size-3)])
else handled([])
},
/* registering the variable */
[register(v,(WidgetMonitoringToolBox mtb,List(WidgetRectangle) -> One redraw) |->
redraw([rect(3,3,size-3,size-3)]))]
).