Rebol 文本字段 - 检查值和改变颜色

Rebol text fields - checking values and changing colors

在下面的原型测试代码中,我试图创建一个比较系统来比较两个字段,并根据它们是否相等来给它们着色。

comparecolors: [
    either answer-user/text = answer-correct/text [
        answer-user/font/color: green
        answer-correct/font/color: green
        show answer-user
        show answer-correct
    ][
        answer-user/font/color: red
        answer-correct/font/color: black
        show answer-user
        show answer-correct
    ]
]

view layout [
    answer: field [
        answer-user/text: copy answer/text
        do comparecolors
        show answer
        focus answer
        show answer-user
    ]
    label "Compare"
    answer-user: info
    answer-correct: info
    across
    text-list "Hello" "Goodbye" "Boy" "Girl" "Soldier" [
        answer-correct/text: copy value
        do comparecolors
        show answer-correct
    ]
]

我遇到的一些问题:

当你看到多个字段在你只更改一个属性时受到影响,这意味着 VID 已经进行了优化,所有这些字段都共享相同的数据结构,并且在这个相同的字体结构中。因此,我们需要强制 VID 分配一个新的字体结构,如下所示:

change-colors: func [ user [object!] correct [object!]
    /local u c
 ][
    set [ u c ]  
    either user/text = correct/text [
        [ green green ]
    ][
         [ red black ]
    ]
    user/font/color: get u
    correct/font/color: get c
    show [ user correct ]   
]

view layout [
    answer: field [
        answer-user/text: copy answer/text
        change-colors answer-user answer-correct
        focus answer
    ] font-color black
    label "Compare"
    answer-user: info  font-color black
    answer-correct: info  font-color black
    across
    text-list "Hello" "Goodbye" "Boy" "Girl" "Soldier" [
        answer-correct/text: copy value
        change-colors answer-user answer-correct
    ]
]