menu_manager_test.anubis 2.9 KB

   
   
   
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"
     )).