diff --git a/README.md b/README.md index 2e6ef02..727843d 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ ### Usage ```nim -requires "https://github.com/calcit-runner/json-paint.nim#v0.0.24" +requires "https://github.com/calcit-runner/json-paint.nim#v0.0.25" ``` ```nim @@ -51,8 +51,7 @@ This library uses HSL/HSLA colors: ```coffee type: 'group' -x: 1 -y: 1 +position: [1, 1], children: [] ``` diff --git a/json_paint.nimble b/json_paint.nimble index 40e35a7..2913c25 100644 --- a/json_paint.nimble +++ b/json_paint.nimble @@ -1,6 +1,6 @@ # Package -version = "0.0.24" +version = "0.0.25" author = "jiyinyiyong" description = "JSON DSL for canvas rendering" license = "MIT" diff --git a/src/json_paint/shape_renderer.nim b/src/json_paint/shape_renderer.nim index 013070d..d88ba9d 100644 --- a/src/json_paint/shape_renderer.nim +++ b/src/json_paint/shape_renderer.nim @@ -65,8 +65,16 @@ proc renderArc(ctx: ptr Context, tree: JsonNode, base: TreeContext) = proc renderGroup(ctx: ptr Context, tree: JsonNode, base: TreeContext) = if tree.contains("children"): - let x = if tree.contains("x"): tree["x"].getFloat else: 0 - let y = if tree.contains("y"): tree["y"].getFloat else: 0 + var x = 0.0 + var y = 0.0 + if tree.contains("position"): + let position = readPointVec(tree["position"]) + x = position.x + y = position.y + if tree.contains("x"): + x = tree["x"].getFloat() + if tree.contains("y"): + y = tree["y"].getFloat() let children = tree["children"] if children.kind == JArray: for item in children.elems: diff --git a/tests/demo.nim b/tests/demo.nim index fb4a691..068003b 100644 --- a/tests/demo.nim +++ b/tests/demo.nim @@ -26,8 +26,7 @@ proc startRenderLoop() = proc renderSomething() = renderCanvas(%* { "type": "group", - "x": 100, - "y": 30, + "position": [100, 30], "children": [ { "type": "arc",