use window.requestAnimationFrame instead of timer based event triggering
This commit is contained in:
parent
d9330cbab9
commit
497aec2114
2 changed files with 9 additions and 2 deletions
|
|
@ -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()
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue