Adding a Scrollbar to TextAuthor: Carl Sassenrath Here's an example that shows how to scroll one or more text faces in a REBOL/View window. This method of scrolling runs very fast on most types of systems. (By the way, a future version of REBOL/View will have this built-in.) The code below creates a layout that contains a text face (t1) with a scroll bar (s1).
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).
When the scroll bar is moved, the SCROLL-TFACE function is called. This function modifies the text paragraph SCROLL value, which will shift the text within its face (vertically in this case, but you could also scroll it horizontally). This function uses size information that is stored in the user-data field by the UPDATE-TFACE function below.
The OPEN-TFACE function reads a text file and then resets and updates the text face.
The RESET-TFACE function sets the the text and the scroll bar back to the top. We also put the SHOW function here to refresh the display (but you don't have to put it here if you have a better place for it).
The UPDATE-TFACE function recomputes important text information whenever text is changed within the face. Setting the line list to NONE forces a face to re-render all of it's text lines. The USER-DATA field holds the new size of the text, and the REDRAG function changes the scroll bar knob (dragger) to the correct proportional size.
If you put all these pieces together into a script file you can give it a try. At the bottom add:
Note that if an error happens, you may need to update to a newer version of REBOL/View. You can add a horizontal scrollbar using similar code. Change the references to /Y to /X above and get the FIRST value from SIZE-TEXT rather than the second. |