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

时间:2015-08-30 19:13:15

标签: rebol

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

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

我遇到的一些问题:

  • 绿色会影响所有字段,而不仅仅是我指定的字段。
  • 当两个字段不相等时,红色不起作用。
  • 系统不会检查没有!价值(我知道它不是在上面的代码中写的,但我尝试了一些不起作用的方法,所以我真的不知道如何去做。)

1 个答案:

答案 0 :(得分:4)

每当您在仅更改一个属性时看到多个字段受到影响时,这意味着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
    ]
]