支持多个面创建的VID布局窗格[rebol2] 请考虑这个简单的ReBOR2代码来说明我的问题: REBOL [] a: make face [ offset: 0x0 color: yellow size: 20x20 ] b: make face [ offset: 0x0 color: red size: 60x60 pane: reduce [ make a [offset: 0x0] make a [offset: 10x10] make a [offset: 10x20] ] ] view layout [ box 200x200 white with [ pane: reduce [ make b [offset: 0x30] ;; one 'instance' of b ] ] ]

支持多个面创建的VID布局窗格[rebol2] 请考虑这个简单的ReBOR2代码来说明我的问题: REBOL [] a: make face [ offset: 0x0 color: yellow size: 20x20 ] b: make face [ offset: 0x0 color: red size: 60x60 pane: reduce [ make a [offset: 0x0] make a [offset: 10x10] make a [offset: 10x20] ] ] view layout [ box 200x200 white with [ pane: reduce [ make b [offset: 0x30] ;; one 'instance' of b ] ] ],rebol,rebol2,Rebol,Rebol2,这里的要点是布局(或面)能够在其窗格块内显示一组面,这样就可以创建同一个面(b)。显示的代码运行良好,b的唯一实例(让我这样称呼它)按其应有的方式显示 但是现在假设我更改了代码,所以我有两个b: view layout [ box 200x200 white with [ pane: reduce [ make b [offset: 0x30] make b [offset: 0x10] ] ] ]

这里的要点是布局(或面)能够在其窗格块内显示一组面,这样就可以创建同一个面(
b
)。显示的代码运行良好,
b
的唯一实例(让我这样称呼它)按其应有的方式显示

但是现在假设我更改了代码,所以我有两个
b

view  layout [
    box 200x200 white with [
        pane: reduce [
            make b [offset: 0x30]
            make b [offset: 0x10]
        ]
    ]
]
在这一点上,我得到了错误

** Script Error: Face object reused (in more than one pane): none
** Where: view
** Near: show scr-face
if new [do-events]
从这条信息中,我推测face
b
不知何故被重用了,并且完全破坏了我想要实现的目标。我对此做了很多研究,在某一点上,我发现可以通过克隆(使用
make
)将要传递给
窗格的面来绕过它;那是我以为我在做的,但没有成功

考虑到这种情况,我的问题是:我如何着手解决这个问题?rebol2可以提供这个“面实例化”吗?或者最好尝试rebol2之外的其他东西(可能是rebol3)


任何帮助都将不胜感激。

Rebol2绝对可以这样做

当您第二次使用b时,您使用的是a的同一个实例。这就是问题所在

您可以编写一个函数,创建必要的面并将其附加到块中,然后返回。 别忘了每次都创建“第一张脸”

此外,检查文档中的迭代面

这里我添加了一个示例:

REBOL []
make-pane: func [ofst [pair! block!] /local a b faces] [
    a: make face [
        offset: 0x0
        color: yellow
        size: 20x20
    ]
    faces: copy []
    either block? ofst [
        foreach o ofst [
            append faces make a [offset: o]
        ]
    ] [
        append faces make a [offset: ofst]
    ]
    b: make face [
        offset: 0x0
        color: red
        size: 60x60
        pane: faces
    ]
]

view  layout [
    box 200x200 white with [
        pane: make-pane [5x30 0x10 20x5]
    ]
]

您可以更改函数以获得更多参数来更改颜色和其他方面。

我在评论中说过,我会回来分享我的发现,我想我得到了一些有趣的东西。正如@endo64所指出的,迭代面很棘手,可能不适合我第一次提出问题时打算做的事情——实现通过面板实例化对象的简单/straigthforward方法

我提出了下面的代码,它实现了一种实例化器。它的部分灵感来自@endo64的面部制作方法,以及对迭代面部的一些修补。此实例化器有一个核心限制,即不接受传递给构造函数的多种类型的对象在同一窗格中创建

无论如何,我发现这是一个有趣的练习,我想把它贴在这里,以防它对某人有用


我使用了问题中相同的代码,现在解决了/绕过了在主布局窗格中创建多个
b
对象的限制
a
b
现在保存一个
实例化器
对象,该对象接收一个要在其窗格内创建的对象和一个位置块(成对偏移),对象应放置在该位置

a: make face [
    offset: 0x0
    color: yellow
    size: 30x20
]

b: make face [
    offset: 0x0
    color: red
    size: 100x100
    inst_b: _instantiator/new reduce a [10x10 10x70 80x80 30x30] ; instantiator here  
    pane: get in inst_b 'pane_function
]
实例化器代码为:


正如已经指出的,问题在于
a
是重用的,而不是
b

layout函数使用一个名为
init
的字段来处理类似的事情。据我所知,
init
首先绑定到面,然后在面本身实例化(至少部分实例化)之后,使用
do
调用

在这种情况下,我将在布局中使用
style
命令(仍然部分使用面对象
a

另一个与您的类似的替代方案是:

b: make face [
    offset: 0x0
    color: red
    size: 60x60
    init: [
        pane: reduce [
            make a [offset: 0x0]
            make a [offset: 10x10]
            make a [offset: 10x20]
        ]
    ]
]
view layout [
    box 200x200
    with [
        append init [
            pane: reduce [
                make b [ offset: 0x0 do init ]
                make b [ offset: 0x60 do init ]
            ]
        ]
    ]
 ]
注意,在这种情况下,
init
是在make子句中手动调用的。我不太清楚为什么需要它。 最后,一切都可以优雅地用风格来解决

view layout [
    style a box yellow 20x20
    style b panel red 60x60 [
        at 0x0 a   ; we can in this style use the just defined a style
        at 10x10 a
        at 10x20 a
    ]
    at 0x0 b
    at 0x60 b
]

感谢您提供的示例代码和伟大的见解,特别是在迭代面上。我目前正在研究这些,我认为(从我目前所读到的)更适合我。为了研究分享的缘故,我打算在回复帖子中转转一下,然后返回我写的任何代码。再次感谢:数字化的脸有点难以使用,而且没有足够的文字说明。但它对网格/表格样式的UI元素很有用;更改了我接受的答案,尽管您的答案为我提供了很好的见解。第二种方法最适合我的问题,并且对于我接下来打算使用此代码构建的内容来说,它是直接/透明的。谢谢你的发帖:D
view layout [
    style
        bb box 60x60
        with [
            append init [
                pane reduce [
                    make a [offset: 0x0]
                    make a [offset: 10x10]
                    make a [offset: 10x20]
               ]
            ]
        ]
    panel 200x200 white [
        at 30x0 bb
        at 0x0  bb
    ]
]
b: make face [
    offset: 0x0
    color: red
    size: 60x60
    init: [
        pane: reduce [
            make a [offset: 0x0]
            make a [offset: 10x10]
            make a [offset: 10x20]
        ]
    ]
]
view layout [
    box 200x200
    with [
        append init [
            pane: reduce [
                make b [ offset: 0x0 do init ]
                make b [ offset: 0x60 do init ]
            ]
        ]
    ]
 ]
view layout [
    style a box yellow 20x20
    style b panel red 60x60 [
        at 0x0 a   ; we can in this style use the just defined a style
        at 10x10 a
        at 10x20 a
    ]
    at 0x0 b
    at 0x60 b
]