Scroller question
I thought I finally understood how to use a scroller, then this: In the sample script below, if you use the 'Load text file' button and select a text file of moderate line size (about 80 characters), the text area of the window will be loaded with the lines from that file. Everything looks good. Then, if you operate the scroller to move down in the text area, and move the mouse pointer over the 'Load text file' button, the text on the button disappears. If you scroll back to the top and move the mouse pointer over the button, the text reappears. Down, disappears; up, reappears; reliably. I used as a model the cookbook example of scrolling text, so I think I checked off the requirements: 1) as-is on the text style, 2) set the line-list, etc., etc. I isolated all that fussing in the LOAD-TEXT-DATA function so it all would be in one spot and I wouldn't forget anything. So I am a bit stumped and wonder if anyone can assist. Thank you. Sample script follows. (I hope this is not a head-slapper.) R E B O L [ Title: 'Show a funny situation with scrolling text' ] TEXT-FILEID: none ;; Name of file we are fixing. TEXT-DATA: copy [] ;; Data from the file, in lines. TEXT-STRING: copy '' ;; Data from the file, as a sting for showing. ;; Called by LOAD-TEXT-FILE for the sake of modularity. LOAD-TEXT-DATA: does [ MAIN-FILEDATA/text: TEXT-STRING MAIN-FILEDATA/para/scroll/y: 0 MAIN-FILEDATA/line-list: none MAIN-FILEDATA/user-data: second size-text MAIN-FILEDATA MAIN-SCROLLER/data: 0 MAIN-SCROLLER/redrag MAIN-FILEDATA/size/y / MAIN-FILEDATA/user-data show MAIN-FILEDATA show MAIN-SCROLLER ] LOAD-TEXT-FILE: does [ if not TEXT-FILEID: request-file/only [ alert 'No file specified.' exit ] ;; We want the text file as lines so we can process one line at a time... TEXT-DATA: copy [] TEXT-DATA: read/lines TEXT-FILEID ;; ...but it seems text must be a string to be put into a text style. ;; TEXT-STRING: read TEXT-FILEID ;; Alternative idea not used TEXT-STRING: copy '' foreach LINE TEXT-DATA [ append TEXT-STRING rejoin [LINE newline] ] ;; Put the string of text into the scrolling text style. LOAD-TEXT-DATA ;; Display the name of the file we are working on. MAIN-FILENAME/text: to-string TEXT-FILEID MAIN-FILENAME/line-list: none show MAIN-FILENAME ] SCROLL-TEXT: does [ MAIN-FILEDATA/para/scroll/y: negate MAIN-SCROLLER/data * (max 0 MAIN-FILEDATA/user-data - MAIN-FILEDATA/size/y) show MAIN-FILEDATA ] MAIN-WINDOW: layout [ across banner 'Conditional Gangpunch' return MAIN-FILEDATA: text 800x600 as-is black white font-name font-fixed MAIN-SCROLLER: scroller 20x600 [SCROLL-TEXT] return button 150 'Load text file' [LOAD-TEXT-FILE] MAIN-FILENAME: info 500 ] view center-face main-window
posted by: Steven White 31-Jan-2017/17:06:47-8:00
OK, maybe a head-slapper. This came to me at 5:30 this morning when I woke up. To see what is going on, change the text of the button to something really long, too long to fit on the button. Then run the program, open a file, operate the scroller just a tiny bit, and move the mouse pointer over the button. The button text does not disappear, it scrolls. To make that not happen, change the "as-is" facet of the text style to "wrap." I originally had "wrap," but I wanted the text file to display as lines so I used "as-is" because of the following remark from cookbook recipe 29: "The text field (t1) above must have the WRAP option (or AS-IS option) in order to force the layout to copy its PARA object. If you don't, then you will end up scrolling all text faces that share the same PARA object (which you will see when they are redrawn in the window)." Originally, using "wrap" instead of "as-is" did not show the text as lines. I reformatted the text to include the line-feed as shown in the function LOAD-TEXT-FILE, changed "wrap" to "as-is," and things seemed to work. I did not know that adding the line-feeds also made "wrap" show the text as lines and that I would not have had to use "as-is." But I thought that "as-is" was OK, based on the documentation. I made a few assumptions and violated a few principles of debugging, and all that led me down the wrong path. We get better, slowly. Thank you.
posted by: Steven White 1-Feb-2017/8:36:01-8:00
Scroller has a built in function. Maybe derived from http://www.rebol.net/cookbook/recipes/0029.html Early Rebol scripts can complicate things. r e b o l [title: "Built In Scroller] view out: layout [ across h3 "Text Scrolling Example" return space 0 text1: text 600x300 wrap green black font-name font-fixed scroller1: scroller 16x300 [scroll-para text1 scroller1] return pad 0x5 space 5 button "Open" [text1/text: read first request-file show text1] ]
posted by: Cal 1-Feb-2017/19:56:35-8:00
Simplest version of what Cal demonstrated: view layout [ across a: area 400x200 scroller [scroll-para a face] ]
posted by: Nick 2-Feb-2017/5:15:38-8:00
|