check_box.anubis 1.67 KB

   

   This is the 'check box' widget. 
   
   
read tools/basis.anubis   
read widget.anubis   
   
   
public define Widget
   create_check_box
     (
       Var(Bool) v
     ). 
   
   
   

   --- That's all for the public part ! --------------------------------------------------
   
   
   
public define Widget
   create_check_box
     (
       Var(Bool) v
     ) =
   with black = rgb(0,0,0), 
        white = rgb(255,255,255), 
         size = (Int32)12, 
   create_widget(
   
   /* positionning childs */ 
   (WidgetPositionToolBox ptb) |-> unique, 
   
   /* getting size */ 
   (One u) |-> (size,size),
   
   /* redrawing the check box */
   (WidgetDrawToolBox dtb) |->
     draw(dtb)(rect(0,0,size,1),black);
     draw(dtb)(rect(0,1,1,size-1),black);
     draw(dtb)(rect(size-1,1,size,size-1),black); 
     draw(dtb)(rect(0,size-1,size,size),black); 
     draw(dtb)(rect(1,1,size-1,size-1),white); 
     if *v 
     then draw(dtb)(rect(3,3,size-3,size-3),black)
     else unique, 
   
   /* duplicate */ 
   (One u) |-> create_check_box(v), 
   
   /* Change size */ 
   (Int32 w, Int32 h) |-> unique, 
   
   /* check box event handling */ 
   (WidgetEventToolBox etb, WidgetNormalEvent e) |->
     if e is
       {
         mouse_gone              then handled([]), 
         mouse_move(ks,x,y)      then handled([]), 
         mouse_click(ks,mc,x,y)  then if mc is left_down
           then v <- not(*v); handled([rect(3,3,size-3,size-3)])
           else handled([])
       },
   
     /* registering the variable */ 
     [register(v,(WidgetMonitoringToolBox mtb,List(WidgetRectangle) -> One redraw) |-> 
                    redraw([rect(3,3,size-3,size-3)]))]
   
   ).