widget_demo.anubis 4.25 KB

                                  The Anubis Project. 
   
                              A Widget System (4th version). 
                          A tutorial/demo for this widget system. 
   
                             Copyright (c) Alain Proute' 2005. 
   
   
   
   Authors: Alain Proute'
            Olivier Duvernois
   

read tools.anubis   
read host_window.anubis   
read widget.anubis   
read tree_node.anubis
read table.anubis
read text.anubis
read window.anubis
read variable_widget.anubis   
read space.anubis   
read button.anubis
   
define String the_title = "Démo/Tutoriel sur les Widgets".
   
   
type Content:...
   
type Item:
   item  (String      title, 
          Content).    
   
type Content:
   empty, 
   widget (Widget),
   items  (List(Item)). 
   

   
   
type Parms:
   parms
     (
       SystemFont     normal_font,
       RGB            text_color,
       SystemFont     title_font,
       RGB            title_color,
       Var(Widget)    content_v
     ). 
   
   
   
define Widget
   text
     (
       Parms    p, 
       String   t
     ) =
   text(t,normal_font(p),text_color(p),4). 
   
   
   
   
   
define Item item_introduction (Parms p) =
   item("Introduction",
        widget(text(p,"Introduction au système de widgets."))). 
   
define Item item_space        (Parms p) =
   item("Espaces",
        widget(text(p,"Les espaces."))). 
   
define Item item_table (Parms p) =
   item("Tables",
        empty). 
   
define Item item_text (Parms p) =
   item("Textes",
        empty). 
   
   
   
   
define Item root_item (Parms p) =
   item("Démo/Tutoriel sur les Widgets",
        items
          [
            item_introduction(p),
            item_space(p),
            item_table(p),
            item_text(p)
          ]). 
   
   
   
define Widget
   index_link
     (
       Parms          p,
       String         t,
       Content        c,
     ) =
   with     f = normal_font(p), 
        width = printed_text_width(f,t),
        black = rgb(0,0,0), 
   button((One u) |-> link(t,f,black,rgb(200,0,0)), 
          (One u) |-> blocking, 
          if c is 
            {
              empty     then (One u) |-> unique, 
              widget(w) then (One u) |-> content_v(p) <- w, 
              items(l)  then (One u) |-> unique
            },
          [ ]
         ).
   
   
define Widget 
   make_index
     (
       Parms        p,
       Item         i
     ) =
   if i is item(title,content) then 
   tree_node(index_link(p,title,content),
             if content is 
               {
                 empty      then [], 
                 widget(_)  then [], 
                 items(l)   then map((Item j) |-> make_index(p,j),l)
               },
             2,unfolded). 
   
   
   
define WidgetHostWindowState -> Widget   
   the_root_widget
     (
       Parms p
     ) =
   with grey = rgb(180,180,200), 
         bgc = (One u) |-> rgb(255,255,200), 
   height_v = var((Word32)450), 
   (WidgetHostWindowState hws) |->
   table(borders(grey,grey,2,1),
         0,0,
     [
       [
         cell(center,center,2,1,none,
              text(the_title,title_font(p),title_color(p),10))
       ],
       [
         cell(window(grey,var(250),height_v,make_index(p,root_item(p)),resizable,both,bgc)),
         cell(window(grey,var(600),height_v,variable(content_v(p)),resizable,both,bgc))
       ]
     ]).
   
   
   
global define One
   widget_demo
     (
       List(String) args
     ) =
   if load_system_font("helvetica_medium_r_10") is 
     {
       failure then print("Cannot load system font helvetica_medium_r_10.\n"),
       success(hmr10) then 
         if load_system_font("helvetica_bold_r_18") is 
           {
             failure then print("Cannot load system font helvetica_medium_r_18.\n"),
             success(hmr18) then 
   
   with normal_font = hmr10, 
         text_color = rgb(0,0,0), 
   with           p = parms(normal_font,
                            text_color,
                            hmr18,
                            rgb(180,0,0),
                            var((Widget)text("Introduction au système de Widgets avec démonstration.",
                                              normal_font,text_color,4))), 
                         
   forget(open_host_window
     (
       the_root_widget(p),
       the_title
     ))}}.