开发者

How do I get the radio button value in Rebol?

I tried this but colors is unknown (I searched a开发者_开发知识库ll over internet amazingly not one single person has documented it !):

V: view layout [
    across
    label "Colours:"
    r: radio of 'colours l: label "Red" 
    radio of 'colours label "Green" 
    radio of 'colours label "Blue"
    return
    label "Fruits:"
    radio of 'fruits label "Apples"
    radio of 'fruits label "Oranges"
    button "close" [unview]
]

probe colors


I believe radio buttons were designed that you named and checked each button:

mycolours: view layout [
    red: radio of 'colours label "Red"
    green: radio of 'colours label "Green"
    blue: radio of 'colours label "Blue"
]

probe red/data
probe green/data
probe blue/data

To get the answer from the word 'colours, you will have to iterate through faces to find faces with that relationship. Here's a quick and dirty iterator (walk-vid):

walk-vid: use [level] [
    level: 0

    func [
        [catch]
        face [object!]
        callback [function!]
        /deep
    ][
        if not in face 'pane [
            throw make error! "Not a face"
        ]

        either deep [
            level: level + 1
        ][
            level: 0 bind second :callback 'level
        ]

        do [callback face]

        case [
            block? face/pane [
                foreach pane face/pane [
                    walk-vid/deep pane :callback
                ]
            ]

            object? face/pane [
                walk-vid/deep face/pane :callback
            ]
        ]

        either deep [
            level: level - 1
        ][
            level: 0
        ]

        face
    ]
]

So, iterate through faces, find relationship, find the selected face. Let's make a function for that:

which-radio: func [
    face [object!]
    group [word!]
    /local selected
][
    walk-vid face func [face] [
        all [
            face/related == group
            face/data
            selected: face
        ]
    ]

    selected
]

Thus to wrap up:

probe which-radio mycolours 'colours

To make life easier, you can add a face/text value to the radio button (labels are not bound to the button):

radio of 'colours "Red" label "Red"


VID dialect does not provide such feature out of the box, but it is easy to add.

REBOL []

stylize/master [
    radio: radio with [
        get-all: has [list][
            if related [
                list: make block! 3
                foreach item parent-face/pane [
                    all [
                        item/related
                        item/related = related
                        append list to-logic item/data
                    ]
                ]
                list
            ]
        ]
    ]
]

view layout [
    across
    label "Colours:"
    r: radio of 'colours l: label "Red" 
    radio of 'colours label "Green" 
    radio of 'colours label "Blue"
    return
    label "Fruits:"
    f: radio of 'fruits label "Apples"
    radio of 'fruits label "Oranges"
    button "close" [unview]
]

print ["colours:" mold r/get-all]
print ["fruits:" mold f/get-all]

Supposing you want to alter all radio button styles, else you would need to remove /master refinement.


In R3GUI radio buttons are grouped by proximity, and you can get their values by naming each button.

view [ 
   r1: radio "one"
   r2: radio "two"
   r3: radio "three"
   button "show" on-action [ print get-face reduce [ r1 r2 r3 ]]
]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