Commit e009b01c8d756b151fbd43dfc15246e229eecbec
1 parent
e69683f4
*** empty log message ***
Showing
5 changed files
with
105 additions
and
45 deletions
Show diff stats
anubis_dev/library/tools/basis.anubis
| ... | ... | @@ -29,7 +29,7 @@ |
| 29 | 29 | *** (4.2.3) Lenght |
| 30 | 30 | *** (4.3) A syntactical variant for 'append' |
| 31 | 31 | *** (4.4) Merging two lists |
| 32 | - *** (4.4.1) with standrad comparison | |
| 32 | + *** (4.4.1) with standard comparison | |
| 33 | 33 | *** (4.4.2) with a non standard comparison: |
| 34 | 34 | *** (4.5) Quick sorting of lists. |
| 35 | 35 | *** (4.6) Randomly shuffling a list. |
| ... | ... | @@ -42,6 +42,7 @@ |
| 42 | 42 | *** (4.8.3) 'map' a list to a list |
| 43 | 43 | *** (4.9) Check that all elements of a list have a given property |
| 44 | 44 | *** (4.10) Replace element in a list by its new_value |
| 45 | + *** (4.11) Get a List($A) from a List($B) | |
| 45 | 46 | *** (5) A generic 'identity' function |
| 46 | 47 | *** (6) Printable trees. |
| 47 | 48 | *** (6.1) Definition |
| ... | ... | @@ -351,6 +352,8 @@ public define String |
| 351 | 352 | |
| 352 | 353 | |
| 353 | 354 | *** (4.1) Find element(s) |
| 355 | + | |
| 356 | + *** (4.1.1) as nth from a list | |
| 354 | 357 | |
| 355 | 358 | public define Maybe($T) |
| 356 | 359 | nth |
| ... | ... | @@ -398,6 +401,56 @@ public define $T |
| 398 | 401 | }. |
| 399 | 402 | |
| 400 | 403 | |
| 404 | + *** (4.1.2) Get a List($A) from a List($B) | |
| 405 | + | |
| 406 | +public define List($A) | |
| 407 | + find_elements | |
| 408 | + ( | |
| 409 | + List($B) l, | |
| 410 | + $B -> Bool test, | |
| 411 | + $B -> List($A) to_a | |
| 412 | + ) = | |
| 413 | + if l is | |
| 414 | + { | |
| 415 | + [] then [], | |
| 416 | + [h . t] then | |
| 417 | + if test(h) | |
| 418 | + then append(to_a(h),find_elements(t,test,to_a)) | |
| 419 | + else find_elements(t,test,to_a) | |
| 420 | + }. | |
| 421 | + | |
| 422 | +public define List($A) | |
| 423 | + find_elements | |
| 424 | + ( | |
| 425 | + List($B) l, | |
| 426 | + $B -> Bool test, | |
| 427 | + $B -> $A to_a | |
| 428 | + ) = | |
| 429 | + if l is | |
| 430 | + { | |
| 431 | + [] then [], | |
| 432 | + [h . t] then | |
| 433 | + if test(h) | |
| 434 | + then [to_a(h) . find_elements(t,test,to_a)] | |
| 435 | + else find_elements(t,test,to_a) | |
| 436 | + }. | |
| 437 | + | |
| 438 | + | |
| 439 | +public define List($A) | |
| 440 | + find_elements | |
| 441 | + ( | |
| 442 | + List($B) l, | |
| 443 | + $B -> $A to_a | |
| 444 | + ) = | |
| 445 | + if l is | |
| 446 | + { | |
| 447 | + [] then [], | |
| 448 | + [h . t] then [to_a(h) . find_elements(t,to_a)] | |
| 449 | + }. | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 401 | 454 | *** (4.2) member |
| 402 | 455 | |
| 403 | 456 | |
| ... | ... | @@ -808,6 +861,10 @@ public define List($T) |
| 808 | 861 | }. |
| 809 | 862 | |
| 810 | 863 | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 811 | 868 | *** (5) A generic 'identity' function |
| 812 | 869 | |
| 813 | 870 | ... | ... |
20.1 KB
anubis_dev/library/widgets3/hypertext.anubis
| ... | ... | @@ -542,9 +542,9 @@ define BlockContent |
| 542 | 542 | BlockContent bc1 + BlockContent bc2 = |
| 543 | 543 | if bc1 is |
| 544 | 544 | { |
| 545 | - empty then bc2, | |
| 546 | - text(w,_) then text(w,bc2), | |
| 547 | - link(w,a,i,_) then link(w,a,i,bc2) | |
| 545 | + empty then bc2, | |
| 546 | + text(w,bc) then text(w,bc+bc2), | |
| 547 | + link(w,a,i,bc) then link(w,a,i,bc+bc2) | |
| 548 | 548 | }. |
| 549 | 549 | |
| 550 | 550 | |
| ... | ... | @@ -594,6 +594,16 @@ define String |
| 594 | 594 | link(s,a,i,b) then s+concat_bcont(b), |
| 595 | 595 | }. |
| 596 | 596 | |
| 597 | +define String | |
| 598 | + print_bl | |
| 599 | + ( | |
| 600 | + List(BlockLine) lbl | |
| 601 | + ) = | |
| 602 | + if lbl is | |
| 603 | + { | |
| 604 | + [] then "", | |
| 605 | + [h . t] then concat_bcont(cont(h))+"|"+print_bl(t) | |
| 606 | + }. | |
| 597 | 607 | |
| 598 | 608 | *** (4.2.1) Transform the text to List(BlockLine) |
| 599 | 609 | ************************************************* |
| ... | ... | @@ -684,27 +694,26 @@ define (List(BlockLine),BlockContent) |
| 684 | 694 | (BlockContent,String) -> BlockLine to_middle, |
| 685 | 695 | String -> BlockContent to_bcont, |
| 686 | 696 | List(BlockLine) so_far |
| 687 | - ) = | |
| 697 | + ) = | |
| 688 | 698 | if nth(i,line) is |
| 689 | 699 | { |
| 690 | 700 | failure then |
| 691 | 701 | with new_words_line = (String)(words_line+" "+word), |
| 692 | 702 | bc_and_line = (String)(concat_bcont(bc)+new_words_line), |
| 693 | 703 | if is_too_large_c(bc_and_line) |
| 694 | - then ([middle(bc+to_bcont(words_line)) . so_far],to_bcont(word)) | |
| 704 | + then ([middle(bc+to_bcont(words_line)) . so_far],to_bcont(word)) | |
| 695 | 705 | else (so_far,to_bcont(bc_and_line)) |
| 696 | 706 | success(c) then |
| 697 | 707 | if c = ' ' |
| 698 | 708 | then // the test on 'words_line' is to avoid a space as first character to begin |
| 699 | 709 | // the all text to print |
| 700 | 710 | with new_words_line = (String)(words_line+(if words_line = "" then "" else " ")+word), |
| 711 | + //with new_words_line = (String)(words_line+word), | |
| 701 | 712 | if is_too_large_c(new_words_line+concat_bcont(bc)) |
| 702 | - then //print("too_large = ["+new_words_line+concat_bcont(bc)+"]\n"); | |
| 703 | - transforming_text(line,empty,i+1,is_too_large,is_too_large,to_middle, | |
| 713 | + then transforming_text(line,empty,i+1,is_too_large,is_too_large,to_middle, | |
| 704 | 714 | word+" ","",to_middle,to_bcont, |
| 705 | 715 | [to_bline(bc,words_line) . so_far]) |
| 706 | - else //print("not_too_large = ["+new_words_line+concat_bcont(bc)+"]\n"); | |
| 707 | - transforming_text(line,bc,i+1,is_too_large_c,is_too_large,to_bline, | |
| 716 | + else transforming_text(line,bc,i+1,is_too_large_c,is_too_large,to_bline, | |
| 708 | 717 | "",new_words_line,to_middle,to_bcont,so_far) |
| 709 | 718 | else transforming_text(line,bc,i+1,is_too_large_c,is_too_large,to_bline, |
| 710 | 719 | word+implode([c]),words_line,to_middle,to_bcont,so_far) |
| ... | ... | @@ -748,11 +757,13 @@ define (List(BlockLine),BlockContent) |
| 748 | 757 | transforming_text(t,empty,is_too_large_i,is_too_large,to_first, |
| 749 | 758 | to_flast,to_middle,to_first,to_last,to_bcont, |
| 750 | 759 | bc_to_bl,[bc_to_bl(new_bc) . new_lbl]+so_far)) |
| 751 | - else transforming_text(t,empty,is_too_large_i,is_too_large,to_first, | |
| 760 | + | |
| 761 | + else if t is [] | |
| 762 | + then (so_far,add_bc) | |
| 763 | + else transforming_text(t,empty,is_too_large_i,is_too_large,to_first, | |
| 752 | 764 | to_flast,to_middle,to_first,to_last,to_bcont, |
| 753 | 765 | bc_to_bl,[to_flast(add_bc,"")]+so_far) |
| 754 | 766 | }. |
| 755 | - | |
| 756 | 767 | |
| 757 | 768 | |
| 758 | 769 | |
| ... | ... | @@ -797,7 +808,7 @@ define List(BlockLine) |
| 797 | 808 | [h . t] then |
| 798 | 809 | if h is |
| 799 | 810 | { |
| 800 | - new_paragraph(txt) then | |
| 811 | + new_paragraph(txt) then | |
| 801 | 812 | if transforming_text |
| 802 | 813 | (split_string_into_lines(txt),b_cont,is_too_large_i,is_too_large, |
| 803 | 814 | (BlockContent bc,String s) |-> first(bc+text(s,empty)), |
| ... | ... | @@ -811,7 +822,7 @@ define List(BlockLine) |
| 811 | 822 | append(reverse(new_lbl), |
| 812 | 823 | transforming_text(t,is_too_large_i,is_too_large,new_bc)), |
| 813 | 824 | |
| 814 | - to_continue(txt) then | |
| 825 | + to_continue(txt) then | |
| 815 | 826 | if transforming_text |
| 816 | 827 | (split_string_into_lines(txt),b_cont,is_too_large,is_too_large, |
| 817 | 828 | (BlockContent bc,String s) |-> middle(bc+text(s,empty)), |
| ... | ... | @@ -825,7 +836,7 @@ define List(BlockLine) |
| 825 | 836 | append(reverse(new_lbl), |
| 826 | 837 | transforming_text(t,is_too_large_i,is_too_large,new_bc)), |
| 827 | 838 | |
| 828 | - new_paragraph(lk,i) then | |
| 839 | + new_paragraph(lk,i) then | |
| 829 | 840 | if transforming_text |
| 830 | 841 | (split_string_into_lines(txt(lk)),b_cont,is_too_large_i,is_too_large, |
| 831 | 842 | (BlockContent bc,String s) |-> first(bc+link(s,action(lk),i,empty)), |
| ... | ... | @@ -2252,11 +2263,19 @@ define List(LinkRectangle) |
| 2252 | 2263 | link_rectangle(index(act_lr),lrect(act_lr),state,action(act_lr))). |
| 2253 | 2264 | |
| 2254 | 2265 | |
| 2266 | +define List(WidgetRectangle) | |
| 2267 | + get_visited_wid_rect | |
| 2268 | + ( | |
| 2269 | + List(LinkRectangle) llr | |
| 2270 | + ) = | |
| 2271 | + find_elements(llr, | |
| 2272 | + (LinkRectangle lr) |-> state(lr)=visited, | |
| 2273 | + (LinkRectangle lr) |-> wid_rect(lrect(lr))). | |
| 2274 | + | |
| 2255 | 2275 | |
| 2256 | 2276 | *** (8.2.2) When mouse moves... |
| 2257 | 2277 | ******************************* |
| 2258 | 2278 | |
| 2259 | - define Maybe((List(LinkRectangle),List(WidgetRectangle),Maybe(LinkRectangle))) | |
| 2260 | 2279 | define Maybe((List(LinkRectangle),List(WidgetRectangle),LinkRectangle)) |
| 2261 | 2280 | mouse_over_lk_rect |
| 2262 | 2281 | ( |
| ... | ... | @@ -2279,7 +2298,7 @@ define Maybe((List(LinkRectangle),List(WidgetRectangle),LinkRectangle)) |
| 2279 | 2298 | mouse_over then mouse_over, |
| 2280 | 2299 | visited then visited |
| 2281 | 2300 | },action(h)), |
| 2282 | - success(([active_lk. so_far], | |
| 2301 | + success(([active_lk . append(t,so_far)], | |
| 2283 | 2302 | wid_rect, |
| 2284 | 2303 | active_lk)) |
| 2285 | 2304 | else mouse_over_lk_rect(t,mx,my,[h . so_far]) |
| ... | ... | @@ -2298,7 +2317,6 @@ define WidgetAnswer |
| 2298 | 2317 | Var(List(LinkRectangle)) lk_rect, |
| 2299 | 2318 | Var(Maybe(LinkRectangle)) active_link |
| 2300 | 2319 | ) = |
| 2301 | - //print_lkr(*lk_rect); | |
| 2302 | 2320 | if e is |
| 2303 | 2321 | { |
| 2304 | 2322 | mouse_gone then |
| ... | ... | @@ -2309,7 +2327,7 @@ define WidgetAnswer |
| 2309 | 2327 | active_link <- failure; |
| 2310 | 2328 | handled(wid_rect(lrect(a_lk))) |
| 2311 | 2329 | }, |
| 2312 | - mouse_move(ks,mx,my) then //print("mx="+mx+" | my="+my+"\n"); | |
| 2330 | + mouse_move(ks,mx,my) then | |
| 2313 | 2331 | if mouse_over_lk_rect(*lk_rect,mx,my,[]) is |
| 2314 | 2332 | { |
| 2315 | 2333 | failure then |
| ... | ... | @@ -2325,8 +2343,8 @@ define WidgetAnswer |
| 2325 | 2343 | }, |
| 2326 | 2344 | success(s) then if s is (new_lk_rect,wid_rect,a_lk) |
| 2327 | 2345 | then lk_rect <- new_lk_rect; |
| 2328 | - active_link <- success(a_lk); | |
| 2329 | - handled(wid_rect) | |
| 2346 | + active_link <- success(a_lk); | |
| 2347 | + handled(wid_rect) | |
| 2330 | 2348 | }, |
| 2331 | 2349 | mouse_click(ks,mc,mx,my) then |
| 2332 | 2350 | if *active_link is |
| ... | ... | @@ -2339,8 +2357,8 @@ define WidgetAnswer |
| 2339 | 2357 | left_up then |
| 2340 | 2358 | lk_rect <- move_link_state(*lk_rect,a_lk,visited); |
| 2341 | 2359 | action(a_lk)(etb); |
| 2342 | - active_link <- failure; | |
| 2343 | - not_handled(wid_rect(lrect(a_lk))), | |
| 2360 | + active_link <- failure; | |
| 2361 | + handled(wid_rect(lrect(a_lk))), | |
| 2344 | 2362 | middle_down then not_handled([]), |
| 2345 | 2363 | middle_up then not_handled([]), |
| 2346 | 2364 | right_down then not_handled([]), |
| ... | ... | @@ -2362,7 +2380,7 @@ define List((String,Int32,WidgetRectangle)) |
| 2362 | 2380 | if llr is |
| 2363 | 2381 | { |
| 2364 | 2382 | [] then [], |
| 2365 | - [h . t] then if ls=state(h) then lrect(h) else rect_to_draw(t,ls) | |
| 2383 | + [h . t] then if ls=state(h) then append(lrect(h),rect_to_draw(t,ls)) else rect_to_draw(t,ls) | |
| 2366 | 2384 | }. |
| 2367 | 2385 | |
| 2368 | 2386 | |
| ... | ... | @@ -2413,25 +2431,9 @@ define One |
| 2413 | 2431 | HyperTextParameters parms, |
| 2414 | 2432 | Int32 htc_width |
| 2415 | 2433 | ) = |
| 2416 | - draw_links_visited(dtb,parms,rect_to_draw(*lk_rect,visited)); | |
| 2417 | 2434 | draw_links_mouse_over |
| 2418 | - (dtb,parms,rect_to_draw(*lk_rect,mouse_over),lighten(text_color(effect(parms)))). | |
| 2419 | - if *active_lk is | |
| 2420 | - { | |
| 2421 | - failure then | |
| 2422 | - draw_links_visited(dtb,parms,rect_to_draw(*lk_rect,visited)), | |
| 2423 | - success(a_lk) then | |
| 2424 | - if state(a_lk) is | |
| 2425 | - { | |
| 2426 | - normal then unique, | |
| 2427 | - mouse_over then | |
| 2428 | - draw_links_mouse_over | |
| 2429 | - (dtb,parms,rect_to_draw(*lk_rect,mouse_over),lighten(text_color(effect(parms)))), | |
| 2430 | - visited then | |
| 2431 | - draw_links_visited(dtb,parms,rect_to_draw(*lk_rect,visited)) | |
| 2432 | - } | |
| 2433 | - }. | |
| 2434 | - | |
| 2435 | + (dtb,parms,rect_to_draw(*lk_rect,mouse_over),lighten(text_color(effect(parms)))); | |
| 2436 | + draw_links_visited(dtb,parms,rect_to_draw(*lk_rect,visited)). | |
| 2435 | 2437 | |
| 2436 | 2438 | |
| 2437 | 2439 | *** () Creating the widget | ... | ... |
anubis_dev/library/widgets3/richard.jpg
anubis_dev/library/widgets3/try_ht.anubis
| ... | ... | @@ -54,7 +54,7 @@ define LinkWidget |
| 54 | 54 | link_richard = |
| 55 | 55 | link("Richard Coeur de Lion", |
| 56 | 56 | (WidgetEventToolBox w) |-> |
| 57 | - forget(open_host_window(100,100,"Richard Coeur de Lion",create_image("richard.jpg")))). | |
| 57 | + forget(open_host_window(100,150,"Richard Coeur de Lion",create_image("richard.jpg")))). | |
| 58 | 58 | |
| 59 | 59 | define LinkWidget |
| 60 | 60 | link_john = |
| ... | ... | @@ -256,14 +256,15 @@ define One |
| 256 | 256 | forget(open_host_window(10,10,"Text & Link/ Left", |
| 257 | 257 | create_hypertext |
| 258 | 258 | (font,normal(red),failure,350,3,2,18,left, |
| 259 | - hypertext_l1+link_richard+hypertext_l2+empty, | |
| 260 | - //hypertext_l11+link_henri2+hypertext_l12+link_richard+hypertext_l2+empty, | |
| 259 | + //hypertext_l1+link_richard+hypertext_l2+empty, | |
| 260 | + hypertext_l11+link_henri2+hypertext_l12+link_richard+hypertext_l2+empty, | |
| 261 | 261 | //hypertext_l1+link_richard+hypertext_l3+link_john+hypertext_l4+empty, |
| 262 | 262 | success(yellow)))); |
| 263 | 263 | |
| 264 | 264 | forget(open_host_window(400,10,"Text & Link/ Right", |
| 265 | 265 | create_hypertext |
| 266 | 266 | (font,normal(red),failure,350,3,2,18,right, |
| 267 | + //hypertext_l1+link_richard+hypertext_l3+link_john+hypertext_l4+empty, | |
| 267 | 268 | hypertext_l1+link_richard+hypertext_l2+empty, |
| 268 | 269 | success(yellow)))); |
| 269 | 270 | ... | ... |