rebol

How do I get the radio button value in Rebol?


I tried this but colors is unknown (I searched all 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

Solution

  • 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"