Commit e7bd8a6e55afb4f005f6bf9bb16d090379f48ca0
1 parent
ec6480d9
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).
Showing
1 changed file
with
39 additions
and
184 deletions
Show diff stats
web/CXM_making_a_web_site.anubis
| ... | ... | @@ -5,7 +5,7 @@ |
| 5 | 5 | *Title* Making interactive Web sites. |
| 6 | 6 | |
| 7 | 7 | *Copyright* Copyright (c) Alain Prouté 2004-2005. |
| 8 | - Copyright (c) Calexium 2007-2015. | |
| 8 | + Copyright (c) Calexium 2007-2016. | |
| 9 | 9 | |
| 10 | 10 | |
| 11 | 11 | *Authors* Alain Prouté |
| ... | ... | @@ -1147,7 +1147,10 @@ public type HTML_In_Form: |
| 1147 | 1147 | hidden (HtmlId id, WebArgName name, InitialValue init), |
| 1148 | 1148 | partial (HTML_Partial_Content), |
| 1149 | 1149 | br, |
| 1150 | - progress (List(CoreAttrs), Int value, Int max). | |
| 1150 | + progress (List(CoreAttrs), Int value, Int max), | |
| 1151 | + ol (List(CoreAttrs), HTML_In_Form content), | |
| 1152 | + ul (List(CoreAttrs), HTML_In_Form content), | |
| 1153 | + li (List(CoreAttrs), HTML_In_Form content). | |
| 1151 | 1154 | |
| 1152 | 1155 | |
| 1153 | 1156 | '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: |
| 1341 | 1344 | HTML_Body /*body*/), |
| 1342 | 1345 | partial (HTML_Partial_Content), |
| 1343 | 1346 | br, |
| 1344 | - progress (List(CoreAttrs), Int value, Int max). | |
| 1347 | + progress (List(CoreAttrs), Int value, Int max), | |
| 1348 | + ol (List(CoreAttrs), HTML_Off_Form content), | |
| 1349 | + ul (List(CoreAttrs), HTML_Off_Form content), | |
| 1350 | + li (List(CoreAttrs), HTML_Off_Form content). | |
| 1345 | 1351 | |
| 1346 | 1352 | 'HTML_Off_Form' defines all the elements you may put outside any form. |
| 1347 | 1353 | |
| ... | ... | @@ -2766,7 +2772,10 @@ type HTML_Any($T): |
| 2766 | 2772 | Maybe((String,List((String,String))))), |
| 2767 | 2773 | any_div (List(CoreAttrs), $T element), |
| 2768 | 2774 | any_div_empty (List(CoreAttrs)), |
| 2769 | - any_coreattrs (List(CoreAttrs)). | |
| 2775 | + any_coreattrs (List(CoreAttrs)), | |
| 2776 | + any_ol (List(CoreAttrs), $T content), | |
| 2777 | + any_ul (List(CoreAttrs), $T content), | |
| 2778 | + any_li (List(CoreAttrs), $T content). | |
| 2770 | 2779 | |
| 2771 | 2780 | |
| 2772 | 2781 | |
| ... | ... | @@ -2800,41 +2809,6 @@ define RGB |
| 2800 | 2809 | 255-g, |
| 2801 | 2810 | 255-b). |
| 2802 | 2811 | |
| 2803 | - | |
| 2804 | - | |
| 2805 | - | |
| 2806 | - *** [5.3] Creating buttons. | |
| 2807 | - | |
| 2808 | - We want to be able to create buttons in the form of a pair of images (rollovers) | |
| 2809 | - automatically. We use the JPEG interface, because for the time being Anubis cannot | |
| 2810 | - handle other kinds of images. | |
| 2811 | - | |
| 2812 | - | |
| 2813 | - Computing printed text length. | |
| 2814 | - | |
| 2815 | - define Int | |
| 2816 | - printed_text_width | |
| 2817 | - ( | |
| 2818 | - Word8 -> Int char_size, | |
| 2819 | - List(Word8) l | |
| 2820 | - ) = | |
| 2821 | - if l is | |
| 2822 | - { | |
| 2823 | - [] then (Int) 0, | |
| 2824 | - [h . t] then char_size(h) + 1+ printed_text_width(char_size,t) | |
| 2825 | - }. | |
| 2826 | - | |
| 2827 | - define Int | |
| 2828 | - printed_text_width | |
| 2829 | - ( | |
| 2830 | - SystemFont font, | |
| 2831 | - String s | |
| 2832 | - ) = | |
| 2833 | - printed_text_width((Word8 c) |-> word8_to_int32(width(get_char_info(font,c))), | |
| 2834 | - explode(s)). | |
| 2835 | - | |
| 2836 | - | |
| 2837 | - | |
| 2838 | 2812 | Converting RGB to RGBA. |
| 2839 | 2813 | |
| 2840 | 2814 | define RGBA |
| ... | ... | @@ -2845,147 +2819,6 @@ define RGBA |
| 2845 | 2819 | if color is rgb(r,g,b) then rgba(r,g,b,255). |
| 2846 | 2820 | |
| 2847 | 2821 | |
| 2848 | - Drawing a 'relief'. | |
| 2849 | - | |
| 2850 | - define One | |
| 2851 | - draw_relief | |
| 2852 | - ( | |
| 2853 | - RGBAImage dest, | |
| 2854 | - RGBA color, | |
| 2855 | - Int contrast, | |
| 2856 | - Int x, | |
| 2857 | - Int y, | |
| 2858 | - Int width, | |
| 2859 | - Int height | |
| 2860 | - ) = | |
| 2861 | - with l = lighten(color,contrast), | |
| 2862 | - d = darken(color,contrast), | |
| 2863 | - draw_rectangle(dest,rect(x,y,x+width,y+1),l); | |
| 2864 | - draw_rectangle(dest,rect(x,y+1,x+1,y+height),l); | |
| 2865 | - draw_rectangle(dest,rect(x+width-1,y+1,x+width,y+height),d); | |
| 2866 | - draw_rectangle(dest,rect(x+1,y+height-1,x+width-1,y+height),d). | |
| 2867 | - | |
| 2868 | - | |
| 2869 | - Creating a button background. | |
| 2870 | - | |
| 2871 | - define RGBAImage | |
| 2872 | - create_button_background | |
| 2873 | - ( | |
| 2874 | - RGBA color, | |
| 2875 | - Int width, | |
| 2876 | - Int height | |
| 2877 | - ) = | |
| 2878 | - with result = create_rgba_image(width,height,color), | |
| 2879 | - draw_relief(result,color,100,0,0,width,height); | |
| 2880 | - draw_relief(result,color,70,1,1,width-2,height-2); | |
| 2881 | - draw_relief(result,color,55,2,2,width-4,height-4); | |
| 2882 | - draw_relief(result,color,35,3,3,width-6,height-6); | |
| 2883 | - draw_relief(result,color,20,4,4,width-8,height-8); | |
| 2884 | - draw_relief(result,color,10,5,5,width-10,height-10); | |
| 2885 | - draw_relief(result,color,5,6,6,width-12,height-12); | |
| 2886 | - result. | |
| 2887 | - | |
| 2888 | - | |
| 2889 | - Drawing the text over the background. | |
| 2890 | - | |
| 2891 | - define One | |
| 2892 | - draw_button_text | |
| 2893 | - ( | |
| 2894 | - RGBAImage image, | |
| 2895 | - String text, | |
| 2896 | - Int text_index, | |
| 2897 | - Int pixel_x, | |
| 2898 | - Int y, | |
| 2899 | - Rectangle clip, | |
| 2900 | - RGBA color, | |
| 2901 | - SystemFont font, | |
| 2902 | - ) = | |
| 2903 | - if nth(text_index,text) is | |
| 2904 | - { | |
| 2905 | - failure then unique, | |
| 2906 | - success(c) then | |
| 2907 | - with cw = draw_system_character(image,clip,pixel_x,y,font,word8_to_int32(c),color), | |
| 2908 | - draw_button_text(image,text,text_index+1,pixel_x+cw+1,y,clip,color,font) | |
| 2909 | - }. | |
| 2910 | - | |
| 2911 | - define One | |
| 2912 | - draw_button_text | |
| 2913 | - ( | |
| 2914 | - RGBAImage image, | |
| 2915 | - String text, | |
| 2916 | - Int text_width, | |
| 2917 | - RGBA light_color, | |
| 2918 | - RGBA dark_color, | |
| 2919 | - SystemFont font | |
| 2920 | - ) = | |
| 2921 | - with image_width = width(image), | |
| 2922 | - image_height = height(image), | |
| 2923 | - x_pos = (image_width-text_width)>>1, | |
| 2924 | - clip = rect(0,0,image_width,image_height), | |
| 2925 | - new_light_color = lighten(light_color,150), | |
| 2926 | - new_dark_color = darken(dark_color,40), | |
| 2927 | - draw_button_text(image, text, 0, x_pos+2, 16, clip, new_dark_color, font); | |
| 2928 | - draw_button_text(image, text, 0, x_pos, 14, clip, new_light_color, font). | |
| 2929 | - | |
| 2930 | - | |
| 2931 | - The next function creates the two images for a button. The information given is the | |
| 2932 | - main color of the button, the text of the button and the minimal width (in pixels) of | |
| 2933 | - the button. The function does not create the button if the images already exist. The | |
| 2934 | - two images are stored in the directory 'site_directory/buttons'. The names of the files | |
| 2935 | - are of the form: | |
| 2936 | - | |
| 2937 | - bxxxx_off.jpg | |
| 2938 | - bxxxx_on.jpg | |
| 2939 | - | |
| 2940 | - where the prefix 'b' is to avoid leading '-' which may perturb UNIX commands (like | |
| 2941 | - 'rm'), and where 'xxxx' is created from the given informations by the formula: | |
| 2942 | - | |
| 2943 | - xxxx = web_arg_encode(sha1((color,text,width))) | |
| 2944 | - | |
| 2945 | - Hence, distinct informations give distinct file names. | |
| 2946 | - | |
| 2947 | - | |
| 2948 | - define String // returns xxxx | |
| 2949 | - create_button_images | |
| 2950 | - ( | |
| 2951 | - String site_directory, | |
| 2952 | - RGBA color, | |
| 2953 | - String text, | |
| 2954 | - Int width, | |
| 2955 | - SystemFont font | |
| 2956 | - ) = | |
| 2957 | - with xxxx = web_arg_encode(sha1((color,text,width))), | |
| 2958 | - buttons_dir = site_directory+"/public/buttons", | |
| 2959 | - off_filepath = buttons_dir+"/b"+xxxx+"_off.jpg", | |
| 2960 | - on_filepath = buttons_dir+"/b"+xxxx+"_on.jpg", | |
| 2961 | - if file_exists(on_filepath) | |
| 2962 | - then xxxx | |
| 2963 | - else with | |
| 2964 | - text_width = printed_text_width(font,text), | |
| 2965 | - button_width = max(width,text_width+12), | |
| 2966 | - button_height = (Int)20, | |
| 2967 | - light_color = lighten(color,60), | |
| 2968 | - very_light_color = lighten(light_color,30), | |
| 2969 | - dark_color = darken(color,40), | |
| 2970 | - background_off = | |
| 2971 | - create_button_background(color,button_width,button_height), | |
| 2972 | - background_on = | |
| 2973 | - create_button_background(light_color,button_width,button_height), | |
| 2974 | - | |
| 2975 | - draw_button_text(background_off,text,text_width,very_light_color,dark_color,font); | |
| 2976 | - draw_button_text(background_on, text,text_width,very_light_color,dark_color,font); | |
| 2977 | - forget(write_image_to_JPEG_file(to_JPEG(background_off), | |
| 2978 | - off_filepath, | |
| 2979 | - 100)); | |
| 2980 | - forget(write_image_to_JPEG_file(to_JPEG(background_on), | |
| 2981 | - on_filepath, | |
| 2982 | - 100)); | |
| 2983 | - xxxx. | |
| 2984 | - | |
| 2985 | - | |
| 2986 | - | |
| 2987 | - | |
| 2988 | - | |
| 2989 | 2822 | *** [5.4] Formating an actioner. |
| 2990 | 2823 | |
| 2991 | 2824 | An actioner works as follows. Assume first that it refers to a form. When it is clicked |
| ... | ... | @@ -4236,7 +4069,13 @@ define Printable_tree |
| 4236 | 4069 | any_div_empty(options) then |
| 4237 | 4070 | [format_div_option(options), "</div>\n"], |
| 4238 | 4071 | any_coreattrs(attributs) then |
| 4239 | - [format_attrs(attributs)] | |
| 4072 | + [format_attrs(attributs)], | |
| 4073 | + any_ol(opts,e) then | |
| 4074 | + ["<ol", format_attrs(opts), ">",format_element(e),"</ol>\n"], | |
| 4075 | + any_ul(opts,e) then | |
| 4076 | + ["<ul", format_attrs(opts), ">",format_element(e),"</ul>\n"], | |
| 4077 | + any_li(opts,e) then | |
| 4078 | + ["<li", format_attrs(opts), ">",format_element(e),"</li>\n"], | |
| 4240 | 4079 | }. |
| 4241 | 4080 | |
| 4242 | 4081 | |
| ... | ... | @@ -4357,7 +4196,13 @@ define Printable_tree |
| 4357 | 4196 | |
| 4358 | 4197 | format(cinfo, sn, ic_v, html_elements, is_https, action_count, head_tags), |
| 4359 | 4198 | br then ["<br>"], |
| 4360 | - progress(options, value, max) then ["<progress max=\"",value,"\" value=\"",max,"\"",format_attrs(options),"></progress>"] | |
| 4199 | + progress(options, value, max) then ["<progress max=\"",value,"\" value=\"",max,"\"",format_attrs(options),"></progress>"], | |
| 4200 | + ol(opts, t) then | |
| 4201 | + format(cinfo,sn,ic_v,any_ol(opts,t),format_element,is_https, action_count, head_tags), | |
| 4202 | + ul(opts, t) then | |
| 4203 | + format(cinfo,sn,ic_v,any_ul(opts,t),format_element,is_https, action_count, head_tags), | |
| 4204 | + li(opts, t) then | |
| 4205 | + format(cinfo,sn,ic_v,any_li(opts,t),format_element,is_https, action_count, head_tags), | |
| 4361 | 4206 | }. |
| 4362 | 4207 | |
| 4363 | 4208 | |
| ... | ... | @@ -4441,7 +4286,10 @@ define Bool |
| 4441 | 4286 | hidden(_,_,_) then false, |
| 4442 | 4287 | partial(_) then false, |
| 4443 | 4288 | br then false, |
| 4444 | - progress(_,_,_) then false | |
| 4289 | + progress(_,_,_) then false, | |
| 4290 | + ol(_,_) then false, | |
| 4291 | + ul(_,_) then false, | |
| 4292 | + li(_,_) then false | |
| 4445 | 4293 | }. |
| 4446 | 4294 | |
| 4447 | 4295 | define String |
| ... | ... | @@ -4573,7 +4421,14 @@ define Printable_tree |
| 4573 | 4421 | head_tags <- *head_tags + tags; |
| 4574 | 4422 | format(cinfo, sn, ic_v, html_elements, is_https, action_count, head_tags), |
| 4575 | 4423 | br then ["<br>"], |
| 4576 | - progress(options, value, max) then ["<progress max=\"",value,"\" value=\"",max,"\"",format_attrs(options),"></progress>"] | |
| 4424 | + progress(options, value, max) then ["<progress max=\"",value,"\" value=\"",max,"\"",format_attrs(options),"></progress>"], | |
| 4425 | + ol(opts, t) then | |
| 4426 | + format(cinfo,sn,ic_v,any_ol(opts,t),format_element,is_https, action_count, head_tags), | |
| 4427 | + ul(opts, t) then | |
| 4428 | + format(cinfo,sn,ic_v,any_ul(opts,t),format_element,is_https, action_count, head_tags), | |
| 4429 | + li(opts, t) then | |
| 4430 | + format(cinfo,sn,ic_v,any_li(opts,t),format_element,is_https, action_count, head_tags), | |
| 4431 | + | |
| 4577 | 4432 | }. |
| 4578 | 4433 | |
| 4579 | 4434 | ... | ... |