widget_test.anubis 7.35 KB

                                  The Anubis Project. 
   
                             A Widget System (4th version). 
                          A global test of this widget system.  
   
                            Copyright (c) Alain Proute' 2005. 
   
   
   Authors: Alain Proute'

   In order to run this test, compile this file and issue the command: 'widget_test'. 
   
  
read tools/basis.anubis   
   
read host_window.anubis
read widget.anubis   
   
read space.anubis   
read table.anubis   
read image.anubis  
read check_box.anubis   
read variable_widget.anubis   
read radio_button.anubis   
read text.anubis   
read scrollbar.anubis   
read simple_window.anubis
read window.anubis
read tree_node.anubis
read button.anubis   
   
   


   
   
   
   
   
   
   -------------------------------

   
define Widget
   tree_node
     (
       Widget        main, 
       List(Widget)  items
     ) =
   tree_node(main,items,4,folded). 
   
   
define WidgetHostWindowState -> Widget
   root_widget_1
     (
       Widget      im,
       Var(Bool)   bool_v, 
       Var(Widget) widget_v,
       SystemFont  font,
       HostImage   not_checked,
       HostImage   checked,
       Var(Word32)  domain_v,
       Var(Word32)  width_v, 
       Var(Word32)  content_size_v, 
       Var(Word32)  offset_v,
       Var(Word32)  window_size_v
     ) =
   with stext = (String s) |-> text(s,font,rgb(0,0,0),2), 
   (WidgetHostWindowState hws) |-> 
   table(
         //nude, 
         borders(rgb(255,255,0),rgb(180,180,180),2,2),
         2,
         2,
     [
   
   /*
       [
         cell(space(10,100,rgb(0,0,200))),
   
         cell(simple_window(var((Word32)200),
                            window_size_v,
                            var((Word32)0),
                            offset_v,
                            var((Word32)0),
                            var((Word32)0),
                            im,
                            (One u) |-> rgb(0,0,100))),
   
         cell(scrollbar(vertical,
                        rgb(180,180,180),
                        (One u) |-> *domain_v,
                        *width_v,
                        content_size_v,
                        offset_v,
                        window_size_v))
       ],
       [
         cell(window(rgb(200,0,0),200,200,
                      table(borders(rgb(200,0,0),rgb(0,200,0),3,3),10,10,[[cell(im)]]),
                       resizable,both,(One u) |-> rgb(0,0,0))),
         cell(center,center,2,1,text("Exemple de texte.\nSur deux lignes.",font,rgb(0,0,0),4)),
         cell(table(nude,20,0,
               [[cell(button(
                     (One u) |-> link("[link] "+
                                      if *bool_v then "True" else "False",font,rgb(0,0,0),rgb(255,0,0)),
                     (One u) |-> blocking, 
                     (One u) |-> bool_v <- not(*bool_v),
                     [register(bool_v)]))],
                [cell(button(
                     (One u) |-> push_down(150,20,
                                           center_text(
                                             "[push down] "+
                                             if *bool_v then "True" else "False",font,rgb(0,0,0)),
                                           rgb(150,150,255)),
                     (One u) |-> blocking, 
                     (One u) |-> bool_v <- not(*bool_v),
                     [register(bool_v)]))],
                [cell(button(
                     (One u) |-> phantom(150,20,
                                         center_text("[phantom] "+
                                           if *bool_v then "True" else "False",font,rgb(0,0,0)),
                                         rgb(150,255,150)),
                     (One u) |-> blocking, 
                     (One u) |-> bool_v <- not(*bool_v),
                     [register(bool_v)]))]]
             ))
       ],
   */ 
   
       [
         cell(window(rgb(200,0,0),300,300,tree_node
               (
                 stext("Documentation"), 
                 [
                   tree_node(stext("Chapitre 1"),[]),
                   tree_node(stext("Chapitre 2"),
                      [
                        stext("Section 2.1"),
                        stext("Section 2.2"),
                        stext("Section 2.3")
                      ]),
                   tree_node(stext("Chapitre 3"),[]),
                   tree_node(stext("Chapitre 4"),[])
                 ]),
             resizable,both,(One u) |-> rgb(255,200,255)))
   /*
        ,
         cell(check_box(bool_v,not_checked,checked)),
         cell(variable(widget_v))         
   */
       ]
     ]).
   
define WidgetHostWindowState -> Widget
   root_widget_2
     (
       Var(Bool)   bool_v,
       Var(Word32)  domain_v,
       Var(Word32)  width_v, 
       Var(Word32)  content_size_v, 
       Var(Word32)  offset_v,
       Var(Word32)  window_size_v   
     ) =
   (WidgetHostWindowState hws) |->
     table(borders(rgb(255,255,0),rgb(180,180,180),2,2),40,40,
      [
        [
          cell(check_box(bool_v))
        ],
        [         
          cell(scrollbar(
               horizontal,
               rgb(180,180,180),
               (One u) |-> *domain_v,
               *width_v,
               content_size_v,
               offset_v,
               window_size_v))
        ]
      ]).  
   
   
   
define Maybe(HostImage)
   load_jpg
     (
       String path
     ) =
   if read_image_from_JPEG_file(path) is
     {
       cannot_open_file then failure, 
       decompress_error then failure, 
       ok(im) then success(to_host_image(im,1))
     }.
   
global define One
   widget_test
     (
       List(String) args
     ) =
   with domain_v = var((Word32)200), 
         width_v = var((Word32)12),
  content_size_v = var((Word32)1000), 
        offset_v = var((Word32)0), 
   window_size_v = var((Word32)200), 
   
     with bool_v = var((Bool)true), 
             n_v = var((Word32)10), 
         color_v = var((RGB)rgb(50,100,130)), 
        widget_v = var((Widget)space(5,40,*color_v)), 
   
 widget_ticket = register_monitor(widget_v,
                  (One u) |-> if *n_v = 0 then unique else 
                              (sleep(10); 
                               n_v <- *n_v-1; 
                               if *color_v is rgb(r,g,b) then 
                                  color_v <- rgb(g,b,r);
                                  widget_v <- space(5,40,*color_v))),
   
   if image("images/cows.jpg") is 
     {
       failure then print("Image './images/cows.jpg' not found.\n"),
       success(im) then if load_system_font("helvetica_medium_r_10") is 
         {
           failure then print("Cannot load system font.\n"), 
           success(font) then 
             if load_jpg("images/not_checked.jpg") is success(im_not_checked) then 
             if load_jpg("images/checked.jpg") is success(im_checked) then 
             forget(open_host_window(
                root_widget_1(im,bool_v,widget_v,font,
                              im_not_checked,
                              im_checked,
                              domain_v,
                              width_v,
                              content_size_v,
                              offset_v,
                              window_size_v
                              ),
                100,
                100,
                "Widget Test 1")) else unique else unique; 
   
             widget_v <- space(5,40,*color_v)
         }
     }.