VID或R3-Gui中的文本和插入符号

时间:2015-02-16 16:30:31

标签: rebol rebol3 r3-gui

一个简单的例子:

如果我输入#" w"在风格"区域"我如何获得#" z"? (例如," qwerty ww" - >" qzerty zz")

2 个答案:

答案 0 :(得分:2)

如果您想要即时转换,您可以在加载前修改R3-GUI。因此,将r3-gui.r3加载到本地目录。然后你添加行,如果键==#" w" [键:#" z"] 到函数 do-text-key ,所以它看起来像

do-text-key: funct [
  "Process text face keyboard events."
  face [object!]
  event [event! object!]
  key
] [
  text-key-map/face: face
  text-key-map/shift?: find event/flags 'shift
  if no-edit: not tag-face? face 'edit [
    key: any [select/skip text-key-map/no-edit key 2 key]
  ]
  either char? key [
    if key == #"w" [key: #"z"]
    text-key-map/key: key
    switch/default key bind text-key-map/chars 'event [
      unless no-edit [
          insert-text-face face key
      ]
    ]
  ] [
    if find event/flags 'control [
      key: any [select text-key-map/control key key]
    ]
      text-key-map/key: key
      switch/default key text-key-map/words [return event]
  ]
  none
]

可能官方的方式是使用 on-key 和Rebol3

load-gui
view [
  a: area  on-key [ ; arg: event
     if arg/type = 'key [
        if  arg/key == #"w" [arg/key:  #"z"]
     ]
     do-actor/style face 'on-key arg face/style
  ]
]

最后一种方法是使用Rebol2动态执行此操作

key-event: func [face event] [
    if event/type = 'key [ 
        if all [event/key = #"w"   ] [
            append a/text  #"z" 
            focus a
            view w 
           return false
        ]
    ] 
    event 
] 
insert-event-func :key-event        

view w: layout [
    a: area 
]

答案 1 :(得分:2)

在阅读r3-gui(text-caret.r3,text-cursor.r3,text-edit.r3,text-keys.r3,text.r3)和editor的一些文件后,我找到了一个解决方案,它不仅可以插入字符,还可以插入字符串:

do %r3-gui.r3

insertText-moveCursor-updateFace: func [
    face
    string
    n-move
][
    insert-text-face face string
    move-cursor face 'left n-move false 
    update-text-caret face 
    see-caret face
    show-later face
]   

i-m-u: :insertText-moveCursor-updateFace

view [
    area on-key [
        either arg/type = 'key [
            switch/default  arg/key [
                #"w" [i-m-u face/names/text-box "z" 0]
                #"[" [i-m-u face/names/text-box "[]" 1]
                #"$" [i-m-u face/names/text-box "func [] []" 4]
            ] [
                ;switch/default 
                do-actor/style face 'on-key arg face/style
            ]
        ] [
            ;arg/type != 'key
            do-actor/style face 'on-key arg face/style
        ]   
    ]   
]

区域是复合样式。它由文本框滚动条组成。它们包含在 face / names

相关问题