[ALLY] Making dynamic button layouts in VIEW
From: bo:rebol at: 29-Jan-2001 16:47
I get asked this question from time to time and there is some insight
involved into how VIEW works, so I thought I would post an example to this
list for the enlightenment of all:
;This is a template for a blank button
button-layout: layout [button "text" ]
;This is your main VIEW
view layout [
text "Enter names for some buttons divided by spaces"
f: field 200
button "Show me!" [
;; first, start off with an empty face to hold the buttons
button-face: layout 
;; keep an offset variable so we know where each button goes
;; Break input from field above into a series of strings
;; and perform some actions on each one
foreach item parse f/text none [
;; The /pane is where sub-faces are stored.
;; This adds the modified blank button templates into the
;; blank button face we created above.
append button-face/pane make button-layout/pane/1 [
;; Buttons expect their label to be in a field called
;; 'texts' which is a block of strings.
texts: reduce [item]
;; The action field determines what will be done when
;; the button is clicked. The COMPOSE statement
;; reduces only the items in parentheses ().
action: func [f e] compose [request/ok (item)]
;; Increment the offset for the next button
ofst: ofst + (button-layout/pane/1/size * 0x1)
;; Set the size for the button-face based on the last offset.
button-face/size: ofst + button-layout/pane/1/size
;; View it!
Bohdan "Bo" Lechnowsky
REBOL Adventure Guide
REBOL Technologies 707-467-8000 (http://www.rebol.com)
The Official Source for REBOL Books (http://www.REBOLpress.com)