VID 'with' keyword
I am looking over Nick's huge document on business applications, trying to make myself a little function that will take a block of data blocks and return the data in a scrollable grid of fields. I used something of his as a model, it works fine, but I don't understand one little item and I don't like to use code I don't understand. The little item is the "with" keyword, marked on the sample script below. Can anyone explain what "with" means and when one uses it? I did scan the VID documentation on the REBOL web site and did not spot it. Thank you. R E B O L [ Title: "Grid layout" Purpose: {Take a block of data consisting of two-element sub-blocks and return a layout that has a two-column grid of the supplied data along with a scroller.} ] GRID-LAYOUT: func [ DATABLOCK /local GRID DISPLAY ] [ GRID: copy [across space 0] forskip DATABLOCK 2 [ append GRID compose [ info 100 (form DATABLOCK/1) info 200 (form DATABLOCK/2) return ] ] DISPLAY: layout [ across DISPBOX: box 300x500 with [ ;;;;; What is the "with" keyword? pane: layout/tight GRID pane/offset: 0x0 ] scroller 20X500 [ DISPBOX/pane/offset/y: DISPBOX/size/y - DISPBOX/pane/size/y * value show DISPBOX ] ] return DISPLAY ] ;;Uncomment to test view GRID-LAYOUT [ "01" "AAAA" "02" "BBBB" "03" "CCCC" "04" "DDDD" "05" "EEEE" "06" "FFFF" "07" "GGGG" "08" "HHHH" "09" "IIII" "10" "JJJJ" "11" "KKKK" "12" "LLLL" "13" "MMMM" "14" "NNNN" "15" "OOOO" "16" "PPPP" "17" "QQQQ" "18" "RRRR" "19" "SSSS" "20" "TTTT" "21" "UUUU" "22" "VVVV" "23" "WWWW" "24" "XXXX" "25" "YYYY" "26" "ZZZZ" ]
posted by: Steven White 27-Feb-2019/17:27:11-8:00
There's a post towards the end of the topic "Looking for an efficient way to handle text face offset" with some details about WITH
posted by: VIDpuzzle 27-Feb-2019/18:14:48-8:00
Simply put: WITH gives you access to the face object of the current element as it is being created. There's an element of under-the-hood about using it as any values you may stick in there may be overwritten by either the INIT block for the particular style or other facets (even those preceding the WITH block). view layout [ box with [color: red size: 200x100] box green 50x100 with [color: red size: 200x100] box with [color: red] blue ]
posted by: Chris 28-Feb-2019/17:26:59-8:00
Of course, you can use WITH to hack the INIT block--then things get interesting: view layout [ box green "Foo" with [ init: [ size: 400x400 color: red text: "I've been modified!" ] ] ] However, if you do use your own custom INIT block, you may lose some of each style's special sauce: view layout [ box with [print ["BOX:" mold init]] text with [print ["TEXT:" mold init]] button with [print ["BUTTON:" mold init]] ; etc. ]
posted by: Chris 28-Feb-2019/17:34:35-8:00
|