Skip to content

Commit

Permalink
Update sigils (#65)
Browse files Browse the repository at this point in the history
* bump version
* bump sigils version
* update deps
* enable windows test again
* use figuro-fixes branch
* sigil update
* add new figuro specific uid / NodeId incrementer
  • Loading branch information
elcritch authored Jan 10, 2025
1 parent 7dfec68 commit 5cb4e3f
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 39 deletions.
1 change: 1 addition & 0 deletions config.nims
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ switch("styleCheck", "hint")
--d:windyNoHttp
--d:printDebugTimings
--d:nimStrictDelete
--deepcopy:on

--hint:"ConvFromXtoItselfNotNeeded:off"

Expand Down
5 changes: 3 additions & 2 deletions figuro.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
45 changes: 18 additions & 27 deletions figuro/common/nodes/ui.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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.}
Expand Down Expand Up @@ -39,7 +41,7 @@ type

Figuro* = ref object of Agent
frame*: AppFrame
parent*: FiguroWeakRef
parent*: WeakRef[Figuro]
uid*: NodeID
name*: string
children*: seq[Figuro]
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 5 additions & 4 deletions figuro/ui/apis.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 2 additions & 5 deletions figuro/ui/core.nim
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,14 @@ proc resetToDefault*(node: Figuro, kind: NodeKind) =
node.zlevel = 0.ZLevel
node.attrs = {}


var nodeDepth = 0
proc nd*(): string =
for i in 0..nodeDepth:
result &= " "

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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion tests/unittests/ttransfer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5cb4e3f

Please sign in to comment.