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

发布于 2024-11-15 21:45:21 字数 385 浏览 3 评论 0原文

我尝试了这个,但颜色未知(我在互联网上进行了搜索,令人惊讶的是没有一个人记录它!):

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

剩一世无双 2024-11-22 21:45:21

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

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

这 ,迭代人脸,查找关系,找到选定的人脸。让我们为此创建一个函数:

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"

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"
瞄了个咪的 2024-11-22 21:45:21

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 细化。

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.

西瓜 2024-11-22 21:45:21

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

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

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 ]]
]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文