Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Question on text formatting

From: gscottjones:mchsi at: 29-Aug-2002 17:10

Hi, Andy, I couldn't quit thinking about this interesting problem, so I managed to kill a good part of the afternoon. But .... I certainly understand event filtering better. Here is what I did. I set up a list of the named buttons in order to allow scrolling with the right and left keys. A space or enter (or any key except the direction keys) open the request box. In order to allow scrolloing down and up with arrow keys, the data will need better structure (it can be done as is, but it is most inelegant) but should be do-able. I changed Button to my own little custom widget based on field. It is markedly ugly as is, but I was focusing on functionality over beauty. Left to be done is restructuring the data (or hacking a kludge that parses the unique aspects of the keys and counts were on a line it is so that it can skip to a similar spot on the line above or below ... whew .. sounds easier to build a smidge more structure into the data!), the filling in the code for up and down arrows captured at the global even level (at bottom of script), changing the focus for mouse click (if desired) to update the index into the data, and beautify/beautify/beautify (most readily done at the style definition at the top ... ??? how to get rid of the caret cursor?). Hope this helps. It sure helped me, but I don't know whether to thank you or curse you for posting such an interesting problem! :-) Listing follows, but there will be major wrap problems!!! I'll send an attachment to to email address. --Scott Jones REBOL [] back_color: blue info-addon: stylize [ my-info: field with [ edge: [size: 1x1 effect: 'bevel] colors: reduce [svvc/field red] ;flags: [field return tabbed on-unfocus] flags: [return tabbed on-unfocus] feel: make feel [ engage: func [face act event index][ switch act [ down [ either not-equal? face ctx-text/view*/focal-face [ focus face ;ctx-text/view*/caret: offset-to-caret face event/offset ][ ;ctx-text/view*/highlight-start: ;ctx-text/view*/highlight-end: none ;ctx-text/view*/caret: offset-to-caret face event/offset ] show face ] ;over [ ; if not-equal? ctx-text/view*/caret offset-to-caret face event/offset [ ; if not ctx-text/view*/highlight-start [ ; ctx-text/view*/highlight-start: ctx-text/view*/caret ; ] ; ctx-text/view*/highlight-end: ; ctx-text/view*/caret: offset-to-caret face event/offset ; show face ; ] ;] key [ do e face/text ] ] ] ] ] ] schedule_list: [ "01" "show title" 00:30 "description" "01" "show extra long title 1" 00:30 "description" "01" "show title 2" 01:00 "description" "01" "show title 3" 00:30 "description" "01" "show title 4" 00:30 "description" "01" "show title 5" 00:30 "description" "01" "show title 6" 00:30 "description" "01" "show title 7" 01:00 "description" "01" "show title 8" 00:30 "description" "01" "show title 9" 00:30 "description" "02" "2 show title" 00:30 "description" "02" "2 show title 1" 00:30 "description" "02" "2 show title 2" 00:30 "description" "02" "2 show title 3" 00:30 "description" "02" "2 show title 4" 00:30 "description" "02" "2 show title 5" 00:30 "description" "02" "2 show title 6" 01:30 "description" "02" "2 show title 7" 00:30 "description" "02" "2 show title 8" 00:30 "description" "02" "2 show title 9" 00:30 "description" "03" "2 show title" 00:30 "description" "03" "3 show title 1" 00:30 "description" "03" "3 show title 2" 00:30 "description" "03" "3 show title 3" 00:30 "description" "03" "3 show title 4" 00:30 "description" "03" "3 show title 5" 00:30 "description" "03" "3 show title 6" 00:30 "description" "03" "3 show title 7" 02:30 "description" "03" "3 show title 8" 00:30 "description" "03" "3 show title 9" 00:30 "description" "04" "4 show title" 00:30 "description" "04" "4 show title 1" 00:30 "description" "04" "4 show title 2" 00:30 "description" "04" "4 show title 3" 00:30 "description" "04" "4 show title 4" 00:30 "description" "04" "4 show title 5" 00:30 "description" "04" "4 show title 6" 00:30 "description" "04" "4 show title 7" 00:30 "description" "04" "4 show title 8" 01:30 "description" "04" "4 show title 9" 01:00 "description" "11" "show title" 00:30 "description" "11" "show title 1" 00:30 "description" "11" "show title 2" 00:30 "description" "11" "show title 3" 00:30 "description" "11" "show title 4" 00:30 "description" "11" "show title 5" 00:30 "description" "12" "show title" 00:30 "description" "12" "show title 1" 00:30 "description" "12" "show title 2" 00:30 "description" "12" "show title 3" 00:30 "description" "12" "show title 4" 00:30 "description" "13" "show title" 00:30 "description" "13" "show title 1" 00:30 "description" "13" "show title 2" 00:30 "description" "13" "show title 3" 00:30 "description" "14" "show title 8" 00:30 "description" "14" "show title 9" 00:30 "description" "21" "show title" 00:30 "description" "21" "show title 1" 00:30 "description" "21" "show title 2" 00:30 "description" "21" "show title 7" 00:30 "description" "21" "show title 8" 00:30 "description" "21" "show title 9" 00:30 "description" "22" "show title" 00:30 "description" "22" "show title 1" 00:30 "description" "22" "show title 9" 00:30 "description" "23" "show title" 00:30 "description" "23" "show title 1" 00:30 "description" "23" "show title 2" 00:30 "description" "23" "show title 3" 00:30 "description" "23" "show title 4" 00:30 "description" "24" "show title 3" 00:30 "description" "24" "show title 4" 00:30 "description" "24" "show title 6" 00:30 "description" "24" "show title 7" 00:30 "description" "24" "show title 8" 00:30 "description" "24" "show title 9" 00:30 "description" ] e: func [t][request/ok rejoin ["Program selected is " t "!"]] ee: [e face/text] ; build timeline timeline: layout [ backcolor back_color origin 0x0 ;make sure no added space space 0x0 across ;used a little less brute force ;(moving with the force :-) text 80 "12:00" text 80 "01:00" text 80 "02:00" text 80 "03:00" text 80 "04:00" text 80 "05:00" text 80 "06:00" text 80 "07:00" text 80 "08:00" text 80 "09:00" text 80 "10:00" text 80 "11:00" text 80 "12:00" text 80 "01:00" text 80 "02:00" text 80 "03:00" text 80 "04:00" text 80 "05:00" text 80 "06:00" text 80 "07:00" text 80 "08:00" text 80 "09:00" text 80 "10:00" text 80 "11:00" ] ; build channel lineup lineup: [ backcolor back_color origin 0x0 space 0x0 pad 0 ] ; build grid page mygrid: [ backcolor gray styles info-addon ] append mygrid [origin 0x0 ] ;append mygrid [space 1x1 across] ;needed to be consistent with the time line append mygrid [space 0x0 across] last-channel: 0 grid_count: 0 grid_v_max: -1 grid_h_max: 0 my-but-blk: copy [] foreach [channel title time description ] schedule_list [ if (last-channel <> channel) [ append mygrid [ return ] grid_v_max: grid_v_max + 1 if(grid_count > grid_h_max) [ grid_h_max: grid_count] grid_count: 0 append lineup [ text ] append lineup channel ;add vertical height of text to match button height append lineup [20x20] ] ;more generic length creation routine size: 80x20 * to-pair append append copy [] ( time / :30) 1 ; size: 80x20 ; if (time >= 1:00) [ size: 160x20 ] ; if (time >= 1:30) [ size: 240x20 ] ; if (time >= 1:30) [ size: 320x20 ] ;append mygrid to-set-word join "bn-" checksum rejoin [channel title time description] append my-but-blk rejoin ["bn-" channel grid_count] append mygrid to-set-word rejoin ["bn-" channel grid_count] ;append mygrid [button] append mygrid [my-info] append mygrid size append mygrid copy title ;get rid of button text wrapping append mygrid [para [wrap?: false]] ;append mygrid [edge [size: 1x1]] append mygrid [ ee ] last-channel: channel grid_count: grid_count + 1 ] grid-f: layout load mygrid grid_h_max: grid_h_max * 2 lineup-f: layout load lineup main: layout [ size 720x400 backcolor back_color across ; guide pad 0 button "cursor-up" [ if(current_grid_count > 0) [ grid-f/offset/2: grid-f/offset/2 + 10 current_grid_count: current_grid_count - 1 grid-f/changes: 'offset lineup-f/offset/2: lineup-f/offset/2 + 10 show grid-small-f show lineup_box ] ] button "cursor-down" [ if(current_grid_count < grid_v_max) [ grid-f/offset/2: grid-f/offset/2 - 10 current_grid_count: current_grid_count + 1 grid-f/changes: 'offset lineup-f/offset/2: lineup-f/offset/2 - 10 show grid-small-f show lineup_box ] ] button "cursor-left" [ if(current_h_grid_count > 0) [ current_h_grid_count: current_h_grid_count - 1 grid-f/offset/1: grid-f/offset/1 + 40 grid-f/changes: 'offset timeline/offset/1: timeline/offset/1 + 40 show grid-small-f show time_box ] ] button "cursor-right" [ if(current_h_grid_count < grid_h_max) [ current_h_grid_count: current_h_grid_count + 1 grid-f/changes: 'offset grid-f/offset/1: grid-f/offset/1 - 40 timeline/offset/1: timeline/offset/1 - 40 show grid-small-f show time_box ] ] button "halt" font [colors: [100.100.100]] [ halt ] at 105x90 lineup_box: info 30x196 at 160x50 time_box: info 400x30 back_color at 150x80 panels: box 540x400 ] setpanel: func [ a [object!] ] [ panels/pane: a grid-f/offset: 0x0 current_grid_count: 0 current_h_grid_count: 0 timeline/offset: 0x0 time_box/pane: timeline ;;; lineup-f/offset: 0x4 ;can now be set to 0 since text correct height lineup-f/offset: 0x0 lineup_box/pane: lineup-f show time_box show lineup_box ] print_times: func [ start_time ] [ curr_pos: 10 for curr_time start_time (start_time + 05:00) 00:30 [ reduce [at curr_pos x 10 text curr_time] curr_pos: curr_pos + 80 ] ] panel_grid: layout [ origin 10x8 backcolor back_color below grid-small-f: box 400x200 gray edge [size: 5x5 white] do [ grid-small-f/pane: grid-f grid-f/offset: 0x0 current_grid_count: 0 current_h_grid_count: 0 ] return ] panel_grid/offset: 0x0 setpanel panel_grid query-before-passing-on: func [face event][ switch/default event/type [ key [ switch/default event/key [ right [ my-but-blk: next my-but-blk if tail? my-but-blk [my-but-blk: head my-but-blk] focus do to-word first my-but-blk return none ] left [ either head? my-but-blk [ my-but-blk: back tail my-but-blk ][ my-but-blk: back my-but-blk ] focus do to-word first my-but-blk return none ] up [ return none ] down [ return none ] ] [return event] ] ] [event] ] focus do to-word first my-but-blk do [insert-event-func :query-before-passing-on ] view main