Skip to content

Commit

Permalink
(fix) fix hangups when loading file
Browse files Browse the repository at this point in the history
  • Loading branch information
xTrayambak committed Oct 26, 2024
1 parent f264f13 commit d154df8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 25 deletions.
7 changes: 5 additions & 2 deletions src/components/layout/processor.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
45 changes: 25 additions & 20 deletions src/components/renderer/core.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<title> 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)
Expand Down Expand Up @@ -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."
Expand Down
1 change: 0 additions & 1 deletion src/components/renderer/process.nim
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ proc talk(
return

let data = client.receive()
echo data
if data.len < 1:
return

Expand Down
4 changes: 2 additions & 2 deletions src/ferus.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit d154df8

Please sign in to comment.