Skip to content

Commit a93f595

Browse files
committed
Merge branch 'main' of github.com:elcritch/figuro
2 parents eab46dd + f6753a9 commit a93f595

24 files changed

+241
-276
lines changed

.github/workflows/build-full.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,25 @@ jobs:
1717
- windows-latest
1818
steps:
1919
- uses: actions/checkout@v1
20-
with:
21-
path: "figuro/"
20+
2221
- uses: iffy/install-nim@v4
2322
with:
2423
version: ${{ matrix.nimversion }}
2524
env:
2625
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26+
27+
- name: Cache packages
28+
uses: actions/cache@v3
29+
with:
30+
path: ~/.nimble
31+
key: ${{ runner.os }}-${{ hashFiles('figuro.nimble') }}
32+
2733
- name: Install Nimble
2834
run: |
2935
nimble install nimble
3036
nim -v
3137
nimble -v
3238
33-
- name: Cache packages
34-
uses: actions/cache@v3
35-
with:
36-
path: vendor
37-
key: ${{ runner.os }}-${{ hashFiles('figuro/atlas.lock') }}
38-
3939
- name: Install Deps
4040
run: |
4141
# sync deps

.github/workflows/build-pr.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,19 @@ jobs:
1414
- ubuntu-latest
1515
steps:
1616
- uses: actions/checkout@v1
17-
with:
18-
path: "fig_ws/"
17+
1918
- uses: iffy/install-nim@v4
2019
with:
2120
version: ${{ matrix.nimversion }}
2221
env:
2322
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2423

24+
- name: Cache packages
25+
uses: actions/cache@v3
26+
with:
27+
path: ~/.nimble
28+
key: ${{ runner.os }}-${{ hashFiles('figuro.nimble') }}
29+
2530
- name: Install Nimble
2631
run: |
2732
nimble install nimble
@@ -33,10 +38,6 @@ jobs:
3338
# new atlas workspace
3439
nimble install -d --verbose
3540
36-
- name: Test build From fig_ws/
37-
run: |
38-
nim c figuro/tests/tclick.nim
39-
4041
- name: Build Tests
4142
run: |
4243
cd figuro/

README.md

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ A GUI toolkit for Nim that is event driven while being small and fast. It tries
1010
Example drawing buttons with a fading background when any of them are hovered (see below for how it works):
1111

