use window.requestAnimationFrame instead of timer based event triggering

This commit is contained in:
Andreas Rumpf 2017-03-31 14:11:42 +02:00
commit 497aec2114
2 changed files with 9 additions and 2 deletions

View file

@ -86,4 +86,4 @@ setRenderer createDom
proc onload(session: cstring) {.exportc.} = proc onload(session: cstring) {.exportc.} =
for i in 0..10_000: for i in 0..10_000:
entries.add("Entry " & $i) entries.add("Entry " & $i)
redraw() init()

View file

@ -147,15 +147,22 @@ proc dodraw() =
if toFocus != nil: if toFocus != nil:
toFocus.focus() toFocus.focus()
proc reqFrame(callback: proc()) {.importc: "window.requestAnimationFrame".}
proc redraw*() = proc redraw*() =
# we buffer redraw requests: # we buffer redraw requests:
when true: when false:
if drawTimeout != nil: if drawTimeout != nil:
clearTimeout(drawTimeout) clearTimeout(drawTimeout)
drawTimeout = setTimeout(dodraw, 30) drawTimeout = setTimeout(dodraw, 30)
elif true:
reqFrame(dodraw)
else: else:
dodraw() dodraw()
proc init*() =
reqFrame(dodraw)
#proc prepend*(parent, kid: Element) = #proc prepend*(parent, kid: Element) =
# parent.insertBefore(kid, parent.firstChild) # parent.insertBefore(kid, parent.firstChild)
# prependChild(parent, kid) # prependChild(parent, kid)