REBOL 3 - How to update a layout that has already

2019-07-01 17:47发布

问题:

I'm trying to add a field to a layout after it has been viewed

view/no-wait m: [field "hello"]
insert tail m 'field
insert tail m "hello"
update-face m
** Script error: update-face does not allow block! for its face argument

I want to update the whole layout, not just the field or some part of it. If I try to use view m, it opens a new window. Do I just have to un-view it and then view again?

回答1:

You can use the LAYOUT function in R3-GUI as well. See the example below:

view/no-wait m: layout [field "hello"]

;We need to get the BACKDROP container which is first sub-face in the WINDOW face
m: first faces? m

append-content m [
    field "world"
]

do-events

Ofcourse there are also other ways how to handle layout content dynamically.



回答2:

Try this example from Richard

REBOL [
    Title: "Layouts example #20"
    Author: "Richard Smolak"
    Version: "$Id: layouts-20.r3 852 2010-10-07 13:28:26Z cyphre $"
]

stylize [

    tbox: hpanel [

        about: "Simple rectangular box."

        facets: [
            init-hint: 200x200
            min-hint: 0x0
            max-hint: guie/max-pair
            break-after: 1
        ]

        options: [
            init-hint: [pair!]
        ]

        actors: [
            on-make: [
                append face/options [
                    content: [
                        button "hello" on-action [print "hello"]
                        button "world" on-action [print "hello"]
                    ]
                ]
                do-actor/style face 'on-make none 'hpanel
            ]
        ]

        draw: [
            pen red
            fill-pen blue
            box 0x0 (viewport-box/bottom-right - 1)
        ]
    ]
]


view [
    test: tbox
    button "clear"
        on-action [
            clear-content test
        ]   
    button "set"
        on-action [
            set-content test [
                button "test"
                field "the best"
            ]
        ]   
    button "insert"
        on-action [
            insert-content test bind/set probe reduce [to-set-word copy/part random "abcdefgh" 2 'button join "button #" 1 + length? test/gob] 'system
        ]
    button "append"
        on-action [
            append-content test reduce ['button join "button #" 1 + length? test/gob]
        ]   
    button "remove 2 faces at pos 3"
        on-action [
            remove-content/pos/part test 3 2
        ]
]

so the words you're looking for are append-content and insert-content which take a face and a block as parameters where the block contains the definition of another face.



回答3:

I don't know view yet, but I have a hint. The first line sets "m" to the block [field "hello"]. Check to see what "update-face" expects...