Dynamic Layout creation
[1/10] from: riusa::email::it at: 15-Mar-2002 17:24
After some tests, I discovered I could create a block (dinamically, at
runtime) and use this to create a layout.
For example: if I want to create some radio buttons at runtime (I'm
reading some records in a database, and every record generates a radio
button), I can create a block and...
==================================
myBlock: [backcolor gray across]
append myBlock [radio label "test"]
view layout myBlock
==================================
the previous code functions. But how can I do to assign a different
variable to every radio-button (see the hypotetical result below):
var1: radio label "test 1" return
var2: radio label "test 2" return
var3: radio label "test 3" return
I cannot create var...
Can someone help me?
Thanks! bye!
--
Prendi GRATIS l'email universale che... risparmia: http://www.email.it/f
Sponsor:
Il simbolo della rete ha compiuto da poco i 450 anni;
Ordina il tuo portafortuna su Airbook.it!
Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=347&d=15-3
[2/10] from: ingo:2b1 at: 15-Mar-2002 21:08
Hi,
Am Fre, 2002-03-15 um 17.24 schrieb [riusa--email--it]:
> After some tests, I discovered I could create a block (dinamically, at
> runtime) and use this to create a layout.
<...>
> But how can I do to assign a different
> variable to every radio-button (see the hypotetical result below):
>
> var1: radio label "test 1" return
> var2: radio label "test 2" return
> var3: radio label "test 3" return
>
> I cannot create var...
I'm sure someone will come up with some better ideas, but this should
give you some ideas:
>> b: []
== []
>> for i 1 10 1 [
append b compose [
(to-set-word join "var" i) text (join "var" i)
]
]
== [var1: text "var1" var2: text "var2" ... ]
>> view layout b
>> var2/text
== "var2"
I hope that helps
Ingo
[3/10] from: sunandadh:aol at: 15-Mar-2002 13:45
[riusa--email--it] writes:
> the previous code functions. But how can I do to assign a different
> variable to every radio-button (see the hypotetical result below):
I don't know how to do it directly, but the approach I would use is to
collect them in a block via a temporary variable, using DO i the layout.
After the layout is executed you can do what you like with the block - though
don't try to print it -- it's full of vid objects and will take a while.
This code may make as much sense as the explanation...
-------
myBlock: [backcolor gray across]
myvars: copy []
loop 10 [
append myBlock [temp: radio label "test"
do [append myvars temp]
] ;; append
] ;; loop
unview/all
view/new layout myBlock
;; now you can manipulate the faces directly, eg
;; set every 2nd radio button true
for nn 1 length? myvars 2 [
myvars/:nn/data: true
show myvars/:nn
]
;; or extract them into variables --
;; (as per an earlier thread, this puts
;; them into an object -- you can automate
;; this code a bit more, especially the object
;; definition)
myobj: make object! [var1: "" var2: "" var3: "" var4: "" var5: ""
var6: "" var7: "" var8: "" var9: "" var10: ""]
for nn 1 length? myvars 1 [
set in myobj to-word join "var" nn myvars/:nn]
;; and then mess with them in the object
myobj/var2/data: true
show myobj/var2
-----------
Sunanda
[4/10] from: ryanc:iesco-dms at: 15-Mar-2002 10:31
You can do that by generating set-words, like so...
repeat num 5 [
append myBlock to-set-word join 'rad num: num + 1
]
But I dont find that too elegant myself. I would do it this way...
repeat num 5 [
repend myBlock ['radio 'user-data num [radio-selected: face/user-data]]
]
It will make your next step easier.
--Ryan
[riusa--email--it]
wrote:
[5/10] from: riusa:email:it at: 16-Mar-2002 0:15
furthermore, about my previous question, I "discovered" another thing:
if I type, from console:
>> A: "b1: button {prova}"
== "b1: button {prova}"
then:
>> la: to-block a
== [b1: button "prova"]
now if I try to make a layout:
>> view layout la
** Script Error: b1 is not defined in this context
** Where: forever
** Near: set :var new new/var: to-word
but if I directly type the block (not write in string then convert):
>> lb: [b1: button "prova"]
== [b1: button "prova"]
>> view layout lb
It works! WHY?! "la" and "lb" seem the same! where is the difference?
where is my mistake?
thanks a lot!
bye!
-----Messaggio originale-----
Da: [rebol-bounce--rebol--com] [mailto:[rebol-bounce--rebol--com]]Per conto di
[riusa--email--it]
Inviato: Friday, March 15, 2002 5:25 PM
A: [rebol-list--rebol--com]
Oggetto: [REBOL] Dynamic Layout creation
After some tests, I discovered I could create a block (dinamically, at
runtime) and use this to create a layout.
For example: if I want to create some radio buttons at runtime (I'm
reading some records in a database, and every record generates a radio
button), I can create a block and...
==================================
myBlock: [backcolor gray across]
append myBlock [radio label "test"]
view layout myBlock
==================================
the previous code functions. But how can I do to assign a different
variable to every radio-button (see the hypotetical result below):
var1: radio label "test 1" return
var2: radio label "test 2" return
var3: radio label "test 3" return
I cannot create var...
Can someone help me?
Thanks! bye!
--
Prendi GRATIS l'email universale che... risparmia: http://www.email.it/f
Sponsor:
Il simbolo della rete ha compiuto da poco i 450 anni;
Ordina il tuo portafortuna su Airbook.it!
Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=347&d=15-3
--
To unsubscribe from this list, please send an email to
[rebol-request--rebol--com] with "unsubscribe" in the
subject, without the quotes.
--
Prendi GRATIS l'email universale che... risparmia: http://www.email.it/f
Sponsor:
Puglia Pocket: le ultime notizie, gratis, sul tuo sito; devi solo prenderlo
Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=314&d=16-3
[6/10] from: carl:cybercraft at: 16-Mar-2002 11:53
On 16-Mar-02, [riusa--email--it] wrote:
> After some tests, I discovered I could create a block (dinamically,
> at runtime) and use this to create a layout. For example: if I want
<<quoted lines omitted: 12>>
> I cannot create var...
> Can someone help me?
Hi,
use 'to-set-word to create a set word, which I think is what you're
after. Example...
rebol []
lo: [
across
]
for n 1 3 1 [
append lo to-set-word join "var" n
append lo [
radio [show-data]
label
]
append lo join "Test " n
append lo to-set-word join "var-data" n
append lo [field return]
]
show-data: does [
var-data1/text: var1/data
var-data2/text: var2/data
var-data3/text: var3/data
show [var-data1 var-data2 var-data3]
]
view layout lo
HTH.
--
Carl Read
[7/10] from: carl:cybercraft at: 16-Mar-2002 15:02
On 16-Mar-02, Alessandro Manotti wrote:
> furthermore, about my previous question, I "discovered" another
> thing: if I type, from console:
<<quoted lines omitted: 14>>
> It works! WHY?! "la" and "lb" seem the same! where is the
> difference? where is my mistake?
Hi Alessandro,
I know a solution to making 'la work. Try...
view layout load la
But I'll leave it up to someone else to explain why 'load makes it
work. I assume it's something to do with "Binds words to global
context." as mentioned with 'load's help...
>> ? load
USAGE:
LOAD source /header /next /library /markup /all
DESCRIPTION:
Loads a file, URL, or string. Binds words to global context.
LOAD is a native value.
And don't worry - I scratched my head over the first time I saw 'load
used like this as well. (:
--
Carl Read
[8/10] from: brett:codeconscious at: 16-Mar-2002 15:52
Hi,
> I assume it's something to do with "Binds words to global
> context." as mentioned with 'load's help...
Sounds right to me.
If you want the TO-BLOCK method to work you can use BIND explicitly
like this:
A: "b1: button {prova}"
la: to-block a
b1: none ; (A)
bind la 'b1 ; (B)
view layout la
>> b1/text
== "prova"
or perhaps like this:
A: "b1: button {prova}"
la: to-block a
obj-a: context [b1: none]
view layout la
>> obj-a/b1/text
== "prova"
In these cases b1 is assigned a context.
In the first example B1 is part of the global context (like what LOAD
does). Note that the line marked (A) is actually unnecessary. I left it
there because I wanted to draw attention to what B1: in the block will
be bound to. In fact the 'B1 on line (B) creates a word B1 in the
global context anyway - so you can remove line (A) and the first
example still works. Line (B) then binds the B1: inside the block to
the global context.
In the second example the B1: is bound to an object context.
Regards,
Brett.
[9/10] from: brett:codeconscious at: 16-Mar-2002 15:55
Oops. Cut and paste glitch in my last email. The second example should look
like:
A: "b1: button {prova}"
la: to-block a
obj-a: context [b1: none]
bind la in obj-a 'self
view layout la
The comments still stand.
Brett.
[10/10] from: riusa:email:it at: 24-Mar-2002 17:43
Thanks to everyone!
I learned a new function: to-set-word and its family!
however, I think the fastest way is to use "LOAD" function.
I can simply create a block, append to it everythink I need, and then load
it and view (view layout load myVar).
I need much time to implement the solution with "bind", since I must bind
every variable contained in the block, instead "load" makes it
automatically.
thank you. bye!
(I made a new little step to become a Rebol expert!)
--
Prendi GRATIS l'email universale che... risparmia: http://www.email.it/f
Sponsor:
Le maglie con il numero e il nome dei tuoi campioni, sono sul Milanstore
Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=313&d=24-3
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted