box.anubis
3.52 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
The Anubis/Paradize Project.
The box widget.
Copyright (c) Alain Prouté 2004-2005.
Authors: Alain Prouté
Olivier Duvernois
read tools/basis.anubis
read widget.anubis
read tools.anubis
This file defines the 'box' widget. A box is just a frame (shown with some relief)
surrounding a widget (the content of the box).
Boxes are available in different styles:
public type BoxStyle:
frame (WidgetParameters),
relief (WidgetParameters),
relief (RGB).
public define Widget
create_box
(
BoxStyle style,
Int32 border_width,
Widget content
).
--- That's all for the public part ! --------------------------------------------------
define One -> (Int32,Int32)
box_get_size
(
Widget content,
Int32 border_width
) =
(One u) |-> if get_size(content)(unique) is (c_w,c_h) then
(c_w+2*border_width,c_h+2*border_width).
public define Widget
create_box
(
BoxStyle style,
Int32 border_width,
Widget content
) =
with b_width = if border_width >= 0 then border_width else 0,
content_impacted = var((Bool)false),
create_widget(
/* set childs positions */
(WidgetPositionToolBox ptb) |->
set_position(content)(ptb,position(b_width,b_width)),
/* get size */
box_get_size(content,b_width),
/* redraw */
(WidgetDrawToolBox dtb) |->
if box_get_size(content,b_width)(unique) is (w,h) then
if style is
{
frame(parms) then
with color = *main_color_v(parms),
light = *light_color_v(parms),
dark = *dark_color_v(parms),
draw(dtb)(rect(0,0,w,b_width),color);
draw(dtb)(rect(0,b_width,b_width,h-b_width),color);
draw(dtb)(rect(w-b_width,b_width,w,h-b_width),color);
draw(dtb)(rect(0,h-b_width,w,h),color);
draw_relief_edge(dtb,1,rect(0,0,w,h),light,dark);
draw_hollow_edge(dtb,1,rect(b_width-1,b_width-1,w-b_width+1,h-b_width+1),light,dark),
relief(parms) then
with color = *main_color_v(parms),
light = *light_color_v(parms),
dark = *dark_color_v(parms),
draw_relief_area(dtb,1,rect(0,0,w,h),color,light,dark),
relief(color) then
with light = lighten(color),
dark = darken(color),
draw_relief_area(dtb,1,rect(0,0,w,h),color,light,dark)
};
redraw(content)(dtb),
/* Duplicate */
(One u) |-> create_box(style,border_width,duplicate(content)(unique)),
/* Change size */
(Int32 w, Int32 h) |->
with d = 2*border_width,
change_size(content)(w-d,h-d),
/* event handling */
(WidgetEventToolBox etb, WidgetNormalEvent e) |->
if box_get_size(content,b_width)(unique) is (w,h) then
if x(e) < b_width | x(e) >= w-b_width
| y(e) < b_width | y(e) >= h-b_width
then (
if *content_impacted
then (
content_impacted <- false;
main_event_handler(content)(etb,mouse_gone)
)
else not_handled([])
)
else (
content_impacted <- true;
main_event_handler(content)(etb,e)
),
/* monitoring */
[ ]
).