Home   Archive   Permalink



set-face question

Just recently, I learned, through a little discussion on the REBOL facebook page, that it is inadvisable to set the text of a text face with a command like "face-name-1/text: text-name-1", but instead to use the set-face function.
    
A few months ago I wrote myself a little demo of a demo program, where I display some instructions in a text area and page through pages of text with a "next" button. This text area also had a scroller next to it because sometimes the text was longer than the area I set up for it. The code to load the text area with the next page of text, reset the scroller, and display the new text, looked like this:
    
LOAD-TEXT-AREA: func [PAGE] [
     CURRENT-TEXT: copy ""
     CURRENT-TEXT: pick LESSON-TEXTS PAGE
     TEXT-AREA/text: CURRENT-TEXT
     TEXT-AREA/para/scroll/y: 0
     TEXT-AREA/line-list: none
     TEXT-AREA/user-data: second size-text TEXT-AREA
     TEXT-SCROLLER/redrag TEXT-AREA/size/y / TEXT-AREA/user-data
     show TEXT-AREA
]
    
This worked find initially, but as I paged through pages of text, and ran associated samples of code by means of another button, at some point the text on my buttons that I used to page through text would disappear. The buttons would work, but they would be blank.    
    
So, using my new-found knowledge, I changed the above procedure to look like this:
    
LOAD-TEXT-AREA: func [PAGE] [
     CURRENT-TEXT: copy ""
     CURRENT-TEXT: pick LESSON-TEXTS PAGE
;; TEXT-AREA/text: CURRENT-TEXT
     set-face TEXT-AREA CURRENT-TEXT
     TEXT-AREA/para/scroll/y: 0
     TEXT-AREA/line-list: none
     TEXT-AREA/user-data: second size-text TEXT-AREA
     TEXT-SCROLLER/redrag TEXT-AREA/size/y / TEXT-AREA/user-data
;; show TEXT-AREA
]
    
Notice that I now set the text with the set-face function, and I don't use the "show" function anymore. This also works fine, and I seem to be no longer having problems with the text on the buttons disappearing.
    
So, the question is, if setting the text value of a face by means of the previous method is "face hacking" and not recommended, is there also a recommended procedure for setting those other attributes of the text area that seem to need setting for the scroller to work? The word TEXT-AREA is a 500x400 face of type "text" and TEXT-SCROLLER is a 16x400 scroller that I use to scroll the text withing TEXT-AREA. Those other attributes I am setting are items I located from a REBOL cookbook entry that explained how to use a scroller to move an area of text. I don't actually know what I am doing with them. I just examined the cookbook example until I thought I understood it, and then used that code whenever I want to scroll text.    
    
Or, am I actually doing things correctly, since they do work?
    
Thank you.

posted by:   Steven White       3-Apr-2014/15:21:57-7:00



You can examine any of the built in VID styles like this:
    
     ? svv/vid-styles/area
    
You can see that the area style has an 'access object which contains these functions:
    
     set-face* get-face* clear-face* reset-face*
    
There are no other access functions which do the things you want, so as far as I know given the example, you are setting values correctly.    
    
** One of the things to watch for, which could be the cause of your problems, is that you should typically use a copy of strings and other series values when setting text:
    
     TEXT-AREA/text: copy CURRENT-TEXT
    
Otherwise, you can end up with problems like this:
    
view layout [
     t: text-list
     f: field [append t/data f/text show t]
]
        
In this case, do this:
        
view layout [
     t: text-list
     f: field [append t/data copy f/text show t]
]

posted by:   Nick       3-Apr-2014/17:17:50-7:00