diff --git a/config.nims b/config.nims index aecb607b..959969cf 100644 --- a/config.nims +++ b/config.nims @@ -8,6 +8,7 @@ switch("styleCheck", "hint") --d:windyNoHttp --d:printDebugTimings --d:nimStrictDelete +--deepcopy:on --hint:"ConvFromXtoItselfNotNeeded:off" diff --git a/figuro.nimble b/figuro.nimble index acacd545..67c0c2b5 100644 --- a/figuro.nimble +++ b/figuro.nimble @@ -7,7 +7,7 @@ srcDir = "." # Dependencies # requires "nim >= 2.0.12" -requires "https://github.com/elcritch/sigils >= 0.7.2" +requires "sigils >= 0.9.4" requires "pixie >= 5.0.1" requires "cssgrid >= 0.6.1" requires "chroma >= 0.2.7" @@ -22,8 +22,9 @@ requires "macroutils >= 1.2.0" requires "cdecl >= 0.7.5" requires "asynctools >= 0.1.1" requires "nimsimd >= 1.2.5" -requires "threading" +requires "threading >= 0.2.1" requires "nimscripter >= 1.1.5" requires "msgpack4nim" requires "stack_strings" requires "micros" +requires "https://github.com/elcritch/windy#figuro-fixes" diff --git a/figuro/common/nodes/ui.nim b/figuro/common/nodes/ui.nim index 54fae866..ff6bcbce 100644 --- a/figuro/common/nodes/ui.nim +++ b/figuro/common/nodes/ui.nim @@ -6,9 +6,11 @@ import sigils import ../../inputs import cssgrid import stack_strings +import sigils/weakrefs export basics, sigils, inputs, cssgrid, stack_strings export unicode, monotimes +export weakrefs when defined(nimscript): {.pragma: runtimeVar, compileTime.} @@ -39,7 +41,7 @@ type Figuro* = ref object of Agent frame*: AppFrame - parent*: FiguroWeakRef + parent*: WeakRef[Figuro] uid*: NodeID name*: string children*: seq[Figuro] @@ -84,9 +86,6 @@ type textLayout*: GlyphArrangement points*: seq[Position] - FiguroWeakRef* = object - cur* {.cursor.}: Figuro - BasicFiguro* = ref object of Figuro StatefulFiguro*[T] = ref object of Figuro @@ -97,33 +96,26 @@ type proc `=destroy`*(obj: type(Figuro()[])) = ## destroy - let objPtr = FiguroWeakRef(cur: cast[Figuro](addr obj)) + let objPtr = unsafeWeakRef(cast[Figuro](addr(obj))) for child in obj.children: assert objPtr == child.parent - child.parent.cur = nil - -proc isNil*(fig: FiguroWeakRef): bool = - fig.cur.isNil() - -proc `[]`*(fig: FiguroWeakRef): Figuro = - cast[Figuro](fig.cur) - -proc children*(fig: FiguroWeakRef): seq[Figuro] = - fig.cur.children + child.parent.pt = nil -proc unsafeWeakRef*(obj: Figuro): FiguroWeakRef = - result = FiguroWeakRef(cur: obj) - -template toRef*(fig: FiguroWeakRef): auto = - fig.cur +proc children*(fig: WeakRef[Figuro]): seq[Figuro] = + fig{}.children proc hash*(a: AppFrame): Hash = a.root.hash() +var lastNodeUID {.runtimeVar.} = 0 + +proc nextFiguroId*(): NodeID = + lastNodeUID.inc() + result = lastNodeUID + proc newFiguro*[T: Figuro](tp: typedesc[T]): T = result = T() - result.debugId = nextAgentId() - result.uid = result.debugId + result.uid = nextFiguroId() proc getName*(fig: Figuro): string = result = $fig.name @@ -134,13 +126,12 @@ proc getId*(fig: Figuro): NodeID = if fig.isNil: NodeID -1 else: fig.uid -proc getId*(fig: FiguroWeakRef): NodeID = +proc getId*(fig: WeakRef[Figuro]): NodeID = if fig.isNil: NodeID -1 else: fig[].uid -proc doTick*(fig: Figuro, - tickCount: int, - now: MonoTime) {.signal.} +proc doTick*(fig: Figuro, tickCount: int, now: MonoTime) {.signal.} + proc doDraw*(fig: Figuro) {.signal.} proc doLoad*(fig: Figuro) {.signal.} proc doHover*(fig: Figuro, @@ -237,7 +228,7 @@ template bubble*(signal: typed, parent: typed) = connect(node, `signal`, parent, `signal Bubble`) template bubble*(signal: typed) = - connect(node, `signal`, node.parent.cur, `signal Bubble`) + connect(node, `signal`, node.parent[], `signal Bubble`) proc printFiguros*(n: Figuro, depth = 0) = echo " ".repeat(depth), "render: ", n.getId, diff --git a/figuro/ui/apis.nim b/figuro/ui/apis.nim index fcb3cce3..085ebee2 100644 --- a/figuro/ui/apis.nim +++ b/figuro/ui/apis.nim @@ -311,10 +311,11 @@ proc findRoot*(node: Figuro): Figuro = result = node var cnt = 0 while not result.parent.isNil() and result.unsafeWeakRef() != result.parent: - result = result.parent.toRef - cnt.inc - if cnt > 10_000: - raise newException(IndexDefect, "error finding root") + withRef result.parent, parent: + result = parent + cnt.inc + if cnt > 10_000: + raise newException(IndexDefect, "error finding root") ## ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ## Node Layouts and Constraints diff --git a/figuro/ui/core.nim b/figuro/ui/core.nim index abf81a4d..e98fded5 100644 --- a/figuro/ui/core.nim +++ b/figuro/ui/core.nim @@ -65,7 +65,6 @@ proc resetToDefault*(node: Figuro, kind: NodeKind) = node.zlevel = 0.ZLevel node.attrs = {} - var nodeDepth = 0 proc nd*(): string = for i in 0..nodeDepth: @@ -73,7 +72,7 @@ proc nd*(): string = proc disable(fig: Figuro) = if not fig.isNil: - fig.parent.cur = nil + fig.parent.pt = nil fig.attrs.incl inactive for child in fig.children: disable(child) @@ -196,8 +195,7 @@ proc preNode*[T: Figuro](kind: NodeKind, name: string, node: var T, parent: Figu node.name = name template configNewNode(node: untyped) = - node.debugId = nextAgentId() - node.uid = node.debugId + node.uid = nextFiguroId() node.parent = parent.unsafeWeakRef() node.frame = parent.frame configNodeName(node, name) @@ -234,7 +232,6 @@ proc preNode*[T: Figuro](kind: NodeKind, name: string, node: var T, parent: Figu # echo nd(), "preNode: Start: ", id, " node: ", node.getId, " parent: ", parent.getId - node.uid = node.debugId node.kind = kind node.highlight = parent.highlight node.transparency = parent.transparency diff --git a/tests/unittests/ttransfer.nim b/tests/unittests/ttransfer.nim index e6736a5e..d74488ee 100644 --- a/tests/unittests/ttransfer.nim +++ b/tests/unittests/ttransfer.nim @@ -106,7 +106,8 @@ suite "test layers": var node = self block: node.zlevel = 20 - discard node.name.tryAdd("root") + # discard node.name.tryAdd("root") + node.name = "root" rectangle "body": rectangle "child0": discard