1212
```nim
13+
import figuro/widgets/button
14+
import figuro/widgets/horizontal
15+
import figuro/widget
16+
import figuro/ui/animations
17+
import figuro
18+
1319
let
1420
typeface = loadTypeFace("IBMPlexSans-Regular.ttf")
1521
font = UiFont(typefaceId: typeface, size: 22)
@@ -21,6 +27,7 @@ type
2127
2228
proc update*(fig: Main) {.signal.}
2329
30+
2431
proc btnTick*(self: Button[int]) {.slot.} =
2532
## slot to increment a button on every tick
2633
self.state.inc
@@ -34,7 +41,7 @@ proc btnClicked*(self: Button[int],
3441
## which we can use to check if it's a mouse click
3542
if buttons == {MouseLeft} or buttons == {DoubleClick}:
3643
if kind == Enter:
37-
self.state.inc()
44+
self.state.inc
3845
refresh(self)
3946
4047
proc btnHover*(self: Main, evtKind: EventKind) {.slot.} =
@@ -45,13 +52,12 @@ proc btnHover*(self: Main, evtKind: EventKind) {.slot.} =
4552
proc draw*(self: Main) {.slot.} =
4653
## draw slot for Main widget called whenever an event
4754
## triggers a node or it's parents to be refreshed
55+
var node = self
56+
node.setName "main"
4857
49-
self.setName "main"
50-
51-
# Calls the widget template `rectangle` which creates a new basic widget node.
52-
# Generally used to draw generic boxes.
53-
# Here we need to pass the `parent` argument since there's no current `node` set
54-
rectangle "body", parent=self:
58+
# Calls the widget template `rectangle`.
59+
# This creates a new basic widget node. Generally used to draw generic rectangles.
60+
rectangle "body":
5561
with node:
5662
# sets the bounding box of this node
5763
box 10'ux, 10'ux, 600'ux, 120'ux
@@ -60,7 +66,7 @@ proc draw*(self: Main) {.slot.} =
6066
fill whiteColor.darken(self.bkgFade.amount)
6167
6268
# sets up horizontal widget node with alternate syntax
63-
horizontal "horiz":
69+
Horizontal.new "horiz":
6470
with node:
6571
box 10'ux, 0'ux, 100'pp, 100'pp
6672
# `itemWidth` is needed to set the width of items
@@ -69,11 +75,11 @@ proc draw*(self: Main) {.slot.} =
6975
layoutItems justify=CxCenter, align=CxCenter
7076
7177
for i in 0 .. 4:
72-
buttonOf[int] "btn", captures=[i]:
73-
# widgets with generic type like Button can use `<name>Of[T]` to set the generic type, otherwise void is used
78+
Button[int].new("btn", captures=i):
7479
let btn = node
7580
with node:
7681
size 100'ux, 100'ux
82+
cornerRadius 5.0
7783
connect(doHover, self, btnHover)
7884
connect(doClick, node, btnClicked)
7985
if i == 0:
@@ -84,13 +90,13 @@ proc draw*(self: Main) {.slot.} =
8490
fill blackColor
8591
setText({font: $(btn.state)}, Center, Middle)
8692
93+
8794
proc tick*(self: Main, tick: int, time: MonoTime) {.slot.} =
88-
## handles background "fade" when buttons are hovered
8995
self.bkgFade.tick(self)
9096
emit self.update()
9197
9298
var main = Main.new()
93-
let frame = newAppFrame(main, size=(400'ui, 140'ui))
99+
let frame = newAppFrame(main, size=(700'ui, 200'ui))
94100
startFiguro(frame)
95101
```
96102

figuro.nimble

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ srcDir = "."
66

77
# Dependencies
88

9-
requires "nim >= 1.6.5"
9+
# requires "nim >= 2.0.12"
1010
requires "pixie >= 5.0.1"
1111
requires "cssgrid >= 0.6.1"
1212
requires "chroma >= 0.2.7"

figuro/common/nodes/ui.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ template toRef*(fig: FiguroWeakRef): auto =
120120
proc hash*(a: AppFrame): Hash =
121121
a.root.hash()
122122
123-
proc new*[T: Figuro](tp: typedesc[T]): T =
123+
proc newFiguro*[T: Figuro](tp: typedesc[T]): T =
124124
result = T()
125125
result.debugId = nextAgentId()
126126
result.uid = result.debugId
@@ -223,7 +223,7 @@ template connect*(
223223
b: Figuro,
224224
slot: typed,
225225
acceptVoidSlot: static bool = false,
226-
) =
226+
): void =
227227
## template override
228228
when signalName(signal) == "doClick":
229229
a.listens.signals.incl {evClick, evClickOut}

figuro/meta/agents.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ proc addAgentListeners*(obj: Agent,
238238
sig: string,
239239
tgt: Agent,
240240
slot: AgentProc
241-
) =
241+
): void =
242242
243243
# echo "add agent listener: ", sig, " obj: ", obj.debugId, " tgt: ", tgt.debugId
244244
# if obj.listeners.hasKey(sig):

figuro/meta/signals.nim

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ proc getSignalName*(signal: NimNode): NimNode =
120120
result = newStrLitNode signal.strVal
121121
# echo "getSignalName:result: ", result.treeRepr
122122

123-
macro signalName*(signal: untyped): untyped =
124-
result = getSignalName(signal)
123+
macro signalName*(signal: untyped): string =
124+
getSignalName(signal)
125125

126126
proc splitNamesImpl(slot: NimNode): Option[(NimNode, NimNode)] =
127127
# echo "splitNamesImpl: ", slot.treeRepr
@@ -161,7 +161,7 @@ macro signalType*(s: untyped): auto =
161161
for arg in obj[2..^1]:
162162
result.add arg[1]
163163

