如何获取Rebol中的单选按钮值?

时间:2011-06-19 08:55:45

标签: rebol

我尝试了这个,但颜色是未知的(我在网上搜索得非常惊人,没有一个人记录过它!):

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

3 个答案:

答案 0 :(得分:2)

我相信单选按钮的设计是你命名并检查每个按钮:

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

要从“颜色”这个词中得到答案,你必须通过面部迭代才能找到具有这种关系的面孔。这是一个快速而又脏的迭代器(walk-vid):

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

    func [[catch] face [object!] callback [function!] /deep][
        unless 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
    ]
]

因此,遍历面孔,找到关系,找到所选面部。让我们为此做一个函数:

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

这样结束:

probe which-radio mycolours 'colours

为了让生活更轻松,您可以将面/文本值添加到单选按钮(标签未绑定到按钮):

radio of 'colours "Red" label "Red"

答案 1 :(得分:0)

VID方言不提供开箱即用的功能,但很容易添加。

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]

假设您要更改所有单选按钮样式,否则您需要删除 / master 细化。

答案 2 :(得分:0)

在R3GUI中,单选按钮按接近程度分组,您可以通过命名每个按钮来获取它们的值。

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