[REBOL] AW: Re: When to define words
From: moeller_thorsten:gmx at: 10-Jul-2001 12:09
Hi Brett,
thanks for your detailed response.
One small question to your sample which works fine (only second one, first
has an error, but doesn't matter)!
Where in this code can i set the offset for the sublayout in your function?
Thorsten
-----Ursprüngliche Nachricht-----
Von: [rebol-bounce--rebol--com] [mailto:[rebol-bounce--rebol--com]]Im Auftrag
von Brett Handley
Gesendet: Dienstag, 10. Juli 2001 02:34
An: [rebol-list--rebol--com]
Betreff: [REBOL] Re: When to define words
Hi Thorsten,
Comments below
> layout2: layout [ H2 "second layout"
> button "Sub" coal [sublayout/pane: sublayout-input show sublayout]
> sublayout: box 300x300 coal
> ]
>
> login: layout [ H2 "first layout"
> label "Input: " myfield: field
> button "go" [unview/all view layout2]
> ]
>
> sublayout-input: layout [ H2 "Sublayout"
> backcolor red
> txt join "Input:" myfield/text
> ]
When the Rebol interpreter has finished evaluating up to this point you will
have created a layout with a TXT on it
that has had it's /text already set - in fact to an empty string. What I
mean is, myfield/text has been evaluated - and it will not be evaluated
again.
> view login
>
> In this sample i didn't get the error, but the sublayout didn't show the
input as well.
You need some code that sets the TXT but only after the input has been
entered.
> Hope it comes clear what i was asking for.
I think so. So repeating myself you need something that will communicate the
user inputted text to the other sublayout.
One way would be to have one sublayout talk directly to the other. This
might be fine in a one off small program, but in a
bigger program it might be hard to understand what is happening.
Another way is to create a common point of reference for the two sublayouts
to access. Given that you user data is very likely to be used in other parts
of the program all you need is a global word or an object to set. Like this
; Somewhere to store our data
user-data: context [
user-input: none
]
layout2: layout [
H2 "second layout"
button "Sub" coal [
input-display/text: user-data/user-input
sublayout/pane: sublayout-input
show sublayout
]
sublayout: box 300x300 coal
]
login: layout [
H2 "first layout"
label "Input: " myfield: field [
; The user entered something - keep track of it
user-data/user-input: myfield/text
]
button "go" [unview/all view layout2]
]
sublayout-input: layout [
H2 "Sublayout"
backcolor red
input-display: txt join "Input:"
]
view login
That solve's the problem but for this example there is a little more we can
do.
For this example, sublayout-input doesn't change once it has the correct
input text set on it. So with that knowledge
we could create it only when we need it. Like this:
; Somewhere to store our data
user-data: context [
user-input: none
]
; A function to create the sublayout when needed
displaysub-layout2: does [
sublayout-input: layout compose [
H2 "Sublayout"
backcolor red
txt join "Input:" (user-data/user-input)
]
sublayout/pane: sublayout-input
show sublayout
]
layout2: layout [
H2 "second layout"
button "Sub" coal [ displaysub-layout2 ]
sublayout: box 300x300 coal
]
login: layout [
H2 "first layout"
label "Input: " myfield: field [
; The user entered something - keep track of it
user-data/user-input: myfield/text
]
button "go" [unview/all view layout2]
]
view login
So this bit of code shows how VID code can be treated as data to be
manipulated until you actually need it displayed.
And to make things clearer I've moved complex code out of the button into a
seperate function.
HTH
Brett.