diff --git a/src/components/layout/processor.nim b/src/components/layout/processor.nim index 47a91f9..14ab10d 100644 --- a/src/components/layout/processor.nim +++ b/src/components/layout/processor.nim @@ -160,7 +160,7 @@ proc addImage*(layout: var Layout, content: string) = proc constructFromElem*(layout: var Layout, elem: HTMLElement) = case elem.tag - of TAG_P, TAG_B, TAG_SPAN, TAG_STRONG, TAG_LI, TAG_A: # FIXME: bold stuff + of TAG_P, TAG_B, TAG_SPAN, TAG_STRONG, TAG_LI, TAG_A, TAG_DIV: # FIXME: bold stuff if not *elem.text: warn "layout: <" & $elem.tag & "> element does not contain any text data, ignoring it." return @@ -268,6 +268,9 @@ proc constructFromDocument*(layout: var Layout, document: HTMLDocument) = pushRemainingChildren(currChildren, remainingChildren) ]# proc update*(layout: var Layout) = - layout.constructFromDocument(layout.document) + if layout.document != nil: + layout.constructFromDocument(layout.document) + else: + warn "Cannot re-calculate layout if document == NULL!" export bumpy diff --git a/src/components/renderer/core.nim b/src/components/renderer/core.nim index 2526ddc..8a6b4f9 100644 --- a/src/components/renderer/core.nim +++ b/src/components/renderer/core.nim @@ -56,29 +56,12 @@ proc setWindowTitle*(renderer: FerusRenderer, title: string) {.inline.} = info "Setting window title to \"" & title & "\"" renderer.window.title = title -proc renderDocument*(renderer: FerusRenderer, document: HTMLDocument) = - info "Rendering HTML document - calculating layout" - - var layout = newLayout(renderer.ipc, renderer.scene.fontManager.get("Default")) - renderer.layout = layout - - if *document.head(): - for child in &document.head(): - if child.tag == TAG_TITLE: - if *child.text: - info "Setting document title: " & &child.text - renderer.setWindowTitle(&child.text & " — Ferus") - else: - warn " tag has no text content!" - else: - info "Document has no <head>" - - layout.constructFromDocument(document) - +proc paintLayout*(renderer: FerusRenderer) = var displayList = newDisplayList(addr renderer.scene) + displayList.doClearAll = true var start, ending: Vec2 - for i, box in layout.boxes: + for i, box in renderer.layout.boxes: if i == 0 or box.pos.y < start.y: `=destroy`(start) wasMoved(start) @@ -110,11 +93,33 @@ proc renderDocument*(renderer: FerusRenderer, document: HTMLDocument) = renderer.scene.camera.setBoundaries(start, ending) displayList.commit() +proc renderDocument*(renderer: FerusRenderer, document: HTMLDocument) = + info "Rendering HTML document - calculating layout" + + var layout = newLayout(renderer.ipc, renderer.scene.fontManager.get("Default")) + + if *document.head(): + for child in &document.head(): + if child.tag == TAG_TITLE: + if *child.text: + info "Setting document title: " & &child.text + renderer.setWindowTitle(&child.text & " — Ferus") + else: + warn "<title> tag has no text content!" + else: + info "Document has no <head>" + + layout.constructFromDocument(document) + renderer.layout = move(layout) + + renderer.paintLayout() + proc resize*(renderer: FerusRenderer, dims: tuple[w, h: int32]) {.inline.} = info "Resizing renderer viewport to $1x$2" % [$dims.w, $dims.h] let casted = (w: dims.w.int, h: dims.h.int) renderer.scene.onResize(casted) #renderer.layout.update() + #renderer.paintLayout() proc initialize*(renderer: FerusRenderer) {.inline.} = info "Initializing renderer." diff --git a/src/components/renderer/process.nim b/src/components/renderer/process.nim index 78c608a..254fe94 100644 --- a/src/components/renderer/process.nim +++ b/src/components/renderer/process.nim @@ -122,7 +122,6 @@ proc talk( return let data = client.receive() - echo data if data.len < 1: return diff --git a/src/ferus.nim b/src/ferus.nim index c430d2a..88a0ba7 100644 --- a/src/ferus.nim +++ b/src/ferus.nim @@ -23,6 +23,8 @@ proc main() {.inline.} = var master = newMasterProcess() initialize master + master.summonRendererProcess() + master.loadFont("assets/fonts/IBMPlexSans-Regular.ttf", "Default") let resource = paramStr(1) var content: string @@ -55,8 +57,6 @@ proc main() {.inline.} = let document = &(&parsedHtml).document # i love unwrapping: electric boogaloo print document - master.summonRendererProcess() - master.loadFont("assets/fonts/IBMPlexSans-Regular.ttf", "Default") master.renderDocument(document) while true: