added post render callback

This commit is contained in:
Fabian Keller 2017-05-19 20:15:07 +02:00
commit d5596c8ff5
2 changed files with 11 additions and 4 deletions

View file

@ -117,6 +117,7 @@ proc same(n: VNode, e: Node): bool =
var var
dorender: proc (): VNode {.closure.} dorender: proc (): VNode {.closure.}
currentTree: VNode currentTree: VNode
postRenderCallback: proc ()
proc replaceById(id: cstring; newTree: Node) = proc replaceById(id: cstring; newTree: Node) =
let x = document.getElementById(id) let x = document.getElementById(id)
@ -279,6 +280,10 @@ proc dodraw() =
updateDirtyElements(nil, olddom, newtree) updateDirtyElements(nil, olddom, newtree)
someDirty = false someDirty = false
currentTree = newtree currentTree = newtree
if not postRenderCallback.isNil:
postRenderCallback()
# now that it's part of the DOM, give it the focus: # now that it's part of the DOM, give it the focus:
if toFocus != nil: if toFocus != nil:
toFocus.focus() toFocus.focus()
@ -299,9 +304,10 @@ proc redraw*() =
proc init(ev: Event) = proc init(ev: Event) =
reqFrame(dodraw) reqFrame(dodraw)
proc setRenderer*(renderer: proc (): VNode) = proc setRenderer*(renderer: proc (): VNode, clientPostRenderCallback: proc () = nil) =
dorender = renderer dorender = renderer
window.onload = init window.onload = init
postRenderCallback = clientPostRenderCallback
proc addEventHandler*(n: VNode; k: EventKind; action: EventHandler) = proc addEventHandler*(n: VNode; k: EventKind; action: EventHandler) =
## Implements the foundation of Karax's event management. ## Implements the foundation of Karax's event management.

View file

@ -273,6 +273,7 @@ type
textDecoration*: cstring textDecoration*: cstring
textIndent*: cstring textIndent*: cstring
textTransform*: cstring textTransform*: cstring
transform*: cstring
top*: cstring top*: cstring
verticalAlign*: cstring verticalAlign*: cstring
visibility*: cstring visibility*: cstring
@ -567,7 +568,7 @@ proc getElementsByClass*(n: Node; name: cstring): seq[Node] {.
type type
BoundingRect* {.importc.} = object BoundingRect* {.importc.} = object
top*, bottom*, left*, right*: int top*, bottom*, left*, right*, x*, y*, width*, height*: float
proc getBoundingClientRect*(e: Node): BoundingRect {. proc getBoundingClientRect*(e: Node): BoundingRect {.
importcpp: "getBoundingClientRect", nodecl.} importcpp: "getBoundingClientRect", nodecl.}
@ -579,8 +580,8 @@ proc clientWidth*(): int {.
proc inViewport*(el: Node): bool = proc inViewport*(el: Node): bool =
let rect = el.getBoundingClientRect() let rect = el.getBoundingClientRect()
result = rect.top >= 0 and rect.left >= 0 and result = rect.top >= 0 and rect.left >= 0 and
rect.bottom <= clientHeight() and rect.bottom <= clientHeight().float and
rect.right <= clientWidth() rect.right <= clientWidth().float
proc scrollTop*(e: Node): int {.importcpp: "#.scrollTop", nodecl.} proc scrollTop*(e: Node): int {.importcpp: "#.scrollTop", nodecl.}
proc offsetHeight*(e: Node): int {.importcpp: "#.offsetHeight", nodecl.} proc offsetHeight*(e: Node): int {.importcpp: "#.offsetHeight", nodecl.}