164-
proc getAgentProcTy[T](tp: AgentProcTy[T]): T =
164+
proc getAgentProcTy*[T](tp: AgentProcTy[T]): T =
165165
discard
166166
167167
template connect*[T](
@@ -170,7 +170,7 @@ template connect*[T](
170170
b: Agent,
171171
slot: Signal[T],
172172
acceptVoidSlot: static bool = false,
173-
) =
173+
): void =
174174
## sets up `b` to recieve events from `a`. Both `a` and `b`
175175
## must subtype `Agent`. The `signal` must be a signal proc,
176176
## while `slot` must be a slot proc.
@@ -196,8 +196,8 @@ template connect*[T](
196196
b, setValue)
197197
emit a.valueChanged(137) #=> prints "setValue! 137"
198198
199-
let agentSlot = slot
200-
# static:
199+
# let agentSlot: Signal[T] = slot
200+
# # static:
201201
block:
202202
## statically verify signal / slot types match
203203
# echo "TYP: ", repr typeof(SignalTypes.`signal`(typeof(a)))
@@ -207,15 +207,15 @@ template connect*[T](
207207
discard
208208
else:
209209
signalType = slotType
210-
a.addAgentListeners(signalName(signal), b, agentSlot)
210+
a.addAgentListeners(signalName(signal), b, slot)
211211
212212
template connect*(
213213
a: Agent,
214214
signal: typed,
215215
b: Agent,
216216
slot: typed,
217217
acceptVoidSlot: static bool = false,
218-
) =
218+
): void =
219219
let agentSlot = `slot`(typeof(b))
220220
block:
221221
## statically verify signal / slot types match

figuro/ui/apis.nim

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ import std/[hashes]
77

88
import commons, core
99

10+
from std/sugar import capture
11+
1012
export core, cssgrid, stack_strings
1113
export with
14+
export capture
1215

1316
# template nodes*[T](fig: T, blk: untyped): untyped =
1417
# ## begin drawing nodes
@@ -86,13 +89,13 @@ proc boxFrom*(current: Figuro, x, y, w, h: float32) =
8689
# ## Note: Experimental!
8790
# nodeImpl(nkDrawable, id, inner)
8891

89-
template rectangle*(id: static string, args: varargs[untyped]): untyped =
92+
template rectangle*(name: string, blk: untyped): auto =
9093
## Starts a new rectangle.
91-
nodeImpl(nkRectangle, id, args)
94+
widget[BasicFiguro](nkRectangle, name, blk)
9295
93-
template text*(id: string, inner: untyped): untyped =
96+
template text*(name: string, blk: untyped): auto =
9497
## Starts a new rectangle.
95-
nodeImpl(nkText, id, inner)
98+
widget[BasicFiguro](nkText, name, blk)
9699
97100
## ---------------------------------------------
98101
## Fidget Node APIs
@@ -472,15 +475,17 @@ proc gridTemplateDebugLines*(node: Figuro, grid: Figuro, color: Color = blueColo
472475
let w = grid.gridTemplate.columns[^1].start.UICoord
473476
let h = grid.gridTemplate.rows[^1].start.UICoord
474477
for col in grid.gridTemplate.columns[1..^2]:
475-
rectangle "column", captures=col:
476-
with node:
477-
fill color
478-
box ux(col.start.UICoord - wd), 0'ux, wd.ux(), h.ux()
478+
capture col:
479+
rectangle "column":
480+
with node:
481+
fill color
482+
box ux(col.start.UICoord - wd), 0'ux, wd.ux(), h.ux()
479483
for row in grid.gridTemplate.rows[1..^2]:
480-
rectangle "row", captures=row:
481-
with node:
482-
fill color
483-
box 0, row.start.UICoord - wd, w.UICoord, wd
484+
capture row:
485+
rectangle "row":
486+
with node:
487+
fill color
488+
box 0, row.start.UICoord - wd, w.UICoord, wd
484489
rectangle "edge":
485490
with node:
486491
fill color.darken(0.5)

0 commit comments

Comments
 (0)