Skip to content

Commit

Permalink
use position field for group; bump 0.0.25
Browse files Browse the repository at this point in the history
  • Loading branch information
tiye committed Dec 16, 2020
1 parent d2f77a4 commit 2332308
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -51,8 +51,7 @@ This library uses HSL/HSLA colors:

```coffee
type: 'group'
x: 1
y: 1
position: [1, 1],
children: []
```

Expand Down
2 changes: 1 addition & 1 deletion json_paint.nimble
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Package

version = "0.0.24"
version = "0.0.25"
author = "jiyinyiyong"
description = "JSON DSL for canvas rendering"
license = "MIT"
Expand Down
12 changes: 10 additions & 2 deletions src/json_paint/shape_renderer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions tests/demo.nim
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ proc startRenderLoop() =
proc renderSomething() =
renderCanvas(%* {
"type": "group",
"x": 100,
"y": 30,
"position": [100, 30],
"children": [
{
"type": "arc",
Expand Down

0 comments on commit 2332308

Please sign in to comment.