[英]Why Rebol engage doesn't work?
I have added keyboard event but none is detected why ? 我添加了键盘事件,但是没有检测到为什么?
plot: [
pen green line 5x404 5x440 pen gold fill-pen 0.255.0 box 3x424 7x418 line 10x396 10x422 pen gold fill-pen 0.255.0 box 8x418 12x402 line 15x397 15x436 pen gold fill-pen 255.0.0 box 13x401 17x435 line 20x429 20x447 pen gold fill-pen 255.0.0 box 18x434 22x446 line 25x441 25x464 pen gold fill-pen 255.0.0 box 23x446 27x463 line 30x445 30x493 pen gold fill-pen 255.0.0 box 28x461 32x482 line 35x470 35x504 pen gold fill-pen 255.0.0 box 33x481 37x492 line 40x466 40x498 pen gold fill-pen 0.255.0 box 38x491 42x477
]
grid: [1100 600]
step-grid: 5
max-n-points: (grid/1 / step-grid) - 1
x-axis-border: 20
Y-margin: 10
X0: 5
grid-color: coal
main: layout [
origin 20x0
space 1x1
panel1: box 1100x580 black effect reduce [
'line-pattern 4 4
'grid 30x30 0x0 (grid-color)
'draw plot
] feel [
engage: func [face action event] [
if action = 'down [drag-start: event/offset]
if action = 'up [drag-end: event/offset
scroll-size: to-integer abs ((pick (drag-start - drag-end) 1) / 5)
]
if action = 'key [
probe event/key
either word? event/key [
probe event/key
if (event/key = 'left) [
probe event/key
]
if (event/key = 'right) [
probe event/key
]
][
]
]
]
]
panel2: box 1100x0 black
panel3: box 1100x20 black
]
view main
focus panel1
A: simple, the engage feel only triggers for key events when the face is the focal-face. 答:很简单,只有当脸部是焦面时,接合感才会触发关键事件。
here is a partial rewrite of your app (faster and more readable too) which uses a global event handler and 'SWITCHes instead of 'IFs. 这是使用全局事件处理程序和'SWITCHes而不是'IFs的应用程序的部分重写(也更快,更易读)。
The input handler is fed ALL events of ALL windows, and can be used to do global tricks like hotkeys. 输入处理程序被馈送所有窗口的ALL事件,并可用于执行诸如热键之类的全局技巧。
obviously, you can improve the event-handler to detect per window, and detect where the mouse is located to only enable keys when appropriate. 显然,您可以改进事件处理程序以检测每个窗口,并检测鼠标的位置以仅在适当的时候启用键。 you could also build an alternate focus tracking that works outside of the usual handling and which doesn't enter the text edit mode. 您还可以构建备用焦点跟踪,该跟踪可以在常规处理方式之外运行,并且不会进入文本编辑模式。
I added a field above, just so you can experiment with the effect of having a focused face active and how to detect it in your event-handler. 我在上面添加了一个字段,以便您可以试验一下激活聚焦的面部的效果以及如何在事件处理程序中对其进行检测。
rebol []
plot: []
data: reduce [ ]
refresh: func [/local clr delta prev-pos pos] [
clear plot
prev-pos: 0x300
foreach [clr delta] data [
pos: prev-pos + (delta * 0x1) + 7x0
append plot compose [
pen (clr) line (prev-pos) (pos) fill-pen (clr) pen none circle dot-size (pos)
]
prev-pos: pos
]
show panel1
]
add-data: func [i][loop i [append data reduce [(random white * .85) + (white * .15) (-20 + random 40)]] refresh]
grid: [800 600]
step-grid: 5
max-n-points: (grid/1 / step-grid) - 1
x-axis-border: 20
Y-margin: 10
X0: 5
grid-color: coal
dot-size: 1
; open up console before vid window
prin "!"
main: layout [
origin 20x0
space 1x1
field 800
panel1: box 800x580 black effect [
line-pattern 4 4
grid 30x30 0x0 grid-color
draw plot
] feel [
engage: func [face action event] [
switch action [
down [
drag-start: event/offset
]
up [
drag-end: event/offset
scroll-size: to-integer abs ((pick (drag-start - drag-end) 1) / 5)
]
]
]
]
panel2: box 800x0 black
panel3: box 800x20 black
]
insert-event-func [
either all [
event/type = 'key
none? system/view/focal-face
][
print ["shortcut: " event/key]
switch event/key [
; escape
#"^[" [quit]
; enter/return
#"^M" [print "resampling data" clear data add-data 100]
up [dot-size: dot-size + 1 show panel1]
down [dot-size: dot-size - 1 show panel1]
left [clear skip tail plot -12 clear skip tail data -2 show panel1]
right [add-data 2]
]
none
][
event
]
]
add-data 100
refresh
view main
focus panel1
Note that there is no need to reduce your code block when you use words within. 请注意,在其中使用单词时,无需减少代码块。 VID automatically resolves word references for you, its a lot easier (and dramatically faster) to make dynamic GUIs once you know this. VID会自动为您解析单词参考,一旦您知道了这一点,它就很容易(而且显着更快)来制作动态GUI。 as a proof, hold down the up or down arrow key, and you'll see the dots resize quite smoothly, even on a full graph. 作为证明,按住向上或向下箭头键,即使在完整的图形上,您也会看到点的大小调整非常平滑。
Also note the return value of event-handler func is the event, if you want view to continue handling the event, or none, if your handler "consumes" the event. 还要注意,如果希望视图继续处理事件,则事件处理程序函数的返回值是事件,或者如果处理程序“使用”该事件,则返回无。
HTH! HTH!
I tried insert-event-func with dummy func and my own example above I fail to see why it doesn't work: 我尝试了使用哑光func和我上面的示例的insert-event-func,但看不到为什么它不起作用:
plot: [
pen green line 5x404 5x440 pen gold fill-pen 0.255.0 box 3x424 7x418 line 10x396 10x422 pen gold fill-pen 0.255.0 box 8x418 12x402 line 15x397 15x436 pen gold fill-pen 255.0.0 box 13x401 17x435 line 20x429 20x447 pen gold fill-pen 255.0.0 box 18x434 22x446 line 25x441 25x464 pen gold fill-pen 255.0.0 box 23x446 27x463 line 30x445 30x493 pen gold fill-pen 255.0.0 box 28x461 32x482 line 35x470 35x504 pen gold fill-pen 255.0.0 box 33x481 37x492 line 40x466 40x498 pen gold fill-pen 0.255.0 box 38x491 42x477
]
grid: [1100 600]
step-grid: 5
max-n-points: (grid/1 / step-grid) - 1
x-axis-border: 20
Y-margin: 10
X0: 5
grid-color: coal
main: layout [
origin 20x0
space 1x1
panel1: box 1100x580 black effect reduce [
'line-pattern 4 4
'grid 30x30 0x0 (grid-color)
'draw plot
] feel [
engage: func [face action event] [
if action = 'down [drag-start: event/offset]
if action = 'up [drag-end: event/offset
scroll-size: to-integer abs ((pick (drag-start - drag-end) 1) / 5)
]
]
]
panel2: box 1100x0 black
panel3: box 1100x20 black
]
insert-event-func [
either all [
event/type = 'key
none? system/view/focal-face
][
print ["shortcut: " event/key]
switch event/key [
; escape
#"^[" [quit]
; enter/return
#"^M" [print "resampling data" clear data add-data 100]
up [print "up"]
down [print "down"]
left [print "left"]
right [print "right"]
]
none
][
event
]
]
view main
focus panel1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.