menu_manager_test.anubis
2.9 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
read host_window.anubis
read widget.anubis
read table.anubis
read button.anubis
read menu_manager.anubis
read menus.anubis
read image.anubis
read variable_widget.anubis
read text.anubis
read window.anubis
define Widget
load_jpg
(
String path,
SystemFont font,
) =
if read_image_from_JPEG_file(path) is
{
cannot_open_file then text("Not a JPEG file.",font,rgb(255,0,0),10),
decompress_error then text("Not a JPEG file.",font,rgb(255,0,0),10),
ok(im) then image(to_host_image(im,1))
}.
define SystemFont
load_font
(
String name
) =
if load_system_font(name) is
{
failure then print("Cannot load system font '"+name+"'.\n"); alert,
success(f) then f
}.
type MMImage:
mmimage(String path).
define $T
head
(
List($T) l
) =
if l is
{
[ ] then alert,
[h . t] then h
}.
global define One
menu_manager_test
(
List(String) args
) =
with command_v = var((MenuCommand)clear),
default_image = to_host_image(create_rgba_image(200,80,rgba(255,255,255,255)),1),
grey = rgb(180,180,180),
black = rgb(0,0,0),
ims = map((String filename) |-> mmimage(filename),
reverse(directory_list("images","*.jpg"))),
font = load_font("helvetica_medium_r_10"),
im_v = var((Widget)load_jpg("images/"+path(head(ims)),font)),
title_v = var((Widget)text(path(head(ims)),font,rgb(255,255,255),4)),
the_menu = (One u) |-> standard_menu
(
grey,font,
map((MMImage i) |-> item((One u) |-> path(i),
(WidgetEventToolBox etb) |->
im_v <- load_jpg("images/"+path(i),font);
title_v <- text(path(i),font,rgb(255,255,255),4)),ims),
command_v
),
forget(open_host_window
(
table(borders(rgb(0,0,0),rgb(0,0,0),0,0),0,0,
[
[cell(top,left,1,1,
button((One u) |-> push_down(80,20,center_text("Menu",font,black),grey),
(One u) |-> blocking,
(WidgetEventToolBox etb) |->
if *command_v is clear
then command_v <- top_bottom(etb,the_menu(unique),rect(0,0,150,20))
else command_v <- clear,
[])),
cell(center,left,1,1,variable(title_v))],
[cell(center,center,2,1,menu_manager(grey,command_v,
window(grey,300,250,
variable(im_v),
resizable,both,(One u) |-> rgb(0,0,0))))]
]
),
"Menu Manager Test"
)).