mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-12-01 07:24:56 -10:00
Compare commits
556
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8b1d6bd938 | ||
|
|
d5a5f35595 | ||
|
|
ee0918e1de | ||
|
|
d650ea3c8c | ||
|
|
ea7acc749a | ||
|
|
43be58e003 | ||
|
|
aaff28f63a | ||
|
|
7a206a973f | ||
|
|
851cf43f2a | ||
|
|
e735051005 | ||
|
|
9720e4e4fd | ||
|
|
fa03494f04 | ||
|
|
f342f6fa08 | ||
|
|
5d7ae25c87 | ||
|
|
b4af039c14 | ||
|
|
fc850de7f3 | ||
|
|
74b9162a9f | ||
|
|
b234cdfb21 | ||
|
|
4a080571a2 | ||
|
|
16f8d6d634 | ||
|
|
37e19eabe3 | ||
|
|
1eb215ee0e | ||
|
|
65f1ed71ca | ||
|
|
6109c13f25 | ||
|
|
84b95608d0 | ||
|
|
2cd6f10299 | ||
|
|
ce95bc3ec0 | ||
|
|
e304c1d879 | ||
|
|
e4df7e6416 | ||
|
|
45863723c6 | ||
|
|
accc54bb24 | ||
|
|
df70f56188 | ||
|
|
e9dfe08996 | ||
|
|
0ca3625252 | ||
|
|
ada0914959 | ||
|
|
79949226ae | ||
|
|
0c7fc3214f | ||
|
|
ae2307b9b0 | ||
|
|
83e031f0d2 | ||
|
|
f9bdac7fd2 | ||
|
|
9b9ea5741d | ||
|
|
678c22644f | ||
|
|
b82d9de927 | ||
|
|
8ae2df47fb | ||
|
|
71fdf3746a | ||
|
|
8d2645e20c | ||
|
|
704af633b7 | ||
|
|
d5bb1396ec | ||
|
|
9bfbc20d87 | ||
|
|
45d6f1bd39 | ||
|
|
38c6685e7f | ||
|
|
cca178384e | ||
|
|
5fb67897de | ||
|
|
9fbd44d21d | ||
|
|
89617462b6 | ||
|
|
26f4c655a1 | ||
|
|
bf0f3510df | ||
|
|
9dfb5bd733 | ||
|
|
9cca3f0e1e | ||
|
|
4a22f23d43 | ||
|
|
950c3afbb5 | ||
|
|
2a86112a93 | ||
|
|
a41fdb3d75 | ||
|
|
f09eb73c08 | ||
|
|
a41b362fe2 | ||
|
|
28e5d1bdc9 | ||
|
|
64adde1ced | ||
|
|
d7f35259c9 | ||
|
|
1c88592fa4 | ||
|
|
ae1ff71f45 | ||
|
|
0e0687c8cb | ||
|
|
29540adc8f | ||
|
|
1356139559 | ||
|
|
35e77de9fe | ||
|
|
ca615fd6fc | ||
|
|
ed738b8e5c | ||
|
|
d2d372d875 | ||
|
|
da3ffa1721 | ||
|
|
9181a62e99 | ||
|
|
c00eb21a7f | ||
|
|
be42a0aada | ||
|
|
11436cfc80 | ||
|
|
a43b3eaa00 | ||
|
|
a1dfe52b70 | ||
|
|
65ba494b14 | ||
|
|
e54b348166 | ||
|
|
fb6a0f9460 | ||
|
|
93a1b1f456 | ||
|
|
8a93b47788 | ||
|
|
b9a8065eb8 | ||
|
|
d5e31c23bb | ||
|
|
8d4f1346a1 | ||
|
|
26d67eb48b | ||
|
|
2196d308a7 | ||
|
|
57c01ed413 | ||
|
|
a0df7c2513 | ||
|
|
f6b4ce71e6 | ||
|
|
8504564f5d | ||
|
|
bf217169f6 | ||
|
|
5af465ce36 | ||
|
|
860174c08e | ||
|
|
c4da22f4a4 | ||
|
|
804831a1ca | ||
|
|
76f0956c2c | ||
|
|
84bdc593ae | ||
|
|
3d3ed7ab01 | ||
|
|
f045b87daf | ||
|
|
7ec885e7c7 | ||
|
|
343969561e | ||
|
|
4e1426eb67 | ||
|
|
c616bd2238 | ||
|
|
faa20bd041 | ||
|
|
3aad7ee8ae | ||
|
|
fdadd9cc0d | ||
|
|
77f7e654e8 | ||
|
|
dfec7c9e4b | ||
|
|
7aec563210 | ||
|
|
7add2adea6 | ||
|
|
4c911f6aa0 | ||
|
|
4f49c000e8 | ||
|
|
9556904aed | ||
|
|
20eb5ccb8a | ||
|
|
04d6c0d5cf | ||
|
|
83cfd0225a | ||
|
|
194c3d0a72 | ||
|
|
8e233d3229 | ||
|
|
9dd1e2bdf9 | ||
|
|
149e1fc4e0 | ||
|
|
d1f7db77ed | ||
|
|
4993a5f6d3 | ||
|
|
8918c43b08 | ||
|
|
d218e408fd | ||
|
|
d4dc2e9e6b | ||
|
|
c3755b3eb7 | ||
|
|
d04e94f549 | ||
|
|
362b54dafa | ||
|
|
5356a9fe7e | ||
|
|
71c15802d0 | ||
|
|
c1704df0b3 | ||
|
|
44f46c12b5 | ||
|
|
5e2398be74 | ||
|
|
de93fa40fb | ||
|
|
3bdec5d005 | ||
|
|
e6bbfe2ea1 | ||
|
|
0a4e03beb9 | ||
|
|
2157ce700c | ||
|
|
7fb55cf59f | ||
|
|
652c1c0e1b | ||
|
|
781aef5f2e | ||
|
|
0a4288eca6 | ||
|
|
5baeb8fd46 | ||
|
|
f04d439b33 | ||
|
|
6e22d6a412 | ||
|
|
5eb80721dd | ||
|
|
fc94487d0b | ||
|
|
37c0d0852d | ||
|
|
9b92edc0e9 | ||
|
|
348e9022a6 | ||
|
|
0001cdf04d | ||
|
|
c2845def11 | ||
|
|
b8bd9499fc | ||
|
|
e92ced1e4a | ||
|
|
e322d8957d | ||
|
|
296185b7fc | ||
|
|
b321c094d2 | ||
|
|
d4768d606f | ||
|
|
148008c695 | ||
|
|
2b5845464c | ||
|
|
5e388cb38f | ||
|
|
49daf2895e | ||
|
|
682d3dafbd | ||
|
|
ad03b5b0bf | ||
|
|
324925aedb | ||
|
|
e78a987e3e | ||
|
|
2c8fa44eb4 | ||
|
|
6b22316077 | ||
|
|
98cabee4c6 | ||
|
|
e0848abc59 | ||
|
|
f237a5ee50 | ||
|
|
df99ab3a72 | ||
|
|
0fc4424a09 | ||
|
|
e9a3199456 | ||
|
|
ef8312806d | ||
|
|
548cbfbf4e | ||
|
|
313c591f70 | ||
|
|
f07f708ee8 | ||
|
|
5f73044b6b | ||
|
|
11aedd8196 | ||
|
|
f4f266b1ba | ||
|
|
77e4e8c894 | ||
|
|
c231bd0eb8 | ||
|
|
095e0bb4ff | ||
|
|
369f7db992 | ||
|
|
79750fb52d | ||
|
|
f7360688f2 | ||
|
|
00920823aa | ||
|
|
0426a01e82 | ||
|
|
02f9cf3e6b | ||
|
|
33f7257e47 | ||
|
|
2921f44e5c | ||
|
|
1e91511f93 | ||
|
|
daf0231c0c | ||
|
|
92adc524ca | ||
|
|
9f0e0ebc96 | ||
|
|
a911bcc165 | ||
|
|
5bedfa4d11 | ||
|
|
e52af0cee0 | ||
|
|
fbdba0e545 | ||
|
|
6cdab6b95d | ||
|
|
e92faf763d | ||
|
|
305c36fb25 | ||
|
|
fc9e69a7a7 | ||
|
|
c9525d76c4 | ||
|
|
451922c217 | ||
|
|
92ea594a2a | ||
|
|
9d3abe385f | ||
|
|
96521333d6 | ||
|
|
d80651e85c | ||
|
|
a16a4c6354 | ||
|
|
d294d75198 | ||
|
|
8f7d3936f8 | ||
|
|
6961687172 | ||
|
|
38d479bdfa | ||
|
|
14660bdb64 | ||
|
|
b362452ff2 | ||
|
|
30573e6eb6 | ||
|
|
9ac039074d | ||
|
|
fdde760259 | ||
|
|
1be90ebb4a | ||
|
|
8fa250a9f9 | ||
|
|
0b70b18338 | ||
|
|
40efbc3261 | ||
|
|
39ce55ab61 | ||
|
|
3e1a9a1acf | ||
|
|
ab93e1f071 | ||
|
|
aa50c42930 | ||
|
|
c73976f407 | ||
|
|
cac1c47b86 | ||
|
|
1426f6401f | ||
|
|
6b951c1806 | ||
|
|
1f860aae6a | ||
|
|
e415714b04 | ||
|
|
a6016b2c03 | ||
|
|
c12f8f1115 | ||
|
|
4e7d72d4b8 | ||
|
|
41d42fe794 | ||
|
|
21dfe04bf8 | ||
|
|
0f26893ec1 | ||
|
|
0cd428f1b1 | ||
|
|
39ed962e16 | ||
|
|
6a5417ed3d | ||
|
|
29052a58db | ||
|
|
84d11b9285 | ||
|
|
5a6192bbd6 | ||
|
|
ca831c00db | ||
|
|
fe8ca88752 | ||
|
|
8fd2529e27 | ||
|
|
641fcc88c6 | ||
|
|
78e35eb6ea | ||
|
|
3302a3b0b8 | ||
|
|
41d295f140 | ||
|
|
a955d6b458 | ||
|
|
97bc10e4c3 | ||
|
|
3af6834d3c | ||
|
|
277641d27e | ||
|
|
f3e945c5d8 | ||
|
|
aef750153b | ||
|
|
f4d37524c8 | ||
|
|
e5b910f840 | ||
|
|
25f49e8750 | ||
|
|
1ef7c9c2c2 | ||
|
|
f34ec257e7 | ||
|
|
1e5b2c7f62 | ||
|
|
c6b669fc88 | ||
|
|
d814b610da | ||
|
|
5181c74205 | ||
|
|
4cb711e3f8 | ||
|
|
e8aea0728a | ||
|
|
6f809fda73 | ||
|
|
ba84e2a968 | ||
|
|
72387d17ad | ||
|
|
048a4c4b70 | ||
|
|
b262195549 | ||
|
|
68a2fb2be3 | ||
|
|
50911a6a25 | ||
|
|
79f3571b02 | ||
|
|
34ea9c59fd | ||
|
|
92ec2069ad | ||
|
|
20e70e7bc9 | ||
|
|
084f14e973 | ||
|
|
694d3d34b3 | ||
|
|
ed457093b1 | ||
|
|
7d44f6ec9e | ||
|
|
54c140e4f3 | ||
|
|
5987c449b2 | ||
|
|
c7605d12a6 | ||
|
|
d9533de9ea | ||
|
|
bc33e14c35 | ||
|
|
2b06d27729 | ||
|
|
b685ca77f2 | ||
|
|
e5b1fad675 | ||
|
|
eb11eec5bb | ||
|
|
182c2a1554 | ||
|
|
913d7093ea | ||
|
|
938fc1783a | ||
|
|
d452ac0de1 | ||
|
|
95bbeb6634 | ||
|
|
5176bfd331 | ||
|
|
db761cf8ed | ||
|
|
34e03038df | ||
|
|
bb3643541d | ||
|
|
ff99f3605c | ||
|
|
9cf037e992 | ||
|
|
888cdf17b0 | ||
|
|
9aef511891 | ||
|
|
0d88e8be9f | ||
|
|
56d38b3f61 | ||
|
|
a6c56c8655 | ||
|
|
2c84bb478f | ||
|
|
9cdaf06ca9 | ||
|
|
027218f16c | ||
|
|
f1ccb74625 | ||
|
|
cb5fabc6ad | ||
|
|
2448157af8 | ||
|
|
d718cdb225 | ||
|
|
dcc9059041 | ||
|
|
d70eae205d | ||
|
|
ed6922d7eb | ||
|
|
abb099a1c3 | ||
|
|
a4d01bfd11 | ||
|
|
d38c767312 | ||
|
|
aba941e81d | ||
|
|
8c67ad508f | ||
|
|
9ca897963f | ||
|
|
2575b94e8f | ||
|
|
b03e4fb215 | ||
|
|
c0eb2ee4ff | ||
|
|
faa5c9d3db | ||
|
|
bedb0d4159 | ||
|
|
94b9d279a2 | ||
|
|
7c4b029d76 | ||
|
|
9ba3c16e79 | ||
|
|
511b4da9f5 | ||
|
|
2c15dc838e | ||
|
|
73b2ef1d58 | ||
|
|
9d2031f7d0 | ||
|
|
7b609ea781 | ||
|
|
5e918af371 | ||
|
|
6e9cac3b32 | ||
|
|
893cbfe450 | ||
|
|
e40ee486a9 | ||
|
|
58182bc2d3 | ||
|
|
3fb8b10f80 | ||
|
|
6fe533a875 | ||
|
|
feea006fc3 | ||
|
|
73897111d0 | ||
|
|
e76dcb15aa | ||
|
|
538959ea90 | ||
|
|
c33f8ae75b | ||
|
|
3126a5b278 | ||
|
|
5f6c18893e | ||
|
|
cdc6f11d92 | ||
|
|
c4b22c03b9 | ||
|
|
6ab9d0360a | ||
|
|
01da817f61 | ||
|
|
040bd71f82 | ||
|
|
f2b0f7c533 | ||
|
|
a2918887f6 | ||
|
|
7b993c5de6 | ||
|
|
3da7f6cea3 | ||
|
|
7569bdb9cb | ||
|
|
4e8a44650e | ||
|
|
b4346fd47d | ||
|
|
e9a18a6437 | ||
|
|
77b0be5c15 | ||
|
|
4bceae26f2 | ||
|
|
c0f50d41d7 | ||
|
|
0b2aa3798a | ||
|
|
13cd718c90 | ||
|
|
39c7ba39cf | ||
|
|
6635e0aeff | ||
|
|
98dabd7ff5 | ||
|
|
a244cc13d0 | ||
|
|
fb71ea426d | ||
|
|
217f32eb88 | ||
|
|
7fb36123e9 | ||
|
|
46220ac268 | ||
|
|
887dbaca2c | ||
|
|
44369cb12b | ||
|
|
56c772de4c | ||
|
|
93e34d00e5 | ||
|
|
46f048b07c | ||
|
|
4b130b4319 | ||
|
|
da0f70bb5f | ||
|
|
5821816228 | ||
|
|
8eaa541c8c | ||
|
|
e4adf16eba | ||
|
|
a8d257e7d6 | ||
|
|
49c592013c | ||
|
|
80db9c13c8 | ||
|
|
cf87796072 | ||
|
|
8859e6b1a0 | ||
|
|
1f23991a72 | ||
|
|
2be252d7b4 | ||
|
|
2c1acbdc62 | ||
|
|
61e751f278 | ||
|
|
cdd62ed269 | ||
|
|
f12094ced6 | ||
|
|
b5c4aa4598 | ||
|
|
da8ae2be43 | ||
|
|
157c011953 | ||
|
|
ae6807f8e3 | ||
|
|
17ba74485a | ||
|
|
1f2eef5f8f | ||
|
|
1b6513b954 | ||
|
|
74fddff589 | ||
|
|
7e24f810c6 | ||
|
|
306cf1110f | ||
|
|
b610eede20 | ||
|
|
21f671555a | ||
|
|
951059aa3a | ||
|
|
e68254eff3 | ||
|
|
61cf619f4b | ||
|
|
7914a09d4b | ||
|
|
95e2cbca15 | ||
|
|
724bb0fc17 | ||
|
|
fb171cd5ac | ||
|
|
cb46be0430 | ||
|
|
7ffc9b9e3b | ||
|
|
58a65c69e9 | ||
|
|
d1d50ec469 | ||
|
|
e25e32ee8a | ||
|
|
d560a39856 | ||
|
|
00e08359a3 | ||
|
|
116ce622d4 | ||
|
|
082fb5d959 | ||
|
|
043f28cc23 | ||
|
|
b7413dd22c | ||
|
|
586737247e | ||
|
|
055b7f0055 | ||
|
|
4a042bade2 | ||
|
|
3aa018a15c | ||
|
|
8508dc6c9d | ||
|
|
fbba0cd037 | ||
|
|
ae7c51a964 | ||
|
|
0c49026c9a | ||
|
|
bc29166d4c | ||
|
|
0f3e3f7337 | ||
|
|
a03db0ac6c | ||
|
|
932ed8653e | ||
|
|
5ab3f067fe | ||
|
|
3df028cb18 | ||
|
|
e423dd96de | ||
|
|
bef58bf395 | ||
|
|
131abf5883 | ||
|
|
3859bd713e | ||
|
|
ac40f1838f | ||
|
|
9055a5f3d5 | ||
|
|
d32caeab52 | ||
|
|
15f4aa8f98 | ||
|
|
99ce2ea565 | ||
|
|
87200f3c2a | ||
|
|
214632c5ec | ||
|
|
64fb4eda61 | ||
|
|
f9e30c4c77 | ||
|
|
bfa48439c8 | ||
|
|
a717403db8 | ||
|
|
fdf13f91cb | ||
|
|
65e0969721 | ||
|
|
8f265e7660 | ||
|
|
98e6b97072 | ||
|
|
a3e9074955 | ||
|
|
04afada5b3 | ||
|
|
3e183fbd28 | ||
|
|
849d6a17be | ||
|
|
20ba069fe0 | ||
|
|
c82093f153 | ||
|
|
010785d8db | ||
|
|
69774d445c | ||
|
|
b42c632474 | ||
|
|
f195e363a5 | ||
|
|
40f99152ce | ||
|
|
3b1170b148 | ||
|
|
3a20091d3a | ||
|
|
e5206c3b50 | ||
|
|
fbc736e1cc | ||
|
|
d7da2ba9e7 | ||
|
|
a5784c8f0b | ||
|
|
83fbaca6f2 | ||
|
|
b6f73b0691 | ||
|
|
557f8020bb | ||
|
|
fb94d99807 | ||
|
|
264601c5f7 | ||
|
|
5db7e1816a | ||
|
|
5b02edfd9a | ||
|
|
7c0a4073e9 | ||
|
|
275100eab0 | ||
|
|
42cd2a4303 | ||
|
|
e4f81fc947 | ||
|
|
492cf18cb0 | ||
|
|
05630bab6e | ||
|
|
a465948ad4 | ||
|
|
63cf0151e2 | ||
|
|
9c7a633d5b | ||
|
|
166241b0e8 | ||
|
|
ea49f3c2fc | ||
|
|
100f81c307 | ||
|
|
886ff03ef2 | ||
|
|
7a1d1f3238 | ||
|
|
612afb7ebb | ||
|
|
daf3f25d21 | ||
|
|
a2de2a9c09 | ||
|
|
98be2b8c79 | ||
|
|
83fda4f08c | ||
|
|
20c6ba19d3 | ||
|
|
7eeb7d84cd | ||
|
|
7ddc66adbe | ||
|
|
c20a243fc2 | ||
|
|
3eecc31bfd | ||
|
|
7099f056dc | ||
|
|
9680d34abf | ||
|
|
592b2fbe32 | ||
|
|
60f80682c5 | ||
|
|
9fc4fcc7a0 | ||
|
|
7915800d73 | ||
|
|
c91be74a55 | ||
|
|
abe2a565d1 | ||
|
|
6154e4d219 | ||
|
|
62b7ccf40c | ||
|
|
9b45af854a | ||
|
|
562e6602eb | ||
|
|
8fb18012cf | ||
|
|
2b3161773f | ||
|
|
167d733f02 | ||
|
|
ee499be31f | ||
|
|
d385f3c69b | ||
|
|
e372f78b7e | ||
|
|
8686b2c891 | ||
|
|
e3aa32bc83 | ||
|
|
77d439ec35 | ||
|
|
c30054579f | ||
|
|
81a319430b | ||
|
|
1fb6fcb447 | ||
|
|
32d244e700 | ||
|
|
0877f9d50e | ||
|
|
14c1dd0397 | ||
|
|
daf7b3e7b9 | ||
|
|
bdf53070f2 | ||
|
|
0d0ec96709 | ||
|
|
6feaf4ec9d | ||
|
|
5541769dc5 | ||
|
|
1fccb112cb | ||
|
|
eb50be844b | ||
|
|
0f0f62c2e9 | ||
|
|
f5b1fee85f | ||
|
|
6f8c4b2adb |
No files matched your search
+9
-1
@@ -1,6 +1,14 @@
|
||||
# Keep `--cfg=web_sys_unstable_apis` here so the wasm wrapper crates build with the same web-sys API signatures (e.g. `put_image_data`/`get_image_data` taking `i32` rather than `f64`) on both native and the wasm target.
|
||||
[target.'cfg(not(target_family = "wasm"))']
|
||||
rustflags = ["--cfg=web_sys_unstable_apis"]
|
||||
# Frame pointers keep the native build profileable: the record model puts ~1KB frames on the stack and
|
||||
# recurses past a hundred of them, so a sampling profiler copying a fixed slice of stack unwinds a frame
|
||||
# or two and reports every sample as its own root. This must live here rather than under `[build]`, which
|
||||
# Cargo ignores whenever any `target.*` section matches.
|
||||
# A build id is what a profiler matches a recorded module against when it goes looking for symbols;
|
||||
# the linker here does not emit one on its own, and without it an imported profile is all addresses.
|
||||
# It has to be the `uuid` style: perf stores a 20 byte id, and the other styles here produce 32 bytes,
|
||||
# which perf truncates and the profiler then reads as a mismatch against the file it was told to use.
|
||||
rustflags = ["--cfg=web_sys_unstable_apis", "-C", "force-frame-pointers=yes", "-C", "link-arg=-Wl,--build-id=uuid"]
|
||||
|
||||
[target.'cfg(target_family = "wasm")']
|
||||
rustflags = [
|
||||
|
||||
Generated
+381
-287
File diff suppressed because it is too large.
Load diff
-11
@@ -15,7 +15,6 @@ members = [
|
||||
"frontend/wrapper",
|
||||
"libraries/dyn-any",
|
||||
"libraries/math-parser",
|
||||
"libraries/ipsum",
|
||||
"libraries/wgpu-sync",
|
||||
"node-graph/libraries/graphene-hash",
|
||||
"node-graph/libraries/*",
|
||||
@@ -41,7 +40,6 @@ default-members = [
|
||||
"frontend/wrapper",
|
||||
"libraries/dyn-any",
|
||||
"libraries/math-parser",
|
||||
"libraries/ipsum",
|
||||
"node-graph/graph-craft",
|
||||
"node-graph/interpreted-executor",
|
||||
"node-graph/node-macro",
|
||||
@@ -107,7 +105,6 @@ wgpu-sync = { path = "libraries/wgpu-sync" }
|
||||
graphite-proc-macros = { path = "proc-macros" }
|
||||
graphite-editor = { path = "editor" }
|
||||
graphene-canvas-utils = { path = "node-graph/libraries/canvas-utils" }
|
||||
ipsum = { path = "libraries/ipsum" }
|
||||
|
||||
# Workspace dependencies
|
||||
rustc-hash = "2.0"
|
||||
@@ -195,13 +192,6 @@ image = { version = "0.25", default-features = false, features = [
|
||||
"jpeg",
|
||||
"bmp",
|
||||
"gif",
|
||||
"webp",
|
||||
"tiff",
|
||||
"ico",
|
||||
"tga",
|
||||
"hdr",
|
||||
"exr",
|
||||
"serde",
|
||||
] }
|
||||
pretty_assertions = "1.4"
|
||||
fern = { version = "0.7", features = ["colored"] }
|
||||
@@ -270,7 +260,6 @@ lto = "thin"
|
||||
debug = true
|
||||
|
||||
[patch.crates-io]
|
||||
winit = { git = "https://github.com/timon-schelling/winit", branch = "graphite" }
|
||||
rfd = { git = "https://github.com/timon-schelling/rfd.git", branch = "graphite" } # TODO: Remove this once https://github.com/PolyMeilex/rfd/pull/317 is merged and released
|
||||
cef = { git = "https://github.com/timon-schelling/cef-rs.git", branch = "graphite-151" }
|
||||
cef-dll-sys = { git = "https://github.com/timon-schelling/cef-rs.git", branch = "graphite-151" }
|
||||
@@ -0,0 +1,146 @@
|
||||
# Index-level narrowing: investigation state
|
||||
|
||||
Branch `brick-wave-investigation`. Why `~/Downloads/brick-waves.graphite` gets no caching around its
|
||||
palette lookup, what we changed, and where it still breaks.
|
||||
|
||||
## The original problem
|
||||
|
||||
`read_index` takes its *Loop Level* as a runtime input, so its signature can only declare
|
||||
`ExtractIndices` → `ContextFeature::ExtractIndex(u8::MAX)` → `IndexLevels::all()`.
|
||||
|
||||
A saturated mask is absorbing in both places it is consumed:
|
||||
|
||||
- `nullify_index_levels` (`core-types/src/context.rs:283`) early-returns on `is_all()`, so nothing is
|
||||
nullified
|
||||
- `IndexLevels::lifted` (`context.rs:253`) has `u32::MAX => self`, so propagation never narrows it
|
||||
- `ContextModification::contains` therefore always succeeds, so `we_introduce_new_deps` is false and
|
||||
**no cache boundary is ever inserted anywhere in the cone**
|
||||
|
||||
In `brick-waves` the whole palette chain (`StringValue → split → item_at_index → join → split →
|
||||
item_at_index → join → hex_to_color`) sits under this, and re-derives per lane: 36864 evaluations
|
||||
where 96 would do.
|
||||
|
||||
## What we built (all in the preprocessor, none of it node-specific in the compiler)
|
||||
|
||||
`node-graph/preprocessor/src/lib.rs`:
|
||||
|
||||
1. `restore_declared_context_features` — re-declares `extract`/`inject`/`index_levels` from the
|
||||
registry. A document serializes `extract`/`inject` (so it can carry a declaration from an older
|
||||
build) and `index_levels` is `#[serde(skip)]`, so the field was only ever trustworthy by accident.
|
||||
2. `determine_index_reads` — when `loop_level` is a literal, narrows `index_levels` to
|
||||
`{loop_level + 1}` (the kernel reads `nth(loop_level + 1)`).
|
||||
3. `expand_network` — carries the wrapper's declaration onto the substituted proto node. Needed
|
||||
because a substitution replaces `implementation` with a template network, and the declaration
|
||||
would otherwise stay on the wrapper that `flatten` dissolves.
|
||||
|
||||
**Verified neutral**: with narrowing disabled (`LEVEL_MODE=off`) the render is byte-identical to
|
||||
baseline (`md5 87fd5f79b006`). So 1 and 3 are sound on their own.
|
||||
|
||||
## What narrowing achieves, and how it breaks
|
||||
|
||||
Masks stop being saturated: precise `{1,2,3,4,6,7}` appear, boundaries go 82 → 109.
|
||||
|
||||
`read_index` itself is **correct** under narrowing — verified at runtime, not inferred:
|
||||
|
||||
| mode | chain seen | value | distinct chains |
|
||||
|---|---|---|---|
|
||||
| `LEVEL_MODE=only0` | `[0, 0, N, 0]` depth 4 | `nth(2) = N` | 36864 |
|
||||
| narrowed | `[0, 0, N]` depth 3 | `nth(2) = N` | **96** |
|
||||
|
||||
Both return the full range 0..95. Nullification strips only the trailing zeroed level and the read
|
||||
still lands on `N`. That is the 384× win we were after.
|
||||
|
||||
But `hex_to_color` receives **1 distinct hex string instead of 63**, and the render collapses from 65
|
||||
colors to 3. So the correct values are lost *downstream* of `read_index`, in the string chain.
|
||||
|
||||
## Ruled out
|
||||
|
||||
- **Off-by-one in the declared level.** Declaring 2, 3, or 4 for the `loop_level=1` reader gives
|
||||
byte-identical broken output. The mask *value* is irrelevant; only its non-saturation matters.
|
||||
- **Keeping level 0 as well.** No change.
|
||||
- **`InjectIndex` falsely discharging the requirement.** `ContextFeature::InjectIndex → INDEX` exists
|
||||
(`context.rs:534`) but the macro never emits it (`parsing.rs:1041`), so `inject` never contains
|
||||
`INDEX`. `new_deps &= !inject` never clears it and `we_supply_existing_deps` never fires for it.
|
||||
The feature is never falsely discharged — only the *level* arithmetic discharges.
|
||||
- **A node overstating `pushed_levels`.** `PROBE_LEVELS` dumps every lift. The only requirement
|
||||
deaths are legitimate lane-drives (`ItemAtIndex` on `list`, `Fill` on its color inputs, …). The two
|
||||
`Repeat`s consume exactly the two levels `read_index` declares: `{0,1,2} → {0,1} → {0}`. The
|
||||
boundary mask follows correctly from the declarations.
|
||||
- **The split/item/join level arithmetic alone.** See the repro below — it does not collapse.
|
||||
|
||||
Narrowing only the `loop_level=0` reader (`LEVEL_MODE=only0`) is byte-identical to baseline and adds
|
||||
4 boundaries, but measures the same as `off` (10s vs 10s over 8 repeats, debug). No partial win to
|
||||
bank; the payoff needs the outer-loop reader.
|
||||
|
||||
## Minimal reproduction (does NOT yet reproduce)
|
||||
|
||||
`proto::test::nested_index_lookup_boundary_levels` in `graph-craft/src/proto.rs`, with helpers
|
||||
`nested_index_lookup_network` and `index_level_boundaries`.
|
||||
|
||||
Builds `split → item_at_index → join` twice against two resolved-level `read_index` nodes, plus two
|
||||
more level-consuming hops standing in for the `Repeat`s. Masks come out `0, 2, 1, 0, 1, 0` — every
|
||||
boundary keeps a level its subtree reads. **No collapse.**
|
||||
|
||||
It is committed as a *characterization* test, not a correctness assertion: an earlier assertion
|
||||
("a boundary requiring INDEX must retain some level") passed for the wrong reason, because the real
|
||||
failure is mask `{0}` above content that varies over deeper levels, not an empty mask. That invariant
|
||||
can't be written until the intended semantics are settled.
|
||||
|
||||
## Leading hypothesis
|
||||
|
||||
The missing ingredient is the real `Repeat`. `string_join` only *consumes* a level; `Repeat` also
|
||||
**injects an index at runtime**. That asymmetry is where the model's two jobs diverge:
|
||||
`ContextModification` computes a cache key *and* rewrites the chain the subtree receives. "A `Repeat`
|
||||
supplies this level, so the requirement vanishes above it" is sound for the **key** — nothing above
|
||||
the `Repeat` varies over it — but the subtree below still evaluates against whatever chain survives.
|
||||
|
||||
`repeat-nodes` is not a `graph-craft` dependency, so a repro including it belongs in
|
||||
`interpreted-executor`, asserting on evaluated values rather than masks.
|
||||
|
||||
## Env gates (all inert when unset)
|
||||
|
||||
| var | where | effect |
|
||||
|---|---|---|
|
||||
| `LEVEL_MODE=off` | preprocessor | disable narrowing → byte-identical to baseline |
|
||||
| `LEVEL_MODE=only0` / `only1` | preprocessor | narrow only that `loop_level` |
|
||||
| `LEVEL_BUMP=N` | preprocessor | add N to declared level for `loop_level >= 1` |
|
||||
| `PROBE_LEVELS` | `proto.rs` | dump every `lifted` call that changes a mask |
|
||||
| `PROBE_READ_INDEX` | `gcore/src/context.rs` | dump each newly seen chain + value |
|
||||
| `PROBE_HEX` | `math/src/lib.rs` | dump distinct `hex_to_color` inputs |
|
||||
|
||||
**Narrowing is ON by default, so the tree renders wrong.** Use `LEVEL_MODE=only0` for a correct run.
|
||||
Remove the probes and the `LEVEL_MODE`/`LEVEL_BUMP` block before this is fit to merge.
|
||||
|
||||
## Artwork
|
||||
|
||||
Committed under `test-artwork/`:
|
||||
|
||||
- `brick-waves-v3.graphite` — the migrated working copy. **Every measurement in this document used
|
||||
this file**; it is the one known to reproduce.
|
||||
- `brick-waves.graphite` — the original as saved from the editor. Kept so nothing is lost, but it
|
||||
**does not load on this branch**:
|
||||
|
||||
```
|
||||
GraphError { identifier: "graphic_nodes::graphic::ToGraphicNode", error: "No implementations found" }
|
||||
```
|
||||
|
||||
It predates the rebase, so it needs a migration that does not exist here yet. Use the v3 copy.
|
||||
|
||||
## Repro commands
|
||||
|
||||
```sh
|
||||
cargo build -p graphene-cli
|
||||
ART=test-artwork/brick-waves-v3.graphite
|
||||
|
||||
# correct vs broken
|
||||
LEVEL_MODE=only0 ./target/debug/graphene-cli export $ART -o ok.svg # 65 colors
|
||||
./target/debug/graphene-cli export $ART -o bad.svg # 3 colors
|
||||
grep -o 'fill="#[0-9a-f]*"' bad.svg | sort -u | wc -l
|
||||
|
||||
# where distinctness is lost
|
||||
PROBE_READ_INDEX=1 ./target/debug/graphene-cli export $ART -o p.svg # read_index: correct, 96 values
|
||||
PROBE_HEX=1 ./target/debug/graphene-cli export $ART -o h.svg # hex_to_color: 1 input, should be 63
|
||||
|
||||
# compile-time masks (note: -o /dev/null short-circuits evaluation, use a real file)
|
||||
./target/debug/graphene-cli compile -p $ART | grep -o "index_levels: IndexLevels([0-9]*)" | sort | uniq -c
|
||||
```
|
||||
Generated
+1
-1
@@ -1 +1 @@
|
||||
{"network_interface":{"network":{"exports":[{"Node":{"node_id":3143874172491239000,"output_index":0}}],"nodes":[[26023588519449590,{"inputs":[{"Node":{"node_id":4002029424845293600,"output_index":0}},{"Value":{"tagged_value":{"Color":{"red":0.94750905,"green":0.5567761,"blue":0.06654528,"alpha":1.0,"linear":true}},"exposed":false}},{"Value":{"tagged_value":{"Color":{"red":0.94750905,"green":0.5567761,"blue":0.06654528,"alpha":1.0,"linear":true}},"exposed":false}},{"Value":{"tagged_value":{"GradientRamp":{"stops":{"color":[{"red":1.0,"green":1.0,"blue":1.0,"alpha":1.0,"linear":true},{"red":0.0,"green":0.0,"blue":0.0,"alpha":1.0,"linear":true}],"position":[0.0,1.0],"midpoint":[0.5,0.5]},"gradient_space":"RgbGamma"}},"exposed":false}},{"Value":{"tagged_value":{"GradientForm":"Linear"},"exposed":false}},{"Value":{"tagged_value":{"Bool":true},"exposed":false}},{"Value":{"tagged_value":{"DAffine2":[0.0,-92.53735521402166,92.53735521402166,0.0,9.606221358397944,-69.72678572415595]},"exposed":false}}],"call_argument":{"Concrete":{"name":"core::option::Option<alloc::sync::Arc<core_types::context::OwnedContextImpl>>"}},"implementation":{"ProtoNode":{"name":"graphene_core::vector::FillNode"}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}],[213744308682803360,{"inputs":[{"Value":{"tagged_value":{"TypeDefault":{"List":{"Concrete":{"name":"graphic_types::graphic::Graphic"}}}},"exposed":true}},{"Node":{"node_id":10463288500489480000,"output_index":0}}],"call_argument":{"Generic":"T"},"implementation":{"Network":{"exports":[{"Node":{"node_id":5,"output_index":0}}],"nodes":[[0,{"inputs":[{"Import":{"import_type":{"Generic":"T"},"import_index":0}}],"call_argument":{"Concrete":{"name":"core::option::Option<alloc::sync::Arc<core_types::context::OwnedContextImpl>>"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::AsGraphicNode"}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}],[1,{"inputs":[{"Import":{"import_type":{"Generic":"T"},"import_index":1}}],"call_argument":{"Concrete":{"name":"core::option::Option<alloc::sync::Arc<core_types::context::OwnedContextImpl>>"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::IntoGroupNode"}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}],[2,{"inputs":[{"Reflection":"DocumentNodePath"}],"call_argument":{"Concrete":{"name":"core::option::Option<alloc::sync::Arc<core_types::context::OwnedContextImpl>>"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::PathOfSubgraphNode"}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}],[3,{"inputs":[{"Node":{"node_id":1,"output_index":0}},{"Value":{"tagged_value":{"String":"editor:layer_path"},"exposed":false}},{"Node":{"node_id":2,"output_index":0}}],"call_argument":{"Concrete":{"name":"core::option::Option<alloc::sync::Arc<core_types::context::OwnedContextImpl>>"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::WriteAttributeNode"}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}],[4,{"inputs":[{"Node":{"node_id":3,"output_index":0}}],"call_argument":{"Concrete":{"name":"core::option::Option<alloc::sync::Arc<core_types::context::OwnedContextImpl>>"}},"implementation":{"ProtoNode":{"name":"graphene_core::memo::MonitorNode"}},"visible":true,"skip_deduplication":true,"context_features":{"extract":"","inject":""}}],[5,{"inputs":[{"Node":{"node_id":0,"output_index":0}},{"Node":{"node_id":4,"output_index":0}}],"call_argument":{"Generic":"T"},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::ExtendNode"}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}]],"scope_injections":[]}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}],[366962978353611840,{"inputs":[{"Node":{"node_id":8366826746721323000,"output_index":0}},{"Value":{"tagged_value":{"BooleanOperation":"Union"},"exposed":false}}],"call_argument":{"Generic":"T"},"implementation":{"ProtoNode":{"name":"path_bool_nodes::BooleanOperationNode"}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}],[799182088624980700,{"inputs":[{"Node":{"node_id":7386572856931342000,"output_index":0}},{"Value":{"tagged_value":{"F64":100.0},"exposed":false}}],"call_argument":{"Concrete":{"name":"core::option::Option<alloc::sync::Arc<core_types::context::OwnedContextImpl>>"}},"implementation":{"ProtoNode":{"name":"math_nodes::DivideNode"}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}],[1250460246919467000,{"inputs":[{"Node":{"node_id":4742778578215475000,"output_index":0}},{"Value":{"tagged_value":{"BooleanOperation":"Union"},"exposed":false}}],"call_argument":{"Generic":"T"},"implementation":{"ProtoNode":{"name":"path_bool_nodes::BooleanOperationNode"}},"visible":true,"skip_deduplication":fLine truncated
|
||||
{"network_interface":{"network":{"exports":[{"Node":{"node_id":3143874172491239000,"output_index":0}}],"nodes":[[26023588519449590,{"inputs":[{"Node":{"node_id":4002029424845293600,"output_index":0}},{"Value":{"tagged_value":{"Color":{"red":0.94750905,"green":0.5567761,"blue":0.06654528,"alpha":1.0,"linear":true}},"exposed":false}},{"Value":{"tagged_value":{"Color":{"red":0.94750905,"green":0.5567761,"blue":0.06654528,"alpha":1.0,"linear":true}},"exposed":false}},{"Value":{"tagged_value":{"GradientRamp":{"stops":{"color":[{"red":1.0,"green":1.0,"blue":1.0,"alpha":1.0,"linear":true},{"red":0.0,"green":0.0,"blue":0.0,"alpha":1.0,"linear":true}],"position":[0.0,1.0],"midpoint":[0.5,0.5]},"gradient_space":"RgbGamma"}},"exposed":false}},{"Value":{"tagged_value":{"GradientForm":"Linear"},"exposed":false}},{"Value":{"tagged_value":{"Bool":true},"exposed":false}},{"Value":{"tagged_value":{"DAffine2":[0.0,-92.53735521402166,92.53735521402166,0.0,9.606221358397944,-69.72678572415595]},"exposed":false}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"graphene_core::vector::FillNode"}},"visible":true,"skip_deduplication":false}],[213744308682803360,{"inputs":[{"Value":{"tagged_value":{"TypeDefault":{"name":"core_types::list::List<graphic_types::graphic::Graphic>"}},"exposed":true}},{"Node":{"node_id":10463288500489480000,"output_index":0}}],"call_argument":{"Generic":"T"},"implementation":{"Network":{"exports":[{"Node":{"node_id":5,"output_index":0}}],"nodes":[[0,{"inputs":[{"Import":{"import_type":{"Generic":"T"},"import_index":0}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::AsGraphicNode"}},"visible":true,"skip_deduplication":false}],[1,{"inputs":[{"Import":{"import_type":{"Generic":"T"},"import_index":1}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::IntoGroupNode"}},"visible":true,"skip_deduplication":false}],[2,{"inputs":[{"Reflection":"DocumentNodePath"}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::PathOfSubgraphNode"}},"visible":true,"skip_deduplication":false}],[3,{"inputs":[{"Node":{"node_id":1,"output_index":0}},{"Node":{"node_id":2,"output_index":0}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::StampLayerPathNode"}},"visible":true,"skip_deduplication":false}],[4,{"inputs":[{"Node":{"node_id":3,"output_index":0}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"graphene_core::memo::MonitorNode"}},"visible":true,"skip_deduplication":true}],[5,{"inputs":[{"Node":{"node_id":0,"output_index":0}},{"Node":{"node_id":4,"output_index":0}}],"call_argument":{"Generic":"T"},"implementation":{"ProtoNode":{"name":"graphene_core::list::ExtendNode"}},"visible":true,"skip_deduplication":false}]],"scope_injections":[]}},"visible":true,"skip_deduplication":false}],[366962978353611840,{"inputs":[{"Node":{"node_id":8366826746721323000,"output_index":0}},{"Value":{"tagged_value":{"BooleanOperation":"Union"},"exposed":false}}],"call_argument":{"Generic":"T"},"implementation":{"ProtoNode":{"name":"path_bool_nodes::BooleanOperationNode"}},"visible":true,"skip_deduplication":false}],[799182088624980700,{"inputs":[{"Node":{"node_id":7386572856931342000,"output_index":0}},{"Value":{"tagged_value":{"F64":100.0},"exposed":false}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl<'_>"}},"implementation":{"ProtoNode":{"name":"math_nodes::DivideNode"}},"visible":true,"skip_deduplication":false}],[1250460246919467000,{"inputs":[{"Node":{"node_id":4742778578215475000,"output_index":0}},{"Value":{"tagged_value":{"BooleanOperation":"Union"},"exposed":false}}],"call_argument":{"Generic":"T"},"implementation":{"ProtoNode":{"name":"path_bool_nodes::BooleanOperationNode"}},"visible":true,"skip_deduplication":false}],[1789832635968548900,{"inputs":[{"Node":{"node_id":1924303400883620400,"output_index":0}},{"Value":{"tagged_value":{"Color":{"red":0.9822506,"green":0.20507872,"blue":0.012983031,"alpha":1.0,"linear":true}},"exposed":false}},{"Value":{"tagged_value":{"Color":{"red":1.0,"green":1.0,"blue":1.0,"alpha":0.25,"linear":true}},"exposed":false}},{"Value":{"tagged_value":{"GradientRamp":{"stops":{"color":[{"red":0.0,"green":0.0,"blue":0.0,"alpha":1.0,"linear":true},{"red":1.0,"green":1.0,"blue":1.0,"alpha":1.0,"linear":true}],"position":[0.0,1.0],"midpoint":[0.5,0.5]},"gradient_space":"RgbGamma"}},"exposed":false}},{"Value":{"tagged_value":{"GradientForm":"Linear"},"exposed":false}},{"Value":{"tagged_value":{"Bool":true},"exposed":false}},{"Value":{"tagged_value":{"DAffine2":[9.4105020317595,0.0,0.0,9.4105020317595,-5.928761491996683,27Line truncated
|
||||
Generated
+1
-1
@@ -1 +1 @@
|
||||
{"network_interface":{"network":{"exports":[{"Node":{"node_id":15709488322180832347,"output_index":0}}],"nodes":[[57904581517036791,{"inputs":[{"Node":{"node_id":9393309733761233513,"output_index":0}},{"Node":{"node_id":15300421479077882117,"output_index":0}}],"call_argument":{"Generic":"T"},"implementation":{"Network":{"exports":[{"Node":{"node_id":5,"output_index":0}}],"nodes":[[0,{"inputs":[{"Import":{"import_type":{"Generic":"T"},"import_index":0}}],"call_argument":{"Concrete":{"name":"core::option::Option<alloc::sync::Arc<core_types::context::OwnedContextImpl>>"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::AsGraphicNode"}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}],[1,{"inputs":[{"Import":{"import_type":{"Generic":"T"},"import_index":1}}],"call_argument":{"Concrete":{"name":"core::option::Option<alloc::sync::Arc<core_types::context::OwnedContextImpl>>"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::IntoGroupNode"}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}],[2,{"inputs":[{"Reflection":"DocumentNodePath"}],"call_argument":{"Concrete":{"name":"core::option::Option<alloc::sync::Arc<core_types::context::OwnedContextImpl>>"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::PathOfSubgraphNode"}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}],[3,{"inputs":[{"Node":{"node_id":1,"output_index":0}},{"Value":{"tagged_value":{"String":"editor:layer_path"},"exposed":false}},{"Node":{"node_id":2,"output_index":0}}],"call_argument":{"Concrete":{"name":"core::option::Option<alloc::sync::Arc<core_types::context::OwnedContextImpl>>"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::WriteAttributeNode"}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}],[4,{"inputs":[{"Node":{"node_id":3,"output_index":0}}],"call_argument":{"Concrete":{"name":"core::option::Option<alloc::sync::Arc<core_types::context::OwnedContextImpl>>"}},"implementation":{"ProtoNode":{"name":"graphene_core::memo::MonitorNode"}},"visible":true,"skip_deduplication":true,"context_features":{"extract":"","inject":""}}],[5,{"inputs":[{"Node":{"node_id":0,"output_index":0}},{"Node":{"node_id":4,"output_index":0}}],"call_argument":{"Generic":"T"},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::ExtendNode"}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}]],"scope_injections":[]}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}],[70804263053697201,{"inputs":[{"Node":{"node_id":13942787566051910019,"output_index":0}},{"Value":{"tagged_value":{"DVec2":[3.410605131648481e-13,3.410605131648481e-13]},"exposed":false}},{"Value":{"tagged_value":{"F64":0.0},"exposed":false}},{"Value":{"tagged_value":{"DVec2":[1268.999999999999,634.9999999999992]},"exposed":false}},{"Value":{"tagged_value":{"DVec2":[0.0,0.0]},"exposed":false}},{"Value":{"tagged_value":{"DVec2":[0.0,0.0]},"exposed":false}},{"Value":{"tagged_value":{"Bool":true},"exposed":false}}],"call_argument":{"Generic":"T"},"implementation":{"Network":{"exports":[{"Node":{"node_id":1,"output_index":0}}],"nodes":[[0,{"inputs":[{"Import":{"import_type":{"Generic":"T"},"import_index":0}}],"call_argument":{"Concrete":{"name":"core::option::Option<alloc::sync::Arc<core_types::context::OwnedContextImpl>>"}},"implementation":{"ProtoNode":{"name":"graphene_core::memo::MonitorNode"}},"visible":true,"skip_deduplication":true,"context_features":{"extract":"","inject":""}}],[1,{"inputs":[{"Node":{"node_id":0,"output_index":0}},{"Import":{"import_type":{"Concrete":{"name":"glam::f64::dvec2::DVec2"}},"import_index":1}},{"Import":{"import_type":{"Concrete":{"name":"f64"}},"import_index":2}},{"Import":{"import_type":{"Concrete":{"name":"glam::f64::dvec2::DVec2"}},"import_index":3}},{"Import":{"import_type":{"Concrete":{"name":"glam::f64::dvec2::DVec2"}},"import_index":4}}],"call_argument":{"Concrete":{"name":"core::option::Option<alloc::sync::Arc<core_types::context::OwnedContextImpl>>"}},"implementation":{"ProtoNode":{"name":"transform_nodes::transform_nodes::TransformNode"}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}]],"scope_injections":[]}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}],[194878846429432339,{"inputs":[{"Value":{"tagged_value":{"TypeDefault":{"Item":{"Concrete":{"name":"vector_types::vector::vector_types::Vector"}}}},"exposed":true}},{"Value":{"tagged_value":{"VectorModification":{"points":{"add":[1,2,3,4],"remove":[],"delta":[[1,[671.7691453623979,420.00000000000006]],[2,[559.8076211353317,450.0000000000001]],[3,[410.5255888325765,410.0]],[4,[522.4871130596428,380.00000000000006]]]},"segments":{"add":[1,2,3,4],"remove":[],"start_point":[[1,1],[2,2],[3,3],[4,4]],"end_point":[[1,2],[2,3],[3Line truncated
|
||||
{"network_interface":{"network":{"exports":[{"Node":{"node_id":15709488322180832347,"output_index":0}}],"nodes":[[57904581517036791,{"inputs":[{"Node":{"node_id":9393309733761233513,"output_index":0}},{"Node":{"node_id":15300421479077882117,"output_index":0}}],"call_argument":{"Generic":"T"},"implementation":{"Network":{"exports":[{"Node":{"node_id":5,"output_index":0}}],"nodes":[[0,{"inputs":[{"Import":{"import_type":{"Generic":"T"},"import_index":0}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::AsGraphicNode"}},"visible":true,"skip_deduplication":false}],[1,{"inputs":[{"Import":{"import_type":{"Generic":"T"},"import_index":1}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::IntoGroupNode"}},"visible":true,"skip_deduplication":false}],[2,{"inputs":[{"Reflection":"DocumentNodePath"}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::PathOfSubgraphNode"}},"visible":true,"skip_deduplication":false}],[3,{"inputs":[{"Node":{"node_id":1,"output_index":0}},{"Node":{"node_id":2,"output_index":0}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::StampLayerPathNode"}},"visible":true,"skip_deduplication":false}],[4,{"inputs":[{"Node":{"node_id":3,"output_index":0}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"graphene_core::memo::MonitorNode"}},"visible":true,"skip_deduplication":true}],[5,{"inputs":[{"Node":{"node_id":0,"output_index":0}},{"Node":{"node_id":4,"output_index":0}}],"call_argument":{"Generic":"T"},"implementation":{"ProtoNode":{"name":"graphene_core::list::ExtendNode"}},"visible":true,"skip_deduplication":false}]],"scope_injections":[]}},"visible":true,"skip_deduplication":false}],[70804263053697201,{"inputs":[{"Node":{"node_id":13942787566051910019,"output_index":0}},{"Value":{"tagged_value":{"DVec2":[3.410605131648481e-13,3.410605131648481e-13]},"exposed":false}},{"Value":{"tagged_value":{"F64":0.0},"exposed":false}},{"Value":{"tagged_value":{"DVec2":[1268.999999999999,634.9999999999992]},"exposed":false}},{"Value":{"tagged_value":{"DVec2":[0.0,0.0]},"exposed":false}},{"Value":{"tagged_value":{"DVec2":[0.0,0.0]},"exposed":false}},{"Value":{"tagged_value":{"Bool":true},"exposed":false}}],"call_argument":{"Generic":"T"},"implementation":{"Network":{"exports":[{"Node":{"node_id":1,"output_index":0}}],"nodes":[[0,{"inputs":[{"Import":{"import_type":{"Generic":"T"},"import_index":0}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"graphene_core::memo::MonitorNode"}},"visible":true,"skip_deduplication":true}],[1,{"inputs":[{"Node":{"node_id":0,"output_index":0}},{"Import":{"import_type":{"Concrete":{"name":"glam::f64::dvec2::DVec2"}},"import_index":1}},{"Import":{"import_type":{"Concrete":{"name":"f64"}},"import_index":2}},{"Import":{"import_type":{"Concrete":{"name":"glam::f64::dvec2::DVec2"}},"import_index":3}},{"Import":{"import_type":{"Concrete":{"name":"glam::f64::dvec2::DVec2"}},"import_index":4}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl<'_>"}},"implementation":{"ProtoNode":{"name":"transform_nodes::transform_nodes::TransformNode"}},"visible":true,"skip_deduplication":false}]],"scope_injections":[]}},"visible":true,"skip_deduplication":false}],[183952488591282082,{"inputs":[{"Node":{"node_id":17965270694495451178,"output_index":0}},{"Value":{"tagged_value":{"DVec2":[0.0,-6.0]},"exposed":false}},{"Value":{"tagged_value":{"F64":0.0},"exposed":false}},{"Value":{"tagged_value":{"DVec2":[1.0,1.0]},"exposed":false}},{"Value":{"tagged_value":{"DVec2":[0.0,0.0]},"exposed":false}},{"Value":{"tagged_value":{"DVec2":[0.0,0.0]},"exposed":false}},{"Value":{"tagged_value":{"Bool":true},"exposed":false}}],"call_argument":{"Generic":"T"},"implementation":{"Network":{"exports":[{"Node":{"node_id":1,"output_index":0}}],"nodes":[[0,{"inputs":[{"Import":{"import_type":{"Generic":"T"},"import_index":0}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"graphene_core::memo::MonitorNode"}},"visible":true,"skip_deduplication":true}],[1,{"inputs":[{"Node":{"node_id":0,"output_index":0}},{"Import":{"import_type":{"Concrete":{"name":"glam::f64::dvec2::DVec2"}},"import_index":1}},{"Import":{"import_type":{"Concrete":{"name":"f64"}},"import_index":2}},{"Import":{"import_type":{"Concrete":{"name":"glam::f64::dvec2::DVec2"}},"import_index":3}},{"Import":{"import_type":{"Concrete":{"name":"glam::f64::dvec2::DVec2"}},"import_index":4}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl<'_>"}},"implementation":{"ProtoNode":{"name":"transform_noLine truncated
|
||||
Generated
+1
-1
@@ -1 +1 @@
|
||||
{"network_interface":{"network":{"exports":[{"Node":{"node_id":12241147352993594415,"output_index":0}}],"nodes":[[80924370013313595,{"inputs":[{"Node":{"node_id":6029481207635803402,"output_index":0}},{"Value":{"tagged_value":{"GradientRamp":{"stops":{"color":[{"red":0.06469504,"green":0.0,"blue":0.0755814,"alpha":1.0,"linear":true},{"red":0.016644126,"green":0.13212071,"blue":0.62523156,"alpha":1.0,"linear":true},{"red":1.0,"green":0.8708812,"blue":0.3485102,"alpha":1.0,"linear":true},{"red":0.30054384,"green":0.8468733,"blue":0.8468733,"alpha":0.01,"linear":true}],"position":[0.0,0.12704918032786883,0.5,1.0],"midpoint":[0.5,0.5,0.5,0.5]},"gradient_space":"RgbGamma"}},"exposed":false}},{"Value":{"tagged_value":{"Bool":false},"exposed":false}}],"call_argument":{"Concrete":{"name":"core::option::Option<alloc::sync::Arc<core_types::context::OwnedContextImpl>>"}},"implementation":{"ProtoNode":{"name":"raster_nodes::gradient_map::GradientMapNode"}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}],[3606681156406984991,{"inputs":[{"Node":{"node_id":6323350524796370485,"output_index":0}},{"Value":{"tagged_value":{"GradientRamp":{"stops":{"color":[{"red":0.0,"green":0.0,"blue":0.0,"alpha":1.0,"linear":true},{"red":0.04631017,"green":0.0,"blue":0.0076861563,"alpha":1.0,"linear":true},{"red":0.83939683,"green":0.7249875,"blue":0.27055356,"alpha":1.0,"linear":true},{"red":0.025397457,"green":0.3485102,"blue":0.3485102,"alpha":1.0,"linear":true},{"red":0.01102731,"green":0.09231063,"blue":0.09231063,"alpha":1.0,"linear":true}],"position":[0.0,0.3237704918032787,0.5655737704918032,0.8155737704918032,1.0],"midpoint":[0.5,0.5,0.5,0.5,0.5]},"gradient_space":"RgbGamma"}},"exposed":false}},{"Value":{"tagged_value":{"Bool":true},"exposed":false}}],"call_argument":{"Concrete":{"name":"core::option::Option<alloc::sync::Arc<core_types::context::OwnedContextImpl>>"}},"implementation":{"ProtoNode":{"name":"raster_nodes::gradient_map::GradientMapNode"}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}],[4388711862172196665,{"inputs":[],"call_argument":{"Concrete":{"name":"core::option::Option<alloc::sync::Arc<core_types::context::OwnedContextImpl>>"}},"implementation":{"ProtoNode":{"name":"raster_nodes::std_nodes::MandelbrotNode"}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"FOOTPRINT","inject":""}}],[6029481207635803402,{"inputs":[{"Node":{"node_id":4388711862172196665,"output_index":0}},{"Value":{"tagged_value":{"DVec2":[0.0,0.0]},"exposed":false}},{"Value":{"tagged_value":{"F64":0.0},"exposed":false}},{"Value":{"tagged_value":{"DVec2":[1000.0,1000.0]},"exposed":false}},{"Value":{"tagged_value":{"DVec2":[0.0,0.0]},"exposed":false}},{"Value":{"tagged_value":{"DVec2":[0.0,0.0]},"exposed":false}},{"Value":{"tagged_value":{"Bool":true},"exposed":false}}],"call_argument":{"Generic":"T"},"implementation":{"Network":{"exports":[{"Node":{"node_id":1,"output_index":0}}],"nodes":[[0,{"inputs":[{"Import":{"import_type":{"Generic":"T"},"import_index":0}}],"call_argument":{"Concrete":{"name":"core::option::Option<alloc::sync::Arc<core_types::context::OwnedContextImpl>>"}},"implementation":{"ProtoNode":{"name":"graphene_core::memo::MonitorNode"}},"visible":true,"skip_deduplication":true,"context_features":{"extract":"","inject":""}}],[1,{"inputs":[{"Node":{"node_id":0,"output_index":0}},{"Import":{"import_type":{"Concrete":{"name":"glam::f64::dvec2::DVec2"}},"import_index":1}},{"Import":{"import_type":{"Concrete":{"name":"f64"}},"import_index":2}},{"Import":{"import_type":{"Concrete":{"name":"glam::f64::dvec2::DVec2"}},"import_index":3}},{"Import":{"import_type":{"Concrete":{"name":"glam::f64::dvec2::DVec2"}},"import_index":4}}],"call_argument":{"Concrete":{"name":"core::option::Option<alloc::sync::Arc<core_types::context::OwnedContextImpl>>"}},"implementation":{"ProtoNode":{"name":"transform_nodes::transform_nodes::TransformNode"}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}]],"scope_injections":[]}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}],[6323350524796370485,{"inputs":[{"Value":{"tagged_value":"None","exposed":false}},{"Value":{"tagged_value":{"Bool":false},"exposed":false}},{"Value":{"tagged_value":{"U32":0},"exposed":false}},{"Value":{"tagged_value":{"F64":35.0},"exposed":false}},{"Value":{"tagged_value":{"NoiseType":"OpenSimplex2"},"exposed":false}},{"Value":{"tagged_value":{"DomainWarpType":"OpenSimplex2"},"exposed":false}},{"Value":{"tagged_value":{"F64":100.0},"exposed":false}},{"Value":{"tagged_value":{"FractalType":"PingPong"},"exposed":false}},{"Value":{"tagged_value":{"U32":3},"exposed":false}},{"Value":{"tagged_value":{"F64":2.0},"exposed":false}},{"Value":{"tagged_value":{"F64":0.5},"exposed":false}},{"Value":{"tagged_value":{"F64":0.0},"exposed":false}},{"Value":{"tagged_value":{"F64":2.0},"exposed":false}},{"Value":{"tagged_Line truncated
|
||||
{"network_interface":{"network":{"exports":[{"Node":{"node_id":12241147352993594415,"output_index":0}}],"nodes":[[80924370013313595,{"inputs":[{"Node":{"node_id":6029481207635803402,"output_index":0}},{"Value":{"tagged_value":{"GradientRamp":{"stops":{"color":[{"red":0.06469504,"green":0.0,"blue":0.0755814,"alpha":1.0,"linear":true},{"red":0.016644126,"green":0.13212071,"blue":0.62523156,"alpha":1.0,"linear":true},{"red":1.0,"green":0.8708812,"blue":0.3485102,"alpha":1.0,"linear":true},{"red":0.30054384,"green":0.8468733,"blue":0.8468733,"alpha":0.01,"linear":true}],"position":[0.0,0.12704918032786883,0.5,1.0],"midpoint":[0.5,0.5,0.5,0.5]},"gradient_space":"RgbGamma"}},"exposed":false}},{"Value":{"tagged_value":{"Bool":false},"exposed":false}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"raster_nodes::gradient_map::GradientMapNode"}},"visible":true,"skip_deduplication":false}],[3606681156406984991,{"inputs":[{"Node":{"node_id":6323350524796370485,"output_index":0}},{"Value":{"tagged_value":{"GradientRamp":{"stops":{"color":[{"red":0.0,"green":0.0,"blue":0.0,"alpha":1.0,"linear":true},{"red":0.04631017,"green":0.0,"blue":0.0076861563,"alpha":1.0,"linear":true},{"red":0.83939683,"green":0.7249875,"blue":0.27055356,"alpha":1.0,"linear":true},{"red":0.025397457,"green":0.3485102,"blue":0.3485102,"alpha":1.0,"linear":true},{"red":0.01102731,"green":0.09231063,"blue":0.09231063,"alpha":1.0,"linear":true}],"position":[0.0,0.3237704918032787,0.5655737704918032,0.8155737704918032,1.0],"midpoint":[0.5,0.5,0.5,0.5,0.5]},"gradient_space":"RgbGamma"}},"exposed":false}},{"Value":{"tagged_value":{"Bool":true},"exposed":false}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"raster_nodes::gradient_map::GradientMapNode"}},"visible":true,"skip_deduplication":false}],[4388711862172196665,{"inputs":[{"Value":{"tagged_value":"None","exposed":true}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl<'_>"}},"implementation":{"ProtoNode":{"name":"raster_nodes::std_nodes::MandelbrotNode"}},"visible":true,"skip_deduplication":false}],[6029481207635803402,{"inputs":[{"Node":{"node_id":4388711862172196665,"output_index":0}},{"Value":{"tagged_value":{"DVec2":[0.0,0.0]},"exposed":false}},{"Value":{"tagged_value":{"F64":0.0},"exposed":false}},{"Value":{"tagged_value":{"DVec2":[1000.0,1000.0]},"exposed":false}},{"Value":{"tagged_value":{"DVec2":[0.0,0.0]},"exposed":false}},{"Value":{"tagged_value":{"DVec2":[0.0,0.0]},"exposed":false}},{"Value":{"tagged_value":{"Bool":true},"exposed":false}}],"call_argument":{"Generic":"T"},"implementation":{"Network":{"exports":[{"Node":{"node_id":1,"output_index":0}}],"nodes":[[0,{"inputs":[{"Import":{"import_type":{"Generic":"T"},"import_index":0}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"graphene_core::memo::MonitorNode"}},"visible":true,"skip_deduplication":true}],[1,{"inputs":[{"Node":{"node_id":0,"output_index":0}},{"Import":{"import_type":{"Concrete":{"name":"glam::f64::dvec2::DVec2"}},"import_index":1}},{"Import":{"import_type":{"Concrete":{"name":"f64"}},"import_index":2}},{"Import":{"import_type":{"Concrete":{"name":"glam::f64::dvec2::DVec2"}},"import_index":3}},{"Import":{"import_type":{"Concrete":{"name":"glam::f64::dvec2::DVec2"}},"import_index":4}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl<'_>"}},"implementation":{"ProtoNode":{"name":"transform_nodes::transform_nodes::TransformNode"}},"visible":true,"skip_deduplication":false}]],"scope_injections":[]}},"visible":true,"skip_deduplication":false}],[6323350524796370485,{"inputs":[{"Value":{"tagged_value":"None","exposed":false}},{"Value":{"tagged_value":{"Bool":false},"exposed":false}},{"Value":{"tagged_value":{"U32":0},"exposed":false}},{"Value":{"tagged_value":{"F64":35.0},"exposed":false}},{"Value":{"tagged_value":{"NoiseType":"OpenSimplex2"},"exposed":false}},{"Value":{"tagged_value":{"DomainWarpType":"OpenSimplex2"},"exposed":false}},{"Value":{"tagged_value":{"F64":100.0},"exposed":false}},{"Value":{"tagged_value":{"FractalType":"PingPong"},"exposed":false}},{"Value":{"tagged_value":{"U32":3},"exposed":false}},{"Value":{"tagged_value":{"F64":2.0},"exposed":false}},{"Value":{"tagged_value":{"F64":0.5},"exposed":false}},{"Value":{"tagged_value":{"F64":0.0},"exposed":false}},{"Value":{"tagged_value":{"F64":2.0},"exposed":false}},{"Value":{"tagged_value":{"CellularDistanceFunction":"Hybrid"},"exposed":false}},{"Value":{"tagged_value":{"CellularReturnType":"CellValue"},"exposed":false}},{"Value":{"tagged_value":{"F64":1.0},"exposed":false}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl<'_>"}},"implementation":{"ProtoNode":{"name":"raster_nodes::std_nodes::NoisePatternNode"}},"visible":true,"skip_deduplication":false}],[6565638614909771142,{"inputs":[{"Node":{"node_id":7Line truncated
|
||||
Generated
+1
-1
@@ -1 +1 @@
|
||||
{"network_interface":{"network":{"exports":[{"Node":{"node_id":392274448837115448,"output_index":0}}],"nodes":[[57390435731316553,{"inputs":[{"Node":{"node_id":8460565235419043665,"output_index":0}},{"Node":{"node_id":13838011362258067867,"output_index":0}},{"Value":{"tagged_value":{"F64":0.0},"exposed":false}},{"Value":{"tagged_value":{"DVec2":[1.0,1.0]},"exposed":false}},{"Value":{"tagged_value":{"DVec2":[0.0,0.0]},"exposed":false}},{"Value":{"tagged_value":{"DVec2":[0.0,0.0]},"exposed":false}},{"Value":{"tagged_value":{"Bool":true},"exposed":false}}],"call_argument":{"Generic":"T"},"implementation":{"Network":{"exports":[{"Node":{"node_id":1,"output_index":0}}],"nodes":[[0,{"inputs":[{"Import":{"import_type":{"Generic":"T"},"import_index":0}}],"call_argument":{"Concrete":{"name":"core::option::Option<alloc::sync::Arc<core_types::context::OwnedContextImpl>>"}},"implementation":{"ProtoNode":{"name":"graphene_core::memo::MonitorNode"}},"visible":true,"skip_deduplication":true,"context_features":{"extract":"","inject":""}}],[1,{"inputs":[{"Node":{"node_id":0,"output_index":0}},{"Import":{"import_type":{"Concrete":{"name":"glam::f64::dvec2::DVec2"}},"import_index":1}},{"Import":{"import_type":{"Concrete":{"name":"f64"}},"import_index":2}},{"Import":{"import_type":{"Concrete":{"name":"glam::f64::dvec2::DVec2"}},"import_index":3}},{"Import":{"import_type":{"Concrete":{"name":"glam::f64::dvec2::DVec2"}},"import_index":4}}],"call_argument":{"Concrete":{"name":"core::option::Option<alloc::sync::Arc<core_types::context::OwnedContextImpl>>"}},"implementation":{"ProtoNode":{"name":"transform_nodes::transform_nodes::TransformNode"}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}]],"scope_injections":[]}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}],[140396870212231820,{"inputs":[{"Node":{"node_id":18095952297474762348,"output_index":0}},{"Value":{"tagged_value":{"BooleanOperation":"Intersect"},"exposed":false}}],"call_argument":{"Generic":"T"},"implementation":{"ProtoNode":{"name":"path_bool_nodes::BooleanOperationNode"}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}],[294265135510952894,{"inputs":[{"Node":{"node_id":11264395591110193456,"output_index":0}},{"Value":{"tagged_value":{"Color":{"red":0.83076996,"green":0.32314324,"blue":0.027320892,"alpha":1.0,"linear":true}},"exposed":false}},{"Value":{"tagged_value":{"Color":{"red":0.6938719,"green":0.048171822,"blue":0.028426038,"alpha":1.0,"linear":true}},"exposed":false}},{"Value":{"tagged_value":{"GradientRamp":{"stops":{"color":[{"red":0.0,"green":0.0,"blue":0.0,"alpha":1.0,"linear":true},{"red":1.0,"green":1.0,"blue":1.0,"alpha":1.0,"linear":true}],"position":[0.0,1.0],"midpoint":[0.5,0.5]},"gradient_space":"RgbGamma"}},"exposed":false}},{"Value":{"tagged_value":{"GradientForm":"Linear"},"exposed":false}},{"Value":{"tagged_value":{"Bool":true},"exposed":false}},{"Value":{"tagged_value":{"DAffine2":[20.0,0.0,0.0,20.0,-10.0,0.0]},"exposed":false}}],"call_argument":{"Concrete":{"name":"core::option::Option<alloc::sync::Arc<core_types::context::OwnedContextImpl>>"}},"implementation":{"ProtoNode":{"name":"graphene_core::vector::FillNode"}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}],[392274448837115448,{"inputs":[{"Value":{"tagged_value":{"TypeDefault":{"List":{"Concrete":{"name":"graphic_types::artboard::Artboard"}}}},"exposed":true}},{"Node":{"node_id":6787585796949551500,"output_index":0}},{"Value":{"tagged_value":{"DVec2":[0.0,0.0]},"exposed":false}},{"Value":{"tagged_value":{"DVec2":[1536.0,768.0]},"exposed":false}},{"Value":{"tagged_value":{"Color":{"red":0.8549927,"green":0.71569365,"blue":0.48514998,"alpha":1.0,"linear":true}},"exposed":false}},{"Value":{"tagged_value":{"Bool":true},"exposed":false}}],"call_argument":{"Generic":"T"},"implementation":{"Network":{"exports":[{"Node":{"node_id":4,"output_index":0}}],"nodes":[[0,{"inputs":[{"Import":{"import_type":{"Fn":[{"Concrete":{"name":"core::option::Option<alloc::sync::Arc<core_types::context::OwnedContextImpl>>"}},{"Generic":"T"}]},"import_index":1}},{"Import":{"import_type":{"Item":{"Concrete":{"name":"graph_craft::document::value::TaggedValue"}}},"import_index":2}},{"Import":{"import_type":{"Item":{"Concrete":{"name":"graph_craft::document::value::TaggedValue"}}},"import_index":3}},{"Import":{"import_type":{"Item":{"Concrete":{"name":"graph_craft::document::value::TaggedValue"}}},"import_index":4}},{"Import":{"import_type":{"Item":{"Concrete":{"name":"graph_craft::document::value::TaggedValue"}}},"import_index":5}}],"call_argument":{"Generic":"T"},"implementation":{"ProtoNode":{"name":"graphic_nodes::artboard::CreateArtboardNode"}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}],[1,{"inputs":[{"Reflection":"DocumentNodePath"}],"call_argument":{"Concrete":{"name":"core::option::Option<alloc::sLine truncated
|
||||
{"network_interface":{"network":{"exports":[{"Node":{"node_id":392274448837115448,"output_index":0}}],"nodes":[[57390435731316553,{"inputs":[{"Node":{"node_id":8460565235419043665,"output_index":0}},{"Node":{"node_id":13838011362258067867,"output_index":0}},{"Value":{"tagged_value":{"F64":0.0},"exposed":false}},{"Value":{"tagged_value":{"DVec2":[1.0,1.0]},"exposed":false}},{"Value":{"tagged_value":{"DVec2":[0.0,0.0]},"exposed":false}},{"Value":{"tagged_value":{"DVec2":[0.0,0.0]},"exposed":false}},{"Value":{"tagged_value":{"Bool":true},"exposed":false}}],"call_argument":{"Generic":"T"},"implementation":{"Network":{"exports":[{"Node":{"node_id":1,"output_index":0}}],"nodes":[[0,{"inputs":[{"Import":{"import_type":{"Generic":"T"},"import_index":0}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"graphene_core::memo::MonitorNode"}},"visible":true,"skip_deduplication":true}],[1,{"inputs":[{"Node":{"node_id":0,"output_index":0}},{"Import":{"import_type":{"Concrete":{"name":"glam::f64::dvec2::DVec2"}},"import_index":1}},{"Import":{"import_type":{"Concrete":{"name":"f64"}},"import_index":2}},{"Import":{"import_type":{"Concrete":{"name":"glam::f64::dvec2::DVec2"}},"import_index":3}},{"Import":{"import_type":{"Concrete":{"name":"glam::f64::dvec2::DVec2"}},"import_index":4}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl<'_>"}},"implementation":{"ProtoNode":{"name":"transform_nodes::transform_nodes::TransformNode"}},"visible":true,"skip_deduplication":false}]],"scope_injections":[]}},"visible":true,"skip_deduplication":false}],[140396870212231820,{"inputs":[{"Node":{"node_id":18095952297474762348,"output_index":0}},{"Value":{"tagged_value":{"BooleanOperation":"Intersect"},"exposed":false}}],"call_argument":{"Generic":"T"},"implementation":{"ProtoNode":{"name":"path_bool_nodes::BooleanOperationNode"}},"visible":true,"skip_deduplication":false}],[294265135510952894,{"inputs":[{"Node":{"node_id":11264395591110193456,"output_index":0}},{"Value":{"tagged_value":{"Color":{"red":0.83076996,"green":0.32314324,"blue":0.027320892,"alpha":1.0,"linear":true}},"exposed":false}},{"Value":{"tagged_value":{"Color":{"red":0.6938719,"green":0.048171822,"blue":0.028426038,"alpha":1.0,"linear":true}},"exposed":false}},{"Value":{"tagged_value":{"GradientRamp":{"stops":{"color":[{"red":0.0,"green":0.0,"blue":0.0,"alpha":1.0,"linear":true},{"red":1.0,"green":1.0,"blue":1.0,"alpha":1.0,"linear":true}],"position":[0.0,1.0],"midpoint":[0.5,0.5]},"gradient_space":"RgbGamma"}},"exposed":false}},{"Value":{"tagged_value":{"GradientForm":"Linear"},"exposed":false}},{"Value":{"tagged_value":{"Bool":true},"exposed":false}},{"Value":{"tagged_value":{"DAffine2":[20.0,0.0,0.0,20.0,-10.0,0.0]},"exposed":false}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"graphene_core::vector::FillNode"}},"visible":true,"skip_deduplication":false}],[392274448837115448,{"inputs":[{"Value":{"tagged_value":{"TypeDefault":{"name":"core_types::list::List<graphic_types::artboard::Artboard>"}},"exposed":true}},{"Node":{"node_id":6787585796949551500,"output_index":0}},{"Value":{"tagged_value":{"DVec2":[0.0,0.0]},"exposed":false}},{"Value":{"tagged_value":{"DVec2":[1536.0,768.0]},"exposed":false}},{"Value":{"tagged_value":{"Color":{"red":0.8549927,"green":0.71569365,"blue":0.48514998,"alpha":1.0,"linear":true}},"exposed":false}},{"Value":{"tagged_value":{"Bool":true},"exposed":false}}],"call_argument":{"Generic":"T"},"implementation":{"Network":{"exports":[{"Node":{"node_id":4,"output_index":0}}],"nodes":[[0,{"inputs":[{"Node":{"node_id":6,"output_index":0}},{"Import":{"import_type":{"Concrete":{"name":"graph_craft::document::value::TaggedValue"}},"import_index":2}},{"Import":{"import_type":{"Concrete":{"name":"graph_craft::document::value::TaggedValue"}},"import_index":3}},{"Import":{"import_type":{"Concrete":{"name":"graph_craft::document::value::TaggedValue"}},"import_index":4}},{"Import":{"import_type":{"Concrete":{"name":"graph_craft::document::value::TaggedValue"}},"import_index":5}}],"call_argument":{"Generic":"T"},"implementation":{"ProtoNode":{"name":"graphic_nodes::artboard::CreateArtboardNode"}},"visible":true,"skip_deduplication":false}],[1,{"inputs":[{"Reflection":"DocumentNodePath"}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::PathOfSubgraphNode"}},"visible":true,"skip_deduplication":false}],[2,{"inputs":[{"Node":{"node_id":0,"output_index":0}},{"Node":{"node_id":1,"output_index":0}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::StampLayerPathNode"}},"visible":true,"skip_deduplication":false}],[3,{"inputs":[{"Node":{"node_id":7,"output_index":0}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementaLine truncated
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"network_interface":{"network":{"exports":[{"Node":{"node_id":4445985685181725042,"output_index":0}}],"nodes":[[239716716021064150,{"inputs":[{"Value":{"tagged_value":{"TypeDefault":{"List":{"Concrete":{"name":"graphic_types::graphic::Graphic"}}}},"exposed":true}},{"Node":{"node_id":7711570794020903773,"output_index":0}}],"call_argument":{"Generic":"T"},"implementation":{"Network":{"exports":[{"Node":{"node_id":5,"output_index":0}}],"nodes":[[0,{"inputs":[{"Import":{"import_type":{"Generic":"T"},"import_index":0}}],"call_argument":{"Concrete":{"name":"core::option::Option<alloc::sync::Arc<core_types::context::OwnedContextImpl>>"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::AsGraphicNode"}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}],[1,{"inputs":[{"Import":{"import_type":{"Generic":"T"},"import_index":1}}],"call_argument":{"Concrete":{"name":"core::option::Option<alloc::sync::Arc<core_types::context::OwnedContextImpl>>"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::IntoGroupNode"}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}],[2,{"inputs":[{"Reflection":"DocumentNodePath"}],"call_argument":{"Concrete":{"name":"core::option::Option<alloc::sync::Arc<core_types::context::OwnedContextImpl>>"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::PathOfSubgraphNode"}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}],[3,{"inputs":[{"Node":{"node_id":1,"output_index":0}},{"Value":{"tagged_value":{"String":"editor:layer_path"},"exposed":false}},{"Node":{"node_id":2,"output_index":0}}],"call_argument":{"Concrete":{"name":"core::option::Option<alloc::sync::Arc<core_types::context::OwnedContextImpl>>"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::WriteAttributeNode"}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}],[4,{"inputs":[{"Node":{"node_id":3,"output_index":0}}],"call_argument":{"Concrete":{"name":"core::option::Option<alloc::sync::Arc<core_types::context::OwnedContextImpl>>"}},"implementation":{"ProtoNode":{"name":"graphene_core::memo::MonitorNode"}},"visible":true,"skip_deduplication":true,"context_features":{"extract":"","inject":""}}],[5,{"inputs":[{"Node":{"node_id":0,"output_index":0}},{"Node":{"node_id":4,"output_index":0}}],"call_argument":{"Generic":"T"},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::ExtendNode"}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}]],"scope_injections":[]}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}],[1801066723091712434,{"inputs":[{"Value":{"tagged_value":"None","exposed":true}},{"Value":{"tagged_value":{"Color":{"red":0.036889445,"green":0.038204364,"blue":0.043735027,"alpha":1.0,"linear":true}},"exposed":false}},{"Value":{"tagged_value":{"F64":1744.31393592},"exposed":false}},{"Value":{"tagged_value":{"F64":63.0},"exposed":false}}],"call_argument":{"Generic":"T"},"implementation":{"Network":{"exports":[{"Node":{"node_id":2288754089236120499,"output_index":0}}],"nodes":[[640915213983348287,{"inputs":[{"Value":{"tagged_value":"None","exposed":false}},{"Value":{"tagged_value":{"F64":4000.0},"exposed":false}},{"Value":{"tagged_value":{"F64":500.0},"exposed":false}},{"Value":{"tagged_value":{"BoxCorners":[0.0]},"exposed":false}},{"Value":{"tagged_value":{"Bool":true},"exposed":false}},{"Value":{"tagged_value":{"Bool":false},"exposed":false}}],"call_argument":{"Concrete":{"name":"core::option::Option<alloc::sync::Arc<core_types::context::OwnedContextImpl>>"}},"implementation":{"ProtoNode":{"name":"vector_nodes::generator_nodes::RectangleNode"}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}],[1791308547102433540,{"inputs":[{"Node":{"node_id":640915213983348287,"output_index":0}},{"Import":{"import_type":{"Generic":"T"},"import_index":1}},{"Value":{"tagged_value":{"Color":{"red":0.9911022,"green":0.6514057,"blue":0.39157256,"alpha":1.0,"linear":true}},"exposed":false}},{"Value":{"tagged_value":{"GradientRamp":{"stops":{"color":[{"red":0.0,"green":0.0,"blue":0.0,"alpha":1.0,"linear":true},{"red":1.0,"green":1.0,"blue":1.0,"alpha":1.0,"linear":true}],"position":[0.0,1.0],"midpoint":[0.5,0.5]},"gradient_space":"RgbGamma"}},"exposed":false}},{"Value":{"tagged_value":{"GradientForm":"Linear"},"exposed":false}},{"Value":{"tagged_value":{"Bool":false},"exposed":false}},{"Value":{"tagged_value":{"DAffine2":[1.0,0.0,0.0,1.0,0.0,0.0]},"exposed":false}}],"call_argument":{"Concrete":{"name":"core::option::Option<alloc::sync::Arc<core_types::context::OwnedContextImpl>>"}},"implementation":{"ProtoNode":{"name":"graphene_core::vector::FillNode"}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}],[2288754089236120499,{"inputs":[{"Node":{"node_id":14158287945315818946,"outLine truncated
|
||||
{"network_interface":{"network":{"exports":[{"Node":{"node_id":4445985685181725042,"output_index":0}}],"nodes":[[239716716021064150,{"inputs":[{"Value":{"tagged_value":{"TypeDefault":{"name":"core_types::list::List<graphic_types::graphic::Graphic>"}},"exposed":true}},{"Node":{"node_id":7711570794020903773,"output_index":0}}],"call_argument":{"Generic":"T"},"implementation":{"Network":{"exports":[{"Node":{"node_id":5,"output_index":0}}],"nodes":[[0,{"inputs":[{"Import":{"import_type":{"Generic":"T"},"import_index":0}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::AsGraphicNode"}},"visible":true,"skip_deduplication":false}],[1,{"inputs":[{"Import":{"import_type":{"Generic":"T"},"import_index":1}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::IntoGroupNode"}},"visible":true,"skip_deduplication":false}],[2,{"inputs":[{"Reflection":"DocumentNodePath"}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::PathOfSubgraphNode"}},"visible":true,"skip_deduplication":false}],[3,{"inputs":[{"Node":{"node_id":1,"output_index":0}},{"Node":{"node_id":2,"output_index":0}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::StampLayerPathNode"}},"visible":true,"skip_deduplication":false}],[4,{"inputs":[{"Node":{"node_id":3,"output_index":0}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"graphene_core::memo::MonitorNode"}},"visible":true,"skip_deduplication":true}],[5,{"inputs":[{"Node":{"node_id":0,"output_index":0}},{"Node":{"node_id":4,"output_index":0}}],"call_argument":{"Generic":"T"},"implementation":{"ProtoNode":{"name":"graphene_core::list::ExtendNode"}},"visible":true,"skip_deduplication":false}]],"scope_injections":[]}},"visible":true,"skip_deduplication":false}],[1801066723091712434,{"inputs":[{"Value":{"tagged_value":"None","exposed":true}},{"Value":{"tagged_value":{"Color":{"red":0.036889445,"green":0.038204364,"blue":0.043735027,"alpha":1.0,"linear":true}},"exposed":false}},{"Value":{"tagged_value":{"F64":1744.31393592},"exposed":false}},{"Value":{"tagged_value":{"F64":63.0},"exposed":false}}],"call_argument":{"Generic":"T"},"implementation":{"Network":{"exports":[{"Node":{"node_id":2288754089236120499,"output_index":0}}],"nodes":[[640915213983348287,{"inputs":[{"Value":{"tagged_value":"None","exposed":false}},{"Value":{"tagged_value":{"F64":4000.0},"exposed":false}},{"Value":{"tagged_value":{"F64":500.0},"exposed":false}},{"Value":{"tagged_value":{"BoxCorners":[0.0]},"exposed":false}},{"Value":{"tagged_value":{"Bool":true},"exposed":false}},{"Value":{"tagged_value":{"Bool":false},"exposed":false}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl<'_>"}},"implementation":{"ProtoNode":{"name":"vector_nodes::generator_nodes::RectangleNode"}},"visible":true,"skip_deduplication":false}],[1791308547102433540,{"inputs":[{"Node":{"node_id":640915213983348287,"output_index":0}},{"Import":{"import_type":{"Generic":"T"},"import_index":1}},{"Value":{"tagged_value":{"Color":{"red":0.9911022,"green":0.6514057,"blue":0.39157256,"alpha":1.0,"linear":true}},"exposed":false}},{"Value":{"tagged_value":{"GradientRamp":{"stops":{"color":[{"red":0.0,"green":0.0,"blue":0.0,"alpha":1.0,"linear":true},{"red":1.0,"green":1.0,"blue":1.0,"alpha":1.0,"linear":true}],"position":[0.0,1.0],"midpoint":[0.5,0.5]},"gradient_space":"RgbGamma"}},"exposed":false}},{"Value":{"tagged_value":{"GradientForm":"Linear"},"exposed":false}},{"Value":{"tagged_value":{"Bool":false},"exposed":false}},{"Value":{"tagged_value":{"DAffine2":[1.0,0.0,0.0,1.0,0.0,0.0]},"exposed":false}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"graphene_core::vector::FillNode"}},"visible":true,"skip_deduplication":false}],[2288754089236120499,{"inputs":[{"Node":{"node_id":14158287945315818946,"output_index":0}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl<'_>"}},"implementation":{"ProtoNode":{"name":"core_types::vector::SplineNode"}},"visible":true,"skip_deduplication":false}],[7828034197076821310,{"inputs":[{"Import":{"import_type":{"Generic":"T"},"import_index":3}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl<'_>"}},"implementation":{"ProtoNode":{"name":"math_nodes::AsU32Node"}},"visible":true,"skip_deduplication":false}],[11731553664207576737,{"inputs":[{"Node":{"node_id":14514477720912258595,"output_index":0}},{"Value":{"tagged_value":{"F64":48.900000000000006},"exposed":false}},{"Node":{"node_id":7828034197076821310,"output_index":0}},{"Value":{"tagged_value":{"Bool":false},"exposed":false}}],"call_argument":{"Concrete":{"namLine truncated
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"network_interface":{"network":{"exports":[{"Node":{"node_id":14972365039974885000,"output_index":0}}],"nodes":[[169695252050218443,{"inputs":[{"Node":{"node_id":13907401402762847509,"output_index":0}},{"Value":{"tagged_value":{"GradientRamp":{"stops":{"color":[{"red":1.0,"green":1.0,"blue":1.0,"alpha":0.75,"linear":true},{"red":1.0,"green":1.0,"blue":1.0,"alpha":0.01,"linear":true}],"position":[0.0,1.0],"midpoint":[0.5,0.5]},"gradient_space":"RgbGamma"}},"exposed":false}},{"Value":{"tagged_value":{"Color":{"red":0.0,"green":0.0,"blue":0.0,"alpha":1.0,"linear":true}},"exposed":false}},{"Value":{"tagged_value":{"GradientRamp":{"stops":{"color":[{"red":1.0,"green":1.0,"blue":1.0,"alpha":0.7734375,"linear":true},{"red":1.0,"green":1.0,"blue":1.0,"alpha":0.01,"linear":true}],"position":[0.0,1.0],"midpoint":[0.5,0.5]},"gradient_space":"RgbGamma"}},"exposed":false}},{"Value":{"tagged_value":{"GradientForm":"Radial"},"exposed":false}},{"Value":{"tagged_value":{"Bool":true},"exposed":false}},{"Value":{"tagged_value":{"DAffine2":[31.55635094002563,-2.7755575615628914e-17,2.7755575615628914e-17,31.55635094002563,-0.225779263556106,34.981204988590605]},"exposed":false}}],"call_argument":{"Concrete":{"name":"core::option::Option<alloc::sync::Arc<core_types::context::OwnedContextImpl>>"}},"implementation":{"ProtoNode":{"name":"graphene_core::vector::FillNode"}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}],[183562335973647870,{"inputs":[{"Node":{"node_id":4248875763694880300,"output_index":0}},{"Node":{"node_id":2181148486404191200,"output_index":0}}],"call_argument":{"Generic":"T"},"implementation":{"Network":{"exports":[{"Node":{"node_id":5,"output_index":0}}],"nodes":[[0,{"inputs":[{"Import":{"import_type":{"Generic":"T"},"import_index":0}}],"call_argument":{"Concrete":{"name":"core::option::Option<alloc::sync::Arc<core_types::context::OwnedContextImpl>>"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::AsGraphicNode"}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}],[1,{"inputs":[{"Import":{"import_type":{"Generic":"T"},"import_index":1}}],"call_argument":{"Concrete":{"name":"core::option::Option<alloc::sync::Arc<core_types::context::OwnedContextImpl>>"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::IntoGroupNode"}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}],[2,{"inputs":[{"Reflection":"DocumentNodePath"}],"call_argument":{"Concrete":{"name":"core::option::Option<alloc::sync::Arc<core_types::context::OwnedContextImpl>>"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::PathOfSubgraphNode"}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}],[3,{"inputs":[{"Node":{"node_id":1,"output_index":0}},{"Value":{"tagged_value":{"String":"editor:layer_path"},"exposed":false}},{"Node":{"node_id":2,"output_index":0}}],"call_argument":{"Concrete":{"name":"core::option::Option<alloc::sync::Arc<core_types::context::OwnedContextImpl>>"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::WriteAttributeNode"}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}],[4,{"inputs":[{"Node":{"node_id":3,"output_index":0}}],"call_argument":{"Concrete":{"name":"core::option::Option<alloc::sync::Arc<core_types::context::OwnedContextImpl>>"}},"implementation":{"ProtoNode":{"name":"graphene_core::memo::MonitorNode"}},"visible":true,"skip_deduplication":true,"context_features":{"extract":"","inject":""}}],[5,{"inputs":[{"Node":{"node_id":0,"output_index":0}},{"Node":{"node_id":4,"output_index":0}}],"call_argument":{"Generic":"T"},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::ExtendNode"}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}]],"scope_injections":[]}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}],[655907162126315400,{"inputs":[{"Value":{"tagged_value":{"TypeDefault":{"Item":{"Concrete":{"name":"vector_types::vector::vector_types::Vector"}}}},"exposed":true}},{"Value":{"tagged_value":{"VectorModification":{"points":{"add":[1,2,3,4,5,6,7,8,9,10,11],"remove":[],"delta":[[1,[416.0,270.9999999999999]],[2,[587.0,291.9999999999999]],[3,[373.0,372.9999999999999]],[4,[484.0,446.9999999999999]],[5,[639.0,438.9999999999999]],[6,[495.0,533.9999999999999]],[7,[304.0,611.9999999999999]],[8,[475.0,671.9999999999999]],[9,[750.0,703.9999999999999]],[10,[455.0,824.9999999999999]],[11,[186.0,824.9999999999999]]]},"segments":{"add":[1,2,3,4,5,6,7,8,9,10],"remove":[],"start_point":[[1,1],[2,2],[3,3],[4,4],[5,5],[6,6],[7,7],[8,8],[9,9],[10,10]],"end_point":[[1,2],[2,3],[3,4],[4,5],[5,6],[6,7],[7,8],[8,9],[9,10],[10,11]],"handle_primary":[[1,[0.0,0.0]],[2,[0.0,0.0]],[3,[0.0,0.0]],[4,[0.0,0.0]],[5,[0.0,0.0]],[6,[0.0,0.0]],[7,[0.0,0.0]],[8,[0.0,0.0]],[9,[0.0,0.0]],[10,[0.0,0.0]]],"handle_end":Line truncated
|
||||
{"network_interface":{"network":{"exports":[{"Node":{"node_id":14972365039974885000,"output_index":0}}],"nodes":[[169695252050218443,{"inputs":[{"Node":{"node_id":6559102076450693000,"output_index":0}},{"Value":{"tagged_value":{"GradientRamp":{"stops":{"color":[{"red":1.0,"green":1.0,"blue":1.0,"alpha":0.75,"linear":true},{"red":1.0,"green":1.0,"blue":1.0,"alpha":0.01,"linear":true}],"position":[0.0,1.0],"midpoint":[0.5,0.5]},"gradient_space":"RgbGamma"}},"exposed":false}},{"Value":{"tagged_value":{"Color":{"red":0.0,"green":0.0,"blue":0.0,"alpha":1.0,"linear":true}},"exposed":false}},{"Value":{"tagged_value":{"GradientRamp":{"stops":{"color":[{"red":1.0,"green":1.0,"blue":1.0,"alpha":0.7734375,"linear":true},{"red":1.0,"green":1.0,"blue":1.0,"alpha":0.01,"linear":true}],"position":[0.0,1.0],"midpoint":[0.5,0.5]},"gradient_space":"RgbGamma"}},"exposed":false}},{"Value":{"tagged_value":{"GradientForm":"Radial"},"exposed":false}},{"Value":{"tagged_value":{"Bool":true},"exposed":false}},{"Value":{"tagged_value":{"DAffine2":[31.55635094002563,-2.7755575615628914e-17,2.7755575615628914e-17,31.55635094002563,-0.225779263556106,34.981204988590605]},"exposed":false}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"graphene_core::vector::FillNode"}},"visible":true,"skip_deduplication":false}],[183562335973647870,{"inputs":[{"Node":{"node_id":4248875763694880300,"output_index":0}},{"Node":{"node_id":2181148486404191200,"output_index":0}}],"call_argument":{"Generic":"T"},"implementation":{"Network":{"exports":[{"Node":{"node_id":5,"output_index":0}}],"nodes":[[0,{"inputs":[{"Import":{"import_type":{"Generic":"T"},"import_index":0}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::AsGraphicNode"}},"visible":true,"skip_deduplication":false}],[1,{"inputs":[{"Import":{"import_type":{"Generic":"T"},"import_index":1}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::IntoGroupNode"}},"visible":true,"skip_deduplication":false}],[2,{"inputs":[{"Reflection":"DocumentNodePath"}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::PathOfSubgraphNode"}},"visible":true,"skip_deduplication":false}],[3,{"inputs":[{"Node":{"node_id":1,"output_index":0}},{"Node":{"node_id":2,"output_index":0}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::StampLayerPathNode"}},"visible":true,"skip_deduplication":false}],[4,{"inputs":[{"Node":{"node_id":3,"output_index":0}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"graphene_core::memo::MonitorNode"}},"visible":true,"skip_deduplication":true}],[5,{"inputs":[{"Node":{"node_id":0,"output_index":0}},{"Node":{"node_id":4,"output_index":0}}],"call_argument":{"Generic":"T"},"implementation":{"ProtoNode":{"name":"graphene_core::list::ExtendNode"}},"visible":true,"skip_deduplication":false}]],"scope_injections":[]}},"visible":true,"skip_deduplication":false}],[655907162126315400,{"inputs":[{"Value":{"tagged_value":{"TypeDefault":{"name":"core_types::list::List<vector_types::vector::vector_types::Vector>"}},"exposed":true}},{"Value":{"tagged_value":{"VectorModification":{"points":{"add":[1,2,3,4,5,6,7,8,9,10,11],"remove":[],"delta":[[1,[416.0,270.9999999999999]],[2,[587.0,291.9999999999999]],[3,[373.0,372.9999999999999]],[4,[484.0,446.9999999999999]],[5,[639.0,438.9999999999999]],[6,[495.0,533.9999999999999]],[7,[304.0,611.9999999999999]],[8,[475.0,671.9999999999999]],[9,[750.0,703.9999999999999]],[10,[455.0,824.9999999999999]],[11,[186.0,824.9999999999999]]]},"segments":{"add":[1,2,3,4,5,6,7,8,9,10],"remove":[],"start_point":[[1,1],[2,2],[3,3],[4,4],[5,5],[6,6],[7,7],[8,8],[9,9],[10,10]],"end_point":[[1,2],[2,3],[3,4],[4,5],[5,6],[6,7],[7,8],[8,9],[9,10],[10,11]],"handle_primary":[[1,[0.0,0.0]],[2,[0.0,0.0]],[3,[0.0,0.0]],[4,[0.0,0.0]],[5,[0.0,0.0]],[6,[0.0,0.0]],[7,[0.0,0.0]],[8,[0.0,0.0]],[9,[0.0,0.0]],[10,[0.0,0.0]]],"handle_end":[[1,[0.0,0.0]],[2,[0.0,0.0]],[3,[0.0,0.0]],[4,[0.0,0.0]],[5,[0.0,0.0]],[6,[0.0,0.0]],[7,[0.0,0.0]],[8,[0.0,0.0]],[9,[0.0,0.0]],[10,[0.0,0.0]]],"stroke":[[1,0],[2,0],[3,0],[4,0],[5,0],[6,0],[7,0],[8,0],[9,0],[10,0]]},"regions":{"add":[],"remove":[],"segment_range":[],"fill":[]},"add_g1_continuous":[],"remove_g1_continuous":[]}},"exposed":false}}],"call_argument":{"Generic":"T"},"implementation":{"Network":{"exports":[{"Node":{"node_id":1,"output_index":0}}],"nodes":[[0,{"inputs":[{"Import":{"import_type":{"Concrete":{"name":"core_types::list::List<vector_types::vector::vector_types::Vector>"}},"import_index":0}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"PrLine truncated
|
||||
Generated
+1
-1
@@ -1 +1 @@
|
||||
{"network_interface":{"network":{"exports":[{"Node":{"node_id":2394762731964337494,"output_index":0}}],"nodes":[[1378578509112405,{"inputs":[{"Value":{"tagged_value":{"TypeDefault":{"Item":{"Concrete":{"name":"vector_types::vector::vector_types::Vector"}}}},"exposed":true}},{"Value":{"tagged_value":{"VectorModification":{"points":{"add":[1,2,3,4,5],"remove":[],"delta":[[1,[602.6886145404666,50.91906721536352]],[2,[599.5281207133061,50.3923182441701]],[3,[590.4855967078191,66.80932784636488]],[4,[594.6410608139003,75.57872275567746]],[5,[593.3924706599604,60.59564090839812]]]},"segments":{"add":[1,2,3,4,5],"remove":[],"start_point":[[1,1],[2,2],[3,3],[4,4],[5,5]],"end_point":[[1,2],[2,3],[3,4],[4,5],[5,1]],"handle_primary":[[1,[0.0,0.0]],[2,[-1.843621399176982,0.5267489711934203]],[3,[1.9314128943758533,7.3257125438195345]],[4,[0.0,0.0]],[5,[1.248590153939972,-3.9798811156835896]]],"handle_end":[[1,[1.843621399176982,-0.5267489711934203]],[2,[-2.7532629181224593,-10.4429315732828]],[3,[0.0,0.0]],[4,[-1.704168058538812,5.432035686592322]],[5,[-4.379820149367788,0.9754610577655498]]],"stroke":[[1,0],[2,0],[3,0],[4,0],[5,0]]},"regions":{"add":[0],"remove":[],"segment_range":[[0,{"start":1,"end":5}]],"fill":[[0,0]]},"add_g1_continuous":[],"remove_g1_continuous":[]}},"exposed":false}}],"call_argument":{"Generic":"T"},"implementation":{"Network":{"exports":[{"Node":{"node_id":1,"output_index":0}}],"nodes":[[0,{"inputs":[{"Import":{"import_type":{"Generic":"T"},"import_index":0}}],"call_argument":{"Concrete":{"name":"core::option::Option<alloc::sync::Arc<core_types::context::OwnedContextImpl>>"}},"implementation":{"ProtoNode":{"name":"graphene_core::memo::MonitorNode"}},"visible":true,"skip_deduplication":true,"context_features":{"extract":"","inject":""}}],[1,{"inputs":[{"Node":{"node_id":0,"output_index":0}},{"Import":{"import_type":{"Concrete":{"name":"vector_types::vector::vector_modification::VectorModification"}},"import_index":1}},{"Reflection":"DocumentNodePath"}],"call_argument":{"Generic":"T"},"implementation":{"ProtoNode":{"name":"vector_nodes::vector_modification_nodes::PathModifyNode"}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}]],"scope_injections":[]}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}],[172538270105470471,{"inputs":[{"Node":{"node_id":9276497172451351253,"output_index":0}},{"Value":{"tagged_value":{"Color":{"red":0.78353786,"green":0.6038274,"blue":0.33245158,"alpha":1.0,"linear":true}},"exposed":false}},{"Value":{"tagged_value":{"Color":{"red":0.78353786,"green":0.6038274,"blue":0.33245158,"alpha":1.0,"linear":true}},"exposed":false}},{"Value":{"tagged_value":{"GradientRamp":{"stops":{"color":[{"red":0.0,"green":0.0,"blue":0.0,"alpha":1.0,"linear":true},{"red":1.0,"green":1.0,"blue":1.0,"alpha":1.0,"linear":true}],"position":[0.0,1.0],"midpoint":[0.5,0.5]},"gradient_space":"RgbGamma"}},"exposed":false}},{"Value":{"tagged_value":{"GradientForm":"Linear"},"exposed":false}},{"Value":{"tagged_value":{"Bool":true},"exposed":false}},{"Value":{"tagged_value":{"DAffine2":[2.170365521878466,0.0,0.0,2.170365521878466,604.9565968314213,108.54930650815425]},"exposed":false}}],"call_argument":{"Concrete":{"name":"core::option::Option<alloc::sync::Arc<core_types::context::OwnedContextImpl>>"}},"implementation":{"ProtoNode":{"name":"graphene_core::vector::FillNode"}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}],[314278016428495768,{"inputs":[{"Node":{"node_id":6282972142629473139,"output_index":0}},{"Node":{"node_id":5020096817747898028,"output_index":0}}],"call_argument":{"Generic":"T"},"implementation":{"Network":{"exports":[{"Node":{"node_id":5,"output_index":0}}],"nodes":[[0,{"inputs":[{"Import":{"import_type":{"Generic":"T"},"import_index":0}}],"call_argument":{"Concrete":{"name":"core::option::Option<alloc::sync::Arc<core_types::context::OwnedContextImpl>>"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::AsGraphicNode"}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}],[1,{"inputs":[{"Import":{"import_type":{"Generic":"T"},"import_index":1}}],"call_argument":{"Concrete":{"name":"core::option::Option<alloc::sync::Arc<core_types::context::OwnedContextImpl>>"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::IntoGroupNode"}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}],[2,{"inputs":[{"Reflection":"DocumentNodePath"}],"call_argument":{"Concrete":{"name":"core::option::Option<alloc::sync::Arc<core_types::context::OwnedContextImpl>>"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::PathOfSubgraphNode"}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}],[3,{"inputs":[{"Node":{"node_id":1,"output_index":0}},{"Value":{"tagged_value":{"String":"editor:layer_path"},"exposed":false}},{"Node":{"node_id":2Line truncated
|
||||
{"network_interface":{"network":{"exports":[{"Node":{"node_id":2394762731964337494,"output_index":0}}],"nodes":[[1378578509112405,{"inputs":[{"Value":{"tagged_value":{"TypeDefault":{"name":"core_types::list::List<vector_types::vector::vector_types::Vector>"}},"exposed":true}},{"Value":{"tagged_value":{"VectorModification":{"points":{"add":[1,2,3,4,5],"remove":[],"delta":[[1,[602.6886145404666,50.91906721536352]],[2,[599.5281207133061,50.3923182441701]],[3,[590.4855967078191,66.80932784636488]],[4,[594.6410608139003,75.57872275567746]],[5,[593.3924706599604,60.59564090839812]]]},"segments":{"add":[1,2,3,4,5],"remove":[],"start_point":[[1,1],[2,2],[3,3],[4,4],[5,5]],"end_point":[[1,2],[2,3],[3,4],[4,5],[5,1]],"handle_primary":[[1,[0.0,0.0]],[2,[-1.843621399176982,0.5267489711934203]],[3,[1.9314128943758533,7.3257125438195345]],[4,[0.0,0.0]],[5,[1.248590153939972,-3.9798811156835896]]],"handle_end":[[1,[1.843621399176982,-0.5267489711934203]],[2,[-2.7532629181224593,-10.4429315732828]],[3,[0.0,0.0]],[4,[-1.704168058538812,5.432035686592322]],[5,[-4.379820149367788,0.9754610577655498]]],"stroke":[[1,0],[2,0],[3,0],[4,0],[5,0]]},"regions":{"add":[0],"remove":[],"segment_range":[[0,{"start":1,"end":5}]],"fill":[[0,0]]},"add_g1_continuous":[],"remove_g1_continuous":[]}},"exposed":false}}],"call_argument":{"Generic":"T"},"implementation":{"Network":{"exports":[{"Node":{"node_id":1,"output_index":0}}],"nodes":[[0,{"inputs":[{"Import":{"import_type":{"Concrete":{"name":"core_types::list::List<vector_types::vector::vector_types::Vector>"}},"import_index":0}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"graphene_core::memo::MonitorNode"}},"visible":true,"skip_deduplication":true}],[1,{"inputs":[{"Node":{"node_id":0,"output_index":0}},{"Import":{"import_type":{"Concrete":{"name":"vector_types::vector::vector_modification::VectorModification"}},"import_index":1}},{"Reflection":"DocumentNodePath"}],"call_argument":{"Generic":"T"},"implementation":{"ProtoNode":{"name":"vector_nodes::vector_modification_nodes::PathModifyNode"}},"visible":true,"skip_deduplication":false}]],"scope_injections":[]}},"visible":true,"skip_deduplication":false}],[172538270105470471,{"inputs":[{"Node":{"node_id":9276497172451351253,"output_index":0}},{"Value":{"tagged_value":{"Color":{"red":0.78353786,"green":0.6038274,"blue":0.33245158,"alpha":1.0,"linear":true}},"exposed":false}},{"Value":{"tagged_value":{"Color":{"red":0.78353786,"green":0.6038274,"blue":0.33245158,"alpha":1.0,"linear":true}},"exposed":false}},{"Value":{"tagged_value":{"GradientRamp":{"stops":{"color":[{"red":0.0,"green":0.0,"blue":0.0,"alpha":1.0,"linear":true},{"red":1.0,"green":1.0,"blue":1.0,"alpha":1.0,"linear":true}],"position":[0.0,1.0],"midpoint":[0.5,0.5]},"gradient_space":"RgbGamma"}},"exposed":false}},{"Value":{"tagged_value":{"GradientForm":"Linear"},"exposed":false}},{"Value":{"tagged_value":{"Bool":true},"exposed":false}},{"Value":{"tagged_value":{"DAffine2":[2.170365521878466,0.0,0.0,2.170365521878466,604.9565968314213,108.54930650815425]},"exposed":false}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"graphene_core::vector::FillNode"}},"visible":true,"skip_deduplication":false}],[314278016428495768,{"inputs":[{"Node":{"node_id":6282972142629473139,"output_index":0}},{"Node":{"node_id":5020096817747898028,"output_index":0}}],"call_argument":{"Generic":"T"},"implementation":{"Network":{"exports":[{"Node":{"node_id":5,"output_index":0}}],"nodes":[[0,{"inputs":[{"Import":{"import_type":{"Generic":"T"},"import_index":0}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::AsGraphicNode"}},"visible":true,"skip_deduplication":false}],[1,{"inputs":[{"Import":{"import_type":{"Generic":"T"},"import_index":1}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::IntoGroupNode"}},"visible":true,"skip_deduplication":false}],[2,{"inputs":[{"Reflection":"DocumentNodePath"}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::PathOfSubgraphNode"}},"visible":true,"skip_deduplication":false}],[3,{"inputs":[{"Node":{"node_id":1,"output_index":0}},{"Node":{"node_id":2,"output_index":0}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::StampLayerPathNode"}},"visible":true,"skip_deduplication":false}],[4,{"inputs":[{"Node":{"node_id":3,"output_index":0}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"graphene_core::memo::MonitorNode"}},"visible":true,"skip_deduplication":true}],[5,{"inputs":[{"Node":{"node_id":0,"output_index":0}},{"Node":{"node_id":4,Line truncated
|
||||
Generated
+1
-1
@@ -1 +1 @@
|
||||
{"network_interface":{"network":{"exports":[{"Node":{"node_id":16815500381887058038,"output_index":0}}],"nodes":[[74,{"inputs":[{"Node":{"node_id":75,"output_index":0}},{"Node":{"node_id":81,"output_index":0}}],"call_argument":{"Generic":"T"},"implementation":{"Network":{"exports":[{"Node":{"node_id":5,"output_index":0}}],"nodes":[[0,{"inputs":[{"Import":{"import_type":{"Generic":"T"},"import_index":0}}],"call_argument":{"Concrete":{"name":"core::option::Option<alloc::sync::Arc<core_types::context::OwnedContextImpl>>"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::AsGraphicNode"}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}],[1,{"inputs":[{"Import":{"import_type":{"Generic":"T"},"import_index":1}}],"call_argument":{"Concrete":{"name":"core::option::Option<alloc::sync::Arc<core_types::context::OwnedContextImpl>>"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::IntoGroupNode"}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}],[2,{"inputs":[{"Reflection":"DocumentNodePath"}],"call_argument":{"Concrete":{"name":"core::option::Option<alloc::sync::Arc<core_types::context::OwnedContextImpl>>"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::PathOfSubgraphNode"}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}],[3,{"inputs":[{"Node":{"node_id":1,"output_index":0}},{"Value":{"tagged_value":{"String":"editor:layer_path"},"exposed":false}},{"Node":{"node_id":2,"output_index":0}}],"call_argument":{"Concrete":{"name":"core::option::Option<alloc::sync::Arc<core_types::context::OwnedContextImpl>>"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::WriteAttributeNode"}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}],[4,{"inputs":[{"Node":{"node_id":3,"output_index":0}}],"call_argument":{"Concrete":{"name":"core::option::Option<alloc::sync::Arc<core_types::context::OwnedContextImpl>>"}},"implementation":{"ProtoNode":{"name":"graphene_core::memo::MonitorNode"}},"visible":true,"skip_deduplication":true,"context_features":{"extract":"","inject":""}}],[5,{"inputs":[{"Node":{"node_id":0,"output_index":0}},{"Node":{"node_id":4,"output_index":0}}],"call_argument":{"Generic":"T"},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::ExtendNode"}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}]],"scope_injections":[]}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}],[75,{"inputs":[{"Node":{"node_id":76,"output_index":0}},{"Node":{"node_id":161,"output_index":0}}],"call_argument":{"Generic":"T"},"implementation":{"Network":{"exports":[{"Node":{"node_id":5,"output_index":0}}],"nodes":[[0,{"inputs":[{"Import":{"import_type":{"Generic":"T"},"import_index":0}}],"call_argument":{"Concrete":{"name":"core::option::Option<alloc::sync::Arc<core_types::context::OwnedContextImpl>>"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::AsGraphicNode"}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}],[1,{"inputs":[{"Import":{"import_type":{"Generic":"T"},"import_index":1}}],"call_argument":{"Concrete":{"name":"core::option::Option<alloc::sync::Arc<core_types::context::OwnedContextImpl>>"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::IntoGroupNode"}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}],[2,{"inputs":[{"Reflection":"DocumentNodePath"}],"call_argument":{"Concrete":{"name":"core::option::Option<alloc::sync::Arc<core_types::context::OwnedContextImpl>>"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::PathOfSubgraphNode"}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}],[3,{"inputs":[{"Node":{"node_id":1,"output_index":0}},{"Value":{"tagged_value":{"String":"editor:layer_path"},"exposed":false}},{"Node":{"node_id":2,"output_index":0}}],"call_argument":{"Concrete":{"name":"core::option::Option<alloc::sync::Arc<core_types::context::OwnedContextImpl>>"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::WriteAttributeNode"}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}],[4,{"inputs":[{"Node":{"node_id":3,"output_index":0}}],"call_argument":{"Concrete":{"name":"core::option::Option<alloc::sync::Arc<core_types::context::OwnedContextImpl>>"}},"implementation":{"ProtoNode":{"name":"graphene_core::memo::MonitorNode"}},"visible":true,"skip_deduplication":true,"context_features":{"extract":"","inject":""}}],[5,{"inputs":[{"Node":{"node_id":0,"output_index":0}},{"Node":{"node_id":4,"output_index":0}}],"call_argument":{"Generic":"T"},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::ExtendNode"}},"visible":true,"skip_deduplication":false,"context_features":{"extract":"","inject":""}}]],"scope_Line truncated
|
||||
{"network_interface":{"network":{"exports":[{"Node":{"node_id":16815500381887058038,"output_index":0}}],"nodes":[[74,{"inputs":[{"Node":{"node_id":75,"output_index":0}},{"Node":{"node_id":81,"output_index":0}}],"call_argument":{"Generic":"T"},"implementation":{"Network":{"exports":[{"Node":{"node_id":5,"output_index":0}}],"nodes":[[0,{"inputs":[{"Import":{"import_type":{"Generic":"T"},"import_index":0}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::AsGraphicNode"}},"visible":true,"skip_deduplication":false}],[1,{"inputs":[{"Import":{"import_type":{"Generic":"T"},"import_index":1}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::IntoGroupNode"}},"visible":true,"skip_deduplication":false}],[2,{"inputs":[{"Reflection":"DocumentNodePath"}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::PathOfSubgraphNode"}},"visible":true,"skip_deduplication":false}],[3,{"inputs":[{"Node":{"node_id":1,"output_index":0}},{"Node":{"node_id":2,"output_index":0}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::StampLayerPathNode"}},"visible":true,"skip_deduplication":false}],[4,{"inputs":[{"Node":{"node_id":3,"output_index":0}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"graphene_core::memo::MonitorNode"}},"visible":true,"skip_deduplication":true}],[5,{"inputs":[{"Node":{"node_id":0,"output_index":0}},{"Node":{"node_id":4,"output_index":0}}],"call_argument":{"Generic":"T"},"implementation":{"ProtoNode":{"name":"graphene_core::list::ExtendNode"}},"visible":true,"skip_deduplication":false}]],"scope_injections":[]}},"visible":true,"skip_deduplication":false}],[75,{"inputs":[{"Node":{"node_id":76,"output_index":0}},{"Node":{"node_id":161,"output_index":0}}],"call_argument":{"Generic":"T"},"implementation":{"Network":{"exports":[{"Node":{"node_id":5,"output_index":0}}],"nodes":[[0,{"inputs":[{"Import":{"import_type":{"Generic":"T"},"import_index":0}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::AsGraphicNode"}},"visible":true,"skip_deduplication":false}],[1,{"inputs":[{"Import":{"import_type":{"Generic":"T"},"import_index":1}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::IntoGroupNode"}},"visible":true,"skip_deduplication":false}],[2,{"inputs":[{"Reflection":"DocumentNodePath"}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::PathOfSubgraphNode"}},"visible":true,"skip_deduplication":false}],[3,{"inputs":[{"Node":{"node_id":1,"output_index":0}},{"Node":{"node_id":2,"output_index":0}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::StampLayerPathNode"}},"visible":true,"skip_deduplication":false}],[4,{"inputs":[{"Node":{"node_id":3,"output_index":0}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"graphene_core::memo::MonitorNode"}},"visible":true,"skip_deduplication":true}],[5,{"inputs":[{"Node":{"node_id":0,"output_index":0}},{"Node":{"node_id":4,"output_index":0}}],"call_argument":{"Generic":"T"},"implementation":{"ProtoNode":{"name":"graphene_core::list::ExtendNode"}},"visible":true,"skip_deduplication":false}]],"scope_injections":[]}},"visible":true,"skip_deduplication":false}],[76,{"inputs":[{"Node":{"node_id":77,"output_index":0}},{"Node":{"node_id":16164610528699022118,"output_index":0}}],"call_argument":{"Generic":"T"},"implementation":{"Network":{"exports":[{"Node":{"node_id":5,"output_index":0}}],"nodes":[[0,{"inputs":[{"Import":{"import_type":{"Generic":"T"},"import_index":0}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::AsGraphicNode"}},"visible":true,"skip_deduplication":false}],[1,{"inputs":[{"Import":{"import_type":{"Generic":"T"},"import_index":1}}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::IntoGroupNode"}},"visible":true,"skip_deduplication":false}],[2,{"inputs":[{"Reflection":"DocumentNodePath"}],"call_argument":{"Concrete":{"name":"core_types::context::ContextImpl"}},"implementation":{"ProtoNode":{"name":"graphic_nodes::graphic::PathOfSubgraphNode"}},"visible":true,"skip_deduplication":false}],[3,{"inputs":[{"Node":{"node_id":1,"output_index":0}},{"Node":{"node_id":2,"output_index":0}}],"call_argumenLine truncated
|
||||
+7
-7
@@ -1,12 +1,12 @@
|
||||
[package]
|
||||
name = "graphite-desktop"
|
||||
version = "0.1.0"
|
||||
description = "Graphite Desktop"
|
||||
version.workspace = true
|
||||
license.workspace = true
|
||||
authors.workspace = true
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
publish.workspace = true
|
||||
authors = ["Graphite Authors <[email protected]>"]
|
||||
license = "MIT OR Apache-2.0"
|
||||
repository = ""
|
||||
edition = "2024"
|
||||
rust-version = "1.87"
|
||||
|
||||
[[bin]]
|
||||
name = "graphite"
|
||||
@@ -44,12 +44,12 @@ rfd = { workspace = true }
|
||||
open = { workspace = true }
|
||||
lzma-rust2 = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
url = { workspace = true }
|
||||
rand = { workspace = true, features = ["thread_rng"] }
|
||||
clap = { workspace = true, features = ["derive"] }
|
||||
interprocess = "2.4.2"
|
||||
fd-lock = "4.0.4"
|
||||
ctrlc = "3.5.1"
|
||||
window_clipboard = "0.5"
|
||||
|
||||
# Windows-specific dependencies
|
||||
[target.'cfg(target_os = "windows")'.dependencies]
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
[package]
|
||||
name = "graphite-desktop-bundle"
|
||||
version = "0.0.0"
|
||||
description = "Graphite Desktop Bundle"
|
||||
version.workspace = true
|
||||
license.workspace = true
|
||||
authors.workspace = true
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
publish.workspace = true
|
||||
authors = ["Graphite Authors <[email protected]>"]
|
||||
license = "MIT OR Apache-2.0"
|
||||
repository = ""
|
||||
edition = "2024"
|
||||
rust-version = "1.87"
|
||||
|
||||
[dependencies]
|
||||
cef-dll-sys = { workspace = true }
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
[package]
|
||||
name = "graphite-desktop-embedded-resources"
|
||||
version = "0.1.0"
|
||||
description = "Graphite Desktop Embedded Resources"
|
||||
version.workspace = true
|
||||
license.workspace = true
|
||||
authors.workspace = true
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
publish.workspace = true
|
||||
authors = ["Graphite Authors <[email protected]>"]
|
||||
license = "MIT OR Apache-2.0"
|
||||
repository = ""
|
||||
edition = "2024"
|
||||
rust-version = "1.87"
|
||||
|
||||
[dependencies]
|
||||
include_dir = { workspace = true }
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
[package]
|
||||
name = "graphite-desktop-platform-linux"
|
||||
version = "0.0.0"
|
||||
description = "Graphite Desktop Platform Linux"
|
||||
version.workspace = true
|
||||
license.workspace = true
|
||||
authors.workspace = true
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
publish.workspace = true
|
||||
authors = ["Graphite Authors <[email protected]>"]
|
||||
license = "MIT OR Apache-2.0"
|
||||
repository = ""
|
||||
edition = "2024"
|
||||
rust-version = "1.87"
|
||||
|
||||
[[bin]]
|
||||
name = "graphite"
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
[package]
|
||||
name = "graphite-desktop-platform-mac"
|
||||
version = "0.0.0"
|
||||
description = "Graphite Desktop Platform Mac"
|
||||
version.workspace = true
|
||||
license.workspace = true
|
||||
authors.workspace = true
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
publish.workspace = true
|
||||
authors = ["Graphite Authors <[email protected]>"]
|
||||
license = "MIT OR Apache-2.0"
|
||||
repository = ""
|
||||
edition = "2024"
|
||||
rust-version = "1.87"
|
||||
|
||||
[features]
|
||||
main = ["dep:graphite-desktop"]
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
[package]
|
||||
name = "graphite-desktop-platform-win"
|
||||
version = "0.0.0"
|
||||
description = "Graphite Desktop Platform Windows"
|
||||
version.workspace = true
|
||||
license.workspace = true
|
||||
authors.workspace = true
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
publish.workspace = true
|
||||
authors = ["Graphite Authors <[email protected]>"]
|
||||
license = "MIT OR Apache-2.0"
|
||||
repository = ""
|
||||
edition = "2024"
|
||||
rust-version = "1.87"
|
||||
|
||||
[[bin]]
|
||||
name = "graphite"
|
||||
|
||||
+33
-96
@@ -9,11 +9,10 @@ use std::sync::mpsc::{Receiver, SyncSender};
|
||||
use std::thread;
|
||||
use std::time::{Duration, Instant};
|
||||
use winit::application::ApplicationHandler;
|
||||
use winit::data_transfer::{DataTransferSendBuilder, TypeHint};
|
||||
use winit::dpi::PhysicalSize;
|
||||
use winit::event::{ElementState, MouseButton, StartCause, WindowEvent};
|
||||
use winit::event_loop::run_on_demand::EventLoopExtRunOnDemand;
|
||||
use winit::event_loop::{ActiveEventLoop, AsyncRequestSerial, ControlFlow, DndAction, EventLoop};
|
||||
use winit::event_loop::{ActiveEventLoop, ControlFlow, EventLoop};
|
||||
use winit::window::WindowId;
|
||||
|
||||
use crate::dirs;
|
||||
@@ -24,7 +23,7 @@ use crate::preferences;
|
||||
use crate::render::{RenderError, RenderState};
|
||||
use crate::ui::{InputEvent, UiCommand, UiInstance};
|
||||
use crate::window::Window;
|
||||
use crate::wrapper::messages::{DesktopFrontendMessage, DesktopWrapperMessage, IngestAction, Preferences};
|
||||
use crate::wrapper::messages::{DesktopFrontendMessage, DesktopWrapperMessage, Preferences};
|
||||
use crate::wrapper::{DesktopWrapper, MmapResourceStorage, NodeGraphExecutionResult, WgpuContext, serialize_frontend_messages};
|
||||
|
||||
pub(crate) struct App {
|
||||
@@ -36,8 +35,6 @@ pub(crate) struct App {
|
||||
window_maximized: bool,
|
||||
window_fullscreen: bool,
|
||||
window_pending_drag: bool,
|
||||
pending_dnd_fetch: Option<AsyncRequestSerial>,
|
||||
pending_clipboard_fetch: Option<AsyncRequestSerial>,
|
||||
input_state: InputState,
|
||||
ui_scale: f64,
|
||||
app_event_receiver: Receiver<AppEvent>,
|
||||
@@ -101,6 +98,11 @@ impl App {
|
||||
});
|
||||
let desktop_wrapper = DesktopWrapper::new(rand::rng().random(), Arc::new(resource_storage), dirs::app_autosave_documents_dir(), wgpu_context.clone(), wake);
|
||||
|
||||
let completion_render_sender = start_render_sender.clone();
|
||||
DesktopWrapper::set_completion_notifier(move || {
|
||||
let _ = completion_render_sender.try_send(());
|
||||
});
|
||||
|
||||
Self {
|
||||
render_state: None,
|
||||
wgpu_context,
|
||||
@@ -110,8 +112,6 @@ impl App {
|
||||
window_maximized: false,
|
||||
window_fullscreen: false,
|
||||
window_pending_drag: false,
|
||||
pending_dnd_fetch: None,
|
||||
pending_clipboard_fetch: None,
|
||||
input_state: InputState::new(),
|
||||
ui_scale: 1.,
|
||||
app_event_receiver,
|
||||
@@ -205,15 +205,15 @@ impl App {
|
||||
};
|
||||
self.send_or_queue_web_message(bytes);
|
||||
}
|
||||
DesktopFrontendMessage::OpenFileDialog { title, options, action } => {
|
||||
DesktopFrontendMessage::OpenFileDialog { title, filters, multiple, context } => {
|
||||
let app_event_scheduler = self.app_event_scheduler.clone();
|
||||
let _ = thread::spawn(move || {
|
||||
let mut dialog = AsyncFileDialog::new().set_title(title);
|
||||
for filter in options.filters {
|
||||
for filter in filters {
|
||||
dialog = dialog.add_filter(filter.name, &filter.extensions);
|
||||
}
|
||||
|
||||
let handles = if options.multiple {
|
||||
let handles = if multiple {
|
||||
futures::executor::block_on(dialog.pick_files()).unwrap_or_default()
|
||||
} else {
|
||||
futures::executor::block_on(dialog.pick_file()).into_iter().collect()
|
||||
@@ -223,8 +223,7 @@ impl App {
|
||||
let path = handle.path().to_path_buf();
|
||||
match fs::read(&path) {
|
||||
Ok(content) => {
|
||||
let action = action.clone();
|
||||
let message = DesktopWrapperMessage::IngestFile { path, content, action };
|
||||
let message = DesktopWrapperMessage::FileDialogResult { path, content, context };
|
||||
app_event_scheduler.schedule(AppEvent::DesktopWrapperMessage(message));
|
||||
}
|
||||
Err(e) => tracing::error!("Failed to read file {}: {}", path.display(), e),
|
||||
@@ -341,10 +340,16 @@ impl App {
|
||||
}
|
||||
}
|
||||
DesktopFrontendMessage::ClipboardRead => {
|
||||
self.app_event_scheduler.schedule(AppEvent::ClipboardRead);
|
||||
if let Some(window) = &self.window {
|
||||
let content = window.clipboard_read();
|
||||
let message = DesktopWrapperMessage::ClipboardReadResult { content };
|
||||
self.app_event_scheduler.schedule(AppEvent::DesktopWrapperMessage(message));
|
||||
}
|
||||
}
|
||||
DesktopFrontendMessage::ClipboardWrite { content } => {
|
||||
self.app_event_scheduler.schedule(AppEvent::ClipboardWrite { content });
|
||||
if let Some(window) = &mut self.window {
|
||||
window.clipboard_write(content);
|
||||
}
|
||||
}
|
||||
DesktopFrontendMessage::PointerLock => {
|
||||
self.input_state.lock_pointer();
|
||||
@@ -467,32 +472,6 @@ impl App {
|
||||
self.ui_frame_received = true;
|
||||
}
|
||||
}
|
||||
AppEvent::ClipboardRead => {
|
||||
let result = event_loop.clipboard().and_then(|id| {
|
||||
let Some(id) = id else { return Ok(None) };
|
||||
let data_transfer = event_loop.data_transfer(id)?;
|
||||
if !data_transfer.has_type(&TypeHint::Plaintext) {
|
||||
return Ok(None);
|
||||
}
|
||||
event_loop.fetch_data_transfer(id, &TypeHint::Plaintext).map(Some)
|
||||
});
|
||||
match result {
|
||||
Ok(Some(serial)) => self.pending_clipboard_fetch = Some(serial),
|
||||
Ok(None) => self.dispatch_desktop_wrapper_message(DesktopWrapperMessage::ClipboardReadResult { content: None }),
|
||||
Err(e) => {
|
||||
tracing::error!("Failed to read from clipboard: {e}");
|
||||
self.dispatch_desktop_wrapper_message(DesktopWrapperMessage::ClipboardReadResult { content: None });
|
||||
}
|
||||
}
|
||||
}
|
||||
AppEvent::ClipboardWrite { content } => {
|
||||
let send_data = DataTransferSendBuilder::new(content)
|
||||
.with_type(TypeHint::Plaintext, |content: &String, _| Some(content.clone()))
|
||||
.build();
|
||||
if let Err(e) = event_loop.set_clipboard(send_data) {
|
||||
tracing::error!("Failed to write to clipboard: {e}");
|
||||
}
|
||||
}
|
||||
AppEvent::CursorChange(cursor) => {
|
||||
if let Some(window) = &mut self.window {
|
||||
window.set_cursor(event_loop, cursor);
|
||||
@@ -521,11 +500,7 @@ impl App {
|
||||
for path in paths {
|
||||
tracing::info!("Opening file: {}", path.display());
|
||||
if let Ok(content) = fs::read(&path) {
|
||||
let message = DesktopWrapperMessage::IngestFile {
|
||||
path,
|
||||
content,
|
||||
action: IngestAction::Open,
|
||||
};
|
||||
let message = DesktopWrapperMessage::OpenFile { path, content };
|
||||
app_event_scheduler.schedule(AppEvent::DesktopWrapperMessage(message));
|
||||
} else {
|
||||
tracing::error!("Failed to read file: {}", path.display());
|
||||
@@ -568,7 +543,7 @@ impl ApplicationHandler for App {
|
||||
}
|
||||
}
|
||||
|
||||
fn window_event(&mut self, event_loop: &dyn ActiveEventLoop, _window_id: WindowId, event: WindowEvent) {
|
||||
fn window_event(&mut self, _event_loop: &dyn ActiveEventLoop, _window_id: WindowId, event: WindowEvent) {
|
||||
// Handle pointer lock release
|
||||
if let WindowEvent::PointerButton {
|
||||
state: ElementState::Released,
|
||||
@@ -631,58 +606,20 @@ impl ApplicationHandler for App {
|
||||
self.exit(Some(ExitReason::UiAccelerationFailure));
|
||||
}
|
||||
}
|
||||
WindowEvent::DragEntered { id, .. } => {
|
||||
let accepts = event_loop.data_transfer(id).is_ok_and(|data_transfer| data_transfer.has_type(&TypeHint::UriList));
|
||||
let actions: &[DndAction] = if accepts { &[DndAction::Copy] } else { &[] };
|
||||
if let Err(e) = event_loop.set_valid_dnd_actions(id, actions) {
|
||||
tracing::error!("Failed to set valid drag and drop actions: {e}");
|
||||
WindowEvent::DragDropped { paths, .. } => {
|
||||
for path in paths {
|
||||
match fs::read(&path) {
|
||||
Ok(content) => {
|
||||
let message = DesktopWrapperMessage::ImportFile { path, content };
|
||||
self.app_event_scheduler.schedule(AppEvent::DesktopWrapperMessage(message));
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::error!("Failed to read dropped file {}: {}", path.display(), e);
|
||||
return;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
WindowEvent::DragDropped { id, .. } => match event_loop.fetch_data_transfer(id, &TypeHint::UriList) {
|
||||
Ok(serial) => self.pending_dnd_fetch = Some(serial),
|
||||
Err(e) => tracing::error!("Failed to fetch dropped data: {e}"),
|
||||
},
|
||||
WindowEvent::DataTransferReceived { serial, ref value, .. } if self.pending_clipboard_fetch == Some(serial) => match value.try_as_string() {
|
||||
Ok(content) => {
|
||||
self.pending_clipboard_fetch = None;
|
||||
let message = DesktopWrapperMessage::ClipboardReadResult { content: Some(content) };
|
||||
self.app_event_scheduler.schedule(AppEvent::DesktopWrapperMessage(message));
|
||||
}
|
||||
Err(e) if e.kind() == std::io::ErrorKind::WouldBlock => {}
|
||||
Err(e) => {
|
||||
self.pending_clipboard_fetch = None;
|
||||
tracing::error!("Failed to read from clipboard: {e}");
|
||||
let message = DesktopWrapperMessage::ClipboardReadResult { content: None };
|
||||
self.app_event_scheduler.schedule(AppEvent::DesktopWrapperMessage(message));
|
||||
}
|
||||
},
|
||||
WindowEvent::DataTransferReceived { serial, ref value, .. } if self.pending_dnd_fetch == Some(serial) => match value.try_as_uris() {
|
||||
Ok(uris) => {
|
||||
self.pending_dnd_fetch = None;
|
||||
let paths = uris.iter().filter_map(|uri| url::Url::parse(uri).ok()?.to_file_path().ok());
|
||||
for path in paths {
|
||||
match fs::read(&path) {
|
||||
Ok(content) => {
|
||||
let message = DesktopWrapperMessage::IngestFile {
|
||||
path,
|
||||
content,
|
||||
action: IngestAction::Import,
|
||||
};
|
||||
self.app_event_scheduler.schedule(AppEvent::DesktopWrapperMessage(message));
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::error!("Failed to read dropped file {}: {}", path.display(), e);
|
||||
return;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
Err(e) if e.kind() == std::io::ErrorKind::WouldBlock => {}
|
||||
Err(e) => {
|
||||
self.pending_dnd_fetch = None;
|
||||
tracing::error!("Failed to read dropped data: {e}");
|
||||
}
|
||||
},
|
||||
|
||||
WindowEvent::PointerMoved { .. } | WindowEvent::PointerLeft { position: Some(_), .. } | WindowEvent::PointerEntered { .. }
|
||||
if !self.input_state.pointer_locked() && self.window_pending_drag =>
|
||||
|
||||
+4
-4
@@ -20,10 +20,10 @@ pub(crate) fn clear_dir(path: &PathBuf) {
|
||||
if let Err(e) = fs::remove_dir_all(&entry_path) {
|
||||
tracing::error!("Failed to remove directory at {:?}: {}", entry_path, e);
|
||||
}
|
||||
} else if entry_path.is_file()
|
||||
&& let Err(e) = fs::remove_file(&entry_path)
|
||||
{
|
||||
tracing::error!("Failed to remove file at {:?}: {}", entry_path, e);
|
||||
} else if entry_path.is_file() {
|
||||
if let Err(e) = fs::remove_file(&entry_path) {
|
||||
tracing::error!("Failed to remove file at {:?}: {}", entry_path, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,10 +8,6 @@ pub(crate) enum AppEvent {
|
||||
WebCommunicationInitialized,
|
||||
DesktopWrapperMessage(DesktopWrapperMessage),
|
||||
NodeGraphExecutionResult(NodeGraphExecutionResult),
|
||||
ClipboardRead,
|
||||
ClipboardWrite {
|
||||
content: String,
|
||||
},
|
||||
Exit,
|
||||
UiCrashed,
|
||||
OpenFiles(Vec<std::path::PathBuf>),
|
||||
|
||||
@@ -221,7 +221,6 @@ impl InputState {
|
||||
let input = match delta {
|
||||
MouseScrollDelta::LineDelta(x, y) => InputEvent::pointer().scrolled_lines(f64::from(*x), f64::from(*y)),
|
||||
MouseScrollDelta::PixelDelta(position) => InputEvent::pointer().scrolled_pixels(position.x, position.y),
|
||||
_ => return,
|
||||
};
|
||||
ui_callback(input.modifiers(self.modifiers).build());
|
||||
return;
|
||||
@@ -230,7 +229,6 @@ impl InputState {
|
||||
let (x, y) = match delta {
|
||||
MouseScrollDelta::LineDelta(x, y) => (f64::from(*x) * SCROLL_LINE_WIDTH, f64::from(*y) * SCROLL_LINE_HEIGHT),
|
||||
MouseScrollDelta::PixelDelta(position) => (position.x, position.y),
|
||||
_ => return,
|
||||
};
|
||||
|
||||
let scroll_delta = ScrollDelta::new(-x * SCROLL_SPEED_X, -y * SCROLL_SPEED_Y, 0.);
|
||||
|
||||
@@ -71,11 +71,10 @@ fn garbage_collect_document_files(state: &PersistedState) {
|
||||
|
||||
for entry in entries.flatten() {
|
||||
let path = entry.path();
|
||||
if path.is_file()
|
||||
&& !valid_paths.contains(&path)
|
||||
&& let Err(e) = std::fs::remove_file(&path)
|
||||
{
|
||||
tracing::error!("Failed to remove orphaned document file {path:?}: {e}");
|
||||
if path.is_file() && !valid_paths.contains(&path) {
|
||||
if let Err(e) = std::fs::remove_file(&path) {
|
||||
tracing::error!("Failed to remove orphaned document file {path:?}: {e}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,7 +228,7 @@ impl RenderState {
|
||||
return;
|
||||
};
|
||||
let size = glam::UVec2::new(viewport_texture.width(), viewport_texture.height());
|
||||
let result = futures::executor::block_on(self.executor.render_vello_scene(&scene, size, &Default::default(), None));
|
||||
let result = self.executor.render_vello_scene(&scene, size, &Default::default(), None);
|
||||
match result {
|
||||
Ok(texture) => {
|
||||
self.overlays_texture = Some(texture);
|
||||
|
||||
@@ -43,6 +43,13 @@ pub(crate) struct Window {
|
||||
#[allow(dead_code)]
|
||||
native_handle: native::NativeWindowImpl,
|
||||
custom_cursors: HashMap<CustomCursorSource, CustomCursor>,
|
||||
clipboard: Option<window_clipboard::Clipboard>,
|
||||
}
|
||||
impl Drop for Window {
|
||||
fn drop(&mut self) {
|
||||
// Clipboard must be dropped before `winit_window`
|
||||
drop(self.clipboard.take());
|
||||
}
|
||||
}
|
||||
|
||||
impl Window {
|
||||
@@ -63,10 +70,12 @@ impl Window {
|
||||
|
||||
let winit_window = event_loop.create_window(attributes).unwrap();
|
||||
let native_handle = native::NativeWindowImpl::new(winit_window.as_ref(), app_event_scheduler);
|
||||
let clipboard = unsafe { window_clipboard::Clipboard::connect(&winit_window) }.ok();
|
||||
Self {
|
||||
winit_window: winit_window.into(),
|
||||
native_handle,
|
||||
custom_cursors: HashMap::new(),
|
||||
clipboard,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,4 +208,28 @@ impl Window {
|
||||
pub(crate) fn update_menu(&self, entries: Vec<MenuItem>) {
|
||||
self.native_handle.update_menu(entries);
|
||||
}
|
||||
|
||||
pub(crate) fn clipboard_read(&self) -> Option<String> {
|
||||
let Some(clipboard) = &self.clipboard else {
|
||||
tracing::error!("Clipboard not available");
|
||||
return None;
|
||||
};
|
||||
match clipboard.read() {
|
||||
Ok(data) => Some(data),
|
||||
Err(e) => {
|
||||
tracing::error!("Failed to read from clipboard: {e}");
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn clipboard_write(&mut self, data: String) {
|
||||
let Some(clipboard) = &mut self.clipboard else {
|
||||
tracing::error!("Clipboard not available");
|
||||
return;
|
||||
};
|
||||
if let Err(e) = clipboard.write(data) {
|
||||
tracing::error!("Failed to write to clipboard: {e}")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,9 @@
|
||||
name = "graphite-desktop-ui"
|
||||
description = "Renders the Graphite editor frontend UI into wgpu textures"
|
||||
version.workspace = true
|
||||
license.workspace = true
|
||||
authors.workspace = true
|
||||
license.workspace = true
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
publish.workspace = true
|
||||
|
||||
[features]
|
||||
default = []
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
[package]
|
||||
name = "graphite-desktop-wrapper"
|
||||
version = "0.1.0"
|
||||
description = "Graphite Desktop Wrapper"
|
||||
version.workspace = true
|
||||
license.workspace = true
|
||||
authors.workspace = true
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
publish.workspace = true
|
||||
authors = ["Graphite Authors <[email protected]>"]
|
||||
license = "MIT OR Apache-2.0"
|
||||
repository = ""
|
||||
edition = "2024"
|
||||
rust-version = "1.87"
|
||||
|
||||
[features]
|
||||
gpu = ["graphite-editor/gpu", "graphene-std/shader-nodes"]
|
||||
|
||||
@@ -2,7 +2,7 @@ use graphite_editor::messages::clipboard::utility_types::ClipboardContentRaw;
|
||||
use graphite_editor::messages::prelude::*;
|
||||
|
||||
use super::DesktopWrapperMessageDispatcher;
|
||||
use super::messages::{DesktopFrontendMessage, DesktopWrapperMessage, EditorMessage, SaveFileDialogContext};
|
||||
use super::messages::{DesktopFrontendMessage, DesktopWrapperMessage, EditorMessage, OpenFileDialogContext, SaveFileDialogContext};
|
||||
|
||||
pub(super) fn handle_desktop_wrapper_message(dispatcher: &mut DesktopWrapperMessageDispatcher, message: DesktopWrapperMessage) {
|
||||
match message {
|
||||
@@ -15,14 +15,14 @@ pub(super) fn handle_desktop_wrapper_message(dispatcher: &mut DesktopWrapperMess
|
||||
DesktopWrapperMessage::Input(message) => {
|
||||
dispatcher.queue_editor_message(EditorMessage::InputPreprocessor(message));
|
||||
}
|
||||
DesktopWrapperMessage::IngestFile { path, content, action } => {
|
||||
dispatcher.queue_editor_message(IngestMessage::Ingest {
|
||||
data: content,
|
||||
action,
|
||||
mime_type: String::new(),
|
||||
path: Some(path),
|
||||
});
|
||||
}
|
||||
DesktopWrapperMessage::FileDialogResult { path, content, context } => match context {
|
||||
OpenFileDialogContext::Open => {
|
||||
dispatcher.queue_desktop_wrapper_message(DesktopWrapperMessage::OpenFile { path, content });
|
||||
}
|
||||
OpenFileDialogContext::Import => {
|
||||
dispatcher.queue_desktop_wrapper_message(DesktopWrapperMessage::ImportFile { path, content });
|
||||
}
|
||||
},
|
||||
DesktopWrapperMessage::SaveFileDialogResult { path, context } => match context {
|
||||
SaveFileDialogContext::Document { document_id, content } => {
|
||||
dispatcher.respond(DesktopFrontendMessage::WriteFile { path: path.clone(), content });
|
||||
@@ -35,6 +35,14 @@ pub(super) fn handle_desktop_wrapper_message(dispatcher: &mut DesktopWrapperMess
|
||||
dispatcher.respond(DesktopFrontendMessage::WriteFile { path, content });
|
||||
}
|
||||
},
|
||||
DesktopWrapperMessage::OpenFile { path, content } => {
|
||||
let message = PortfolioMessage::OpenFile { path, content };
|
||||
dispatcher.queue_editor_message(message);
|
||||
}
|
||||
DesktopWrapperMessage::ImportFile { path, content } => {
|
||||
let message = PortfolioMessage::ImportFile { path, content };
|
||||
dispatcher.queue_editor_message(message);
|
||||
}
|
||||
DesktopWrapperMessage::PollNodeGraphEvaluation => dispatcher.poll_node_graph_evaluation(),
|
||||
DesktopWrapperMessage::UpdateMaximized { maximized } => {
|
||||
let message = FrontendMessage::UpdateMaximized { maximized };
|
||||
|
||||
@@ -3,23 +3,27 @@ use graphite_editor::messages::layout::utility_types::layout_widget::LayoutTarge
|
||||
use graphite_editor::messages::prelude::FrontendMessage;
|
||||
|
||||
use super::DesktopWrapperMessageDispatcher;
|
||||
use super::messages::{DesktopFrontendMessage, IngestAction, SaveFileDialogContext};
|
||||
use super::messages::{DesktopFrontendMessage, OpenFileDialogContext, SaveFileDialogContext};
|
||||
|
||||
pub(super) fn intercept_frontend_message(dispatcher: &mut DesktopWrapperMessageDispatcher, message: FrontendMessage) -> Option<FrontendMessage> {
|
||||
match message {
|
||||
FrontendMessage::RenderOverlays { context } => {
|
||||
dispatcher.respond(DesktopFrontendMessage::UpdateOverlays(context.take_scene()));
|
||||
}
|
||||
FrontendMessage::TriggerBrowse { options, action } => {
|
||||
let title = match action {
|
||||
IngestAction::Open => "Open Document",
|
||||
IngestAction::Import => "Import File",
|
||||
_ => "Select File",
|
||||
};
|
||||
FrontendMessage::TriggerOpen { filters } => {
|
||||
dispatcher.respond(DesktopFrontendMessage::OpenFileDialog {
|
||||
title: title.to_string(),
|
||||
options,
|
||||
action,
|
||||
title: "Open Document".to_string(),
|
||||
filters,
|
||||
multiple: true,
|
||||
context: OpenFileDialogContext::Open,
|
||||
});
|
||||
}
|
||||
FrontendMessage::TriggerImport { filters } => {
|
||||
dispatcher.respond(DesktopFrontendMessage::OpenFileDialog {
|
||||
title: "Import File".to_string(),
|
||||
filters,
|
||||
multiple: false,
|
||||
context: OpenFileDialogContext::Import,
|
||||
});
|
||||
}
|
||||
FrontendMessage::TriggerSaveDocument {
|
||||
|
||||
@@ -53,6 +53,10 @@ impl DesktopWrapper {
|
||||
executor.execute()
|
||||
}
|
||||
|
||||
pub fn set_completion_notifier(notifier: impl Fn() + Send + Sync + 'static) {
|
||||
graphite_editor::node_graph_executor::set_completion_notifier(Arc::new(notifier));
|
||||
}
|
||||
|
||||
pub async fn execute_node_graph() -> NodeGraphExecutionResult {
|
||||
let result = graphite_editor::node_graph_executor::run_node_graph().await;
|
||||
match result {
|
||||
|
||||
@@ -44,10 +44,10 @@ impl<'a> DesktopWrapperMessageDispatcher<'a> {
|
||||
|
||||
pub(super) fn poll_node_graph_evaluation(&mut self) {
|
||||
let mut responses = VecDeque::new();
|
||||
if let Err(e) = self.editor.poll_node_graph_evaluation(&mut responses)
|
||||
&& e != "No active document"
|
||||
{
|
||||
tracing::error!("Error poling node graph: {}", e);
|
||||
if let Err(e) = self.editor.poll_node_graph_evaluation(&mut responses) {
|
||||
if e != "No active document" {
|
||||
tracing::error!("Error poling node graph: {}", e);
|
||||
}
|
||||
}
|
||||
while let Some(message) = responses.pop_front() {
|
||||
self.queue_editor_message(message);
|
||||
|
||||
@@ -3,10 +3,9 @@ use std::path::PathBuf;
|
||||
|
||||
pub(crate) use graphite_editor::messages::prelude::Message as EditorMessage;
|
||||
|
||||
pub use graphite_editor::messages::frontend::utility_types::{DocumentInfo, FileDialogOptions, FileFilter, PersistedState};
|
||||
pub use graphite_editor::messages::frontend::utility_types::{DocumentInfo, FileFilter, PersistedState};
|
||||
pub use graphite_editor::messages::input_mapper::utility_types::keyboard::{Key, ModifierKeys};
|
||||
pub use graphite_editor::messages::input_mapper::utility_types::pointer::{EditorPointerState, MouseKeys, ScrollDelta};
|
||||
pub use graphite_editor::messages::portfolio::ingest::utility_types::IngestAction;
|
||||
pub use graphite_editor::messages::prelude::DocumentId;
|
||||
pub use graphite_editor::messages::prelude::InputPreprocessorMessage as InputMessage;
|
||||
pub use graphite_editor::messages::prelude::PreferencesMessageHandler as Preferences;
|
||||
@@ -16,8 +15,9 @@ pub enum DesktopFrontendMessage {
|
||||
OpenLaunchDocuments,
|
||||
OpenFileDialog {
|
||||
title: String,
|
||||
options: FileDialogOptions,
|
||||
action: IngestAction,
|
||||
filters: Vec<FileFilter>,
|
||||
multiple: bool,
|
||||
context: OpenFileDialogContext,
|
||||
},
|
||||
SaveFileDialog {
|
||||
title: String,
|
||||
@@ -87,8 +87,10 @@ pub enum DesktopWrapperMessage {
|
||||
FromWeb(Box<EditorMessage>),
|
||||
Wake,
|
||||
Input(InputMessage),
|
||||
IngestFile { path: PathBuf, content: Vec<u8>, action: IngestAction },
|
||||
FileDialogResult { path: PathBuf, content: Vec<u8>, context: OpenFileDialogContext },
|
||||
SaveFileDialogResult { path: PathBuf, context: SaveFileDialogContext },
|
||||
OpenFile { path: PathBuf, content: Vec<u8> },
|
||||
ImportFile { path: PathBuf, content: Vec<u8> },
|
||||
PollNodeGraphEvaluation,
|
||||
UpdateMaximized { maximized: bool },
|
||||
UpdateFullscreen { fullscreen: bool },
|
||||
@@ -101,6 +103,12 @@ pub enum DesktopWrapperMessage {
|
||||
LoadThirdPartyLicenses { text: String },
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub enum OpenFileDialogContext {
|
||||
Open,
|
||||
Import,
|
||||
}
|
||||
|
||||
pub enum SaveFileDialogContext {
|
||||
Document { document_id: DocumentId, content: Vec<u8> },
|
||||
File { content: Vec<u8> },
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
[package]
|
||||
name = "document-container"
|
||||
description = "Container abstraction for the on-disk side of the .gdd document format"
|
||||
edition.workspace = true
|
||||
version.workspace = true
|
||||
license.workspace = true
|
||||
authors.workspace = true
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
publish.workspace = true
|
||||
|
||||
[features]
|
||||
default = []
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
[package]
|
||||
name = "document-format"
|
||||
description = "Typed handle for the .gdd document format, sitting over document-graph-storage and document-container"
|
||||
edition.workspace = true
|
||||
version.workspace = true
|
||||
license.workspace = true
|
||||
authors.workspace = true
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
publish.workspace = true
|
||||
|
||||
[features]
|
||||
# Runtime bridge: the editor <-> storage conversion methods (stage/commit from a `NodeNetwork`,
|
||||
|
||||
@@ -76,29 +76,6 @@ impl<L: Layout> Gdd<L> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Stage ops the caller built from what the editor recorded, rather than deriving them by converting
|
||||
/// the whole document and diffing it against the working registry.
|
||||
///
|
||||
/// Otherwise identical to [`stage_runtime_snapshot`](Self::stage_runtime_snapshot): each op becomes a
|
||||
/// hot frame, and the proto-node declaration bytes go to the byte store.
|
||||
#[cfg(feature = "conversion")]
|
||||
pub fn stage_constructed_ops(
|
||||
&mut self,
|
||||
ops: Vec<document_graph_storage::RegistryDelta>,
|
||||
declaration_bytes: &document_graph_storage::from_runtime::DeclarationBytes,
|
||||
byte_store: &dyn ResourceStorage,
|
||||
) -> Result<(), Error> {
|
||||
let hot_ops = self.session.stage_computed_ops(ops)?;
|
||||
|
||||
for hot_op in &hot_ops {
|
||||
self.append_hot_frame(hot_op)?;
|
||||
}
|
||||
for bytes in declaration_bytes.values() {
|
||||
byte_store.store(bytes);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Retire every pending hot op into durable history as a single interaction (marking the batch's last
|
||||
/// delta as the interaction boundary), then re-snapshot the registry. One interaction is one undo unit,
|
||||
/// so the caller invokes this at each undo-step boundary and before any undo/redo. A no-op when there
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
[package]
|
||||
name = "document-graph-storage"
|
||||
description = "Provides a delta based graph representation used in the Graphite file format"
|
||||
edition.workspace = true
|
||||
version.workspace = true
|
||||
license.workspace = true
|
||||
authors.workspace = true
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
publish.workspace = true
|
||||
|
||||
[features]
|
||||
conversion = ["dep:graph-craft", "dep:core-types"]
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
pub mod node {
|
||||
pub const CALL_ARGUMENT: &str = "call_argument";
|
||||
pub const CONTEXT_FEATURES: &str = "context_features";
|
||||
pub const VISIBLE: &str = "visible";
|
||||
pub const SKIP_DEDUPLICATION: &str = "skip_deduplication";
|
||||
pub const REFLECTION_METADATA: &str = "reflection_metadata";
|
||||
@@ -31,6 +30,8 @@ pub mod node {
|
||||
|
||||
pub mod session {
|
||||
pub mod network {
|
||||
pub const PREVIEWING: &str = "ui::previewing";
|
||||
|
||||
// TODO: Remove these graph ui nav-specific attributes
|
||||
pub const NAV_PTZ: &str = "ui::nav::ptz";
|
||||
pub const NAV_TRANSFORM: &str = "ui::nav::transform";
|
||||
@@ -58,11 +59,6 @@ pub mod network {
|
||||
/// serialized blob so its shape can evolve (e.g. dropping the `Type`) without a model change. The
|
||||
/// node references use stable storage IDs, resolved back to runtime-local IDs on conversion.
|
||||
pub const SCOPE_INJECTIONS: &str = "scope_injections";
|
||||
|
||||
/// Whole-vec LWW of the display order of the network's pinned nodes, as stable storage IDs.
|
||||
/// Concurrent reorders do not merge, but the pinned set is already shared, and a shared set with
|
||||
/// per-peer ordering would diverge with no way to reconcile.
|
||||
pub const PINNED_ORDER: &str = "ui::pinned_order";
|
||||
}
|
||||
|
||||
pub mod delta {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::{Attributes, AttributesWrite, InputSlot, Network, NetworkId, Node, NodeId, NodeInput, PeerId, ResourceEntry, ResourceId, Rev, SourceKey, TimeStamp, UserId, Value, attr, compute_rev};
|
||||
use crate::{Attributes, AttributesWrite, Network, NetworkId, Node, NodeId, NodeInput, PeerId, ResourceEntry, ResourceId, Rev, SourceKey, TimeStamp, UserId, Value, attr, compute_rev};
|
||||
use graphene_resource::ResourceHash;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -92,7 +92,7 @@ impl Delta {
|
||||
|
||||
/// Op payload. Timestamps live on the wrapping `Delta` — one per delta, applied to all LWW-eligible
|
||||
/// writes within. See `notes/document-format-collaboration.md`.
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub enum RegistryDelta {
|
||||
AddNode {
|
||||
id: NodeId,
|
||||
@@ -109,16 +109,6 @@ pub enum RegistryDelta {
|
||||
index: u32,
|
||||
new_input: NodeInput,
|
||||
},
|
||||
/// A node's whole input list, for a change to the number or order of its slots that the
|
||||
/// index-addressed `ChangeNodeInput` cannot express. Assigns rather than merging: concurrent
|
||||
/// per-slot edits are lost, which is inherent to the indices themselves moving.
|
||||
///
|
||||
/// Touches only the inputs, leaving the node's attributes and implementation alone, so it composes
|
||||
/// with attribute ops on the same node instead of reverting them.
|
||||
SetNodeInputs {
|
||||
id: NodeId,
|
||||
inputs: Vec<InputSlot>,
|
||||
},
|
||||
ChangeNodeAttribute {
|
||||
id: NodeId,
|
||||
delta: AttributeDelta,
|
||||
@@ -200,7 +190,7 @@ pub enum RegistryDelta {
|
||||
}
|
||||
|
||||
/// `value: None` means remove. The timestamp comes from the wrapping `Delta`.
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct AttributeDelta {
|
||||
pub key: String,
|
||||
pub value: Option<serde_json::Value>,
|
||||
|
||||
@@ -194,10 +194,6 @@ impl Document {
|
||||
RegistryDelta::RemoveNode { id, .. } => {
|
||||
registry.node_instances.remove(&id);
|
||||
}
|
||||
RegistryDelta::SetNodeInputs { id, inputs } => {
|
||||
let node = registry.node_instances.get_mut(&id).ok_or(CrdtError::TargetNodeDoesNotExist(id))?;
|
||||
node.inputs = inputs;
|
||||
}
|
||||
RegistryDelta::ChangeNodeInput { id, index, new_input } => {
|
||||
let node = registry.node_instances.get_mut(&id).ok_or(CrdtError::TargetNodeDoesNotExist(id))?;
|
||||
let input = node.inputs.get_mut(index as usize).ok_or(CrdtError::InputIndexOutOfBounds(index as usize))?;
|
||||
@@ -309,14 +305,6 @@ impl Document {
|
||||
}
|
||||
self.ensure_node_exists(target, *id)?;
|
||||
}
|
||||
RegistryDelta::SetNodeInputs { id, inputs } => {
|
||||
for slot in inputs {
|
||||
if let NodeInput::Node { id: referenced, .. } = slot.input {
|
||||
self.ensure_node_exists(target, referenced)?;
|
||||
}
|
||||
}
|
||||
self.ensure_node_exists(target, *id)?;
|
||||
}
|
||||
RegistryDelta::ChangeNodeAttribute { id, .. } | RegistryDelta::ChangeNodeInputAttribute { id, .. } => self.ensure_node_exists(target, *id)?,
|
||||
RegistryDelta::SetNetworkExport {
|
||||
id: network, export: export_target, ..
|
||||
@@ -354,10 +342,6 @@ impl Document {
|
||||
Ok(match delta {
|
||||
RegistryDelta::AddNode { id, node } => RegistryDelta::RemoveNode { id: *id, snapshot: node.clone() },
|
||||
RegistryDelta::RemoveNode { id, snapshot } => RegistryDelta::AddNode { id: *id, node: snapshot.clone() },
|
||||
&RegistryDelta::SetNodeInputs { id, .. } => {
|
||||
let node = registry.node_instances.get(&id).ok_or(CrdtError::TargetNodeDoesNotExist(id))?;
|
||||
RegistryDelta::SetNodeInputs { id, inputs: node.inputs.clone() }
|
||||
}
|
||||
&RegistryDelta::ChangeNodeInput { id, index: input_idx, .. } => {
|
||||
let node = registry.node_instances.get(&id).ok_or(CrdtError::TargetNodeDoesNotExist(id))?;
|
||||
let slot = node.inputs().get(input_idx as usize).ok_or(CrdtError::InputIndexOutOfBounds(input_idx as usize))?;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use core_types::Context;
|
||||
use core_types::context::ContextDependencies;
|
||||
use core_types::uuid::NodeId as RuntimeNodeId;
|
||||
use graph_craft::concrete;
|
||||
use graph_craft::document::value::TaggedValue;
|
||||
@@ -60,34 +59,6 @@ impl NodePath {
|
||||
}
|
||||
}
|
||||
|
||||
/// Resolves a node's storage identity: the identity the metadata source holds for it where there is
|
||||
/// one, and a hash of its location otherwise. Every place a node is named goes through here, so a
|
||||
/// node's own registry key and every reference to it agree.
|
||||
///
|
||||
/// A held identity travels with the node, so moving it between networks keeps it. A hashed one is
|
||||
/// derived from the node's place in the tree, so it changes when the node moves; it stands in for a
|
||||
/// node no source names, such as one in a network that has never been stored.
|
||||
pub(crate) struct NodeIds<'a, M: NodeMetadataSource + ?Sized> {
|
||||
pub(crate) metadata: Option<&'a M>,
|
||||
pub(crate) metadata_path: &'a [RuntimeNodeId],
|
||||
pub(crate) peer: PeerId,
|
||||
}
|
||||
|
||||
impl<M: NodeMetadataSource + ?Sized> Clone for NodeIds<'_, M> {
|
||||
fn clone(&self) -> Self {
|
||||
*self
|
||||
}
|
||||
}
|
||||
|
||||
impl<M: NodeMetadataSource + ?Sized> Copy for NodeIds<'_, M> {}
|
||||
|
||||
impl<M: NodeMetadataSource + ?Sized> NodeIds<'_, M> {
|
||||
fn resolve(&self, path: &NodePath, local_id: RuntimeNodeId) -> NodeId {
|
||||
self.metadata
|
||||
.and_then(|metadata| metadata.storage_node_id(self.metadata_path, local_id))
|
||||
.unwrap_or_else(|| path.to_global_id(self.peer))
|
||||
}
|
||||
}
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum ConversionError {
|
||||
#[error("Failed to serialize value: {0}")]
|
||||
@@ -210,40 +181,33 @@ fn convert_resources(resources: &graphene_resource::ResourceRegistry, referenced
|
||||
if !referenced.contains(&id) {
|
||||
continue;
|
||||
}
|
||||
if let Some(entry) = convert_resource_entry(resources, id, peer)? {
|
||||
registry.resources.insert(id, entry);
|
||||
let Some(info) = resources.info(&id) else { continue };
|
||||
|
||||
let mut entry = crate::ResourceEntry {
|
||||
hash: info.hash.copied(),
|
||||
hash_timestamp: TimeStamp::ORIGIN,
|
||||
..Default::default()
|
||||
};
|
||||
for (position, source) in info.sources.iter().enumerate() {
|
||||
let key = crate::SourceKey {
|
||||
priority: crate::Priority::new(position as f64).expect("enumerate index is finite"),
|
||||
peer,
|
||||
};
|
||||
let body = serde_json::to_value(source).map_err(|error| ConversionError::SerializationError(error.to_string()))?;
|
||||
entry.set_source(
|
||||
key,
|
||||
crate::SourceValue {
|
||||
source: body,
|
||||
timestamp: TimeStamp::ORIGIN,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
registry.resources.insert(id, entry);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Snapshot one runtime resource into a storage entry, or `None` if the runtime has no such resource.
|
||||
pub fn convert_resource_entry(resources: &graphene_resource::ResourceRegistry, id: ResourceId, peer: PeerId) -> Result<Option<crate::ResourceEntry>, ConversionError> {
|
||||
let Some(info) = resources.info(&id) else { return Ok(None) };
|
||||
|
||||
let mut entry = crate::ResourceEntry {
|
||||
hash: info.hash.copied(),
|
||||
hash_timestamp: TimeStamp::ORIGIN,
|
||||
..Default::default()
|
||||
};
|
||||
for (position, source) in info.sources.iter().enumerate() {
|
||||
let key = crate::SourceKey {
|
||||
priority: crate::Priority::new(position as f64).expect("enumerate index is finite"),
|
||||
peer,
|
||||
};
|
||||
let body = serde_json::to_value(source).map_err(|error| ConversionError::SerializationError(error.to_string()))?;
|
||||
entry.set_source(
|
||||
key,
|
||||
crate::SourceValue {
|
||||
source: body,
|
||||
timestamp: TimeStamp::ORIGIN,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Ok(Some(entry))
|
||||
}
|
||||
|
||||
/// Collect the `ResourceId`s referenced by `TaggedValue::Resource` inputs anywhere in the network
|
||||
/// (recursively through nested networks). These are the resources the document actually uses; the
|
||||
/// runtime cache may hold more (history-retained orphans) that shouldn't be snapshotted into storage.
|
||||
@@ -296,20 +260,6 @@ struct ConversionContext<'m, M: NodeMetadataSource + ?Sized> {
|
||||
peer: PeerId,
|
||||
}
|
||||
|
||||
impl<'m, M: NodeMetadataSource + ?Sized> ConversionContext<'m, M> {
|
||||
/// The identity resolver for nodes addressed inside the network at `metadata_path`.
|
||||
fn ids<'a>(&self, metadata_path: &'a [RuntimeNodeId]) -> NodeIds<'a, M>
|
||||
where
|
||||
'm: 'a,
|
||||
{
|
||||
NodeIds {
|
||||
metadata: Some(self.metadata),
|
||||
metadata_path,
|
||||
peer: self.peer,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn convert_network<M: NodeMetadataSource + ?Sized>(
|
||||
node_network: &NodeNetwork,
|
||||
network_id: NetworkId,
|
||||
@@ -320,7 +270,7 @@ fn convert_network<M: NodeMetadataSource + ?Sized>(
|
||||
) -> Result<(), ConversionError> {
|
||||
for (runtime_node_id, doc_node) in &node_network.nodes {
|
||||
let node_path = child_path(parent_path, network_id, *runtime_node_id);
|
||||
let global_id = ctx.ids(metadata_path).resolve(&node_path, *runtime_node_id);
|
||||
let global_id = node_path.to_global_id(ctx.peer);
|
||||
|
||||
let location = NodeLocation {
|
||||
network_id,
|
||||
@@ -328,7 +278,7 @@ fn convert_network<M: NodeMetadataSource + ?Sized>(
|
||||
metadata_path,
|
||||
runtime_node_id: *runtime_node_id,
|
||||
};
|
||||
let mut node = convert_node(doc_node, location, registry, ctx, true)?;
|
||||
let mut node = convert_node(doc_node, location, registry, ctx)?;
|
||||
node.attributes.set(node::ORIGINAL_NODE_ID, serde_json::json!(runtime_node_id.0), TimeStamp::ORIGIN);
|
||||
registry.node_instances.insert(global_id, node);
|
||||
}
|
||||
@@ -338,15 +288,15 @@ fn convert_network<M: NodeMetadataSource + ?Sized>(
|
||||
.iter()
|
||||
.map(|export| {
|
||||
Ok(ExportSlot {
|
||||
target: Some(convert_input(export, parent_path, network_id, ctx.ids(metadata_path))?),
|
||||
target: Some(convert_input(export, parent_path, network_id, ctx.peer)?),
|
||||
timestamp: TimeStamp::ORIGIN,
|
||||
})
|
||||
})
|
||||
.collect::<Result<Vec<_>, ConversionError>>()?;
|
||||
|
||||
let mut attributes = crate::Attributes::new();
|
||||
write_ui_network_attributes(&mut attributes, ctx.metadata, metadata_path, parent_path, network_id, ctx.ids(metadata_path), TimeStamp::ORIGIN)?;
|
||||
write_scope_injections(&mut attributes, node_network, parent_path, network_id, ctx.ids(metadata_path), TimeStamp::ORIGIN)?;
|
||||
write_ui_network_attributes(&mut attributes, ctx.metadata, metadata_path, TimeStamp::ORIGIN)?;
|
||||
write_scope_injections(&mut attributes, node_network, parent_path, network_id, ctx.peer, TimeStamp::ORIGIN)?;
|
||||
|
||||
registry.networks.insert(network_id, Network { exports, attributes });
|
||||
ctx.network_ids.insert(metadata_path.to_vec(), network_id);
|
||||
@@ -357,12 +307,12 @@ fn convert_network<M: NodeMetadataSource + ?Sized>(
|
||||
/// Serialize a network's `scope_injections` onto its attributes as one whole-map LWW blob, remapping
|
||||
/// each runtime-local node reference to its stable storage global ID so the reference survives a
|
||||
/// round trip even if runtime IDs are later reshuffled.
|
||||
fn write_scope_injections<M: NodeMetadataSource + ?Sized>(
|
||||
fn write_scope_injections(
|
||||
attributes: &mut crate::Attributes,
|
||||
node_network: &NodeNetwork,
|
||||
parent_path: Option<&NodePath>,
|
||||
network_id: NetworkId,
|
||||
ids: NodeIds<'_, M>,
|
||||
peer: PeerId,
|
||||
timestamp: TimeStamp,
|
||||
) -> Result<(), ConversionError> {
|
||||
if node_network.scope_injections.is_empty() {
|
||||
@@ -373,7 +323,7 @@ fn write_scope_injections<M: NodeMetadataSource + ?Sized>(
|
||||
.scope_injections
|
||||
.iter()
|
||||
.map(|(key, (runtime_id, ty))| {
|
||||
let storage_id = ids.resolve(&child_path(parent_path, network_id, *runtime_id), *runtime_id);
|
||||
let storage_id = child_path(parent_path, network_id, *runtime_id).to_global_id(peer);
|
||||
(key.clone(), (storage_id, ty.clone()))
|
||||
})
|
||||
.collect();
|
||||
@@ -400,13 +350,7 @@ struct NodeLocation<'a> {
|
||||
runtime_node_id: RuntimeNodeId,
|
||||
}
|
||||
|
||||
fn convert_node<M: NodeMetadataSource + ?Sized>(
|
||||
doc_node: &DocumentNode,
|
||||
location: NodeLocation<'_>,
|
||||
registry: &mut Registry,
|
||||
ctx: &mut ConversionContext<'_, M>,
|
||||
recurse: bool,
|
||||
) -> Result<Node, ConversionError> {
|
||||
fn convert_node<M: NodeMetadataSource + ?Sized>(doc_node: &DocumentNode, location: NodeLocation<'_>, registry: &mut Registry, ctx: &mut ConversionContext<'_, M>) -> Result<Node, ConversionError> {
|
||||
let NodeLocation {
|
||||
network_id,
|
||||
parent_path,
|
||||
@@ -423,7 +367,7 @@ fn convert_node<M: NodeMetadataSource + ?Sized>(
|
||||
write_ui_input_attributes(&mut input_attrs, ctx.metadata, metadata_path, runtime_node_id, input_index, timestamp)?;
|
||||
|
||||
inputs.push(InputSlot {
|
||||
input: convert_input(input, parent_path, network_id, ctx.ids(metadata_path))?,
|
||||
input: convert_input(input, parent_path, network_id, ctx.peer)?,
|
||||
timestamp,
|
||||
attributes: input_attrs,
|
||||
});
|
||||
@@ -438,16 +382,13 @@ fn convert_node<M: NodeMetadataSource + ?Sized>(
|
||||
} else {
|
||||
metadata_path
|
||||
};
|
||||
let implementation = convert_implementation(&doc_node.implementation, &node_path, child_metadata_path, registry, ctx, recurse)?;
|
||||
let implementation = convert_implementation(&doc_node.implementation, &node_path, child_metadata_path, registry, ctx)?;
|
||||
|
||||
// Defaults match `DocumentNode::default()`; `to_runtime` rehydrates absent keys from the same defaults.
|
||||
let mut attributes = crate::Attributes::new();
|
||||
attributes
|
||||
.set_if_not_default(node::CALL_ARGUMENT, &doc_node.call_argument, &concrete!(Context), timestamp)
|
||||
.map_err(map_serialization_error(node::CALL_ARGUMENT))?;
|
||||
attributes
|
||||
.set_if_not_default(node::CONTEXT_FEATURES, &doc_node.context_features, &ContextDependencies::default(), timestamp)
|
||||
.map_err(map_serialization_error(node::CONTEXT_FEATURES))?;
|
||||
attributes
|
||||
.set_if_not_default(node::VISIBLE, &doc_node.visible, &true, timestamp)
|
||||
.map_err(map_serialization_error(node::VISIBLE))?;
|
||||
@@ -465,50 +406,6 @@ fn convert_node<M: NodeMetadataSource + ?Sized>(
|
||||
})
|
||||
}
|
||||
|
||||
/// The `call_argument` attribute write for a node, cleared when the value is the default that
|
||||
/// `to_runtime` rehydrates an absent key from. For staging paths that encode this field alone.
|
||||
pub fn encode_call_argument(call_argument: &core_types::Type) -> Result<crate::AttributeDelta, ConversionError> {
|
||||
encode_if_not_default(node::CALL_ARGUMENT, call_argument, &concrete!(Context))
|
||||
}
|
||||
|
||||
/// The `context_features` attribute write, cleared at its default like [`encode_call_argument`].
|
||||
pub fn encode_context_features(context_features: &ContextDependencies) -> Result<crate::AttributeDelta, ConversionError> {
|
||||
encode_if_not_default(node::CONTEXT_FEATURES, context_features, &ContextDependencies::default())
|
||||
}
|
||||
|
||||
fn encode_if_not_default<T: Serialize + PartialEq>(key: &str, value: &T, default: &T) -> Result<crate::AttributeDelta, ConversionError> {
|
||||
let value = if value == default {
|
||||
None
|
||||
} else {
|
||||
Some(serde_json::to_value(value).map_err(map_serialization_error(key))?)
|
||||
};
|
||||
|
||||
Ok(crate::AttributeDelta { key: key.to_string(), value })
|
||||
}
|
||||
|
||||
/// Public form of the node ui-attribute encoding, for staging paths that encode single nodes.
|
||||
pub fn encode_node_ui_attributes<M: NodeMetadataSource + ?Sized>(
|
||||
attributes: &mut crate::Attributes,
|
||||
metadata: &M,
|
||||
metadata_path: &[RuntimeNodeId],
|
||||
runtime_node_id: RuntimeNodeId,
|
||||
timestamp: TimeStamp,
|
||||
) -> Result<(), ConversionError> {
|
||||
write_ui_attributes(attributes, metadata, metadata_path, runtime_node_id, timestamp)
|
||||
}
|
||||
|
||||
/// Public form of the per-input ui-attribute encoding, matching `encode_node_ui_attributes`.
|
||||
pub fn encode_input_ui_attributes<M: NodeMetadataSource + ?Sized>(
|
||||
attributes: &mut crate::Attributes,
|
||||
metadata: &M,
|
||||
metadata_path: &[RuntimeNodeId],
|
||||
runtime_node_id: RuntimeNodeId,
|
||||
input_index: usize,
|
||||
timestamp: TimeStamp,
|
||||
) -> Result<(), ConversionError> {
|
||||
write_ui_input_attributes(attributes, metadata, metadata_path, runtime_node_id, input_index, timestamp)
|
||||
}
|
||||
|
||||
fn write_ui_attributes<M: NodeMetadataSource + ?Sized>(
|
||||
attributes: &mut crate::Attributes,
|
||||
metadata: &M,
|
||||
@@ -550,31 +447,11 @@ fn write_ui_attributes<M: NodeMetadataSource + ?Sized>(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Node references here are remapped to stable storage IDs for the same reason `write_scope_injections`
|
||||
/// does it: a runtime ID is not stable across a round trip.
|
||||
fn write_ui_network_attributes<M: NodeMetadataSource + ?Sized>(
|
||||
attributes: &mut crate::Attributes,
|
||||
metadata: &M,
|
||||
network_path: &[RuntimeNodeId],
|
||||
parent_path: Option<&NodePath>,
|
||||
network_id: NetworkId,
|
||||
ids: NodeIds<'_, M>,
|
||||
timestamp: TimeStamp,
|
||||
) -> Result<(), ConversionError> {
|
||||
fn write_ui_network_attributes<M: NodeMetadataSource + ?Sized>(attributes: &mut crate::Attributes, metadata: &M, network_path: &[RuntimeNodeId], timestamp: TimeStamp) -> Result<(), ConversionError> {
|
||||
if let Some(reference) = metadata.reference(network_path) {
|
||||
attributes.set(node::ui::REFERENCE, serde_json::Value::String(reference.to_string()), timestamp);
|
||||
}
|
||||
|
||||
let to_storage_id = |runtime_id: RuntimeNodeId| ids.resolve(&child_path(parent_path, network_id, runtime_id), runtime_id);
|
||||
|
||||
let pinned_order = metadata.pinned_order(network_path);
|
||||
if !pinned_order.is_empty() {
|
||||
let stored: Vec<NodeId> = pinned_order.into_iter().map(to_storage_id).collect();
|
||||
attributes
|
||||
.set_serialized(network::PINNED_ORDER, &stored, timestamp)
|
||||
.map_err(map_serialization_error(network::PINNED_ORDER))?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -605,10 +482,10 @@ fn write_ui_input_attributes<M: NodeMetadataSource + ?Sized>(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn convert_input<M: NodeMetadataSource + ?Sized>(input: &GraphCraftNodeInput, parent_path: Option<&NodePath>, network_id: NetworkId, ids: NodeIds<'_, M>) -> Result<NodeInput, ConversionError> {
|
||||
fn convert_input(input: &GraphCraftNodeInput, parent_path: Option<&NodePath>, network_id: NetworkId, peer: PeerId) -> Result<NodeInput, ConversionError> {
|
||||
Ok(match input {
|
||||
GraphCraftNodeInput::Node { node_id, output_index } => NodeInput::Node {
|
||||
id: ids.resolve(&child_path(parent_path, network_id, *node_id), *node_id),
|
||||
id: child_path(parent_path, network_id, *node_id).to_global_id(peer),
|
||||
index: (*output_index).try_into().map_err(|_| ConversionError::IndexOverflow(*output_index))?,
|
||||
},
|
||||
GraphCraftNodeInput::Value { tagged_value, exposed } => {
|
||||
@@ -625,9 +502,7 @@ fn convert_input<M: NodeMetadataSource + ?Sized>(input: &GraphCraftNodeInput, pa
|
||||
})
|
||||
}
|
||||
|
||||
/// The non-ui attributes a slot carries, derived from the input itself: the declared type of an
|
||||
/// import, and a reflection node.s metadata. Public for staging paths that rebuild a node.s slots.
|
||||
pub fn convert_input_attributes(input: &GraphCraftNodeInput) -> Result<crate::Attributes, ConversionError> {
|
||||
fn convert_input_attributes(input: &GraphCraftNodeInput) -> Result<crate::Attributes, ConversionError> {
|
||||
let mut attributes = crate::Attributes::new();
|
||||
let timestamp = TimeStamp::ORIGIN;
|
||||
|
||||
@@ -654,7 +529,6 @@ fn convert_implementation<M: NodeMetadataSource + ?Sized>(
|
||||
child_metadata_path: &[RuntimeNodeId],
|
||||
registry: &mut Registry,
|
||||
ctx: &mut ConversionContext<'_, M>,
|
||||
recurse: bool,
|
||||
) -> Result<Implementation, ConversionError> {
|
||||
Ok(match implementation {
|
||||
DocumentNodeImplementation::ProtoNode(identifier) => {
|
||||
@@ -686,181 +560,10 @@ fn convert_implementation<M: NodeMetadataSource + ?Sized>(
|
||||
// `to_runtime` -> `from_runtime` round trip reproduces the same `NetworkId` (and thus the
|
||||
// same node-path hashes underneath it).
|
||||
let nested_network_id = current_node_path.owned_network_id(ctx.peer);
|
||||
if recurse {
|
||||
convert_network(nested_network, nested_network_id, Some(current_node_path), child_metadata_path, registry, ctx)?;
|
||||
}
|
||||
convert_network(nested_network, nested_network_id, Some(current_node_path), child_metadata_path, registry, ctx)?;
|
||||
Implementation::Network(nested_network_id)
|
||||
}
|
||||
// TODO: Support Extract in the Registry format.
|
||||
DocumentNodeImplementation::Extract => return Err(ConversionError::UnsupportedImplementation),
|
||||
})
|
||||
}
|
||||
|
||||
/// Derives the storage IDs for entities addressed by runtime network paths, resolving each through
|
||||
/// the same [`NodeIds`] a whole-document conversion uses so scoped and whole-document conversions agree.
|
||||
pub struct PathResolver<'m> {
|
||||
metadata: Option<&'m dyn NodeMetadataSource>,
|
||||
peer: PeerId,
|
||||
}
|
||||
|
||||
impl<'m> PathResolver<'m> {
|
||||
/// Without a metadata source every node falls back to a hash of its location, which only matches a
|
||||
/// whole-document conversion while no node has a stored identity.
|
||||
pub fn new(metadata: Option<&'m dyn NodeMetadataSource>, peer: PeerId) -> Self {
|
||||
Self { metadata, peer }
|
||||
}
|
||||
|
||||
/// The storage `NetworkId` of the network at `local_path` (`ROOT_NETWORK` for the empty path).
|
||||
pub fn network_id(&self, local_path: &[RuntimeNodeId]) -> NetworkId {
|
||||
match self.owner_path(local_path) {
|
||||
None => ROOT_NETWORK,
|
||||
Some(owner) => owner.owned_network_id(self.peer),
|
||||
}
|
||||
}
|
||||
|
||||
/// The storage `NodeId` of the node with `local_id` inside the network at `local_path`.
|
||||
pub fn node_id(&self, local_path: &[RuntimeNodeId], local_id: RuntimeNodeId) -> NodeId {
|
||||
let owner = self.owner_path(local_path);
|
||||
self.ids(local_path).resolve(&child_path(owner.as_ref(), self.network_id(local_path), local_id), local_id)
|
||||
}
|
||||
|
||||
/// Converts one runtime input inside the network at `local_path` to its storage form, resolving
|
||||
/// node references to their storage IDs.
|
||||
pub fn convert_input_at(&self, input: &GraphCraftNodeInput, local_path: &[RuntimeNodeId]) -> Result<NodeInput, ConversionError> {
|
||||
let owner = self.owner_path(local_path);
|
||||
convert_input(input, owner.as_ref(), self.network_id(local_path), self.ids(local_path))
|
||||
}
|
||||
|
||||
/// The identity resolver for nodes addressed inside the network at `local_path`.
|
||||
fn ids<'a>(&self, local_path: &'a [RuntimeNodeId]) -> NodeIds<'a, dyn NodeMetadataSource + 'm>
|
||||
where
|
||||
'm: 'a,
|
||||
{
|
||||
NodeIds {
|
||||
metadata: self.metadata,
|
||||
metadata_path: local_path,
|
||||
peer: self.peer,
|
||||
}
|
||||
}
|
||||
|
||||
/// The `NodePath` of the node owning the network at `local_path`, or `None` for the root network.
|
||||
fn owner_path(&self, local_path: &[RuntimeNodeId]) -> Option<NodePath> {
|
||||
let mut owner: Option<NodePath> = None;
|
||||
for &local_id in local_path {
|
||||
let network_id = match &owner {
|
||||
None => ROOT_NETWORK,
|
||||
Some(owner) => owner.owned_network_id(self.peer),
|
||||
};
|
||||
owner = Some(child_path(owner.as_ref(), network_id, local_id));
|
||||
}
|
||||
owner
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts a chosen subset of runtime entities into a scratch [`Registry`] through the same
|
||||
/// encoders as a whole-document conversion, so staging can derive deltas for just those entities.
|
||||
pub struct ScopedConversion<'m> {
|
||||
ctx: ConversionContext<'m, dyn NodeMetadataSource + 'm>,
|
||||
resolver: PathResolver<'m>,
|
||||
}
|
||||
|
||||
impl<'m> ScopedConversion<'m> {
|
||||
pub fn new(metadata: &'m dyn NodeMetadataSource, peer: PeerId) -> Self {
|
||||
Self {
|
||||
ctx: ConversionContext {
|
||||
declaration_ids: HashMap::new(),
|
||||
declaration_bytes: HashMap::new(),
|
||||
network_ids: HashMap::new(),
|
||||
metadata,
|
||||
peer,
|
||||
},
|
||||
resolver: PathResolver::new(Some(metadata), peer),
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts the node with `local_id` in the network at `local_path` into `registry` under its
|
||||
/// stable IDs. `recurse` also converts the contents of any nested network the node implements;
|
||||
/// without it only the node itself is converted, with its nested network referenced by ID.
|
||||
pub fn convert_node_at(&mut self, registry: &mut Registry, local_path: &[RuntimeNodeId], local_id: RuntimeNodeId, doc_node: &DocumentNode, recurse: bool) -> Result<(), ConversionError> {
|
||||
let owner_path = self.resolver.owner_path(local_path);
|
||||
let location = NodeLocation {
|
||||
network_id: self.resolver.network_id(local_path),
|
||||
parent_path: owner_path.as_ref(),
|
||||
metadata_path: local_path,
|
||||
runtime_node_id: local_id,
|
||||
};
|
||||
|
||||
let mut node = convert_node(doc_node, location, registry, &mut self.ctx, recurse)?;
|
||||
node.attributes.set(node::ORIGINAL_NODE_ID, serde_json::json!(local_id.0), TimeStamp::ORIGIN);
|
||||
registry.node_instances.insert(self.resolver.node_id(local_path, local_id), node);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Converts the entry of the network at `local_path` (its export slots and network-level
|
||||
/// attributes, not its nodes) into `registry`.
|
||||
pub fn convert_network_entry_at(&mut self, registry: &mut Registry, local_path: &[RuntimeNodeId], node_network: &NodeNetwork) -> Result<(), ConversionError> {
|
||||
let owner_path = self.resolver.owner_path(local_path);
|
||||
let network_id = self.resolver.network_id(local_path);
|
||||
|
||||
let exports = node_network
|
||||
.exports
|
||||
.iter()
|
||||
.map(|export| {
|
||||
Ok(ExportSlot {
|
||||
target: Some(convert_input(export, owner_path.as_ref(), network_id, self.ctx.ids(local_path))?),
|
||||
timestamp: TimeStamp::ORIGIN,
|
||||
})
|
||||
})
|
||||
.collect::<Result<Vec<_>, ConversionError>>()?;
|
||||
|
||||
let mut attributes = crate::Attributes::new();
|
||||
write_ui_network_attributes(
|
||||
&mut attributes,
|
||||
self.ctx.metadata,
|
||||
local_path,
|
||||
owner_path.as_ref(),
|
||||
network_id,
|
||||
self.ctx.ids(local_path),
|
||||
TimeStamp::ORIGIN,
|
||||
)?;
|
||||
write_scope_injections(&mut attributes, node_network, owner_path.as_ref(), network_id, self.ctx.ids(local_path), TimeStamp::ORIGIN)?;
|
||||
|
||||
registry.networks.insert(network_id, Network { exports, attributes });
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// The extracted proto-node declaration bytes, for the caller to persist into its byte store.
|
||||
pub fn finish(self) -> DeclarationBytes {
|
||||
self.ctx.declaration_bytes
|
||||
}
|
||||
}
|
||||
|
||||
/// The `TaggedValue::Resource` IDs referenced by a stored node's value inputs.
|
||||
///
|
||||
/// Peeks at the externally-tagged serde shape (`{"Resource": <id>}`) rather than deserializing the
|
||||
/// whole `TaggedValue`, which can be arbitrarily large. `resource_ref_shape_matches_serde` asserts
|
||||
/// this stays in lockstep with the real serialization.
|
||||
pub fn node_value_resource_refs(node: &Node) -> impl Iterator<Item = ResourceId> + '_ {
|
||||
node.inputs.iter().filter_map(|slot| value_resource_ref(&slot.input))
|
||||
}
|
||||
|
||||
/// The `TaggedValue::Resource` ID referenced by a stored value input, if any.
|
||||
pub fn value_resource_ref(input: &NodeInput) -> Option<ResourceId> {
|
||||
match input {
|
||||
NodeInput::Value { value, .. } => value.get("Resource").and_then(|id| serde_json::from_value(id.clone()).ok()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod resource_ref_shape {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn resource_ref_shape_matches_serde() {
|
||||
let id = ResourceId::from_hash(&ResourceHash::from(b"shape test".as_slice()));
|
||||
let value = serde_json::to_value(TaggedValue::Resource(id)).expect("TaggedValue::Resource serializes");
|
||||
let parsed: Option<ResourceId> = value.get("Resource").and_then(|inner| serde_json::from_value(inner.clone()).ok());
|
||||
assert_eq!(parsed, Some(id), "The shape peek in node_value_resource_refs must match TaggedValue's serde form");
|
||||
}
|
||||
}
|
||||
@@ -29,10 +29,7 @@ pub use resources::*;
|
||||
pub use session::*;
|
||||
|
||||
#[cfg(any(feature = "conversion", test))]
|
||||
pub use from_runtime::{
|
||||
PathResolver, RuntimeConversion, ScopedConversion, convert_input_attributes, convert_resource_entry, decode_declaration, encode_declaration, encode_input_ui_attributes, encode_node_ui_attributes,
|
||||
node_value_resource_refs, value_resource_ref,
|
||||
};
|
||||
pub use from_runtime::{RuntimeConversion, decode_declaration, encode_declaration};
|
||||
#[cfg(any(feature = "conversion", test))]
|
||||
pub use metadata_source::{InputMetadataEntry, NetworkMetadataEntry, NoMetadata, NodeMetadataEntry, NodeMetadataSource, Position};
|
||||
#[cfg(any(feature = "conversion", test))]
|
||||
|
||||
@@ -8,15 +8,11 @@ use std::collections::HashMap;
|
||||
|
||||
use core_types::uuid::NodeId as RuntimeNodeId;
|
||||
|
||||
/// One node's editor-side metadata, produced by `Registry::to_runtime_with_metadata`. One entry per
|
||||
/// node, since every node carries an identity to restore even when it carries no `ui::*` attribute.
|
||||
/// One node's editor-side metadata, produced by `Registry::to_runtime_with_metadata`.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct NodeMetadataEntry {
|
||||
pub network_path: Vec<RuntimeNodeId>,
|
||||
pub local_id: RuntimeNodeId,
|
||||
/// The node's storage identity. Restoring it pins the node to this identity, so a later conversion
|
||||
/// keeps it instead of re-deriving one from the node's location.
|
||||
pub storage_id: crate::NodeId,
|
||||
pub position: Option<Position>,
|
||||
pub is_layer: bool,
|
||||
pub display_name: Option<String>,
|
||||
@@ -28,7 +24,19 @@ pub struct NodeMetadataEntry {
|
||||
pub output_names: Vec<String>,
|
||||
}
|
||||
|
||||
/// Per-network metadata. Separate from `NodeMetadataEntry` since these are
|
||||
impl NodeMetadataEntry {
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.position.is_none()
|
||||
&& !self.is_layer
|
||||
&& self.display_name.is_none()
|
||||
&& !self.locked
|
||||
&& !self.pinned
|
||||
&& self.output_names.is_empty()
|
||||
&& self.input_metadata.iter().all(InputMetadataEntry::is_empty)
|
||||
}
|
||||
}
|
||||
|
||||
/// Per-network metadata (navigation, previewing). Separate from `NodeMetadataEntry` since these are
|
||||
/// properties of a network, not of any node.
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct NetworkMetadataEntry {
|
||||
@@ -36,13 +44,16 @@ pub struct NetworkMetadataEntry {
|
||||
/// Empty = root network.
|
||||
pub network_path: Vec<RuntimeNodeId>,
|
||||
/// Stable storage id of this network. Lets the editor associate per-network, per-peer view state
|
||||
/// (the node-graph nav, in `session.json`) with a network across reparenting.
|
||||
/// (node-graph nav + previewing, in `session.json`) with a network across reparenting.
|
||||
pub network_id: crate::NetworkId,
|
||||
/// Matches the runtime's `NodeNetworkPersistentMetadata::reference` — definition lineage tag.
|
||||
pub reference: Option<String>,
|
||||
/// The display order of the network's pinned nodes. Shared for the same reason the pinned flag is:
|
||||
/// a shared set with per-peer ordering could never reconcile.
|
||||
pub pinned_order: Vec<RuntimeNodeId>,
|
||||
}
|
||||
|
||||
impl NetworkMetadataEntry {
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.reference.is_none()
|
||||
}
|
||||
}
|
||||
|
||||
/// Per-input editor metadata. Mirrors `InputPersistentMetadata` but wraps strings in `Option` so
|
||||
@@ -56,6 +67,12 @@ pub struct InputMetadataEntry {
|
||||
pub input_data: HashMap<String, serde_json::Value>,
|
||||
}
|
||||
|
||||
impl InputMetadataEntry {
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.input_name.is_none() && self.input_description.is_none() && self.widget_override.is_none() && self.input_data.is_empty()
|
||||
}
|
||||
}
|
||||
|
||||
/// Editor-side metadata source. Methods default to "no data" so implementors only override what
|
||||
/// they carry. Returns are JSON-shaped where the underlying types live editor-side (PTZ, etc.).
|
||||
pub trait NodeMetadataSource {
|
||||
@@ -93,18 +110,9 @@ pub trait NodeMetadataSource {
|
||||
HashMap::new()
|
||||
}
|
||||
|
||||
/// The storage identity this node is pinned to, if it has one. A node the source does not name
|
||||
/// falls back to a hash of its location.
|
||||
fn storage_node_id(&self, _network_path: &[RuntimeNodeId], _local_id: RuntimeNodeId) -> Option<crate::NodeId> {
|
||||
None
|
||||
}
|
||||
fn reference(&self, _network_path: &[RuntimeNodeId]) -> Option<&str> {
|
||||
None
|
||||
}
|
||||
/// The display order of the network's pinned nodes.
|
||||
fn pinned_order(&self, _network_path: &[RuntimeNodeId]) -> Vec<RuntimeNodeId> {
|
||||
Vec::new()
|
||||
}
|
||||
}
|
||||
|
||||
/// No-op metadata source. Use when there's nothing to attach (synthetic networks, CLI tools).
|
||||
|
||||
@@ -129,12 +129,6 @@ impl Session {
|
||||
Ok(revs)
|
||||
}
|
||||
|
||||
/// Stages ops computed outside the session (an incremental runtime projection) as hot ops, the
|
||||
/// same way `stage_from_runtime` stages a diff's ops.
|
||||
pub fn stage_computed_ops(&mut self, ops: Vec<RegistryDelta>) -> Result<Vec<HotOp>, CrdtError> {
|
||||
self.stage_ops(ops)
|
||||
}
|
||||
|
||||
/// Apply each op as a hot op with a freshly-ticked timestamp, returning the staged frames in
|
||||
/// order. Each tick is strictly later than the last, so the final frame carries the latest
|
||||
/// timestamp, which is what the caller passes to `retire`.
|
||||
|
||||
@@ -14,7 +14,9 @@ use crate::{NetworkId, NodeMetadataSource, PeerId, Position, Registry};
|
||||
/// Test networks with Import inputs will fail compilation (which is expected).
|
||||
fn verify_network_compiles(network: &NodeNetwork) -> Result<(), String> {
|
||||
let compiler = Compiler {};
|
||||
compiler.compile_single(network.clone()).map_err(|e| format!("Compilation failed: {:?}", e))?;
|
||||
compiler
|
||||
.compile_single(network.clone(), &graph_craft::proto::Registry::new())
|
||||
.map_err(|e| format!("Compilation failed: {:?}", e))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -246,11 +248,6 @@ fn test_nested_network_flattening() {
|
||||
#[test]
|
||||
fn test_metadata_preservation() {
|
||||
// Create a network with nodes that have non-default metadata
|
||||
let context_features = ContextDependencies {
|
||||
extract: core_types::context::ContextFeatures::FOOTPRINT | core_types::context::ContextFeatures::REAL_TIME,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let network = NodeNetwork {
|
||||
exports: vec![NodeInput::node(NodeId(1), 0)],
|
||||
nodes: [
|
||||
@@ -260,7 +257,6 @@ fn test_metadata_preservation() {
|
||||
inputs: vec![NodeInput::import(concrete!(f64), 0), NodeInput::import(Type::Generic(Cow::Borrowed("T")), 1)],
|
||||
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("test::NodeWithMetadata")),
|
||||
call_argument: concrete!(String),
|
||||
context_features,
|
||||
visible: false, // Non-default value
|
||||
skip_deduplication: true, // Non-default value
|
||||
..Default::default()
|
||||
@@ -294,8 +290,12 @@ fn test_metadata_preservation() {
|
||||
let conv_node_1 = converted.nodes.get(&NodeId(1)).unwrap();
|
||||
assert_eq!(orig_node_1.call_argument, conv_node_1.call_argument, "call_argument for node 1 should be preserved");
|
||||
|
||||
// Verify context_features is preserved
|
||||
assert_eq!(orig_node_0.context_features, conv_node_0.context_features, "context_features should be preserved");
|
||||
// Verify context_features is not stored
|
||||
assert_eq!(
|
||||
conv_node_0.context_features,
|
||||
ContextDependencies::default(),
|
||||
"context_features should resolve at compile, not round-trip"
|
||||
);
|
||||
|
||||
// Verify visible is preserved
|
||||
assert_eq!(orig_node_0.visible, conv_node_0.visible, "visible should be preserved");
|
||||
|
||||
@@ -168,7 +168,7 @@ fn convert_network(
|
||||
let network = context.registry.networks.get(&network_id).ok_or(ConversionError::NetworkNotFound(network_id))?;
|
||||
|
||||
if let Some(collector) = network_collector.as_mut() {
|
||||
collector.push(extract_network_metadata(context.registry, &network.attributes, metadata_path, network_id));
|
||||
collector.push(extract_network_metadata(&network.attributes, metadata_path, network_id));
|
||||
}
|
||||
|
||||
let mut nodes: FxHashMap<RuntimeNodeId, DocumentNode> = FxHashMap::default();
|
||||
@@ -176,8 +176,10 @@ fn convert_network(
|
||||
let local_id = node.attributes.get(node::ORIGINAL_NODE_ID).and_then(|v| v.value.as_u64()).unwrap_or(global_id.0);
|
||||
let runtime_id = RuntimeNodeId(local_id);
|
||||
|
||||
if let Some(collector) = node_collector.as_mut() {
|
||||
collector.push(extract_ui_metadata(node, global_id, metadata_path, runtime_id));
|
||||
if let Some(collector) = node_collector.as_mut()
|
||||
&& let Some(entry) = extract_ui_metadata(node, metadata_path, runtime_id)
|
||||
{
|
||||
collector.push(entry);
|
||||
}
|
||||
|
||||
let doc_node = convert_node(context, node, metadata_path, runtime_id, node_collector, network_collector)?;
|
||||
@@ -237,10 +239,10 @@ fn read_scope_injections(registry: &Registry, network_id: NetworkId, attributes:
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Emitted for every node, since `storage_id` is worth restoring even where no `ui::*` attribute is.
|
||||
/// `input_metadata` is always sized to match `node.inputs.len()` for a strict slot-by-slot rebuild;
|
||||
/// empty slots use `InputMetadataEntry::default()`.
|
||||
fn extract_ui_metadata(node: &crate::Node, storage_id: NodeId, network_path: &[RuntimeNodeId], local_id: RuntimeNodeId) -> NodeMetadataEntry {
|
||||
/// Returns `None` when the node has no `ui::*` attributes at all so callers don't end up with
|
||||
/// empty entries for unconverted-from-runtime nodes. `input_metadata` is always sized to match
|
||||
/// `node.inputs.len()` for a strict slot-by-slot rebuild; empty slots use `InputMetadataEntry::default()`.
|
||||
fn extract_ui_metadata(node: &crate::Node, network_path: &[RuntimeNodeId], local_id: RuntimeNodeId) -> Option<NodeMetadataEntry> {
|
||||
let position: Option<Position> = node.attributes.get_typed(node::ui::POSITION);
|
||||
let is_layer = node.attributes.get_or(node::ui::IS_LAYER, false);
|
||||
let display_name: Option<String> = node.attributes.get_typed(node::ui::DISPLAY_NAME);
|
||||
@@ -250,10 +252,9 @@ fn extract_ui_metadata(node: &crate::Node, storage_id: NodeId, network_path: &[R
|
||||
|
||||
let input_metadata: Vec<InputMetadataEntry> = node.inputs.iter().map(|slot| &slot.attributes).map(extract_input_metadata).collect();
|
||||
|
||||
NodeMetadataEntry {
|
||||
let entry = NodeMetadataEntry {
|
||||
network_path: network_path.to_vec(),
|
||||
local_id,
|
||||
storage_id,
|
||||
position,
|
||||
is_layer,
|
||||
display_name,
|
||||
@@ -261,31 +262,15 @@ fn extract_ui_metadata(node: &crate::Node, storage_id: NodeId, network_path: &[R
|
||||
pinned,
|
||||
input_metadata,
|
||||
output_names,
|
||||
}
|
||||
};
|
||||
(!entry.is_empty()).then_some(entry)
|
||||
}
|
||||
|
||||
/// Node references stored here are storage IDs, resolved back to runtime-local IDs the way
|
||||
/// `read_scope_injections` does. A reference to a node that is no longer in this network is dropped
|
||||
/// rather than failing the conversion: the preview target or a pinned node can have been deleted.
|
||||
fn extract_network_metadata(registry: &Registry, attributes: &crate::Attributes, network_path: &[RuntimeNodeId], network_id: NetworkId) -> NetworkMetadataEntry {
|
||||
let to_runtime_id = |storage_id: NodeId| {
|
||||
let node = registry.node_instances.get(&storage_id).filter(|node| node.network == network_id)?;
|
||||
let local_id = node.attributes.get(node::ORIGINAL_NODE_ID).and_then(|value| value.value.as_u64()).unwrap_or(storage_id.0);
|
||||
Some(RuntimeNodeId(local_id))
|
||||
};
|
||||
|
||||
let pinned_order = attributes
|
||||
.get_typed::<Vec<NodeId>>(network::PINNED_ORDER)
|
||||
.unwrap_or_default()
|
||||
.into_iter()
|
||||
.filter_map(to_runtime_id)
|
||||
.collect();
|
||||
|
||||
fn extract_network_metadata(attributes: &crate::Attributes, network_path: &[RuntimeNodeId], network_id: NetworkId) -> NetworkMetadataEntry {
|
||||
NetworkMetadataEntry {
|
||||
network_path: network_path.to_vec(),
|
||||
network_id,
|
||||
reference: attributes.get_typed(node::ui::REFERENCE),
|
||||
pinned_order,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -325,8 +310,8 @@ fn convert_node(
|
||||
implementation: convert_implementation(context, &node.implementation, metadata_path, runtime_node_id, node_collector, network_collector)?,
|
||||
visible: node.attributes.get_or(node::VISIBLE, true),
|
||||
skip_deduplication: node.attributes.get_or(node::SKIP_DEDUPLICATION, false),
|
||||
context_features: node.attributes.get_or_default(node::CONTEXT_FEATURES),
|
||||
// Regenerated during compilation; not stored.
|
||||
context_features: Default::default(),
|
||||
original_location: Default::default(),
|
||||
})
|
||||
}
|
||||
|
||||
+9
-6
@@ -1,11 +1,14 @@
|
||||
[package]
|
||||
name = "graphite-editor"
|
||||
version.workspace = true
|
||||
license.workspace = true
|
||||
authors.workspace = true
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
publish.workspace = true
|
||||
publish = false
|
||||
version = "0.0.0"
|
||||
rust-version = "1.88"
|
||||
authors = ["Graphite Authors <[email protected]>"]
|
||||
edition = "2024"
|
||||
readme = "../README.md"
|
||||
homepage = "https://graphite.art"
|
||||
repository = "https://github.com/GraphiteEditor/Graphite"
|
||||
license = "MIT OR Apache-2.0"
|
||||
|
||||
[features]
|
||||
default = ["gpu"]
|
||||
|
||||
@@ -266,8 +266,8 @@ impl Dispatcher {
|
||||
Message::MenuBar(message) => {
|
||||
let menu_bar_message_handler = &mut self.message_handlers.menu_bar_message_handler;
|
||||
|
||||
menu_bar_message_handler.focus_document = self.message_handlers.portfolio_message_handler.workspace.panel_layout.focus_document;
|
||||
let layout = &self.message_handlers.portfolio_message_handler.workspace.panel_layout;
|
||||
menu_bar_message_handler.focus_document = self.message_handlers.portfolio_message_handler.workspace_panel_layout.focus_document;
|
||||
let layout = &self.message_handlers.portfolio_message_handler.workspace_panel_layout;
|
||||
menu_bar_message_handler.data_panel_open = layout.is_panel_present(PanelType::Data);
|
||||
menu_bar_message_handler.layers_panel_open = layout.is_panel_present(PanelType::Layers);
|
||||
menu_bar_message_handler.properties_panel_open = layout.is_panel_present(PanelType::Properties);
|
||||
@@ -427,7 +427,6 @@ impl Dispatcher {
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::messages::portfolio::ingest::utility_types::IngestAction;
|
||||
pub use crate::test_utils::test_prelude::*;
|
||||
|
||||
#[tokio::test]
|
||||
@@ -479,11 +478,9 @@ mod test {
|
||||
"Demo artwork '{document_name}' has more than 1 line (remember to open and re-save it in Graphite)",
|
||||
);
|
||||
|
||||
let responses = editor.editor.handle_message(IngestMessage::Ingest {
|
||||
data: document_serialized_content.into_bytes(),
|
||||
action: IngestAction::Open,
|
||||
mime_type: String::new(),
|
||||
path: Some(file_name.into()),
|
||||
let responses = editor.editor.handle_message(PortfolioMessage::OpenFile {
|
||||
path: file_name.into(),
|
||||
content: document_serialized_content.bytes().collect(),
|
||||
});
|
||||
|
||||
// Check if the graph renders
|
||||
|
||||
@@ -8,7 +8,5 @@ pub enum EventMessage {
|
||||
CanvasTransformed,
|
||||
ToolAbort,
|
||||
SelectionChanged,
|
||||
/// The document graph's nodes or wires changed, so state derived from the selection's chains may be stale
|
||||
GraphChanged,
|
||||
WorkingColorChanged,
|
||||
}
|
||||
@@ -11,6 +11,7 @@ use crate::messages::tool::utility_types::ToolType;
|
||||
use graph_craft::application_io::resource::{DataSource, ResourceHash};
|
||||
use graph_craft::document::NodeId;
|
||||
use graphene_std::Color;
|
||||
use graphene_std::raster::Image;
|
||||
use graphene_std::vector::misc::{BezierHandles, HandleId, point_to_dvec2, segment_to_handles};
|
||||
use graphene_std::vector::{PointId, SegmentId, VectorModificationType};
|
||||
use graphite_proc_macros::{ExtractField, message_handler_data};
|
||||
@@ -50,6 +51,22 @@ impl MessageHandler<ClipboardMessage, ClipboardMessageContext<'_>> for Clipboard
|
||||
responses.add(FrontendMessage::TriggerSelectionWrite { content: text });
|
||||
}
|
||||
}
|
||||
ClipboardContentRaw::Svg(svg) => {
|
||||
responses.add(PortfolioMessage::InsertSvg {
|
||||
svg,
|
||||
name: None,
|
||||
mouse: None,
|
||||
parent_and_insert_index: None,
|
||||
});
|
||||
}
|
||||
ClipboardContentRaw::Image { data, width, height } => {
|
||||
responses.add(PortfolioMessage::InsertImage {
|
||||
image: Image::from_image_data(&data, width, height),
|
||||
name: None,
|
||||
mouse: None,
|
||||
parent_and_insert_index: None,
|
||||
});
|
||||
}
|
||||
},
|
||||
ClipboardMessage::ReadSelection { content, cut } => {
|
||||
if let Some(text) = content {
|
||||
@@ -230,20 +247,9 @@ impl MessageHandler<ClipboardMessage, ClipboardMessageContext<'_>> for Clipboard
|
||||
let mut vectors = Vec::new();
|
||||
let mut resources = Vec::new();
|
||||
for item in items {
|
||||
// Pasted templates skip document migration, so stored types normalize here
|
||||
match item {
|
||||
ClipboardItem::Layer(mut entry) => {
|
||||
for (_, template) in &mut entry.nodes {
|
||||
template.normalize_stored_types();
|
||||
}
|
||||
layers.push(entry);
|
||||
}
|
||||
ClipboardItem::Nodes(mut nodes) => {
|
||||
for (_, template) in &mut nodes {
|
||||
template.normalize_stored_types();
|
||||
}
|
||||
node_groups.push(nodes);
|
||||
}
|
||||
ClipboardItem::Layer(entry) => layers.push(entry),
|
||||
ClipboardItem::Nodes(nodes) => node_groups.push(nodes),
|
||||
ClipboardItem::Vector(vector) => vectors.push(vector),
|
||||
ClipboardItem::Resource(resource) => resources.push(resource),
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ use graphene_std::vector::Vector;
|
||||
#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize)]
|
||||
pub enum ClipboardContentRaw {
|
||||
Text(String),
|
||||
Svg(String),
|
||||
Image { data: Vec<u8>, width: u32, height: u32 },
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize)]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::messages::layout::utility_types::widgets::input_widgets::{SliderInputUpdate, VisualColorPickersInputUpdate};
|
||||
use crate::messages::layout::utility_types::widgets::input_widgets::{SpectrumInputUpdate, VisualColorPickersInputUpdate};
|
||||
use crate::messages::prelude::*;
|
||||
use graphene_std::vector::style::{FillChoice, GradientHueDirection, GradientInterpolation, GradientSpace, GradientSpread};
|
||||
|
||||
@@ -45,8 +45,8 @@ pub enum ColorPickerMessage {
|
||||
/// Swap the current "new" color with the captured "old" color.
|
||||
SwapNewWithOld,
|
||||
|
||||
/// `SliderInput` change: marker move/insert/delete, midpoint move/reset, or active marker selection changed.
|
||||
GradientUpdate { update: SliderInputUpdate },
|
||||
/// `SpectrumInput` change: marker move/insert/delete, midpoint move/reset, or active marker selection changed.
|
||||
GradientUpdate { update: SpectrumInputUpdate },
|
||||
/// Gradient spread choice from the gradient "Ends" selection.
|
||||
SetGradientSpread { gradient_spread: GradientSpread },
|
||||
/// Gradient cyclic choice: whether the stops wrap as a cycle, from the "Cyclic" checkbox.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::messages::color_picker::color_picker_message::{HsvChannel, RgbChannel};
|
||||
use crate::messages::layout::utility_types::widget_prelude::*;
|
||||
use crate::messages::layout::utility_types::widgets::input_widgets::{ColorPresetsInputUpdate, SliderInputUpdate, SliderMarker, VisualColorPickersInputUpdate};
|
||||
use crate::messages::layout::utility_types::widgets::input_widgets::{ColorPresetsInputUpdate, SpectrumInputUpdate, SpectrumMarker, VisualColorPickersInputUpdate};
|
||||
use crate::messages::prelude::*;
|
||||
use graphene_std::Color;
|
||||
use graphene_std::color::SRGBA8;
|
||||
@@ -377,10 +377,10 @@ impl ColorPickerMessageHandler {
|
||||
});
|
||||
}
|
||||
|
||||
/// Apply an incoming `SliderInput` intent to the gradient state and broadcast the result.
|
||||
fn apply_gradient_update(&mut self, update: SliderInputUpdate, responses: &mut VecDeque<Message>) {
|
||||
/// Apply an incoming `SpectrumInput` intent to the gradient state and broadcast the result.
|
||||
fn apply_gradient_update(&mut self, update: SpectrumInputUpdate, responses: &mut VecDeque<Message>) {
|
||||
// Active marker selection is the one update that doesn't mutate the gradient
|
||||
if let SliderInputUpdate::ActiveMarker {
|
||||
if let SpectrumInputUpdate::ActiveMarker {
|
||||
active_marker_index,
|
||||
active_marker_is_midpoint,
|
||||
} = update
|
||||
@@ -401,19 +401,19 @@ impl ColorPickerMessageHandler {
|
||||
let Some(mut gradient) = self.gradient.clone() else { return };
|
||||
|
||||
match update {
|
||||
SliderInputUpdate::MoveMarker { index, position } => {
|
||||
SpectrumInputUpdate::MoveMarker { index, position } => {
|
||||
let new_index = gradient.move_stop(index as usize, position, self.gradient_cyclic);
|
||||
if Some(index) == self.active_marker_index {
|
||||
self.active_marker_index = Some(new_index as u32);
|
||||
}
|
||||
}
|
||||
SliderInputUpdate::MoveMidpoint { index, position } => {
|
||||
SpectrumInputUpdate::MoveMidpoint { index, position } => {
|
||||
if (index as usize) >= gradient.len() {
|
||||
return;
|
||||
}
|
||||
gradient.set_midpoint(index as usize, position.clamp(MIN_MIDPOINT, MAX_MIDPOINT));
|
||||
}
|
||||
SliderInputUpdate::InsertMarker { position } => {
|
||||
SpectrumInputUpdate::InsertMarker { position } => {
|
||||
let new_index = gradient.insert_stop(position, self.gradient_settings());
|
||||
self.active_marker_index = Some(new_index as u32);
|
||||
self.active_marker_is_midpoint = false;
|
||||
@@ -422,7 +422,7 @@ impl ColorPickerMessageHandler {
|
||||
self.snapshot_old();
|
||||
}
|
||||
}
|
||||
SliderInputUpdate::InsertDuplicate { index, position } => {
|
||||
SpectrumInputUpdate::InsertDuplicate { index, position } => {
|
||||
let source = index as usize;
|
||||
let Some(insert_index) = gradient.duplicate_stop(source, position, self.gradient_cyclic) else {
|
||||
return;
|
||||
@@ -432,7 +432,7 @@ impl ColorPickerMessageHandler {
|
||||
self.active_marker_index = Some(dragged_index as u32);
|
||||
self.active_marker_is_midpoint = false;
|
||||
}
|
||||
SliderInputUpdate::RemoveDuplicate { index } => {
|
||||
SpectrumInputUpdate::RemoveDuplicate { index } => {
|
||||
let anchor = index as usize;
|
||||
if anchor >= gradient.len() || gradient.len() <= 2 {
|
||||
return;
|
||||
@@ -449,7 +449,7 @@ impl ColorPickerMessageHandler {
|
||||
self.active_marker_index = Some(active - 1);
|
||||
}
|
||||
}
|
||||
SliderInputUpdate::DeleteMarker { index } => {
|
||||
SpectrumInputUpdate::DeleteMarker { index } => {
|
||||
// Enforce minimum stop count. The gradient editor needs at least 2 stops to remain meaningful.
|
||||
if gradient.len() <= 2 || (index as usize) >= gradient.len() {
|
||||
return;
|
||||
@@ -463,10 +463,10 @@ impl ColorPickerMessageHandler {
|
||||
self.snapshot_old();
|
||||
}
|
||||
}
|
||||
SliderInputUpdate::ResetMidpoint { index } => {
|
||||
SpectrumInputUpdate::ResetMidpoint { index } => {
|
||||
gradient.reset_midpoint(index as usize);
|
||||
}
|
||||
SliderInputUpdate::ResetMarker { index } => {
|
||||
SpectrumInputUpdate::ResetMarker { index } => {
|
||||
let i = index as usize;
|
||||
let count = gradient.len();
|
||||
if i >= count {
|
||||
@@ -483,7 +483,7 @@ impl ColorPickerMessageHandler {
|
||||
self.active_marker_index = Some(new_index as u32);
|
||||
}
|
||||
}
|
||||
SliderInputUpdate::ActiveMarker { .. } => unreachable!("handled above"),
|
||||
SpectrumInputUpdate::ActiveMarker { .. } => unreachable!("handled above"),
|
||||
}
|
||||
|
||||
responses.add(FrontendMessage::ColorPickerColorChanged {
|
||||
@@ -514,10 +514,10 @@ impl ColorPickerMessageHandler {
|
||||
if let Some(gradient) = &self.gradient {
|
||||
// For gradient editing, the markers' handle colors mirror their gradient stop colors
|
||||
let markers = (0..gradient.len())
|
||||
.filter_map(|i| Some(SliderMarker::new(gradient.position(i, self.gradient_cyclic), gradient.midpoint(i), gradient.color(i)?)))
|
||||
.filter_map(|i| Some(SpectrumMarker::new(gradient.position(i, self.gradient_cyclic), gradient.midpoint(i), gradient.color(i)?)))
|
||||
.collect();
|
||||
let mut row_widgets = vec![
|
||||
SliderInput::new(GradientStops::from(gradient))
|
||||
SpectrumInput::new(GradientStops::from(gradient))
|
||||
.track_space(self.gradient_space)
|
||||
.track_cyclic(self.gradient_cyclic)
|
||||
.track_hue_direction(self.gradient_hue_direction)
|
||||
@@ -529,9 +529,8 @@ impl ColorPickerMessageHandler {
|
||||
.allow_insert(!self.disabled)
|
||||
.allow_delete(!self.disabled)
|
||||
.allow_reorder(true)
|
||||
.allow_select(true)
|
||||
.disabled(self.disabled)
|
||||
.on_update(|update: &SliderInputUpdate| ColorPickerMessage::GradientUpdate { update: update.clone() }.into())
|
||||
.on_update(|update: &SpectrumInputUpdate| ColorPickerMessage::GradientUpdate { update: update.clone() }.into())
|
||||
.widget_instance(),
|
||||
];
|
||||
|
||||
@@ -556,12 +555,12 @@ impl ColorPickerMessageHandler {
|
||||
return Message::NoOp;
|
||||
};
|
||||
let update = if is_midpoint {
|
||||
SliderInputUpdate::MoveMidpoint {
|
||||
SpectrumInputUpdate::MoveMidpoint {
|
||||
index: captured_index,
|
||||
position: new_value / 100.,
|
||||
}
|
||||
} else {
|
||||
SliderInputUpdate::MoveMarker {
|
||||
SpectrumInputUpdate::MoveMarker {
|
||||
index: captured_index,
|
||||
position: new_value / 100.,
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ impl MessageHandler<DialogMessage, DialogMessageContext<'_>> for DialogMessageHa
|
||||
.network_interface
|
||||
.node_metadata(&layer.to_node(), &[])
|
||||
.map(|node| node.persistent_metadata.display_name.clone())
|
||||
.filter(|name| !name.is_empty())
|
||||
.and_then(|name| if name.is_empty() { None } else { Some(name) })
|
||||
.unwrap_or_else(|| "Artboard".to_string());
|
||||
(layer, name)
|
||||
})
|
||||
|
||||
@@ -94,38 +94,19 @@ impl DialogLayoutHolder for ExportDialogMessageHandler {
|
||||
|
||||
impl LayoutHolder for ExportDialogMessageHandler {
|
||||
fn layout(&self) -> Layout {
|
||||
// The vector type, then the raster ones
|
||||
let file_types = [
|
||||
vec![(FileType::Svg, "SVG")],
|
||||
vec![
|
||||
(FileType::Png, "PNG"),
|
||||
(FileType::Jpg, "JPG"),
|
||||
(FileType::Webp, "WEBP"),
|
||||
(FileType::Tiff, "TIFF"),
|
||||
(FileType::Bmp, "BMP"),
|
||||
(FileType::Tga, "TGA"),
|
||||
(FileType::Ico, "ICO"),
|
||||
],
|
||||
];
|
||||
let selected_index = file_types.iter().flatten().position(|(file_type, _)| *file_type == self.file_type);
|
||||
let entries = file_types
|
||||
let entries = [(FileType::Png, "PNG"), (FileType::Jpg, "JPG"), (FileType::Svg, "SVG")]
|
||||
.into_iter()
|
||||
.map(|section| {
|
||||
section
|
||||
.into_iter()
|
||||
.map(|(file_type, name)| {
|
||||
MenuListEntry::new(format!("{file_type:?}"))
|
||||
.label(name)
|
||||
.on_commit(move |_| ExportDialogMessage::FileType { file_type }.into())
|
||||
})
|
||||
.collect()
|
||||
.map(|(file_type, name)| {
|
||||
RadioEntryData::new(format!("{file_type:?}"))
|
||||
.label(name)
|
||||
.on_update(move |_| ExportDialogMessage::FileType { file_type }.into())
|
||||
})
|
||||
.collect();
|
||||
|
||||
let export_type = vec![
|
||||
TextLabel::new("File Type").table_align(true).min_width(100).widget_instance(),
|
||||
Separator::new(SeparatorStyle::Unrelated).widget_instance(),
|
||||
DropdownInput::new(entries).selected_index(selected_index.map(|index| index as u32)).min_width(200).widget_instance(),
|
||||
RadioInput::new(entries).selected_index(Some(self.file_type as u32)).widget_instance(),
|
||||
];
|
||||
|
||||
let resolution = vec![
|
||||
|
||||
@@ -18,7 +18,7 @@ impl DialogLayoutHolder for FailedToLoadDocumentsDialog {
|
||||
.tooltip_description("Save the raw document data to disk so it can be recovered later.")
|
||||
.on_update(|_| {
|
||||
DialogMessage::CloseAndThen {
|
||||
followups: vec![FailedDocumentsMessage::DownloadFailedToLoadDocuments.into()],
|
||||
followups: vec![PortfolioMessage::DownloadFailedToLoadDocuments.into()],
|
||||
}
|
||||
.into()
|
||||
})
|
||||
@@ -27,7 +27,7 @@ impl DialogLayoutHolder for FailedToLoadDocumentsDialog {
|
||||
.tooltip_description("Permanently delete the autosaved data for these documents.")
|
||||
.on_update(|_| {
|
||||
DialogMessage::CloseAndThen {
|
||||
followups: vec![FailedDocumentsMessage::DiscardFailedToLoadDocuments.into()],
|
||||
followups: vec![PortfolioMessage::DiscardFailedToLoadDocuments.into()],
|
||||
}
|
||||
.into()
|
||||
})
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use super::IconName;
|
||||
use super::utility_types::{MouseCursorIcon, PersistedState};
|
||||
use crate::messages::app_window::app_window_message_handler::AppWindowPlatform;
|
||||
use crate::messages::frontend::utility_types::{DocumentInfo, EyedropperPreviewImage, FileDialogOptions, FileFilter, FileType, RasterizedImage};
|
||||
use crate::messages::frontend::utility_types::{DocumentInfo, EyedropperPreviewImage, FileFilter, RasterizedImage};
|
||||
use crate::messages::input_mapper::utility_types::misc::ActionShortcut;
|
||||
use crate::messages::layout::utility_types::widget_prelude::*;
|
||||
use crate::messages::portfolio::document::node_graph::utility_types::{
|
||||
@@ -9,7 +9,6 @@ use crate::messages::portfolio::document::node_graph::utility_types::{
|
||||
};
|
||||
use crate::messages::portfolio::document::utility_types::nodes::{LayerPanelEntry, LayerStructureEntry};
|
||||
use crate::messages::portfolio::document::utility_types::wires::{WirePath, WirePathUpdate};
|
||||
use crate::messages::portfolio::ingest::utility_types::IngestAction;
|
||||
use crate::messages::portfolio::utility_types::WorkspacePanelLayout;
|
||||
use crate::messages::prelude::*;
|
||||
use crate::messages::tool::tool_messages::eyedropper_tool::PrimarySecondary;
|
||||
@@ -88,9 +87,11 @@ pub enum FrontendMessage {
|
||||
commit_date: String,
|
||||
},
|
||||
TriggerDisplayThirdPartyLicensesDialog,
|
||||
TriggerBrowse {
|
||||
options: FileDialogOptions,
|
||||
action: IngestAction,
|
||||
TriggerOpen {
|
||||
filters: Vec<FileFilter>,
|
||||
},
|
||||
TriggerImport {
|
||||
filters: Vec<FileFilter>,
|
||||
},
|
||||
TriggerSaveDocument {
|
||||
document_id: DocumentId,
|
||||
@@ -109,8 +110,7 @@ pub enum FrontendMessage {
|
||||
TriggerExportImage {
|
||||
svg: String,
|
||||
name: String,
|
||||
#[serde(rename = "fileType")]
|
||||
file_type: FileType,
|
||||
mime: String,
|
||||
size: (f64, f64),
|
||||
},
|
||||
TriggerFetchAndOpenDocument {
|
||||
|
||||
@@ -47,30 +47,28 @@ pub enum MouseCursorIcon {
|
||||
Rotate,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "wasm", derive(tsify::Tsify), tsify(from_wasm_abi))]
|
||||
#[cfg_attr(feature = "wasm", derive(tsify::Tsify))]
|
||||
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
pub enum FileType {
|
||||
#[default]
|
||||
Png,
|
||||
Jpg,
|
||||
Webp,
|
||||
Tiff,
|
||||
Bmp,
|
||||
Tga,
|
||||
Ico,
|
||||
Svg,
|
||||
}
|
||||
|
||||
impl FileType {
|
||||
pub fn to_mime(self) -> &'static str {
|
||||
match self {
|
||||
FileType::Png => "image/png",
|
||||
FileType::Jpg => "image/jpeg",
|
||||
FileType::Svg => "image/svg+xml",
|
||||
}
|
||||
}
|
||||
|
||||
pub fn extension(self) -> &'static str {
|
||||
match self {
|
||||
FileType::Png => "png",
|
||||
FileType::Jpg => "jpg",
|
||||
FileType::Webp => "webp",
|
||||
FileType::Tiff => "tiff",
|
||||
FileType::Bmp => "bmp",
|
||||
FileType::Tga => "tga",
|
||||
FileType::Ico => "ico",
|
||||
FileType::Svg => "svg",
|
||||
}
|
||||
}
|
||||
@@ -79,64 +77,13 @@ impl FileType {
|
||||
let name = match self {
|
||||
FileType::Png => "PNG Image",
|
||||
FileType::Jpg => "JPEG Image",
|
||||
FileType::Webp => "WEBP Image",
|
||||
FileType::Tiff => "TIFF Image",
|
||||
FileType::Bmp => "BMP Image",
|
||||
FileType::Tga => "TGA Image",
|
||||
FileType::Ico => "ICO Image",
|
||||
FileType::Svg => "SVG Image",
|
||||
};
|
||||
FileFilter {
|
||||
name: name.into(),
|
||||
extensions: vec![self.extension().into()],
|
||||
mime_types: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Encodes 8-bit RGBA pixels with straight alpha as a file of this raster type.
|
||||
pub fn encode(self, width: u32, height: u32, rgba: Vec<u8>) -> Result<Vec<u8>, String> {
|
||||
use image::buffer::ConvertBuffer;
|
||||
use image::{ImageFormat, RgbImage, RgbaImage};
|
||||
|
||||
let Some(mut image) = RgbaImage::from_raw(width, height, rgba) else {
|
||||
return Err("Failed to create image buffer for export".to_string());
|
||||
};
|
||||
|
||||
let format = match self {
|
||||
FileType::Png => ImageFormat::Png,
|
||||
FileType::Jpg => ImageFormat::Jpeg,
|
||||
FileType::Webp => ImageFormat::WebP,
|
||||
FileType::Tiff => ImageFormat::Tiff,
|
||||
FileType::Bmp => ImageFormat::Bmp,
|
||||
FileType::Tga => ImageFormat::Tga,
|
||||
FileType::Ico => ImageFormat::Ico,
|
||||
FileType::Svg => return Err("SVG cannot be exported from an image buffer".to_string()),
|
||||
};
|
||||
if self == FileType::Ico && (width > 256 || height > 256) {
|
||||
return Err("An ICO image can be at most 256 pixels wide and tall. Lower the scale factor or choose a smaller export area.".to_string());
|
||||
}
|
||||
|
||||
let mut encoded = Vec::new();
|
||||
let mut cursor = std::io::Cursor::new(&mut encoded);
|
||||
|
||||
let result = if self == FileType::Jpg {
|
||||
// Composite onto a white background since JPG doesn't support transparency
|
||||
for pixel in image.pixels_mut() {
|
||||
let [r, g, b, a] = pixel.0;
|
||||
let alpha = a as f32 / 255.;
|
||||
let blend = |channel: u8| (channel as f32 * alpha + 255. * (1. - alpha)).round() as u8;
|
||||
*pixel = image::Rgba([blend(r), blend(g), blend(b), 255]);
|
||||
}
|
||||
|
||||
let image: RgbImage = image.convert();
|
||||
image.write_to(&mut cursor, format)
|
||||
} else {
|
||||
image.write_to(&mut cursor, format)
|
||||
};
|
||||
result.map_err(|error| format!("Failed to encode {self:?}: {error}"))?;
|
||||
|
||||
Ok(encoded)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "wasm", derive(tsify::Tsify))]
|
||||
@@ -170,49 +117,4 @@ pub struct RasterizedImage {
|
||||
pub struct FileFilter {
|
||||
pub name: String,
|
||||
pub extensions: Vec<String>,
|
||||
#[serde(rename = "mimeTypes")]
|
||||
pub mime_types: Vec<String>,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "wasm", derive(tsify::Tsify))]
|
||||
#[derive(Clone, Debug, Default, Eq, PartialEq, Hash, serde::Serialize, serde::Deserialize)]
|
||||
pub struct FileDialogOptions {
|
||||
pub filters: Vec<FileFilter>,
|
||||
pub multiple: bool,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use graphene_std::raster::Image;
|
||||
|
||||
#[test]
|
||||
fn every_raster_file_type_encodes_an_image_that_reads_back() {
|
||||
// Opaque red, then fully transparent
|
||||
let pixels = vec![255, 0, 0, 255, 0, 0, 0, 0];
|
||||
|
||||
for file_type in [FileType::Png, FileType::Jpg, FileType::Webp, FileType::Tiff, FileType::Bmp, FileType::Tga, FileType::Ico] {
|
||||
let encoded = file_type.encode(2, 1, pixels.clone()).unwrap_or_else(|error| panic!("{file_type:?}: {error}"));
|
||||
let decoded = Image::from_encoded(&encoded).unwrap_or_else(|| panic!("{file_type:?} should read back"));
|
||||
assert_eq!((decoded.width, decoded.height), (2, 1), "{file_type:?}");
|
||||
|
||||
// Only JPG lacks transparency, so it lands on white
|
||||
let transparent = decoded.to_flat_u8().0[4..8].to_vec();
|
||||
if file_type == FileType::Jpg {
|
||||
assert!(transparent.iter().all(|&channel| channel > 250), "{transparent:?}");
|
||||
} else {
|
||||
assert_eq!(transparent[3], 0, "{file_type:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn file_types_that_cannot_hold_the_image_say_so() {
|
||||
assert!(FileType::Svg.encode(1, 1, vec![0; 4]).is_err());
|
||||
assert!(FileType::Png.encode(2, 2, vec![0; 4]).is_err());
|
||||
|
||||
let too_large = FileType::Ico.encode(257, 1, vec![0; 257 * 4]).unwrap_err();
|
||||
assert!(too_large.contains("256 pixels"), "{too_large}");
|
||||
assert!(FileType::Ico.encode(256, 1, vec![0; 256 * 4]).is_ok());
|
||||
}
|
||||
}
|
||||
@@ -444,11 +444,11 @@ pub fn input_mappings(zoom_with_scroll: bool) -> Mapping {
|
||||
entry!(KeyDown(Tab); modifiers=[Control, Shift], action_dispatch=PortfolioMessage::PrevDocument),
|
||||
entry!(KeyDown(KeyW); modifiers=[Accel], action_dispatch=PortfolioMessage::CloseActiveDocumentWithConfirmation),
|
||||
entry!(KeyDown(KeyW); modifiers=[Accel, Alt], action_dispatch=PortfolioMessage::CloseAllDocumentsWithConfirmation),
|
||||
entry!(KeyDown(KeyO); modifiers=[Accel], action_dispatch=IngestMessage::Open),
|
||||
entry!(KeyDown(KeyI); modifiers=[Accel], action_dispatch=IngestMessage::Import),
|
||||
entry!(KeyDown(KeyO); modifiers=[Accel], action_dispatch=PortfolioMessage::Open),
|
||||
entry!(KeyDown(KeyI); modifiers=[Accel], action_dispatch=PortfolioMessage::Import),
|
||||
entry!(KeyDown(KeyR); modifiers=[Alt], action_dispatch=PortfolioMessage::ToggleRulers),
|
||||
entry!(KeyDown(KeyD); modifiers=[Alt], action_dispatch=WorkspaceMessage::ToggleDataPanelOpen),
|
||||
entry!(KeyDown(Enter); modifiers=[Alt], action_dispatch=WorkspaceMessage::ToggleFocusDocument),
|
||||
entry!(KeyDown(KeyD); modifiers=[Alt], action_dispatch=PortfolioMessage::ToggleDataPanelOpen),
|
||||
entry!(KeyDown(Enter); modifiers=[Alt], action_dispatch=PortfolioMessage::ToggleFocusDocument),
|
||||
//
|
||||
// DialogMessage
|
||||
entry!(KeyDown(KeyE); modifiers=[Accel], action_dispatch=DialogMessage::RequestExportDialog),
|
||||
|
||||
@@ -30,9 +30,4 @@ pub enum LayoutMessage {
|
||||
layout_target: LayoutTarget,
|
||||
widget_id: WidgetId,
|
||||
},
|
||||
WidgetValueFileDrop {
|
||||
layout_target: LayoutTarget,
|
||||
widget_id: WidgetId,
|
||||
file: DroppedFile,
|
||||
},
|
||||
}
|
||||
@@ -76,21 +76,6 @@ impl MessageHandler<LayoutMessage, LayoutMessageContext<'_>> for LayoutMessageHa
|
||||
responses.add((icon_button.on_drag_drop.callback)(icon_button));
|
||||
}
|
||||
}
|
||||
LayoutMessage::WidgetValueFileDrop { layout_target, widget_id, file } => {
|
||||
let Some(layout) = self.layouts.get_mut(layout_target as usize) else {
|
||||
warn!("WidgetValueFileDrop referenced an invalid layout. `widget_id: {widget_id}`, `layout_target: {layout_target:?}`");
|
||||
return;
|
||||
};
|
||||
let Some(widget_instance) = layout.iter_mut().find(|widget| widget.widget_id == widget_id) else {
|
||||
warn!("WidgetValueFileDrop referenced an invalid widget ID. `widget_id: {widget_id}`, `layout_target: {layout_target:?}`");
|
||||
return;
|
||||
};
|
||||
if let Widget::DropdownInput(dropdown_input) = &*widget_instance.widget
|
||||
&& dropdown_input.takes_file_drop
|
||||
{
|
||||
responses.add((dropdown_input.on_file_drop.callback)(&file));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -270,34 +255,20 @@ impl LayoutMessageHandler {
|
||||
|
||||
responses.add(callback_message);
|
||||
}
|
||||
Widget::SliderInput(slider_input) => {
|
||||
Widget::SpectrumInput(spectrum_input) => {
|
||||
let callback_message = match action {
|
||||
WidgetValueAction::Commit => (slider_input.on_commit.callback)(&()),
|
||||
WidgetValueAction::Commit => (spectrum_input.on_commit.callback)(&()),
|
||||
WidgetValueAction::Update => {
|
||||
let Ok(update) = serde_json::from_value::<SliderInputUpdate>(value) else {
|
||||
warn!("SliderInput update was not able to be parsed as SliderInputUpdate");
|
||||
let Ok(update) = serde_json::from_value::<SpectrumInputUpdate>(value) else {
|
||||
warn!("SpectrumInput update was not able to be parsed as SpectrumInputUpdate");
|
||||
return;
|
||||
};
|
||||
// Don't mutate the stored widget here: leaving its old values lets the layout diff detect a change
|
||||
// when the new layout is rebuilt with the updated state. Otherwise the frontend's stored layout
|
||||
// keeps stale values for `activeMarkerIndex`, etc., and any other widget's diff (e.g. the position
|
||||
// NumberInput) will trigger Svelte to re-spread those stale props onto SliderInput, clobbering
|
||||
// NumberInput) will trigger Svelte to re-spread those stale props onto SpectrumInput, clobbering
|
||||
// its local `activeMarkerIndex` and making subsequent drags target the wrong stop.
|
||||
(slider_input.on_update.callback)(&update)
|
||||
}
|
||||
};
|
||||
|
||||
responses.add(callback_message);
|
||||
}
|
||||
Widget::TransferCurveInput(curve_input) => {
|
||||
let callback_message = match action {
|
||||
WidgetValueAction::Commit => (curve_input.on_commit.callback)(&()),
|
||||
WidgetValueAction::Update => {
|
||||
let Ok(update) = serde_json::from_value::<TransferCurveInputUpdate>(value) else {
|
||||
warn!("TransferCurveInput update was not able to be parsed as TransferCurveInputUpdate");
|
||||
return;
|
||||
};
|
||||
(curve_input.on_update.callback)(&update)
|
||||
(spectrum_input.on_update.callback)(&update)
|
||||
}
|
||||
};
|
||||
|
||||
@@ -561,47 +532,22 @@ fn populate_computed_display_fields(layout: &mut Layout) {
|
||||
for instance in layout.iter_mut() {
|
||||
match &mut *instance.widget {
|
||||
Widget::ColorInput(color_input) => {
|
||||
color_input.swatch_samples = match &color_input.value {
|
||||
FillChoice::None => Vec::new(),
|
||||
FillChoice::Solid(color) => vec![GradientSample::new(0., graphene_std::Color::from(*color))],
|
||||
FillChoice::Gradient(ramp) => graphene_std::vector::style::Gradient::from(&ramp.stops)
|
||||
.interpolated_samples_or_black(ramp.into())
|
||||
.into_iter()
|
||||
.map(|(position, color, _)| GradientSample::new(position, color))
|
||||
.collect(),
|
||||
};
|
||||
color_input.chosen_gradient = color_input.value.to_css_background_image();
|
||||
}
|
||||
Widget::TransferCurveInput(curve_input) => {
|
||||
const SAMPLE_COUNT: usize = 128;
|
||||
let curve = graphene_std::transfer_curve::TransferCurve::new(curve_input.points.iter().map(|&(x, y)| glam::DVec2::new(x, y)).collect());
|
||||
let evaluator = curve.evaluator();
|
||||
let [x_min, x_max] = curve_input.domain;
|
||||
let [y_min, y_max] = curve_input.range;
|
||||
let (x_span, y_span) = ((x_max - x_min).max(f64::EPSILON), (y_max - y_min).max(f64::EPSILON));
|
||||
// A spline overshooting the range rides its edge as a flat line, as the clamped adjustment it depicts does
|
||||
let clamp_to_range = curve_input.clamp_to_range;
|
||||
curve_input.samples = (0..=SAMPLE_COUNT)
|
||||
.map(|i| {
|
||||
let t = i as f64 / SAMPLE_COUNT as f64;
|
||||
let y = (evaluator.evaluate(x_min + t * x_span) - y_min) / y_span;
|
||||
(t, if clamp_to_range { y.clamp(0., 1.) } else { y })
|
||||
})
|
||||
.collect();
|
||||
}
|
||||
Widget::SliderInput(slider_input) => {
|
||||
Widget::SpectrumInput(spectrum_input) => {
|
||||
// The track strip spans exactly 0 to 1, which no spread affects, so the widget carries no spread of its own
|
||||
let settings = graphene_std::vector::style::GradientSettings {
|
||||
spread: Default::default(),
|
||||
cyclic: slider_input.track_cyclic,
|
||||
space: slider_input.track_space,
|
||||
hue_direction: slider_input.track_hue_direction,
|
||||
interpolation: slider_input.track_interpolation,
|
||||
cyclic: spectrum_input.track_cyclic,
|
||||
space: spectrum_input.track_space,
|
||||
hue_direction: spectrum_input.track_hue_direction,
|
||||
interpolation: spectrum_input.track_interpolation,
|
||||
};
|
||||
let track_gradient = graphene_std::vector::style::Gradient::from(&slider_input.track);
|
||||
slider_input.track_samples = track_gradient
|
||||
let track_gradient = graphene_std::vector::style::Gradient::from(&spectrum_input.track);
|
||||
spectrum_input.track_samples = track_gradient
|
||||
.interpolated_samples_or_black(settings)
|
||||
.into_iter()
|
||||
.map(|(position, color, _)| GradientSample::new(position, color))
|
||||
.map(|(position, color, _)| SpectrumSample::new(position, color))
|
||||
.collect();
|
||||
// The end caps sample the track's boundary colors, which a cyclic wrap makes the wrapped interval's boundary-crossing color rather than the outermost stops'
|
||||
let track_evaluator = track_gradient.evaluator(settings);
|
||||
@@ -609,8 +555,8 @@ fn populate_computed_display_fields(layout: &mut Layout) {
|
||||
let color = track_evaluator.evaluate(t);
|
||||
SRGBA8::from(color).to_css_hex()
|
||||
};
|
||||
slider_input.track_start_css = cap(0.);
|
||||
slider_input.track_end_css = cap(1.);
|
||||
spectrum_input.track_start_css = cap(0.);
|
||||
spectrum_input.track_end_css = cap(1.);
|
||||
}
|
||||
Widget::ColorComparisonInput(comparison) => {
|
||||
let contrasting = |color: Option<SRGBA8>| color.map_or(SRGBA8::BLACK, |color| color.contrasting_text_color()).to_css_hex();
|
||||
|
||||
@@ -470,8 +470,7 @@ impl LayoutGroup {
|
||||
| Widget::ParameterExposeButton(_)
|
||||
| Widget::ColorComparisonInput(_)
|
||||
| Widget::ColorPresetsInput(_)
|
||||
| Widget::SliderInput(_)
|
||||
| Widget::TransferCurveInput(_)
|
||||
| Widget::SpectrumInput(_)
|
||||
| Widget::VisualColorPickersInput(_) => continue,
|
||||
};
|
||||
if val.is_empty() {
|
||||
@@ -809,7 +808,6 @@ pub enum Widget {
|
||||
ColorComparisonInput(ColorComparisonInput),
|
||||
ColorInput(ColorInput),
|
||||
ColorPresetsInput(ColorPresetsInput),
|
||||
TransferCurveInput(TransferCurveInput),
|
||||
DropdownInput(DropdownInput),
|
||||
IconButton(IconButton),
|
||||
IconLabel(IconLabel),
|
||||
@@ -823,7 +821,7 @@ pub enum Widget {
|
||||
PopoverButton(PopoverButton),
|
||||
RadioInput(RadioInput),
|
||||
Separator(Separator),
|
||||
SliderInput(SliderInput),
|
||||
SpectrumInput(SpectrumInput),
|
||||
TextAreaInput(TextAreaInput),
|
||||
TextButton(TextButton),
|
||||
TextInput(TextInput),
|
||||
@@ -888,8 +886,7 @@ impl DiffUpdate {
|
||||
| Widget::WorkingColorsInput(_)
|
||||
| Widget::ColorComparisonInput(_)
|
||||
| Widget::ColorPresetsInput(_)
|
||||
| Widget::SliderInput(_)
|
||||
| Widget::TransferCurveInput(_)
|
||||
| Widget::SpectrumInput(_)
|
||||
| Widget::VisualColorPickersInput(_) => None,
|
||||
};
|
||||
|
||||
|
||||
@@ -193,11 +193,11 @@ pub struct ColorInput {
|
||||
// Content
|
||||
#[widget_builder(constructor)]
|
||||
pub value: FillChoice<SRGBA8>,
|
||||
/// Straight-alpha color samples drawn by the frontend as the stops of an SVG gradient filling the swatch. Auto-populated from `value` at layout-send time.
|
||||
/// Empty when `value` is `FillChoice::<SRGBA8>::None`, in which case the frontend uses its "none" fallback styling.
|
||||
#[serde(rename = "swatchSamples")]
|
||||
/// CSS `linear-gradient(...)` (or solid-color stand-in) for the swatch's `background-image`. Auto-populated from `value` at layout-send time.
|
||||
/// `None` when `value` is `FillChoice::<SRGBA8>::None`, in which case the frontend uses its "none" fallback styling.
|
||||
#[serde(rename = "chosenGradient")]
|
||||
#[widget_builder(skip)]
|
||||
pub swatch_samples: Vec<GradientSample>,
|
||||
pub chosen_gradient: Option<String>,
|
||||
#[serde(rename = "allowNone")]
|
||||
#[derivative(Default(value = "true"))]
|
||||
pub allow_none: bool,
|
||||
|
||||
@@ -83,10 +83,6 @@ pub struct DropdownInput {
|
||||
pub virtual_scrolling: bool,
|
||||
#[derivative(Default(value = "true"))]
|
||||
pub interactive: bool,
|
||||
// Set along with the `on_file_drop` callback
|
||||
#[serde(rename = "takesFileDrop")]
|
||||
#[widget_builder(skip)]
|
||||
pub takes_file_drop: bool,
|
||||
|
||||
// Sizing
|
||||
#[serde(rename = "minWidth")]
|
||||
@@ -101,28 +97,8 @@ pub struct DropdownInput {
|
||||
pub tooltip_description: String,
|
||||
#[serde(rename = "tooltipShortcut")]
|
||||
pub tooltip_shortcut: Option<ActionShortcut>,
|
||||
|
||||
// Callbacks
|
||||
#[serde(skip)]
|
||||
#[derivative(Debug = "ignore", PartialEq = "ignore")]
|
||||
#[widget_builder(skip)]
|
||||
pub on_file_drop: WidgetCallback<DroppedFile>,
|
||||
}
|
||||
|
||||
impl DropdownInput {
|
||||
/// Makes the widget take a file dropped on it, which is handed to the callback.
|
||||
pub fn on_file_drop(mut self, callback: impl Fn(&DroppedFile) -> Message + 'static + Send + Sync) -> Self {
|
||||
self.takes_file_drop = true;
|
||||
self.on_file_drop = WidgetCallback::new(callback);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
pub struct DroppedFile {
|
||||
pub name: String,
|
||||
pub mime_type: String,
|
||||
pub data: Vec<u8>,
|
||||
//
|
||||
// Callbacks exists on the `MenuListEntry` children, not this parent `DropdownInput`
|
||||
}
|
||||
|
||||
pub type MenuListEntrySections = Vec<Vec<MenuListEntry>>;
|
||||
@@ -605,50 +581,7 @@ pub enum ColorPresetsInputUpdate {
|
||||
#[cfg_attr(feature = "wasm", derive(tsify::Tsify))]
|
||||
#[derive(Clone, Derivative, serde::Serialize, serde::Deserialize, WidgetBuilder)]
|
||||
#[derivative(Debug, PartialEq, Default)]
|
||||
pub struct TransferCurveInput {
|
||||
// Content
|
||||
/// The control points in the units of `domain` and `range`, in any x order, since sampling sorts them.
|
||||
#[widget_builder(constructor)]
|
||||
pub points: Vec<(f64, f64)>,
|
||||
/// The x extent the box spans, left to right.
|
||||
pub domain: [f64; 2],
|
||||
/// The y extent the box spans, bottom to top.
|
||||
pub range: [f64; 2],
|
||||
/// Whether the drawn curve and a dragged point's y stay inside `range`. A point's x always stays inside `domain`.
|
||||
#[serde(rename = "clampToRange")]
|
||||
pub clamp_to_range: bool,
|
||||
/// Polyline of the curve in box-normalized 0..1 coordinates with y upward. Auto-populated from `points` at layout-send time.
|
||||
#[widget_builder(skip)]
|
||||
pub samples: Vec<(f64, f64)>,
|
||||
/// Whether clicking empty space inserts a point.
|
||||
#[serde(rename = "allowInsert")]
|
||||
pub allow_insert: bool,
|
||||
/// Whether double-click or right-click removes a point. The handler still has the final say (e.g., enforcing a minimum count).
|
||||
#[serde(rename = "allowDelete")]
|
||||
pub allow_delete: bool,
|
||||
pub disabled: bool,
|
||||
|
||||
// Callbacks
|
||||
#[serde(skip)]
|
||||
#[derivative(Debug = "ignore", PartialEq = "ignore")]
|
||||
pub on_update: WidgetCallback<TransferCurveInputUpdate>,
|
||||
#[serde(skip)]
|
||||
#[derivative(Debug = "ignore", PartialEq = "ignore")]
|
||||
pub on_commit: WidgetCallback<()>,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "wasm", derive(tsify::Tsify))]
|
||||
#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
pub enum TransferCurveInputUpdate {
|
||||
MovePoint { index: u32, x: f64, y: f64 },
|
||||
InsertPoint { x: f64, y: f64 },
|
||||
DeletePoint { index: u32 },
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "wasm", derive(tsify::Tsify))]
|
||||
#[derive(Clone, Derivative, serde::Serialize, serde::Deserialize, WidgetBuilder)]
|
||||
#[derivative(Debug, PartialEq, Default)]
|
||||
pub struct SliderInput {
|
||||
pub struct SpectrumInput {
|
||||
// Content
|
||||
/// The colored gradient drawn behind the markers (display-only, caller-owned).
|
||||
#[widget_builder(constructor)]
|
||||
@@ -665,10 +598,10 @@ pub struct SliderInput {
|
||||
/// The path the track's stops interpolate along, used to bake `track_samples` and by the frontend to suppress the midpoint diamonds when stepped.
|
||||
#[serde(rename = "trackInterpolation")]
|
||||
pub track_interpolation: GradientInterpolation,
|
||||
/// Straight-alpha color samples drawn by the frontend as the stops of an SVG gradient filling the track strip. Auto-populated from `track` at layout-send time.
|
||||
/// Straight-alpha samples the frontend draws as the stops of an SVG gradient filling the track strip. Auto-populated from `track` at layout-send time.
|
||||
#[serde(rename = "trackSamples")]
|
||||
#[widget_builder(skip)]
|
||||
pub track_samples: Vec<GradientSample>,
|
||||
pub track_samples: Vec<SpectrumSample>,
|
||||
/// Hex string for the track strip's leftmost solid-color end-cap. Auto-populated by evaluating `track` at position 0.
|
||||
#[serde(rename = "trackStartCSS")]
|
||||
#[widget_builder(skip)]
|
||||
@@ -678,7 +611,7 @@ pub struct SliderInput {
|
||||
#[widget_builder(skip)]
|
||||
pub track_end_css: String,
|
||||
/// The handles the user can drag along the track. Their handle colors are caller-owned (e.g., for a gradient editor they follow the stop colors, for a "Shadows/Midpoints/Highlights" widget they're hardcoded).
|
||||
pub markers: Vec<SliderMarker>,
|
||||
pub markers: Vec<SpectrumMarker>,
|
||||
#[serde(rename = "activeMarkerIndex")]
|
||||
pub active_marker_index: Option<u32>,
|
||||
#[serde(rename = "activeMarkerIsMidpoint")]
|
||||
@@ -686,34 +619,24 @@ pub struct SliderInput {
|
||||
/// Whether to render midpoint diamonds between adjacent markers (only meaningful for gradient-like uses).
|
||||
#[serde(rename = "showMidpoints")]
|
||||
pub show_midpoints: bool,
|
||||
/// Whether clicking the track inserts a new marker at the click position. Otherwise the click picks up the nearest marker.
|
||||
/// Whether clicking the track inserts a new marker at the click position.
|
||||
#[serde(rename = "allowInsert")]
|
||||
pub allow_insert: bool,
|
||||
/// Whether right-click or pressing Delete removes a marker. The handler still has the final say on whether the deletion goes through (e.g., enforcing a minimum count).
|
||||
#[serde(rename = "allowDelete")]
|
||||
pub allow_delete: bool,
|
||||
/// Whether dragging a marker past another reorders them, which also needs `allow_select`. Otherwise the dragged marker is clamped between its neighbors.
|
||||
/// Whether dragging a marker past another reorders them. If false, the dragged marker is clamped between its neighbors.
|
||||
#[serde(rename = "allowReorder")]
|
||||
pub allow_reorder: bool,
|
||||
/// Whether the track's ends meet, as on a hue wheel: a run dragged by its strip or dashed link wraps past them, a lone marker stops.
|
||||
#[serde(rename = "allowWrap")]
|
||||
pub allow_wrap: bool,
|
||||
/// Whether clicking a marker selects it, keeping it highlighted and reported as the active marker until another is chosen,
|
||||
/// as a gradient editor needs for the stop being edited. Otherwise the highlight only follows the pointer and the drag.
|
||||
#[serde(rename = "allowSelect")]
|
||||
pub allow_select: bool,
|
||||
/// Compact mode: 8px track height with 8px top padding, for use in rows alongside other widgets.
|
||||
pub narrow: bool,
|
||||
/// Plain range-slider mode, for a number beside its number input: a flat 4px track is drawn in place of the gradient, so `track` is never shown.
|
||||
#[serde(rename = "rangeSlider")]
|
||||
pub range_slider: bool,
|
||||
/// Whether the input is disabled (dimmed and read-only).
|
||||
pub disabled: bool,
|
||||
|
||||
// Callbacks
|
||||
#[serde(skip)]
|
||||
#[derivative(Debug = "ignore", PartialEq = "ignore")]
|
||||
pub on_update: WidgetCallback<SliderInputUpdate>,
|
||||
pub on_update: WidgetCallback<SpectrumInputUpdate>,
|
||||
#[serde(skip)]
|
||||
#[derivative(Debug = "ignore", PartialEq = "ignore")]
|
||||
pub on_commit: WidgetCallback<()>,
|
||||
@@ -721,59 +644,30 @@ pub struct SliderInput {
|
||||
|
||||
#[cfg_attr(feature = "wasm", derive(tsify::Tsify))]
|
||||
#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
pub struct SliderMarker {
|
||||
/// Position along the track, normally 0..1. A shifted or stretched non-cyclic ramp can push it outside, where it is not drawn.
|
||||
pub struct SpectrumMarker {
|
||||
/// Position of the marker along the spectrum track, normally from 0 to 1. A shifted or stretched non-cyclic ramp can
|
||||
/// place it outside that range, where the track draws only the markers falling within its visible span.
|
||||
position: f64,
|
||||
/// Midpoint (0..1) of the interval to the next marker, used only with `show_midpoints`. The last marker's midpoint spans the wrap of a cyclic track, or is otherwise ignored.
|
||||
/// Position (0..1) of the midpoint between this marker and the next, used only if `show_midpoints` is true.
|
||||
/// The last marker's value controls the wrapped interval when `track_cyclic` is set, and is otherwise ignored.
|
||||
midpoint: f64,
|
||||
/// CSS color string for the marker handle's fill. Set via `SliderMarker::new` from a linear [`Color`],
|
||||
/// CSS color string for the marker handle's fill. Set via `SpectrumMarker::new` from a linear [`Color`],
|
||||
/// discarding any transparency so the handle always shows the RGB that steers the interpolation.
|
||||
#[serde(rename = "handleColorCSS")]
|
||||
handle_color_css: String,
|
||||
/// Whether this marker and the next form a split handle: one marker split down the middle while they coincide, two halves joined by a strip once apart.
|
||||
#[serde(rename = "pairedWithNext")]
|
||||
paired_with_next: bool,
|
||||
/// Whether a dashed line runs from this marker to the next through the lane below the track. Dragging it carries both markers, along with any split-handle halves attached to them.
|
||||
#[serde(rename = "dashedToNext")]
|
||||
dashed_to_next: bool,
|
||||
/// Whether this marker follows its neighbors instead of bounding them, so they may drag past its drawn position.
|
||||
#[serde(rename = "betweenNeighbors")]
|
||||
between_neighbors: bool,
|
||||
}
|
||||
|
||||
impl SliderMarker {
|
||||
impl SpectrumMarker {
|
||||
pub fn new(position: f64, midpoint: f64, handle_color: Color) -> Self {
|
||||
let handle_color_css = format!("#{}", SRGBA8::from(handle_color).to_rgb_hex());
|
||||
Self {
|
||||
position,
|
||||
midpoint,
|
||||
handle_color_css,
|
||||
paired_with_next: false,
|
||||
dashed_to_next: false,
|
||||
between_neighbors: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn between_neighbors(mut self) -> Self {
|
||||
self.between_neighbors = true;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn pair_with_next(mut self) -> Self {
|
||||
self.paired_with_next = true;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn dash_to_next(mut self) -> Self {
|
||||
self.dashed_to_next = true;
|
||||
self
|
||||
Self { position, midpoint, handle_color_css }
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "wasm", derive(tsify::Tsify))]
|
||||
#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
pub struct GradientSample {
|
||||
/// Position (0..1) of the sample along the gradient, drawn as the SVG stop's `offset`.
|
||||
pub struct SpectrumSample {
|
||||
/// Position (0..1) of the sample along the spectrum track, drawn as the SVG stop's `offset`.
|
||||
position: f64,
|
||||
/// `#rrggbb` hex of the sample's color, drawn as the SVG stop's `stop-color`.
|
||||
color: String,
|
||||
@@ -781,7 +675,7 @@ pub struct GradientSample {
|
||||
alpha: f32,
|
||||
}
|
||||
|
||||
impl GradientSample {
|
||||
impl SpectrumSample {
|
||||
pub fn new(position: f64, color: Color) -> Self {
|
||||
Self {
|
||||
position,
|
||||
@@ -793,7 +687,7 @@ impl GradientSample {
|
||||
|
||||
#[cfg_attr(feature = "wasm", derive(tsify::Tsify))]
|
||||
#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
pub enum SliderInputUpdate {
|
||||
pub enum SpectrumInputUpdate {
|
||||
MoveMarker {
|
||||
index: u32,
|
||||
position: f64,
|
||||
|
||||
@@ -123,8 +123,8 @@ impl LayoutHolder for MenuBarMessageHandler {
|
||||
MenuListEntry::new("Open…")
|
||||
.label("Open…")
|
||||
.icon("Folder")
|
||||
.tooltip_shortcut(action_shortcut!(IngestMessageDiscriminant::Open))
|
||||
.on_commit(|_| IngestMessage::Open.into()),
|
||||
.tooltip_shortcut(action_shortcut!(PortfolioMessageDiscriminant::Open))
|
||||
.on_commit(|_| PortfolioMessage::Open.into()),
|
||||
MenuListEntry::new("Open Demo Artwork…")
|
||||
.label("Open Demo Artwork…")
|
||||
.icon("Image")
|
||||
@@ -163,8 +163,8 @@ impl LayoutHolder for MenuBarMessageHandler {
|
||||
MenuListEntry::new("Import…")
|
||||
.label("Import…")
|
||||
.icon("FileImport")
|
||||
.tooltip_shortcut(action_shortcut!(IngestMessageDiscriminant::Import))
|
||||
.on_commit(|_| IngestMessage::Import.into())
|
||||
.tooltip_shortcut(action_shortcut!(PortfolioMessageDiscriminant::Import))
|
||||
.on_commit(|_| PortfolioMessage::Import.into())
|
||||
.disabled(no_active_document),
|
||||
MenuListEntry::new("Export…")
|
||||
.label("Export…")
|
||||
@@ -651,33 +651,33 @@ impl LayoutHolder for MenuBarMessageHandler {
|
||||
MenuListEntry::new("Focus Document")
|
||||
.label("Focus Document")
|
||||
.icon(if self.focus_document { "CheckboxChecked" } else { "CheckboxUnchecked" })
|
||||
.tooltip_shortcut(action_shortcut!(WorkspaceMessageDiscriminant::ToggleFocusDocument))
|
||||
.on_commit(|_| WorkspaceMessage::ToggleFocusDocument.into()),
|
||||
.tooltip_shortcut(action_shortcut!(PortfolioMessageDiscriminant::ToggleFocusDocument))
|
||||
.on_commit(|_| PortfolioMessage::ToggleFocusDocument.into()),
|
||||
],
|
||||
vec![
|
||||
MenuListEntry::new("Reset Workspace")
|
||||
.label("Reset Workspace")
|
||||
.icon("Reset")
|
||||
.on_commit(|_| WorkspaceMessage::ResetWorkspaceLayout.into()),
|
||||
.on_commit(|_| PortfolioMessage::ResetWorkspaceLayout.into()),
|
||||
],
|
||||
vec![
|
||||
MenuListEntry::new("Properties")
|
||||
.label("Properties")
|
||||
.icon(if self.properties_panel_open { "CheckboxChecked" } else { "CheckboxUnchecked" })
|
||||
.tooltip_shortcut(action_shortcut!(WorkspaceMessageDiscriminant::TogglePropertiesPanelOpen))
|
||||
.on_commit(|_| WorkspaceMessage::TogglePropertiesPanelOpen.into())
|
||||
.tooltip_shortcut(action_shortcut!(PortfolioMessageDiscriminant::TogglePropertiesPanelOpen))
|
||||
.on_commit(|_| PortfolioMessage::TogglePropertiesPanelOpen.into())
|
||||
.disabled(self.focus_document),
|
||||
MenuListEntry::new("Layers")
|
||||
.label("Layers")
|
||||
.icon(if self.layers_panel_open { "CheckboxChecked" } else { "CheckboxUnchecked" })
|
||||
.tooltip_shortcut(action_shortcut!(WorkspaceMessageDiscriminant::ToggleLayersPanelOpen))
|
||||
.on_commit(|_| WorkspaceMessage::ToggleLayersPanelOpen.into())
|
||||
.tooltip_shortcut(action_shortcut!(PortfolioMessageDiscriminant::ToggleLayersPanelOpen))
|
||||
.on_commit(|_| PortfolioMessage::ToggleLayersPanelOpen.into())
|
||||
.disabled(self.focus_document),
|
||||
MenuListEntry::new("Data")
|
||||
.label("Data")
|
||||
.icon(if self.data_panel_open { "CheckboxChecked" } else { "CheckboxUnchecked" })
|
||||
.tooltip_shortcut(action_shortcut!(WorkspaceMessageDiscriminant::ToggleDataPanelOpen))
|
||||
.on_commit(|_| WorkspaceMessage::ToggleDataPanelOpen.into())
|
||||
.tooltip_shortcut(action_shortcut!(PortfolioMessageDiscriminant::ToggleDataPanelOpen))
|
||||
.on_commit(|_| PortfolioMessage::ToggleDataPanelOpen.into())
|
||||
.disabled(self.focus_document),
|
||||
],
|
||||
])
|
||||
|
||||
@@ -10,30 +10,25 @@ use graph_craft::document::NodeId;
|
||||
use graphene_std::animation::RealTimeMode;
|
||||
use graphene_std::blending::BlendMode;
|
||||
use graphene_std::color::SRGBA8;
|
||||
use graphene_std::core_types::misc::format_f64;
|
||||
use graphene_std::extract_xy::XY;
|
||||
use graphene_std::gradient::Gradient;
|
||||
use graphene_std::list::{Item, List, NodeIdPath};
|
||||
use graphene_std::list::{Item, List};
|
||||
use graphene_std::math::float_noise::round_away_float_noise;
|
||||
use graphene_std::memo::IORecord;
|
||||
use graphene_std::raster::{
|
||||
AdjustmentChannel, CellularDistanceFunction, CellularReturnType, DesaturateMethod, DomainWarpType, FractalType, HueSaturationRange, NoiseType, RedGreenBlue, RedGreenBlueAlpha, RelativeAbsolute,
|
||||
SelectiveColorChoice, TonalRange,
|
||||
CellularDistanceFunction, CellularReturnType, DomainWarpType, FractalType, LuminanceCalculation, NoiseType, RedGreenBlue, RedGreenBlueAlpha, RelativeAbsolute, SelectiveColorChoice,
|
||||
};
|
||||
use graphene_std::raster_types::{CPU, GPU, Raster};
|
||||
use graphene_std::text::TextAlign;
|
||||
use graphene_std::text_nodes::{StringCapitalization, TextDenomination};
|
||||
use graphene_std::transfer_curve::TransferCurve;
|
||||
use graphene_std::text_nodes::StringCapitalization;
|
||||
use graphene_std::transform::{ReferencePoint, ScaleType};
|
||||
use graphene_std::vector::misc::{
|
||||
ArcType, BezierHandles, BooleanOperation, BoxCorners, CentroidType, ExtrudeJoiningAlgorithm, GridType, InterpolationDistribution, MergeByDistanceAlgorithm, PointSpacingType, RowsOrColumns,
|
||||
SpiralType,
|
||||
ArcType, BooleanOperation, BoxCorners, CentroidType, ExtrudeJoiningAlgorithm, GridType, InterpolationDistribution, MergeByDistanceAlgorithm, PointSpacingType, RowsOrColumns, SpiralType,
|
||||
};
|
||||
use graphene_std::vector::style::{
|
||||
DashPattern, FillChoice, GradientForm, GradientHueDirection, GradientInterpolation, GradientRamp, GradientSettings, GradientSpace, GradientSpread, StrokeAlign, StrokeCap, StrokeJoin,
|
||||
DashPattern, FillChoice, GradientForm, GradientHueDirection, GradientInterpolation, GradientRamp, GradientSettings, GradientSpace, GradientSpread, PaintOrder, StrokeAlign, StrokeCap, StrokeJoin,
|
||||
};
|
||||
use graphene_std::vector::{QRCodeErrorCorrectionLevel, Vector};
|
||||
use graphene_std::{Appearance, Artboard, Color, Context, Cover, Coverage, Graphic};
|
||||
use graphene_std::{Artboard, Color, Graphic};
|
||||
use std::any::Any;
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -191,8 +186,8 @@ macro_rules! generate_layout_downcast {
|
||||
($introspected_data:expr, $data:expr, [ $($ty:ty),* $(,)? ]) => {
|
||||
if false { None }
|
||||
$(
|
||||
else if let Some(io) = $introspected_data.downcast_ref::<IORecord<Context, $ty>>() {
|
||||
Some(io.output.layout_with_breadcrumb($data))
|
||||
else if let Some(element) = $introspected_data.downcast_ref::<$ty>() {
|
||||
Some(element.layout_with_breadcrumb($data))
|
||||
}
|
||||
)*
|
||||
else { None }
|
||||
@@ -200,10 +195,15 @@ macro_rules! generate_layout_downcast {
|
||||
}
|
||||
// TODO: We simply try all these types sequentially. Find a better strategy.
|
||||
fn generate_layout(introspected_data: &Arc<dyn std::any::Any + Send + Sync + 'static>, data: &mut LayoutData) -> Option<Vec<LayoutGroup>> {
|
||||
// `Item<NodeIdPath>` is interpreted as a path (e.g. the value produced by `path_of_subgraph`), shown as a
|
||||
// `List<NodeId>` is interpreted as a path (e.g. the value produced by `path_of_subgraph`), shown as a
|
||||
// `List` where each item's NodeId resolves against the prefix made up of the items above it.
|
||||
if let Some(io) = introspected_data.downcast_ref::<IORecord<Context, Item<NodeIdPath>>>() {
|
||||
return Some(table_node_id_path_layout_with_breadcrumb(&io.output.element().0, data));
|
||||
if let Some(list) = introspected_data.downcast_ref::<List<NodeId>>() {
|
||||
return Some(table_node_id_path_layout_with_breadcrumb(list, data));
|
||||
}
|
||||
// The path's plain value form, produced by `path_of_subgraph` on leveled wires.
|
||||
if let Some(path) = introspected_data.downcast_ref::<Vec<NodeId>>() {
|
||||
let list: List<NodeId> = path.iter().copied().map(graphene_std::list::Item::new_from_element).collect();
|
||||
return Some(table_node_id_path_layout_with_breadcrumb(&list, data));
|
||||
}
|
||||
generate_layout_downcast!(introspected_data, data, [
|
||||
List<Artboard>,
|
||||
@@ -231,23 +231,19 @@ fn generate_layout(introspected_data: &Arc<dyn std::any::Any + Send + Sync + 'st
|
||||
List<GradientInterpolation>,
|
||||
List<DashPattern>,
|
||||
List<BoxCorners>,
|
||||
List<TransferCurve>,
|
||||
List<StrokeJoin>,
|
||||
List<StrokeAlign>,
|
||||
List<StrokeCap>,
|
||||
List<PaintOrder>,
|
||||
List<MergeByDistanceAlgorithm>,
|
||||
List<ExtrudeJoiningAlgorithm>,
|
||||
List<PointSpacingType>,
|
||||
List<StringCapitalization>,
|
||||
List<TextDenomination>,
|
||||
List<DesaturateMethod>,
|
||||
List<LuminanceCalculation>,
|
||||
List<RedGreenBlue>,
|
||||
List<RedGreenBlueAlpha>,
|
||||
List<RelativeAbsolute>,
|
||||
List<SelectiveColorChoice>,
|
||||
List<TonalRange>,
|
||||
List<AdjustmentChannel>,
|
||||
List<HueSaturationRange>,
|
||||
List<XY>,
|
||||
List<ScaleType>,
|
||||
List<ReferencePoint>,
|
||||
@@ -266,66 +262,60 @@ fn generate_layout(introspected_data: &Arc<dyn std::any::Any + Send + Sync + 'st
|
||||
List<QRCodeErrorCorrectionLevel>,
|
||||
List<InterpolationDistribution>,
|
||||
List<RowsOrColumns>,
|
||||
Item<Artboard>,
|
||||
Item<Graphic>,
|
||||
Item<Vector>,
|
||||
Item<Raster<CPU>>,
|
||||
Item<Raster<GPU>>,
|
||||
Item<Color>,
|
||||
Item<Gradient>,
|
||||
Item<String>,
|
||||
Item<f64>,
|
||||
Item<f32>,
|
||||
Item<u32>,
|
||||
Item<u64>,
|
||||
Item<i32>,
|
||||
Item<i64>,
|
||||
Item<bool>,
|
||||
Item<DVec2>,
|
||||
Item<DAffine2>,
|
||||
Item<BlendMode>,
|
||||
Item<GradientForm>,
|
||||
Item<GradientSpread>,
|
||||
Item<GradientSpace>,
|
||||
Item<GradientHueDirection>,
|
||||
Item<GradientInterpolation>,
|
||||
Item<DashPattern>,
|
||||
Item<BoxCorners>,
|
||||
Item<TransferCurve>,
|
||||
Item<StrokeJoin>,
|
||||
Item<StrokeAlign>,
|
||||
Item<StrokeCap>,
|
||||
Item<MergeByDistanceAlgorithm>,
|
||||
Item<ExtrudeJoiningAlgorithm>,
|
||||
Item<PointSpacingType>,
|
||||
Item<StringCapitalization>,
|
||||
Item<TextDenomination>,
|
||||
Item<DesaturateMethod>,
|
||||
Item<RedGreenBlue>,
|
||||
Item<RedGreenBlueAlpha>,
|
||||
Item<RelativeAbsolute>,
|
||||
Item<SelectiveColorChoice>,
|
||||
Item<TonalRange>,
|
||||
Item<AdjustmentChannel>,
|
||||
Item<HueSaturationRange>,
|
||||
Item<XY>,
|
||||
Item<ScaleType>,
|
||||
Item<ReferencePoint>,
|
||||
Item<CentroidType>,
|
||||
Item<BooleanOperation>,
|
||||
Item<NoiseType>,
|
||||
Item<FractalType>,
|
||||
Item<CellularDistanceFunction>,
|
||||
Item<CellularReturnType>,
|
||||
Item<DomainWarpType>,
|
||||
Item<RealTimeMode>,
|
||||
Item<GridType>,
|
||||
Item<ArcType>,
|
||||
Item<SpiralType>,
|
||||
Item<TextAlign>,
|
||||
Item<QRCodeErrorCorrectionLevel>,
|
||||
Item<InterpolationDistribution>,
|
||||
Item<RowsOrColumns>,
|
||||
Artboard,
|
||||
Graphic,
|
||||
Vector,
|
||||
Raster<CPU>,
|
||||
Raster<GPU>,
|
||||
Color,
|
||||
Gradient,
|
||||
String,
|
||||
f64,
|
||||
f32,
|
||||
u32,
|
||||
u64,
|
||||
i32,
|
||||
i64,
|
||||
bool,
|
||||
DVec2,
|
||||
DAffine2,
|
||||
BlendMode,
|
||||
GradientForm,
|
||||
GradientSpace,
|
||||
GradientSpread,
|
||||
DashPattern,
|
||||
BoxCorners,
|
||||
StrokeJoin,
|
||||
StrokeAlign,
|
||||
StrokeCap,
|
||||
PaintOrder,
|
||||
MergeByDistanceAlgorithm,
|
||||
ExtrudeJoiningAlgorithm,
|
||||
PointSpacingType,
|
||||
StringCapitalization,
|
||||
LuminanceCalculation,
|
||||
RedGreenBlue,
|
||||
RedGreenBlueAlpha,
|
||||
RelativeAbsolute,
|
||||
SelectiveColorChoice,
|
||||
XY,
|
||||
ScaleType,
|
||||
ReferencePoint,
|
||||
CentroidType,
|
||||
BooleanOperation,
|
||||
NoiseType,
|
||||
FractalType,
|
||||
CellularDistanceFunction,
|
||||
CellularReturnType,
|
||||
DomainWarpType,
|
||||
RealTimeMode,
|
||||
GridType,
|
||||
ArcType,
|
||||
SpiralType,
|
||||
TextAlign,
|
||||
QRCodeErrorCorrectionLevel,
|
||||
InterpolationDistribution,
|
||||
RowsOrColumns,
|
||||
])
|
||||
}
|
||||
|
||||
@@ -491,7 +481,7 @@ impl<T: TableItemLayout> TableItemLayout for List<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl TableItemLayout for Artboard {
|
||||
impl TableItemLayout for Artboard<'_> {
|
||||
fn type_name() -> &'static str {
|
||||
"Artboard"
|
||||
}
|
||||
@@ -507,15 +497,6 @@ impl TableItemLayout for Artboard {
|
||||
}
|
||||
}
|
||||
|
||||
impl TableItemLayout for graphene_std::brush::Stroke {
|
||||
fn type_name() -> &'static str {
|
||||
"Stroke"
|
||||
}
|
||||
fn identifier(&self) -> String {
|
||||
format!("Stroke ({} {})", self.len(), if self.len() == 1 { "sample" } else { "samples" })
|
||||
}
|
||||
}
|
||||
|
||||
impl TableItemLayout for DashPattern {
|
||||
fn type_name() -> &'static str {
|
||||
"DashPattern"
|
||||
@@ -536,65 +517,6 @@ impl TableItemLayout for DashPattern {
|
||||
}
|
||||
}
|
||||
|
||||
impl TableItemLayout for Appearance {
|
||||
fn type_name() -> &'static str {
|
||||
"Appearance"
|
||||
}
|
||||
fn identifier(&self) -> String {
|
||||
"Appearance".to_string()
|
||||
}
|
||||
// The wrapping `Item` already contributes the breadcrumb; the inner list supplies the next level
|
||||
fn layout_with_breadcrumb(&self, data: &mut LayoutData) -> Vec<LayoutGroup> {
|
||||
self.value_page(data)
|
||||
}
|
||||
// Label the spreadsheet's element button with the inner list's identifier, like Artboard
|
||||
fn value_widgets(&self, target: PathStep, data: &LayoutData) -> Vec<WidgetInstance> {
|
||||
self.0.value_widgets(target, data)
|
||||
}
|
||||
fn value_page(&self, data: &mut LayoutData) -> Vec<LayoutGroup> {
|
||||
self.0.layout_with_breadcrumb(data)
|
||||
}
|
||||
}
|
||||
|
||||
impl TableItemLayout for Coverage {
|
||||
fn type_name() -> &'static str {
|
||||
"Coverage"
|
||||
}
|
||||
fn identifier(&self) -> String {
|
||||
"Coverage".to_string()
|
||||
}
|
||||
// The wrapping row already contributes the breadcrumb; the inner item supplies the next level
|
||||
fn layout_with_breadcrumb(&self, data: &mut LayoutData) -> Vec<LayoutGroup> {
|
||||
self.value_page(data)
|
||||
}
|
||||
fn value_widgets(&self, target: PathStep, data: &LayoutData) -> Vec<WidgetInstance> {
|
||||
self.0.value_widgets(target, data)
|
||||
}
|
||||
fn value_page(&self, data: &mut LayoutData) -> Vec<LayoutGroup> {
|
||||
self.0.layout_with_breadcrumb(data)
|
||||
}
|
||||
}
|
||||
|
||||
impl TableItemLayout for TransferCurve {
|
||||
fn type_name() -> &'static str {
|
||||
"Transfer Curve"
|
||||
}
|
||||
fn identifier(&self) -> String {
|
||||
let points = self.points().len();
|
||||
format!("Transfer Curve ({points} {})", if points == 1 { "point" } else { "points" })
|
||||
}
|
||||
// The wrapping `Item` already contributes the breadcrumb; the inner list supplies the next level
|
||||
fn layout_with_breadcrumb(&self, data: &mut LayoutData) -> Vec<LayoutGroup> {
|
||||
self.value_page(data)
|
||||
}
|
||||
fn value_widgets(&self, target: PathStep, data: &LayoutData) -> Vec<WidgetInstance> {
|
||||
self.0.value_widgets(target, data)
|
||||
}
|
||||
fn value_page(&self, data: &mut LayoutData) -> Vec<LayoutGroup> {
|
||||
self.0.layout_with_breadcrumb(data)
|
||||
}
|
||||
}
|
||||
|
||||
impl TableItemLayout for BoxCorners {
|
||||
fn type_name() -> &'static str {
|
||||
"BoxCorners"
|
||||
@@ -615,41 +537,23 @@ impl TableItemLayout for BoxCorners {
|
||||
}
|
||||
}
|
||||
|
||||
impl TableItemLayout for graphene_std::core_types::none::None {
|
||||
fn type_name() -> &'static str {
|
||||
"None"
|
||||
}
|
||||
fn identifier(&self) -> String {
|
||||
"None".to_string()
|
||||
}
|
||||
fn value_page(&self, _data: &mut LayoutData) -> Vec<LayoutGroup> {
|
||||
label("None")
|
||||
}
|
||||
}
|
||||
|
||||
impl TableItemLayout for Graphic {
|
||||
impl TableItemLayout for Graphic<'_> {
|
||||
fn type_name() -> &'static str {
|
||||
"Graphic"
|
||||
}
|
||||
fn identifier(&self) -> String {
|
||||
match self {
|
||||
Self::None(item) => item.identifier(),
|
||||
Self::Graphic(item) => item.identifier(),
|
||||
Self::Vector(item) => item.identifier(),
|
||||
Self::RasterCPU(item) => item.identifier(),
|
||||
Self::RasterGPU(item) => item.identifier(),
|
||||
Self::Color(item) => item.identifier(),
|
||||
Self::Gradient(item) => item.identifier(),
|
||||
Self::Text(item) => item.identifier(),
|
||||
Self::NoneList(list) => list.identifier(),
|
||||
Self::None => "None".to_string(),
|
||||
Self::Stroke(_) => "Brush Stroke".to_string(),
|
||||
Self::GraphicList(list) => list.identifier(),
|
||||
Self::VectorList(list) => list.identifier(),
|
||||
Self::RasterCPUList(list) => list.identifier(),
|
||||
Self::RasterGPUList(list) => list.identifier(),
|
||||
Self::ColorList(list) => list.identifier(),
|
||||
Self::GradientList(list) => list.identifier(),
|
||||
Self::TextList(list) => list.identifier(),
|
||||
Self::StrokeList(list) => list.identifier(),
|
||||
Self::Vector(list) => list.identifier(),
|
||||
Self::RasterCPU(list) => list.identifier(),
|
||||
Self::RasterGPU(list) => list.identifier(),
|
||||
Self::Color(list) => list.identifier(),
|
||||
Self::Gradient(list) => list.identifier(),
|
||||
Self::Text(list) => list.identifier(),
|
||||
Self::Group(_) => "Group".to_string(),
|
||||
Self::Segmented(_) => "Stack".to_string(),
|
||||
}
|
||||
}
|
||||
// Don't put a breadcrumb for Graphic
|
||||
@@ -658,23 +562,17 @@ impl TableItemLayout for Graphic {
|
||||
}
|
||||
fn value_page(&self, data: &mut LayoutData) -> Vec<LayoutGroup> {
|
||||
match self {
|
||||
Self::None(item) => item.layout_with_breadcrumb(data),
|
||||
Self::Graphic(item) => item.layout_with_breadcrumb(data),
|
||||
Self::Vector(item) => item.layout_with_breadcrumb(data),
|
||||
Self::RasterCPU(item) => item.layout_with_breadcrumb(data),
|
||||
Self::RasterGPU(item) => item.layout_with_breadcrumb(data),
|
||||
Self::Color(item) => item.layout_with_breadcrumb(data),
|
||||
Self::Gradient(item) => item.layout_with_breadcrumb(data),
|
||||
Self::Text(item) => item.layout_with_breadcrumb(data),
|
||||
Self::NoneList(list) => list.layout_with_breadcrumb(data),
|
||||
Self::None => label("None"),
|
||||
Self::Stroke(_) => label("Brush Stroke"),
|
||||
Self::GraphicList(list) => list.layout_with_breadcrumb(data),
|
||||
Self::VectorList(list) => list.layout_with_breadcrumb(data),
|
||||
Self::RasterCPUList(list) => list.layout_with_breadcrumb(data),
|
||||
Self::RasterGPUList(list) => list.layout_with_breadcrumb(data),
|
||||
Self::ColorList(list) => list.layout_with_breadcrumb(data),
|
||||
Self::GradientList(list) => list.layout_with_breadcrumb(data),
|
||||
Self::TextList(list) => list.layout_with_breadcrumb(data),
|
||||
Self::StrokeList(list) => list.layout_with_breadcrumb(data),
|
||||
Self::Vector(list) => list.layout_with_breadcrumb(data),
|
||||
Self::RasterCPU(list) => list.layout_with_breadcrumb(data),
|
||||
Self::RasterGPU(list) => list.layout_with_breadcrumb(data),
|
||||
Self::Color(list) => list.layout_with_breadcrumb(data),
|
||||
Self::Gradient(list) => list.layout_with_breadcrumb(data),
|
||||
Self::Text(list) => list.layout_with_breadcrumb(data),
|
||||
Self::Group(_) => Vec::new(),
|
||||
Self::Segmented(_) => Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -705,6 +603,27 @@ impl TableItemLayout for Vector {
|
||||
|
||||
let mut table_rows = Vec::new();
|
||||
match data.vector_table_tab {
|
||||
VectorTableTab::Points => {
|
||||
table_rows.push(column_headings(&["", "position"]));
|
||||
table_rows.extend(self.point_domain.iter().map(|(id, position)| {
|
||||
let position = DVec2::new(round_away_float_noise(position.x), round_away_float_noise(position.y));
|
||||
vec![
|
||||
TextLabel::new(format!("{}", id.inner())).narrow(true).widget_instance(),
|
||||
TextLabel::new(format!("{position}")).narrow(true).widget_instance(),
|
||||
]
|
||||
}));
|
||||
}
|
||||
VectorTableTab::Segments => {
|
||||
table_rows.push(column_headings(&["", "start_index", "end_index", "handles"]));
|
||||
table_rows.extend(self.segment_domain.iter().map(|(id, start, end, handles)| {
|
||||
vec![
|
||||
TextLabel::new(format!("{}", id.inner())).narrow(true).widget_instance(),
|
||||
TextLabel::new(format!("{start}")).narrow(true).widget_instance(),
|
||||
TextLabel::new(format!("{end}")).narrow(true).widget_instance(),
|
||||
TextLabel::new(format!("{handles:?}")).narrow(true).widget_instance(),
|
||||
]
|
||||
}));
|
||||
}
|
||||
VectorTableTab::Handles => {
|
||||
table_rows.push(column_headings(&["", "colinear_manipulators[0]", "colinear_manipulators[1]"]));
|
||||
table_rows.extend(self.colinear_manipulators.iter().enumerate().map(|(index, [a, b])| {
|
||||
@@ -715,31 +634,6 @@ impl TableItemLayout for Vector {
|
||||
]
|
||||
}));
|
||||
}
|
||||
VectorTableTab::Points => {
|
||||
table_rows.push(column_headings(&["", "position"]));
|
||||
table_rows.extend(self.point_domain.iter().map(|(id, position)| {
|
||||
vec![
|
||||
TextLabel::new(format!("{}", id.inner())).narrow(true).widget_instance(),
|
||||
TextLabel::new(format_dvec2(position)).narrow(true).widget_instance(),
|
||||
]
|
||||
}));
|
||||
}
|
||||
VectorTableTab::Segments => {
|
||||
table_rows.push(column_headings(&["", "start_point", "end_point", "handles"]));
|
||||
table_rows.extend(self.segment_domain.iter().map(|(id, start, end, handles)| {
|
||||
let handles = match handles {
|
||||
BezierHandles::Linear => "Linear".to_string(),
|
||||
BezierHandles::Quadratic { handle } => format!("Quadratic — {}", format_dvec2(handle)),
|
||||
BezierHandles::Cubic { handle_start, handle_end } => format!("Cubic — start: {}, end: {}", format_dvec2(handle_start), format_dvec2(handle_end)),
|
||||
};
|
||||
vec![
|
||||
TextLabel::new(format!("{}", id.inner())).narrow(true).widget_instance(),
|
||||
TextLabel::new(format!("Point {start}")).narrow(true).widget_instance(),
|
||||
TextLabel::new(format!("Point {end}")).narrow(true).widget_instance(),
|
||||
TextLabel::new(handles).narrow(true).widget_instance(),
|
||||
]
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
vec![LayoutGroup::row(table_tabs), LayoutGroup::table(table_rows, false)]
|
||||
@@ -860,32 +754,20 @@ macro_rules! impl_table_item_layout_for_number {
|
||||
}
|
||||
}
|
||||
impl_table_item_layout_for_number!(
|
||||
f32 => "Number (f32)",
|
||||
u32 => "Number (u32)",
|
||||
i32 => "Number (i32)",
|
||||
u64 => "Number (u64)",
|
||||
i64 => "Number (i64)",
|
||||
);
|
||||
|
||||
impl TableItemLayout for f32 {
|
||||
fn type_name() -> &'static str {
|
||||
"Number (f32)"
|
||||
}
|
||||
fn identifier(&self) -> String {
|
||||
// Only infinity widens to f64 without gaining digits, so finite values keep the f32 spelling
|
||||
if self.is_infinite() { format_f64(*self as f64) } else { format!("{self}") }
|
||||
}
|
||||
fn value_widgets(&self, _target: PathStep, _data: &LayoutData) -> Vec<WidgetInstance> {
|
||||
vec![TextLabel::new(self.identifier()).selectable(true).narrow(true).widget_instance()]
|
||||
}
|
||||
}
|
||||
|
||||
// Denoised so 0.1 + 0.2 reads as 0.3 rather than 0.30000000000000004. We don't do this for f32 because it lacks precision to reliably distinguish between intentional digits and noise.
|
||||
impl TableItemLayout for f64 {
|
||||
fn type_name() -> &'static str {
|
||||
"Number"
|
||||
}
|
||||
fn identifier(&self) -> String {
|
||||
format_f64(round_away_float_noise(*self))
|
||||
format!("{}", round_away_float_noise(*self))
|
||||
}
|
||||
fn value_widgets(&self, _target: PathStep, _data: &LayoutData) -> Vec<WidgetInstance> {
|
||||
vec![TextLabel::new(self.identifier()).selectable(true).narrow(true).widget_instance()]
|
||||
@@ -977,7 +859,7 @@ impl TableItemLayout for Option<f64> {
|
||||
}
|
||||
fn value_widgets(&self, _target: PathStep, _data: &LayoutData) -> Vec<WidgetInstance> {
|
||||
let text = match self {
|
||||
Some(value) => format!("Some({})", format_f64(round_away_float_noise(*value))),
|
||||
Some(value) => format!("Some({})", round_away_float_noise(*value)),
|
||||
None => "None".to_string(),
|
||||
};
|
||||
|
||||
@@ -1071,7 +953,6 @@ macro_rules! impl_table_item_layout_for_choice_enum {
|
||||
}
|
||||
impl_table_item_layout_for_choice_enum!(
|
||||
BlendMode,
|
||||
Cover,
|
||||
GradientForm,
|
||||
GradientSpread,
|
||||
GradientSpace,
|
||||
@@ -1080,19 +961,16 @@ impl_table_item_layout_for_choice_enum!(
|
||||
StrokeJoin,
|
||||
StrokeAlign,
|
||||
StrokeCap,
|
||||
PaintOrder,
|
||||
MergeByDistanceAlgorithm,
|
||||
ExtrudeJoiningAlgorithm,
|
||||
PointSpacingType,
|
||||
StringCapitalization,
|
||||
TextDenomination,
|
||||
DesaturateMethod,
|
||||
LuminanceCalculation,
|
||||
RedGreenBlue,
|
||||
RedGreenBlueAlpha,
|
||||
RelativeAbsolute,
|
||||
SelectiveColorChoice,
|
||||
TonalRange,
|
||||
AdjustmentChannel,
|
||||
HueSaturationRange,
|
||||
XY,
|
||||
ScaleType,
|
||||
CentroidType,
|
||||
@@ -1287,12 +1165,8 @@ macro_rules! known_item_types {
|
||||
Raster<GPU>,
|
||||
Graphic,
|
||||
Artboard,
|
||||
Appearance,
|
||||
Coverage,
|
||||
Cover,
|
||||
DashPattern,
|
||||
BoxCorners,
|
||||
TransferCurve,
|
||||
BlendMode,
|
||||
GradientForm,
|
||||
GradientSpread,
|
||||
@@ -1302,19 +1176,16 @@ macro_rules! known_item_types {
|
||||
StrokeJoin,
|
||||
StrokeAlign,
|
||||
StrokeCap,
|
||||
PaintOrder,
|
||||
MergeByDistanceAlgorithm,
|
||||
ExtrudeJoiningAlgorithm,
|
||||
PointSpacingType,
|
||||
StringCapitalization,
|
||||
TextDenomination,
|
||||
DesaturateMethod,
|
||||
LuminanceCalculation,
|
||||
RedGreenBlue,
|
||||
RedGreenBlueAlpha,
|
||||
RelativeAbsolute,
|
||||
SelectiveColorChoice,
|
||||
TonalRange,
|
||||
AdjustmentChannel,
|
||||
HueSaturationRange,
|
||||
XY,
|
||||
ScaleType,
|
||||
ReferencePoint,
|
||||
@@ -1353,10 +1224,6 @@ fn display_value_override(any: &dyn Any) -> Option<String> {
|
||||
/// element-column rendering and attribute-column rendering. Returns `None` for unrecognized
|
||||
/// types so the caller can fall back to a debug-formatted [`TextLabel`].
|
||||
fn dispatch_value_widgets(any: &dyn Any, target: PathStep, data: &LayoutData) -> Option<Vec<WidgetInstance>> {
|
||||
// `NodeIdPath` (e.g. the `editor:layer_path` attribute) drills into its inner path list, matching `drilldown_attribute_layout`.
|
||||
if let Some(path) = any.downcast_ref::<NodeIdPath>() {
|
||||
return Some(path.0.value_widgets(target, data));
|
||||
}
|
||||
macro_rules! check {
|
||||
( $($ty:ty),* $(,)? ) => {
|
||||
$(
|
||||
@@ -1410,13 +1277,18 @@ fn table_node_id_path_layout_with_breadcrumb(path: &List<NodeId>, data: &mut Lay
|
||||
}
|
||||
|
||||
/// Type-dispatched recursion into an attribute value for the Data panel breadcrumb navigation.
|
||||
/// Mirrors [`dispatch_value_widget`] but routes to [`TableItemLayout::layout_with_breadcrumb`].
|
||||
/// Mirrors [`dispatch_value_widgets`] but routes to [`TableItemLayout::layout_with_breadcrumb`].
|
||||
/// Returns `None` for unrecognized types.
|
||||
fn drilldown_attribute_layout(any: &dyn Any, data: &mut LayoutData) -> Option<Vec<LayoutGroup>> {
|
||||
// `NodeIdPath` is interpreted as a path (e.g. the `editor:layer_path` attribute), so each item's NodeId value
|
||||
// resolves against the prefix made up of preceding items. Handled before the generic blanket impl.
|
||||
if let Some(path) = any.downcast_ref::<NodeIdPath>() {
|
||||
return Some(table_node_id_path_layout_with_breadcrumb(&path.0, data));
|
||||
// `List<NodeId>` is interpreted as a path (e.g. the `editor:layer_path` attribute), so each item's NodeId value
|
||||
// resolves against the prefix made up of preceding items. Handled before the generic `List<T>` blanket impl.
|
||||
if let Some(path) = any.downcast_ref::<List<NodeId>>() {
|
||||
return Some(table_node_id_path_layout_with_breadcrumb(path, data));
|
||||
}
|
||||
// The path's plain value form, the layer-path marker's owned shape.
|
||||
if let Some(path) = any.downcast_ref::<Vec<NodeId>>() {
|
||||
let list: List<NodeId> = path.iter().copied().map(graphene_std::list::Item::new_from_element).collect();
|
||||
return Some(table_node_id_path_layout_with_breadcrumb(&list, data));
|
||||
}
|
||||
macro_rules! check {
|
||||
( $($ty:ty),* $(,)? ) => {
|
||||
|
||||
@@ -5,7 +5,6 @@ use document_graph_storage::Registry;
|
||||
use graph_craft::application_io::resource::{ResourceId, ResourceRegistry, ResourceStorage};
|
||||
|
||||
use super::utility_types::network_interface::NodeNetworkInterface;
|
||||
use super::utility_types::network_interface::editor_delta::{EditorDelta, construct_batch};
|
||||
use super::utility_types::network_interface::storage_metadata::{StorageMetadataView, collect_network_view_settings};
|
||||
|
||||
/// Per-document undo/redo state: the legacy snapshot stacks plus the `Gdd` working-copy cursor that is
|
||||
@@ -102,7 +101,6 @@ impl DocumentHistory {
|
||||
/// round-trip check, off by default for its perf cost.
|
||||
pub fn stage_snapshot(
|
||||
&mut self,
|
||||
deltas: &[EditorDelta],
|
||||
interface: &NodeNetworkInterface,
|
||||
registry: &ResourceRegistry,
|
||||
view_settings: BTreeMap<String, serde_json::Value>,
|
||||
@@ -111,68 +109,21 @@ impl DocumentHistory {
|
||||
) {
|
||||
let Some(storage) = self.storage.as_mut() else { return };
|
||||
|
||||
// A working copy that does not hold the document yet has no baseline for a batch of changes to
|
||||
// apply to, so the first commit writes the whole document and every later one stages only what
|
||||
// the store recorded. Reading that from the working copy rather than from the caller means a path
|
||||
// that mounts storage and then commits does not have to know which of the two it is.
|
||||
let staged = match storage.registry().node_instances.is_empty() {
|
||||
true => Self::stage_whole_document(storage, interface, registry, byte_store),
|
||||
// An autosave with nothing edited since the last commit still persists the view state below.
|
||||
false if deltas.is_empty() => Ok(()),
|
||||
false => Self::stage_recorded(storage, deltas, interface, registry, byte_store),
|
||||
};
|
||||
if let Err(error) = staged {
|
||||
let network = interface.document_network();
|
||||
let metadata_view = StorageMetadataView::new(interface);
|
||||
|
||||
let network_view_settings = storage
|
||||
.network_ids(network, &metadata_view)
|
||||
.ok()
|
||||
.map(|network_ids| collect_network_view_settings(interface, &network_ids));
|
||||
|
||||
// Stage without retiring: a tool drag fires several `CommitTransaction`s but is one legacy undo
|
||||
// step, so the deltas accumulate as hot ops and coalesce at the next undo-step boundary.
|
||||
if let Err(error) = storage.stage_runtime_snapshot(network, &metadata_view, registry, byte_store) {
|
||||
log::error!("Storage snapshot staging failed: {error}");
|
||||
return;
|
||||
}
|
||||
|
||||
self.persist_view_state(interface, view_settings, legacy_document);
|
||||
}
|
||||
|
||||
/// Converts the whole document and stages the difference from what the working copy holds.
|
||||
///
|
||||
/// Stages without retiring: a tool drag fires several `CommitTransaction`s but is one legacy undo
|
||||
/// step, so the ops accumulate in the hot log and coalesce at the next undo-step boundary.
|
||||
fn stage_whole_document(storage: &mut document_format::GddV1, interface: &NodeNetworkInterface, registry: &ResourceRegistry, byte_store: &dyn ResourceStorage) -> Result<(), String> {
|
||||
let metadata_view = StorageMetadataView::new(interface);
|
||||
storage
|
||||
.stage_runtime_snapshot(interface.document_network(), &metadata_view, registry, byte_store)
|
||||
.map_err(|error| error.to_string())
|
||||
}
|
||||
|
||||
/// Stages what the store recorded since the last drain.
|
||||
///
|
||||
/// This and the whole-document conversion produce the same registry for the same edit, which
|
||||
/// `verify_round_trip` checks when the `validate_storage_round_trip` preference is on. They differ in
|
||||
/// what they cost and in what they can miss: a conversion sees every change however it was made,
|
||||
/// while this sees only what went through the store, so a write that bypasses it is not persisted.
|
||||
fn stage_recorded(
|
||||
storage: &mut document_format::GddV1,
|
||||
deltas: &[EditorDelta],
|
||||
interface: &NodeNetworkInterface,
|
||||
registry: &ResourceRegistry,
|
||||
byte_store: &dyn ResourceStorage,
|
||||
) -> Result<(), String> {
|
||||
let peer = storage.session().peer();
|
||||
let metadata_view = StorageMetadataView::new(interface);
|
||||
let constructed = construct_batch(deltas, storage.registry(), registry, &metadata_view, peer).map_err(|error| error.to_string())?;
|
||||
|
||||
storage
|
||||
.stage_constructed_ops(constructed.ops, &constructed.declaration_bytes, byte_store)
|
||||
.map_err(|error| error.to_string())
|
||||
}
|
||||
|
||||
/// The parts of a commit that are not the graph: the per-peer view settings, and the legacy bytes the
|
||||
/// dual-write soak validates the new format against. Both staging paths persist them; they differ
|
||||
/// only in how the graph ops are derived.
|
||||
fn persist_view_state(&mut self, interface: &NodeNetworkInterface, view_settings: BTreeMap<String, serde_json::Value>, legacy_document: &str) {
|
||||
let Some(storage) = self.storage.as_mut() else { return };
|
||||
|
||||
let network_view_settings = storage
|
||||
.network_ids(interface.document_network(), &StorageMetadataView::new(interface))
|
||||
.ok()
|
||||
.map(|network_ids| collect_network_view_settings(interface, &network_ids));
|
||||
|
||||
if let Err(error) = storage.set_view_settings(view_settings) {
|
||||
log::error!("Persisting view settings failed: {error}");
|
||||
}
|
||||
@@ -183,6 +134,8 @@ impl DocumentHistory {
|
||||
log::error!("Persisting per-network view settings failed: {error}");
|
||||
}
|
||||
|
||||
// Dual-write soak: embed the legacy `.graphite` bytes so the new format
|
||||
// can be validated against (and recovered from) the old one on open.
|
||||
if let Err(error) = storage.store_legacy_document(legacy_document.as_bytes()) {
|
||||
log::error!("Embedding legacy document into working copy failed: {error}");
|
||||
}
|
||||
|
||||
@@ -9,10 +9,12 @@ use crate::messages::portfolio::document::utility_types::document_metadata::Laye
|
||||
use crate::messages::portfolio::document::utility_types::misc::{AlignAggregate, AlignAxis, FlipAxis, GridSnapping};
|
||||
use crate::messages::portfolio::utility_types::PanelType;
|
||||
use crate::messages::prelude::*;
|
||||
use glam::{DAffine2, IVec2, UVec2};
|
||||
use glam::{DAffine2, IVec2};
|
||||
use graph_craft::document::NodeId;
|
||||
use graphene_std::Appearance;
|
||||
use graphene_std::Color;
|
||||
use graphene_std::raster::BlendMode;
|
||||
use graphene_std::raster::Image;
|
||||
use graphene_std::transform::Footprint;
|
||||
use graphene_std::vector::Vector;
|
||||
use graphene_std::vector::click_target::ClickTarget;
|
||||
@@ -115,8 +117,7 @@ pub enum DocumentMessage {
|
||||
},
|
||||
InsertImage {
|
||||
name: Option<String>,
|
||||
data: Arc<[u8]>,
|
||||
size: UVec2,
|
||||
image: Image<Color>,
|
||||
mouse: Option<(f64, f64)>,
|
||||
parent_and_insert_index: Option<(LayerNodeIdentifier, usize)>,
|
||||
/// When true (file-open flow), place the image at the document origin so `WrapContentInArtboard`
|
||||
|
||||
@@ -35,9 +35,9 @@ use crate::node_graph_executor::NodeGraphExecutor;
|
||||
use glam::{DAffine2, DVec2};
|
||||
use graph_craft::application_io::resource::ResourceId;
|
||||
use graph_craft::application_io::wgpu_available;
|
||||
use graph_craft::descriptor;
|
||||
use graph_craft::document::value::TaggedValue;
|
||||
use graph_craft::document::{NodeId, NodeInput, NodeNetwork, OldNodeNetwork};
|
||||
use graph_craft::list;
|
||||
use graphene_std::Cover;
|
||||
use graphene_std::math::quad::Quad;
|
||||
use graphene_std::path_bool_nodes::boolean_intersect;
|
||||
@@ -249,7 +249,6 @@ impl MessageHandler<DocumentMessage, DocumentMessageContext<'_>> for DocumentMes
|
||||
DocumentMessage::PropertiesPanel(message) => {
|
||||
let context = PropertiesPanelMessageContext {
|
||||
executor,
|
||||
document_id,
|
||||
network_interface: &mut self.network_interface,
|
||||
resources: &self.resources,
|
||||
selection_network_path: &self.selection_network_path,
|
||||
@@ -798,14 +797,15 @@ impl MessageHandler<DocumentMessage, DocumentMessageContext<'_>> for DocumentMes
|
||||
}
|
||||
DocumentMessage::InsertImage {
|
||||
name,
|
||||
data,
|
||||
size,
|
||||
image,
|
||||
mouse,
|
||||
parent_and_insert_index,
|
||||
place_at_origin,
|
||||
} => {
|
||||
// All the image's pixels have been converted to 0..=1, linear, and premultiplied by `Color::from_rgba8_srgb`
|
||||
|
||||
let layer_parent = self.new_layer_parent(true);
|
||||
let image_size = size.as_dvec2();
|
||||
let image_size = DVec2::new(image.width as f64, image.height as f64);
|
||||
|
||||
let mut transform = if place_at_origin {
|
||||
// File-open flow: place at document origin without centering so `WrapContentInArtboard` can wrap it
|
||||
@@ -813,7 +813,7 @@ impl MessageHandler<DocumentMessage, DocumentMessageContext<'_>> for DocumentMes
|
||||
} else {
|
||||
// Clipboard paste or drag-drop: center at cursor or viewport center.
|
||||
// Convert the document-space cursor to the parent's local coordinate space so that
|
||||
// an artboard at a nonzero position does not offset the placement.
|
||||
// an artboard at a non-zero position does not offset the placement.
|
||||
let parent_to_document = {
|
||||
let metadata = self.metadata();
|
||||
metadata.document_to_viewport.inverse() * metadata.transform_to_viewport(layer_parent)
|
||||
@@ -828,7 +828,7 @@ impl MessageHandler<DocumentMessage, DocumentMessageContext<'_>> for DocumentMes
|
||||
|
||||
responses.add(DocumentMessage::StartTransaction);
|
||||
|
||||
let layer = graph_modification_utils::new_image_layer(data, layer_node_id, layer_parent, responses);
|
||||
let layer = graph_modification_utils::new_image_layer(image, layer_node_id, layer_parent, responses);
|
||||
|
||||
if let Some(name) = name {
|
||||
responses.add(NodeGraphMessage::SetDisplayName {
|
||||
@@ -876,7 +876,7 @@ impl MessageHandler<DocumentMessage, DocumentMessageContext<'_>> for DocumentMes
|
||||
} else {
|
||||
// Clipboard paste or drag-drop: center at cursor or viewport center.
|
||||
// Convert the document-space cursor to the parent's local coordinate space so that
|
||||
// an artboard at a nonzero position does not offset the placement.
|
||||
// an artboard at a non-zero position does not offset the placement.
|
||||
let parent_to_document = {
|
||||
let metadata = self.metadata();
|
||||
metadata.document_to_viewport.inverse() * metadata.transform_to_viewport(layer_parent)
|
||||
@@ -1100,7 +1100,6 @@ impl MessageHandler<DocumentMessage, DocumentMessageContext<'_>> for DocumentMes
|
||||
filters: vec![FileFilter {
|
||||
name: "Graphite Document".into(),
|
||||
extensions: vec![extension.into()],
|
||||
mime_types: Vec::new(),
|
||||
}],
|
||||
content: content.into(),
|
||||
})
|
||||
@@ -1902,8 +1901,8 @@ impl DocumentMessageHandler {
|
||||
|
||||
layer_click_targets.is_some_and(|targets| {
|
||||
targets.iter().all(|target| match target.target_type() {
|
||||
ClickTargetType::Path(path) => {
|
||||
let mut path = path.clone();
|
||||
ClickTargetType::Path(_) | ClickTargetType::Instance { .. } => {
|
||||
let mut path = target.path_in_layer().map(|path| path.into_owned()).unwrap_or_default();
|
||||
path.apply_affine(Affine::new(layer_transform.to_cols_array()));
|
||||
bezpath_is_inside_bezpath(&path, &viewport_polygon, None, None)
|
||||
}
|
||||
@@ -2026,30 +2025,14 @@ impl DocumentMessageHandler {
|
||||
self.history.retire_storage_interaction();
|
||||
}
|
||||
|
||||
/// Stages what the store recorded since the last commit into the `Gdd` working copy.
|
||||
///
|
||||
/// The batch boundary: everything the interface recorded since the last one is this commit's batch.
|
||||
/// Draining happens whether or not a working copy is mounted, so the buffer cannot grow across a
|
||||
/// session that never mounts one.
|
||||
/// Stages the runtime network into the `Gdd` working copy.
|
||||
pub fn commit_storage_snapshot(&mut self, byte_store: &dyn graph_craft::application_io::resource::ResourceStorage, validate: bool) {
|
||||
let deltas = self.network_interface.take_deltas();
|
||||
use crate::messages::portfolio::document::utility_types::network_interface::storage_metadata::DocumentSettings;
|
||||
|
||||
if self.history.storage().is_none() {
|
||||
return;
|
||||
}
|
||||
|
||||
let (view_settings, legacy_document) = self.storage_side_channels();
|
||||
self.history
|
||||
.stage_snapshot(&deltas, &self.network_interface, &self.resources.registry, view_settings, legacy_document.as_str(), byte_store);
|
||||
|
||||
if validate {
|
||||
self.history.verify_round_trip(&self.network_interface, &self.resources.registry);
|
||||
}
|
||||
}
|
||||
|
||||
/// The per-peer view settings and legacy bytes that ride along with either kind of staging.
|
||||
fn storage_side_channels(&self) -> (std::collections::BTreeMap<String, serde_json::Value>, String) {
|
||||
use crate::messages::portfolio::document::utility_types::network_interface::storage_metadata::DocumentSettings;
|
||||
|
||||
let view_settings = DocumentSettings {
|
||||
document_ptz: &self.document_ptz,
|
||||
render_mode: &self.render_mode,
|
||||
@@ -2060,7 +2043,14 @@ impl DocumentMessageHandler {
|
||||
}
|
||||
.to_view_map();
|
||||
|
||||
(view_settings, self.serialize_document())
|
||||
let legacy_document = self.serialize_document();
|
||||
|
||||
self.history
|
||||
.stage_snapshot(&self.network_interface, &self.resources.registry, view_settings, legacy_document.as_str(), byte_store);
|
||||
|
||||
if validate {
|
||||
self.history.verify_round_trip(&self.network_interface, &self.resources.registry);
|
||||
}
|
||||
}
|
||||
|
||||
/// Restore `view_settings` map into the document.
|
||||
@@ -2774,7 +2764,7 @@ impl DocumentMessageHandler {
|
||||
}
|
||||
|
||||
let solidify_stroke_definition = document_node_definitions::resolve_proto_node_type(graphene_std::vector::solidify_stroke::IDENTIFIER).expect("Solidify Stroke node should exist");
|
||||
let item_at_index_definition = document_node_definitions::resolve_proto_node_type(graphene_std::graphic::item_at_index::IDENTIFIER).expect("Item at Index node should exist");
|
||||
let item_at_index_definition = document_node_definitions::resolve_proto_node_type(graphene_std::list::item_at_index::IDENTIFIER).expect("Item at Index node should exist");
|
||||
|
||||
let mut resulting_layers: Vec<NodeId> = Vec::new();
|
||||
|
||||
@@ -2787,10 +2777,10 @@ impl DocumentMessageHandler {
|
||||
let appearance = self.network_interface.document_metadata().layer_appearance_attributes.get(&layer);
|
||||
|
||||
let has_fill = appearance.is_some_and(|appearance| appearance.has_painted_cover(Cover::Fill));
|
||||
// A visible stroke needs both renderable geometry (nonzero weight) and paint that draws something
|
||||
// A visible stroke needs both renderable geometry (non-zero weight) and paint that draws something
|
||||
let has_stroke = appearance.is_some_and(|appearance| {
|
||||
appearance.first_coverage_of(Cover::Stroke).is_some_and(|coverage| coverage.stroke_params().has_renderable_stroke())
|
||||
&& appearance.first_paint_of(Cover::Stroke).is_some_and(|paint| !paint.is_guaranteed_fully_transparent())
|
||||
&& appearance.first_paint_of(Cover::Stroke).is_some_and(|paint| !paint.is_fully_transparent())
|
||||
});
|
||||
|
||||
// No stroke means there's nothing to solidify. Fill-only layers are already in the desired form, so skip.
|
||||
@@ -3549,7 +3539,7 @@ impl DocumentMessageHandler {
|
||||
})
|
||||
.on_commit(|_| DocumentMessage::AddTransaction.into())
|
||||
.max_width(100)
|
||||
.tooltip_label("Fill Opacity")
|
||||
.tooltip_label("Fill")
|
||||
.widget_instance(),
|
||||
];
|
||||
let layers_panel_control_bar_left = Layout(vec![LayoutGroup::row(widgets)]);
|
||||
@@ -3760,7 +3750,7 @@ impl DocumentMessageHandler {
|
||||
let first_or_last_selected_layer = match relative_index_offset.signum() {
|
||||
-1 => selected_layers.next(),
|
||||
1 => selected_layers.last(),
|
||||
_ => panic!("selected_layers_reorder() must be given a nonzero value"),
|
||||
_ => panic!("selected_layers_reorder() must be given a non-zero value"),
|
||||
};
|
||||
|
||||
let Some(pivot_layer) = first_or_last_selected_layer else {
|
||||
@@ -3810,7 +3800,7 @@ impl DocumentMessageHandler {
|
||||
/// Create a network interface with a single export
|
||||
fn default_document_network_interface() -> NodeNetworkInterface {
|
||||
let mut network_interface = NodeNetworkInterface::default();
|
||||
network_interface.add_export(TaggedValue::TypeDefault(list!(graphene_std::Artboard)), -1, "", &[]);
|
||||
network_interface.add_export(TaggedValue::TypeDefault(descriptor!(graphene_std::list::List<graphene_std::Artboard>)), -1, "", &[]);
|
||||
network_interface
|
||||
}
|
||||
|
||||
@@ -3842,8 +3832,8 @@ fn quad_to_kurbo(quad: Quad) -> BezPath {
|
||||
|
||||
fn click_targets_to_kurbo<'a>(click_targets: impl Iterator<Item = &'a ClickTarget>, transform: DAffine2) -> BezPath {
|
||||
let segments = click_targets
|
||||
.filter_map(|target| if let ClickTargetType::Path(path) = target.target_type() { Some(path.segments()) } else { None })
|
||||
.flatten()
|
||||
.filter_map(|target| target.path_in_layer().map(|path| path.into_owned()))
|
||||
.flat_map(|path| path.segments().collect::<Vec<_>>())
|
||||
.map(|bezier| Affine::new(transform.to_cols_array()) * bezier);
|
||||
BezPath::from_path_segments(segments)
|
||||
}
|
||||
@@ -4174,7 +4164,7 @@ mod document_message_handler_tests {
|
||||
.await;
|
||||
|
||||
// The operation completed without crashing
|
||||
// Verifying application still functions by performing another operation
|
||||
// Verifying application still functions by performing another operation, which panics if the folder move left the editor broken
|
||||
editor.handle_message(DocumentMessage::CreateEmptyFolder).await;
|
||||
}
|
||||
|
||||
@@ -4345,22 +4335,23 @@ mod document_message_handler_tests {
|
||||
|
||||
let instrumented = editor.eval_graph().await.unwrap();
|
||||
|
||||
// The emptiness guards keep these assertions honest: a wrong `Output` type on `grab_all_input` yields no records at all, which would otherwise pass without checking anything
|
||||
// An empty stack base is never served: `Extend` maps no lane onto it, so the monitor records nothing rather than an empty list.
|
||||
// A base that wrongly carried a phantom element would therefore show up as a recorded row, which this catches.
|
||||
// The `news` guard below is what keeps both assertions honest, since a wrong `Output` type empties every record.
|
||||
let base_lengths: Vec<usize> = instrumented
|
||||
.grab_all_input::<graphene_std::graphic::extend::BaseInput, graphene_std::list::List<graphene_std::Graphic>>(&editor.runtime)
|
||||
.grab_all_input::<graphene_std::list::extend::BaseInput, graphene_std::list::List<graphene_std::Graphic>>(&editor.runtime)
|
||||
.map(|base| base.len())
|
||||
.collect();
|
||||
assert!(!base_lengths.is_empty(), "Instrumentation should have recorded at least one stack base");
|
||||
assert!(base_lengths.iter().all(|&len| len == 0), "Every stack base should be empty, found lengths {base_lengths:?}");
|
||||
|
||||
let news: Vec<graphene_std::list::List<graphene_std::Graphic>> = instrumented
|
||||
.grab_all_input::<graphene_std::graphic::extend::NewInput, graphene_std::list::List<graphene_std::Graphic>>(&editor.runtime)
|
||||
.grab_all_input::<graphene_std::list::extend::NewInput, graphene_std::list::List<graphene_std::Graphic>>(&editor.runtime)
|
||||
.collect();
|
||||
assert!(!news.is_empty(), "Instrumentation should have recorded at least one stacked element list");
|
||||
let phantom_count = news
|
||||
.iter()
|
||||
.flat_map(|new| new.iter_element_values())
|
||||
.filter(|graphic| matches!(graphic, graphene_std::Graphic::None(_)))
|
||||
.filter(|graphic| matches!(graphic, graphene_std::Graphic::None))
|
||||
.count();
|
||||
assert_eq!(phantom_count, 0, "No stacked element should be a phantom None graphic");
|
||||
}
|
||||
|
||||
@@ -6,10 +6,10 @@ use glam::{DAffine2, DVec2};
|
||||
use graph_craft::document::NodeId;
|
||||
use graphene_std::Color;
|
||||
use graphene_std::raster::BlendMode;
|
||||
use graphene_std::raster_types::Image;
|
||||
use graphene_std::text::{Font, TypesettingConfig};
|
||||
use graphene_std::vector::style::{GradientForm, GradientHueDirection, GradientInterpolation, GradientSettings, GradientSpace, GradientSpread, PaintOrder, Stroke};
|
||||
use graphene_std::vector::{Gradient, VectorModificationType};
|
||||
use std::sync::Arc;
|
||||
|
||||
#[impl_message(Message, DocumentMessage, GraphOperation)]
|
||||
#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize)]
|
||||
@@ -91,7 +91,7 @@ pub enum GraphOperationMessage {
|
||||
color: Option<Color>,
|
||||
stroke: Stroke,
|
||||
},
|
||||
StrokeOrderSet {
|
||||
StrokePaintOrderSet {
|
||||
layer: LayerNodeIdentifier,
|
||||
paint_order: PaintOrder,
|
||||
},
|
||||
@@ -141,7 +141,7 @@ pub enum GraphOperationMessage {
|
||||
},
|
||||
NewBitmapLayer {
|
||||
id: NodeId,
|
||||
data: Arc<[u8]>,
|
||||
image: Image<Color>,
|
||||
parent: LayerNodeIdentifier,
|
||||
insert_index: usize,
|
||||
},
|
||||
|
||||
+12
-89
@@ -1,17 +1,18 @@
|
||||
use super::transform_utils;
|
||||
use super::utility_types::{ModifyInputsContext, set_stroke_paint_order};
|
||||
use super::utility_types::ModifyInputsContext;
|
||||
use crate::consts::{LAYER_INDENT_OFFSET, STACK_VERTICAL_GAP};
|
||||
use crate::messages::portfolio::document::graph_operation::utility_types::TransformIn;
|
||||
use crate::messages::portfolio::document::node_graph::document_node_definitions::{BLEND_PATH_INPUT_INDEX, DefinitionIdentifier, resolve_proto_node_type};
|
||||
use crate::messages::portfolio::document::node_graph::document_node_definitions::{BLEND_PATH_INPUT_INDEX, resolve_proto_node_type};
|
||||
use crate::messages::portfolio::document::utility_types::document_metadata::LayerNodeIdentifier;
|
||||
use crate::messages::portfolio::document::utility_types::network_interface::{InputConnector, NodeNetworkInterface, OutputConnector};
|
||||
use crate::messages::portfolio::document::utility_types::nodes::CollapsedLayers;
|
||||
use crate::messages::prelude::*;
|
||||
use crate::messages::tool::common_functionality::graph_modification_utils::get_clip_mode;
|
||||
use glam::{DAffine2, DVec2, IVec2};
|
||||
use graph_craft::descriptor;
|
||||
use graph_craft::document::value::TaggedValue;
|
||||
use graph_craft::document::{NodeId, NodeInput};
|
||||
use graph_craft::list;
|
||||
use graphene_std::list::List;
|
||||
use graphene_std::renderer::convert_usvg_path::convert_usvg_path;
|
||||
use graphene_std::text::{Font, TypesettingConfig};
|
||||
use graphene_std::vector::style::{Gradient, GradientForm, GradientSettings, GradientSpace, GradientSpread, GradientStop, Stroke, StrokeAlign, StrokeCap, StrokeJoin};
|
||||
@@ -132,15 +133,12 @@ impl MessageHandler<GraphOperationMessage, GraphOperationMessageContext<'_>> for
|
||||
modify_inputs.stroke_set(color, stroke);
|
||||
}
|
||||
}
|
||||
GraphOperationMessage::StrokeOrderSet { layer, paint_order } => {
|
||||
let stroke_reference = DefinitionIdentifier::ProtoNode(graphene_std::vector::stroke::IDENTIFIER);
|
||||
let Some(stroke_node_id) = ModifyInputsContext::locate_node_in_layer_chain(&stroke_reference, layer, network_interface) else {
|
||||
return;
|
||||
};
|
||||
if set_stroke_paint_order(network_interface, &[], stroke_node_id, paint_order) {
|
||||
GraphOperationMessage::StrokePaintOrderSet { layer, paint_order } => {
|
||||
if let Some(stroke_node_id) = crate::messages::tool::common_functionality::graph_modification_utils::get_stroke_id(layer, network_interface)
|
||||
&& super::utility_types::set_stroke_paint_order(network_interface, &[], stroke_node_id, paint_order)
|
||||
{
|
||||
responses.add(PropertiesPanelMessage::Refresh);
|
||||
responses.add(NodeGraphMessage::RunDocumentGraph);
|
||||
responses.add(NodeGraphMessage::SendGraph);
|
||||
}
|
||||
}
|
||||
GraphOperationMessage::TransformChange {
|
||||
@@ -252,7 +250,7 @@ impl MessageHandler<GraphOperationMessage, GraphOperationMessageContext<'_>> for
|
||||
}
|
||||
|
||||
// Set the bottom input of the artboard back to artboard
|
||||
let bottom_input = NodeInput::type_default(list!(Artboard), true);
|
||||
let bottom_input = NodeInput::type_default(descriptor!(List<Artboard>), true);
|
||||
network_interface.set_input(&InputConnector::primary_input(artboard_layer.to_node()), bottom_input, &[]);
|
||||
} else {
|
||||
// We have some non layers (e.g. just a rectangle node). We disconnect the bottom input and connect it to the left input.
|
||||
@@ -260,17 +258,17 @@ impl MessageHandler<GraphOperationMessage, GraphOperationMessageContext<'_>> for
|
||||
network_interface.set_input(&InputConnector::layer_secondary_input(artboard_layer.to_node()), primary_input, &[]);
|
||||
|
||||
// Set the bottom input of the artboard back to artboard
|
||||
let bottom_input = NodeInput::type_default(list!(Artboard), true);
|
||||
let bottom_input = NodeInput::type_default(descriptor!(List<Artboard>), true);
|
||||
network_interface.set_input(&InputConnector::primary_input(artboard_layer.to_node()), bottom_input, &[]);
|
||||
}
|
||||
}
|
||||
responses.add_front(NodeGraphMessage::SelectedNodesSet { nodes: vec![id] });
|
||||
responses.add(NodeGraphMessage::RunDocumentGraph);
|
||||
}
|
||||
GraphOperationMessage::NewBitmapLayer { id, data, parent, insert_index } => {
|
||||
GraphOperationMessage::NewBitmapLayer { id, image, parent, insert_index } => {
|
||||
let mut modify_inputs = ModifyInputsContext::new(network_interface, responses);
|
||||
let layer = modify_inputs.create_layer(id);
|
||||
modify_inputs.insert_image_data(data, layer);
|
||||
modify_inputs.insert_image_data(image, layer);
|
||||
network_interface.move_layer_to_stack(layer, parent, insert_index, &[]);
|
||||
responses.add(NodeGraphMessage::RunDocumentGraph);
|
||||
}
|
||||
@@ -1071,81 +1069,6 @@ fn apply_usvg_fill(fill: &usvg::Fill, modify_inputs: &mut ModifyInputsContext, g
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[tokio::test]
|
||||
async fn stroke_order_set_reorders_the_fill_and_stroke_nodes() {
|
||||
use crate::messages::tool::common_functionality::graph_modification_utils::get_stroke_paint_order;
|
||||
use crate::test_utils::test_prelude::*;
|
||||
use graphene_std::vector::style::PaintOrder;
|
||||
|
||||
let mut editor = EditorTestUtils::create();
|
||||
editor.new_document().await;
|
||||
editor.drag_tool(ToolType::Rectangle, 0., 0., 100., 100., ModifierKeys::empty()).await;
|
||||
|
||||
let document = editor.active_document();
|
||||
let layer = document.metadata().all_layers().next().unwrap();
|
||||
let paint_order = get_stroke_paint_order(layer, &document.network_interface);
|
||||
assert_eq!(paint_order, PaintOrder::StrokeAbove, "a fresh shape should stroke above its fill");
|
||||
|
||||
editor
|
||||
.handle_message(GraphOperationMessage::StrokeOrderSet {
|
||||
layer,
|
||||
paint_order: PaintOrder::StrokeBelow,
|
||||
})
|
||||
.await;
|
||||
let paint_order = get_stroke_paint_order(layer, &editor.active_document().network_interface);
|
||||
assert_eq!(paint_order, PaintOrder::StrokeBelow, "the rewrite should move the stroke downstream of the fill");
|
||||
|
||||
editor
|
||||
.handle_message(GraphOperationMessage::StrokeOrderSet {
|
||||
layer,
|
||||
paint_order: PaintOrder::StrokeAbove,
|
||||
})
|
||||
.await;
|
||||
let paint_order = get_stroke_paint_order(layer, &editor.active_document().network_interface);
|
||||
assert_eq!(paint_order, PaintOrder::StrokeAbove, "the rewrite should move the stroke back upstream of the fill");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn a_node_inserted_between_the_fill_and_stroke_makes_the_order_swap_inapplicable() {
|
||||
use crate::messages::portfolio::document::node_graph::document_node_definitions::resolve_proto_node_type;
|
||||
use crate::messages::tool::common_functionality::graph_modification_utils::stroke_paint_order_applicable;
|
||||
use crate::test_utils::test_prelude::*;
|
||||
|
||||
let mut editor = EditorTestUtils::create();
|
||||
editor.new_document().await;
|
||||
editor.drag_tool(ToolType::Rectangle, 0., 0., 100., 100., ModifierKeys::empty()).await;
|
||||
|
||||
let layer = editor.active_document().metadata().all_layers().next().unwrap();
|
||||
assert!(
|
||||
stroke_paint_order_applicable(layer, &editor.active_document().network_interface),
|
||||
"a fresh shape's adjacent Fill and Stroke pair should be swappable"
|
||||
);
|
||||
|
||||
let stroke_reference = DefinitionIdentifier::ProtoNode(graphene_std::vector::stroke::IDENTIFIER);
|
||||
let stroke_node_id = ModifyInputsContext::locate_node_in_layer_chain(&stroke_reference, layer, &editor.active_document().network_interface).unwrap();
|
||||
|
||||
let node_template = Box::new(resolve_proto_node_type(graphene_std::ops::passthrough::IDENTIFIER).unwrap().default_node_template());
|
||||
let passthrough_node_id = NodeId::new();
|
||||
editor
|
||||
.handle_message(NodeGraphMessage::InsertNode {
|
||||
node_id: passthrough_node_id,
|
||||
node_template,
|
||||
})
|
||||
.await;
|
||||
editor
|
||||
.handle_message(NodeGraphMessage::InsertNodeBetween {
|
||||
node_id: passthrough_node_id,
|
||||
input_connector: InputConnector::node_at_index(stroke_node_id, 0),
|
||||
insert_node_input_index: 0,
|
||||
})
|
||||
.await;
|
||||
|
||||
assert!(
|
||||
!stroke_paint_order_applicable(layer, &editor.active_document().network_interface),
|
||||
"a node between the pair should gray the order radio out"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn color_interpolation_resolves_per_gradient_with_inheritance_and_style_priority() {
|
||||
let svg = r##"<svg xmlns="http://www.w3.org/2000/svg" color-interpolation="linearRGB">
|
||||
|
||||
@@ -12,14 +12,15 @@ use glam::{DAffine2, DVec2, IVec2};
|
||||
use graph_craft::application_io::resource::ResourceId;
|
||||
use graph_craft::document::value::TaggedValue;
|
||||
use graph_craft::document::{NodeId, NodeInput};
|
||||
use graph_craft::{ProtoNodeIdentifier, list};
|
||||
use graph_craft::{ProtoNodeIdentifier, concrete, descriptor};
|
||||
use graphene_std::list::List;
|
||||
use graphene_std::raster::BlendMode;
|
||||
use graphene_std::raster_types::Image;
|
||||
use graphene_std::text::{Font, TypesettingConfig};
|
||||
use graphene_std::vector::style::{GradientForm, GradientHueDirection, GradientInterpolation, GradientSettings, GradientSpace, GradientSpread, PaintOrder, Stroke};
|
||||
use graphene_std::vector::{Gradient, GradientRamp, Vector, VectorModification, VectorModificationType};
|
||||
use graphene_std::{Artboard, Color, Graphic};
|
||||
use kurbo::BezPath;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(PartialEq, Clone, Copy, Debug, serde::Serialize, serde::Deserialize)]
|
||||
pub enum TransformIn {
|
||||
@@ -70,8 +71,8 @@ impl<'a> ModifyInputsContext<'a> {
|
||||
/// Creates an artboard as the primary export for the document network.
|
||||
pub fn create_artboard(&mut self, new_id: NodeId, location: DVec2, dimensions: DVec2, background: Color, clip: bool) -> LayerNodeIdentifier {
|
||||
let artboard_node_template = resolve_network_node_type("Artboard").expect("Node").node_template_input_override([
|
||||
Some(NodeInput::type_default(list!(Artboard), true)),
|
||||
Some(NodeInput::type_default(list!(Graphic), true)),
|
||||
Some(NodeInput::type_default(descriptor!(List<Artboard>), true)),
|
||||
Some(NodeInput::type_default(descriptor!(List<Graphic>), true)),
|
||||
Some(NodeInput::value(TaggedValue::DVec2(location), false)),
|
||||
Some(NodeInput::value(TaggedValue::DVec2(dimensions), false)),
|
||||
Some(NodeInput::value(TaggedValue::Color(background), false)),
|
||||
@@ -85,7 +86,7 @@ impl<'a> ModifyInputsContext<'a> {
|
||||
let boolean = resolve_proto_node_type(graphene_std::path_bool_nodes::boolean_operation::IDENTIFIER)
|
||||
.expect("Boolean node does not exist")
|
||||
.node_template_input_override([
|
||||
Some(NodeInput::type_default(list!(Graphic), true)),
|
||||
Some(NodeInput::type_default(descriptor!(List<Graphic>), true)),
|
||||
Some(NodeInput::value(TaggedValue::BooleanOperation(operation), false)),
|
||||
]);
|
||||
|
||||
@@ -97,7 +98,7 @@ impl<'a> ModifyInputsContext<'a> {
|
||||
pub fn insert_blend_data(&mut self, layer: LayerNodeIdentifier, count: f64) -> NodeId {
|
||||
let blend = resolve_network_node_type("Blend")
|
||||
.expect("Blend node does not exist")
|
||||
.node_template_input_override([Some(NodeInput::type_default(list!(Graphic), true)), Some(NodeInput::value(TaggedValue::F64(count), false))]);
|
||||
.node_template_input_override([Some(NodeInput::type_default(descriptor!(List<Graphic>), true)), Some(NodeInput::value(TaggedValue::F64(count), false))]);
|
||||
|
||||
let blend_id = NodeId::new();
|
||||
self.network_interface.insert_node(blend_id, blend, &[]);
|
||||
@@ -109,7 +110,7 @@ impl<'a> ModifyInputsContext<'a> {
|
||||
pub fn insert_morph_data(&mut self, layer: LayerNodeIdentifier) -> NodeId {
|
||||
let morph = resolve_proto_node_type(graphene_std::vector::morph::IDENTIFIER)
|
||||
.expect("Morph node does not exist")
|
||||
.node_template_input_override([Some(NodeInput::type_default(list!(Graphic), true)), Some(NodeInput::value(TaggedValue::F64(0.5), false))]);
|
||||
.node_template_input_override([Some(NodeInput::type_default(descriptor!(List<Graphic>), true)), Some(NodeInput::value(TaggedValue::F64(0.5), false))]);
|
||||
|
||||
let morph_id = NodeId::new();
|
||||
self.network_interface.insert_node(morph_id, morph, &[]);
|
||||
@@ -270,17 +271,20 @@ impl<'a> ModifyInputsContext<'a> {
|
||||
self.network_interface.set_chain_position(node_id, &[]);
|
||||
}
|
||||
|
||||
pub fn insert_image_data(&mut self, data: Arc<[u8]>, layer: LayerNodeIdentifier) {
|
||||
pub fn insert_image_data(&mut self, image: Image<Color>, layer: LayerNodeIdentifier) {
|
||||
let transform = resolve_proto_node_type(graphene_std::transform_nodes::transform::IDENTIFIER)
|
||||
.expect("Transform node does not exist")
|
||||
.default_node_template();
|
||||
|
||||
let resource_id = ResourceId::new();
|
||||
self.responses.add(ResourceMessage::StoreEmbedded { resource_id, data });
|
||||
self.responses.add(ResourceMessage::StoreEmbedded {
|
||||
resource_id,
|
||||
data: image.to_png().into(),
|
||||
});
|
||||
|
||||
let image_node = resolve_proto_node_type(graphene_std::raster_nodes::std_nodes::image::IDENTIFIER)
|
||||
.expect("Image node does not exist")
|
||||
.node_template_input_override([None, Some(NodeInput::value(TaggedValue::Resource(resource_id), false))]);
|
||||
.node_template_input_override([Some(NodeInput::value(TaggedValue::Resource(resource_id), false))]);
|
||||
|
||||
let image_node_id = NodeId::new();
|
||||
self.network_interface.insert_node(image_node_id, image_node, &[]);
|
||||
@@ -410,7 +414,7 @@ impl<'a> ModifyInputsContext<'a> {
|
||||
// TODO: Allow the 'Path' node to operate on `List` data by utilizing the reference (index or ID?) for each item.
|
||||
if node_definition.identifier == "Path" {
|
||||
let layer_input_type = self.network_interface.input_type(&InputConnector::layer_secondary_input(output_layer.to_node()), &[]);
|
||||
if layer_input_type.compiled_element_name().as_deref() == Some("Graphic") {
|
||||
if layer_input_type.compiled_nested_type() == Some(&concrete!(List<Graphic>)) {
|
||||
let Some(combine_paths_definition) = resolve_proto_node_type(graphene_std::vector_nodes::combine_paths::IDENTIFIER) else {
|
||||
log::error!("Combine Paths does not exist in ModifyInputsContext::existing_node_id");
|
||||
return None;
|
||||
@@ -427,8 +431,7 @@ impl<'a> ModifyInputsContext<'a> {
|
||||
}
|
||||
|
||||
pub fn fill_color_set(&mut self, color: Option<Color>) {
|
||||
let existing_fill_node_id = self.existing_chain_hosted_node_id(graphene_std::vector_nodes::fill::IDENTIFIER, false);
|
||||
let Some(fill_node_id) = existing_fill_node_id.or_else(|| self.existing_chain_hosted_node_id(graphene_std::vector_nodes::fill::IDENTIFIER, true)) else {
|
||||
let Some(fill_node_id) = self.existing_chain_hosted_node_id(graphene_std::vector_nodes::fill::IDENTIFIER, true) else {
|
||||
return;
|
||||
};
|
||||
let input_connector = InputConnector::node(fill_node_id, graphene_std::vector::fill::PaintInput);
|
||||
@@ -440,15 +443,10 @@ impl<'a> ModifyInputsContext<'a> {
|
||||
}
|
||||
let fill_value = color.map_or_else(TaggedValue::no_paint, TaggedValue::Color);
|
||||
self.set_input_with_refresh(input_connector, NodeInput::value(fill_value, false), false);
|
||||
|
||||
if existing_fill_node_id.is_none() {
|
||||
self.restore_default_stroke_order();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fill_gradient_set(&mut self, gradient: Gradient, gradient_form: GradientForm, settings: GradientSettings, transform: DAffine2) {
|
||||
let existing_fill_node_id = self.existing_chain_hosted_node_id(graphene_std::vector_nodes::fill::IDENTIFIER, false);
|
||||
let Some(fill_node_id) = existing_fill_node_id.or_else(|| self.existing_chain_hosted_node_id(graphene_std::vector_nodes::fill::IDENTIFIER, true)) else {
|
||||
let Some(fill_node_id) = self.existing_chain_hosted_node_id(graphene_std::vector_nodes::fill::IDENTIFIER, true) else {
|
||||
return;
|
||||
};
|
||||
let backup_input_connector = InputConnector::node(fill_node_id, graphene_std::vector::fill::BackupGradientInput);
|
||||
@@ -489,21 +487,6 @@ impl<'a> ModifyInputsContext<'a> {
|
||||
NodeInput::value(TaggedValue::GradientForm(gradient_form), false),
|
||||
false,
|
||||
);
|
||||
|
||||
if existing_fill_node_id.is_none() {
|
||||
self.restore_default_stroke_order();
|
||||
}
|
||||
}
|
||||
|
||||
/// A freshly created Fill node lands at the chain start, downstream of any Stroke node, where it would
|
||||
/// paint over the stroke. This hops the stroke back downstream so it keeps painting above by default.
|
||||
fn restore_default_stroke_order(&mut self) {
|
||||
let Some(output_layer) = self.get_output_layer() else { return };
|
||||
let stroke_reference = DefinitionIdentifier::ProtoNode(graphene_std::vector::stroke::IDENTIFIER);
|
||||
let Some(stroke_node_id) = Self::locate_node_in_layer_chain(&stroke_reference, output_layer, self.network_interface) else {
|
||||
return;
|
||||
};
|
||||
set_stroke_paint_order(self.network_interface, &[], stroke_node_id, PaintOrder::StrokeAbove);
|
||||
}
|
||||
|
||||
pub fn blend_mode_set(&mut self, blend_mode: BlendMode) {
|
||||
@@ -1019,37 +1002,40 @@ fn primary_output_consumers(network_interface: &mut NodeNetworkInterface, networ
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
/// The fill wired directly to the stroke on either side, and whether the stroke currently paints above it.
|
||||
/// The downstream node of the pair appends its cover last, so it paints on top.
|
||||
pub fn adjacent_fill_of_stroke(network_interface: &mut NodeNetworkInterface, network_path: &[NodeId], stroke_node_id: NodeId) -> Option<(NodeId, bool)> {
|
||||
let fill_reference = DefinitionIdentifier::ProtoNode(graphene_std::vector::fill::IDENTIFIER);
|
||||
let is_fill = |network_interface: &NodeNetworkInterface, node_id: &NodeId| network_interface.reference(node_id, network_path) == Some(fill_reference.clone());
|
||||
|
||||
let stroke_primary_source = match network_interface.input_from_connector(&InputConnector::node_at_index(stroke_node_id, 0), network_path) {
|
||||
Some(NodeInput::Node { node_id, output_index: 0, .. }) => Some(*node_id),
|
||||
_ => None,
|
||||
};
|
||||
if let Some(source) = stroke_primary_source.filter(|source| is_fill(network_interface, source)) {
|
||||
return Some((source, true));
|
||||
}
|
||||
let consumers = primary_output_consumers(network_interface, network_path, stroke_node_id);
|
||||
let fill_consumer = consumers.iter().find_map(|connector| match connector {
|
||||
InputConnector::Node { node_id, input_index: 0 } if is_fill(network_interface, node_id) => Some(*node_id),
|
||||
_ => None,
|
||||
});
|
||||
fill_consumer.map(|fill_node_id| (fill_node_id, false))
|
||||
}
|
||||
|
||||
/// Swaps a chain's directly adjacent Stroke and Fill nodes when their order disagrees with the requested
|
||||
/// paint order: both nodes append their cover, so the downstream one of the pair paints on top, following
|
||||
/// the painter's algorithm. Without a fill wired directly to the stroke, nothing changes.
|
||||
/// Returns whether the graph changed.
|
||||
pub fn set_stroke_paint_order(network_interface: &mut NodeNetworkInterface, network_path: &[NodeId], stroke_node_id: NodeId, paint_order: PaintOrder) -> bool {
|
||||
let fill_reference = DefinitionIdentifier::ProtoNode(graphene_std::vector::fill::IDENTIFIER);
|
||||
let is_fill = |network_interface: &NodeNetworkInterface, node_id: &NodeId| network_interface.reference(node_id, network_path).as_ref() == Some(&fill_reference);
|
||||
|
||||
// Find the fill wired directly to the stroke on either side; the downstream one of the pair paints on top
|
||||
let stroke_primary_source = match network_interface.input_from_connector(&InputConnector::node_at_index(stroke_node_id, 0), network_path) {
|
||||
Some(NodeInput::Node { node_id, output_index: 0, .. }) => Some(*node_id),
|
||||
_ => None,
|
||||
};
|
||||
let (fill_node_id, currently_above) = if let Some(source) = stroke_primary_source.filter(|source| is_fill(network_interface, source)) {
|
||||
(source, true)
|
||||
} else {
|
||||
let consumers = primary_output_consumers(network_interface, network_path, stroke_node_id);
|
||||
let fill_consumer = consumers.iter().find_map(|connector| match connector {
|
||||
InputConnector::Node { node_id, input_index: 0 } if is_fill(network_interface, node_id) => Some(*node_id),
|
||||
_ => None,
|
||||
});
|
||||
let Some(fill_node_id) = fill_consumer else { return false };
|
||||
(fill_node_id, false)
|
||||
let Some((fill_node_id, currently_above)) = adjacent_fill_of_stroke(network_interface, network_path, stroke_node_id) else {
|
||||
return false;
|
||||
};
|
||||
|
||||
if (paint_order == PaintOrder::StrokeAbove) == currently_above {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Swap the pair in place: the downstream node takes the upstream one's source, consumers of the
|
||||
// downstream node move over to the upstream one, and the wire linking the pair reverses direction
|
||||
let (upstream, downstream) = if currently_above { (fill_node_id, stroke_node_id) } else { (stroke_node_id, fill_node_id) };
|
||||
let Some(upstream_source) = network_interface.input_from_connector(&InputConnector::node_at_index(upstream, 0), network_path).cloned() else {
|
||||
return false;
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
mod document_node_derive;
|
||||
|
||||
use super::node_properties::choice::enum_choice;
|
||||
use super::node_properties::{self, ParameterWidgetsInfo, SliderRange};
|
||||
use super::node_properties::{self, ParameterWidgetsInfo};
|
||||
use super::utility_types::{FrontendNodeType, InputTypeConstraint};
|
||||
use crate::messages::layout::utility_types::widget_prelude::*;
|
||||
use crate::messages::portfolio::document::utility_types::network_interface::{
|
||||
InputMetadata, NodeNetworkInterface, NodeNetworkTemplate, NodeTemplate, NodeTemplateImplementation, NodeTypePersistentMetadata, Vec2InputSettings, WidgetOverride,
|
||||
};
|
||||
use crate::messages::portfolio::ingest::utility_types::TypeFilter;
|
||||
use crate::messages::prelude::{DocumentId, FontsMessage, FontsMessageHandler, Message, ResourceMessageHandler, Responses};
|
||||
use crate::messages::prelude::{FontsMessage, FontsMessageHandler, Message, ResourceMessageHandler, Responses};
|
||||
use crate::node_graph_executor::NodeGraphExecutor;
|
||||
use glam::DVec2;
|
||||
use graph_craft::ProtoNodeIdentifier;
|
||||
use graph_craft::document::value::*;
|
||||
use graph_craft::document::*;
|
||||
use graph_craft::{concrete, list};
|
||||
use graph_craft::{concrete, descriptor};
|
||||
use graphene_std::extract_xy::XY;
|
||||
use graphene_std::list::List;
|
||||
use graphene_std::raster::{CellularDistanceFunction, CellularReturnType, Color, DomainWarpType, FractalType, NoiseType, RedGreenBlueAlpha};
|
||||
use graphene_std::raster_types::{CPU, Raster};
|
||||
#[allow(unused_imports)]
|
||||
@@ -27,7 +27,6 @@ use std::collections::{HashMap, VecDeque};
|
||||
pub struct NodePropertiesContext<'a> {
|
||||
pub responses: &'a mut VecDeque<Message>,
|
||||
pub executor: &'a mut NodeGraphExecutor,
|
||||
pub document_id: DocumentId,
|
||||
pub network_interface: &'a mut NodeNetworkInterface,
|
||||
pub resources: &'a ResourceMessageHandler,
|
||||
pub fonts: &'a FontsMessageHandler,
|
||||
@@ -160,7 +159,8 @@ fn document_node_definitions() -> HashMap<DefinitionIdentifier, DocumentNodeDefi
|
||||
node_type_metadata: NodeTypePersistentMetadata::node(IVec2::new(-21, -2)),
|
||||
..Default::default()
|
||||
},
|
||||
// Secondary (left) input type coercion
|
||||
// Collection of the content into the layer's group; the group keeps
|
||||
// the content level's element type for the legacy boundary.
|
||||
NodeTemplate {
|
||||
inputs: vec![NodeInput::import(generic!(T), 1)],
|
||||
implementation: NodeTemplateImplementation::ProtoNode(graphic::into_group::IDENTIFIER),
|
||||
@@ -177,12 +177,8 @@ fn document_node_definitions() -> HashMap<DefinitionIdentifier, DocumentNodeDefi
|
||||
// Stamp each item of the content with the parent layer's NodeId via the `editor:layer_path` attribute,
|
||||
// so editor tools (e.g. selection, click target routing) can trace data back to its owning layer.
|
||||
NodeTemplate {
|
||||
inputs: vec![
|
||||
NodeInput::node(NodeId(1), 0),
|
||||
NodeInput::value(TaggedValue::String(graphene_std::ATTR_EDITOR_LAYER_PATH.to_string()), false),
|
||||
NodeInput::node(NodeId(2), 0),
|
||||
],
|
||||
implementation: NodeTemplateImplementation::ProtoNode(graphic::write_attribute::IDENTIFIER),
|
||||
inputs: vec![NodeInput::node(NodeId(1), 0), NodeInput::node(NodeId(2), 0)],
|
||||
implementation: NodeTemplateImplementation::ProtoNode(graphic::stamp_layer_path::IDENTIFIER),
|
||||
node_type_metadata: NodeTypePersistentMetadata::node(IVec2::new(-14, -1)),
|
||||
..Default::default()
|
||||
},
|
||||
@@ -197,7 +193,7 @@ fn document_node_definitions() -> HashMap<DefinitionIdentifier, DocumentNodeDefi
|
||||
NodeTemplate {
|
||||
call_argument: generic!(T),
|
||||
inputs: vec![NodeInput::node(NodeId(0), 0), NodeInput::node(NodeId(4), 0)],
|
||||
implementation: NodeTemplateImplementation::ProtoNode(graphic::extend::IDENTIFIER),
|
||||
implementation: NodeTemplateImplementation::ProtoNode(list::extend::IDENTIFIER),
|
||||
node_type_metadata: NodeTypePersistentMetadata::node(IVec2::new(0, -2)),
|
||||
..Default::default()
|
||||
},
|
||||
@@ -208,7 +204,7 @@ fn document_node_definitions() -> HashMap<DefinitionIdentifier, DocumentNodeDefi
|
||||
.collect(),
|
||||
..Default::default()
|
||||
}),
|
||||
inputs: vec![NodeInput::type_default(list!(Graphic), true), NodeInput::type_default(list!(Graphic), true)],
|
||||
inputs: vec![NodeInput::type_default(descriptor!(List<Graphic>), true), NodeInput::type_default(descriptor!(List<Graphic>), true)],
|
||||
input_metadata: vec![("Base", "TODO").into(), ("Content", "TODO").into()],
|
||||
output_names: vec!["Out".to_string()],
|
||||
node_type_metadata: NodeTypePersistentMetadata::layer(IVec2::new(0, 0)),
|
||||
@@ -228,11 +224,11 @@ fn document_node_definitions() -> HashMap<DefinitionIdentifier, DocumentNodeDefi
|
||||
call_argument: generic!(T),
|
||||
implementation: NodeTemplateImplementation::ProtoNode(artboard::create_artboard::IDENTIFIER),
|
||||
inputs: vec![
|
||||
NodeInput::import(Type::Fn(concrete!(Context).into(), generic!(T).into()), 1),
|
||||
NodeInput::import(item!(TaggedValue), 2),
|
||||
NodeInput::import(item!(TaggedValue), 3),
|
||||
NodeInput::import(item!(TaggedValue), 4),
|
||||
NodeInput::import(item!(TaggedValue), 5),
|
||||
NodeInput::node(NodeId(6), 0),
|
||||
NodeInput::import(concrete!(TaggedValue), 2),
|
||||
NodeInput::import(concrete!(TaggedValue), 3),
|
||||
NodeInput::import(concrete!(TaggedValue), 4),
|
||||
NodeInput::import(concrete!(TaggedValue), 5),
|
||||
],
|
||||
node_type_metadata: NodeTypePersistentMetadata::node(IVec2::new(-21, -3)),
|
||||
..Default::default()
|
||||
@@ -247,18 +243,14 @@ fn document_node_definitions() -> HashMap<DefinitionIdentifier, DocumentNodeDefi
|
||||
// Stamp each item of the content with the parent layer's NodeId via the `editor:layer_path` attribute,
|
||||
// so editor tools (e.g. selection, click target routing) can trace data back to its owning layer.
|
||||
NodeTemplate {
|
||||
inputs: vec![
|
||||
NodeInput::node(NodeId(0), 0),
|
||||
NodeInput::value(TaggedValue::String(graphene_std::ATTR_EDITOR_LAYER_PATH.to_string()), false),
|
||||
NodeInput::node(NodeId(1), 0),
|
||||
],
|
||||
implementation: NodeTemplateImplementation::ProtoNode(graphic::write_attribute::IDENTIFIER),
|
||||
inputs: vec![NodeInput::node(NodeId(0), 0), NodeInput::node(NodeId(1), 0)],
|
||||
implementation: NodeTemplateImplementation::ProtoNode(graphic::stamp_layer_path::IDENTIFIER),
|
||||
node_type_metadata: NodeTypePersistentMetadata::node(IVec2::new(-14, -3)),
|
||||
..Default::default()
|
||||
},
|
||||
// The monitor node is used to display a thumbnail in the UI.
|
||||
NodeTemplate {
|
||||
inputs: vec![NodeInput::node(NodeId(2), 0)],
|
||||
inputs: vec![NodeInput::node(NodeId(7), 0)],
|
||||
implementation: NodeTemplateImplementation::ProtoNode(memo::monitor::IDENTIFIER),
|
||||
call_argument: generic!(T),
|
||||
skip_deduplication: true,
|
||||
@@ -267,13 +259,37 @@ fn document_node_definitions() -> HashMap<DefinitionIdentifier, DocumentNodeDefi
|
||||
},
|
||||
NodeTemplate {
|
||||
inputs: vec![
|
||||
NodeInput::import(graphene_std::Type::Fn(Box::new(concrete!(Context)), Box::new(list!(Artboard))), 0),
|
||||
NodeInput::import(graphene_std::Type::Fn(Box::new(concrete!(Context)), Box::new(concrete!(List<Artboard>))), 0),
|
||||
NodeInput::node(NodeId(3), 0),
|
||||
],
|
||||
implementation: NodeTemplateImplementation::ProtoNode(graphic::extend::IDENTIFIER),
|
||||
implementation: NodeTemplateImplementation::ProtoNode(list::extend::IDENTIFIER),
|
||||
node_type_metadata: NodeTypePersistentMetadata::node(IVec2::new(0, -4)),
|
||||
..Default::default()
|
||||
},
|
||||
// Content coercion into a graphic level, evaluated within the artboard's footprint
|
||||
NodeTemplate {
|
||||
inputs: vec![NodeInput::import(generic!(T), 1)],
|
||||
implementation: NodeTemplateImplementation::ProtoNode(graphic::as_graphic::IDENTIFIER),
|
||||
node_type_metadata: NodeTypePersistentMetadata::node(IVec2::new(-35, -3)),
|
||||
..Default::default()
|
||||
},
|
||||
NodeTemplate {
|
||||
inputs: vec![NodeInput::node(NodeId(5), 0), NodeInput::import(concrete!(TaggedValue), 2)],
|
||||
implementation: NodeTemplateImplementation::ProtoNode(artboard::translate_footprint::IDENTIFIER),
|
||||
node_type_metadata: NodeTypePersistentMetadata::node(IVec2::new(-28, -3)),
|
||||
..Default::default()
|
||||
},
|
||||
// Lifts the artboard element onto a one-lane level so it concatenates with the base stack
|
||||
NodeTemplate {
|
||||
inputs: vec![
|
||||
NodeInput::node(NodeId(2), 0),
|
||||
NodeInput::value(TaggedValue::U32(1), false),
|
||||
NodeInput::value(TaggedValue::Bool(false), false),
|
||||
],
|
||||
implementation: NodeTemplateImplementation::ProtoNode(repeat_nodes::repeat::IDENTIFIER),
|
||||
node_type_metadata: NodeTypePersistentMetadata::node(IVec2::new(-10, -3)),
|
||||
..Default::default()
|
||||
},
|
||||
]
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
@@ -282,8 +298,8 @@ fn document_node_definitions() -> HashMap<DefinitionIdentifier, DocumentNodeDefi
|
||||
..Default::default()
|
||||
}),
|
||||
inputs: vec![
|
||||
NodeInput::type_default(list!(Artboard), true),
|
||||
NodeInput::type_default(list!(Graphic), true),
|
||||
NodeInput::type_default(descriptor!(List<Artboard>), true),
|
||||
NodeInput::type_default(descriptor!(List<Graphic>), true),
|
||||
NodeInput::value(TaggedValue::DVec2(DVec2::ZERO), false),
|
||||
NodeInput::value(TaggedValue::DVec2(DVec2::new(1920., 1080.)), false),
|
||||
NodeInput::value(TaggedValue::Color(Color::WHITE), false),
|
||||
@@ -355,7 +371,7 @@ fn document_node_definitions() -> HashMap<DefinitionIdentifier, DocumentNodeDefi
|
||||
// 3: Floor (integer count per subpath)
|
||||
NodeTemplate {
|
||||
implementation: NodeTemplateImplementation::ProtoNode(math_nodes::floor::IDENTIFIER),
|
||||
inputs: vec![NodeInput::import(item!(f64), 1)],
|
||||
inputs: vec![NodeInput::import(concrete!(f64), 1)],
|
||||
node_type_metadata: NodeTypePersistentMetadata::node(IVec2::new(2, 13)),
|
||||
..Default::default()
|
||||
},
|
||||
@@ -443,8 +459,8 @@ fn document_node_definitions() -> HashMap<DefinitionIdentifier, DocumentNodeDefi
|
||||
NodeInput::import(generic!(T), 0),
|
||||
NodeInput::node(NodeId(14), 0),
|
||||
NodeInput::value(TaggedValue::Bool(false), false),
|
||||
NodeInput::import(item!(vector::misc::InterpolationDistribution), 3),
|
||||
NodeInput::import(item!(Vector), 4),
|
||||
NodeInput::import(concrete!(vector::misc::InterpolationDistribution), 3),
|
||||
NodeInput::import(concrete!(Vector), 4),
|
||||
],
|
||||
node_type_metadata: NodeTypePersistentMetadata::node(IVec2::new(44, 3)),
|
||||
..Default::default()
|
||||
@@ -478,11 +494,11 @@ fn document_node_definitions() -> HashMap<DefinitionIdentifier, DocumentNodeDefi
|
||||
..Default::default()
|
||||
}),
|
||||
inputs: vec![
|
||||
NodeInput::type_default(list!(Vector), true),
|
||||
NodeInput::type_default(descriptor!(List<Vector>), true),
|
||||
NodeInput::value(TaggedValue::F64(10.), false),
|
||||
NodeInput::value(TaggedValue::Bool(Default::default()), false),
|
||||
NodeInput::value(TaggedValue::InterpolationDistribution(Default::default()), false),
|
||||
NodeInput::type_default(item!(Vector), false),
|
||||
NodeInput::type_default(descriptor!(List<Vector>), false),
|
||||
],
|
||||
input_metadata: vec![
|
||||
("Content", "TODO").into(),
|
||||
@@ -542,7 +558,7 @@ fn document_node_definitions() -> HashMap<DefinitionIdentifier, DocumentNodeDefi
|
||||
},
|
||||
// 5: Map
|
||||
NodeTemplate {
|
||||
implementation: NodeTemplateImplementation::ProtoNode(graphic::map::IDENTIFIER),
|
||||
implementation: NodeTemplateImplementation::ProtoNode(list::map::IDENTIFIER),
|
||||
inputs: vec![NodeInput::node(NodeId(4), 0), NodeInput::node(NodeId(3), 0)],
|
||||
node_type_metadata: NodeTypePersistentMetadata::node(IVec2::new(28, 0)),
|
||||
..Default::default()
|
||||
@@ -568,7 +584,7 @@ fn document_node_definitions() -> HashMap<DefinitionIdentifier, DocumentNodeDefi
|
||||
.collect(),
|
||||
..Default::default()
|
||||
}),
|
||||
inputs: vec![NodeInput::type_default(list!(Vector), true)],
|
||||
inputs: vec![NodeInput::type_default(descriptor!(List<Vector>), true)],
|
||||
input_metadata: vec![("Vector", "TODO").into()],
|
||||
output_names: vec!["Vector".to_string()],
|
||||
node_type_metadata: NodeTypePersistentMetadata::node(IVec2::new(0, 0)),
|
||||
@@ -585,7 +601,12 @@ fn document_node_definitions() -> HashMap<DefinitionIdentifier, DocumentNodeDefi
|
||||
exports: vec![NodeInput::node(NodeId(1), 0)],
|
||||
nodes: [
|
||||
NodeTemplate {
|
||||
inputs: vec![NodeInput::value(TaggedValue::None, false), NodeInput::import(item!(String), 1)],
|
||||
inputs: vec![
|
||||
NodeInput::value(TaggedValue::None, false),
|
||||
NodeInput::import(concrete!(String), 1),
|
||||
NodeInput::scope("graphene_std::runtime::RuntimeNode"),
|
||||
NodeInput::Reflection(graph_craft::document::DocumentNodeMetadata::SourceId),
|
||||
],
|
||||
implementation: NodeTemplateImplementation::ProtoNode(platform_application_io::load_resource::IDENTIFIER),
|
||||
node_type_metadata: NodeTypePersistentMetadata::node(IVec2::new(0, 0)),
|
||||
..Default::default()
|
||||
@@ -633,7 +654,14 @@ fn document_node_definitions() -> HashMap<DefinitionIdentifier, DocumentNodeDefi
|
||||
..Default::default()
|
||||
},
|
||||
NodeTemplate {
|
||||
inputs: vec![NodeInput::import(generic!(T), 0), NodeInput::import(item!(Footprint), 1), NodeInput::node(NodeId(1), 0)],
|
||||
inputs: vec![
|
||||
NodeInput::value(TaggedValue::None, false),
|
||||
NodeInput::import(generic!(T), 0),
|
||||
NodeInput::import(concrete!(Footprint), 1),
|
||||
NodeInput::node(NodeId(1), 0),
|
||||
NodeInput::scope("graphene_std::runtime::RuntimeNode"),
|
||||
NodeInput::Reflection(graph_craft::document::DocumentNodeMetadata::SourceId),
|
||||
],
|
||||
implementation: NodeTemplateImplementation::ProtoNode(platform_application_io::rasterize::IDENTIFIER),
|
||||
node_type_metadata: NodeTypePersistentMetadata::node(IVec2::new(14, 0)),
|
||||
..Default::default()
|
||||
@@ -646,7 +674,7 @@ fn document_node_definitions() -> HashMap<DefinitionIdentifier, DocumentNodeDefi
|
||||
..Default::default()
|
||||
}),
|
||||
inputs: vec![
|
||||
NodeInput::type_default(list!(Vector), true),
|
||||
NodeInput::type_default(descriptor!(List<Vector>), true),
|
||||
NodeInput::value(
|
||||
TaggedValue::Footprint(Footprint {
|
||||
transform: DAffine2::from_scale_angle_translation(DVec2::new(1000., 1000.), 0., DVec2::new(0., 0.)),
|
||||
@@ -678,7 +706,7 @@ fn document_node_definitions() -> HashMap<DefinitionIdentifier, DocumentNodeDefi
|
||||
nodes: [
|
||||
NodeTemplate {
|
||||
inputs: vec![
|
||||
NodeInput::import(list!(Raster<CPU>), 0),
|
||||
NodeInput::import(concrete!(List<Raster<CPU>>), 0),
|
||||
NodeInput::value(TaggedValue::RedGreenBlueAlpha(RedGreenBlueAlpha::Red), false),
|
||||
],
|
||||
implementation: NodeTemplateImplementation::ProtoNode(raster_nodes::adjustments::extract_channel::IDENTIFIER),
|
||||
@@ -688,7 +716,7 @@ fn document_node_definitions() -> HashMap<DefinitionIdentifier, DocumentNodeDefi
|
||||
},
|
||||
NodeTemplate {
|
||||
inputs: vec![
|
||||
NodeInput::import(list!(Raster<CPU>), 0),
|
||||
NodeInput::import(concrete!(List<Raster<CPU>>), 0),
|
||||
NodeInput::value(TaggedValue::RedGreenBlueAlpha(RedGreenBlueAlpha::Green), false),
|
||||
],
|
||||
implementation: NodeTemplateImplementation::ProtoNode(raster_nodes::adjustments::extract_channel::IDENTIFIER),
|
||||
@@ -698,7 +726,7 @@ fn document_node_definitions() -> HashMap<DefinitionIdentifier, DocumentNodeDefi
|
||||
},
|
||||
NodeTemplate {
|
||||
inputs: vec![
|
||||
NodeInput::import(list!(Raster<CPU>), 0),
|
||||
NodeInput::import(concrete!(List<Raster<CPU>>), 0),
|
||||
NodeInput::value(TaggedValue::RedGreenBlueAlpha(RedGreenBlueAlpha::Blue), false),
|
||||
],
|
||||
implementation: NodeTemplateImplementation::ProtoNode(raster_nodes::adjustments::extract_channel::IDENTIFIER),
|
||||
@@ -708,7 +736,7 @@ fn document_node_definitions() -> HashMap<DefinitionIdentifier, DocumentNodeDefi
|
||||
},
|
||||
NodeTemplate {
|
||||
inputs: vec![
|
||||
NodeInput::import(list!(Raster<CPU>), 0),
|
||||
NodeInput::import(concrete!(List<Raster<CPU>>), 0),
|
||||
NodeInput::value(TaggedValue::RedGreenBlueAlpha(RedGreenBlueAlpha::Alpha), false),
|
||||
],
|
||||
implementation: NodeTemplateImplementation::ProtoNode(raster_nodes::adjustments::extract_channel::IDENTIFIER),
|
||||
@@ -723,7 +751,7 @@ fn document_node_definitions() -> HashMap<DefinitionIdentifier, DocumentNodeDefi
|
||||
.collect(),
|
||||
..Default::default()
|
||||
}),
|
||||
inputs: vec![NodeInput::type_default(list!(Raster<CPU>), true)],
|
||||
inputs: vec![NodeInput::type_default(descriptor!(List<Raster<CPU>>), true)],
|
||||
input_metadata: vec![("Image", "TODO").into()],
|
||||
output_names: vec!["".to_string(), "Red".to_string(), "Green".to_string(), "Blue".to_string(), "Alpha".to_string()],
|
||||
..Default::default()
|
||||
@@ -739,14 +767,14 @@ fn document_node_definitions() -> HashMap<DefinitionIdentifier, DocumentNodeDefi
|
||||
exports: vec![NodeInput::value(TaggedValue::None, false), NodeInput::node(NodeId(0), 0), NodeInput::node(NodeId(1), 0)],
|
||||
nodes: [
|
||||
NodeTemplate {
|
||||
inputs: vec![NodeInput::import(item!(DVec2), 0), NodeInput::value(TaggedValue::XY(XY::X), false)],
|
||||
inputs: vec![NodeInput::import(concrete!(DVec2), 0), NodeInput::value(TaggedValue::XY(XY::X), false)],
|
||||
implementation: NodeTemplateImplementation::ProtoNode(extract_xy::extract_xy::IDENTIFIER),
|
||||
call_argument: generic!(T),
|
||||
node_type_metadata: NodeTypePersistentMetadata::node(IVec2::new(0, 0)),
|
||||
..Default::default()
|
||||
},
|
||||
NodeTemplate {
|
||||
inputs: vec![NodeInput::import(item!(DVec2), 0), NodeInput::value(TaggedValue::XY(XY::Y), false)],
|
||||
inputs: vec![NodeInput::import(concrete!(DVec2), 0), NodeInput::value(TaggedValue::XY(XY::Y), false)],
|
||||
implementation: NodeTemplateImplementation::ProtoNode(extract_xy::extract_xy::IDENTIFIER),
|
||||
call_argument: generic!(T),
|
||||
node_type_metadata: NodeTypePersistentMetadata::node(IVec2::new(0, 2)),
|
||||
@@ -776,7 +804,7 @@ fn document_node_definitions() -> HashMap<DefinitionIdentifier, DocumentNodeDefi
|
||||
category: "",
|
||||
node_template: NodeTemplate {
|
||||
implementation: NodeTemplateImplementation::Extract,
|
||||
inputs: vec![NodeInput::type_default(concrete!(DocumentNode), true)],
|
||||
inputs: vec![NodeInput::type_default(descriptor!(DocumentNode), true)],
|
||||
input_metadata: vec![("Node", "TODO").into()],
|
||||
output_names: vec!["Document Node".to_string()],
|
||||
..Default::default()
|
||||
@@ -799,11 +827,11 @@ fn document_node_definitions() -> HashMap<DefinitionIdentifier, DocumentNodeDefi
|
||||
// Node 0: regex_find proto node — returns List<String> of [whole_match, ...capture_groups]
|
||||
NodeTemplate {
|
||||
inputs: vec![
|
||||
NodeInput::import(item!(String), 0),
|
||||
NodeInput::import(item!(String), 1),
|
||||
NodeInput::import(item!(f64), 2),
|
||||
NodeInput::import(item!(bool), 3),
|
||||
NodeInput::import(item!(bool), 4),
|
||||
NodeInput::import(concrete!(String), 0),
|
||||
NodeInput::import(concrete!(String), 1),
|
||||
NodeInput::import(concrete!(f64), 2),
|
||||
NodeInput::import(concrete!(bool), 3),
|
||||
NodeInput::import(concrete!(bool), 4),
|
||||
],
|
||||
implementation: NodeTemplateImplementation::ProtoNode(text_nodes::regex::regex_find::IDENTIFIER),
|
||||
node_type_metadata: NodeTypePersistentMetadata::node(IVec2::new(0, 0)),
|
||||
@@ -812,14 +840,14 @@ fn document_node_definitions() -> HashMap<DefinitionIdentifier, DocumentNodeDefi
|
||||
// Node 1: item_at_index at index 0, extracts the whole match as a bare String (drops the item's start/end/name attributes since the unwrapped String can't carry them)
|
||||
NodeTemplate {
|
||||
inputs: vec![NodeInput::node(NodeId(0), 0), NodeInput::value(TaggedValue::F64(0.), false)],
|
||||
implementation: NodeTemplateImplementation::ProtoNode(graphic::item_at_index::IDENTIFIER),
|
||||
implementation: NodeTemplateImplementation::ProtoNode(list::item_at_index::IDENTIFIER),
|
||||
node_type_metadata: NodeTypePersistentMetadata::node(IVec2::new(8, 0)),
|
||||
..Default::default()
|
||||
},
|
||||
// Node 2: remove_at_index at index 0, returns the capture group items as a List<String>, preserving each item's start/end/name attributes
|
||||
NodeTemplate {
|
||||
inputs: vec![NodeInput::node(NodeId(0), 0), NodeInput::value(TaggedValue::F64(0.), false)],
|
||||
implementation: NodeTemplateImplementation::ProtoNode(graphic::remove_at_index::IDENTIFIER),
|
||||
implementation: NodeTemplateImplementation::ProtoNode(list::remove_at_index::IDENTIFIER),
|
||||
node_type_metadata: NodeTypePersistentMetadata::node(IVec2::new(8, 2)),
|
||||
..Default::default()
|
||||
},
|
||||
@@ -890,7 +918,7 @@ fn document_node_definitions() -> HashMap<DefinitionIdentifier, DocumentNodeDefi
|
||||
..Default::default()
|
||||
}),
|
||||
inputs: vec![
|
||||
NodeInput::type_default(item!(Vector), true),
|
||||
NodeInput::type_default(descriptor!(List<Vector>), true),
|
||||
NodeInput::value(TaggedValue::VectorModification(Default::default()), false),
|
||||
],
|
||||
input_metadata: vec![("Content", "TODO").into(), ("Modification", "TODO").into()],
|
||||
@@ -916,12 +944,10 @@ fn static_node_properties() -> NodeProperties {
|
||||
map.insert("brightness_contrast_properties".to_string(), Box::new(node_properties::brightness_contrast_properties));
|
||||
map.insert("channel_mixer_properties".to_string(), Box::new(node_properties::channel_mixer_properties));
|
||||
map.insert("levels_properties".to_string(), Box::new(node_properties::levels_properties));
|
||||
map.insert("transfer_curves_properties".to_string(), Box::new(node_properties::transfer_curves_properties));
|
||||
map.insert("hue_saturation_properties".to_string(), Box::new(node_properties::hue_saturation_properties));
|
||||
map.insert("black_and_white_properties".to_string(), Box::new(node_properties::black_and_white_properties));
|
||||
map.insert("threshold_properties".to_string(), Box::new(node_properties::threshold_properties));
|
||||
map.insert("vibrance_properties".to_string(), Box::new(node_properties::vibrance_properties));
|
||||
map.insert("color_balance_properties".to_string(), Box::new(node_properties::color_balance_properties));
|
||||
map.insert("fill_properties".to_string(), Box::new(node_properties::fill_properties));
|
||||
map.insert("stroke_properties".to_string(), Box::new(node_properties::stroke_properties));
|
||||
map.insert("offset_path_properties".to_string(), Box::new(node_properties::offset_path_properties));
|
||||
@@ -1075,26 +1101,19 @@ fn static_input_properties() -> InputProperties {
|
||||
ParameterWidgetsInfo::at_index(node_id, index, false, context),
|
||||
index - 1,
|
||||
number_input,
|
||||
None,
|
||||
))])
|
||||
}),
|
||||
);
|
||||
map.insert(
|
||||
// Like `optional_f64`, but with a 0-100% range slider beside the number input, double-click restoring the full 100%.
|
||||
// Like `optional_f64`, but the number input is configured as a percentage with a 0-100 range.
|
||||
// As with `optional_f64`, the bool input must be at the input index directly before the f64 input.
|
||||
"optional_percentage".to_string(),
|
||||
Box::new(|node_id, index, context| {
|
||||
let number_input = NumberInput::default().mode_increment().unit("%").min(0.).max(100.);
|
||||
let slider = SliderRange {
|
||||
min: 0.,
|
||||
max: 100.,
|
||||
default: Some(100.),
|
||||
};
|
||||
let number_input = NumberInput::default().percentage().min(0.).max(100.);
|
||||
Ok(vec![LayoutGroup::row(node_properties::optional_f64_widget(
|
||||
ParameterWidgetsInfo::at_index(node_id, index, false, context),
|
||||
index - 1,
|
||||
number_input,
|
||||
Some(slider),
|
||||
))])
|
||||
}),
|
||||
);
|
||||
@@ -1250,13 +1269,13 @@ fn static_input_properties() -> InputProperties {
|
||||
"noise_properties_fractal_weighted_strength".to_string(),
|
||||
Box::new(|node_id, index, context| {
|
||||
let (fractal_active, coherent_noise_active, _, _, _, domain_warp_only_fractal_type_wrongly_active) = node_properties::query_noise_pattern_state(node_id, context)?;
|
||||
let fractal_weighted_strength = node_properties::range_slider_widget(
|
||||
let fractal_weighted_strength = node_properties::number_widget(
|
||||
ParameterWidgetsInfo::at_index(node_id, index, true, context),
|
||||
NumberInput::default()
|
||||
.mode_range()
|
||||
.min(0.)
|
||||
.max(1.)
|
||||
.max(1.) // Defined for the 0-1 range
|
||||
.disabled(!coherent_noise_active || !fractal_active || domain_warp_only_fractal_type_wrongly_active),
|
||||
SliderRange { min: 0., max: 1., default: Some(0.) },
|
||||
);
|
||||
Ok(vec![fractal_weighted_strength.into()])
|
||||
}),
|
||||
@@ -1463,20 +1482,6 @@ fn static_input_properties() -> InputProperties {
|
||||
Ok(result)
|
||||
}),
|
||||
);
|
||||
map.insert(
|
||||
"image_file".to_string(),
|
||||
Box::new(|node_id, index, context| {
|
||||
let widgets = node_properties::resource_widget(ParameterWidgetsInfo::at_index(node_id, index, true, context), vec![TypeFilter::raster()]);
|
||||
Ok(vec![LayoutGroup::row(widgets)])
|
||||
}),
|
||||
);
|
||||
map.insert(
|
||||
"lut_file".to_string(),
|
||||
Box::new(|node_id, index, context| {
|
||||
let widgets = node_properties::resource_widget(ParameterWidgetsInfo::at_index(node_id, index, true, context), vec![TypeFilter::lut()]);
|
||||
Ok(vec![LayoutGroup::row(widgets)])
|
||||
}),
|
||||
);
|
||||
map.insert(
|
||||
"artboard_background".to_string(),
|
||||
Box::new(|node_id, index, context| {
|
||||
@@ -1549,26 +1554,6 @@ impl InputTypeConstraint {
|
||||
}
|
||||
}
|
||||
|
||||
/// Check if a type reaches the constraint through an `input_adapter`, the per-connector node which the preprocessor places ahead of
|
||||
/// every ranked connector to convert or embed a convertible element, such as a color literal feeding a `Graphic` paint wire.
|
||||
#[must_use]
|
||||
fn satisfies_through_input_adapter(&self, ty: &Type) -> bool {
|
||||
let provided = Self::type_name(ty);
|
||||
|
||||
interpreted_executor::node_registry::NODE_REGISTRY
|
||||
.iter()
|
||||
.filter(|(identifier, _)| identifier.as_str().starts_with("input_adapter<"))
|
||||
.flat_map(|(_, implementations)| implementations.keys())
|
||||
.any(|node_io| node_io.inputs.first().is_some_and(|from| Self::type_name(from) == provided) && self.satisfies(&node_io.return_value))
|
||||
}
|
||||
|
||||
/// Check if a default value of this type is valid for the constraint.
|
||||
#[must_use]
|
||||
fn accepts_default_value(&self, ty: &Type) -> bool {
|
||||
// Empty types are used when the input must come from the graph so they can be skipped
|
||||
ty.nested_type() == &concrete!(()) || self.satisfies(ty) || self.satisfies_through_input_adapter(ty)
|
||||
}
|
||||
|
||||
/// Compute the type constraint for one input. Note that this cannot use the infrastructure in the node network interface as the node is not placed in a network.
|
||||
#[must_use]
|
||||
fn compute_constraint_for_input(template_document_node: &NodeTemplate, name: &str, input_index: usize) -> Self {
|
||||
@@ -1601,7 +1586,7 @@ impl InputTypeConstraint {
|
||||
|
||||
// Find the union of all the possible types from the dynamic executor implementations
|
||||
let mut result_accepted = Self::empty();
|
||||
for node_io in implementations.keys() {
|
||||
for node_io in implementations.iter().map(|entry| &entry.io) {
|
||||
if let Some(input_type) = node_io.inputs.get(input_index) {
|
||||
result_accepted.insert(input_type);
|
||||
}
|
||||
@@ -1625,7 +1610,9 @@ impl InputTypeConstraint {
|
||||
for (index, (constraint, input)) in all_input_constraints.iter().zip(&template_document_node.inputs).enumerate() {
|
||||
if let Some(value) = input.as_value() {
|
||||
let input_ty = value.ty();
|
||||
if !constraint.accepts_default_value(&input_ty) {
|
||||
|
||||
// Empty types are used when the input must come from the graph so they can be skipped.
|
||||
if input_ty.nested_type() != &concrete!(()) && !constraint.satisfies(&input_ty) {
|
||||
warn!("The default value for input index {index} node {name} is {input_ty}, but does not satisfy {constraint:?}");
|
||||
}
|
||||
}
|
||||
@@ -1721,27 +1708,6 @@ mod test {
|
||||
|
||||
editor.eval_graph().await.expect("the Origins to Polyline chain should type-resolve and evaluate");
|
||||
}
|
||||
|
||||
// Guards the unconnected Path input, whose default must match the rank of the Morph connector it feeds
|
||||
#[tokio::test]
|
||||
async fn blend_resolves_and_evaluates_with_default_inputs() {
|
||||
let mut editor = EditorTestUtils::create();
|
||||
editor.new_document().await;
|
||||
editor.draw_rect(0., 0., 10., 10.).await;
|
||||
|
||||
let layer = editor.active_document().metadata().all_layers().next().expect("drawing a rectangle should create a layer");
|
||||
let node_id = NodeId::new();
|
||||
let node_template = resolve_network_node_type("Blend").expect("the Blend definition should exist").default_node_template();
|
||||
editor
|
||||
.handle_message(NodeGraphMessage::InsertNode {
|
||||
node_id,
|
||||
node_template: Box::new(node_template),
|
||||
})
|
||||
.await;
|
||||
editor.handle_message(NodeGraphMessage::MoveNodeToChainStart { node_id, parent: layer }).await;
|
||||
|
||||
editor.eval_graph().await.expect("the Blend network should type-resolve and evaluate");
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -1750,7 +1716,7 @@ mod test_type_constraints {
|
||||
use crate::messages::portfolio::document::node_graph::utility_types::InputTypeConstraint;
|
||||
use crate::messages::portfolio::document::utility_types::network_interface::{NodeNetworkTemplate, NodeTemplate, NodeTemplateImplementation};
|
||||
use crate::test_utils::test_prelude::*;
|
||||
use core_types::{Ctx, list::Item};
|
||||
use core_types::Ctx;
|
||||
use graph_craft::document::{NodeId, NodeInput};
|
||||
use graphene_std::{Type, concrete, generic};
|
||||
use node_macro;
|
||||
@@ -1762,25 +1728,6 @@ mod test_type_constraints {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_definition_default_value_satisfies_its_constraint() {
|
||||
let mut violations = Vec::new();
|
||||
for definition in super::DOCUMENT_NODE_TYPES.values() {
|
||||
let name = &definition.node_template.display_name;
|
||||
let constraints = InputTypeConstraint::constraints_for_all_inputs(&definition.node_template, name);
|
||||
|
||||
for (index, (constraint, input)) in constraints.iter().zip(&definition.node_template.inputs).enumerate() {
|
||||
if let Some(value) = input.as_value()
|
||||
&& !constraint.accepts_default_value(&value.ty())
|
||||
{
|
||||
violations.push(format!("{name} input {index}: {} does not satisfy {constraint:?}", value.ty()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert!(violations.is_empty(), "Default values rejected by their input constraints:\n{}", violations.join("\n"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn passthrough() {
|
||||
let node_type = resolve_proto_node_type(graphene_std::ops::passthrough::IDENTIFIER).expect("passthrough node");
|
||||
@@ -1789,7 +1736,7 @@ mod test_type_constraints {
|
||||
}
|
||||
|
||||
#[node_macro::node(category(""))]
|
||||
fn test_node_accept_f32_f64_dvec2<T: std::any::Any>(_: impl Ctx, #[implementations(f32, f64, DVec2)] a: Item<T>, _b: Item<bool>) -> Item<T> {
|
||||
fn test_node_accept_f32_f64_dvec2<T: std::any::Any>(_: impl Ctx, #[implementations(f32, f64, DVec2)] a: T, _b: bool) -> T {
|
||||
a
|
||||
}
|
||||
|
||||
@@ -1803,7 +1750,7 @@ mod test_type_constraints {
|
||||
}
|
||||
|
||||
#[node_macro::node(category(""))]
|
||||
fn test_node_accept_f32_f64_string<T: std::any::Any>(_: impl Ctx, #[implementations(f32, f64, String)] a: Item<T>, _b: Item<bool>) -> Item<T> {
|
||||
fn test_node_accept_f32_f64_string<T: std::any::Any>(_: impl Ctx, #[implementations(f32, f64, String)] a: T, _b: bool) -> T {
|
||||
a
|
||||
}
|
||||
|
||||
|
||||
+5
-6
@@ -28,7 +28,7 @@ pub(super) fn post_process_nodes(custom: Vec<DocumentNodeDefinition>) -> HashMap
|
||||
// fallback when deriving `call_argument` so it reflects the impls actually registered, which will usually be `Context`.
|
||||
let extended_node_registry = &*interpreted_executor::node_registry::NODE_REGISTRY;
|
||||
let node_registry = NODE_REGISTRY.lock().unwrap();
|
||||
let empty_implementations: Vec<(NodeConstructor, NodeIOTypes)> = Vec::new();
|
||||
let empty_implementations: Vec<RegistryEntry> = Vec::new();
|
||||
let context_type = concrete!(Context);
|
||||
for (id, metadata) in NODE_METADATA.lock().unwrap().iter() {
|
||||
let identifier = DefinitionIdentifier::ProtoNode(id.clone());
|
||||
@@ -41,18 +41,17 @@ pub(super) fn post_process_nodes(custom: Vec<DocumentNodeDefinition>) -> HashMap
|
||||
fields,
|
||||
description,
|
||||
properties,
|
||||
context_features,
|
||||
..
|
||||
} = metadata;
|
||||
|
||||
let implementations = node_registry.get(id).unwrap_or(&empty_implementations);
|
||||
|
||||
let first_node_io = implementations.first().map(|(_, node_io)| node_io).unwrap_or(const { &NodeIOTypes::empty() });
|
||||
let first_node_io = implementations.first().map(|entry| &entry.io).unwrap_or(const { &NodeIOTypes::empty() });
|
||||
|
||||
let call_arguments: Vec<&Type> = if !implementations.is_empty() {
|
||||
implementations.iter().map(|(_, io)| &io.call_argument).collect()
|
||||
implementations.iter().map(|entry| &entry.io.call_argument).collect()
|
||||
} else if let Some(impls) = extended_node_registry.get(id) {
|
||||
impls.keys().map(|io| &io.call_argument).collect()
|
||||
impls.iter().map(|entry| &entry.io.call_argument).collect()
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
@@ -74,7 +73,7 @@ pub(super) fn post_process_nodes(custom: Vec<DocumentNodeDefinition>) -> HashMap
|
||||
inputs,
|
||||
call_argument: input_type.clone(),
|
||||
implementation: NodeTemplateImplementation::ProtoNode(id.clone()),
|
||||
context_features: ContextDependencies::from(context_features.as_slice()),
|
||||
context_features: ContextDependencies::default(),
|
||||
// TODO: Store information for input overrides in the node macro
|
||||
input_metadata: fields
|
||||
.iter()
|
||||
|
||||
@@ -60,6 +60,7 @@ pub enum NodeGraphMessage {
|
||||
DisconnectInput {
|
||||
input_connector: InputConnector,
|
||||
},
|
||||
DisconnectRootNode,
|
||||
EnterNestedNetwork,
|
||||
DuplicateSelectedNodes,
|
||||
ExposeInput {
|
||||
@@ -156,6 +157,7 @@ pub enum NodeGraphMessage {
|
||||
SetInputValue {
|
||||
node_id: NodeId,
|
||||
input_index: usize,
|
||||
// Boxed to keep the whole editor message tree small; `TaggedValue` alone is 568 bytes
|
||||
value: Box<TaggedValue>,
|
||||
},
|
||||
SetInput {
|
||||
|
||||
@@ -406,6 +406,9 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
|
||||
NodeGraphMessage::DisconnectInput { input_connector } => {
|
||||
network_interface.disconnect_input(&input_connector, selection_network_path);
|
||||
}
|
||||
NodeGraphMessage::DisconnectRootNode => {
|
||||
network_interface.start_previewing_without_restore(selection_network_path);
|
||||
}
|
||||
NodeGraphMessage::DuplicateSelectedNodes => {
|
||||
let all_selected_nodes = network_interface.upstream_chain_nodes(selection_network_path);
|
||||
|
||||
@@ -1096,8 +1099,18 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
|
||||
self.wire_in_progress_to_connector = Some(point);
|
||||
// Disconnect if the wire was previously connected to an input
|
||||
if let Some(disconnecting) = &self.disconnecting {
|
||||
// Previewing leaves the export alone, so dragging its wire off is an ordinary disconnect
|
||||
responses.add(NodeGraphMessage::DisconnectInput { input_connector: *disconnecting });
|
||||
let mut disconnect_root_node = false;
|
||||
if let Previewing::Yes { root_node_to_restore } = network_interface.previewing(selection_network_path)
|
||||
&& root_node_to_restore.is_some()
|
||||
&& *disconnecting == InputConnector::Export(0)
|
||||
{
|
||||
disconnect_root_node = true;
|
||||
}
|
||||
if disconnect_root_node {
|
||||
responses.add(NodeGraphMessage::DisconnectRootNode);
|
||||
} else {
|
||||
responses.add(NodeGraphMessage::DisconnectInput { input_connector: *disconnecting });
|
||||
}
|
||||
// Update the frontend that the node is disconnected
|
||||
responses.add(NodeGraphMessage::RunDocumentGraph);
|
||||
responses.add(NodeGraphMessage::SendGraph);
|
||||
@@ -1721,7 +1734,6 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
|
||||
responses.add(NodeGraphMessage::UpdateLayerPanel);
|
||||
responses.add(DocumentMessage::DocumentStructureChanged);
|
||||
responses.add(PropertiesPanelMessage::Refresh);
|
||||
responses.add(EventMessage::GraphChanged);
|
||||
if breadcrumb_network_path == selection_network_path && graph_view_overlay_open {
|
||||
let nodes = self.collect_nodes(network_interface, breadcrumb_network_path);
|
||||
self.frontend_nodes = nodes.iter().map(|node| node.id).collect();
|
||||
@@ -1745,6 +1757,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
|
||||
NodeGraphMessage::SetInputValue { node_id, input_index, value } => {
|
||||
use graphene_std::vector::generator_nodes::*;
|
||||
|
||||
let value = *value;
|
||||
let reference = network_interface.reference(&node_id, selection_network_path);
|
||||
let is_text_node = reference.as_ref().is_some_and(|r| *r == DefinitionIdentifier::ProtoNode(graphene_std::text::text::IDENTIFIER));
|
||||
let is_stroke_node = reference.as_ref().is_some_and(|r| *r == DefinitionIdentifier::ProtoNode(graphene_std::vector::stroke::IDENTIFIER));
|
||||
@@ -1756,7 +1769,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
|
||||
.any(|id| *r == DefinitionIdentifier::ProtoNode(id))
|
||||
});
|
||||
|
||||
let input = NodeInput::value(*value, false);
|
||||
let input = NodeInput::value(value, false);
|
||||
responses.add(NodeGraphMessage::SetInput {
|
||||
input_connector: InputConnector::node_at_index(node_id, input_index),
|
||||
input,
|
||||
@@ -2678,8 +2691,8 @@ impl NodeGraphMessageHandler {
|
||||
wire_path_update: None,
|
||||
}));
|
||||
|
||||
if let Some(wire_to_preview) = network_interface.wire_to_preview(graph_wire_style, breadcrumb_network_path) {
|
||||
added_wires.push(wire_to_preview);
|
||||
if let Some(wire_to_root) = network_interface.wire_to_root(graph_wire_style, breadcrumb_network_path) {
|
||||
added_wires.push(wire_to_root);
|
||||
} else {
|
||||
added_wires.push(WirePathUpdate {
|
||||
id: NodeId(u64::MAX),
|
||||
@@ -2691,7 +2704,7 @@ impl NodeGraphMessageHandler {
|
||||
added_wires
|
||||
}
|
||||
|
||||
pub(crate) fn collect_nodes(&self, network_interface: &mut NodeNetworkInterface, breadcrumb_network_path: &[NodeId]) -> Vec<FrontendNode> {
|
||||
fn collect_nodes(&self, network_interface: &mut NodeNetworkInterface, breadcrumb_network_path: &[NodeId]) -> Vec<FrontendNode> {
|
||||
let Some(network) = network_interface.nested_network(breadcrumb_network_path) else {
|
||||
log::error!("Could not get nested network when collecting nodes");
|
||||
return Vec::new();
|
||||
@@ -2726,12 +2739,16 @@ impl NodeGraphMessageHandler {
|
||||
(false, false)
|
||||
};
|
||||
|
||||
let is_export = network_interface
|
||||
.input_from_connector(&InputConnector::Export(0), breadcrumb_network_path)
|
||||
.is_some_and(|export| export.as_node().is_some_and(|export_node_id| node_id == export_node_id));
|
||||
let is_root_node = network_interface.root_node(breadcrumb_network_path).is_some_and(|root_node| root_node.node_id == node_id);
|
||||
|
||||
let Some(position) = network_interface.position(&node_id, breadcrumb_network_path) else {
|
||||
log::error!("Could not get position for node: {node_id}");
|
||||
continue;
|
||||
};
|
||||
// Asked of the preview itself rather than inferred from the export, which previewing no longer rewires
|
||||
let previewed = matches!(network_interface.previewing(breadcrumb_network_path), Previewing::Yes { previewed } if previewed.node_id == node_id);
|
||||
let previewed = is_export && !is_root_node;
|
||||
|
||||
let locked = network_interface.is_locked(&node_id, breadcrumb_network_path);
|
||||
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,5 +1,10 @@
|
||||
use graph_craft::document::NodeId;
|
||||
use graphene_std::{Type, simplify_identifier_name};
|
||||
use graph_craft::document::value::TaggedValue;
|
||||
use graphene_std::Type;
|
||||
use graphene_std::list::List;
|
||||
use graphene_std::raster_types::{CPU, Raster};
|
||||
use graphene_std::vector::Vector;
|
||||
use graphene_std::{Artboard, Graphic};
|
||||
|
||||
#[cfg_attr(feature = "wasm", derive(tsify::Tsify))]
|
||||
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Hash, serde::Serialize, serde::Deserialize)]
|
||||
@@ -19,22 +24,20 @@ pub enum FrontendGraphDataType {
|
||||
|
||||
impl FrontendGraphDataType {
|
||||
pub fn from_type(input: &Type) -> Self {
|
||||
// Color a wire by its element type, peeling a rank-0 `Item` or rank-1 `List` wrapper (and a whole-list `Bundle` cell) so all ranks share the element's color
|
||||
let nested_type = input.nested_type();
|
||||
let element = match nested_type.bundle_element_name() {
|
||||
Some(bundle_element) => simplify_identifier_name(bundle_element),
|
||||
None => nested_type.list_element().unwrap_or(nested_type).identifier_name(),
|
||||
};
|
||||
|
||||
match element.as_str() {
|
||||
"Vector" => Self::Vector,
|
||||
"Graphic" => Self::Graphic,
|
||||
"Artboard" => Self::Artboard,
|
||||
"Color" => Self::Color,
|
||||
"Gradient" => Self::Gradient,
|
||||
"String" => Self::Typography,
|
||||
"f64" | "f32" | "u32" | "u64" | "bool" | "DVec2" | "DAffine2" => Self::Number,
|
||||
raster if raster.starts_with("Raster") => Self::Raster,
|
||||
match TaggedValue::from_type_or_none(input) {
|
||||
TaggedValue::U32(_) | TaggedValue::U64(_) | TaggedValue::F32(_) | TaggedValue::F64(_) | TaggedValue::DVec2(_) | TaggedValue::F64Array(_) | TaggedValue::DAffine2(_) => Self::Number,
|
||||
TaggedValue::Color(_) => Self::Color,
|
||||
TaggedValue::LegacyGradient(_) | TaggedValue::GradientRamp(_) => Self::Gradient,
|
||||
TaggedValue::String(_) => Self::Typography,
|
||||
// Types whose `TaggedValue` variant has been removed are routed through `TypeDefault` and identified by the descriptor's type name.
|
||||
TaggedValue::TypeDefault(td) => match td.name.as_ref() {
|
||||
n if n == graphene_std::core_types::normalize_type_name(std::any::type_name::<List<Graphic>>()) => Self::Graphic,
|
||||
n if n == graphene_std::core_types::normalize_type_name(std::any::type_name::<List<Artboard>>()) => Self::Artboard,
|
||||
n if n == graphene_std::core_types::normalize_type_name(std::any::type_name::<List<Raster<CPU>>>()) => Self::Raster,
|
||||
n if n == graphene_std::core_types::normalize_type_name(std::any::type_name::<List<Vector>>()) => Self::Vector,
|
||||
n if n == graphene_std::core_types::normalize_type_name(std::any::type_name::<List<String>>()) => Self::Typography,
|
||||
_ => Self::General,
|
||||
},
|
||||
_ => Self::General,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1012,6 +1012,11 @@ impl OverlayContextInternal {
|
||||
self.manipulator_anchor(transform.transform_point2(point.position), false, None);
|
||||
}
|
||||
ClickTargetType::Path(bezpath) => combined.extend(bezpath.elements().iter().copied()),
|
||||
ClickTargetType::Instance { path, transform } => {
|
||||
let mut placed = (**path).clone();
|
||||
placed.apply_affine(Affine::new(transform.to_cols_array()));
|
||||
combined.extend(placed.elements().iter().copied());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -972,6 +972,11 @@ impl OverlayContext {
|
||||
self.manipulator_anchor(transform.transform_point2(point.position), false, None);
|
||||
}
|
||||
ClickTargetType::Path(bezpath) => combined.extend(bezpath.elements().iter().copied()),
|
||||
ClickTargetType::Instance { path, transform } => {
|
||||
let mut placed = (**path).clone();
|
||||
placed.apply_affine(Affine::new(transform.to_cols_array()));
|
||||
combined.extend(placed.elements().iter().copied());
|
||||
}
|
||||
});
|
||||
|
||||
if !combined.is_empty() {
|
||||
|
||||
-3
@@ -9,7 +9,6 @@ use crate::node_graph_executor::NodeGraphExecutor;
|
||||
#[derive(ExtractField)]
|
||||
pub struct PropertiesPanelMessageContext<'a> {
|
||||
pub executor: &'a mut NodeGraphExecutor,
|
||||
pub document_id: DocumentId,
|
||||
pub network_interface: &'a mut NodeNetworkInterface,
|
||||
pub resources: &'a ResourceMessageHandler,
|
||||
pub selection_network_path: &'a [NodeId],
|
||||
@@ -27,7 +26,6 @@ impl MessageHandler<PropertiesPanelMessage, PropertiesPanelMessageContext<'_>> f
|
||||
fn process_message(&mut self, message: PropertiesPanelMessage, responses: &mut VecDeque<Message>, context: PropertiesPanelMessageContext) {
|
||||
let PropertiesPanelMessageContext {
|
||||
executor,
|
||||
document_id,
|
||||
network_interface,
|
||||
resources,
|
||||
selection_network_path,
|
||||
@@ -53,7 +51,6 @@ impl MessageHandler<PropertiesPanelMessage, PropertiesPanelMessageContext<'_>> f
|
||||
let mut node_properties_context = NodePropertiesContext {
|
||||
responses,
|
||||
executor,
|
||||
document_id,
|
||||
network_interface,
|
||||
resources,
|
||||
selection_network_path,
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
//! metadata survives the conversion. The end-to-end save/reopen pipeline is covered separately in
|
||||
//! [`round_trip_tests`](super::round_trip_tests).
|
||||
|
||||
use std::collections::{BTreeSet, HashMap};
|
||||
use std::collections::HashMap;
|
||||
|
||||
use document_graph_storage::{NodeMetadataSource, PeerId, Registry};
|
||||
|
||||
@@ -57,6 +57,22 @@ fn editor_metadata_round_trip_against_demo() {
|
||||
|| !source.input_data(&network_path, local_id, i).is_empty()
|
||||
});
|
||||
|
||||
let any_metadata = expected_position.is_some()
|
||||
|| expected_is_layer
|
||||
|| expected_display.as_deref().is_some_and(|s| !s.is_empty())
|
||||
|| expected_locked
|
||||
|| expected_pinned
|
||||
|| any_input_metadata_present
|
||||
|| !expected_output_names.is_empty();
|
||||
|
||||
if !any_metadata {
|
||||
assert!(
|
||||
!entries_by_address.contains_key(&(network_path.clone(), local_id)),
|
||||
"node {local_id:?} in network {network_path:?} has no editor metadata but produced an entry"
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
let entry = entries_by_address
|
||||
.get(&(network_path.clone(), local_id))
|
||||
.unwrap_or_else(|| panic!("missing entry for node {local_id:?} in network {network_path:?}"));
|
||||
@@ -246,79 +262,6 @@ fn editor_interface_rebuild_round_trip() {
|
||||
assert!(checked_any_reference, "demo artwork produced no reference metadata: fixture is wrong or extraction is broken");
|
||||
}
|
||||
|
||||
/// The rebuild pins every node to the identity storage named it, rather than leaving it to be
|
||||
/// re-derived. Re-converting under a different peer is the sharp test: a location hash mixes the peer
|
||||
/// in, so it would produce an entirely different set of IDs.
|
||||
#[test]
|
||||
fn rebuilt_interface_keeps_storage_identities() {
|
||||
let document = load_demo("changing-seasons.graphite");
|
||||
let view = StorageMetadataView::new(&document.network_interface);
|
||||
|
||||
let network = document.network_interface.document_network().clone();
|
||||
let conversion = Registry::convert_from_runtime(&network, &view, &Default::default(), PeerId(0)).expect("convert_from_runtime failed");
|
||||
let declarations = conversion.declarations().expect("rebuild declarations");
|
||||
let registry = conversion.registry;
|
||||
let (rebuilt_network, node_entries, network_entries) = registry.to_runtime_with_full_metadata(&declarations).expect("to_runtime_with_full_metadata failed");
|
||||
|
||||
let rebuilt = build_interface_from_storage(rebuilt_network, node_entries, network_entries).expect("build_interface_from_storage failed");
|
||||
|
||||
let reconverted_network = rebuilt.document_network().clone();
|
||||
let reconverted = Registry::convert_from_runtime(&reconverted_network, &StorageMetadataView::new(&rebuilt), &Default::default(), PeerId(9)).expect("re-convert from_runtime failed");
|
||||
|
||||
let stored_ids: BTreeSet<_> = registry.node_instances.keys().copied().collect();
|
||||
let reconverted_ids: BTreeSet<_> = reconverted.registry.node_instances.keys().copied().collect();
|
||||
|
||||
assert!(!stored_ids.is_empty(), "demo artwork produced no nodes: fixture is wrong");
|
||||
assert_eq!(reconverted_ids, stored_ids, "re-converting the rebuilt interface under a different peer changed the node identities");
|
||||
}
|
||||
|
||||
/// Opening an old document runs its upgrades through the ordinary mutators, so the store records them.
|
||||
/// Those recordings are the document arriving rather than edits to it, so the migration has to leave
|
||||
/// the buffer empty instead of handing the first commit a pile of changes to the document's own
|
||||
/// starting state.
|
||||
#[test]
|
||||
fn migrating_a_document_records_no_changes() {
|
||||
let mut document = load_demo("painted-dreams.graphite");
|
||||
document.network_interface.discard_deltas();
|
||||
|
||||
crate::messages::portfolio::document_migration::document_migration_upgrades(&mut document, false);
|
||||
|
||||
let recorded = document.network_interface.take_deltas();
|
||||
assert!(recorded.is_empty(), "migration left {} recorded changes behind", recorded.len());
|
||||
}
|
||||
|
||||
/// The pinned display order is document state, so it survives a registry round trip. It names nodes and
|
||||
/// the stored form uses storage IDs, so this also checks the references resolve back to the right
|
||||
/// runtime nodes.
|
||||
#[test]
|
||||
fn pinned_order_round_trips_through_the_registry() {
|
||||
let mut document = load_demo("changing-seasons.graphite");
|
||||
|
||||
let pinned: Vec<_> = document.network_interface.document_network().nodes.keys().copied().take(3).collect();
|
||||
assert_eq!(pinned.len(), 3, "demo artwork should have at least three nodes: fixture is wrong");
|
||||
|
||||
{
|
||||
let interface = &mut document.network_interface;
|
||||
let Some(mut network) = interface.network_mut(&[]) else {
|
||||
panic!("the document network should resolve")
|
||||
};
|
||||
network.set_pinned_order(pinned.clone());
|
||||
}
|
||||
|
||||
let network = document.network_interface.document_network().clone();
|
||||
let view = StorageMetadataView::new(&document.network_interface);
|
||||
let conversion = Registry::convert_from_runtime(&network, &view, &Default::default(), PeerId(0)).expect("convert_from_runtime failed");
|
||||
let declarations = conversion.declarations().expect("rebuild declarations");
|
||||
let (rebuilt_network, node_entries, network_entries) = conversion.registry.to_runtime_with_full_metadata(&declarations).expect("to_runtime failed");
|
||||
let rebuilt = build_interface_from_storage(rebuilt_network, node_entries, network_entries).expect("build_interface_from_storage failed");
|
||||
|
||||
let rebuilt_metadata = rebuilt.network_metadata(&[]).expect("the rebuilt document network should resolve");
|
||||
assert_eq!(
|
||||
rebuilt_metadata.persistent_metadata.pinned_node_order, pinned,
|
||||
"the pinned display order did not survive the registry round trip"
|
||||
);
|
||||
}
|
||||
|
||||
/// Per-peer view settings (`ui::doc::*`) survive the `session.json` round-trip: serialize them into
|
||||
/// the view map, then apply it onto a fresh handler and confirm each field matches.
|
||||
#[test]
|
||||
|
||||
@@ -15,7 +15,6 @@ use crate::messages::portfolio::document::document_message_handler::DocumentMess
|
||||
use crate::messages::portfolio::document::utility_types::misc::GroupFolderType;
|
||||
use crate::messages::portfolio::document::utility_types::network_interface::NodeNetworkInterface;
|
||||
use crate::messages::portfolio::document::utility_types::network_interface::storage_metadata::{StorageMetadataView, build_interface_from_storage};
|
||||
use crate::messages::portfolio::ingest::utility_types::IngestAction;
|
||||
use crate::test_utils::test_prelude::*;
|
||||
use graphene_std::NodeParameter;
|
||||
use graphene_std::vector::style::RenderMode;
|
||||
@@ -491,15 +490,6 @@ async fn live_undo_new_document_draw_rect() {
|
||||
assert_eq!(editor.active_document().network_interface.document_network(), &before_rect, "undo should restore the pre-rect network");
|
||||
}
|
||||
|
||||
fn paste_named_image() -> IngestMessage {
|
||||
IngestMessage::Ingest {
|
||||
data: Image::new(2, 2, Color::WHITE).to_png(),
|
||||
action: IngestAction::Paste,
|
||||
mime_type: String::new(),
|
||||
path: Some("pasted.png".into()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Pasting an image is one user action and must be one undo step: the paste handler brackets the layer add,
|
||||
/// name set, reparent, and transform in a single transaction. Were the name set to open its own nested
|
||||
/// transaction (a historical wart), the first undo would revert only the name and leave the layer behind, so
|
||||
@@ -513,7 +503,15 @@ async fn paste_image_with_name_is_one_undo_step() {
|
||||
|
||||
// Paste with a name so the handler emits the `SetDisplayName` sub-step that historically opened its
|
||||
// own transaction. `create_raster_image` passes `name: None` and so wouldn't exercise this path.
|
||||
editor.handle_message(paste_named_image()).await;
|
||||
let image = Image::new(2, 2, Color::WHITE);
|
||||
editor
|
||||
.handle_message(PortfolioMessage::InsertImage {
|
||||
name: Some("pasted".into()),
|
||||
image,
|
||||
mouse: None,
|
||||
parent_and_insert_index: None,
|
||||
})
|
||||
.await;
|
||||
assert_eq!(
|
||||
editor.active_document().metadata().all_layers().count(),
|
||||
layers_before + 1,
|
||||
@@ -528,38 +526,6 @@ async fn paste_image_with_name_is_one_undo_step() {
|
||||
);
|
||||
}
|
||||
|
||||
/// Choosing "None" in the Image node's file picker leaves the empty-resource placeholder, which must still render.
|
||||
#[tokio::test]
|
||||
async fn image_node_with_no_file_still_evaluates() {
|
||||
use graph_craft::application_io::resource::Resource;
|
||||
use graph_craft::document::DocumentNodeImplementation;
|
||||
use graph_craft::document::value::TaggedValue;
|
||||
use graph_craft::item;
|
||||
|
||||
let mut editor = EditorTestUtils::create();
|
||||
editor.new_document().await;
|
||||
editor.create_raster_image(Image::new(2, 2, Color::WHITE), None).await;
|
||||
|
||||
let image_node_id = editor
|
||||
.active_document()
|
||||
.network_interface
|
||||
.document_network()
|
||||
.nodes
|
||||
.iter()
|
||||
.find(|(_, node)| matches!(&node.implementation, DocumentNodeImplementation::ProtoNode(identifier) if *identifier == graphene_std::raster_nodes::std_nodes::image::IDENTIFIER))
|
||||
.map(|(id, _)| *id)
|
||||
.expect("the pasted image should be an Image node");
|
||||
editor
|
||||
.handle_message(NodeGraphMessage::SetInputValue {
|
||||
node_id: image_node_id,
|
||||
input_index: graphene_std::raster_nodes::std_nodes::image::ResourceInput::INDEX,
|
||||
value: TaggedValue::TypeDefault(item!(Resource)).into(),
|
||||
})
|
||||
.await;
|
||||
|
||||
editor.eval_graph().await.expect("an Image node with no file chosen should still evaluate");
|
||||
}
|
||||
|
||||
/// Undoing an image paste reverts the interaction's `AddResource` in the `Gdd` cursor while the runtime keeps
|
||||
/// the resource alive for legacy redo, so the cursor legitimately holds fewer resources than a fresh
|
||||
/// `from_runtime`. Drives the relaxed comparison: every resource the current network references must be in
|
||||
@@ -572,7 +538,15 @@ async fn undo_image_paste_resources_subset_of_runtime() {
|
||||
let byte_store = mount_in_memory_storage(&mut editor).await;
|
||||
editor.active_document_mut().commit_storage_snapshot(&byte_store, true);
|
||||
|
||||
editor.handle_message(paste_named_image()).await;
|
||||
let image = Image::new(2, 2, Color::WHITE);
|
||||
editor
|
||||
.handle_message(PortfolioMessage::InsertImage {
|
||||
name: Some("pasted".into()),
|
||||
image,
|
||||
mouse: None,
|
||||
parent_and_insert_index: None,
|
||||
})
|
||||
.await;
|
||||
|
||||
editor.handle_message(DocumentMessage::Undo).await;
|
||||
|
||||
@@ -608,7 +582,15 @@ async fn undo_twice_steps_cursor_two_interactions() {
|
||||
editor.draw_rect(0., 0., 100., 100.).await;
|
||||
let after_rect = editor.active_document().network_interface.document_network().clone();
|
||||
|
||||
editor.handle_message(paste_named_image()).await;
|
||||
let image = Image::new(2, 2, Color::WHITE);
|
||||
editor
|
||||
.handle_message(PortfolioMessage::InsertImage {
|
||||
name: Some("pasted".into()),
|
||||
image,
|
||||
mouse: None,
|
||||
parent_and_insert_index: None,
|
||||
})
|
||||
.await;
|
||||
|
||||
// First undo: removes the paste, back to the post-rectangle network. Cursor and legacy must agree.
|
||||
editor.handle_message(DocumentMessage::Undo).await;
|
||||
@@ -693,11 +675,9 @@ async fn demo_artwork_edit_autosaves_and_round_trips() {
|
||||
// Open a real demo artwork through the normal open path and let it render.
|
||||
let content = std::fs::read_to_string("../demo-artwork/changing-seasons.graphite").expect("read demo artwork");
|
||||
editor
|
||||
.handle_message(IngestMessage::Ingest {
|
||||
data: content.into_bytes(),
|
||||
action: IngestAction::Open,
|
||||
mime_type: String::new(),
|
||||
path: Some("changing-seasons.graphite".into()),
|
||||
.handle_message(PortfolioMessage::OpenFile {
|
||||
path: "changing-seasons.graphite".into(),
|
||||
content: content.bytes().collect(),
|
||||
})
|
||||
.await;
|
||||
|
||||
@@ -761,7 +741,7 @@ async fn none_fill_survives_document_reopen() {
|
||||
.handle_message(NodeGraphMessage::SetInputValue {
|
||||
node_id: fill_node_id,
|
||||
input_index: graphene_std::vector::fill::PaintInput::INDEX,
|
||||
value: graph_craft::document::value::TaggedValue::no_paint().into(),
|
||||
value: Box::new(graph_craft::document::value::TaggedValue::no_paint()),
|
||||
})
|
||||
.await;
|
||||
assert!(fill_paint_value(editor.active_document()).is_no_paint(), "the None pick should store as no_paint");
|
||||
|
||||
@@ -20,6 +20,30 @@ pub fn load_demo(file_name: &str) -> DocumentMessageHandler {
|
||||
DocumentMessageHandler::deserialize_document(&content).unwrap_or_else(|e| panic!("Failed to deserialize {path}: {e:?}"))
|
||||
}
|
||||
|
||||
/// Dev tool: writes each demo's migrated re-save into the directory named by `DEMO_OUT`, leaving the checked-in originals untouched.
|
||||
#[test]
|
||||
#[ignore = "dev tool: set DEMO_OUT and run explicitly"]
|
||||
fn migrate_demo_artwork_into_demo_out() {
|
||||
use crate::messages::portfolio::document_migration::{
|
||||
document_migration_reset_layer_definitions, document_migration_reset_node_definition, document_migration_string_preprocessing, document_migration_upgrades,
|
||||
};
|
||||
let out_dir = std::env::var("DEMO_OUT").expect("set DEMO_OUT to the output directory");
|
||||
for entry in std::fs::read_dir("../demo-artwork").unwrap() {
|
||||
let path = entry.unwrap().path();
|
||||
if path.extension().and_then(|extension| extension.to_str()) != Some("graphite") {
|
||||
continue;
|
||||
}
|
||||
let content = std::fs::read_to_string(&path).unwrap();
|
||||
let content = document_migration_string_preprocessing(content);
|
||||
let reset = document_migration_reset_node_definition(&content);
|
||||
let reset_layers = document_migration_reset_layer_definitions(&content);
|
||||
let mut document = DocumentMessageHandler::deserialize_document(&content).unwrap_or_else(|e| panic!("Failed to deserialize {}: {e:?}", path.display()));
|
||||
document_migration_upgrades(&mut document, reset, reset_layers);
|
||||
let out = format!("{out_dir}/{}", path.file_name().unwrap().to_string_lossy());
|
||||
std::fs::write(out, document.serialize_document()).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
/// Walk every node in every nested network and collect `(network_path, local_id)` pairs, so a test can
|
||||
/// iterate every node addressable from the metadata side.
|
||||
pub fn node_paths(interface: &NodeNetworkInterface) -> Vec<(Vec<NodeId>, NodeId)> {
|
||||
|
||||
@@ -40,7 +40,8 @@ pub struct DocumentMetadata {
|
||||
/// Vector data keyed by layer ID, used as fallback when no Path node exists.
|
||||
/// This provides accurate SegmentIds for layers without explicit Path nodes.
|
||||
pub layer_vector_data: HashMap<LayerNodeIdentifier, Arc<Vector>>,
|
||||
/// Per-layer `ATTR_APPEARANCE` attribute, exposed so message handlers can read paint information that lives on the list.
|
||||
/// Per-layer resolved appearance snapshot, exposed so message handlers can
|
||||
/// read the paint and stroke parameters that live on the coverage rows.
|
||||
pub layer_appearance_attributes: HashMap<LayerNodeIdentifier, Arc<Appearance>>,
|
||||
/// Transform from document space to viewport space.
|
||||
pub document_to_viewport: DAffine2,
|
||||
@@ -188,8 +189,8 @@ impl DocumentMetadata {
|
||||
self.visual_targets(layer)?
|
||||
.iter()
|
||||
.filter_map(|click_target| match click_target.target_type() {
|
||||
ClickTargetType::Path(path) => {
|
||||
let mut transformed = path.clone();
|
||||
ClickTargetType::Path(_) | ClickTargetType::Instance { .. } => {
|
||||
let mut transformed = click_target.path_in_layer().map(|path| path.into_owned()).unwrap_or_default();
|
||||
transformed.apply_affine(Affine::new(transform.to_cols_array()));
|
||||
|
||||
let control_box = transformed.control_box();
|
||||
@@ -253,11 +254,8 @@ impl DocumentMetadata {
|
||||
self.all_layers().filter_map(|layer| self.bounding_box_viewport(layer)).reduce(Quad::combine_bounds)
|
||||
}
|
||||
|
||||
pub fn layer_outline(&self, layer: LayerNodeIdentifier) -> impl Iterator<Item = &BezPath> {
|
||||
self.visual_targets(layer).unwrap_or(&[]).iter().filter_map(|target| match target.target_type() {
|
||||
ClickTargetType::Path(path) => Some(path),
|
||||
ClickTargetType::FreePoint(_) => None,
|
||||
})
|
||||
pub fn layer_outline(&self, layer: LayerNodeIdentifier) -> impl Iterator<Item = std::borrow::Cow<'_, BezPath>> {
|
||||
self.visual_targets(layer).unwrap_or(&[]).iter().filter_map(|target| target.path_in_layer())
|
||||
}
|
||||
|
||||
pub fn layer_with_free_points_outline(&self, layer: LayerNodeIdentifier) -> impl Iterator<Item = &ClickTargetType> {
|
||||
|
||||
@@ -1,22 +1,14 @@
|
||||
mod apply;
|
||||
mod caches;
|
||||
#[cfg(test)]
|
||||
mod characterization_tests;
|
||||
mod deserialization;
|
||||
pub mod editor_delta;
|
||||
#[cfg(test)]
|
||||
mod editor_delta_tests;
|
||||
mod frontend;
|
||||
mod geometry;
|
||||
mod hit_tests;
|
||||
mod invalidation;
|
||||
mod layout;
|
||||
mod memo_network;
|
||||
mod mutations;
|
||||
mod queries;
|
||||
mod resolved_types;
|
||||
pub mod storage_metadata;
|
||||
mod store;
|
||||
mod structure;
|
||||
mod template;
|
||||
mod types;
|
||||
@@ -24,9 +16,6 @@ mod types;
|
||||
mod validation;
|
||||
mod view;
|
||||
|
||||
pub use editor_delta::{EditorDelta, NetworkMetadataChange, NodeMetadataChange};
|
||||
use store::Guarded;
|
||||
pub use store::NodeLocator;
|
||||
pub use template::*;
|
||||
pub use types::*;
|
||||
pub use view::{NetworkError, NetworkView};
|
||||
@@ -51,8 +40,6 @@ use graph_craft::Type;
|
||||
use graph_craft::application_io::resource::ResourceId;
|
||||
use graph_craft::document::value::TaggedValue;
|
||||
use graph_craft::document::{DocumentNode, DocumentNodeImplementation, NodeId, NodeInput, NodeNetwork, OldDocumentNodeImplementation, OldNodeNetwork};
|
||||
use graphene_std::Appearance;
|
||||
use graphene_std::ContextDependencies;
|
||||
use graphene_std::math::quad::Quad;
|
||||
use graphene_std::transform::Footprint;
|
||||
use graphene_std::vector::click_target::{ClickTarget, ClickTargetType, FreePoint};
|
||||
@@ -70,9 +57,9 @@ use std::sync::Arc;
|
||||
pub struct NodeNetworkInterface {
|
||||
/// The node graph that generates this document's artwork. It recursively stores its sub-graphs, so this root graph is the whole snapshot of the document content.
|
||||
/// A public mutable reference should never be created. It should only be mutated through custom setters which perform the necessary side effects to keep network_metadata in sync
|
||||
network: Guarded<MemoNetwork>,
|
||||
network: MemoNetwork,
|
||||
/// Stores all editor information for a NodeNetwork. Should automatically kept in sync by the setter methods when changes to the document network are made.
|
||||
network_metadata: Guarded<NodeNetworkMetadata>,
|
||||
network_metadata: NodeNetworkMetadata,
|
||||
// TODO: Wrap in a TransientCache
|
||||
/// Stores the document network's structural topology. Should automatically kept in sync by the setter methods when changes to the document network are made.
|
||||
#[serde(skip)]
|
||||
@@ -82,14 +69,6 @@ pub struct NodeNetworkInterface {
|
||||
pub resolved_types: ResolvedDocumentNodeTypes,
|
||||
#[serde(skip)]
|
||||
transaction_status: TransactionStatus,
|
||||
/// What the writes since the last drain changed, in write order, appended by `store.rs` alone.
|
||||
///
|
||||
/// Emitting here rather than in the mutators makes it impossible to write without saying what was
|
||||
/// written, the same way writing through the store makes it impossible to update one tree without
|
||||
/// the other. Transient: a snapshot clone starts empty, since the snapshot is a state rather than
|
||||
/// a set of changes.
|
||||
#[serde(skip)]
|
||||
deltas: Vec<EditorDelta>,
|
||||
}
|
||||
|
||||
impl Clone for NodeNetworkInterface {
|
||||
@@ -100,7 +79,6 @@ impl Clone for NodeNetworkInterface {
|
||||
document_metadata: Default::default(),
|
||||
resolved_types: Default::default(),
|
||||
transaction_status: TransactionStatus::Finished,
|
||||
deltas: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -112,14 +90,9 @@ impl PartialEq for NodeNetworkInterface {
|
||||
}
|
||||
|
||||
impl NodeNetworkInterface {
|
||||
/// Normalizes the stored types of every node at every nesting level, for an older document whose stored types predate the current form.
|
||||
pub fn normalize_stored_types(&mut self) {
|
||||
self.migrate_graph(NodeNetwork::normalize_stored_types);
|
||||
}
|
||||
|
||||
/// Add DocumentNodePath input to the PathModifyNode protonode
|
||||
pub fn migrate_path_modify_node(&mut self) {
|
||||
self.migrate_graph(fix_network);
|
||||
fix_network(self.document_network_mut());
|
||||
fn fix_network(network: &mut NodeNetwork) {
|
||||
for node in network.nodes.values_mut() {
|
||||
if let Some(network) = node.implementation.get_network_mut() {
|
||||
@@ -161,11 +134,11 @@ mod network_interface_tests {
|
||||
content: ClipboardContentRaw::Text(clipboard),
|
||||
})
|
||||
.await;
|
||||
let nodes = &editor.active_document().network_interface.document_network().nodes;
|
||||
let original = nodes.get(&rectangle).expect("original node should exist");
|
||||
let nodes = &mut editor.active_document_mut().network_interface.network_mut(&[]).unwrap().nodes;
|
||||
let orignal = nodes.remove(&rectangle).expect("original node should exist");
|
||||
assert!(
|
||||
nodes.iter().any(|(node_id, other)| *node_id != rectangle && other == original),
|
||||
"duplicated node should exist\nother nodes: {nodes:#?}\noriginal {original:#?}"
|
||||
nodes.values().any(|other| *other == orignal),
|
||||
"duplicated node should exist\nother nodes: {nodes:#?}\norignal {orignal:#?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,130 +0,0 @@
|
||||
use super::*;
|
||||
use graph_craft::runtime_delta::RuntimeDelta;
|
||||
|
||||
// Replay: putting a delta back into the interface, the inverse of the store recording one.
|
||||
//
|
||||
// Mechanism only. A mutator decides policy, validates, and lays nodes out, then records what it
|
||||
// settled on; replaying reproduces that outcome rather than deciding it again. A peer running
|
||||
// different layout rules must still end up with the state the delta describes.
|
||||
impl NodeNetworkInterface {
|
||||
/// Mirrors a delta into the interface without recording it.
|
||||
///
|
||||
/// A delta reaching here came from somewhere else, so recording it would offer a change this peer
|
||||
/// never made back to whoever sent it. Writing through the store and then dropping what the store
|
||||
/// recorded keeps the two parallel trees written by one place, which is the property the store
|
||||
/// exists for, without the echo.
|
||||
#[cfg_attr(not(test), expect(dead_code, reason = "no caller until deltas from another peer are replayed; the replay tests exercise it"))]
|
||||
pub(crate) fn apply(&mut self, delta: &EditorDelta) {
|
||||
let recorded = self.deltas.len();
|
||||
self.mirror(delta);
|
||||
self.deltas.truncate(recorded);
|
||||
}
|
||||
|
||||
fn mirror(&mut self, delta: &EditorDelta) {
|
||||
match delta {
|
||||
// The metadata arrives separately, so a node lands with default metadata that the paired
|
||||
// snapshot then fills in. Replacing an entry and adding one are the same write here; they
|
||||
// differ only in what the storage side has to remove first.
|
||||
EditorDelta::Graph(RuntimeDelta::AddNode { network_path, node_id, node }) | EditorDelta::Graph(RuntimeDelta::ReplaceNode { network_path, node_id, node }) => {
|
||||
let template = NodeTemplate::from_parts((**node).clone(), DocumentNodePersistentMetadata::default());
|
||||
self.insert_node_entry(NodeLocator::new(*node_id, network_path), template);
|
||||
}
|
||||
|
||||
EditorDelta::Graph(RuntimeDelta::RemoveNode { network_path, node_id }) => {
|
||||
self.remove_node_entry(NodeLocator::new(*node_id, network_path));
|
||||
}
|
||||
|
||||
EditorDelta::Graph(RuntimeDelta::SetInput {
|
||||
network_path,
|
||||
node_id,
|
||||
input_index,
|
||||
input,
|
||||
}) => {
|
||||
self.set_input_slot(&InputConnector::node_at_index(*node_id, *input_index), network_path, input.clone());
|
||||
}
|
||||
|
||||
EditorDelta::Graph(RuntimeDelta::SetInputs { network_path, node_id, inputs }) => {
|
||||
let Some(mut node) = self.node_mut(NodeLocator::new(*node_id, network_path)) else { return };
|
||||
|
||||
// The slots are what changed; their metadata follows in the paired delta. Resizing keeps the
|
||||
// two arrays the same length in the meantime, which the rest of the interface assumes.
|
||||
let mut input_metadata = node.input_metadata().to_vec();
|
||||
input_metadata.resize(inputs.len(), InputMetadata::default());
|
||||
node.replace_inputs(inputs.clone(), input_metadata);
|
||||
}
|
||||
|
||||
EditorDelta::Graph(RuntimeDelta::SetExport { network_path, export_index, input }) => match input {
|
||||
None => {
|
||||
self.remove_export_slot(network_path, *export_index);
|
||||
}
|
||||
// A peer can name a slot past the end of this network's exports, which is an insert here
|
||||
// rather than a write to a slot that does not exist yet.
|
||||
Some(input) if *export_index >= self.number_of_exports(network_path) => {
|
||||
self.insert_export_slot(network_path, *export_index, input.clone(), String::new());
|
||||
}
|
||||
Some(input) => {
|
||||
self.set_input_slot(&InputConnector::Export(*export_index), network_path, input.clone());
|
||||
}
|
||||
},
|
||||
|
||||
EditorDelta::Graph(RuntimeDelta::SetVisibility { network_path, node_id, visible }) => {
|
||||
if let Some(mut node) = self.node_mut(NodeLocator::new(*node_id, network_path)) {
|
||||
node.set_visible(*visible);
|
||||
}
|
||||
}
|
||||
|
||||
EditorDelta::Graph(RuntimeDelta::SetCallArgument { network_path, node_id, call_argument }) => {
|
||||
if let Some(mut node) = self.node_mut(NodeLocator::new(*node_id, network_path)) {
|
||||
node.set_call_argument(call_argument.clone());
|
||||
}
|
||||
}
|
||||
|
||||
EditorDelta::Graph(RuntimeDelta::SetContextFeatures {
|
||||
network_path,
|
||||
node_id,
|
||||
context_features,
|
||||
}) => {
|
||||
if let Some(mut node) = self.node_mut(NodeLocator::new(*node_id, network_path)) {
|
||||
node.set_context_features(*context_features);
|
||||
}
|
||||
}
|
||||
|
||||
EditorDelta::NodeMetadataSnapshot { network_path, node_id, metadata } => {
|
||||
if let Some(mut node) = self.node_mut(NodeLocator::new(*node_id, network_path)) {
|
||||
node.replace_metadata((**metadata).clone());
|
||||
}
|
||||
}
|
||||
|
||||
EditorDelta::NodeInputMetadata {
|
||||
network_path,
|
||||
node_id,
|
||||
input_metadata,
|
||||
} => {
|
||||
if let Some(mut node) = self.node_mut(NodeLocator::new(*node_id, network_path)) {
|
||||
node.set_input_metadata(input_metadata.clone());
|
||||
}
|
||||
}
|
||||
|
||||
EditorDelta::NodeMetadata { network_path, node_id, change } => {
|
||||
let Some(mut node) = self.node_mut(NodeLocator::new(*node_id, network_path)) else { return };
|
||||
match change {
|
||||
NodeMetadataChange::NodeType(node_type) => node.set_node_type(node_type.clone()),
|
||||
NodeMetadataChange::DisplayName(display_name) => node.set_display_name(display_name.clone()),
|
||||
NodeMetadataChange::Locked(locked) => node.set_locked(*locked),
|
||||
NodeMetadataChange::Pinned(pinned) => node.set_pinned(*pinned),
|
||||
NodeMetadataChange::OutputNames(output_names) => node.set_output_names(output_names.clone()),
|
||||
NodeMetadataChange::InputName { index, name } => node.set_input_name(*index, name.clone()),
|
||||
NodeMetadataChange::WidgetOverride { index, widget_override } => node.set_widget_override(*index, widget_override.clone()),
|
||||
};
|
||||
}
|
||||
|
||||
EditorDelta::NetworkMetadata { network_path, change } => {
|
||||
let Some(mut network) = self.network_mut(network_path) else { return };
|
||||
match change {
|
||||
NetworkMetadataChange::Reference(reference) => network.set_reference(reference.clone()),
|
||||
NetworkMetadataChange::PinnedOrder(order) => network.set_pinned_order(order.clone()),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+491
-110
@@ -29,48 +29,48 @@ impl NodeNetworkInterface {
|
||||
};
|
||||
self.unload_stack_dependents(network_path);
|
||||
|
||||
let Some(history) = self.selection_history_mut(network_path) else {
|
||||
let Some(network_metadata) = self.network_metadata_mut(network_path) else {
|
||||
log::error!("Could not get nested network_metadata in selected_nodes");
|
||||
return None;
|
||||
};
|
||||
|
||||
// Initialize default value if selection_undo_history is empty
|
||||
if history.undo.is_empty() {
|
||||
history.undo.push_back(SelectedNodes::default());
|
||||
if network_metadata.persistent_metadata.selection_undo_history.is_empty() {
|
||||
network_metadata.persistent_metadata.selection_undo_history.push_back(SelectedNodes::default());
|
||||
}
|
||||
|
||||
// Update history only if selection is non-empty/does not contain only artboards
|
||||
if !is_selection_empty && prev_state.as_ref() != Some(&last_selection_state) {
|
||||
history.undo.push_back(last_selection_state);
|
||||
history.redo.clear();
|
||||
network_metadata.persistent_metadata.selection_undo_history.push_back(last_selection_state);
|
||||
network_metadata.persistent_metadata.selection_redo_history.clear();
|
||||
|
||||
if history.undo.len() > crate::consts::MAX_UNDO_HISTORY_LEN {
|
||||
history.undo.pop_front();
|
||||
if network_metadata.persistent_metadata.selection_undo_history.len() > crate::consts::MAX_UNDO_HISTORY_LEN {
|
||||
network_metadata.persistent_metadata.selection_undo_history.pop_front();
|
||||
}
|
||||
}
|
||||
|
||||
history.undo.back_mut()
|
||||
network_metadata.persistent_metadata.selection_undo_history.back_mut()
|
||||
}
|
||||
|
||||
pub fn selection_step_back(&mut self, network_path: &[NodeId]) {
|
||||
let Some(history) = self.selection_history_mut(network_path) else {
|
||||
let Some(network_metadata) = self.network_metadata_mut(network_path) else {
|
||||
log::error!("Could not get nested network_metadata in selection_step_back");
|
||||
return;
|
||||
};
|
||||
|
||||
if let Some(selection_state) = history.undo.pop_back() {
|
||||
history.redo.push_front(selection_state);
|
||||
if let Some(selection_state) = network_metadata.persistent_metadata.selection_undo_history.pop_back() {
|
||||
network_metadata.persistent_metadata.selection_redo_history.push_front(selection_state);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn selection_step_forward(&mut self, network_path: &[NodeId]) {
|
||||
let Some(history) = self.selection_history_mut(network_path) else {
|
||||
let Some(network_metadata) = self.network_metadata_mut(network_path) else {
|
||||
log::error!("Could not get nested network_metadata in selection_step_forward");
|
||||
return;
|
||||
};
|
||||
|
||||
if let Some(selection_state) = history.redo.pop_front() {
|
||||
history.undo.push_back(selection_state);
|
||||
if let Some(selection_state) = network_metadata.persistent_metadata.selection_redo_history.pop_front() {
|
||||
network_metadata.persistent_metadata.selection_undo_history.push_back(selection_state);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,11 +96,11 @@ impl NodeNetworkInterface {
|
||||
}
|
||||
|
||||
pub(crate) fn try_get_stack_dependents(&mut self, network_path: &[NodeId]) -> Option<&HashMap<NodeId, LayerOwner>> {
|
||||
let Some(transient) = self.network_transient_mut(network_path) else {
|
||||
let Some(network_metadata) = self.network_metadata_mut(network_path) else {
|
||||
log::error!("Could not get nested network_metadata in try_get_stack_dependents");
|
||||
return None;
|
||||
};
|
||||
let Some(stack_dependents) = transient.stack_dependents.get_loaded_mut() else {
|
||||
let Some(stack_dependents) = network_metadata.transient_metadata.stack_dependents.get_loaded_mut() else {
|
||||
log::error!("could not load stack_dependents");
|
||||
return None;
|
||||
};
|
||||
@@ -240,14 +240,14 @@ impl NodeNetworkInterface {
|
||||
}
|
||||
|
||||
pub fn unload_stack_dependents(&mut self, network_path: &[NodeId]) {
|
||||
let Some(transient) = self.network_transient_mut(network_path) else {
|
||||
let Some(network_metadata) = self.network_metadata_mut(network_path) else {
|
||||
log::error!("Could not get nested network_metadata in unload_stack_dependents");
|
||||
return;
|
||||
};
|
||||
transient.stack_dependents.unload();
|
||||
network_metadata.transient_metadata.stack_dependents.unload();
|
||||
|
||||
// Drag offsets are only meaningful relative to the stack dependents snapshot they were accumulated against, so they must not outlive it
|
||||
transient.drag_offsets.borrow_mut().clear();
|
||||
network_metadata.transient_metadata.drag_offsets.borrow_mut().clear();
|
||||
}
|
||||
|
||||
/// The vertical distance the node has been pushed from its resting position during the current drag.
|
||||
@@ -274,13 +274,13 @@ impl NodeNetworkInterface {
|
||||
}
|
||||
|
||||
pub fn import_export_ports(&mut self, network_path: &[NodeId]) -> Option<&Ports> {
|
||||
self.load_import_export_ports(network_path);
|
||||
self.try_load_import_export_ports(network_path);
|
||||
|
||||
let Some(transient) = self.network_transient_mut(network_path) else {
|
||||
let Some(network_metadata) = self.network_metadata_mut(network_path) else {
|
||||
log::error!("Could not get nested network_metadata in export_ports");
|
||||
return None;
|
||||
};
|
||||
let Some(ports) = transient.import_export_ports.get_loaded_mut() else {
|
||||
let Some(ports) = network_metadata.transient_metadata.import_export_ports.get_loaded_mut() else {
|
||||
log::error!("could not load import ports");
|
||||
return None;
|
||||
};
|
||||
@@ -289,26 +289,54 @@ impl NodeNetworkInterface {
|
||||
|
||||
/// Reads the import/export ports through &self, loading them first if needed.
|
||||
pub(crate) fn with_import_export_ports<R>(&self, network_path: &[NodeId], read: impl FnOnce(&Ports) -> R) -> Option<R> {
|
||||
self.network_metadata(network_path)?
|
||||
.transient_metadata
|
||||
.import_export_ports
|
||||
.with_loaded_or(|| self.compute_import_export_ports(network_path), read)
|
||||
self.try_load_import_export_ports(network_path);
|
||||
self.network_metadata(network_path)?.transient_metadata.import_export_ports.with_loaded(read)
|
||||
}
|
||||
|
||||
pub fn load_import_export_ports(&self, network_path: &[NodeId]) {
|
||||
fn try_load_import_export_ports(&self, network_path: &[NodeId]) {
|
||||
let Some(network_metadata) = self.network_metadata(network_path) else {
|
||||
log::error!("Could not get nested network_metadata in export_ports");
|
||||
return;
|
||||
};
|
||||
network_metadata.transient_metadata.import_export_ports.ensure_loaded(|| self.compute_import_export_ports(network_path));
|
||||
if !network_metadata.transient_metadata.import_export_ports.is_loaded() {
|
||||
self.load_import_export_ports(network_path);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn load_import_export_ports(&self, network_path: &[NodeId]) {
|
||||
let Some(import_export_position) = self.import_export_position(network_path) else {
|
||||
log::error!("Could not get import_export_position");
|
||||
return;
|
||||
};
|
||||
let Some(network) = self.nested_network(network_path) else { return };
|
||||
let mut import_export_ports = Ports::new();
|
||||
|
||||
if !network_path.is_empty() {
|
||||
let import_start_index = if self.hidden_primary_import(network_path) { 1 } else { 0 };
|
||||
for import_index in import_start_index..self.number_of_imports(network_path) {
|
||||
import_export_ports.insert_output_port_at_center(import_index, import_export_position.0.as_dvec2() + DVec2::new(0., import_index as f64 * 24.));
|
||||
}
|
||||
}
|
||||
|
||||
let export_start_index = if self.hidden_primary_export(network_path) { 1 } else { 0 };
|
||||
for export_index in export_start_index..network.exports.len() {
|
||||
import_export_ports.insert_input_port_at_center(export_index, import_export_position.1.as_dvec2() + DVec2::new(0., export_index as f64 * 24.));
|
||||
}
|
||||
|
||||
let Some(network_metadata) = self.network_metadata(network_path) else {
|
||||
log::error!("Could not get current network in load_export_ports");
|
||||
return;
|
||||
};
|
||||
|
||||
network_metadata.transient_metadata.import_export_ports.store(import_export_ports);
|
||||
}
|
||||
|
||||
pub(crate) fn unload_import_export_ports(&mut self, network_path: &[NodeId]) {
|
||||
let Some(transient) = self.network_transient_mut(network_path) else {
|
||||
let Some(network_metadata) = self.network_metadata_mut(network_path) else {
|
||||
log::error!("Could not get nested network_metadata in unload_export_ports");
|
||||
return;
|
||||
};
|
||||
transient.import_export_ports.unload();
|
||||
network_metadata.transient_metadata.import_export_ports.unload();
|
||||
|
||||
// Always unload all wires connected to them as well
|
||||
let number_of_imports = self.number_of_imports(network_path);
|
||||
@@ -336,13 +364,18 @@ impl NodeNetworkInterface {
|
||||
}
|
||||
|
||||
pub fn modify_import_export(&mut self, network_path: &[NodeId]) -> Option<&ModifyImportExportClickTarget> {
|
||||
self.load_modify_import_export(network_path);
|
||||
|
||||
let Some(transient) = self.network_transient_mut(network_path) else {
|
||||
let Some(network_metadata) = self.network_metadata(network_path) else {
|
||||
log::error!("Could not get nested network_metadata in modify_import_export");
|
||||
return None;
|
||||
};
|
||||
let Some(click_targets) = transient.modify_import_export.get_loaded_mut() else {
|
||||
if !network_metadata.transient_metadata.modify_import_export.is_loaded() {
|
||||
self.load_modify_import_export(network_path);
|
||||
}
|
||||
let Some(network_metadata) = self.network_metadata_mut(network_path) else {
|
||||
log::error!("Could not get nested network_metadata in modify_import_export");
|
||||
return None;
|
||||
};
|
||||
let Some(click_targets) = network_metadata.transient_metadata.modify_import_export.get_loaded_mut() else {
|
||||
log::error!("could not load modify import export ports");
|
||||
return None;
|
||||
};
|
||||
@@ -350,22 +383,74 @@ impl NodeNetworkInterface {
|
||||
}
|
||||
|
||||
pub fn load_modify_import_export(&self, network_path: &[NodeId]) {
|
||||
let mut reorder_imports_exports = Ports::new();
|
||||
let mut remove_imports_exports = Ports::new();
|
||||
|
||||
if !network_path.is_empty() {
|
||||
let ports_built = self.with_import_export_ports(network_path, |import_exports| {
|
||||
for (import_index, import_click_target) in import_exports.output_ports() {
|
||||
let Some(import_bounding_box) = import_click_target.bounding_box() else {
|
||||
log::error!("Could not get export bounding box in load_modify_import_export");
|
||||
continue;
|
||||
};
|
||||
let reorder_import_center = (import_bounding_box[0] + import_bounding_box[1]) / 2. + DVec2::new(-12., 0.);
|
||||
|
||||
if *import_index == 0 {
|
||||
let remove_import_center = reorder_import_center + DVec2::new(-4., 0.);
|
||||
let remove_import = ClickTarget::new_with_path(rectangle_path(remove_import_center - DVec2::new(8., 8.), remove_import_center + DVec2::new(8., 8.)), 0.);
|
||||
remove_imports_exports.insert_custom_output_port(*import_index, remove_import);
|
||||
} else {
|
||||
let remove_import_center = reorder_import_center + DVec2::new(-12., 0.);
|
||||
let reorder_import = ClickTarget::new_with_path(rectangle_path(reorder_import_center - DVec2::new(3., 4.), reorder_import_center + DVec2::new(3., 4.)), 0.);
|
||||
let remove_import = ClickTarget::new_with_path(rectangle_path(remove_import_center - DVec2::new(8., 8.), remove_import_center + DVec2::new(8., 8.)), 0.);
|
||||
reorder_imports_exports.insert_custom_output_port(*import_index, reorder_import);
|
||||
remove_imports_exports.insert_custom_output_port(*import_index, remove_import);
|
||||
}
|
||||
}
|
||||
|
||||
for (export_index, export_click_target) in import_exports.input_ports() {
|
||||
let Some(export_bounding_box) = export_click_target.bounding_box() else {
|
||||
log::error!("Could not get export bounding box in load_modify_import_export");
|
||||
continue;
|
||||
};
|
||||
let reorder_export_center = (export_bounding_box[0] + export_bounding_box[1]) / 2. + DVec2::new(12., 0.);
|
||||
|
||||
if *export_index == 0 {
|
||||
let remove_export_center = reorder_export_center + DVec2::new(4., 0.);
|
||||
let remove_export = ClickTarget::new_with_path(rectangle_path(remove_export_center - DVec2::new(8., 8.), remove_export_center + DVec2::new(8., 8.)), 0.);
|
||||
remove_imports_exports.insert_custom_input_port(*export_index, remove_export);
|
||||
} else {
|
||||
let remove_export_center = reorder_export_center + DVec2::new(12., 0.);
|
||||
let reorder_export = ClickTarget::new_with_path(rectangle_path(reorder_export_center - DVec2::new(3., 4.), reorder_export_center + DVec2::new(3., 4.)), 0.);
|
||||
let remove_export = ClickTarget::new_with_path(rectangle_path(remove_export_center - DVec2::new(8., 8.), remove_export_center + DVec2::new(8., 8.)), 0.);
|
||||
reorder_imports_exports.insert_custom_input_port(*export_index, reorder_export);
|
||||
remove_imports_exports.insert_custom_input_port(*export_index, remove_export);
|
||||
}
|
||||
}
|
||||
});
|
||||
if ports_built.is_none() {
|
||||
log::error!("Could not get import_export_ports in load_modify_import_export");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
let Some(network_metadata) = self.network_metadata(network_path) else {
|
||||
log::error!("Could not get nested network_metadata in modify_import_export");
|
||||
log::error!("Could not get current network in load_modify_import_export");
|
||||
return;
|
||||
};
|
||||
network_metadata
|
||||
.transient_metadata
|
||||
.modify_import_export
|
||||
.ensure_loaded(|| self.compute_modify_import_export(network_path));
|
||||
|
||||
network_metadata.transient_metadata.modify_import_export.store(ModifyImportExportClickTarget {
|
||||
remove_imports_exports,
|
||||
reorder_imports_exports,
|
||||
});
|
||||
}
|
||||
|
||||
pub(crate) fn unload_modify_import_export(&mut self, network_path: &[NodeId]) {
|
||||
let Some(transient) = self.network_transient_mut(network_path) else {
|
||||
let Some(network_metadata) = self.network_metadata_mut(network_path) else {
|
||||
log::error!("Could not get nested network_metadata in unload_export_ports");
|
||||
return;
|
||||
};
|
||||
transient.modify_import_export.unload();
|
||||
network_metadata.transient_metadata.modify_import_export.unload();
|
||||
}
|
||||
|
||||
/// Reads the owned nodes of a layer through &self if they are loaded.
|
||||
@@ -383,47 +468,51 @@ impl NodeNetworkInterface {
|
||||
return None;
|
||||
};
|
||||
|
||||
let bounding_box = network_metadata
|
||||
.transient_metadata
|
||||
.all_nodes_bounding_box
|
||||
.with_loaded_or(|| self.compute_all_nodes_bounding_box(network_path), |bounds| *bounds);
|
||||
if !network_metadata.transient_metadata.all_nodes_bounding_box.is_loaded() {
|
||||
self.load_all_nodes_bounding_box(network_path);
|
||||
}
|
||||
|
||||
let bounding_box = self.network_metadata(network_path)?.transient_metadata.all_nodes_bounding_box.with_loaded(|bounds| *bounds);
|
||||
if bounding_box.is_none() {
|
||||
log::error!("could not load all nodes bounding box");
|
||||
}
|
||||
bounding_box
|
||||
}
|
||||
|
||||
/// The combined bounds of every node in the network, in node graph space.
|
||||
fn compute_all_nodes_bounding_box(&self, network_path: &[NodeId]) -> Option<[DVec2; 2]> {
|
||||
let network_metadata = self.network_metadata(network_path)?;
|
||||
pub fn load_all_nodes_bounding_box(&self, network_path: &[NodeId]) {
|
||||
let Some(network_metadata) = self.network_metadata(network_path) else {
|
||||
log::error!("Could not get nested network_metadata in load_all_nodes_bounding_box");
|
||||
return;
|
||||
};
|
||||
let nodes = network_metadata.persistent_metadata.node_metadata.keys().copied().collect::<Vec<_>>();
|
||||
|
||||
Some(
|
||||
nodes
|
||||
.iter()
|
||||
.filter_map(|node_id| self.node_bounding_box(node_id, network_path))
|
||||
.reduce(Quad::combine_bounds)
|
||||
.unwrap_or([DVec2::new(0., 0.), DVec2::new(0., 0.)]),
|
||||
)
|
||||
let all_nodes_bounding_box = nodes
|
||||
.iter()
|
||||
.filter_map(|node_id| self.node_bounding_box(node_id, network_path))
|
||||
.reduce(Quad::combine_bounds)
|
||||
.unwrap_or([DVec2::new(0., 0.), DVec2::new(0., 0.)]);
|
||||
|
||||
let Some(network_metadata) = self.network_metadata(network_path) else { return };
|
||||
network_metadata.transient_metadata.all_nodes_bounding_box.store(all_nodes_bounding_box);
|
||||
}
|
||||
|
||||
pub fn unload_all_nodes_bounding_box(&mut self, network_path: &[NodeId]) {
|
||||
let Some(transient) = self.network_transient_mut(network_path) else {
|
||||
let Some(network_metadata) = self.network_metadata_mut(network_path) else {
|
||||
log::error!("Could not get nested network_metadata in unload_all_nodes_bounding_box");
|
||||
return;
|
||||
};
|
||||
transient.all_nodes_bounding_box.unload();
|
||||
network_metadata.transient_metadata.all_nodes_bounding_box.unload();
|
||||
self.unload_import_export_ports(network_path);
|
||||
}
|
||||
|
||||
pub fn outward_wires(&mut self, network_path: &[NodeId]) -> Option<&HashMap<OutputConnector, Vec<InputConnector>>> {
|
||||
self.load_outward_wires(network_path);
|
||||
self.try_load_outward_wires(network_path);
|
||||
|
||||
let Some(transient) = self.network_transient_mut(network_path) else {
|
||||
let Some(network_metadata) = self.network_metadata_mut(network_path) else {
|
||||
log::error!("Could not get nested network_metadata in outward_wires");
|
||||
return None;
|
||||
};
|
||||
let Some(outward_wires) = transient.outward_wires.get_loaded_mut() else {
|
||||
let Some(outward_wires) = network_metadata.transient_metadata.outward_wires.get_loaded_mut() else {
|
||||
log::error!("could not load outward wires");
|
||||
return None;
|
||||
};
|
||||
@@ -433,29 +522,28 @@ impl NodeNetworkInterface {
|
||||
|
||||
/// Reads the outward wires through &self, loading them first if needed.
|
||||
pub(crate) fn with_outward_wires<R>(&self, network_path: &[NodeId], read: impl FnOnce(&HashMap<OutputConnector, Vec<InputConnector>>) -> R) -> Option<R> {
|
||||
self.network_metadata(network_path)?
|
||||
.transient_metadata
|
||||
.outward_wires
|
||||
.with_loaded_or(|| self.compute_outward_wires(network_path), read)
|
||||
self.try_load_outward_wires(network_path);
|
||||
self.network_metadata(network_path)?.transient_metadata.outward_wires.with_loaded(read)
|
||||
}
|
||||
|
||||
fn load_outward_wires(&self, network_path: &[NodeId]) {
|
||||
fn try_load_outward_wires(&self, network_path: &[NodeId]) {
|
||||
let Some(network_metadata) = self.network_metadata(network_path) else {
|
||||
log::error!("Could not get nested network_metadata in outward_wires");
|
||||
return;
|
||||
};
|
||||
network_metadata.transient_metadata.outward_wires.ensure_loaded(|| self.compute_outward_wires(network_path));
|
||||
if !network_metadata.transient_metadata.outward_wires.is_loaded() {
|
||||
self.load_outward_wires(network_path);
|
||||
}
|
||||
}
|
||||
|
||||
/// Every input fed by each node output and each import of the network.
|
||||
fn compute_outward_wires(&self, network_path: &[NodeId]) -> Option<HashMap<OutputConnector, Vec<InputConnector>>> {
|
||||
fn load_outward_wires(&self, network_path: &[NodeId]) {
|
||||
let mut outward_wires = HashMap::new();
|
||||
let Some(network) = self.nested_network(network_path) else {
|
||||
log::error!("Could not get nested network in compute_outward_wires");
|
||||
return None;
|
||||
log::error!("Could not get nested network in load_outward_wires");
|
||||
return;
|
||||
};
|
||||
// Initialize all output connectors for nodes
|
||||
for node_id in network.nodes.keys() {
|
||||
for (node_id, _) in network.nodes.iter() {
|
||||
let number_of_outputs = self.number_of_outputs(node_id, network_path);
|
||||
for output_index in 0..number_of_outputs {
|
||||
outward_wires.insert(OutputConnector::node(*node_id, output_index), Vec::new());
|
||||
@@ -495,7 +583,9 @@ impl NodeNetworkInterface {
|
||||
}
|
||||
}
|
||||
|
||||
Some(outward_wires)
|
||||
let Some(network_metadata) = self.network_metadata(network_path) else { return };
|
||||
|
||||
network_metadata.transient_metadata.outward_wires.store(outward_wires);
|
||||
}
|
||||
|
||||
pub(crate) fn unload_outward_wires(&mut self, network_path: &[NodeId]) {
|
||||
@@ -510,10 +600,10 @@ impl NodeNetworkInterface {
|
||||
/// avoiding a full rebuild. If the cache is not loaded, this is a no-op (it will be fully
|
||||
/// rebuilt on the next read via `outward_wires()`).
|
||||
pub(crate) fn update_outward_wires(&mut self, network_path: &[NodeId], input_connector: &InputConnector, old_input: &NodeInput, new_input: &NodeInput) {
|
||||
let Some(transient) = self.network_transient_mut(network_path) else {
|
||||
let Some(network_metadata) = self.network_metadata_mut(network_path) else {
|
||||
return;
|
||||
};
|
||||
let Some(outward_wires) = transient.outward_wires.get_loaded_mut() else {
|
||||
let Some(outward_wires) = network_metadata.transient_metadata.outward_wires.get_loaded_mut() else {
|
||||
return;
|
||||
};
|
||||
|
||||
@@ -540,23 +630,55 @@ impl NodeNetworkInterface {
|
||||
return None;
|
||||
}
|
||||
|
||||
node_metadata
|
||||
.transient_metadata
|
||||
.layer_width
|
||||
.with_loaded_or(|| Some(self.compute_layer_width(node_id, network_path)), |layer_width| *layer_width)
|
||||
if !node_metadata.transient_metadata.layer_width.is_loaded() {
|
||||
self.load_layer_width(node_id, network_path);
|
||||
}
|
||||
|
||||
let node_metadata = self.node_metadata(node_id, network_path)?;
|
||||
node_metadata.transient_metadata.layer_width.with_loaded(|layer_width| *layer_width)
|
||||
}
|
||||
|
||||
pub fn load_layer_width(&self, node_id: &NodeId, network_path: &[NodeId]) {
|
||||
const GAP_WIDTH: f64 = 8.;
|
||||
const FONT_SIZE: f64 = 14.;
|
||||
let left_thumbnail_padding = GRID_SIZE as f64 / 2.;
|
||||
let thumbnail_width = 3. * GRID_SIZE as f64;
|
||||
let layer_text = self.display_name(node_id, network_path);
|
||||
|
||||
let text_width = text_width(&layer_text, FONT_SIZE);
|
||||
|
||||
let grip_padding = 4.;
|
||||
let grip_width = 8.;
|
||||
let lock_icon_width = if self.is_locked(node_id, network_path) { GRID_SIZE as f64 } else { 0. };
|
||||
let icon_overhang_width = GRID_SIZE as f64 / 2.;
|
||||
|
||||
let layer_width_pixels = left_thumbnail_padding + thumbnail_width + GAP_WIDTH + text_width + grip_padding + grip_width + lock_icon_width + icon_overhang_width;
|
||||
let layer_width = ((layer_width_pixels / 24.).ceil() as u32).max(8);
|
||||
|
||||
let Some(node_metadata) = self.node_metadata(node_id, network_path) else {
|
||||
log::error!("Could not get nested node_metadata in load_layer_width");
|
||||
return;
|
||||
};
|
||||
|
||||
// Ensure layer width is not loaded for a non layer node
|
||||
if node_metadata.persistent_metadata.is_layer() {
|
||||
node_metadata.transient_metadata.layer_width.store(layer_width);
|
||||
} else {
|
||||
log::warn!("Tried loading layer width for non layer node");
|
||||
}
|
||||
}
|
||||
|
||||
/// Unloads layer width if the node is a layer
|
||||
pub fn try_unload_layer_width(&mut self, node_id: &NodeId, network_path: &[NodeId]) {
|
||||
let is_layer = self.is_layer(node_id, network_path);
|
||||
|
||||
let Some(transient) = self.node_transient_mut(node_id, network_path) else {
|
||||
let Some(node_metadata) = self.node_metadata_mut(node_id, network_path) else {
|
||||
return;
|
||||
};
|
||||
|
||||
// If the node is a layer, then the width and click targets need to be recalculated
|
||||
if is_layer {
|
||||
transient.layer_width.unload();
|
||||
node_metadata.transient_metadata.layer_width.unload();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -688,27 +810,26 @@ impl NodeNetworkInterface {
|
||||
network_metadata.transient_metadata.wires.borrow_mut().remove(input);
|
||||
}
|
||||
|
||||
/// The dashed wire from the previewed node to the export, drawn alongside the solid wire the export
|
||||
/// is really connected to.
|
||||
///
|
||||
/// Previewing does not rewire the export, so both are shown: the solid wire says what the document
|
||||
/// renders, and this one says what this peer is looking at instead.
|
||||
pub fn wire_to_preview(&self, graph_wire_style: GraphWireStyle, network_path: &[NodeId]) -> Option<WirePathUpdate> {
|
||||
/// When previewing, there may be a second path to the root node.
|
||||
pub fn wire_to_root(&self, graph_wire_style: GraphWireStyle, network_path: &[NodeId]) -> Option<WirePathUpdate> {
|
||||
let input = InputConnector::Export(0);
|
||||
let current_export = self.upstream_output_connector(&input, network_path)?;
|
||||
|
||||
let Previewing::Yes { previewed } = self.previewing(network_path) else { return None };
|
||||
let root_node = match self.previewing(network_path) {
|
||||
Previewing::Yes { root_node_to_restore } => root_node_to_restore,
|
||||
Previewing::No => None,
|
||||
}?;
|
||||
|
||||
// The export already reaches it, so a second wire would land on top of the solid one
|
||||
if self.upstream_output_connector(&input, network_path).and_then(|export| export.node_id()) == Some(previewed.node_id) {
|
||||
if Some(root_node.node_id) == current_export.node_id() {
|
||||
return None;
|
||||
}
|
||||
let Some(input_position) = self.get_input_center(&input, network_path) else {
|
||||
log::error!("Could not get input position for wire end in preview: {input:?}");
|
||||
log::error!("Could not get input position for wire end in root node: {input:?}");
|
||||
return None;
|
||||
};
|
||||
let upstream_output = OutputConnector::node(previewed.node_id, previewed.output_index);
|
||||
let upstream_output = OutputConnector::node(root_node.node_id, root_node.output_index);
|
||||
let Some(output_position) = self.get_output_center(&upstream_output, network_path) else {
|
||||
log::error!("Could not get output position for wire start in preview: {upstream_output:?}");
|
||||
log::error!("Could not get output position for wire start in root node: {upstream_output:?}");
|
||||
return None;
|
||||
};
|
||||
let vertical_end = input.node_id().is_some_and(|node_id| self.is_layer(&node_id, network_path) && input.input_index() == 0);
|
||||
@@ -782,38 +903,46 @@ impl NodeNetworkInterface {
|
||||
}
|
||||
|
||||
pub fn node_click_targets(&mut self, node_id: &NodeId, network_path: &[NodeId]) -> Option<&DocumentNodeClickTargets> {
|
||||
self.load_node_click_targets(node_id, network_path);
|
||||
self.try_load_node_click_targets(node_id, network_path);
|
||||
|
||||
let transient = self.node_transient_mut(node_id, network_path)?;
|
||||
let Some(click_targets) = transient.click_targets.get_loaded_mut() else {
|
||||
let node_metadata = self.node_metadata_mut(node_id, network_path)?;
|
||||
let Some(click_targets) = node_metadata.transient_metadata.click_targets.get_loaded_mut() else {
|
||||
log::error!("Could not load node type metadata when getting click targets");
|
||||
return None;
|
||||
};
|
||||
Some(click_targets)
|
||||
}
|
||||
|
||||
pub(crate) fn load_node_click_targets(&self, node_id: &NodeId, network_path: &[NodeId]) {
|
||||
pub(crate) fn try_load_node_click_targets(&self, node_id: &NodeId, network_path: &[NodeId]) {
|
||||
let Some(node_metadata) = self.node_metadata(node_id, network_path) else {
|
||||
log::error!("Could not get nested node_metadata in node_click_targets");
|
||||
return;
|
||||
};
|
||||
node_metadata.transient_metadata.click_targets.ensure_loaded(|| self.compute_node_click_targets(node_id, network_path));
|
||||
if !node_metadata.transient_metadata.click_targets.is_loaded() {
|
||||
self.load_node_click_targets(node_id, network_path)
|
||||
};
|
||||
}
|
||||
|
||||
/// Loads the node click targets if needed, then reads them through &self.
|
||||
pub(crate) fn with_node_click_targets<R>(&self, node_id: &NodeId, network_path: &[NodeId], read: impl FnOnce(&DocumentNodeClickTargets) -> R) -> Option<R> {
|
||||
self.node_metadata(node_id, network_path)?
|
||||
.transient_metadata
|
||||
.click_targets
|
||||
.with_loaded_or(|| self.compute_node_click_targets(node_id, network_path), read)
|
||||
self.try_load_node_click_targets(node_id, network_path);
|
||||
self.with_node_click_targets_if_loaded(node_id, network_path, read)
|
||||
}
|
||||
|
||||
/// Reads the modify import/export click targets through &self, loading them first if needed.
|
||||
pub(crate) fn with_modify_import_export<R>(&self, network_path: &[NodeId], read: impl FnOnce(&ModifyImportExportClickTarget) -> R) -> Option<R> {
|
||||
self.network_metadata(network_path)?
|
||||
.transient_metadata
|
||||
.modify_import_export
|
||||
.with_loaded_or(|| self.compute_modify_import_export(network_path), read)
|
||||
self.try_load_modify_import_export(network_path);
|
||||
self.network_metadata(network_path)?.transient_metadata.modify_import_export.with_loaded(read)
|
||||
}
|
||||
|
||||
fn try_load_modify_import_export(&self, network_path: &[NodeId]) {
|
||||
let Some(network_metadata) = self.network_metadata(network_path) else {
|
||||
log::error!("Could not get nested network_metadata in modify_import_export");
|
||||
return;
|
||||
};
|
||||
if !network_metadata.transient_metadata.modify_import_export.is_loaded() {
|
||||
self.load_modify_import_export(network_path);
|
||||
}
|
||||
}
|
||||
|
||||
/// Reads the node click targets through &self if they are already loaded.
|
||||
@@ -826,8 +955,179 @@ impl NodeNetworkInterface {
|
||||
result
|
||||
}
|
||||
|
||||
pub fn load_node_click_targets(&self, node_id: &NodeId, network_path: &[NodeId]) {
|
||||
let Some(node_position) = self.position_from_downstream_node(node_id, network_path) else {
|
||||
log::error!("Could not get node position in load_node_click_targets for node {node_id}");
|
||||
return;
|
||||
};
|
||||
let Some(node_metadata) = self.node_metadata(node_id, network_path) else {
|
||||
log::error!("Could not get nested node_metadata in load_node_click_targets");
|
||||
return;
|
||||
};
|
||||
let Some(document_node) = self.document_node(node_id, network_path) else {
|
||||
log::error!("Could not get document node in load_node_click_targets");
|
||||
return;
|
||||
};
|
||||
|
||||
let node_top_left = node_position.as_dvec2() * GRID_SIZE as f64;
|
||||
let mut port_click_targets = Ports::new();
|
||||
let document_node_click_targets = if !node_metadata.persistent_metadata.is_layer() {
|
||||
// Create input/output click targets
|
||||
let mut input_row_count = 0;
|
||||
for (input_index, input) in document_node.inputs.iter().enumerate() {
|
||||
if input.is_exposed() {
|
||||
port_click_targets.insert_node_input(input_index, input_row_count, node_top_left);
|
||||
}
|
||||
// Primary input row is always displayed, even if the input is not exposed
|
||||
if input_index == 0 || input.is_exposed() {
|
||||
input_row_count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
let number_of_outputs = match &document_node.implementation {
|
||||
DocumentNodeImplementation::Network(network) => network.exports.len(),
|
||||
_ => 1,
|
||||
};
|
||||
// If the node has a hidden primary output, do not display the first output
|
||||
let start_index = if self.hidden_primary_output(node_id, network_path) { 1 } else { 0 };
|
||||
for output_index in start_index..number_of_outputs {
|
||||
port_click_targets.insert_node_output(output_index, node_top_left);
|
||||
}
|
||||
|
||||
let height = input_row_count.max(number_of_outputs).max(1) as u32 * GRID_SIZE;
|
||||
let width = 5 * GRID_SIZE;
|
||||
// Offset down by half a grid so the click target sits below the top connector strip.
|
||||
let node_click_target_top_left = node_top_left + DVec2::new(0., HALF_GRID_SIZE as f64);
|
||||
let node_click_target_bottom_right = node_click_target_top_left + DVec2::new(width as f64, height as f64);
|
||||
|
||||
let radius = 3.;
|
||||
let path = rounded_rectangle_path(node_click_target_top_left, node_click_target_bottom_right, [radius; 4]);
|
||||
let node_click_target = ClickTarget::new_with_path(path, 0.);
|
||||
|
||||
DocumentNodeClickTargets {
|
||||
node_click_target,
|
||||
port_click_targets,
|
||||
node_type_metadata: NodeTypeClickTargets::Node,
|
||||
}
|
||||
} else {
|
||||
// Layer inputs
|
||||
port_click_targets.insert_layer_input(0, node_top_left);
|
||||
if document_node.inputs.iter().filter(|input| input.is_exposed()).count() > 1 {
|
||||
port_click_targets.insert_layer_input(1, node_top_left);
|
||||
}
|
||||
port_click_targets.insert_layer_output(node_top_left);
|
||||
|
||||
let layer_width_cells = self.layer_width(node_id, network_path).unwrap_or_else(|| {
|
||||
log::error!("Could not get layer width in load_node_click_targets");
|
||||
0
|
||||
});
|
||||
let width = layer_width_cells * GRID_SIZE;
|
||||
let height = 2 * GRID_SIZE;
|
||||
let locked = self.is_locked(node_id, network_path);
|
||||
|
||||
// The layer is `2 * GRID_SIZE` tall, so its vertical center sits one grid unit below `node_top_left.y`.
|
||||
// Visibility/lock buttons fill a 1-grid-cell square (so half-extents of HALF_GRID_SIZE each side of center).
|
||||
const LAYER_VERTICAL_CENTER: f64 = GRID_SIZE as f64;
|
||||
const ICON_HALF_EXTENT: f64 = HALF_GRID_SIZE as f64;
|
||||
|
||||
// Update visibility button click target
|
||||
let visibility_offset = node_top_left + DVec2::new(width as f64, LAYER_VERTICAL_CENTER);
|
||||
let path = rounded_rectangle_path(
|
||||
DVec2::new(-ICON_HALF_EXTENT, -ICON_HALF_EXTENT) + visibility_offset,
|
||||
DVec2::new(ICON_HALF_EXTENT, ICON_HALF_EXTENT) + visibility_offset,
|
||||
[3.; 4],
|
||||
);
|
||||
let visibility_click_target = ClickTarget::new_with_path(path, 0.);
|
||||
|
||||
// Update lock button click target, positioned one grid unit to the left of the visibility button (only when locked)
|
||||
let lock_click_target = if locked {
|
||||
let lock_offset = node_top_left + DVec2::new(width as f64 - GRID_SIZE as f64, LAYER_VERTICAL_CENTER);
|
||||
let path = rounded_rectangle_path(
|
||||
DVec2::new(-ICON_HALF_EXTENT, -ICON_HALF_EXTENT) + lock_offset,
|
||||
DVec2::new(ICON_HALF_EXTENT, ICON_HALF_EXTENT) + lock_offset,
|
||||
[3.; 4],
|
||||
);
|
||||
Some(ClickTarget::new_with_path(path, 0.))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
// Update grip button click target, which is positioned to the left of the leftmost icon.
|
||||
// The grip is 8px wide but spans the full layer-vertical-center band.
|
||||
const GRIP_WIDTH: f64 = 8.;
|
||||
let icons_width = if locked { GRID_SIZE as f64 } else { 0. };
|
||||
let grip_offset_right_edge = node_top_left + DVec2::new(width as f64 - ICON_HALF_EXTENT - icons_width, LAYER_VERTICAL_CENTER);
|
||||
let path = rounded_rectangle_path(
|
||||
DVec2::new(-GRIP_WIDTH, -ICON_HALF_EXTENT) + grip_offset_right_edge,
|
||||
DVec2::new(0., ICON_HALF_EXTENT) + grip_offset_right_edge,
|
||||
[0.; 4],
|
||||
);
|
||||
let grip_click_target = ClickTarget::new_with_path(path, 0.);
|
||||
|
||||
// Update display-name text click target, used to detect double-click rename. Sized to the text bounds
|
||||
// (not the surrounding `.details` area) so the rest of the layer still drills into the subgraph on double-click.
|
||||
|
||||
/// `.layer` margin-left (= 12), for chain layers the negative margin-left and positive padding-left cancel out, keeping content at this same offset
|
||||
const LAYER_LEFT_MARGIN: f64 = HALF_GRID_SIZE as f64;
|
||||
/// `.thumbnail` (70px) + its 1px side margins (= 72)
|
||||
const THUMBNAIL_BLOCK_WIDTH: f64 = 3. * GRID_SIZE as f64;
|
||||
/// `.details` margin-left
|
||||
const DETAILS_LEFT_MARGIN: f64 = 8.;
|
||||
const NAME_LEFT_OFFSET: f64 = LAYER_LEFT_MARGIN + THUMBNAIL_BLOCK_WIDTH + DETAILS_LEFT_MARGIN;
|
||||
/// Distance from layer's right edge to visibility's left edge (= 12)
|
||||
const VISIBILITY_INSET_FROM_LAYER_RIGHT: f64 = HALF_GRID_SIZE as f64;
|
||||
const FONT_SIZE: f64 = 14.;
|
||||
|
||||
let display_name = self.display_name(node_id, network_path);
|
||||
let name_click_target = if display_name.is_empty() {
|
||||
None
|
||||
} else {
|
||||
let name_left = node_top_left.x + NAME_LEFT_OFFSET;
|
||||
let icons_reserve = VISIBILITY_INSET_FROM_LAYER_RIGHT + icons_width + GRIP_WIDTH;
|
||||
let name_right_max = node_top_left.x + width as f64 - icons_reserve;
|
||||
let name_width = text_width(&display_name, FONT_SIZE);
|
||||
let name_right = (name_left + name_width).min(name_right_max);
|
||||
if name_right > name_left {
|
||||
// The 1-grid-tall name strip is centered vertically in the 2-grid-tall layer.
|
||||
let name_top = node_top_left.y + HALF_GRID_SIZE as f64;
|
||||
let name_bottom = node_top_left.y + GRID_SIZE as f64 + HALF_GRID_SIZE as f64;
|
||||
let path = rounded_rectangle_path(DVec2::new(name_left, name_top), DVec2::new(name_right, name_bottom), [3.; 4]);
|
||||
Some(ClickTarget::new_with_path(path, 0.))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
};
|
||||
|
||||
// Create layer click target, which is contains the layer and the chain background
|
||||
let chain_width_grid_spaces = self.chain_width(node_id, network_path);
|
||||
|
||||
let node_bottom_right = node_top_left + DVec2::new(width as f64, height as f64);
|
||||
let chain_top_left = node_top_left - DVec2::new((chain_width_grid_spaces * GRID_SIZE) as f64, 0.);
|
||||
const CORNER_RADIUS: f64 = 10.;
|
||||
let path = rounded_rectangle_path(chain_top_left, node_bottom_right, [CORNER_RADIUS; 4]);
|
||||
let node_click_target = ClickTarget::new_with_path(path, 0.);
|
||||
|
||||
DocumentNodeClickTargets {
|
||||
node_click_target,
|
||||
port_click_targets,
|
||||
node_type_metadata: NodeTypeClickTargets::Layer(Box::new(LayerClickTargets {
|
||||
visibility_click_target,
|
||||
lock_click_target,
|
||||
grip_click_target,
|
||||
name_click_target,
|
||||
})),
|
||||
}
|
||||
};
|
||||
|
||||
let Some(node_metadata) = self.node_metadata(node_id, network_path) else {
|
||||
log::error!("Could not get nested node_metadata in load_node_click_targets");
|
||||
return;
|
||||
};
|
||||
node_metadata.transient_metadata.click_targets.store(document_node_click_targets);
|
||||
}
|
||||
|
||||
pub fn node_bounding_box(&self, node_id: &NodeId, network_path: &[NodeId]) -> Option<[DVec2; 2]> {
|
||||
self.load_node_click_targets(node_id, network_path);
|
||||
self.try_load_node_click_targets(node_id, network_path);
|
||||
self.try_get_node_bounding_box(node_id, network_path)
|
||||
}
|
||||
|
||||
@@ -836,22 +1136,103 @@ impl NodeNetworkInterface {
|
||||
.flatten()
|
||||
}
|
||||
|
||||
pub fn load_all_node_click_targets(&self, network_path: &[NodeId]) {
|
||||
pub fn try_load_all_node_click_targets(&self, network_path: &[NodeId]) {
|
||||
let Some(network) = self.nested_network(network_path) else {
|
||||
log::error!("Could not get network in load_all_node_click_targets");
|
||||
return;
|
||||
};
|
||||
for node_id in network.nodes.keys().cloned().collect::<Vec<_>>() {
|
||||
self.load_node_click_targets(&node_id, network_path);
|
||||
self.try_load_node_click_targets(&node_id, network_path);
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the top left position in node graph coordinates for a node by recursively iterating downstream through cached positions, which means the iteration can be broken once a known position is reached.
|
||||
pub fn position_from_downstream_node(&self, node_id: &NodeId, network_path: &[NodeId]) -> Option<IVec2> {
|
||||
let Some(node_metadata) = self.node_metadata(node_id, network_path) else {
|
||||
log::error!("Could not get nested node_metadata in position_from_downstream_node");
|
||||
return None;
|
||||
};
|
||||
match &node_metadata.persistent_metadata.node_type_metadata {
|
||||
NodeTypePersistentMetadata::Layer(layer_metadata) => {
|
||||
match layer_metadata.position {
|
||||
LayerPosition::Absolute(position) => Some(position),
|
||||
LayerPosition::Stack(y_offset) => {
|
||||
let Some(downstream_node_connectors) = self
|
||||
.with_outward_wires(network_path, |outward_wires| outward_wires.get(&OutputConnector::primary_output(*node_id)).cloned())
|
||||
.flatten()
|
||||
else {
|
||||
log::error!("Could not get downstream node in position_from_downstream_node");
|
||||
return None;
|
||||
};
|
||||
let downstream_connector = downstream_node_connectors
|
||||
.iter()
|
||||
.find_map(|input_connector| input_connector.node_id().map(|node_id| (node_id, input_connector.input_index())));
|
||||
|
||||
let Some((downstream_node_id, _)) = downstream_connector else {
|
||||
log::error!("Could not get downstream node input connector for node {node_id}");
|
||||
return None;
|
||||
};
|
||||
// Get the height of the node to ensure nodes do not overlap
|
||||
let Some(downstream_node_height) = self.height_from_click_target(&downstream_node_id, network_path) else {
|
||||
log::error!("Could not get click target height in position_from_downstream_node");
|
||||
return None;
|
||||
};
|
||||
self.position(&downstream_node_id, network_path)
|
||||
.map(|position| position + IVec2::new(0, 1 + downstream_node_height as i32 + y_offset as i32))
|
||||
}
|
||||
}
|
||||
}
|
||||
NodeTypePersistentMetadata::Node(node_metadata) => {
|
||||
match node_metadata.position {
|
||||
NodePosition::Absolute(position) => Some(position),
|
||||
NodePosition::Chain => {
|
||||
// Iterate through primary flow to find the first Layer
|
||||
let mut current_node_id = *node_id;
|
||||
let mut node_distance_from_layer = 1;
|
||||
loop {
|
||||
// TODO: Use root node to restore if previewing
|
||||
let Some(downstream_node_connectors) = self
|
||||
.with_outward_wires(network_path, |outward_wires| outward_wires.get(&OutputConnector::primary_output(current_node_id)).cloned())
|
||||
.flatten()
|
||||
else {
|
||||
log::error!("Could not get downstream node for node {node_id} with Position::Chain");
|
||||
return None;
|
||||
};
|
||||
let Some(downstream_node_id) = downstream_node_connectors.iter().find_map(|input_connector| {
|
||||
if let InputConnector::Node { node_id, input_index } = input_connector {
|
||||
let downstream_input_index = if self.is_layer(node_id, network_path) { 1 } else { 0 };
|
||||
if *input_index == downstream_input_index { Some(node_id) } else { None }
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}) else {
|
||||
log::error!("Could not get downstream node input connector with input index 1 for node with Position::Chain");
|
||||
return None;
|
||||
};
|
||||
let Some(downstream_node_metadata) = self.network_metadata(network_path)?.persistent_metadata.node_metadata.get(downstream_node_id) else {
|
||||
log::error!("Downstream node metadata not found in node_metadata for node with Position::Chain");
|
||||
return None;
|
||||
};
|
||||
if downstream_node_metadata.persistent_metadata.is_layer() {
|
||||
// Get the position of the layer
|
||||
let layer_position = self.position(downstream_node_id, network_path)?;
|
||||
return Some(layer_position + IVec2::new(-node_distance_from_layer * NODE_CHAIN_WIDTH, 0));
|
||||
}
|
||||
node_distance_from_layer += 1;
|
||||
current_node_id = *downstream_node_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn unload_node_click_targets(&mut self, node_id: &NodeId, network_path: &[NodeId]) {
|
||||
let Some(transient) = self.node_transient_mut(node_id, network_path) else {
|
||||
let Some(node_metadata) = self.node_metadata_mut(node_id, network_path) else {
|
||||
log::error!("Could not get nested node_metadata in unload_node_click_target");
|
||||
return;
|
||||
};
|
||||
transient.click_targets.unload();
|
||||
node_metadata.transient_metadata.click_targets.unload();
|
||||
self.unload_wires_for_node(node_id, network_path);
|
||||
}
|
||||
|
||||
|
||||
+30
-147
@@ -126,50 +126,29 @@ async fn cyclic_connection_is_rejected_without_side_effects() {
|
||||
assert_invariants(&editor, "after rejecting a cyclic connection");
|
||||
}
|
||||
|
||||
/// The check answers for the network with the proposed input substituted, so it has to see a loop that
|
||||
/// closes through intermediate nodes rather than only one that connects two neighbours.
|
||||
#[tokio::test]
|
||||
async fn a_cycle_closing_through_a_chain_is_rejected() {
|
||||
let mut editor = EditorTestUtils::create();
|
||||
editor.new_document().await;
|
||||
|
||||
let a = editor.create_node_by_name(rectangle_definition()).await;
|
||||
let b = editor.create_node_by_name(rectangle_definition()).await;
|
||||
let c = editor.create_node_by_name(rectangle_definition()).await;
|
||||
|
||||
let network_interface = &mut editor.active_document_mut().network_interface;
|
||||
network_interface.set_input(&InputConnector::node_at_index(a, 1), NodeInput::node(b, 0), &[]);
|
||||
network_interface.set_input(&InputConnector::node_at_index(b, 1), NodeInput::node(c, 0), &[]);
|
||||
|
||||
// `a` already reaches `c` through `b`, so feeding `a` back into `c` closes a three-node loop
|
||||
let input_before = network_interface.input_from_connector(&InputConnector::node_at_index(c, 1), &[]).cloned();
|
||||
network_interface.set_input(&InputConnector::node_at_index(c, 1), NodeInput::node(a, 0), &[]);
|
||||
|
||||
let input_after = network_interface.input_from_connector(&InputConnector::node_at_index(c, 1), &[]).cloned();
|
||||
assert_eq!(input_before, input_after, "A cycle closing through an intermediate node should be rejected");
|
||||
|
||||
assert_invariants(&editor, "after rejecting a chained cyclic connection");
|
||||
}
|
||||
|
||||
/// An export is not something a node takes as input, so connecting one cannot close a loop and must
|
||||
/// not be refused.
|
||||
#[tokio::test]
|
||||
async fn connecting_an_export_is_never_cyclic() {
|
||||
async fn toggling_preview_on_a_disconnected_export() {
|
||||
let mut editor = EditorTestUtils::create();
|
||||
editor.new_document().await;
|
||||
|
||||
let node = editor.create_node_by_name(rectangle_definition()).await;
|
||||
|
||||
let network_interface = &mut editor.active_document_mut().network_interface;
|
||||
network_interface.set_input(&InputConnector::Export(0), NodeInput::node(node, 0), &[]);
|
||||
network_interface.disconnect_input(&InputConnector::Export(0), &[]);
|
||||
|
||||
assert_eq!(
|
||||
network_interface.input_from_connector(&InputConnector::Export(0), &[]).cloned(),
|
||||
Some(NodeInput::node(node, 0)),
|
||||
"Connecting a node to the export should be accepted"
|
||||
);
|
||||
// Previewing a node while the export is disconnected is a preview with nothing to restore
|
||||
network_interface.toggle_preview(node, &[]);
|
||||
assert_eq!(network_interface.previewing(&[]), Previewing::Yes { root_node_to_restore: None });
|
||||
let export = network_interface.input_from_connector(&InputConnector::Export(0), &[]);
|
||||
assert_eq!(export.and_then(|input| input.as_node()), Some(node), "The previewed node should be wired to the export");
|
||||
|
||||
assert_invariants(&editor, "after connecting the export");
|
||||
// Ending the preview restores the disconnected export
|
||||
network_interface.toggle_preview(node, &[]);
|
||||
assert_eq!(network_interface.previewing(&[]), Previewing::No);
|
||||
let export = network_interface.input_from_connector(&InputConnector::Export(0), &[]);
|
||||
assert!(export.is_some_and(|input| input.as_node().is_none()), "Ending the preview should disconnect the export again");
|
||||
|
||||
assert_invariants(&editor, "after toggling preview twice");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -381,10 +360,8 @@ async fn signature_edits_keep_parallel_metadata_in_sync() {
|
||||
assert_invariants(&editor, "after removing the added export");
|
||||
}
|
||||
|
||||
/// Previewing renders a different node without rewiring anything: the export keeps whatever it is
|
||||
/// connected to, so ending a preview has nothing to restore and cannot disconnect anything.
|
||||
#[tokio::test]
|
||||
async fn previewing_leaves_the_export_alone() {
|
||||
async fn toggle_preview_transitions_with_a_connected_export() {
|
||||
let mut editor = EditorTestUtils::create();
|
||||
editor.new_document().await;
|
||||
|
||||
@@ -396,125 +373,31 @@ async fn previewing_leaves_the_export_alone() {
|
||||
let export_node = |network_interface: &super::NodeNetworkInterface| network_interface.input_from_connector(&InputConnector::Export(0), &[]).and_then(|input| input.as_node());
|
||||
assert_eq!(export_node(network_interface), Some(artboard));
|
||||
|
||||
// Previewing a node names it without touching the export
|
||||
// Previewing a node remembers the artboard as the connection to restore
|
||||
network_interface.toggle_preview(node, &[]);
|
||||
assert_eq!(export_node(network_interface), Some(node));
|
||||
assert_eq!(
|
||||
network_interface.previewing(&[]),
|
||||
Previewing::Yes {
|
||||
previewed: RootNode { node_id: node, output_index: 0 }
|
||||
root_node_to_restore: Some(RootNode { node_id: artboard, output_index: 0 })
|
||||
}
|
||||
);
|
||||
assert_eq!(export_node(network_interface), Some(artboard), "Previewing must not rewire the export");
|
||||
|
||||
// Previewing a different node moves the preview, still without touching the export
|
||||
network_interface.toggle_preview(artboard, &[]);
|
||||
assert_eq!(
|
||||
network_interface.previewing(&[]),
|
||||
Previewing::Yes {
|
||||
previewed: RootNode { node_id: artboard, output_index: 0 }
|
||||
}
|
||||
);
|
||||
// Toggling the previewed node again restores the artboard connection
|
||||
network_interface.toggle_preview(node, &[]);
|
||||
assert_eq!(export_node(network_interface), Some(artboard));
|
||||
|
||||
// Toggling the previewed node again ends the preview, leaving the export as it always was
|
||||
network_interface.toggle_preview(artboard, &[]);
|
||||
assert_eq!(network_interface.previewing(&[]), Previewing::No);
|
||||
|
||||
// Toggling the restore node while previewing promotes it to the export with nothing left to restore
|
||||
network_interface.toggle_preview(node, &[]);
|
||||
network_interface.toggle_preview(artboard, &[]);
|
||||
assert_eq!(export_node(network_interface), Some(artboard));
|
||||
assert_eq!(network_interface.previewing(&[]), Previewing::Yes { root_node_to_restore: None });
|
||||
|
||||
// Toggling it once more ends the preview by disconnecting the export entirely
|
||||
network_interface.toggle_preview(artboard, &[]);
|
||||
assert_eq!(export_node(network_interface), None);
|
||||
assert_eq!(network_interface.previewing(&[]), Previewing::No);
|
||||
|
||||
assert_invariants(&editor, "after cycling through the preview states");
|
||||
}
|
||||
|
||||
/// The graph handed to the compiler renders the previewed node, which is the whole point of a preview
|
||||
/// that does not rewire the document.
|
||||
#[tokio::test]
|
||||
async fn the_evaluated_network_renders_the_previewed_node() {
|
||||
let mut editor = EditorTestUtils::create();
|
||||
editor.new_document().await;
|
||||
|
||||
let artboard = NodeId::new();
|
||||
editor.handle_message(new_artboard_message(artboard)).await;
|
||||
let node = editor.create_node_by_name_at(rectangle_definition(), 0, 20).await;
|
||||
|
||||
let network_interface = &mut editor.active_document_mut().network_interface;
|
||||
network_interface.toggle_preview(node, &[]);
|
||||
|
||||
let evaluated = network_interface.network_to_evaluate();
|
||||
assert_eq!(
|
||||
evaluated.exports.first().and_then(|export| export.as_node()),
|
||||
Some(node),
|
||||
"The network being evaluated should export the previewed node"
|
||||
);
|
||||
assert_eq!(
|
||||
network_interface.document_network().exports.first().and_then(|export| export.as_node()),
|
||||
Some(artboard),
|
||||
"The document itself should be unchanged"
|
||||
);
|
||||
}
|
||||
|
||||
/// The previewed node is marked for the frontend so it can be highlighted. Derived from the preview
|
||||
/// itself: it used to be inferred from the export, which previewing no longer rewires, so inferring it
|
||||
/// would silently mark nothing.
|
||||
#[tokio::test]
|
||||
async fn the_previewed_node_is_flagged_for_the_frontend() {
|
||||
use crate::messages::portfolio::document::node_graph::NodeGraphMessageHandler;
|
||||
|
||||
let mut editor = EditorTestUtils::create();
|
||||
editor.new_document().await;
|
||||
|
||||
let artboard = NodeId::new();
|
||||
editor.handle_message(new_artboard_message(artboard)).await;
|
||||
let node = editor.create_node_by_name_at(rectangle_definition(), 0, 20).await;
|
||||
|
||||
let handler = NodeGraphMessageHandler::default();
|
||||
let network_interface = &mut editor.active_document_mut().network_interface;
|
||||
|
||||
let flagged = |handler: &NodeGraphMessageHandler, network_interface: &mut super::NodeNetworkInterface| {
|
||||
handler
|
||||
.collect_nodes(network_interface, &[])
|
||||
.into_iter()
|
||||
.filter(|node| node.previewed)
|
||||
.map(|node| node.id)
|
||||
.collect::<Vec<_>>()
|
||||
};
|
||||
|
||||
assert!(flagged(&handler, network_interface).is_empty(), "Nothing is previewed to begin with");
|
||||
|
||||
network_interface.toggle_preview(node, &[]);
|
||||
assert_eq!(flagged(&handler, network_interface), vec![node], "The previewed node should be the one flagged");
|
||||
|
||||
network_interface.toggle_preview(node, &[]);
|
||||
assert!(flagged(&handler, network_interface).is_empty(), "Ending the preview should unflag it");
|
||||
}
|
||||
|
||||
/// Resolving a batch of positions shares one downstream walk, so it has to agree with resolving each
|
||||
/// node on its own. A stack is the case that matters: every layer walks through the ones below it, so
|
||||
/// a shared memo is what keeps the batch from being quadratic.
|
||||
#[tokio::test]
|
||||
async fn batched_positions_agree_with_resolving_each_node() {
|
||||
let mut editor = EditorTestUtils::create();
|
||||
editor.new_document().await;
|
||||
editor.handle_message(new_artboard_message(NodeId::new())).await;
|
||||
|
||||
for offset in 0..4 {
|
||||
editor.draw_rect(0., offset as f64 * 20., 100., offset as f64 * 20. + 10.).await;
|
||||
}
|
||||
|
||||
let network_interface = &editor.active_document().network_interface;
|
||||
let node_ids = network_interface.document_network().nodes.keys().copied().collect::<Vec<_>>();
|
||||
assert!(node_ids.len() > 4, "the fixture should build a stack, found {} nodes", node_ids.len());
|
||||
|
||||
let batched = network_interface.positions(node_ids.iter().copied(), &[]);
|
||||
let individually = node_ids
|
||||
.iter()
|
||||
.filter_map(|node_id| network_interface.position(node_id, &[]).map(|position| (*node_id, position)))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
assert_eq!(batched.len(), individually.len(), "The batch should resolve exactly the nodes that resolve on their own");
|
||||
for (node_id, position) in individually {
|
||||
assert_eq!(
|
||||
batched.iter().find(|(batched_id, _)| *batched_id == node_id).map(|(_, position)| *position),
|
||||
Some(position),
|
||||
"Batched position disagrees for node {node_id}"
|
||||
);
|
||||
}
|
||||
}
|
||||
-2
@@ -141,8 +141,6 @@ impl From<DocumentNodePersistentMetadataStringReference> for DocumentNodePersist
|
||||
metadata.persistent_metadata.reference = old.reference;
|
||||
}
|
||||
DocumentNodePersistentMetadata {
|
||||
// Predates stored identities, so this node falls back to a hash of its location
|
||||
storage_id: None,
|
||||
display_name: old.display_name,
|
||||
input_metadata: old.input_metadata,
|
||||
output_names: old.output_names,
|
||||
|
||||
-770
@@ -1,770 +0,0 @@
|
||||
use super::storage_metadata::position_from_runtime;
|
||||
use super::{DocumentNodeMetadata, DocumentNodePersistentMetadata, LayerPosition, NodePosition, NodeTypePersistentMetadata};
|
||||
use super::{InputMetadata, InputPersistentMetadata};
|
||||
use document_graph_storage::attr::network as network_attr;
|
||||
use document_graph_storage::attr::node as node_attr;
|
||||
use document_graph_storage::from_runtime::{ConversionError, DeclarationBytes};
|
||||
use document_graph_storage::{AttributeDelta, Attributes, Implementation, NodeMetadataSource, PathResolver, Position, Registry, RegistryDelta, ScopedConversion, TimeStamp};
|
||||
use document_graph_storage::{convert_input_attributes, convert_resource_entry, encode_input_ui_attributes, encode_node_ui_attributes, node_value_resource_refs, value_resource_ref};
|
||||
use graph_craft::application_io::resource::{ResourceId, ResourceRegistry};
|
||||
use graph_craft::document::NodeId;
|
||||
use graph_craft::runtime_delta::RuntimeDelta;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
/// A [`RuntimeDelta`] extended with the editor-only change kinds, which carry the `ui::*` metadata
|
||||
/// the compiler has no use for. The compiler consumes only the `Graph` variant.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum EditorDelta {
|
||||
Graph(RuntimeDelta),
|
||||
/// Every `ui::*` attribute of a node that has just been added, including everything nested under
|
||||
/// it, so one delta covers a group and its contents.
|
||||
///
|
||||
/// Asserting the whole set is sound here precisely because the node is new: every field was just
|
||||
/// written, so there is no concurrent peer holding state for it to clobber. An edit to an existing
|
||||
/// node must use [`EditorDelta::NodeMetadata`] instead.
|
||||
NodeMetadataSnapshot {
|
||||
network_path: Vec<NodeId>,
|
||||
node_id: NodeId,
|
||||
metadata: Box<DocumentNodePersistentMetadata>,
|
||||
},
|
||||
/// One field of an existing node's metadata.
|
||||
NodeMetadata {
|
||||
network_path: Vec<NodeId>,
|
||||
node_id: NodeId,
|
||||
change: NodeMetadataChange,
|
||||
},
|
||||
/// A node's whole input metadata array, paired with the `SetInputs` that changed the slots it
|
||||
/// indexes. Whole-array for the same reason: an insert shifts every later entry.
|
||||
NodeInputMetadata {
|
||||
network_path: Vec<NodeId>,
|
||||
node_id: NodeId,
|
||||
input_metadata: Vec<InputMetadata>,
|
||||
},
|
||||
/// One field of an existing network's metadata.
|
||||
NetworkMetadata {
|
||||
network_path: Vec<NodeId>,
|
||||
change: NetworkMetadataChange,
|
||||
},
|
||||
}
|
||||
|
||||
/// One field of a node's persistent metadata, named the way the store writes it so each write has
|
||||
/// exactly one delta. Every variant carries the post-change value, never a difference.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum NodeMetadataChange {
|
||||
/// Whether the node is displayed as a layer and where it sits, which are one choice: a layer and a
|
||||
/// node do not have the same kinds of position. Encodes to `ui::position` and `ui::is_layer`, which
|
||||
/// merge independently, so a concurrent move and a concurrent layer toggle both survive.
|
||||
NodeType(NodeTypePersistentMetadata),
|
||||
DisplayName(String),
|
||||
Locked(bool),
|
||||
Pinned(bool),
|
||||
/// The whole vec, since the encoding is one array-valued attribute rather than a slot each.
|
||||
OutputNames(Vec<String>),
|
||||
InputName {
|
||||
index: usize,
|
||||
name: String,
|
||||
},
|
||||
WidgetOverride {
|
||||
index: usize,
|
||||
widget_override: Option<String>,
|
||||
},
|
||||
}
|
||||
|
||||
/// One field of a network's persistent metadata. The navigation transform and width are absent
|
||||
/// deliberately: they are per-peer view state, persisted to `session.json` rather than the registry.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum NetworkMetadataChange {
|
||||
/// The definition the network was instantiated from, dropped once it is edited away from it.
|
||||
Reference(Option<String>),
|
||||
/// The whole order, since the encoding is one array-valued attribute rather than a slot each.
|
||||
PinnedOrder(Vec<NodeId>),
|
||||
}
|
||||
|
||||
pub struct ConstructedOps {
|
||||
pub ops: Vec<RegistryDelta>,
|
||||
pub declaration_bytes: DeclarationBytes,
|
||||
}
|
||||
|
||||
/// Constructs the storage ops for one gesture's deltas, in delta order. Removal closures and
|
||||
/// resource liveness are computed against the whole batch, since several removals in one gesture
|
||||
/// can jointly orphan a resource that each alone would not. Op timestamps are placeholders,
|
||||
/// re-stamped by the staging clock.
|
||||
///
|
||||
/// `metadata` addresses each delta's node by the identity the interface holds for it, so the ops
|
||||
/// land on the same nodes a whole-document conversion of that interface would produce.
|
||||
pub fn construct_batch(
|
||||
deltas: &[EditorDelta],
|
||||
working: &Registry,
|
||||
resources: &ResourceRegistry,
|
||||
metadata: &dyn NodeMetadataSource,
|
||||
peer: document_graph_storage::PeerId,
|
||||
) -> Result<ConstructedOps, ConversionError> {
|
||||
let identities = IdentitiesOnly(metadata);
|
||||
let resolver = PathResolver::new(Some(&identities), peer);
|
||||
let mut batch = BatchRegistry::new(working);
|
||||
let mut ops = Vec::new();
|
||||
let mut declaration_bytes = DeclarationBytes::new();
|
||||
let mut batch_removed_nodes = Vec::new();
|
||||
|
||||
// In delta order, so each delta reads what the ones before it did. Removals accumulate as they are
|
||||
// met rather than being gathered up front, since a removal can name a node an earlier delta added.
|
||||
for delta in deltas {
|
||||
delta.construct(resources, peer, &identities, &resolver, &mut batch, &mut batch_removed_nodes, &mut ops, &mut declaration_bytes)?;
|
||||
}
|
||||
|
||||
batch_removed_nodes.sort();
|
||||
batch_removed_nodes.dedup();
|
||||
construct_resource_removals(&batch_removed_nodes, &batch, &mut ops);
|
||||
Ok(ConstructedOps { ops, declaration_bytes })
|
||||
}
|
||||
|
||||
impl EditorDelta {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn construct(
|
||||
&self,
|
||||
resources: &ResourceRegistry,
|
||||
peer: document_graph_storage::PeerId,
|
||||
identities: &dyn NodeMetadataSource,
|
||||
resolver: &PathResolver,
|
||||
batch: &mut BatchRegistry,
|
||||
batch_removed_nodes: &mut Vec<document_graph_storage::NodeId>,
|
||||
ops: &mut Vec<RegistryDelta>,
|
||||
declaration_bytes: &mut DeclarationBytes,
|
||||
) -> Result<(), ConversionError> {
|
||||
match self {
|
||||
EditorDelta::Graph(RuntimeDelta::AddNode { network_path, node_id, node }) => {
|
||||
construct_structural_additions(network_path, *node_id, node, batch, resources, identities, peer, ops, declaration_bytes)?;
|
||||
}
|
||||
|
||||
EditorDelta::Graph(RuntimeDelta::ReplaceNode { network_path, node_id, node }) => {
|
||||
construct_removals(resolver.node_id(network_path, *node_id), batch, batch_removed_nodes, ops);
|
||||
construct_structural_additions(network_path, *node_id, node, batch, resources, identities, peer, ops, declaration_bytes)?;
|
||||
}
|
||||
|
||||
EditorDelta::Graph(RuntimeDelta::RemoveNode { network_path, node_id }) => {
|
||||
construct_removals(resolver.node_id(network_path, *node_id), batch, batch_removed_nodes, ops);
|
||||
}
|
||||
|
||||
EditorDelta::Graph(RuntimeDelta::SetVisibility { network_path, node_id, visible }) => {
|
||||
ops.push(RegistryDelta::ChangeNodeAttribute {
|
||||
id: resolver.node_id(network_path, *node_id),
|
||||
delta: AttributeDelta {
|
||||
key: node_attr::VISIBLE.to_string(),
|
||||
value: (!visible).then_some(serde_json::Value::Bool(false)),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
EditorDelta::Graph(RuntimeDelta::SetInput {
|
||||
network_path,
|
||||
node_id,
|
||||
input_index,
|
||||
input,
|
||||
}) => {
|
||||
ops.push(RegistryDelta::ChangeNodeInput {
|
||||
id: resolver.node_id(network_path, *node_id),
|
||||
index: (*input_index).try_into().map_err(|_| ConversionError::IndexOverflow(*input_index))?,
|
||||
new_input: resolver.convert_input_at(input, network_path)?,
|
||||
});
|
||||
}
|
||||
|
||||
EditorDelta::Graph(RuntimeDelta::SetExport { network_path, export_index, input }) => {
|
||||
ops.push(RegistryDelta::SetNetworkExport {
|
||||
id: resolver.network_id(network_path),
|
||||
index: (*export_index).try_into().map_err(|_| ConversionError::IndexOverflow(*export_index))?,
|
||||
export: input.as_ref().map(|input| resolver.convert_input_at(input, network_path)).transpose()?,
|
||||
});
|
||||
}
|
||||
|
||||
EditorDelta::Graph(RuntimeDelta::SetCallArgument { network_path, node_id, call_argument }) => {
|
||||
ops.push(RegistryDelta::ChangeNodeAttribute {
|
||||
id: resolver.node_id(network_path, *node_id),
|
||||
delta: document_graph_storage::from_runtime::encode_call_argument(call_argument)?,
|
||||
});
|
||||
}
|
||||
|
||||
EditorDelta::Graph(RuntimeDelta::SetContextFeatures {
|
||||
network_path,
|
||||
node_id,
|
||||
context_features,
|
||||
}) => {
|
||||
ops.push(RegistryDelta::ChangeNodeAttribute {
|
||||
id: resolver.node_id(network_path, *node_id),
|
||||
delta: document_graph_storage::from_runtime::encode_context_features(context_features)?,
|
||||
});
|
||||
}
|
||||
|
||||
EditorDelta::NodeMetadataSnapshot { network_path, node_id, metadata } => {
|
||||
construct_metadata_snapshot(network_path, *node_id, metadata, batch, resolver, ops)?;
|
||||
}
|
||||
|
||||
EditorDelta::Graph(RuntimeDelta::SetInputs { network_path, node_id, inputs }) => {
|
||||
// Only the slots are written, so the node's attributes and everything nested under it are
|
||||
// left as they are: an edit made earlier in this batch is not reverted by the rebuild.
|
||||
// The slots' `ui::*` attributes arrive with the paired input metadata delta.
|
||||
let inputs = inputs
|
||||
.iter()
|
||||
.map(|input| {
|
||||
Ok(document_graph_storage::InputSlot {
|
||||
input: resolver.convert_input_at(input, network_path)?,
|
||||
timestamp: TimeStamp::ORIGIN,
|
||||
attributes: convert_input_attributes(input)?,
|
||||
})
|
||||
})
|
||||
.collect::<Result<Vec<_>, ConversionError>>()?;
|
||||
|
||||
ops.push(RegistryDelta::SetNodeInputs {
|
||||
id: resolver.node_id(network_path, *node_id),
|
||||
inputs,
|
||||
});
|
||||
}
|
||||
|
||||
EditorDelta::NodeMetadata { network_path, node_id, change } => {
|
||||
ops.extend(node_metadata_ops(resolver.node_id(network_path, *node_id), change)?);
|
||||
}
|
||||
|
||||
EditorDelta::NodeInputMetadata {
|
||||
network_path,
|
||||
node_id,
|
||||
input_metadata,
|
||||
} => {
|
||||
let global_id = resolver.node_id(network_path, *node_id);
|
||||
let source = InputMetadataSource(input_metadata);
|
||||
let working_node = batch.node(global_id);
|
||||
|
||||
// An insert shifts every later slot, so the array is asserted whole: a `ui::` key the slot
|
||||
// no longer carries is cleared rather than left behind at its old index.
|
||||
for input_index in 0..input_metadata.len() {
|
||||
let mut encoded = Attributes::new();
|
||||
encode_input_ui_attributes(&mut encoded, &source, network_path, *node_id, input_index, TimeStamp::ORIGIN)?;
|
||||
let current = working_node.and_then(|node| node.inputs().get(input_index)).map(|slot| &slot.attributes);
|
||||
|
||||
for delta in ui_attribute_writes(current, &encoded) {
|
||||
ops.push(RegistryDelta::ChangeNodeInputAttribute {
|
||||
id: global_id,
|
||||
index: input_index.try_into().map_err(|_| ConversionError::IndexOverflow(input_index))?,
|
||||
delta,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EditorDelta::NetworkMetadata { network_path, change } => {
|
||||
let delta = match change {
|
||||
NetworkMetadataChange::Reference(reference) => AttributeDelta {
|
||||
key: node_attr::ui::REFERENCE.to_string(),
|
||||
value: reference.clone().map(serde_json::Value::String),
|
||||
},
|
||||
NetworkMetadataChange::PinnedOrder(order) => {
|
||||
let stored: Vec<_> = order.iter().map(|node_id| resolver.node_id(network_path, *node_id)).collect();
|
||||
AttributeDelta {
|
||||
key: network_attr::PINNED_ORDER.to_string(),
|
||||
value: (!stored.is_empty()).then(|| serialize_attribute(network_attr::PINNED_ORDER, &stored)).transpose()?,
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
ops.push(RegistryDelta::ChangeNetworkAttribute {
|
||||
id: resolver.network_id(network_path),
|
||||
delta,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn serialize_attribute<T: serde::Serialize>(key: &str, value: &T) -> Result<serde_json::Value, ConversionError> {
|
||||
serde_json::to_value(value).map_err(|error| ConversionError::SerializationError(format!("{key}: {error:?}")))
|
||||
}
|
||||
|
||||
/// The attribute writes one metadata field makes, as the whole-document encoder would write them.
|
||||
///
|
||||
/// A field set back to its unset value clears the attribute, since absence is how that encoder spells
|
||||
/// unset. Clearing rather than writing a sentinel keeps the two paths producing the same registry.
|
||||
fn node_metadata_ops(global_id: document_graph_storage::NodeId, change: &NodeMetadataChange) -> Result<Vec<RegistryDelta>, ConversionError> {
|
||||
let node_attribute = |key: &str, value: Option<serde_json::Value>| RegistryDelta::ChangeNodeAttribute {
|
||||
id: global_id,
|
||||
delta: AttributeDelta { key: key.to_string(), value },
|
||||
};
|
||||
let input_attribute = |key: &str, index: usize, value: Option<serde_json::Value>| {
|
||||
Ok::<_, ConversionError>(RegistryDelta::ChangeNodeInputAttribute {
|
||||
id: global_id,
|
||||
index: index.try_into().map_err(|_| ConversionError::IndexOverflow(index))?,
|
||||
delta: AttributeDelta { key: key.to_string(), value },
|
||||
})
|
||||
};
|
||||
|
||||
// Absence is how the encoder spells an unset flag, and the empty string is the runtime's own
|
||||
// sentinel for an unset name.
|
||||
let flag = |value: bool| value.then_some(serde_json::Value::Bool(true));
|
||||
let non_empty = |value: &str| (!value.is_empty()).then(|| serde_json::Value::String(value.to_string()));
|
||||
Ok(match change {
|
||||
NodeMetadataChange::NodeType(node_type) => {
|
||||
let position = position_from_runtime(node_type);
|
||||
vec![
|
||||
node_attribute(node_attr::ui::POSITION, Some(serialize_attribute(node_attr::ui::POSITION, &position)?)),
|
||||
node_attribute(node_attr::ui::IS_LAYER, flag(matches!(node_type, NodeTypePersistentMetadata::Layer(_)))),
|
||||
]
|
||||
}
|
||||
NodeMetadataChange::DisplayName(display_name) => vec![node_attribute(node_attr::ui::DISPLAY_NAME, non_empty(display_name))],
|
||||
NodeMetadataChange::Locked(locked) => vec![node_attribute(node_attr::ui::LOCKED, flag(*locked))],
|
||||
NodeMetadataChange::Pinned(pinned) => vec![node_attribute(node_attr::ui::PINNED, flag(*pinned))],
|
||||
NodeMetadataChange::OutputNames(output_names) => {
|
||||
let value = (!output_names.is_empty()).then(|| serialize_attribute(node_attr::ui::OUTPUT_NAMES, output_names)).transpose()?;
|
||||
vec![node_attribute(node_attr::ui::OUTPUT_NAMES, value)]
|
||||
}
|
||||
NodeMetadataChange::InputName { index, name } => vec![input_attribute(node_attr::input::ui::NAME, *index, non_empty(name))?],
|
||||
NodeMetadataChange::WidgetOverride { index, widget_override } => {
|
||||
let value = widget_override.as_deref().and_then(non_empty);
|
||||
vec![input_attribute(node_attr::input::ui::WIDGET_OVERRIDE, *index, value)?]
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// Converts through the same encoders as a whole-document conversion, with identities only as the
|
||||
/// source: ui attributes arrive via the gesture's paired `NodeMetadata` delta.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn construct_structural_additions(
|
||||
network_path: &[NodeId],
|
||||
node_id: NodeId,
|
||||
node: &graph_craft::document::DocumentNode,
|
||||
batch: &mut BatchRegistry,
|
||||
resources: &ResourceRegistry,
|
||||
identities: &dyn NodeMetadataSource,
|
||||
peer: document_graph_storage::PeerId,
|
||||
ops: &mut Vec<RegistryDelta>,
|
||||
declaration_bytes: &mut DeclarationBytes,
|
||||
) -> Result<(), ConversionError> {
|
||||
let mut scoped = ScopedConversion::new(identities, peer);
|
||||
let mut scratch = Registry::default();
|
||||
scoped.convert_node_at(&mut scratch, network_path, node_id, node, true)?;
|
||||
declaration_bytes.extend(scoped.finish());
|
||||
|
||||
let mut networks: Vec<_> = scratch.networks.iter().collect();
|
||||
networks.sort_by_key(|(id, _)| **id);
|
||||
for (id, network) in networks {
|
||||
ops.push(RegistryDelta::AddNetwork { id: *id, network: network.clone() });
|
||||
}
|
||||
|
||||
// Recorded as well as emitted, so a later delta in this batch that reads one of these nodes back
|
||||
// finds it rather than looking only at the registry the batch started from.
|
||||
let mut nodes: Vec<_> = scratch.node_instances.iter().collect();
|
||||
nodes.sort_by_key(|(id, _)| **id);
|
||||
let added: Vec<_> = nodes.into_iter().map(|(id, node)| (*id, node.clone())).collect();
|
||||
for (id, node) in added {
|
||||
ops.push(RegistryDelta::AddNode { id, node: node.clone() });
|
||||
batch.record_addition(id, node);
|
||||
}
|
||||
|
||||
let mut new_resources: Vec<_> = scratch
|
||||
.resources
|
||||
.iter()
|
||||
.filter(|(id, _)| !batch.working.resources.contains_key(id))
|
||||
.map(|(id, entry)| (*id, entry.clone()))
|
||||
.collect();
|
||||
new_resources.sort_by_key(|(id, _)| *id);
|
||||
for (id, entry) in new_resources {
|
||||
if batch.record_resource(id, entry.clone()) {
|
||||
ops.push(RegistryDelta::AddResource { id, entry });
|
||||
}
|
||||
}
|
||||
let mut tagged: Vec<ResourceId> = scratch.node_instances.values().flat_map(node_value_resource_refs).collect();
|
||||
tagged.sort();
|
||||
tagged.dedup();
|
||||
for id in tagged {
|
||||
if batch.resource(id).is_none()
|
||||
&& !scratch.resources.contains_key(&id)
|
||||
&& let Some(entry) = convert_resource_entry(resources, id, peer)?
|
||||
{
|
||||
batch.record_resource(id, entry.clone());
|
||||
ops.push(RegistryDelta::AddResource { id, entry });
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn construct_metadata_snapshot(
|
||||
network_path: &[NodeId],
|
||||
node_id: NodeId,
|
||||
metadata: &DocumentNodePersistentMetadata,
|
||||
batch: &BatchRegistry,
|
||||
resolver: &PathResolver,
|
||||
ops: &mut Vec<RegistryDelta>,
|
||||
) -> Result<(), ConversionError> {
|
||||
let source = MetadataCopySource {
|
||||
anchor_path: network_path,
|
||||
anchor_id: node_id,
|
||||
metadata,
|
||||
};
|
||||
|
||||
let mut pending = vec![(network_path.to_vec(), node_id, metadata)];
|
||||
while let Some((path, id, node_metadata)) = pending.pop() {
|
||||
let global_id = resolver.node_id(&path, id);
|
||||
let working_node = batch.node(global_id);
|
||||
|
||||
let mut encoded = Attributes::new();
|
||||
encode_node_ui_attributes(&mut encoded, &source, &path, id, TimeStamp::ORIGIN)?;
|
||||
for delta in ui_attribute_writes(working_node.map(|node| node.attributes()), &encoded) {
|
||||
ops.push(RegistryDelta::ChangeNodeAttribute { id: global_id, delta });
|
||||
}
|
||||
|
||||
for input_index in 0..node_metadata.input_metadata.len() {
|
||||
let mut encoded = Attributes::new();
|
||||
encode_input_ui_attributes(&mut encoded, &source, &path, id, input_index, TimeStamp::ORIGIN)?;
|
||||
let current = working_node.and_then(|node| node.inputs().get(input_index)).map(|slot| &slot.attributes);
|
||||
for delta in ui_attribute_writes(current, &encoded) {
|
||||
ops.push(RegistryDelta::ChangeNodeInputAttribute {
|
||||
id: global_id,
|
||||
index: input_index.try_into().map_err(|_| ConversionError::IndexOverflow(input_index))?,
|
||||
delta,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(network_metadata) = &node_metadata.network_metadata {
|
||||
let mut nested_path = path.clone();
|
||||
nested_path.push(id);
|
||||
let network_id = resolver.network_id(&nested_path);
|
||||
|
||||
let target = network_metadata.persistent_metadata.reference.clone().map(serde_json::Value::String);
|
||||
let current = batch
|
||||
.working
|
||||
.networks
|
||||
.get(&network_id)
|
||||
.and_then(|network| network.attributes.get(node_attr::ui::REFERENCE))
|
||||
.map(|value| value.value.clone());
|
||||
if current != target {
|
||||
ops.push(RegistryDelta::ChangeNetworkAttribute {
|
||||
id: network_id,
|
||||
delta: AttributeDelta {
|
||||
key: node_attr::ui::REFERENCE.to_string(),
|
||||
value: target,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
for (child_id, child) in &network_metadata.persistent_metadata.node_metadata {
|
||||
pending.push((nested_path.clone(), *child_id, &child.persistent_metadata));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Every `ui::` attribute of `encoded`, plus a clear for each `ui::` key of `current` that `encoded`
|
||||
/// does not carry. Values are compared only to decide what to clear, never to skip a write.
|
||||
///
|
||||
/// Restating a value that already matches looks redundant but is load-bearing: `current` is the
|
||||
/// registry as it stood before the batch, and these writes follow an op in the same batch that
|
||||
/// rebuilt what they describe. A value the pre-batch state agrees with may already have been cleared
|
||||
/// by that op, so skipping it would leave the attribute missing.
|
||||
fn ui_attribute_writes(current: Option<&Attributes>, encoded: &Attributes) -> Vec<AttributeDelta> {
|
||||
let owned = |key: &str| key.starts_with("ui::");
|
||||
let mut deltas = Vec::new();
|
||||
|
||||
if let Some(current) = current {
|
||||
for key in current.keys() {
|
||||
if owned(key) && !encoded.contains_key(key) {
|
||||
deltas.push(AttributeDelta { key: key.clone(), value: None });
|
||||
}
|
||||
}
|
||||
}
|
||||
for (key, value) in encoded {
|
||||
deltas.push(AttributeDelta {
|
||||
key: key.clone(),
|
||||
value: Some(value.value.clone()),
|
||||
});
|
||||
}
|
||||
|
||||
deltas.sort_by(|a, b| a.key.cmp(&b.key));
|
||||
deltas
|
||||
}
|
||||
|
||||
/// Emits the removal of a node and everything nested under it, recording what was removed so the
|
||||
/// batch's resource liveness accounts for all of it at the end.
|
||||
fn construct_removals(node_id: document_graph_storage::NodeId, batch: &BatchRegistry, batch_removed_nodes: &mut Vec<document_graph_storage::NodeId>, ops: &mut Vec<RegistryDelta>) {
|
||||
let (mut removed_nodes, mut removed_networks) = removal_closure(node_id, batch);
|
||||
|
||||
removed_nodes.sort();
|
||||
removed_networks.sort();
|
||||
for id in &removed_nodes {
|
||||
let Some(snapshot) = batch.node(*id) else { continue };
|
||||
ops.push(RegistryDelta::RemoveNode { id: *id, snapshot: snapshot.clone() });
|
||||
}
|
||||
for id in &removed_networks {
|
||||
let Some(snapshot) = batch.working.networks.get(id) else { continue };
|
||||
ops.push(RegistryDelta::RemoveNetwork { id: *id, snapshot: snapshot.clone() });
|
||||
}
|
||||
|
||||
batch_removed_nodes.extend(removed_nodes);
|
||||
}
|
||||
|
||||
/// Emits removals for resources referenced only by the batch's removed nodes, checked after every
|
||||
/// removal is known.
|
||||
fn construct_resource_removals(batch_removed_nodes: &[document_graph_storage::NodeId], batch: &BatchRegistry, ops: &mut Vec<RegistryDelta>) {
|
||||
let removed_node_set: HashSet<_> = batch_removed_nodes.iter().copied().collect();
|
||||
let mut candidates: Vec<ResourceId> = batch_removed_nodes
|
||||
.iter()
|
||||
.filter_map(|id| batch.node(*id))
|
||||
.flat_map(|node| {
|
||||
let declaration = match node.implementation() {
|
||||
Implementation::ProtoNode(declaration) => Some(*declaration),
|
||||
Implementation::Network(_) => None,
|
||||
};
|
||||
declaration.into_iter().chain(node_value_resource_refs(node))
|
||||
})
|
||||
.collect();
|
||||
candidates.sort();
|
||||
candidates.dedup();
|
||||
if candidates.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Gathered in one pass so each candidate is a lookup rather than another scan of the whole registry
|
||||
let mut still_referenced: HashSet<ResourceId> = HashSet::new();
|
||||
for (id, node) in batch.working.node_instances.iter().chain(&batch.added) {
|
||||
if removed_node_set.contains(id) {
|
||||
continue;
|
||||
}
|
||||
if let Implementation::ProtoNode(declaration) = node.implementation() {
|
||||
still_referenced.insert(*declaration);
|
||||
}
|
||||
still_referenced.extend(node_value_resource_refs(node));
|
||||
}
|
||||
for network in batch.working.networks.values() {
|
||||
still_referenced.extend(network.exports.iter().filter_map(|slot| slot.target.as_ref().and_then(value_resource_ref)));
|
||||
}
|
||||
|
||||
for candidate in candidates {
|
||||
if !still_referenced.contains(&candidate)
|
||||
&& let Some(entry) = batch.resource(candidate)
|
||||
{
|
||||
ops.push(RegistryDelta::RemoveResource {
|
||||
id: candidate,
|
||||
snapshot: entry.clone(),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The registry a delta is constructed against: what the batch started from, plus the nodes deltas
|
||||
/// earlier in the same batch have added.
|
||||
///
|
||||
/// A delta that reads a node back cannot read only the starting registry. A node added and removed
|
||||
/// within one batch is not in it, and a later delta that rebuilds a node would rebuild the version
|
||||
/// that predates the batch. Additions are tracked rather than the whole registry copied, so the cost
|
||||
/// is the size of the batch rather than of the document.
|
||||
///
|
||||
/// Nodes are also indexed by network, so a removal closure walks only the subtree it removes instead
|
||||
/// of rescanning every node for each nested network it meets.
|
||||
struct BatchRegistry<'a> {
|
||||
working: &'a Registry,
|
||||
added: HashMap<document_graph_storage::NodeId, document_graph_storage::Node>,
|
||||
added_resources: HashMap<ResourceId, document_graph_storage::ResourceEntry>,
|
||||
by_network: HashMap<document_graph_storage::NetworkId, Vec<document_graph_storage::NodeId>>,
|
||||
}
|
||||
|
||||
impl<'a> BatchRegistry<'a> {
|
||||
fn new(working: &'a Registry) -> Self {
|
||||
let mut by_network: HashMap<_, Vec<_>> = HashMap::new();
|
||||
for (id, node) in &working.node_instances {
|
||||
by_network.entry(node.network()).or_default().push(*id);
|
||||
}
|
||||
Self {
|
||||
working,
|
||||
added: HashMap::new(),
|
||||
added_resources: HashMap::new(),
|
||||
by_network,
|
||||
}
|
||||
}
|
||||
|
||||
/// Records a node an earlier delta in this batch added, so a later one can read it back.
|
||||
fn record_addition(&mut self, id: document_graph_storage::NodeId, node: document_graph_storage::Node) {
|
||||
self.by_network.entry(node.network()).or_default().push(id);
|
||||
self.added.insert(id, node);
|
||||
}
|
||||
|
||||
/// Records a resource this batch added. Returns whether it is new to the batch, so the caller emits
|
||||
/// one addition for a resource several nodes reference.
|
||||
fn record_resource(&mut self, id: ResourceId, entry: document_graph_storage::ResourceEntry) -> bool {
|
||||
self.added_resources.insert(id, entry).is_none()
|
||||
}
|
||||
|
||||
fn node(&self, id: document_graph_storage::NodeId) -> Option<&document_graph_storage::Node> {
|
||||
self.added.get(&id).or_else(|| self.working.node_instances.get(&id))
|
||||
}
|
||||
|
||||
fn resource(&self, id: ResourceId) -> Option<&document_graph_storage::ResourceEntry> {
|
||||
self.added_resources.get(&id).or_else(|| self.working.resources.get(&id))
|
||||
}
|
||||
|
||||
fn children(&self, network_id: document_graph_storage::NetworkId) -> &[document_graph_storage::NodeId] {
|
||||
self.by_network.get(&network_id).map_or(&[], Vec::as_slice)
|
||||
}
|
||||
}
|
||||
|
||||
/// The node together with everything nested under it, and the networks that nesting owns.
|
||||
fn removal_closure(node_id: document_graph_storage::NodeId, batch: &BatchRegistry) -> (Vec<document_graph_storage::NodeId>, Vec<document_graph_storage::NetworkId>) {
|
||||
let mut nodes = Vec::new();
|
||||
let mut networks = Vec::new();
|
||||
collect_removal_closure(node_id, batch, &mut nodes, &mut networks);
|
||||
(nodes, networks)
|
||||
}
|
||||
|
||||
fn collect_removal_closure(node_id: document_graph_storage::NodeId, batch: &BatchRegistry, nodes: &mut Vec<document_graph_storage::NodeId>, networks: &mut Vec<document_graph_storage::NetworkId>) {
|
||||
let Some(node) = batch.node(node_id) else { return };
|
||||
nodes.push(node_id);
|
||||
|
||||
if let &Implementation::Network(network_id) = node.implementation() {
|
||||
networks.push(network_id);
|
||||
for &child_id in batch.children(network_id) {
|
||||
collect_removal_closure(child_id, batch, nodes, networks);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Narrows a metadata source to the node identities alone, so a scoped conversion addresses nodes the
|
||||
/// way a whole-document conversion does without also re-encoding ui attributes the gesture's paired
|
||||
/// `NodeMetadata` delta already carries.
|
||||
struct IdentitiesOnly<'a>(&'a dyn NodeMetadataSource);
|
||||
|
||||
impl NodeMetadataSource for IdentitiesOnly<'_> {
|
||||
fn storage_node_id(&self, network_path: &[NodeId], local_id: NodeId) -> Option<document_graph_storage::NodeId> {
|
||||
self.0.storage_node_id(network_path, local_id)
|
||||
}
|
||||
}
|
||||
|
||||
/// Serves one node's input metadata for encoding a [`EditorDelta::NodeInputMetadata`] delta. Only the
|
||||
/// per-input accessors answer, since the node-level ones are never reached: the delta encodes through
|
||||
/// `encode_input_ui_attributes` alone.
|
||||
struct InputMetadataSource<'a>(&'a [InputMetadata]);
|
||||
|
||||
impl InputMetadataSource<'_> {
|
||||
fn persistent(&self, input_index: usize) -> Option<&InputPersistentMetadata> {
|
||||
self.0.get(input_index).map(|metadata| &metadata.persistent_metadata)
|
||||
}
|
||||
}
|
||||
|
||||
impl NodeMetadataSource for InputMetadataSource<'_> {
|
||||
fn input_name(&self, _network_path: &[NodeId], _local_id: NodeId, input_index: usize) -> Option<&str> {
|
||||
Some(self.persistent(input_index)?.input_name.as_str())
|
||||
}
|
||||
|
||||
fn input_description(&self, _network_path: &[NodeId], _local_id: NodeId, input_index: usize) -> Option<&str> {
|
||||
Some(self.persistent(input_index)?.input_description.as_str())
|
||||
}
|
||||
|
||||
fn widget_override(&self, _network_path: &[NodeId], _local_id: NodeId, input_index: usize) -> Option<&str> {
|
||||
self.persistent(input_index)?.widget_override.as_deref()
|
||||
}
|
||||
|
||||
fn input_data(&self, _network_path: &[NodeId], _local_id: NodeId, input_index: usize) -> HashMap<String, serde_json::Value> {
|
||||
self.persistent(input_index).map(|metadata| metadata.input_data.clone()).unwrap_or_default()
|
||||
}
|
||||
}
|
||||
|
||||
/// Serves a metadata copy as the [`document_graph_storage::NodeMetadataSource`] for its own
|
||||
/// encoding, resolving requested paths relative to the anchor node the copy was taken from.
|
||||
struct MetadataCopySource<'a> {
|
||||
anchor_path: &'a [NodeId],
|
||||
anchor_id: NodeId,
|
||||
metadata: &'a DocumentNodePersistentMetadata,
|
||||
}
|
||||
|
||||
impl MetadataCopySource<'_> {
|
||||
fn metadata_for(&self, metadata_path: &[NodeId], node_id: NodeId) -> Option<&DocumentNodePersistentMetadata> {
|
||||
let relative = metadata_path.strip_prefix(self.anchor_path)?;
|
||||
|
||||
let (mut current, rest) = match relative.split_first() {
|
||||
None => return (node_id == self.anchor_id).then_some(self.metadata),
|
||||
Some((first, rest)) if *first == self.anchor_id => (self.metadata, rest),
|
||||
Some(_) => return None,
|
||||
};
|
||||
|
||||
for step in rest {
|
||||
current = child_metadata(current, *step)?;
|
||||
}
|
||||
child_metadata(current, node_id)
|
||||
}
|
||||
}
|
||||
|
||||
fn child_metadata(metadata: &DocumentNodePersistentMetadata, child_id: NodeId) -> Option<&DocumentNodePersistentMetadata> {
|
||||
metadata
|
||||
.network_metadata
|
||||
.as_ref()
|
||||
.and_then(|network| network.persistent_metadata.node_metadata.get(&child_id))
|
||||
.map(|child: &DocumentNodeMetadata| &child.persistent_metadata)
|
||||
}
|
||||
|
||||
impl document_graph_storage::NodeMetadataSource for MetadataCopySource<'_> {
|
||||
fn position(&self, metadata_path: &[NodeId], node_id: NodeId) -> Option<Position> {
|
||||
match &self.metadata_for(metadata_path, node_id)?.node_type_metadata {
|
||||
NodeTypePersistentMetadata::Layer(layer) => Some(match layer.position {
|
||||
LayerPosition::Absolute(offset) => Position::Absolute([offset.x, offset.y]),
|
||||
LayerPosition::Stack(offset) => Position::Stack(offset),
|
||||
}),
|
||||
NodeTypePersistentMetadata::Node(node) => Some(match *node.position() {
|
||||
NodePosition::Absolute(offset) => Position::Absolute([offset.x, offset.y]),
|
||||
NodePosition::Chain => Position::Chain,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
fn is_layer(&self, metadata_path: &[NodeId], node_id: NodeId) -> bool {
|
||||
self.metadata_for(metadata_path, node_id)
|
||||
.is_some_and(|metadata| matches!(metadata.node_type_metadata, NodeTypePersistentMetadata::Layer(_)))
|
||||
}
|
||||
|
||||
fn display_name(&self, metadata_path: &[NodeId], node_id: NodeId) -> Option<&str> {
|
||||
self.metadata_for(metadata_path, node_id).map(|metadata| metadata.display_name.as_str())
|
||||
}
|
||||
|
||||
fn locked(&self, metadata_path: &[NodeId], node_id: NodeId) -> bool {
|
||||
self.metadata_for(metadata_path, node_id).is_some_and(|metadata| metadata.locked)
|
||||
}
|
||||
|
||||
fn pinned(&self, metadata_path: &[NodeId], node_id: NodeId) -> bool {
|
||||
self.metadata_for(metadata_path, node_id).is_some_and(|metadata| metadata.pinned)
|
||||
}
|
||||
|
||||
fn output_names(&self, metadata_path: &[NodeId], node_id: NodeId) -> Vec<String> {
|
||||
self.metadata_for(metadata_path, node_id).map(|metadata| metadata.output_names.clone()).unwrap_or_default()
|
||||
}
|
||||
|
||||
fn input_name(&self, metadata_path: &[NodeId], node_id: NodeId, input_index: usize) -> Option<&str> {
|
||||
self.metadata_for(metadata_path, node_id)
|
||||
.and_then(|metadata| metadata.input_metadata.get(input_index))
|
||||
.map(|input| input.persistent_metadata.input_name.as_str())
|
||||
}
|
||||
|
||||
fn input_description(&self, metadata_path: &[NodeId], node_id: NodeId, input_index: usize) -> Option<&str> {
|
||||
self.metadata_for(metadata_path, node_id)
|
||||
.and_then(|metadata| metadata.input_metadata.get(input_index))
|
||||
.map(|input| input.persistent_metadata.input_description.as_str())
|
||||
}
|
||||
|
||||
fn widget_override(&self, metadata_path: &[NodeId], node_id: NodeId, input_index: usize) -> Option<&str> {
|
||||
self.metadata_for(metadata_path, node_id)
|
||||
.and_then(|metadata| metadata.input_metadata.get(input_index))
|
||||
.and_then(|input| input.persistent_metadata.widget_override.as_deref())
|
||||
}
|
||||
|
||||
fn input_data(&self, metadata_path: &[NodeId], node_id: NodeId, input_index: usize) -> std::collections::HashMap<String, serde_json::Value> {
|
||||
self.metadata_for(metadata_path, node_id)
|
||||
.and_then(|metadata| metadata.input_metadata.get(input_index))
|
||||
.map(|input| input.persistent_metadata.input_data.clone())
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
fn reference(&self, network_path: &[NodeId]) -> Option<&str> {
|
||||
let (owner_path, owner_id) = network_path.split_last().map(|(last, rest)| (rest, *last))?;
|
||||
self.metadata_for(owner_path, owner_id)?
|
||||
.network_metadata
|
||||
.as_ref()
|
||||
.and_then(|network| network.persistent_metadata.reference.as_deref())
|
||||
}
|
||||
}
|
||||
-554
@@ -1,554 +0,0 @@
|
||||
use super::DocumentNodePersistentMetadata;
|
||||
use super::InputConnector;
|
||||
use super::editor_delta::{EditorDelta, NetworkMetadataChange, NodeMetadataChange, construct_batch};
|
||||
use super::storage_metadata::StorageMetadataView;
|
||||
use crate::test_utils::test_prelude::*;
|
||||
use document_graph_storage::delta::compute_deltas;
|
||||
use document_graph_storage::{PeerId, Registry, RegistryDelta, Session};
|
||||
use graph_craft::document::NodeInput;
|
||||
use graph_craft::document::value::TaggedValue;
|
||||
use graph_craft::runtime_delta::RuntimeDelta;
|
||||
use graphene_std::uuid::NodeId;
|
||||
|
||||
const PEER: PeerId = PeerId(7);
|
||||
|
||||
fn rectangle_definition() -> DefinitionIdentifier {
|
||||
DefinitionIdentifier::ProtoNode(graphene_std::vector::generator_nodes::rectangle::IDENTIFIER)
|
||||
}
|
||||
|
||||
fn convert(editor: &EditorTestUtils) -> Registry {
|
||||
let document = editor.active_document();
|
||||
Registry::convert_from_runtime(
|
||||
document.network_interface.document_network(),
|
||||
&StorageMetadataView::new(&document.network_interface),
|
||||
&document.resources.registry,
|
||||
PEER,
|
||||
)
|
||||
.expect("conversion should succeed")
|
||||
.registry
|
||||
}
|
||||
|
||||
fn construct(editor: &EditorTestUtils, deltas: &[EditorDelta], working: &Registry) -> Vec<RegistryDelta> {
|
||||
let document = editor.active_document();
|
||||
construct_batch(deltas, working, &document.resources.registry, &StorageMetadataView::new(&document.network_interface), PEER)
|
||||
.expect("construction should succeed")
|
||||
.ops
|
||||
}
|
||||
|
||||
fn node_metadata(editor: &EditorTestUtils, node_id: NodeId) -> DocumentNodePersistentMetadata {
|
||||
editor
|
||||
.active_document()
|
||||
.network_interface
|
||||
.node_metadata(&node_id, &[])
|
||||
.expect("node metadata should exist")
|
||||
.persistent_metadata
|
||||
.clone()
|
||||
}
|
||||
|
||||
fn metadata_change(node_id: NodeId, change: NodeMetadataChange) -> EditorDelta {
|
||||
EditorDelta::NodeMetadata {
|
||||
network_path: Vec::new(),
|
||||
node_id,
|
||||
change,
|
||||
}
|
||||
}
|
||||
|
||||
fn assert_same_stored_effect(working: &Registry, constructed: Vec<RegistryDelta>, diffed: Vec<RegistryDelta>, at: &str) {
|
||||
let baseline = compute_deltas(&Registry::default(), working);
|
||||
|
||||
let mut from_construction = Session::with_peer(PEER);
|
||||
from_construction.stage_computed_ops(baseline.clone()).expect("baseline should stage");
|
||||
from_construction.stage_computed_ops(constructed).expect("constructed ops should stage");
|
||||
|
||||
let mut from_diff = Session::with_peer(PEER);
|
||||
from_diff.stage_computed_ops(baseline).expect("baseline should stage");
|
||||
from_diff.stage_computed_ops(diffed).expect("diffed ops should stage");
|
||||
|
||||
assert!(
|
||||
from_construction.registry().value_equal(from_diff.registry()),
|
||||
"Constructed ops must produce the same stored state as the whole-document diff: {at}\nresidual: {:#?}",
|
||||
compute_deltas(from_construction.registry(), from_diff.registry())
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn set_input_value_constructs_the_exact_diff_op() {
|
||||
let mut editor = EditorTestUtils::create();
|
||||
editor.new_document().await;
|
||||
let node = editor.create_node_by_name(rectangle_definition()).await;
|
||||
|
||||
let working = convert(&editor);
|
||||
let input = NodeInput::value(TaggedValue::F64(42.), false);
|
||||
editor.active_document_mut().network_interface.set_input(&InputConnector::node_at_index(node, 1), input.clone(), &[]);
|
||||
|
||||
let delta = EditorDelta::Graph(RuntimeDelta::SetInput {
|
||||
network_path: Vec::new(),
|
||||
node_id: node,
|
||||
input_index: 1,
|
||||
input,
|
||||
});
|
||||
|
||||
let constructed = construct(&editor, std::slice::from_ref(&delta), &working);
|
||||
let diffed = compute_deltas(&working, &convert(&editor));
|
||||
assert_eq!(constructed, diffed, "A value edit should construct exactly the diff's op");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn wiring_and_export_edits_construct_the_exact_diff_ops() {
|
||||
let mut editor = EditorTestUtils::create();
|
||||
editor.new_document().await;
|
||||
let a = editor.create_node_by_name(rectangle_definition()).await;
|
||||
let b = editor.create_node_by_name(rectangle_definition()).await;
|
||||
|
||||
let working = convert(&editor);
|
||||
let wire = NodeInput::node(b, 0);
|
||||
editor.active_document_mut().network_interface.set_input(&InputConnector::node_at_index(a, 1), wire.clone(), &[]);
|
||||
let delta = EditorDelta::Graph(RuntimeDelta::SetInput {
|
||||
network_path: Vec::new(),
|
||||
node_id: a,
|
||||
input_index: 1,
|
||||
input: wire,
|
||||
});
|
||||
let constructed = construct(&editor, std::slice::from_ref(&delta), &working);
|
||||
let diffed = compute_deltas(&working, &convert(&editor));
|
||||
assert_eq!(constructed, diffed, "A wiring edit should construct exactly the diff's op");
|
||||
|
||||
let working = convert(&editor);
|
||||
let export = NodeInput::node(a, 0);
|
||||
editor.active_document_mut().network_interface.set_input(&InputConnector::Export(0), export.clone(), &[]);
|
||||
let delta = EditorDelta::Graph(RuntimeDelta::SetExport {
|
||||
network_path: Vec::new(),
|
||||
export_index: 0,
|
||||
input: Some(export),
|
||||
});
|
||||
let constructed = construct(&editor, std::slice::from_ref(&delta), &working);
|
||||
let diffed = compute_deltas(&working, &convert(&editor));
|
||||
assert_eq!(constructed, diffed, "An export edit should construct exactly the diff's op");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn adding_a_node_as_structure_plus_metadata_matches_the_diff() {
|
||||
let mut editor = EditorTestUtils::create();
|
||||
editor.new_document().await;
|
||||
|
||||
let working = convert(&editor);
|
||||
let template = crate::messages::portfolio::document::node_graph::document_node_definitions::resolve_document_node_type(&rectangle_definition())
|
||||
.expect("rectangle definition")
|
||||
.default_node_template();
|
||||
let node_id = NodeId(0xDE17A);
|
||||
let (document_node, metadata) = template.clone().into_parts();
|
||||
editor.active_document_mut().network_interface.insert_node(node_id, template, &[]);
|
||||
|
||||
let deltas = [
|
||||
EditorDelta::Graph(RuntimeDelta::AddNode {
|
||||
network_path: Vec::new(),
|
||||
node_id,
|
||||
node: Box::new(document_node),
|
||||
}),
|
||||
EditorDelta::NodeMetadataSnapshot {
|
||||
network_path: Vec::new(),
|
||||
node_id,
|
||||
metadata: Box::new(metadata),
|
||||
},
|
||||
];
|
||||
|
||||
let constructed = construct(&editor, &deltas, &working);
|
||||
let diffed = compute_deltas(&working, &convert(&editor));
|
||||
assert_same_stored_effect(&working, constructed, diffed, "node addition");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn per_field_metadata_edits_match_the_diff() {
|
||||
let mut editor = EditorTestUtils::create();
|
||||
editor.new_document().await;
|
||||
let node = editor.create_node_by_name(rectangle_definition()).await;
|
||||
|
||||
let working = convert(&editor);
|
||||
{
|
||||
let network_interface = &mut editor.active_document_mut().network_interface;
|
||||
network_interface.set_display_name(&node, "Renamed".to_string(), &[]);
|
||||
network_interface.set_visibility(&node, &[], false);
|
||||
network_interface.set_locked(&node, &[], true);
|
||||
network_interface.set_pinned(&node, &[], true);
|
||||
network_interface.shift_node(&node, glam::IVec2::new(3, 5), &[]);
|
||||
}
|
||||
|
||||
let metadata = node_metadata(&editor, node);
|
||||
let deltas = [
|
||||
metadata_change(node, NodeMetadataChange::DisplayName(metadata.display_name.clone())),
|
||||
metadata_change(node, NodeMetadataChange::Locked(metadata.locked)),
|
||||
metadata_change(node, NodeMetadataChange::Pinned(metadata.pinned)),
|
||||
metadata_change(node, NodeMetadataChange::NodeType(metadata.node_type_metadata.clone())),
|
||||
EditorDelta::Graph(RuntimeDelta::SetVisibility {
|
||||
network_path: Vec::new(),
|
||||
node_id: node,
|
||||
visible: false,
|
||||
}),
|
||||
// Pinning a node also appends it to the network's display order, which is network state.
|
||||
EditorDelta::NetworkMetadata {
|
||||
network_path: Vec::new(),
|
||||
change: NetworkMetadataChange::PinnedOrder(vec![node]),
|
||||
},
|
||||
];
|
||||
let constructed = construct(&editor, &deltas, &working);
|
||||
let diffed = compute_deltas(&working, &convert(&editor));
|
||||
assert_same_stored_effect(&working, constructed, diffed, "per-field metadata edits");
|
||||
}
|
||||
|
||||
/// The encoding spells "unset" as an absent attribute, so a field set back to its unset value has to
|
||||
/// clear the key rather than write a sentinel. The wholesale copy got this by omitting the key; a
|
||||
/// per-field delta has to say it, and saying it wrong leaves the old value stored.
|
||||
#[tokio::test]
|
||||
async fn clearing_a_metadata_field_removes_the_attribute() {
|
||||
let mut editor = EditorTestUtils::create();
|
||||
editor.new_document().await;
|
||||
let node = editor.create_node_by_name(rectangle_definition()).await;
|
||||
|
||||
{
|
||||
let network_interface = &mut editor.active_document_mut().network_interface;
|
||||
network_interface.set_display_name(&node, "Renamed".to_string(), &[]);
|
||||
network_interface.set_locked(&node, &[], true);
|
||||
}
|
||||
|
||||
let working = convert(&editor);
|
||||
{
|
||||
let network_interface = &mut editor.active_document_mut().network_interface;
|
||||
network_interface.set_display_name(&node, String::new(), &[]);
|
||||
network_interface.set_locked(&node, &[], false);
|
||||
}
|
||||
|
||||
let metadata = node_metadata(&editor, node);
|
||||
let deltas = [
|
||||
metadata_change(node, NodeMetadataChange::DisplayName(metadata.display_name.clone())),
|
||||
metadata_change(node, NodeMetadataChange::Locked(metadata.locked)),
|
||||
];
|
||||
let constructed = construct(&editor, &deltas, &working);
|
||||
let diffed = compute_deltas(&working, &convert(&editor));
|
||||
assert_same_stored_effect(&working, constructed, diffed, "cleared metadata fields");
|
||||
}
|
||||
|
||||
/// The gate emission exists for: what the store says it wrote has to be what a whole-document
|
||||
/// conversion of the result would show. Hand-written deltas cannot catch a setter that forgets to
|
||||
/// emit, or emits the wrong field; taking them from the interface after a real edit can.
|
||||
#[tokio::test]
|
||||
async fn emitted_deltas_reproduce_the_diff() {
|
||||
let mut editor = EditorTestUtils::create();
|
||||
editor.new_document().await;
|
||||
let node = editor.create_node_by_name(rectangle_definition()).await;
|
||||
|
||||
let working = convert(&editor);
|
||||
editor.active_document_mut().network_interface.discard_deltas();
|
||||
|
||||
{
|
||||
let network_interface = &mut editor.active_document_mut().network_interface;
|
||||
network_interface.set_display_name(&node, "Renamed".to_string(), &[]);
|
||||
network_interface.set_locked(&node, &[], true);
|
||||
network_interface.set_pinned(&node, &[], true);
|
||||
network_interface.set_visibility(&node, &[], false);
|
||||
network_interface.shift_node(&node, glam::IVec2::new(3, 5), &[]);
|
||||
}
|
||||
|
||||
let emitted = editor.active_document_mut().network_interface.take_deltas();
|
||||
assert!(!emitted.is_empty(), "the edits should have emitted deltas");
|
||||
|
||||
let constructed = construct(&editor, &emitted, &working);
|
||||
let diffed = compute_deltas(&working, &convert(&editor));
|
||||
assert_same_stored_effect(&working, constructed, diffed, "emitted deltas");
|
||||
}
|
||||
|
||||
/// A write that changes nothing is not a write, so it must not emit. Otherwise a redundant setter call
|
||||
/// would stamp a fresh timestamp and win against a concurrent peer that did change the field.
|
||||
#[tokio::test]
|
||||
async fn unchanged_writes_emit_nothing() {
|
||||
let mut editor = EditorTestUtils::create();
|
||||
editor.new_document().await;
|
||||
let node = editor.create_node_by_name(rectangle_definition()).await;
|
||||
|
||||
editor.active_document_mut().network_interface.set_display_name(&node, "Named".to_string(), &[]);
|
||||
editor.active_document_mut().network_interface.discard_deltas();
|
||||
|
||||
{
|
||||
let network_interface = &mut editor.active_document_mut().network_interface;
|
||||
network_interface.set_display_name(&node, "Named".to_string(), &[]);
|
||||
network_interface.set_locked(&node, &[], false);
|
||||
network_interface.shift_node(&node, glam::IVec2::ZERO, &[]);
|
||||
}
|
||||
|
||||
let emitted = editor.active_document_mut().network_interface.take_deltas();
|
||||
assert!(emitted.is_empty(), "re-writing the same values should emit nothing, got {emitted:#?}");
|
||||
}
|
||||
|
||||
/// Structural writes go through the store too, so inserting and deleting a node must be recorded
|
||||
/// without the caller saying anything about it.
|
||||
#[tokio::test]
|
||||
async fn emitted_deltas_reproduce_the_diff_for_structural_edits() {
|
||||
let mut editor = EditorTestUtils::create();
|
||||
editor.new_document().await;
|
||||
|
||||
let working = convert(&editor);
|
||||
editor.active_document_mut().network_interface.discard_deltas();
|
||||
|
||||
let template = crate::messages::portfolio::document::node_graph::document_node_definitions::resolve_document_node_type(&rectangle_definition())
|
||||
.expect("rectangle definition")
|
||||
.default_node_template();
|
||||
let node_id = NodeId(0xDE17A);
|
||||
editor.active_document_mut().network_interface.insert_node(node_id, template, &[]);
|
||||
|
||||
let emitted = editor.active_document_mut().network_interface.take_deltas();
|
||||
let constructed = construct(&editor, &emitted, &working);
|
||||
let diffed = compute_deltas(&working, &convert(&editor));
|
||||
assert_same_stored_effect(&working, constructed, diffed, "emitted node insertion");
|
||||
|
||||
let working = convert(&editor);
|
||||
editor.active_document_mut().network_interface.discard_deltas();
|
||||
editor.active_document_mut().network_interface.delete_nodes(vec![node_id], true, &[]);
|
||||
|
||||
let emitted = editor.active_document_mut().network_interface.take_deltas();
|
||||
let constructed = construct(&editor, &emitted, &working);
|
||||
let diffed = compute_deltas(&working, &convert(&editor));
|
||||
assert_same_stored_effect(&working, constructed, diffed, "emitted node deletion");
|
||||
}
|
||||
|
||||
/// Adding an import shifts every later input slot, which no index-addressed op can express. The store
|
||||
/// restates the whole list instead, so this checks that restatement lands the same as the diff.
|
||||
#[tokio::test]
|
||||
async fn emitted_deltas_reproduce_the_diff_for_an_arity_change() {
|
||||
let mut editor = EditorTestUtils::create();
|
||||
editor.new_document().await;
|
||||
editor.draw_rect(0., 0., 100., 100.).await;
|
||||
editor
|
||||
.handle_message(DocumentMessage::GroupSelectedLayers {
|
||||
group_folder_type: crate::messages::portfolio::document::utility_types::misc::GroupFolderType::Layer,
|
||||
})
|
||||
.await;
|
||||
|
||||
let group = editor
|
||||
.active_document()
|
||||
.network_interface
|
||||
.document_network()
|
||||
.nodes
|
||||
.iter()
|
||||
.find(|(_, node)| matches!(node.implementation, graph_craft::document::DocumentNodeImplementation::Network(_)))
|
||||
.map(|(id, _)| *id)
|
||||
.expect("the group should be a network node");
|
||||
|
||||
let working = convert(&editor);
|
||||
editor.active_document_mut().network_interface.discard_deltas();
|
||||
|
||||
editor
|
||||
.active_document_mut()
|
||||
.network_interface
|
||||
.add_import(TaggedValue::F64(7.), true, -1, "Added", "An added import", &[group]);
|
||||
|
||||
let emitted = editor.active_document_mut().network_interface.take_deltas();
|
||||
assert!(!emitted.is_empty(), "adding an import should have emitted deltas");
|
||||
|
||||
let constructed = construct(&editor, &emitted, &working);
|
||||
let diffed = compute_deltas(&working, &convert(&editor));
|
||||
assert_same_stored_effect(&working, constructed, diffed, "emitted import addition");
|
||||
}
|
||||
|
||||
/// An arity change rebuilds the node's whole record, so anything written to that node earlier in the
|
||||
/// same batch has to survive it. Renaming first and adding the import second is the order that catches
|
||||
/// a rebuild sourced from the pre-batch registry rather than from what the batch has done so far.
|
||||
#[tokio::test]
|
||||
async fn an_arity_change_keeps_an_earlier_edit_to_the_same_node() {
|
||||
let mut editor = EditorTestUtils::create();
|
||||
editor.new_document().await;
|
||||
editor.draw_rect(0., 0., 100., 100.).await;
|
||||
editor
|
||||
.handle_message(DocumentMessage::GroupSelectedLayers {
|
||||
group_folder_type: crate::messages::portfolio::document::utility_types::misc::GroupFolderType::Layer,
|
||||
})
|
||||
.await;
|
||||
|
||||
let group = editor
|
||||
.active_document()
|
||||
.network_interface
|
||||
.document_network()
|
||||
.nodes
|
||||
.iter()
|
||||
.find(|(_, node)| matches!(node.implementation, graph_craft::document::DocumentNodeImplementation::Network(_)))
|
||||
.map(|(id, _)| *id)
|
||||
.expect("the group should be a network node");
|
||||
|
||||
let working = convert(&editor);
|
||||
editor.active_document_mut().network_interface.discard_deltas();
|
||||
|
||||
editor.active_document_mut().network_interface.set_display_name(&group, "Renamed".to_string(), &[]);
|
||||
editor
|
||||
.active_document_mut()
|
||||
.network_interface
|
||||
.add_import(TaggedValue::F64(7.), true, -1, "Added", "An added import", &[group]);
|
||||
|
||||
let emitted = editor.active_document_mut().network_interface.take_deltas();
|
||||
let constructed = construct(&editor, &emitted, &working);
|
||||
let diffed = compute_deltas(&working, &convert(&editor));
|
||||
assert_same_stored_effect(&working, constructed, diffed, "rename then arity change");
|
||||
}
|
||||
|
||||
/// The gate replay exists for: what the store recorded has to be enough to reproduce the write that
|
||||
/// produced it. Clone the interface before an edit, apply what the edit recorded onto the clone, and
|
||||
/// the two should agree. Something the store failed to record, or recorded wrongly, surfaces here
|
||||
/// rather than as drift on another peer.
|
||||
async fn assert_replay_reproduces(edit: impl FnOnce(&mut EditorTestUtils)) {
|
||||
let mut editor = EditorTestUtils::create();
|
||||
editor.new_document().await;
|
||||
editor.draw_rect(0., 0., 100., 100.).await;
|
||||
editor
|
||||
.handle_message(DocumentMessage::GroupSelectedLayers {
|
||||
group_folder_type: crate::messages::portfolio::document::utility_types::misc::GroupFolderType::Layer,
|
||||
})
|
||||
.await;
|
||||
editor.active_document_mut().network_interface.discard_deltas();
|
||||
|
||||
let before = editor.active_document().network_interface.clone();
|
||||
edit(&mut editor);
|
||||
|
||||
let recorded = editor.active_document_mut().network_interface.take_deltas();
|
||||
assert!(!recorded.is_empty(), "the edit should have recorded something to replay");
|
||||
|
||||
let mut replayed = before;
|
||||
for delta in &recorded {
|
||||
replayed.apply(delta);
|
||||
}
|
||||
|
||||
assert_eq!(
|
||||
replayed,
|
||||
editor.active_document().network_interface,
|
||||
"replaying {} recorded deltas did not reproduce the edited interface",
|
||||
recorded.len()
|
||||
);
|
||||
}
|
||||
|
||||
fn only_group(editor: &EditorTestUtils) -> NodeId {
|
||||
editor
|
||||
.active_document()
|
||||
.network_interface
|
||||
.document_network()
|
||||
.nodes
|
||||
.iter()
|
||||
.find(|(_, node)| matches!(node.implementation, graph_craft::document::DocumentNodeImplementation::Network(_)))
|
||||
.map(|(id, _)| *id)
|
||||
.expect("the group should be a network node")
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn replaying_metadata_edits_reproduces_the_interface() {
|
||||
assert_replay_reproduces(|editor| {
|
||||
let group = only_group(editor);
|
||||
let network_interface = &mut editor.active_document_mut().network_interface;
|
||||
network_interface.set_display_name(&group, "Renamed".to_string(), &[]);
|
||||
network_interface.set_locked(&group, &[], true);
|
||||
network_interface.set_pinned(&group, &[], true);
|
||||
network_interface.set_visibility(&group, &[], false);
|
||||
network_interface.shift_node(&group, glam::IVec2::new(3, 5), &[]);
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn replaying_an_arity_change_reproduces_the_interface() {
|
||||
assert_replay_reproduces(|editor| {
|
||||
let group = only_group(editor);
|
||||
editor
|
||||
.active_document_mut()
|
||||
.network_interface
|
||||
.add_import(TaggedValue::F64(7.), true, -1, "Added", "An added import", &[group]);
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn replaying_a_node_insertion_reproduces_the_interface() {
|
||||
assert_replay_reproduces(|editor| {
|
||||
let template = crate::messages::portfolio::document::node_graph::document_node_definitions::resolve_document_node_type(&rectangle_definition())
|
||||
.expect("rectangle definition")
|
||||
.default_node_template();
|
||||
editor.active_document_mut().network_interface.insert_node(NodeId(0xDE17A), template, &[]);
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
||||
/// A node added and removed inside one batch is never in the registry the batch started from, so the
|
||||
/// removal has nothing to look up there. The pair has to cancel out rather than leaving the addition
|
||||
/// staged on its own.
|
||||
#[tokio::test]
|
||||
async fn a_node_added_and_removed_in_one_batch_leaves_nothing_behind() {
|
||||
let mut editor = EditorTestUtils::create();
|
||||
editor.new_document().await;
|
||||
|
||||
let working = convert(&editor);
|
||||
editor.active_document_mut().network_interface.discard_deltas();
|
||||
|
||||
let template = crate::messages::portfolio::document::node_graph::document_node_definitions::resolve_document_node_type(&rectangle_definition())
|
||||
.expect("rectangle definition")
|
||||
.default_node_template();
|
||||
let node_id = NodeId(0xDE17A);
|
||||
editor.active_document_mut().network_interface.insert_node(node_id, template, &[]);
|
||||
editor.active_document_mut().network_interface.delete_nodes(vec![node_id], true, &[]);
|
||||
|
||||
let emitted = editor.active_document_mut().network_interface.take_deltas();
|
||||
let constructed = construct(&editor, &emitted, &working);
|
||||
let diffed = compute_deltas(&working, &convert(&editor));
|
||||
assert_same_stored_effect(&working, constructed, diffed, "add then remove in one batch");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn removing_a_nested_network_node_matches_the_diff() {
|
||||
let mut editor = EditorTestUtils::create();
|
||||
editor.new_document().await;
|
||||
editor.draw_rect(0., 0., 100., 100.).await;
|
||||
editor
|
||||
.handle_message(DocumentMessage::GroupSelectedLayers {
|
||||
group_folder_type: crate::messages::portfolio::document::utility_types::misc::GroupFolderType::Layer,
|
||||
})
|
||||
.await;
|
||||
|
||||
let before: Vec<NodeId> = editor.active_document().network_interface.document_network().nodes.keys().copied().collect();
|
||||
let working = convert(&editor);
|
||||
|
||||
let group = editor
|
||||
.active_document()
|
||||
.network_interface
|
||||
.document_network()
|
||||
.nodes
|
||||
.iter()
|
||||
.find(|(_, node)| matches!(node.implementation, graph_craft::document::DocumentNodeImplementation::Network(_)))
|
||||
.map(|(id, _)| *id)
|
||||
.expect("the group should be a network node");
|
||||
editor.active_document_mut().network_interface.delete_nodes(vec![group], true, &[]);
|
||||
|
||||
let network = editor.active_document().network_interface.document_network().clone();
|
||||
let mut deltas: Vec<EditorDelta> = before
|
||||
.iter()
|
||||
.filter(|id| !network.nodes.contains_key(id))
|
||||
.map(|id| {
|
||||
EditorDelta::Graph(RuntimeDelta::RemoveNode {
|
||||
network_path: Vec::new(),
|
||||
node_id: *id,
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
for (index, export) in network.exports.iter().enumerate() {
|
||||
deltas.push(EditorDelta::Graph(RuntimeDelta::SetExport {
|
||||
network_path: Vec::new(),
|
||||
export_index: index,
|
||||
input: Some(export.clone()),
|
||||
}));
|
||||
}
|
||||
for (node_id, node) in &network.nodes {
|
||||
for (index, input) in node.inputs.iter().enumerate() {
|
||||
deltas.push(EditorDelta::Graph(RuntimeDelta::SetInput {
|
||||
network_path: Vec::new(),
|
||||
node_id: *node_id,
|
||||
input_index: index,
|
||||
input: input.clone(),
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
let constructed = construct(&editor, &deltas, &working);
|
||||
let diffed = compute_deltas(&working, &convert(&editor));
|
||||
assert_same_stored_effect(&working, constructed, diffed, "nested network removal");
|
||||
}
|
||||
@@ -1,181 +0,0 @@
|
||||
//! The shapes the node graph frontend is sent: one entry per visible port, carrying its type, its
|
||||
//! name and what it connects to. Read-only projections of the graph, never a source of truth.
|
||||
|
||||
use super::*;
|
||||
|
||||
impl NodeNetworkInterface {
|
||||
pub fn frontend_imports(&self, network_path: &[NodeId]) -> Vec<Option<FrontendGraphOutput>> {
|
||||
match network_path.split_last() {
|
||||
Some((node_id, encapsulating_network_path)) => {
|
||||
let Some(node) = self.document_node(node_id, encapsulating_network_path) else {
|
||||
log::error!("Could not get node {node_id} in network {encapsulating_network_path:?}");
|
||||
return Vec::new();
|
||||
};
|
||||
let mut frontend_imports = (0..node.inputs.len())
|
||||
.map(|import_index| self.frontend_output_from_connector(&OutputConnector::Import(import_index), network_path))
|
||||
.collect::<Vec<_>>();
|
||||
if frontend_imports.is_empty() {
|
||||
frontend_imports.push(None);
|
||||
}
|
||||
frontend_imports
|
||||
}
|
||||
// In the document network display no imports
|
||||
None => Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn frontend_exports(&self, network_path: &[NodeId]) -> Vec<Option<FrontendGraphInput>> {
|
||||
let Some(network) = self.nested_network(network_path) else { return Vec::new() };
|
||||
let mut frontend_exports = ((0..network.exports.len()).map(|export_index| self.frontend_input_from_connector(&InputConnector::Export(export_index), network_path))).collect::<Vec<_>>();
|
||||
if frontend_exports.is_empty() {
|
||||
frontend_exports.push(None);
|
||||
}
|
||||
frontend_exports
|
||||
}
|
||||
|
||||
/// Returns None if there is an error, it is a hidden primary export, or a hidden input
|
||||
pub fn frontend_input_from_connector(&self, input_connector: &InputConnector, network_path: &[NodeId]) -> Option<FrontendGraphInput> {
|
||||
// Return None if it is a hidden input
|
||||
if self.input_from_connector(input_connector, network_path).is_some_and(|input| !input.is_exposed()) {
|
||||
return None;
|
||||
}
|
||||
let input_type = self.input_type(input_connector, network_path);
|
||||
let data_type = input_type.displayed_type();
|
||||
let resolved_type = input_type.resolved_type_node_string();
|
||||
|
||||
let connected_to = self
|
||||
.upstream_output_connector(input_connector, network_path)
|
||||
.map(|output_connector| match output_connector {
|
||||
OutputConnector::Node { node_id, output_index } => {
|
||||
let name = self.display_name(&node_id, network_path);
|
||||
format!("Connected to output #{output_index} of \"{name}\", ID: {node_id}.")
|
||||
}
|
||||
OutputConnector::Import(import_index) => format!("Connected to import #{import_index}."),
|
||||
})
|
||||
.unwrap_or("Connected to nothing.".to_string());
|
||||
|
||||
let (name, description) = match input_connector {
|
||||
InputConnector::Node { node_id, input_index } => self.displayed_input_name_and_description(node_id, *input_index, network_path),
|
||||
InputConnector::Export(export_index) => {
|
||||
// Get export name from parent node metadata input, which must match the number of exports.
|
||||
// Empty string means to use type, or "Export + index" if type is empty determined
|
||||
let export_name = if network_path.is_empty() {
|
||||
"Canvas".to_string()
|
||||
} else {
|
||||
self.encapsulating_node_metadata(network_path)
|
||||
.and_then(|encapsulating_metadata| encapsulating_metadata.persistent_metadata.output_names.get(*export_index).cloned())
|
||||
.unwrap_or_default()
|
||||
};
|
||||
|
||||
let export_name = if !export_name.is_empty() {
|
||||
export_name
|
||||
} else if let Some(export_type_name) = input_type.compiled_nested_type().map(ToString::to_string) {
|
||||
export_type_name
|
||||
} else {
|
||||
format!("Export #{}", export_index)
|
||||
};
|
||||
|
||||
(export_name, String::new())
|
||||
}
|
||||
};
|
||||
|
||||
let valid_types = self.potential_valid_input_types(input_connector, network_path).iter().map(ToString::to_string).collect::<Vec<_>>();
|
||||
let valid_types = {
|
||||
// Dedupe while preserving order
|
||||
let mut found = HashSet::new();
|
||||
valid_types.into_iter().filter(|s| found.insert(s.clone())).collect::<Vec<_>>()
|
||||
};
|
||||
|
||||
Some(FrontendGraphInput {
|
||||
data_type,
|
||||
resolved_type,
|
||||
name,
|
||||
description,
|
||||
valid_types,
|
||||
connected_to,
|
||||
})
|
||||
}
|
||||
|
||||
/// Returns None if there is an error, it is the document network, a hidden primary output or import
|
||||
pub fn frontend_output_from_connector(&self, output_connector: &OutputConnector, network_path: &[NodeId]) -> Option<FrontendGraphOutput> {
|
||||
let output_type = self.output_type(output_connector, network_path);
|
||||
let (name, description) = match output_connector {
|
||||
OutputConnector::Node { node_id, output_index } => {
|
||||
// Do not display the primary output port for a node if it is a network node with a hidden primary export
|
||||
if *output_index == 0 && self.hidden_primary_output(node_id, network_path) {
|
||||
return None;
|
||||
};
|
||||
// Get the output name from the interior network export name
|
||||
let node_metadata = self.node_metadata(node_id, network_path)?;
|
||||
let output_name = node_metadata.persistent_metadata.output_names.get(*output_index).cloned().unwrap_or_default();
|
||||
|
||||
let output_name = if !output_name.is_empty() { output_name } else { output_type.resolved_type_node_string() };
|
||||
(output_name, String::new())
|
||||
}
|
||||
OutputConnector::Import(import_index) => {
|
||||
// Get the import name from the encapsulating node input metadata
|
||||
let Some((encapsulating_node_id, encapsulating_path)) = network_path.split_last() else {
|
||||
// Return None if it is an import in the document network
|
||||
return None;
|
||||
};
|
||||
// Return None if the primary input is hidden and this is the primary import
|
||||
if *import_index == 0 && self.hidden_primary_import(network_path) {
|
||||
return None;
|
||||
};
|
||||
let (import_name, description) = self.displayed_input_name_and_description(encapsulating_node_id, *import_index, encapsulating_path);
|
||||
|
||||
let import_name = if !import_name.is_empty() {
|
||||
import_name
|
||||
} else if let Some(import_type_name) = output_type.compiled_nested_type().map(ToString::to_string) {
|
||||
import_type_name
|
||||
} else {
|
||||
format!("Import #{}", import_index)
|
||||
};
|
||||
|
||||
(import_name, description)
|
||||
}
|
||||
};
|
||||
let data_type = output_type.displayed_type();
|
||||
let resolved_type = output_type.resolved_type_node_string();
|
||||
let mut connected_to = self
|
||||
.with_outward_wires(network_path, |outward_wires| outward_wires.get(output_connector).cloned())
|
||||
.flatten()
|
||||
.unwrap_or_default()
|
||||
.iter()
|
||||
.map(|input| match input {
|
||||
&InputConnector::Node { node_id, input_index } => {
|
||||
let name = self.display_name(&node_id, network_path);
|
||||
format!("Connected to input #{input_index} of \"{name}\", ID: {node_id}.")
|
||||
}
|
||||
InputConnector::Export(export_index) => format!("Connected to export #{export_index}."),
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
if connected_to.is_empty() {
|
||||
connected_to.push("Connected to nothing.".to_string());
|
||||
}
|
||||
|
||||
Some(FrontendGraphOutput {
|
||||
data_type,
|
||||
resolved_type,
|
||||
name,
|
||||
description,
|
||||
connected_to,
|
||||
})
|
||||
}
|
||||
|
||||
/// Returns the input name to display in the properties panel. If the name is empty then the type is used.
|
||||
pub fn displayed_input_name_and_description(&self, node_id: &NodeId, input_index: usize, network_path: &[NodeId]) -> (String, String) {
|
||||
let Some(input_metadata) = self.persistent_input_metadata(node_id, input_index, network_path) else {
|
||||
log::warn!("input metadata not found in displayed_input_name_and_description");
|
||||
return (String::new(), String::new());
|
||||
};
|
||||
let description = input_metadata.input_description.to_string();
|
||||
let name = if input_metadata.input_name.is_empty() {
|
||||
self.input_type(&InputConnector::node_at_index(*node_id, input_index), network_path).resolved_type_node_string()
|
||||
} else {
|
||||
input_metadata.input_name.to_string()
|
||||
};
|
||||
(name, description)
|
||||
}
|
||||
}
|
||||
@@ -1,352 +0,0 @@
|
||||
//! Geometry of the node graph: where a node's body, ports and handles sit in node graph space.
|
||||
//!
|
||||
//! Derived from the grid model in `layout`, never the other way round. These are pure computations;
|
||||
//! the caller decides whether to cache the result.
|
||||
|
||||
use super::*;
|
||||
|
||||
impl NodeNetworkInterface {
|
||||
/// The node body, its ports, and for a layer its visibility, lock, grip and name handles, all in node graph space.
|
||||
pub(super) fn compute_node_click_targets(&self, node_id: &NodeId, network_path: &[NodeId]) -> Option<DocumentNodeClickTargets> {
|
||||
let Some(node_position) = self.position(node_id, network_path) else {
|
||||
log::error!("Could not get node position in compute_node_click_targets for node {node_id}");
|
||||
return None;
|
||||
};
|
||||
let node_metadata = self.node_metadata(node_id, network_path)?;
|
||||
let Some(document_node) = self.document_node(node_id, network_path) else {
|
||||
log::error!("Could not get document node in compute_node_click_targets");
|
||||
return None;
|
||||
};
|
||||
|
||||
let node_top_left = node_position.as_dvec2() * GRID_SIZE as f64;
|
||||
let mut port_click_targets = Ports::new();
|
||||
let document_node_click_targets = if !node_metadata.persistent_metadata.is_layer() {
|
||||
// Create input/output click targets
|
||||
let mut input_row_count = 0;
|
||||
for (input_index, input) in document_node.inputs.iter().enumerate() {
|
||||
if input.is_exposed() {
|
||||
port_click_targets.insert_node_input(input_index, input_row_count, node_top_left);
|
||||
}
|
||||
// Primary input row is always displayed, even if the input is not exposed
|
||||
if input_index == 0 || input.is_exposed() {
|
||||
input_row_count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
let number_of_outputs = match &document_node.implementation {
|
||||
DocumentNodeImplementation::Network(network) => network.exports.len(),
|
||||
_ => 1,
|
||||
};
|
||||
// If the node has a hidden primary output, do not display the first output
|
||||
let start_index = if self.hidden_primary_output(node_id, network_path) { 1 } else { 0 };
|
||||
for output_index in start_index..number_of_outputs {
|
||||
port_click_targets.insert_node_output(output_index, node_top_left);
|
||||
}
|
||||
|
||||
let height = self.displayed_row_count(node_id, network_path) as u32 * GRID_SIZE;
|
||||
let width = 5 * GRID_SIZE;
|
||||
// Offset down by half a grid so the click target sits below the top connector strip.
|
||||
let node_click_target_top_left = node_top_left + DVec2::new(0., HALF_GRID_SIZE as f64);
|
||||
let node_click_target_bottom_right = node_click_target_top_left + DVec2::new(width as f64, height as f64);
|
||||
|
||||
let radius = 3.;
|
||||
let path = rounded_rectangle_path(node_click_target_top_left, node_click_target_bottom_right, [radius; 4]);
|
||||
let node_click_target = ClickTarget::new_with_path(path, 0.);
|
||||
|
||||
DocumentNodeClickTargets {
|
||||
node_click_target,
|
||||
port_click_targets,
|
||||
node_type_metadata: NodeTypeClickTargets::Node,
|
||||
}
|
||||
} else {
|
||||
// Layer inputs
|
||||
port_click_targets.insert_layer_input(0, node_top_left);
|
||||
if document_node.inputs.iter().filter(|input| input.is_exposed()).count() > 1 {
|
||||
port_click_targets.insert_layer_input(1, node_top_left);
|
||||
}
|
||||
port_click_targets.insert_layer_output(node_top_left);
|
||||
|
||||
let layer_width_cells = self.layer_width(node_id, network_path).unwrap_or_else(|| {
|
||||
log::error!("Could not get layer width in load_node_click_targets");
|
||||
0
|
||||
});
|
||||
let width = layer_width_cells * GRID_SIZE;
|
||||
let height = LAYER_GRID_HEIGHT * GRID_SIZE;
|
||||
let locked = self.is_locked(node_id, network_path);
|
||||
|
||||
// The layer is `2 * GRID_SIZE` tall, so its vertical center sits one grid unit below `node_top_left.y`.
|
||||
// Visibility/lock buttons fill a 1-grid-cell square (so half-extents of HALF_GRID_SIZE each side of center).
|
||||
const LAYER_VERTICAL_CENTER: f64 = GRID_SIZE as f64;
|
||||
const ICON_HALF_EXTENT: f64 = HALF_GRID_SIZE as f64;
|
||||
|
||||
// Update visibility button click target
|
||||
let visibility_offset = node_top_left + DVec2::new(width as f64, LAYER_VERTICAL_CENTER);
|
||||
let path = rounded_rectangle_path(
|
||||
DVec2::new(-ICON_HALF_EXTENT, -ICON_HALF_EXTENT) + visibility_offset,
|
||||
DVec2::new(ICON_HALF_EXTENT, ICON_HALF_EXTENT) + visibility_offset,
|
||||
[3.; 4],
|
||||
);
|
||||
let visibility_click_target = ClickTarget::new_with_path(path, 0.);
|
||||
|
||||
// Update lock button click target, positioned one grid unit to the left of the visibility button (only when locked)
|
||||
let lock_click_target = if locked {
|
||||
let lock_offset = node_top_left + DVec2::new(width as f64 - GRID_SIZE as f64, LAYER_VERTICAL_CENTER);
|
||||
let path = rounded_rectangle_path(
|
||||
DVec2::new(-ICON_HALF_EXTENT, -ICON_HALF_EXTENT) + lock_offset,
|
||||
DVec2::new(ICON_HALF_EXTENT, ICON_HALF_EXTENT) + lock_offset,
|
||||
[3.; 4],
|
||||
);
|
||||
Some(ClickTarget::new_with_path(path, 0.))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
// Update grip button click target, which is positioned to the left of the leftmost icon.
|
||||
// The grip is 8px wide but spans the full layer-vertical-center band.
|
||||
const GRIP_WIDTH: f64 = 8.;
|
||||
let icons_width = if locked { GRID_SIZE as f64 } else { 0. };
|
||||
let grip_offset_right_edge = node_top_left + DVec2::new(width as f64 - ICON_HALF_EXTENT - icons_width, LAYER_VERTICAL_CENTER);
|
||||
let path = rounded_rectangle_path(
|
||||
DVec2::new(-GRIP_WIDTH, -ICON_HALF_EXTENT) + grip_offset_right_edge,
|
||||
DVec2::new(0., ICON_HALF_EXTENT) + grip_offset_right_edge,
|
||||
[0.; 4],
|
||||
);
|
||||
let grip_click_target = ClickTarget::new_with_path(path, 0.);
|
||||
|
||||
// Update display-name text click target, used to detect double-click rename. Sized to the text bounds
|
||||
// (not the surrounding `.details` area) so the rest of the layer still drills into the subgraph on double-click.
|
||||
|
||||
/// `.layer` margin-left (= 12), for chain layers the negative margin-left and positive padding-left cancel out, keeping content at this same offset
|
||||
const LAYER_LEFT_MARGIN: f64 = HALF_GRID_SIZE as f64;
|
||||
/// `.thumbnail` (70px) + its 1px side margins (= 72)
|
||||
const THUMBNAIL_BLOCK_WIDTH: f64 = 3. * GRID_SIZE as f64;
|
||||
/// `.details` margin-left
|
||||
const DETAILS_LEFT_MARGIN: f64 = 8.;
|
||||
const NAME_LEFT_OFFSET: f64 = LAYER_LEFT_MARGIN + THUMBNAIL_BLOCK_WIDTH + DETAILS_LEFT_MARGIN;
|
||||
/// Distance from layer's right edge to visibility's left edge (= 12)
|
||||
const VISIBILITY_INSET_FROM_LAYER_RIGHT: f64 = HALF_GRID_SIZE as f64;
|
||||
const FONT_SIZE: f64 = 14.;
|
||||
|
||||
let display_name = self.display_name(node_id, network_path);
|
||||
let name_click_target = if display_name.is_empty() {
|
||||
None
|
||||
} else {
|
||||
let name_left = node_top_left.x + NAME_LEFT_OFFSET;
|
||||
let icons_reserve = VISIBILITY_INSET_FROM_LAYER_RIGHT + icons_width + GRIP_WIDTH;
|
||||
let name_right_max = node_top_left.x + width as f64 - icons_reserve;
|
||||
let name_width = text_width(&display_name, FONT_SIZE);
|
||||
let name_right = (name_left + name_width).min(name_right_max);
|
||||
if name_right > name_left {
|
||||
// The 1-grid-tall name strip is centered vertically in the 2-grid-tall layer.
|
||||
let name_top = node_top_left.y + HALF_GRID_SIZE as f64;
|
||||
let name_bottom = node_top_left.y + GRID_SIZE as f64 + HALF_GRID_SIZE as f64;
|
||||
let path = rounded_rectangle_path(DVec2::new(name_left, name_top), DVec2::new(name_right, name_bottom), [3.; 4]);
|
||||
Some(ClickTarget::new_with_path(path, 0.))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
};
|
||||
|
||||
// Create layer click target, which is contains the layer and the chain background
|
||||
let chain_width_grid_spaces = self.chain_width(node_id, network_path);
|
||||
|
||||
let node_bottom_right = node_top_left + DVec2::new(width as f64, height as f64);
|
||||
let chain_top_left = node_top_left - DVec2::new((chain_width_grid_spaces * GRID_SIZE) as f64, 0.);
|
||||
const CORNER_RADIUS: f64 = 10.;
|
||||
let path = rounded_rectangle_path(chain_top_left, node_bottom_right, [CORNER_RADIUS; 4]);
|
||||
let node_click_target = ClickTarget::new_with_path(path, 0.);
|
||||
|
||||
DocumentNodeClickTargets {
|
||||
node_click_target,
|
||||
port_click_targets,
|
||||
node_type_metadata: NodeTypeClickTargets::Layer(Box::new(LayerClickTargets {
|
||||
visibility_click_target,
|
||||
lock_click_target,
|
||||
grip_click_target,
|
||||
name_click_target,
|
||||
})),
|
||||
}
|
||||
};
|
||||
|
||||
Some(document_node_click_targets)
|
||||
}
|
||||
|
||||
/// The add, remove and reorder handles that sit beside each import and export port.
|
||||
pub(super) fn compute_modify_import_export(&self, network_path: &[NodeId]) -> Option<ModifyImportExportClickTarget> {
|
||||
let mut reorder_imports_exports = Ports::new();
|
||||
let mut remove_imports_exports = Ports::new();
|
||||
|
||||
if !network_path.is_empty() {
|
||||
let ports_built = self.with_import_export_ports(network_path, |import_exports| {
|
||||
for (import_index, import_click_target) in import_exports.output_ports() {
|
||||
let Some(import_bounding_box) = import_click_target.bounding_box() else {
|
||||
log::error!("Could not get export bounding box in load_modify_import_export");
|
||||
continue;
|
||||
};
|
||||
let reorder_import_center = (import_bounding_box[0] + import_bounding_box[1]) / 2. + DVec2::new(-12., 0.);
|
||||
|
||||
if *import_index == 0 {
|
||||
let remove_import_center = reorder_import_center + DVec2::new(-4., 0.);
|
||||
let remove_import = ClickTarget::new_with_path(rectangle_path(remove_import_center - DVec2::new(8., 8.), remove_import_center + DVec2::new(8., 8.)), 0.);
|
||||
remove_imports_exports.insert_custom_output_port(*import_index, remove_import);
|
||||
} else {
|
||||
let remove_import_center = reorder_import_center + DVec2::new(-12., 0.);
|
||||
let reorder_import = ClickTarget::new_with_path(rectangle_path(reorder_import_center - DVec2::new(3., 4.), reorder_import_center + DVec2::new(3., 4.)), 0.);
|
||||
let remove_import = ClickTarget::new_with_path(rectangle_path(remove_import_center - DVec2::new(8., 8.), remove_import_center + DVec2::new(8., 8.)), 0.);
|
||||
reorder_imports_exports.insert_custom_output_port(*import_index, reorder_import);
|
||||
remove_imports_exports.insert_custom_output_port(*import_index, remove_import);
|
||||
}
|
||||
}
|
||||
|
||||
for (export_index, export_click_target) in import_exports.input_ports() {
|
||||
let Some(export_bounding_box) = export_click_target.bounding_box() else {
|
||||
log::error!("Could not get export bounding box in load_modify_import_export");
|
||||
continue;
|
||||
};
|
||||
let reorder_export_center = (export_bounding_box[0] + export_bounding_box[1]) / 2. + DVec2::new(12., 0.);
|
||||
|
||||
if *export_index == 0 {
|
||||
let remove_export_center = reorder_export_center + DVec2::new(4., 0.);
|
||||
let remove_export = ClickTarget::new_with_path(rectangle_path(remove_export_center - DVec2::new(8., 8.), remove_export_center + DVec2::new(8., 8.)), 0.);
|
||||
remove_imports_exports.insert_custom_input_port(*export_index, remove_export);
|
||||
} else {
|
||||
let remove_export_center = reorder_export_center + DVec2::new(12., 0.);
|
||||
let reorder_export = ClickTarget::new_with_path(rectangle_path(reorder_export_center - DVec2::new(3., 4.), reorder_export_center + DVec2::new(3., 4.)), 0.);
|
||||
let remove_export = ClickTarget::new_with_path(rectangle_path(remove_export_center - DVec2::new(8., 8.), remove_export_center + DVec2::new(8., 8.)), 0.);
|
||||
reorder_imports_exports.insert_custom_input_port(*export_index, reorder_export);
|
||||
remove_imports_exports.insert_custom_input_port(*export_index, remove_export);
|
||||
}
|
||||
}
|
||||
});
|
||||
if ports_built.is_none() {
|
||||
log::error!("Could not get import_export_ports in compute_modify_import_export");
|
||||
return None;
|
||||
}
|
||||
}
|
||||
|
||||
Some(ModifyImportExportClickTarget {
|
||||
remove_imports_exports,
|
||||
reorder_imports_exports,
|
||||
})
|
||||
}
|
||||
|
||||
/// A port for each import and export of the network, placed down the left and right edges.
|
||||
pub(super) fn compute_import_export_ports(&self, network_path: &[NodeId]) -> Option<Ports> {
|
||||
let Some(import_export_position) = self.import_export_position(network_path) else {
|
||||
log::error!("Could not get import_export_position");
|
||||
return None;
|
||||
};
|
||||
let network = self.nested_network(network_path)?;
|
||||
let mut import_export_ports = Ports::new();
|
||||
|
||||
if !network_path.is_empty() {
|
||||
let import_start_index = if self.hidden_primary_import(network_path) { 1 } else { 0 };
|
||||
for import_index in import_start_index..self.number_of_imports(network_path) {
|
||||
import_export_ports.insert_output_port_at_center(import_index, import_export_position.0.as_dvec2() + DVec2::new(0., import_index as f64 * 24.));
|
||||
}
|
||||
}
|
||||
|
||||
let export_start_index = if self.hidden_primary_export(network_path) { 1 } else { 0 };
|
||||
for export_index in export_start_index..network.exports.len() {
|
||||
import_export_ports.insert_input_port_at_center(export_index, import_export_position.1.as_dvec2() + DVec2::new(0., export_index as f64 * 24.));
|
||||
}
|
||||
|
||||
Some(import_export_ports)
|
||||
}
|
||||
|
||||
/// The width of a layer in grid units, which covers its thumbnail, its name and its icons. Cached
|
||||
/// because measuring the name's text is slow.
|
||||
pub(super) fn compute_layer_width(&self, node_id: &NodeId, network_path: &[NodeId]) -> u32 {
|
||||
const GAP_WIDTH: f64 = 8.;
|
||||
const FONT_SIZE: f64 = 14.;
|
||||
let left_thumbnail_padding = GRID_SIZE as f64 / 2.;
|
||||
let thumbnail_width = 3. * GRID_SIZE as f64;
|
||||
let layer_text = self.display_name(node_id, network_path);
|
||||
|
||||
let text_width = text_width(&layer_text, FONT_SIZE);
|
||||
|
||||
let grip_padding = 4.;
|
||||
let grip_width = 8.;
|
||||
let lock_icon_width = if self.is_locked(node_id, network_path) { GRID_SIZE as f64 } else { 0. };
|
||||
let icon_overhang_width = GRID_SIZE as f64 / 2.;
|
||||
|
||||
let layer_width_pixels = left_thumbnail_padding + thumbnail_width + GAP_WIDTH + text_width + grip_padding + grip_width + lock_icon_width + icon_overhang_width;
|
||||
((layer_width_pixels / 24.).ceil() as u32).max(8)
|
||||
}
|
||||
pub fn import_export_position(&self, network_path: &[NodeId]) -> Option<(IVec2, IVec2)> {
|
||||
let Some(all_nodes_bounding_box) = self.all_nodes_bounding_box(network_path) else {
|
||||
log::error!("Could not get all nodes bounding box in load_export_ports");
|
||||
return None;
|
||||
};
|
||||
let Some(network) = self.nested_network(network_path) else {
|
||||
log::error!("Could not get current network in load_export_ports");
|
||||
return None;
|
||||
};
|
||||
|
||||
let Some(network_metadata) = self.network_metadata(network_path) else {
|
||||
log::error!("Could not get nested network_metadata in load_export_ports");
|
||||
return None;
|
||||
};
|
||||
let node_graph_to_viewport = network_metadata.persistent_metadata.navigation_metadata.node_graph_to_viewport;
|
||||
let target_viewport_top_left = DVec2::new(IMPORTS_TO_LEFT_EDGE_PIXEL_GAP as f64, IMPORTS_TO_TOP_EDGE_PIXEL_GAP as f64);
|
||||
|
||||
let node_graph_pixel_offset_top_left = node_graph_to_viewport.inverse().transform_point2(target_viewport_top_left);
|
||||
|
||||
// A 5x5 grid offset from the top left corner
|
||||
let node_graph_grid_space_offset_top_left = node_graph_to_viewport.inverse().transform_point2(DVec2::ZERO) + DVec2::new(5. * GRID_SIZE as f64, 4. * GRID_SIZE as f64);
|
||||
|
||||
// The inner bound of the import is the highest/furthest left of the two offsets
|
||||
let top_left_inner_bound = DVec2::new(
|
||||
node_graph_pixel_offset_top_left.x.min(node_graph_grid_space_offset_top_left.x),
|
||||
node_graph_pixel_offset_top_left.y.min(node_graph_grid_space_offset_top_left.y),
|
||||
);
|
||||
|
||||
let offset_from_top_left = if network
|
||||
.exports
|
||||
.first()
|
||||
.is_some_and(|export| export.as_node().is_some_and(|export_node| self.is_layer(&export_node, network_path)))
|
||||
{
|
||||
DVec2::new(-4. * GRID_SIZE as f64, -2. * GRID_SIZE as f64)
|
||||
} else {
|
||||
DVec2::new(-4. * GRID_SIZE as f64, 0.)
|
||||
};
|
||||
|
||||
let bounding_box_top_left = DVec2::new((all_nodes_bounding_box[0].x / 24. + 0.5).floor() * 24., (all_nodes_bounding_box[0].y / 24. + 0.5).floor() * 24.) + offset_from_top_left;
|
||||
let import_top_left = DVec2::new(top_left_inner_bound.x.min(bounding_box_top_left.x), top_left_inner_bound.y.min(bounding_box_top_left.y));
|
||||
let rounded_import_top_left = DVec2::new((import_top_left.x / 24.).round() * 24., (import_top_left.y / 24.).round() * 24.);
|
||||
|
||||
let viewport_width = network_metadata.persistent_metadata.navigation_metadata.node_graph_width;
|
||||
|
||||
let target_viewport_top_right = DVec2::new(viewport_width - EXPORTS_TO_RIGHT_EDGE_PIXEL_GAP as f64, EXPORTS_TO_TOP_EDGE_PIXEL_GAP as f64);
|
||||
|
||||
// An offset from the right edge in viewport pixels
|
||||
let node_graph_pixel_offset_top_right = node_graph_to_viewport.inverse().transform_point2(target_viewport_top_right);
|
||||
|
||||
// A 5x5 grid offset from the right corner
|
||||
let node_graph_grid_space_offset_top_right = node_graph_to_viewport.inverse().transform_point2(DVec2::new(viewport_width, 0.)) + DVec2::new(-5. * GRID_SIZE as f64, 4. * GRID_SIZE as f64);
|
||||
|
||||
// The inner bound of the export is the highest/furthest right of the two offsets.
|
||||
// When zoomed out this keeps it a constant grid space away from the edge, but when zoomed in it prevents the exports from getting too far in
|
||||
let top_right_inner_bound = DVec2::new(
|
||||
node_graph_pixel_offset_top_right.x.max(node_graph_grid_space_offset_top_right.x),
|
||||
node_graph_pixel_offset_top_right.y.min(node_graph_grid_space_offset_top_right.y),
|
||||
);
|
||||
|
||||
let offset_from_top_right = if network
|
||||
.exports
|
||||
.first()
|
||||
.is_some_and(|export| export.as_node().is_some_and(|export_node| self.is_layer(&export_node, network_path)))
|
||||
{
|
||||
DVec2::new(2. * GRID_SIZE as f64, -2. * GRID_SIZE as f64)
|
||||
} else {
|
||||
DVec2::new(4. * GRID_SIZE as f64, 0.)
|
||||
};
|
||||
|
||||
let mut bounding_box_top_right = DVec2::new((all_nodes_bounding_box[1].x / 24. + 0.5).floor() * 24., (all_nodes_bounding_box[0].y / 24. + 0.5).floor() * 24.);
|
||||
bounding_box_top_right += offset_from_top_right;
|
||||
let export_top_right = DVec2::new(top_right_inner_bound.x.max(bounding_box_top_right.x), top_right_inner_bound.y.min(bounding_box_top_right.y));
|
||||
let rounded_export_top_right = DVec2::new((export_top_right.x / 24.).round() * 24., (export_top_right.y / 24.).round() * 24.);
|
||||
|
||||
Some((rounded_import_top_left.as_ivec2(), rounded_export_top_right.as_ivec2()))
|
||||
}
|
||||
}
|
||||
@@ -121,11 +121,11 @@ impl NodeNetworkInterface {
|
||||
}
|
||||
|
||||
pub fn node_graph_ptz_mut(&mut self, network_path: &[NodeId]) -> Option<&mut PTZ> {
|
||||
let Some(navigation) = self.navigation_mut(network_path) else {
|
||||
let Some(network_metadata) = self.network_metadata_mut(network_path) else {
|
||||
log::error!("Could not get nested network_metadata in node_graph_ptz_mut");
|
||||
return None;
|
||||
};
|
||||
Some(&mut navigation.node_graph_ptz)
|
||||
Some(&mut network_metadata.persistent_metadata.navigation_metadata.node_graph_ptz)
|
||||
}
|
||||
|
||||
// TODO: Optimize getting click target intersections from click by using a spacial data structure like a quadtree instead of linear search
|
||||
|
||||
-40
@@ -1,40 +0,0 @@
|
||||
//! What a change feeds: each rule names a kind of edit and unloads everything derived from it.
|
||||
//!
|
||||
//! Declared here once rather than restated at each mutation site, so two edits of the same kind cannot
|
||||
//! disagree about what they invalidate.
|
||||
|
||||
use super::*;
|
||||
|
||||
impl NodeNetworkInterface {
|
||||
/// Unloads everything a node's position feeds: its own geometry, the geometry of every node placed
|
||||
/// relative to it, and the network bounds. A chain node also sets the width of the layer encapsulating
|
||||
/// its chain, so that layer reloads too.
|
||||
///
|
||||
/// Takes the changed nodes as a batch, so a run of moves walks the upstream cone once.
|
||||
pub(crate) fn invalidate_positions(&mut self, node_ids: Vec<NodeId>, network_path: &[NodeId]) {
|
||||
let encapsulating_layers = node_ids
|
||||
.iter()
|
||||
.filter(|node_id| self.is_chain(node_id, network_path))
|
||||
.filter_map(|node_id| self.downstream_layer_for_chain_node(node_id, network_path))
|
||||
.collect::<Vec<_>>();
|
||||
for downstream_layer in encapsulating_layers {
|
||||
self.unload_node_click_targets(&downstream_layer, network_path);
|
||||
}
|
||||
|
||||
self.unload_upstream_node_click_targets(node_ids, network_path);
|
||||
self.unload_all_nodes_bounding_box(network_path);
|
||||
}
|
||||
|
||||
/// Unloads the network's import and export strip: the ports themselves and the handles beside them
|
||||
/// for adding, removing and reordering.
|
||||
pub(crate) fn invalidate_import_export(&mut self, network_path: &[NodeId]) {
|
||||
self.unload_import_export_ports(network_path);
|
||||
self.unload_modify_import_export(network_path);
|
||||
}
|
||||
|
||||
/// Unloads what a node's name or lock state feeds: a layer's width, and the geometry sized from it.
|
||||
pub(crate) fn invalidate_node_appearance(&mut self, node_id: &NodeId, network_path: &[NodeId]) {
|
||||
self.try_unload_layer_width(node_id, network_path);
|
||||
self.unload_node_click_targets(node_id, network_path);
|
||||
}
|
||||
}
|
||||
+330
-541
File diff suppressed because it is too large.
Load diff
+764
-314
File diff suppressed because it is too large.
Load diff
+317
-35
@@ -22,24 +22,10 @@ impl NodeNetworkInterface {
|
||||
pub fn document_network(&self) -> &NodeNetwork {
|
||||
self.network.network()
|
||||
}
|
||||
|
||||
/// The document network as it should be evaluated, which is the document itself with the previewed
|
||||
/// node substituted for the export.
|
||||
///
|
||||
/// Previewing is this peer's alone, so it is applied to the copy being compiled rather than written
|
||||
/// into the document. Every path that compiles the graph goes through here, so none of them can
|
||||
/// render the export while the user is previewing something else.
|
||||
pub fn network_to_evaluate(&self) -> NodeNetwork {
|
||||
let mut network = self.document_network().clone();
|
||||
|
||||
if let Previewing::Yes { previewed } = self.previewing(&[])
|
||||
&& let Some(export) = network.exports.first_mut()
|
||||
{
|
||||
*export = NodeInput::node(previewed.node_id, previewed.output_index);
|
||||
}
|
||||
|
||||
network
|
||||
pub fn document_network_mut(&mut self) -> &mut NodeNetwork {
|
||||
self.network.network_mut()
|
||||
}
|
||||
|
||||
/// Gets the nested network based on network_path
|
||||
pub fn nested_network(&self, network_path: &[NodeId]) -> Option<&NodeNetwork> {
|
||||
let Some(network) = self.document_network().nested_network(network_path) else {
|
||||
@@ -186,11 +172,6 @@ impl NodeNetworkInterface {
|
||||
self.query(network_path, "has_primary_input", |view| view.has_primary_input(node_id)).unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Grid rows the node body spans, which is the greater of its input rows and its output count.
|
||||
pub fn displayed_row_count(&self, node_id: &NodeId, network_path: &[NodeId]) -> usize {
|
||||
self.query(network_path, "displayed_row_count", |view| view.displayed_row_count(node_id)).unwrap_or(1)
|
||||
}
|
||||
|
||||
pub fn number_of_outputs(&self, node_id: &NodeId, network_path: &[NodeId]) -> usize {
|
||||
self.query(network_path, "number_of_outputs", |view| view.number_of_outputs(node_id)).unwrap_or_default()
|
||||
}
|
||||
@@ -312,16 +293,273 @@ impl NodeNetworkInterface {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn collect_used_resources(&self, target: &mut HashSet<ResourceId>) {
|
||||
visit_network_resources(self.document_network(), &mut |id| {
|
||||
target.insert(id);
|
||||
pub fn position(&self, node_id: &NodeId, network_path: &[NodeId]) -> Option<IVec2> {
|
||||
self.try_load_node_click_targets(node_id, network_path);
|
||||
let top_left_position = self.try_get_node_bounding_box(node_id, network_path).map(|mut bounding_box| {
|
||||
if !self.is_layer(node_id, network_path) {
|
||||
bounding_box[0] -= DVec2::new(0., 12.);
|
||||
}
|
||||
(bounding_box[0] / 24.).as_ivec2()
|
||||
});
|
||||
top_left_position.map(|position| {
|
||||
if self.is_layer(node_id, network_path) {
|
||||
position + IVec2::new(self.chain_width(node_id, network_path) as i32, 0)
|
||||
} else {
|
||||
position
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn collect_resources_use_counts(&self) -> HashMap<ResourceId, usize> {
|
||||
let mut counts = HashMap::new();
|
||||
visit_network_resources(self.document_network(), &mut |id| *counts.entry(id).or_insert(0) += 1);
|
||||
counts
|
||||
pub fn collect_used_resources(&self, target: &mut HashSet<ResourceId>) {
|
||||
collect_network_resources(self.document_network(), target);
|
||||
}
|
||||
|
||||
pub fn frontend_imports(&self, network_path: &[NodeId]) -> Vec<Option<FrontendGraphOutput>> {
|
||||
match network_path.split_last() {
|
||||
Some((node_id, encapsulating_network_path)) => {
|
||||
let Some(node) = self.document_node(node_id, encapsulating_network_path) else {
|
||||
log::error!("Could not get node {node_id} in network {encapsulating_network_path:?}");
|
||||
return Vec::new();
|
||||
};
|
||||
let mut frontend_imports = (0..node.inputs.len())
|
||||
.map(|import_index| self.frontend_output_from_connector(&OutputConnector::Import(import_index), network_path))
|
||||
.collect::<Vec<_>>();
|
||||
if frontend_imports.is_empty() {
|
||||
frontend_imports.push(None);
|
||||
}
|
||||
frontend_imports
|
||||
}
|
||||
// In the document network display no imports
|
||||
None => Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn frontend_exports(&self, network_path: &[NodeId]) -> Vec<Option<FrontendGraphInput>> {
|
||||
let Some(network) = self.nested_network(network_path) else { return Vec::new() };
|
||||
let mut frontend_exports = ((0..network.exports.len()).map(|export_index| self.frontend_input_from_connector(&InputConnector::Export(export_index), network_path))).collect::<Vec<_>>();
|
||||
if frontend_exports.is_empty() {
|
||||
frontend_exports.push(None);
|
||||
}
|
||||
frontend_exports
|
||||
}
|
||||
|
||||
pub fn import_export_position(&self, network_path: &[NodeId]) -> Option<(IVec2, IVec2)> {
|
||||
let Some(all_nodes_bounding_box) = self.all_nodes_bounding_box(network_path) else {
|
||||
log::error!("Could not get all nodes bounding box in load_export_ports");
|
||||
return None;
|
||||
};
|
||||
let Some(network) = self.nested_network(network_path) else {
|
||||
log::error!("Could not get current network in load_export_ports");
|
||||
return None;
|
||||
};
|
||||
|
||||
let Some(network_metadata) = self.network_metadata(network_path) else {
|
||||
log::error!("Could not get nested network_metadata in load_export_ports");
|
||||
return None;
|
||||
};
|
||||
let node_graph_to_viewport = network_metadata.persistent_metadata.navigation_metadata.node_graph_to_viewport;
|
||||
let target_viewport_top_left = DVec2::new(IMPORTS_TO_LEFT_EDGE_PIXEL_GAP as f64, IMPORTS_TO_TOP_EDGE_PIXEL_GAP as f64);
|
||||
|
||||
let node_graph_pixel_offset_top_left = node_graph_to_viewport.inverse().transform_point2(target_viewport_top_left);
|
||||
|
||||
// A 5x5 grid offset from the top left corner
|
||||
let node_graph_grid_space_offset_top_left = node_graph_to_viewport.inverse().transform_point2(DVec2::ZERO) + DVec2::new(5. * GRID_SIZE as f64, 4. * GRID_SIZE as f64);
|
||||
|
||||
// The inner bound of the import is the highest/furthest left of the two offsets
|
||||
let top_left_inner_bound = DVec2::new(
|
||||
node_graph_pixel_offset_top_left.x.min(node_graph_grid_space_offset_top_left.x),
|
||||
node_graph_pixel_offset_top_left.y.min(node_graph_grid_space_offset_top_left.y),
|
||||
);
|
||||
|
||||
let offset_from_top_left = if network
|
||||
.exports
|
||||
.first()
|
||||
.is_some_and(|export| export.as_node().is_some_and(|export_node| self.is_layer(&export_node, network_path)))
|
||||
{
|
||||
DVec2::new(-4. * GRID_SIZE as f64, -2. * GRID_SIZE as f64)
|
||||
} else {
|
||||
DVec2::new(-4. * GRID_SIZE as f64, 0.)
|
||||
};
|
||||
|
||||
let bounding_box_top_left = DVec2::new((all_nodes_bounding_box[0].x / 24. + 0.5).floor() * 24., (all_nodes_bounding_box[0].y / 24. + 0.5).floor() * 24.) + offset_from_top_left;
|
||||
let import_top_left = DVec2::new(top_left_inner_bound.x.min(bounding_box_top_left.x), top_left_inner_bound.y.min(bounding_box_top_left.y));
|
||||
let rounded_import_top_left = DVec2::new((import_top_left.x / 24.).round() * 24., (import_top_left.y / 24.).round() * 24.);
|
||||
|
||||
let viewport_width = network_metadata.persistent_metadata.navigation_metadata.node_graph_width;
|
||||
|
||||
let target_viewport_top_right = DVec2::new(viewport_width - EXPORTS_TO_RIGHT_EDGE_PIXEL_GAP as f64, EXPORTS_TO_TOP_EDGE_PIXEL_GAP as f64);
|
||||
|
||||
// An offset from the right edge in viewport pixels
|
||||
let node_graph_pixel_offset_top_right = node_graph_to_viewport.inverse().transform_point2(target_viewport_top_right);
|
||||
|
||||
// A 5x5 grid offset from the right corner
|
||||
let node_graph_grid_space_offset_top_right = node_graph_to_viewport.inverse().transform_point2(DVec2::new(viewport_width, 0.)) + DVec2::new(-5. * GRID_SIZE as f64, 4. * GRID_SIZE as f64);
|
||||
|
||||
// The inner bound of the export is the highest/furthest right of the two offsets.
|
||||
// When zoomed out this keeps it a constant grid space away from the edge, but when zoomed in it prevents the exports from getting too far in
|
||||
let top_right_inner_bound = DVec2::new(
|
||||
node_graph_pixel_offset_top_right.x.max(node_graph_grid_space_offset_top_right.x),
|
||||
node_graph_pixel_offset_top_right.y.min(node_graph_grid_space_offset_top_right.y),
|
||||
);
|
||||
|
||||
let offset_from_top_right = if network
|
||||
.exports
|
||||
.first()
|
||||
.is_some_and(|export| export.as_node().is_some_and(|export_node| self.is_layer(&export_node, network_path)))
|
||||
{
|
||||
DVec2::new(2. * GRID_SIZE as f64, -2. * GRID_SIZE as f64)
|
||||
} else {
|
||||
DVec2::new(4. * GRID_SIZE as f64, 0.)
|
||||
};
|
||||
|
||||
let mut bounding_box_top_right = DVec2::new((all_nodes_bounding_box[1].x / 24. + 0.5).floor() * 24., (all_nodes_bounding_box[0].y / 24. + 0.5).floor() * 24.);
|
||||
bounding_box_top_right += offset_from_top_right;
|
||||
let export_top_right = DVec2::new(top_right_inner_bound.x.max(bounding_box_top_right.x), top_right_inner_bound.y.min(bounding_box_top_right.y));
|
||||
let rounded_export_top_right = DVec2::new((export_top_right.x / 24.).round() * 24., (export_top_right.y / 24.).round() * 24.);
|
||||
|
||||
Some((rounded_import_top_left.as_ivec2(), rounded_export_top_right.as_ivec2()))
|
||||
}
|
||||
|
||||
/// Returns None if there is an error, it is a hidden primary export, or a hidden input
|
||||
pub fn frontend_input_from_connector(&self, input_connector: &InputConnector, network_path: &[NodeId]) -> Option<FrontendGraphInput> {
|
||||
// Return None if it is a hidden input
|
||||
if self.input_from_connector(input_connector, network_path).is_some_and(|input| !input.is_exposed()) {
|
||||
return None;
|
||||
}
|
||||
let input_type = self.input_type(input_connector, network_path);
|
||||
let data_type = input_type.displayed_type();
|
||||
let resolved_type = input_type.resolved_type_node_string();
|
||||
|
||||
let connected_to = self
|
||||
.upstream_output_connector(input_connector, network_path)
|
||||
.map(|output_connector| match output_connector {
|
||||
OutputConnector::Node { node_id, output_index } => {
|
||||
let name = self.display_name(&node_id, network_path);
|
||||
format!("Connected to output #{output_index} of \"{name}\", ID: {node_id}.")
|
||||
}
|
||||
OutputConnector::Import(import_index) => format!("Connected to import #{import_index}."),
|
||||
})
|
||||
.unwrap_or("Connected to nothing.".to_string());
|
||||
|
||||
let (name, description) = match input_connector {
|
||||
InputConnector::Node { node_id, input_index } => self.displayed_input_name_and_description(node_id, *input_index, network_path),
|
||||
InputConnector::Export(export_index) => {
|
||||
// Get export name from parent node metadata input, which must match the number of exports.
|
||||
// Empty string means to use type, or "Export + index" if type is empty determined
|
||||
let export_name = if network_path.is_empty() {
|
||||
"Canvas".to_string()
|
||||
} else {
|
||||
self.encapsulating_node_metadata(network_path)
|
||||
.and_then(|encapsulating_metadata| encapsulating_metadata.persistent_metadata.output_names.get(*export_index).cloned())
|
||||
.unwrap_or_default()
|
||||
};
|
||||
|
||||
let export_name = if !export_name.is_empty() {
|
||||
export_name
|
||||
} else if let Some(export_type_name) = input_type.compiled_nested_type().map(ToString::to_string) {
|
||||
export_type_name
|
||||
} else {
|
||||
format!("Export #{}", export_index)
|
||||
};
|
||||
|
||||
(export_name, String::new())
|
||||
}
|
||||
};
|
||||
|
||||
let valid_types = self.potential_valid_input_types(input_connector, network_path).iter().map(ToString::to_string).collect::<Vec<_>>();
|
||||
let valid_types = {
|
||||
// Dedupe while preserving order
|
||||
let mut found = HashSet::new();
|
||||
valid_types.into_iter().filter(|s| found.insert(s.clone())).collect::<Vec<_>>()
|
||||
};
|
||||
|
||||
Some(FrontendGraphInput {
|
||||
data_type,
|
||||
resolved_type,
|
||||
name,
|
||||
description,
|
||||
valid_types,
|
||||
connected_to,
|
||||
})
|
||||
}
|
||||
|
||||
/// Returns None if there is an error, it is the document network, a hidden primary output or import
|
||||
pub fn frontend_output_from_connector(&self, output_connector: &OutputConnector, network_path: &[NodeId]) -> Option<FrontendGraphOutput> {
|
||||
let output_type = self.output_type(output_connector, network_path);
|
||||
let (name, description) = match output_connector {
|
||||
OutputConnector::Node { node_id, output_index } => {
|
||||
// Do not display the primary output port for a node if it is a network node with a hidden primary export
|
||||
if *output_index == 0 && self.hidden_primary_output(node_id, network_path) {
|
||||
return None;
|
||||
};
|
||||
// Get the output name from the interior network export name
|
||||
let node_metadata = self.node_metadata(node_id, network_path)?;
|
||||
let output_name = node_metadata.persistent_metadata.output_names.get(*output_index).cloned().unwrap_or_default();
|
||||
|
||||
let output_name = if !output_name.is_empty() { output_name } else { output_type.resolved_type_node_string() };
|
||||
(output_name, String::new())
|
||||
}
|
||||
OutputConnector::Import(import_index) => {
|
||||
// Get the import name from the encapsulating node input metadata
|
||||
let Some((encapsulating_node_id, encapsulating_path)) = network_path.split_last() else {
|
||||
// Return None if it is an import in the document network
|
||||
return None;
|
||||
};
|
||||
// Return None if the primary input is hidden and this is the primary import
|
||||
if *import_index == 0 && self.hidden_primary_import(network_path) {
|
||||
return None;
|
||||
};
|
||||
let (import_name, description) = self.displayed_input_name_and_description(encapsulating_node_id, *import_index, encapsulating_path);
|
||||
|
||||
let import_name = if !import_name.is_empty() {
|
||||
import_name
|
||||
} else if let Some(import_type_name) = output_type.compiled_nested_type().map(ToString::to_string) {
|
||||
import_type_name
|
||||
} else {
|
||||
format!("Import #{}", import_index)
|
||||
};
|
||||
|
||||
(import_name, description)
|
||||
}
|
||||
};
|
||||
let data_type = output_type.displayed_type();
|
||||
let resolved_type = output_type.resolved_type_node_string();
|
||||
let mut connected_to = self
|
||||
.with_outward_wires(network_path, |outward_wires| outward_wires.get(output_connector).cloned())
|
||||
.flatten()
|
||||
.unwrap_or_default()
|
||||
.iter()
|
||||
.map(|input| match input {
|
||||
&InputConnector::Node { node_id, input_index } => {
|
||||
let name = self.display_name(&node_id, network_path);
|
||||
format!("Connected to input #{input_index} of \"{name}\", ID: {node_id}.")
|
||||
}
|
||||
InputConnector::Export(export_index) => format!("Connected to export #{export_index}."),
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
if connected_to.is_empty() {
|
||||
connected_to.push("Connected to nothing.".to_string());
|
||||
}
|
||||
|
||||
Some(FrontendGraphOutput {
|
||||
data_type,
|
||||
resolved_type,
|
||||
name,
|
||||
description,
|
||||
connected_to,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn height_from_click_target(&self, node_id: &NodeId, network_path: &[NodeId]) -> Option<u32> {
|
||||
self.try_load_node_click_targets(node_id, network_path);
|
||||
let mut node_height: Option<u32> = self
|
||||
.try_get_node_bounding_box(node_id, network_path)
|
||||
.map(|bounding_box| ((bounding_box[1].y - bounding_box[0].y) / 24.) as u32);
|
||||
if !self.is_layer(node_id, network_path) {
|
||||
node_height = node_height.map(|height| height + 1);
|
||||
}
|
||||
node_height
|
||||
}
|
||||
|
||||
/// Returns whether every downstream path from the node's outputs stays within the dependent set defined by `classify`, meaning nothing else in the graph depends on this node.
|
||||
@@ -549,11 +787,29 @@ impl NodeNetworkInterface {
|
||||
}
|
||||
|
||||
pub fn set_input_override(&mut self, node_id: &NodeId, index: usize, widget_override: Option<String>, network_path: &[NodeId]) {
|
||||
let Some(mut node) = self.node_mut(NodeLocator::new(*node_id, network_path)) else {
|
||||
log::error!("Could not get node {node_id} in set_input_override");
|
||||
let Some(metadata) = self
|
||||
.node_metadata_mut(node_id, network_path)
|
||||
.and_then(|node_metadata| node_metadata.persistent_metadata.input_metadata.get_mut(index))
|
||||
else {
|
||||
log::error!("Could not get input metadata for {node_id} index {index} in set_input_override");
|
||||
return;
|
||||
};
|
||||
node.set_widget_override(index, widget_override);
|
||||
metadata.persistent_metadata.widget_override = widget_override;
|
||||
}
|
||||
|
||||
/// Returns the input name to display in the properties panel. If the name is empty then the type is used.
|
||||
pub fn displayed_input_name_and_description(&self, node_id: &NodeId, input_index: usize, network_path: &[NodeId]) -> (String, String) {
|
||||
let Some(input_metadata) = self.persistent_input_metadata(node_id, input_index, network_path) else {
|
||||
log::warn!("input metadata not found in displayed_input_name_and_description");
|
||||
return (String::new(), String::new());
|
||||
};
|
||||
let description = input_metadata.input_description.to_string();
|
||||
let name = if input_metadata.input_name.is_empty() {
|
||||
self.input_type(&InputConnector::node_at_index(*node_id, input_index), network_path).resolved_type_node_string()
|
||||
} else {
|
||||
input_metadata.input_name.to_string()
|
||||
};
|
||||
(name, description)
|
||||
}
|
||||
|
||||
/// Returns the display name of the node. If the display name is empty, it will return "Untitled Node" or "Untitled Layer" depending on the node type.
|
||||
@@ -920,14 +1176,40 @@ impl NodeNetworkInterface {
|
||||
nested_network_metadata.persistent_metadata.node_metadata.insert(node_id, node_metadata);
|
||||
}
|
||||
}
|
||||
Self::from_trees(node_network, network_metadata)
|
||||
Self {
|
||||
network: MemoNetwork::new(node_network),
|
||||
network_metadata,
|
||||
document_metadata: DocumentMetadata::default(),
|
||||
resolved_types: ResolvedDocumentNodeTypes::default(),
|
||||
transaction_status: TransactionStatus::Finished,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Private mutable getters for use within the network interface
|
||||
impl NodeNetworkInterface {
|
||||
pub(crate) fn network_mut(&mut self, network_path: &[NodeId]) -> Option<&mut NodeNetwork> {
|
||||
self.document_network_mut().nested_network_mut(network_path)
|
||||
}
|
||||
|
||||
pub(crate) fn network_metadata_mut(&mut self, network_path: &[NodeId]) -> Option<&mut NodeNetworkMetadata> {
|
||||
self.network_metadata.nested_metadata_mut(network_path)
|
||||
}
|
||||
|
||||
pub(crate) fn node_metadata_mut(&mut self, node_id: &NodeId, network_path: &[NodeId]) -> Option<&mut DocumentNodeMetadata> {
|
||||
let Some(network_metadata) = self.network_metadata_mut(network_path) else {
|
||||
log::error!("Could not get nested network_metadata");
|
||||
return None;
|
||||
};
|
||||
let Some(node_metadata) = network_metadata.persistent_metadata.node_metadata.get_mut(node_id) else {
|
||||
log::error!("Could not get nested node_metadata for node {node_id} in network {network_path:?}");
|
||||
return None;
|
||||
};
|
||||
Some(node_metadata)
|
||||
}
|
||||
|
||||
/// Mutably get the network which the encapsulating node of the currently viewed network is part of. Will always be None in the document network.
|
||||
pub(super) fn encapsulating_network_metadata_mut(&mut self, network_path: &[NodeId]) -> Option<&mut NodeNetworkMetadata> {
|
||||
pub(crate) fn encapsulating_network_metadata_mut(&mut self, network_path: &[NodeId]) -> Option<&mut NodeNetworkMetadata> {
|
||||
let mut encapsulating_path = network_path.to_vec();
|
||||
encapsulating_path.pop()?;
|
||||
let Some(parent_metadata) = self.network_metadata_mut(&encapsulating_path) else {
|
||||
@@ -938,7 +1220,7 @@ impl NodeNetworkInterface {
|
||||
}
|
||||
|
||||
/// Get the node metadata for the node which encapsulates the currently viewed network. Will always be None in the document network.
|
||||
pub(super) fn encapsulating_node_metadata_mut(&mut self, network_path: &[NodeId]) -> Option<&mut DocumentNodeMetadata> {
|
||||
pub(crate) fn encapsulating_node_metadata_mut(&mut self, network_path: &[NodeId]) -> Option<&mut DocumentNodeMetadata> {
|
||||
let mut encapsulating_path = network_path.to_vec();
|
||||
let encapsulating_node_id = encapsulating_path.pop()?;
|
||||
let Some(parent_metadata) = self.network_metadata_mut(&encapsulating_path) else {
|
||||
|
||||
+26
-37
@@ -57,20 +57,26 @@ impl TypeSource {
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether the compiled type is a rank-1 `List<T>`, as opposed to a rank-0 `Item<T>` or a bare value.
|
||||
/// A bundled cell carrying a whole list displays as the list it carries.
|
||||
/// Whether the compiled type is a packed `Record` lane, as opposed to a bare rank-0 value.
|
||||
pub fn is_list(&self) -> bool {
|
||||
self.compiled_nested_type().is_some_and(|ty| matches!(ty, Type::List(_)) || ty.bundle_element_name().is_some())
|
||||
// `nested_type` peels `Record`, so the rank has to be read off the unpeeled type
|
||||
fn is_record(ty: &Type) -> bool {
|
||||
match ty {
|
||||
Type::Fn(_, output) | Type::Future(output) => is_record(output),
|
||||
Type::Record(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
match self {
|
||||
TypeSource::Compiled(compiled_type) => is_record(compiled_type),
|
||||
TypeSource::TaggedValue(value_type) => is_record(value_type),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// The element type with any rank-0 `Item` or rank-1 `List` wrapper peeled, so semantic type checks can be rank-agnostic.
|
||||
pub fn compiled_element_type(&self) -> Option<&Type> {
|
||||
Some(element_of(self.compiled_nested_type()?))
|
||||
}
|
||||
|
||||
/// The identifier name of [`Self::compiled_element_type`].
|
||||
/// The element type's identifier name, so semantic type checks can be rank-agnostic.
|
||||
pub fn compiled_element_name(&self) -> Option<String> {
|
||||
Some(self.compiled_element_type()?.identifier_name())
|
||||
Some(self.compiled_nested_type()?.identifier_name())
|
||||
}
|
||||
|
||||
pub fn compiled_nested_type(&self) -> Option<&Type> {
|
||||
@@ -109,14 +115,6 @@ impl TypeSource {
|
||||
}
|
||||
}
|
||||
|
||||
/// Peels any `Fn`/`Future` wrapper, then any rank-0 `Item` or rank-1 `List` wrapper, down to the element type.
|
||||
fn element_of(ty: &Type) -> &Type {
|
||||
match ty.nested_type() {
|
||||
Type::Item(element) | Type::List(element) => element.as_ref(),
|
||||
other => other,
|
||||
}
|
||||
}
|
||||
|
||||
impl NodeNetworkInterface {
|
||||
fn input_has_error(&self, input_connector: &InputConnector, network_path: &[NodeId]) -> bool {
|
||||
match input_connector {
|
||||
@@ -185,13 +183,13 @@ impl NodeNetworkInterface {
|
||||
}
|
||||
|
||||
let chain_type = self.input_type(&secondary_input, network_path);
|
||||
match chain_type.compiled_element_type() {
|
||||
match chain_type.compiled_nested_type() {
|
||||
Some(element) => {
|
||||
let Some(implementations) = NODE_REGISTRY.get(node) else {
|
||||
log::error!("Proto node {node:?} not found in the node registry, in layer_chain_hosts_node");
|
||||
return false;
|
||||
};
|
||||
implementations.keys().any(|node_io| node_io.inputs.first().is_some_and(|content| element_of(content) == element))
|
||||
implementations.iter().any(|entry| entry.io.inputs.first().is_some_and(|content| content.nested_type() == element))
|
||||
}
|
||||
None => !matches!(chain_type, TypeSource::Invalid),
|
||||
}
|
||||
@@ -243,18 +241,7 @@ impl NodeNetworkInterface {
|
||||
}
|
||||
};
|
||||
|
||||
// A List-typed default drops to its Item counterpart (when that has a default value and the connector accepts rank 0),
|
||||
// since a stored Item default can promote back onto a List connector but a stored List default can never return to rank 0
|
||||
if let Some(element) = guaranteed_type.nested_type().list_element()
|
||||
&& let Some(item_type) = self
|
||||
.potential_valid_input_types(input_connector, network_path)
|
||||
.into_iter()
|
||||
.find(|ty| matches!(ty.nested_type(), Type::Item(item_element) if item_element.as_ref() == element))
|
||||
&& let Some(item_default) = TaggedValue::from_type(&item_type)
|
||||
{
|
||||
return item_default;
|
||||
}
|
||||
|
||||
// `TaggedValue::from_type` recurses through `Record` to the element, so a record default already drops to rank 0
|
||||
TaggedValue::from_type_or_none(&guaranteed_type)
|
||||
}
|
||||
|
||||
@@ -300,8 +287,9 @@ impl NodeNetworkInterface {
|
||||
};
|
||||
let number_of_inputs = self.number_of_inputs(node_id, network_path);
|
||||
implementations
|
||||
.keys()
|
||||
.filter_map(|node_io| {
|
||||
.iter()
|
||||
.filter_map(|entry| {
|
||||
let node_io = &entry.io;
|
||||
// Check if this NodeIOTypes implementation is valid for the other inputs
|
||||
let valid_implementation = (0..number_of_inputs).filter(|iterator_index| iterator_index != input_index).all(|iterator_index| {
|
||||
let input_type = self.input_type_not_invalid(&InputConnector::node_at_index(*node_id, iterator_index), network_path);
|
||||
@@ -340,8 +328,9 @@ impl NodeNetworkInterface {
|
||||
let valid_output_types = self.valid_output_types(&OutputConnector::primary_output(*node_id), network_path);
|
||||
|
||||
implementations
|
||||
.keys()
|
||||
.filter_map(|node_io| {
|
||||
.iter()
|
||||
.filter_map(|entry| {
|
||||
let node_io = &entry.io;
|
||||
if !valid_output_types.iter().any(|output_type| output_type.nested_type() == node_io.return_value.nested_type()) {
|
||||
return None;
|
||||
}
|
||||
@@ -370,7 +359,7 @@ impl NodeNetworkInterface {
|
||||
log::error!("Protonode {render_node:?} not found in registry");
|
||||
return Vec::new();
|
||||
};
|
||||
implementations.keys().map(|types| types.inputs[1].clone()).collect()
|
||||
implementations.iter().map(|entry| entry.io.inputs[1].clone()).collect()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+35
-37
@@ -13,9 +13,10 @@ use glam::IVec2;
|
||||
use graph_craft::document::{DocumentNodeImplementation, NodeId, NodeNetwork};
|
||||
use graphene_std::vector::style::RenderMode;
|
||||
|
||||
use super::memo_network::MemoNetwork;
|
||||
use super::{
|
||||
DocumentNodePersistentMetadata, DocumentNodeTransientMetadata, InputMetadata, InputPersistentMetadata, LayerPosition, NavigationMetadata, NodeNetworkInterface, NodeNetworkMetadata,
|
||||
NodePersistentMetadata, NodePosition, NodeTypePersistentMetadata, PTZ,
|
||||
NodePersistentMetadata, NodePosition, NodeTypePersistentMetadata, PTZ, Previewing,
|
||||
};
|
||||
use crate::messages::portfolio::document::overlays::utility_types::OverlaysVisibilitySettings;
|
||||
use crate::messages::portfolio::document::utility_types::misc::SnappingState;
|
||||
@@ -64,7 +65,16 @@ impl StorageMetadataView<'_> {
|
||||
|
||||
impl NodeMetadataSource for StorageMetadataView<'_> {
|
||||
fn position(&self, network_path: &[NodeId], local_id: NodeId) -> Option<Position> {
|
||||
Some(position_from_runtime(&self.persistent(network_path, local_id)?.node_type_metadata))
|
||||
match &self.persistent(network_path, local_id)?.node_type_metadata {
|
||||
NodeTypePersistentMetadata::Layer(layer) => match layer.position {
|
||||
LayerPosition::Absolute(v) => Some(Position::Absolute([v.x, v.y])),
|
||||
LayerPosition::Stack(offset) => Some(Position::Stack(offset)),
|
||||
},
|
||||
NodeTypePersistentMetadata::Node(node) => match *node.position() {
|
||||
NodePosition::Absolute(v) => Some(Position::Absolute([v.x, v.y])),
|
||||
NodePosition::Chain => Some(Position::Chain),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn is_layer(&self, network_path: &[NodeId], local_id: NodeId) -> bool {
|
||||
@@ -104,21 +114,10 @@ impl NodeMetadataSource for StorageMetadataView<'_> {
|
||||
self.persistent(network_path, local_id).map(|p| p.output_names.clone()).unwrap_or_default()
|
||||
}
|
||||
|
||||
fn storage_node_id(&self, network_path: &[NodeId], local_id: NodeId) -> Option<document_graph_storage::NodeId> {
|
||||
self.persistent(network_path, local_id)?.storage_id.map(document_graph_storage::NodeId)
|
||||
}
|
||||
fn reference(&self, network_path: &[NodeId]) -> Option<&str> {
|
||||
let network_metadata = self.interface.network_metadata.nested_metadata(network_path)?;
|
||||
network_metadata.persistent_metadata.reference.as_deref()
|
||||
}
|
||||
|
||||
fn pinned_order(&self, network_path: &[NodeId]) -> Vec<NodeId> {
|
||||
self.interface
|
||||
.network_metadata
|
||||
.nested_metadata(network_path)
|
||||
.map(|network_metadata| network_metadata.persistent_metadata.pinned_node_order.clone())
|
||||
.unwrap_or_default()
|
||||
}
|
||||
}
|
||||
|
||||
impl DocumentSettings<'_> {
|
||||
@@ -149,20 +148,6 @@ impl DocumentSettings<'_> {
|
||||
|
||||
/// Inverse of the position extraction in `NodeMetadataSource::position`.
|
||||
/// `(Stack, !is_layer)` and `(Chain, is_layer)` shouldn't arise from a faithful round-trip; they fall back to a default of the matching variant.
|
||||
/// The stored position of a node, which pairs with `is_layer` to reconstruct the runtime node type.
|
||||
pub fn position_from_runtime(node_type: &NodeTypePersistentMetadata) -> Position {
|
||||
match node_type {
|
||||
NodeTypePersistentMetadata::Layer(layer) => match layer.position {
|
||||
LayerPosition::Absolute(v) => Position::Absolute([v.x, v.y]),
|
||||
LayerPosition::Stack(offset) => Position::Stack(offset),
|
||||
},
|
||||
NodeTypePersistentMetadata::Node(node) => match *node.position() {
|
||||
NodePosition::Absolute(v) => Position::Absolute([v.x, v.y]),
|
||||
NodePosition::Chain => Position::Chain,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn position_to_runtime(position: Position, is_layer: bool) -> NodeTypePersistentMetadata {
|
||||
match (position, is_layer) {
|
||||
(Position::Absolute([x, y]), true) => NodeTypePersistentMetadata::layer(IVec2::new(x, y)),
|
||||
@@ -188,7 +173,12 @@ pub fn build_interface_from_storage(network: NodeNetwork, node_entries: Vec<Node
|
||||
apply_entries_into_tree(&network, &mut network_metadata, node_entries)?;
|
||||
apply_network_entries_into_tree(&mut network_metadata, network_entries);
|
||||
|
||||
Ok(NodeNetworkInterface::from_trees(network, network_metadata))
|
||||
let interface = NodeNetworkInterface {
|
||||
network: MemoNetwork::new(network),
|
||||
network_metadata,
|
||||
..Default::default()
|
||||
};
|
||||
Ok(interface)
|
||||
}
|
||||
|
||||
/// Build the runtime-`network_path` -> stable-`NetworkId` map from the `NetworkMetadataEntry`s that
|
||||
@@ -233,6 +223,13 @@ pub fn collect_network_view_settings(
|
||||
settings.insert(session::network::NAV_WIDTH.to_string(), value);
|
||||
}
|
||||
|
||||
// Skip the inert `Previewing::No` default so a network that has never been previewed stays empty.
|
||||
if !matches!(network_metadata.persistent_metadata.previewing, Previewing::No)
|
||||
&& let Ok(value) = serde_json::to_value(network_metadata.persistent_metadata.previewing)
|
||||
{
|
||||
settings.insert(session::network::PREVIEWING.to_string(), value);
|
||||
}
|
||||
|
||||
if !settings.is_empty() {
|
||||
out.insert(network_id, settings);
|
||||
}
|
||||
@@ -252,24 +249,30 @@ pub fn apply_network_view_settings(
|
||||
) {
|
||||
for (network_path, network_id) in network_ids {
|
||||
let Some(settings) = network_view_settings.get(network_id) else { continue };
|
||||
let Some(navigation) = interface.navigation_mut(network_path) else {
|
||||
let Some(network_metadata) = interface.network_metadata.nested_metadata_mut(network_path) else {
|
||||
continue;
|
||||
};
|
||||
let persistent = &mut network_metadata.persistent_metadata;
|
||||
|
||||
if let Some(value) = settings.get(session::network::NAV_PTZ)
|
||||
&& let Ok(ptz) = serde_json::from_value::<PTZ>(value.clone())
|
||||
{
|
||||
navigation.node_graph_ptz = ptz;
|
||||
persistent.navigation_metadata.node_graph_ptz = ptz;
|
||||
}
|
||||
if let Some(value) = settings.get(session::network::NAV_TRANSFORM)
|
||||
&& let Ok(transform) = serde_json::from_value(value.clone())
|
||||
{
|
||||
navigation.node_graph_to_viewport = transform;
|
||||
persistent.navigation_metadata.node_graph_to_viewport = transform;
|
||||
}
|
||||
if let Some(value) = settings.get(session::network::NAV_WIDTH)
|
||||
&& let Ok(width) = serde_json::from_value(value.clone())
|
||||
{
|
||||
navigation.node_graph_width = width;
|
||||
persistent.navigation_metadata.node_graph_width = width;
|
||||
}
|
||||
if let Some(value) = settings.get(session::network::PREVIEWING)
|
||||
&& let Ok(previewing) = serde_json::from_value::<Previewing>(value.clone())
|
||||
{
|
||||
persistent.previewing = previewing;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -285,7 +288,6 @@ fn apply_network_entries_into_tree(metadata: &mut NodeNetworkMetadata, entries:
|
||||
if let Some(reference) = entry.reference {
|
||||
network_metadata.persistent_metadata.reference = Some(reference);
|
||||
}
|
||||
network_metadata.persistent_metadata.pinned_node_order = entry.pinned_order;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -327,10 +329,6 @@ fn apply_entries_into_tree(network: &NodeNetwork, metadata: &mut NodeNetworkMeta
|
||||
|
||||
let persistent = &mut document_node_metadata.persistent_metadata;
|
||||
|
||||
// Pins the node to the identity storage holds for it, so the next conversion reuses it rather
|
||||
// than re-deriving one from the node's location.
|
||||
persistent.storage_id = Some(entry.storage_id.0);
|
||||
|
||||
if let Some(position) = entry.position {
|
||||
persistent.node_type_metadata = position_to_runtime(position, entry.is_layer);
|
||||
} else if entry.is_layer {
|
||||
|
||||
Loaded 100 of 397 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user