[REBOL] speed up view
From: rotenca::telvia::it at: 4-Jul-2002 19:58
This little hack to speed up view.
I think that something like this should be present at native level in View.
---
Ciao
Romano
------
rebol [
Title: "Eat"
Author: "Italian Connexion (Gabriele Santilli - Romano Paolo Tenca)"
Purpose: "Event filtering --- speeds up view!"
]
context [
;the words of this context are the event/type to compress
no-queue: context []
wake-event: func [event /local no-btn] bind [
either not pop-face [
do event
empty? screen-face/pane
][
either any [pop-face = event/face within? event/offset win-offset?
pop-face pop-face/size] [
no-btn: false
if block? get in pop-face 'pane [
no-btn: foreach item pop-face/pane [if get in item 'action
[break/return false] true]
]
if any [all [event/type = 'up no-btn] event/type = 'close]
[hide-popup]
do event
] [
if pop-face/action [
if not find [move time] event/type [hide-popup]
do event
]
]
none? find pop-list pop-face
]
] in system/view 'self
awake: func [port no-queue /local event events lasttype] [
events: clear []
while [event: pick port 1] [
either all [in no-queue event/type lasttype = event/type] [
change back tail events event
] [
lasttype: event/type
insert tail events event
]
]
foreach event events [
if wake-event event [return true]
]
false
]
system/ports/wait-list/1/awake: func [port] [awake port no-queue]
to-ob: func [blk [block!]][
blk: copy blk
forall blk [change blk to-set-word first blk]
context insert blk none
]
free: true
set 'eat func [
/forever for [block!]
/only blk [block!]
][
either forever [
no-queue: to-ob for
][
if not only [blk: [move key offset scroll-line scroll-page]]
if all [free not empty? blk][
free: false
awake system/view/event-port to-ob blk
free: true
]
]
]
]
print {
Example:
to compress all the events of type 'offset and 'move:
eat/forever [offset move]
to remove all events compression:
eat/forever []
to compress only once (at the end of a VID action for example)
the events of type [move key offset scroll-line scroll-page]:
eat
to compress only once the events of type 'move 'scroll-line
'scroll-page:
eat/only [move scroll-line scroll-page]
}
e: ne: 1
delay: 500000
view layout [
area 200x50 wrap "Try to move the slider up and down keeping the left
button pressed and see the difference"
guide
text white "Standard"
slider [print ["pressed not eated" ne] ne: ne + 1 loop delay []]
return
pad 100
return
text white "Eated"
slider [print ["pressed eated " e] e: e + 1 loop delay [] eat/only
[move]]
]
halt