[REBOL] Re: New to list
From: greggirwin:mindspring at: 9-Jun-2003 13:27
Hi John,
Welcome out of lurk mode! :)
jsnP> My question may be rather simple. I do not understand how to add
jsnP> buttons or other named objects to a view interface during execution.
jsnP> Several projects I am working on need to create variables and buttons on
jsnP> the fly since I have no idea how many I will need at run time.
There are lots of variables in that kind of picture. For example,
how are the names to be used if you don't know what they are until
runtime, and do you need to really create them "on the fly" or is the
app data/configuration driven where it's static once a particular
session is running?
I usually prefer to build a block I can feed to LAYOUT, but there are
times when that just isn't a good solution.
; Build a layout block dynamically
buttons: [ ; << could be loaded from a file
open "Open" [print "Open"]
close "Close" [print "Close"]
save "Save" [print "Save"]
]
block: copy [
size 150x200
]
foreach [name text action] buttons [
append block reduce [
to set-word! join 'b- name 'button text action
]
]
view layout block
;========================================================
; Add faces dynamically at runtime
count: 0
view lay: layout [
size 150x400
button "Add Button" [
f: make face append second get-style 'button [state: off]
count: count + 1
f/text: join "Button " count
set to word! join 'b- count f
f/action: reduce ['print f/text]
f/offset: to pair! reduce [20 add 30 count * 30]
append lay/pane f
show lay
]
]
HTH!
-- Gregg