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.} =
|
||||
for i in 0..10_000:
|
||||
entries.add("Entry " & $i)
|
||||
redraw()
|
||||
init()
|
||||
|
|
|
|||
|
|
@ -147,15 +147,22 @@ proc dodraw() =
|
|||
if toFocus != nil:
|
||||
toFocus.focus()
|
||||
|
||||
proc reqFrame(callback: proc()) {.importc: "window.requestAnimationFrame".}
|
||||
|
||||
proc redraw*() =
|
||||
# we buffer redraw requests:
|
||||
when true:
|
||||
when false:
|
||||
if drawTimeout != nil:
|
||||
clearTimeout(drawTimeout)
|
||||
drawTimeout = setTimeout(dodraw, 30)
|
||||
elif true:
|
||||
reqFrame(dodraw)
|
||||
else:
|
||||
dodraw()
|
||||
|
||||
proc init*() =
|
||||
reqFrame(dodraw)
|
||||
|
||||
#proc prepend*(parent, kid: Element) =
|
||||
# parent.insertBefore(kid, parent.firstChild)
|
||||
# prependChild(parent, kid)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue