menu_manager_test.anubis
3.26 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
read tools/basis.anubis
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("Cannot open file: '"+path+"'.",font,rgb(255,0,0),10),
decompress_error then text("Decompression error: '"+path+"'.",font,rgb(255,0,0),10),
ok(im) then image(to_host_image(im,1))
}.
type MMImage:
mmimage(String path).
define $T
head
(
List($T) l,
$T default,
) =
if l is
{
[ ] then default,
[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),
default_mmimage = mmimage(""),
grey = rgb(180,180,180),
black = rgb(0,0,0),
ims = map((String filename) |-> mmimage(filename),
reverse(directory_list("images","*.jpg"))),
mbfont = load_system_font("helvetica_medium_r_10"),
if mbfont is
{
failure then print("Cannot load system font.\n"),
success(font) then
with
im_v = var((Widget)load_jpg("images/"+path(head(ims,default_mmimage)),font)),
title_v = var((Widget)text(path(head(ims,default_mmimage)),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)
+ [separator,
item((One _) |-> "Quit",
(WidgetEventToolBox etb) |-> close_host_window(etb))],
command_v
),
with root = table(borders(rgb(0,0,0),rgb(0,0,0),0,0),0,0,
[
[cell(top,left,1,1,none,
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,none,variable(title_v))],
[cell(center,center,2,1,none,menu_manager(grey,command_v,
window(grey,300,250,
variable(im_v),
resizable,both,(One u) |-> rgb(0,0,0))))]
]
),
forget(open_host_window(root,100,100,"Menu Manager Test"));
forget(open_host_window(root,100,100,"Menu Manager Test"));
forget(open_host_window(root,400,400,"Menu Manager Test (clone)"))
}.