text.anubis 3.21 KB
   
   
                             The Anubis/Paradize Project.
   
                                    The text widget. 
   
                         Copyright (c) Alain Prouté 2004-2005. 

   
   Authors:   Alain Prouté
              Olivier Duvernois


   
   This  widget  shows  a  simple  'inert'  text. For  a  more  sophisticated  widget  see
   'widgets3/hypertext.anubis'.
   
   
   
read widget.anubis
read tools.anubis     

  
public define Widget
   create_text
     (
       String                            text,    // text to be printed (may have several lines)
       SystemFont                        font, 
       RGB                   foreground_color,
       Int32                           margin     // to be put on 4 sides
     ).
   
   
   
   
   --- That's all for the public part ! --------------------------------------------------

   
   
define One
   redraw_text
     (
       WidgetDrawToolBox                   dtb, 
       List(String)                       text,
       SystemFont                         font, 
       Int32                 total_font_height,
       RGB                    foreground_color, 
       Int32                            margin, 
       Int32                                 y
     ) =
   if text is 
     {
       [ ] then unique, 
       [line1 . lines] then 
         forget(draw(dtb)(line1,font,foreground_color,position(margin,y))); 
         redraw_text(dtb,
                     lines,
                     font,
                     total_font_height,
                     foreground_color,
                     margin,
                     y+total_font_height)
     }.
   
   
   
   
public define Widget
   create_text
     (
       String                            text,    // text to be printed (may have several lines)
       SystemFont                        font, 
       RGB                   foreground_color,
       Int32                           margin     // to be put on 4 sides
     ) =
   with         lines = split_string_into_lines(text), 
         margin_twice = margin*2, 
              w_width = margin_twice+printed_text_width(font,lines), 
             w_height = margin_twice+printed_text_height(font,lines), 
                 info = get_font_info(font), 
          font_height = int8_to_int32(height(info)), 
           font_depth = int8_to_int32(depth(info)),
    total_font_height = font_height+font_depth, 
     create_widget
       (
         /* setting childs positions */ 
         (WidgetPositionToolBox ptb) |-> unique, 
   
         /* getting size */ 
         (One u) |-> (w_width,w_height), 
   
         /* redraw */ 
         (WidgetDrawToolBox dtb) |->
            redraw_text(dtb,
                        lines,
                        font,
                        total_font_height,
                        foreground_color,
                        margin,
                        font_height+margin), 
   
         /* duplicate */ 
         (One u) |-> create_text(text,font,foreground_color,margin), 
   
         /* Change size */ 
         (Int32 w, Int32 h) |-> unique, 
   
         /* main event handler */ 
         (WidgetEventToolBox etb, WidgetNormalEvent e) |-> not_handled([]), 
   
         /* registrations */ 
         [ ]
       ).