From e7bd8a6e55afb4f005f6bf9bb16d090379f48ca0 Mon Sep 17 00:00:00 2001 From: totoro Date: Tue, 9 Feb 2016 11:52:28 +0100 Subject: [PATCH] Add ol, ul and li in element of HTML_xx_form Remove the dead code for creating jpeg buttons with relief (Nowadays with a sip of css it's 100 times more beautiful). --- web/CXM_making_a_web_site.anubis | 223 +++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 1 file changed, 39 insertions(+), 184 deletions(-) diff --git a/web/CXM_making_a_web_site.anubis b/web/CXM_making_a_web_site.anubis index f392349..6f02584 100644 --- a/web/CXM_making_a_web_site.anubis +++ b/web/CXM_making_a_web_site.anubis @@ -5,7 +5,7 @@ *Title* Making interactive Web sites. *Copyright* Copyright (c) Alain Prouté 2004-2005. - Copyright (c) Calexium 2007-2015. + Copyright (c) Calexium 2007-2016. *Authors* Alain Prouté @@ -1147,7 +1147,10 @@ public type HTML_In_Form: hidden (HtmlId id, WebArgName name, InitialValue init), partial (HTML_Partial_Content), br, - progress (List(CoreAttrs), Int value, Int max). + progress (List(CoreAttrs), Int value, Int max), + ol (List(CoreAttrs), HTML_In_Form content), + ul (List(CoreAttrs), HTML_In_Form content), + li (List(CoreAttrs), HTML_In_Form content). 'HTML_In_Form' defines all the elements you may put within a form. We define a @@ -1341,7 +1344,10 @@ public type HTML_Off_Form: HTML_Body /*body*/), partial (HTML_Partial_Content), br, - progress (List(CoreAttrs), Int value, Int max). + progress (List(CoreAttrs), Int value, Int max), + ol (List(CoreAttrs), HTML_Off_Form content), + ul (List(CoreAttrs), HTML_Off_Form content), + li (List(CoreAttrs), HTML_Off_Form content). 'HTML_Off_Form' defines all the elements you may put outside any form. @@ -2766,7 +2772,10 @@ type HTML_Any($T): Maybe((String,List((String,String))))), any_div (List(CoreAttrs), $T element), any_div_empty (List(CoreAttrs)), - any_coreattrs (List(CoreAttrs)). + any_coreattrs (List(CoreAttrs)), + any_ol (List(CoreAttrs), $T content), + any_ul (List(CoreAttrs), $T content), + any_li (List(CoreAttrs), $T content). @@ -2800,41 +2809,6 @@ define RGB 255-g, 255-b). - - - - *** [5.3] Creating buttons. - - We want to be able to create buttons in the form of a pair of images (rollovers) - automatically. We use the JPEG interface, because for the time being Anubis cannot - handle other kinds of images. - - - Computing printed text length. - - define Int - printed_text_width - ( - Word8 -> Int char_size, - List(Word8) l - ) = - if l is - { - [] then (Int) 0, - [h . t] then char_size(h) + 1+ printed_text_width(char_size,t) - }. - - define Int - printed_text_width - ( - SystemFont font, - String s - ) = - printed_text_width((Word8 c) |-> word8_to_int32(width(get_char_info(font,c))), - explode(s)). - - - Converting RGB to RGBA. define RGBA @@ -2845,147 +2819,6 @@ define RGBA if color is rgb(r,g,b) then rgba(r,g,b,255). - Drawing a 'relief'. - - define One - draw_relief - ( - RGBAImage dest, - RGBA color, - Int contrast, - Int x, - Int y, - Int width, - Int height - ) = - with l = lighten(color,contrast), - d = darken(color,contrast), - draw_rectangle(dest,rect(x,y,x+width,y+1),l); - draw_rectangle(dest,rect(x,y+1,x+1,y+height),l); - draw_rectangle(dest,rect(x+width-1,y+1,x+width,y+height),d); - draw_rectangle(dest,rect(x+1,y+height-1,x+width-1,y+height),d). - - - Creating a button background. - - define RGBAImage - create_button_background - ( - RGBA color, - Int width, - Int height - ) = - with result = create_rgba_image(width,height,color), - draw_relief(result,color,100,0,0,width,height); - draw_relief(result,color,70,1,1,width-2,height-2); - draw_relief(result,color,55,2,2,width-4,height-4); - draw_relief(result,color,35,3,3,width-6,height-6); - draw_relief(result,color,20,4,4,width-8,height-8); - draw_relief(result,color,10,5,5,width-10,height-10); - draw_relief(result,color,5,6,6,width-12,height-12); - result. - - - Drawing the text over the background. - - define One - draw_button_text - ( - RGBAImage image, - String text, - Int text_index, - Int pixel_x, - Int y, - Rectangle clip, - RGBA color, - SystemFont font, - ) = - if nth(text_index,text) is - { - failure then unique, - success(c) then - with cw = draw_system_character(image,clip,pixel_x,y,font,word8_to_int32(c),color), - draw_button_text(image,text,text_index+1,pixel_x+cw+1,y,clip,color,font) - }. - - define One - draw_button_text - ( - RGBAImage image, - String text, - Int text_width, - RGBA light_color, - RGBA dark_color, - SystemFont font - ) = - with image_width = width(image), - image_height = height(image), - x_pos = (image_width-text_width)>>1, - clip = rect(0,0,image_width,image_height), - new_light_color = lighten(light_color,150), - new_dark_color = darken(dark_color,40), - draw_button_text(image, text, 0, x_pos+2, 16, clip, new_dark_color, font); - draw_button_text(image, text, 0, x_pos, 14, clip, new_light_color, font). - - - The next function creates the two images for a button. The information given is the - main color of the button, the text of the button and the minimal width (in pixels) of - the button. The function does not create the button if the images already exist. The - two images are stored in the directory 'site_directory/buttons'. The names of the files - are of the form: - - bxxxx_off.jpg - bxxxx_on.jpg - - where the prefix 'b' is to avoid leading '-' which may perturb UNIX commands (like - 'rm'), and where 'xxxx' is created from the given informations by the formula: - - xxxx = web_arg_encode(sha1((color,text,width))) - - Hence, distinct informations give distinct file names. - - - define String // returns xxxx - create_button_images - ( - String site_directory, - RGBA color, - String text, - Int width, - SystemFont font - ) = - with xxxx = web_arg_encode(sha1((color,text,width))), - buttons_dir = site_directory+"/public/buttons", - off_filepath = buttons_dir+"/b"+xxxx+"_off.jpg", - on_filepath = buttons_dir+"/b"+xxxx+"_on.jpg", - if file_exists(on_filepath) - then xxxx - else with - text_width = printed_text_width(font,text), - button_width = max(width,text_width+12), - button_height = (Int)20, - light_color = lighten(color,60), - very_light_color = lighten(light_color,30), - dark_color = darken(color,40), - background_off = - create_button_background(color,button_width,button_height), - background_on = - create_button_background(light_color,button_width,button_height), - - draw_button_text(background_off,text,text_width,very_light_color,dark_color,font); - draw_button_text(background_on, text,text_width,very_light_color,dark_color,font); - forget(write_image_to_JPEG_file(to_JPEG(background_off), - off_filepath, - 100)); - forget(write_image_to_JPEG_file(to_JPEG(background_on), - on_filepath, - 100)); - xxxx. - - - - - *** [5.4] Formating an actioner. An actioner works as follows. Assume first that it refers to a form. When it is clicked @@ -4236,7 +4069,13 @@ define Printable_tree any_div_empty(options) then [format_div_option(options), "\n"], any_coreattrs(attributs) then - [format_attrs(attributs)] + [format_attrs(attributs)], + any_ol(opts,e) then + ["",format_element(e),"\n"], + any_ul(opts,e) then + ["",format_element(e),"\n"], + any_li(opts,e) then + ["",format_element(e),"\n"], }. @@ -4357,7 +4196,13 @@ define Printable_tree format(cinfo, sn, ic_v, html_elements, is_https, action_count, head_tags), br then ["
"], - progress(options, value, max) then [""] + progress(options, value, max) then [""], + ol(opts, t) then + format(cinfo,sn,ic_v,any_ol(opts,t),format_element,is_https, action_count, head_tags), + ul(opts, t) then + format(cinfo,sn,ic_v,any_ul(opts,t),format_element,is_https, action_count, head_tags), + li(opts, t) then + format(cinfo,sn,ic_v,any_li(opts,t),format_element,is_https, action_count, head_tags), }. @@ -4441,7 +4286,10 @@ define Bool hidden(_,_,_) then false, partial(_) then false, br then false, - progress(_,_,_) then false + progress(_,_,_) then false, + ol(_,_) then false, + ul(_,_) then false, + li(_,_) then false }. define String @@ -4573,7 +4421,14 @@ define Printable_tree head_tags <- *head_tags + tags; format(cinfo, sn, ic_v, html_elements, is_https, action_count, head_tags), br then ["
"], - progress(options, value, max) then [""] + progress(options, value, max) then [""], + ol(opts, t) then + format(cinfo,sn,ic_v,any_ol(opts,t),format_element,is_https, action_count, head_tags), + ul(opts, t) then + format(cinfo,sn,ic_v,any_ul(opts,t),format_element,is_https, action_count, head_tags), + li(opts, t) then + format(cinfo,sn,ic_v,any_li(opts,t),format_element,is_https, action_count, head_tags), + }. -- libgit2 0.21.4