In the following Rebol 2 code, why does button a
become visible 5 seconds after it's clicked, while remaining hidden 5 seconds after button b
is clicked?
f: does [hide a wait 5]
view layout [
a: button "a" [f]
b: button "b" [f]
]
In the following Rebol 2 code, why does button a
become visible 5 seconds after it's clicked, while remaining hidden 5 seconds after button b
is clicked?
f: does [hide a wait 5]
view layout [
a: button "a" [f]
b: button "b" [f]
]
It looks like a bug that
view layout [
a: button "hide me" [ hide face ]
b: button "hide a" [ hide a ]
]
doesn't work to hide the "a" button unless the hide is called from another button. Your wait 5 must be triggering an update of the layout so that the button disappears.
Instead of wait 5, using do-events (wait []) keeps the button hidden.
view layout [
a: button "hide me" [ hide face do-events ]
b: button "hide a" [ hide a ]
]
When each button is clicked, it is redrawn to look “pressed”, and stays “pressed” until its action
has completed. Then, after it's action
has completed, the button is redrawn as “unpressed”.
During button a
's action
, it is hidden, but when its action
is completed, it is shown again when it's “unpressed” state is drawn. According to this function summary of hide, hide
only “temporarily removes the face from view”, and “The face will become visible again the next time the face is shown either directly or indirectly through one of its parent faces.”
During button b
's action
, button a
is hidden, but when button b
's action
is completed, it is button b
that is redrawn as “unpressed”. At this point, button a
is untouched and remained hidden.
Considering Graham Chiu's code:
view layout [
a: button "hide me" [ hide face do-events ]
b: button "hide a" [ hide a ]
]
In this case, the reason why button a
remains hidden after being clicked, is that its action
doesn't reach completion until the window is closed. If wait 5
represents code which needs to be executed when the button is clicked, it needs to be put before do-events
. Otherwise it is not executed until the window is closed.
view layout [
a: button "hide me and print" [
hide face
print "I need to say this when clicked."
do-events
print "I can wait until the window is closed."
]
b: button "hide a" [ hide a ]
]
Some other ways to make a button hide itself can be found on this page under the subheading: “Hiding self”. For example:
view l: layout [b: button [b/show?: false unview/all view l]]