我想动态地在视图布局中添加一个按钮,其中演员导致此添加属于已经是布局一部分的按钮。
我从这开始:
REBOL [title: "Dynamic Button Addition"]
tilesize: 60x60
curtile: 1
stylize [
p: button [
facets: [init-size: tilesize max-size: tilesize]
actors: [
on-action: [
++ curtile
append tiles compose [ p (to-string curtile) ]
print ? tiles/options/content
v/redraw
]
]
]
]
v: [
tiles: hgroup [ p "1" ]
]
view v
...每次点击似乎都没有tiles/options/content
的值。
如果进行这些更改,我可以改变它:
append tiledata compose [ p (to-string curtile) ]
和
tiledata: [ p "1" ]
v: [
tiles: hgroup tiledata
但是,这不会导致屏幕上的任何更改。如果我用这个替换最后四行:
v: view [
tiles: hgroup tiledata
]
...以便v
现在是视图而不是视图的布局,当我点击时出现此错误:
** Script error: v has no value
** Where: actor all foreach do-actor unless do-face if actor all foreach do-actor if do-event do-event if do-event either -apply- wake-up loop -apply- wait forever try do-events if view do either either either -apply-
** Near: actor face :data
这对我来说很有意义,因为v
尚未定义,直到我退出程序IIUC。
如何在程序结束之前对v
进行更改,但在将其传递给view
之后?
答案 0 :(得分:1)
不是很好,但如果你更换
就可以了 v/redraw
这两行
unview/all
view v
how to update a layout that has already be viewed
上有一个真实的动态示例我会简化它
stylize [
tbox: hpanel [
actors: [
on-make: [
append face/options [
content: [
]
]
do-actor/style face 'on-make none 'hpanel
]
]
]
]
view/across [
button "button 1"
on-action [
append-content test compose [
button ( join "button " 2 + length? test/gob)
]
]
test: tbox
]