simplifications

This commit is contained in:
Andreas Rumpf 2017-04-27 17:39:54 +02:00
commit ebccc4e9a1

View file

@ -29,79 +29,57 @@ type
var appState: AppState var appState: AppState
proc createTableCell(id: cstring): VNode = proc createTableCell(id: cstring): VNode =
kout cstring"createTableCell"
proc tableCellClick(ev: karax.Event; n: VNode) = proc tableCellClick(ev: karax.Event; n: VNode) =
kout cstring"tableCellClick"
kout "Clicked" & id kout "Clicked" & id
# ev.stopPropogation()
result = buildHtml(td(class="TableCell", onclick=tableCellClick)): result = buildHtml(td(class="TableCell", onclick=tableCellClick)):
text id text id
proc createTableRow(item: TableItemState): VNode = proc createTableRow(item: TableItemState): VNode =
kout cstring"createTableRow"
var children: seq[VNode] = @[]
children.add createTableCell("#" & &item.id)
for i in 0..<len(item.props):
children.add(createTableCell(item.props[i]))
var className = cstring"TableRow" var className = cstring"TableRow"
if item.active: if item.active:
className = cstring"TableRow active" className = cstring"TableRow active"
result = buildHtml(tr(class=className, `data-id` = &item.id)): result = buildHtml(tr(class=className, `data-id` = &item.id)):
for child in children: createTableCell("#" & &item.id)
child for i in 0..<len(item.props):
createTableCell(item.props[i])
proc tableCreateVNode(data: TableState): VNode = proc tableCreateVNode(data: TableState): VNode =
kout cstring"tableCreateVNode"
result = buildHtml(table(class="Table")): result = buildHtml(table(class="Table")):
tbody: tbody:
for child in data.items: for child in data.items:
createTableRow(child) createTableRow(child)
proc createAnimBox(item: AnimBoxState): VNode = proc createAnimBox(item: AnimBoxState): VNode =
kout cstring"createAnimBox" let time = item.time
var time = item.time let dataId: cstring = &item.id
var dataId: cstring = &item.id let color: float = float(time mod 10) / 10
var color: float = float(time mod 10) / 10 let divStyles: cstring = "border-radius: " & &(time mod 10) & "px; background: rgba(0,0,0," & cstring($color) & ")"
var divStyles: cstring = "border-radius: " & &(time mod 10) & "px; background: rgba(0,0,0," & cstring($color) & ")"
result = flatHtml(tdiv(class="AnimBox", `data-id`=dataId, style=divStyles)) result = flatHtml(tdiv(class="AnimBox", `data-id`=dataId, style=divStyles))
proc animCreateVNode(data: AnimState): VNode = proc animCreateVNode(data: AnimState): VNode =
kout cstring"animCreateVNode"
result = buildHtml(tdiv(class="Anim")): result = buildHtml(tdiv(class="Anim")):
for child in data.items: for child in data.items:
createAnimBox(child) createAnimBox(child)
proc createTreeLeaf(data: TreeNodeState): VNode = proc createTreeLeaf(data: TreeNodeState): VNode =
kout cstring"createTreeLeaf"
result = buildHtml(li(class="TreeLeaf")): result = buildHtml(li(class="TreeLeaf")):
text &data.id text &data.id
proc createTreeNode(data: TreeNodeState): VNode = proc createTreeNode(data: TreeNodeState): VNode =
kout cstring"createTreeNode"
var children: seq[VNode] = @[]
for i in 0..<len(data.children):
var n = data.children[i]
if n.container:
children.add(createTreeNode(n))
else:
children.add(createTreeLeaf(n))
result = buildHtml(ul(class="TreeNode")): result = buildHtml(ul(class="TreeNode")):
for child in children: for n in data.children:
child if n.container:
createTreeNode(n)
else:
createTreeLeaf(n)
proc treeCreateVNode(data: TreeState): VNode = proc treeCreateVNode(data: TreeState): VNode =
kout cstring"treeCreateVNode"
result = buildHtml(tdiv(class="Tree")): result = buildHtml(tdiv(class="Tree")):
createTreeNode(data.root) createTreeNode(data.root)
proc update(): VNode = proc update(): VNode =
if appState == nil: assert appState != nil
kout cstring"stupid fuck"
return newVNode(VNodeKind.tdiv)
let location = appState.location let location = appState.location
var children: VNode = nil var children: VNode = nil
if location == cstring"table": if location == cstring"table":
@ -115,15 +93,11 @@ proc update(): VNode =
children children
proc a(state: AppState) = proc a(state: AppState) =
kout cstring"setting state here"
appState = state appState = state
redrawForce() redrawForce()
proc b(samples: RootRef) = proc b(samples: RootRef) =
kout cstring"end called" document.body.innerHTML = cstring"<pre>" & toJson(samples) & cstring"</pre>"
#document.body.innerHTML = cstring"<pre>" & toJson(samples) & cstring"</pre>"
#redraw()
discard
proc init*(a: cstring, b: cstring) {.importc: "uibench.init", nodecl.} proc init*(a: cstring, b: cstring) {.importc: "uibench.init", nodecl.}
proc run*(a: proc(state: AppState), b: proc(samples: RootRef)) {.importc: "uibench.run", nodecl.} proc run*(a: proc(state: AppState), b: proc(samples: RootRef)) {.importc: "uibench.run", nodecl.}
@ -131,6 +105,4 @@ proc run*(a: proc(state: AppState), b: proc(samples: RootRef)) {.importc: "uiben
init(cstring"Nim-karax", cstring"0.6.1") init(cstring"Nim-karax", cstring"0.6.1")
setRendererOnly update setRendererOnly update
kout cstring"running"
run(a, b) run(a, b)