Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VID layout pane supporting multiple face creations [rebol2]

Tags:

rebol

rebol2

Please consider this simple rebol2 code to illustrate my problem:

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
        ]
    ]
]

The main point here is for a layout (or face) to be able to display a bunch of faces inside its pane block in such a manner that multiple creations of the same face (b in this case) should be possible. The shown code works well, and the only instance (let me call it this way) of b is displayed as it should be.

But now suppose I change the code so I have, say, 2 instances of b:

view  layout [
    box 200x200 white with [
        pane: reduce [
            make b [offset: 0x30]
            make b [offset: 0x10]
        ]
    ]
]

At this point I get the error

** Script Error: Face object reused (in more than one pane): none
** Where: view
** Near: show scr-face
if new [do-events]

From the message I presume here that face b is somehow getting reused and messing exactly what I'm trying to achieve. I've done lots of research on this and at some point I found that it is possible to get around it by cloning (using make) the face to be passed to pane; that's what I thought I was doing, but with no success at all.

Given this scenario, my question is: how can I go about to solve this? is rebol2 ok to provide this "face-instantiation" or it is best to try something else outside rebol2 (perhaps rebol3)?

Any help will be greatly appreciated.

like image 849
rdonatoiop Avatar asked Sep 29 '22 03:09

rdonatoiop


1 Answers

Rebol2 is definitely ok to do this.

When you MAKE b second time you are using the same instance of a. That is the problem.

You can write a function that creates necessary faces and append them to a block and return. Don't forget to create 'a (first face) every time.

Additionally, check for the iterated faces in the documentation.

Here I added an example:

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]
    ]
]

You can change the function to get more parameters to change color and other facets as well.

like image 110
endo64 Avatar answered Dec 28 '22 02:12

endo64