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

[REBOL] Re: Compose iterated fields with different names for each

From: brett:codeconscious at: 12-Jan-2002 13:23

Hi Philippe,
> Could explain me more about the "with" stuff attached with the field ? Is
> like the html form ?
First I need to correct my earlier post. Not every face has a tag field. I just learnt that I actually created TAG using WITH. Have a look section "6.7. Face Facet Blocks" of the View Developer's guide. It says of "with": "The with block allows you to specify any other type of face characteristic using standard REBOL object format." What this is saying is that WITH allows you to extend the definition of a style for your own purposes. That is, you can add more fields (facets). These fields could contain strings, numbers, functions or any other type of value you want. You can use it in a style definition (probably more useful) or use it like it did, directly on the thing (field, box, etc) you are creating. Some examples. First WITH allows you to set existing fields using the normal Rebol object format: view layout [ box with [color: green] ] Now to extend a style. Here I will add my own field "special-value" (like I did with TAG in my earlier post): view layout [ style named-box box green with [special-value: none] Text "The box has a special value. Press the buttons to set and print it." the-box: named-box button "Set" [the-box/special-value: now] button "Print" [print the-box/special-value] ] I did not realise before now just how powerful this extending feature is. It could be used to help build more sophisticated frameworks or reduce the complexity of your code. For example, when you create styles you can base one style upon another in order to share common features. But what if you are using someone else's styles? Here is a contrived example. Instead of writing: view layout [ box "click me" red [ print ["box has been activated"] ] button "click me" [ print ["button has been activated"] ] ] we can use common code: a-common-action: [ action: func[face value][print [face/style "has been activated"]] ] view layout [ box "click me" red with a-common-action button "click me" with a-common-action ] Cheers Brett.