-
Notifications
You must be signed in to change notification settings - Fork 7
/
changes.patch
3323 lines (3289 loc) · 119 KB
/
changes.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
diff --git a/.gitignore b/.gitignore
index 5fa1eb9..96486fd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -28,7 +28,3 @@ migrate_working_dir/
.dart_tool/
.packages
build/
-
-Blueprint/
-Joystick/
-
diff --git a/LICENSE b/LICENSE
index a28d639..66251f2 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,7 +1,3 @@
-=============================
-LICENSE 1
-=============================
-
Copyright 2024 Alex S Torres
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
@@ -12,20 +8,4 @@ Redistribution and use in source and binary forms, with or without modification,
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-=============================
-LICENSE 2
-=============================
-
-Copyright 2024 Pip Doun
-
-Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
-
-1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
-
-2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
-
-3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\ No newline at end of file
diff --git a/README.md b/README.md
index 7ababc2..2c95aba 100644
--- a/README.md
+++ b/README.md
@@ -16,10 +16,9 @@ and the Flutter guide for
<p align="center">A highly customizable node editor for Flutter</p>
-https://github.com/user-attachments/assets/60980604-69ad-477f-900f-deec0219b913
-
-<img src="https://raw.githubusercontent.com/alexst07/flutter_node_editor/master/midia/nodes.png"/>
-
+<p align="center">
+ <img src="https://raw.githubusercontent.com/alexst07/flutter_node_editor/master/midia/nodes.png"/>
+</p>
## Features
diff --git a/examples/advanced/lib/main.dart b/examples/advanced/lib/main.dart
index 248aa85..4788464 100644
--- a/examples/advanced/lib/main.dart
+++ b/examples/advanced/lib/main.dart
@@ -1,17 +1,8 @@
-import 'dart:convert';
-
import 'package:flutter/material.dart';
import 'package:node_editor/node_editor.dart';
-import 'Blueprint/blueprint.dart';
-import 'joystick/flutter_joystick.dart';
-import 'dart:io' show Platform;
+import 'nodes.dart';
-//hardcoded
-String bp =
- '{"nodes":[{"name":"adder_1720696047881054","type":"adder","value":70.0,"pos":"Offset(217.1, 14.7)","ports":{"adder_inPort_1720696047881718":{"type":"input","multiConnections":false,"maxConnections":null},"adder_outPort_1720696047881719":{"type":"output","multiConnections":false,"maxConnections":null},"adder_inPort2_1720696047881720":{"type":"input","multiConnections":false,"maxConnections":null}}},{"name":"int_1720695994049152","type":"integer","value":"50","pos":"Offset(9.2, 18.6)","ports":{"int_outPort_1720695994054281":{"type":"output","multiConnections":false,"maxConnections":null}}},{"name":"adder_1720696047881054","type":"adder","value":70.0,"pos":"Offset(217.1, 14.7)","ports":{"adder_inPort_1720696047881718":{"type":"input","multiConnections":false,"maxConnections":null},"adder_outPort_1720696047881719":{"type":"output","multiConnections":false,"maxConnections":null},"adder_inPort2_1720696047881720":{"type":"input","multiConnections":false,"maxConnections":null}}},{"name":"int_1720696012552220","type":"integer","value":"20","pos":"Offset(8.9, 68.2)","ports":{"int_outPort_1720696012552244":{"type":"output","multiConnections":false,"maxConnections":null}}},{"name":"adder_1720696066246650","type":"adder","value":90.0,"pos":"Offset(22.3, 197.7)","ports":{"adder_inPort_1720696066246671":{"type":"input","multiConnections":false,"maxConnections":null},"adder_outPort_1720696066246673":{"type":"output","multiConnections":false,"maxConnections":null},"adder_inPort2_1720696066246675":{"type":"input","multiConnections":false,"maxConnections":null}}},{"name":"adder_1720696047881054","type":"adder","value":70.0,"pos":"Offset(217.1, 14.7)","ports":{"adder_inPort_1720696047881718":{"type":"input","multiConnections":false,"maxConnections":null},"adder_outPort_1720696047881719":{"type":"output","multiConnections":false,"maxConnections":null},"adder_inPort2_1720696047881720":{"type":"input","multiConnections":false,"maxConnections":null}}},{"name":"adder_1720696066246650","type":"adder","value":90.0,"pos":"Offset(22.3, 197.7)","ports":{"adder_inPort_1720696066246671":{"type":"input","multiConnections":false,"maxConnections":null},"adder_outPort_1720696066246673":{"type":"output","multiConnections":false,"maxConnections":null},"adder_inPort2_1720696066246675":{"type":"input","multiConnections":false,"maxConnections":null}}},{"name":"int_1720696012552220","type":"integer","value":"20","pos":"Offset(8.9, 68.2)","ports":{"int_outPort_1720696012552244":{"type":"output","multiConnections":false,"maxConnections":null}}},{"name":"adder_1720696129323395","type":"adder","value":160.0,"pos":"Offset(220.4, 240.0)","ports":{"adder_inPort_1720696129323414":{"type":"input","multiConnections":false,"maxConnections":null},"adder_outPort_1720696129323416":{"type":"output","multiConnections":false,"maxConnections":null},"adder_inPort2_1720696129323417":{"type":"input","multiConnections":false,"maxConnections":null}}},{"name":"adder_1720696066246650","type":"adder","value":90.0,"pos":"Offset(22.3, 197.7)","ports":{"adder_inPort_1720696066246671":{"type":"input","multiConnections":false,"maxConnections":null},"adder_outPort_1720696066246673":{"type":"output","multiConnections":false,"maxConnections":null},"adder_inPort2_1720696066246675":{"type":"input","multiConnections":false,"maxConnections":null}}},{"name":"adder_1720696129323395","type":"adder","value":160.0,"pos":"Offset(220.4, 240.0)","ports":{"adder_inPort_1720696129323414":{"type":"input","multiConnections":false,"maxConnections":null},"adder_outPort_1720696129323416":{"type":"output","multiConnections":false,"maxConnections":null},"adder_inPort2_1720696129323417":{"type":"input","multiConnections":false,"maxConnections":null}}},{"name":"adder_1720696047881054","type":"adder","value":70.0,"pos":"Offset(217.1, 14.7)","ports":{"adder_inPort_1720696047881718":{"type":"input","multiConnections":false,"maxConnections":null},"adder_outPort_1720696047881719":{"type":"output","multiConnections":false,"maxConnections":null},"adder_inPort2_1720696047881720":{"type":"input","multiConnections":false,"maxConnections":null}}},{"name":"print_1720696147104722","type":"print","value":"160.0","pos":"Offset(20.7, 360.4)","ports":{"print_inPort_1720696147104758":{"type":"input","multiConnections":false,"maxConnections":null}}},{"name":"adder_1720696129323395","type":"adder","value":160.0,"pos":"Offset(220.4, 240.0)","ports":{"adder_inPort_1720696129323414":{"type":"input","multiConnections":false,"maxConnections":null},"adder_outPort_1720696129323416":{"type":"output","multiConnections":false,"maxConnections":null},"adder_inPort2_1720696129323417":{"type":"input","multiConnections":false,"maxConnections":null}}}],"connections":[{"outPort":"int_outPort_1720695994054281","inPort":"adder_inPort_1720696047881718"},{"outPort":"int_outPort_1720696012552244","inPort":"adder_inPort2_1720696047881720"},{"outPort":"adder_outPort_1720696047881719","inPort":"adder_inPort_1720696066246671"},{"outPort":"int_outPort_1720696012552244","inPort":"adder_inPort2_1720696066246675"},{"outPort":"adder_outPort_1720696066246673","inPort":"adder_inPort_1720696129323414"},{"outPort":"adder_outPort_1720696047881719","inPort":"adder_inPort2_1720696129323417"},{"outPort":"adder_outPort_1720696129323416","inPort":"print_inPort_1720696147104758"}]}';
-//
-//start from here
void main() {
runApp(const MyApp());
}
@@ -22,42 +13,70 @@ class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
- debugShowCheckedModeBanner: false,
- title: 'Chains',
+ title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
- home: const MyHomePage(),
+ home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
- const MyHomePage({super.key});
+ const MyHomePage({super.key, required this.title});
+
+ final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
- final BlueprintController controller = BlueprintController();
- final JoystickController stickCtrl = JoystickController();
-
+ final NodeEditorController controller = NodeEditorController();
final FocusNode _focusNode = FocusNode();
-
- bool assetsLoaded = false;
-
+ final FocusNode _focusNode2 = FocusNode();
+ final TextEditingController _controller = TextEditingController();
@override
void initState() {
- controller.joystick = stickCtrl;
- controller.context = context;
- controller.needUpdate.addListener(() {
- setState(() {});
+ controller.addSelectListener((Connection conn) {
+ debugPrint("ON SELECT inNode: ${conn.inNode}, inPort: ${conn.inPort}");
});
+
+ controller.addNode(
+ componentNode('node_1_1'),
+ NodePosition.afterLast,
+ );
+ controller.addNode(
+ componentNode('node_1_2'),
+ NodePosition.afterLast,
+ );
+ controller.addNode(
+ componentNode('node_1_3'),
+ NodePosition.afterLast,
+ );
+ controller.addNode(
+ receiverNode('node_2_1', _focusNode2, _controller),
+ NodePosition.afterLast,
+ );
+ controller.addNode(
+ binaryNode('node_3_1'),
+ NodePosition.afterLast,
+ );
+ controller.addNode(
+ sinkNode('node_4_1'),
+ NodePosition.afterLast,
+ );
super.initState();
}
+ void _addNewNode() {
+ controller.addNode(
+ componentNode("new_node"),
+ NodePosition.afterLast,
+ );
+ }
+
@override
void dispose() {
_focusNode.dispose();
@@ -67,102 +86,27 @@ class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
- appBar: AppBar(
- backgroundColor: Theme.of(context).colorScheme.inversePrimary,
- actions: [
- //mount asset
- Padding(
- padding: const EdgeInsets.only(left: 8.0),
- child: Row(
- children: [
- assetsLoaded ? const Text("Eject") : const Text("Mount"),
- assetsLoaded
- ? IconButton(
- onPressed: () {},
- icon: const Icon(Icons.eject_rounded))
- : IconButton(
- onPressed: () {},
- icon: const Icon(Icons.sd_storage_rounded))
- ],
- ),
- ),
- Expanded(child: Container()),
- // select all
- IconButton(
- onPressed: () {
- controller.selectAll();
- },
- icon: const Icon(Icons.select_all_rounded)),
- //mapping
- IconButton(
- onPressed: () {
- var tree = controller.saveBlueprint();
- String jsonTree = jsonEncode(tree);
- debugPrint(jsonTree);
- // like a tree
- },
- icon: const Icon(Icons.map_rounded)),
- //sideload
- IconButton(
- onPressed: () {
- controller.cleanBlueprint();
- controller.loadBlueprint(bp);
- },
- icon: const Icon(Icons.upload_file_rounded)),
- //run
- IconButton(
- onPressed: () {
- debugPrint("Running nodes!");
- controller.runNodes();
- },
- icon: const Icon(Icons.play_circle_outline_rounded))
- ],
- ),
- body: NodeEditor(
- focusNode: _focusNode,
- controller: controller,
- background: const GridBackground(),
- infiniteCanvasSize: 5000,
- ),
- floatingActionButton: Padding(
- padding: const EdgeInsets.only(left: 40.0),
- child: Row(
- crossAxisAlignment: CrossAxisAlignment.end,
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- !(Platform.isWindows || Platform.isMacOS)
- ? SizedBox(
- width: 100,
- height: 100,
- child: Joystick(
- stick: const JoystickStick(
- decoration: null,
- ),
- controller: stickCtrl,
- listener: (details) {
- for (var name in controller.selecteds) {
- controller.moveNodePosition(
- name, Offset(details.x * 12, details.y * 12));
- }
- },
- ),
- )
- : Container(),
- ValueListenableBuilder(
- valueListenable: controller.selectedAny,
- builder: (context, selectedAny, child) {
- return selectedAny
- ? FloatingActionButton(
- onPressed: () {
- controller.deleteSelectedNodes();
- },
- child: const Icon(Icons.delete_outline_rounded),
- )
- : Container();
- },
- ),
- ],
- ),
- ));
+ appBar: AppBar(
+ backgroundColor: Theme.of(context).colorScheme.inversePrimary,
+ title: Text(widget.title),
+ actions: [
+ IconButton(
+ onPressed: () {
+ debugPrint('controller.toMap(): ${controller.toJson()}');
+ },
+ icon: const Icon(Icons.abc))
+ ],
+ ),
+ body: NodeEditor(
+ focusNode: _focusNode,
+ controller: controller,
+ background: const GridBackground(),
+ infiniteCanvasSize: 5000,
+ ),
+ floatingActionButton: FloatingActionButton(
+ onPressed: _addNewNode,
+ child: const Icon(Icons.add),
+ ),
+ );
}
}
diff --git a/examples/advanced/lib/nodes.dart b/examples/advanced/lib/nodes.dart
new file mode 100644
index 0000000..06b493b
--- /dev/null
+++ b/examples/advanced/lib/nodes.dart
@@ -0,0 +1,417 @@
+import 'package:flutter/material.dart';
+import 'package:node_editor/node_editor.dart';
+
+NodeWidgetBase componentNode(String name) {
+ return TitleBarNodeWidget(
+ name: name,
+ typeName: 'node_1',
+ backgroundColor: Colors.black87,
+ radius: 10,
+ selectedBorder: Border.all(color: Colors.white),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.end,
+ children: [
+ Row(
+ mainAxisAlignment: MainAxisAlignment.end,
+ children: [
+ const Text('Output 1'),
+ OutPortWidget(
+ name: 'PortOut1',
+ icon: const Icon(
+ Icons.play_arrow_outlined,
+ color: Colors.red,
+ size: 24,
+ ),
+ iconConnected: const Icon(
+ Icons.play_arrow,
+ color: Colors.red,
+ size: 24,
+ ),
+ multiConnections: false,
+ connectionTheme:
+ ConnectionTheme(color: Colors.red, strokeWidth: 2),
+ ),
+ ],
+ ),
+ Row(
+ mainAxisAlignment: MainAxisAlignment.end,
+ children: [
+ const Text('Output 2'),
+ SizedBox(
+ width: 24,
+ height: 24,
+ child: OutPortWidget(
+ name: 'PortOut2',
+ icon: const Icon(
+ Icons.circle_outlined,
+ color: Colors.yellowAccent,
+ size: 20,
+ ),
+ iconConnected: const Icon(
+ Icons.circle,
+ color: Colors.yellowAccent,
+ size: 20,
+ ),
+ multiConnections: false,
+ connectionTheme:
+ ConnectionTheme(color: Colors.yellowAccent, strokeWidth: 2),
+ ),
+ ),
+ ],
+ ),
+ Row(
+ mainAxisAlignment: MainAxisAlignment.end,
+ children: [
+ const CheckBoxProperty(name: 'check_port'),
+ const Text('Output 3'),
+ OutPortWidget(
+ name: 'PortOut3',
+ icon: const Icon(
+ Icons.play_arrow_outlined,
+ color: Colors.green,
+ size: 24,
+ ),
+ iconConnected: const Icon(
+ Icons.play_arrow,
+ color: Colors.green,
+ size: 24,
+ ),
+ multiConnections: false,
+ connectionTheme:
+ ConnectionTheme(color: Colors.green, strokeWidth: 2),
+ ),
+ ],
+ ),
+ Row(
+ mainAxisAlignment: MainAxisAlignment.center,
+ children: [
+ Flexible(
+ child: Container(
+ height: 30,
+ padding: const EdgeInsets.only(left: 4),
+ decoration: const BoxDecoration(
+ color: Colors.white10, // Container color
+ borderRadius:
+ BorderRadius.all(Radius.circular(10)), // Rounded corners
+ ),
+ child: Builder(builder: (context) {
+ return Theme(
+ data: Theme.of(context).copyWith(
+ canvasColor: Colors.black,
+ ),
+ child: DropdownMenuProperty<int>(
+ underline: const SizedBox(),
+ name: 'select',
+ dropdownColor: Colors.white,
+ style: const TextStyle(color: Colors.white),
+ items: const [
+ DropdownMenuItem(
+ value: 0,
+ child: Text(
+ 'Item1',
+ style: TextStyle(color: Colors.black),
+ ),
+ ),
+ DropdownMenuItem(
+ value: 1,
+ child: Text(
+ 'Item2',
+ style: TextStyle(color: Colors.black),
+ ),
+ ),
+ DropdownMenuItem(
+ value: 2,
+ child: Text(
+ 'Item3',
+ style: TextStyle(color: Colors.black),
+ ),
+ ),
+ ],
+ onChanged: (int? v) {},
+ ),
+ );
+ }),
+ ),
+ ),
+ ],
+ ),
+ const Row(
+ mainAxisAlignment: MainAxisAlignment.center,
+ children: [
+ Text('check 1:'),
+ CheckBoxProperty(name: 'check_prop1'),
+ ],
+ ),
+ ],
+ ),
+ title: const Text('Components'),
+ iconTileSpacing: 5,
+ titleBarPadding: const EdgeInsets.all(4.0),
+ titleBarGradient: const LinearGradient(
+ colors: [Color.fromRGBO(0, 23, 135, 1.0), Colors.lightBlue]),
+ icon: const Icon(
+ Icons.rectangle_outlined,
+ color: Colors.white,
+ ),
+ width: 200,
+ );
+}
+
+NodeWidgetBase receiverNode(
+ String name, FocusNode focusNode, TextEditingController controller) {
+ return TitleBarNodeWidget(
+ name: name,
+ typeName: 'node_2',
+ backgroundColor: Colors.black87,
+ radius: 10,
+ selectedBorder: Border.all(color: Colors.white),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.end,
+ children: [
+ Row(
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
+ children: [
+ Row(
+ mainAxisAlignment: MainAxisAlignment.start,
+ children: [
+ InPortWidget(
+ name: 'PortIn1',
+ onConnect: (String name, String port) => true,
+ icon: const Icon(
+ Icons.play_arrow_outlined,
+ color: Colors.red,
+ size: 24,
+ ),
+ iconConnected: const Icon(
+ Icons.play_arrow,
+ color: Colors.red,
+ size: 24,
+ ),
+ multiConnections: false,
+ connectionTheme:
+ ConnectionTheme(color: Colors.red, strokeWidth: 2),
+ ),
+ const Text('Input 1'),
+ ],
+ ),
+ Row(
+ mainAxisAlignment: MainAxisAlignment.end,
+ children: [
+ const Text('Output 3'),
+ OutPortWidget(
+ name: 'PortOut3',
+ icon: const Icon(
+ Icons.play_arrow_outlined,
+ color: Colors.blue,
+ size: 24,
+ ),
+ iconConnected: const Icon(
+ Icons.play_arrow,
+ color: Colors.blue,
+ size: 24,
+ ),
+ multiConnections: false,
+ connectionTheme:
+ ConnectionTheme(color: Colors.blue, strokeWidth: 2),
+ ),
+ ],
+ ),
+ ],
+ ),
+ Row(
+ mainAxisAlignment: MainAxisAlignment.start,
+ children: [
+ InPortWidget(
+ name: 'PortIn2',
+ onConnect: (String name, String port) => true,
+ icon: const Icon(
+ Icons.play_arrow_outlined,
+ color: Colors.red,
+ size: 24,
+ ),
+ iconConnected: const Icon(
+ Icons.play_arrow,
+ color: Colors.red,
+ size: 24,
+ ),
+ multiConnections: false,
+ connectionTheme:
+ ConnectionTheme(color: Colors.red, strokeWidth: 2),
+ ),
+ const Text('Input 2'),
+ ],
+ ),
+ Row(
+ mainAxisAlignment: MainAxisAlignment.center,
+ children: [
+ const Text('Value: '),
+ SizedBox(
+ width: 50,
+ height: 25,
+ child: TextEditProperty(
+ name: 'text_prop',
+ focusNode: focusNode,
+ controller: controller,
+ style: const TextStyle(
+ color: Colors.white,
+ fontWeight: FontWeight.normal,
+ fontSize: 14),
+ decoration: InputDecoration(
+ filled: true,
+ contentPadding:
+ const EdgeInsets.symmetric(vertical: 0.0, horizontal: 5.0),
+ fillColor: Colors.white10,
+ border: OutlineInputBorder(
+ borderSide: const BorderSide(color: Colors.white),
+ borderRadius: BorderRadius.circular(5)),
+ ),
+ ),
+ ),
+ ],
+ ),
+ ],
+ ),
+ title: const Text('Receiver'),
+ iconTileSpacing: 5,
+ titleBarPadding: const EdgeInsets.all(4.0),
+ titleBarGradient: const LinearGradient(
+ colors: [Color.fromRGBO(12, 100, 6, 1.0), Colors.greenAccent]),
+ icon: const Icon(
+ Icons.receipt_rounded,
+ color: Colors.white,
+ ),
+ width: 200,
+ );
+}
+
+NodeWidgetBase binaryNode(String name) {
+ return ContainerNodeWidget(
+ name: name,
+ typeName: 'node_3',
+ backgroundColor: Colors.blue.shade800,
+ radius: 10,
+ width: 200,
+ contentPadding: const EdgeInsets.all(4),
+ selectedBorder: Border.all(color: Colors.white),
+ child: Row(
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
+ children: [
+ Column(
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
+ children: [
+ InPortWidget(
+ name: 'PortIn1',
+ onConnect: (String name, String port) => true,
+ icon: const Icon(
+ Icons.circle_outlined,
+ color: Colors.yellowAccent,
+ size: 20,
+ ),
+ iconConnected: const Icon(
+ Icons.circle,
+ color: Colors.yellowAccent,
+ size: 20,
+ ),
+ multiConnections: false,
+ connectionTheme:
+ ConnectionTheme(color: Colors.yellowAccent, strokeWidth: 2),
+ ),
+ InPortWidget(
+ name: 'PortIn2',
+ onConnect: (String name, String port) => true,
+ icon: const Icon(
+ Icons.circle_outlined,
+ color: Colors.yellowAccent,
+ size: 20,
+ ),
+ iconConnected: const Icon(
+ Icons.circle,
+ color: Colors.yellowAccent,
+ size: 20,
+ ),
+ multiConnections: false,
+ connectionTheme:
+ ConnectionTheme(color: Colors.yellowAccent, strokeWidth: 2),
+ ),
+ ],
+ ),
+ const Icon(Icons.safety_divider),
+ OutPortWidget(
+ name: 'PortOut1',
+ icon: const Icon(
+ Icons.pause_circle_outline,
+ color: Colors.deepOrange,
+ size: 24,
+ ),
+ iconConnected: const Icon(
+ Icons.pause_circle,
+ color: Colors.deepOrange,
+ size: 24,
+ ),
+ multiConnections: false,
+ connectionTheme:
+ ConnectionTheme(color: Colors.deepOrange, strokeWidth: 2),
+ ),
+ ],
+ ),
+ );
+}
+
+NodeWidgetBase sinkNode(String name) {
+ return TitleBarNodeWidget(
+ name: name,
+ typeName: 'node_4',
+ backgroundColor: Colors.green.shade800,
+ radius: 10,
+ selectedBorder: Border.all(color: Colors.white),
+ child: Padding(
+ padding: const EdgeInsets.only(top: 8, bottom: 8),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.end,
+ children: [
+ Row(
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
+ children: [
+ Row(
+ mainAxisAlignment: MainAxisAlignment.start,
+ children: [
+ InPortWidget(
+ name: 'PortIn1',
+ onConnect: (String name, String port) => true,
+ icon: const Icon(
+ Icons.add_circle_outline,
+ color: Colors.blueAccent,
+ size: 24,
+ ),
+ iconConnected: const Icon(
+ Icons.add_circle_outlined,
+ color: Colors.blueAccent,
+ size: 24,
+ ),
+ multiConnections: false,
+ connectionTheme: ConnectionTheme(
+ color: Colors.blueAccent, strokeWidth: 2),
+ ),
+ const Text('Input 2'),
+ ],
+ ),
+ ],
+ ),
+ ],
+ ),
+ ),
+ title: const Text(
+ 'Sinker',
+ style: TextStyle(color: Colors.deepOrange, fontWeight: FontWeight.bold),
+ ),
+ iconTileSpacing: 5,
+ titleBarPadding: const EdgeInsets.all(4.0),
+ titleBarGradient:
+ const LinearGradient(colors: [Colors.yellowAccent, Colors.yellow]),
+ icon: const Icon(
+ Icons.calculate_rounded,
+ color: Colors.deepOrange,
+ ),
+ width: 200,
+ );
+}
diff --git a/lib/node_editor.dart b/lib/node_editor.dart
index 0b1afbd..92d8034 100644
--- a/lib/node_editor.dart
+++ b/lib/node_editor.dart
@@ -1,13 +1,23 @@
library node_editor;
-export 'ui/background.dart'
+export 'src/background.dart'
show NodeEditorBackgroundBase, SolidBackground, GridBackground;
-export 'ui/connections.dart' show Connection, ConnectionTheme;
-export 'ui/controller.dart' show NodeEditorController;
-export 'ui/editor.dart' show NodeEditor;
-export 'ui/inherit.dart' show ControllerInheritedWidget;
-export 'ui/node_widget.dart' show NodeWidgetBase, NodeEditorInheritedWidget;
-export 'ui/nodes.dart' show NodeModel;
-export 'ui/port_widget.dart' show InPortWidget, OutPortWidget;
-export 'ui/position.dart' show NodePosition, NodePositionType;
-export 'ui/utils.dart';
+export 'src/connections.dart' show Connection, ConnectionTheme;
+export 'src/controller.dart' show NodeEditorController;
+export 'src/custom_painter.dart' show NodeEditor;
+export 'src/inherit.dart' show ControllerInheritedWidget;
+export 'src/node_widget.dart'
+ show
+ NodeWidgetBase,
+ NodeEditorInheritedWidget,
+ TitleBarNodeWidget,
+ ContainerNodeWidget,
+ BinaryOperationNode,
+ UnaryOperationNode;
+export 'src/nodes.dart' show NodeModel;
+export 'src/port.dart' show InPortWidget, OutPortWidget;
+export 'src/position.dart' show NodePosition, NodePositionType;
+export 'src/properties.dart' show PropertyMixin;
+export 'src/properties/checkbox.dart' show CheckBoxProperty;
+export 'src/properties/dropdown.dart' show DropdownMenuProperty;
+export 'src/properties/text_edit.dart' show TextEditProperty;
diff --git a/lib/ui/background.dart b/lib/src/background.dart
similarity index 100%
rename from lib/ui/background.dart
rename to lib/src/background.dart
diff --git a/lib/ui/connections.dart b/lib/src/connections.dart
similarity index 98%
rename from lib/ui/connections.dart
rename to lib/src/connections.dart
index 761f56f..91abe3c 100644
--- a/lib/ui/connections.dart
+++ b/lib/src/connections.dart
@@ -150,6 +150,7 @@ class ConnectionsManager {
void selectOnTap(NodeEditorController controller, Offset tapPosition) {
Offset viewportOffset = controller.getViewportOffset();
+ debugPrint('selectOnTap->tapPosition: $tapPosition');
for (var conn in connections) {
Offset? startPoint = getPortPosition(controller, conn.outPort);
Offset? endPoint = getPortPosition(controller, conn.inPort);
@@ -175,7 +176,7 @@ class ConnectionsManager {
mousePosition(Offset pos) {
if (startPointConnection != null) {
mousePoint = pos;
- // debugPrint('Mouse set_pos: $pos');
+ debugPrint('Mouse set_pos: $pos');
}
}
}
diff --git a/lib/ui/controller.dart b/lib/src/controller.dart
similarity index 97%
rename from lib/ui/controller.dart
rename to lib/src/controller.dart
index e46eb5e..0c432d4 100644
--- a/lib/ui/controller.dart
+++ b/lib/src/controller.dart
@@ -176,6 +176,13 @@ class NodeEditorController with ChangeNotifier {
return nodesManager.getPort(nodeName, portName);
}
+ void addProperty(
+ String nodeName,
+ Property property,
+ ) {
+ nodesManager.nodes[nodeName]!.addProperty(property);
+ }
+
void selectOnTap(Offset tapPosition) {
nodesManager.unselectAllNodes();
connectionsManager.selectOnTap(this, tapPosition);
diff --git a/lib/ui/curve.dart b/lib/src/curve.dart
similarity index 100%
rename from lib/ui/curve.dart
rename to lib/src/curve.dart
diff --git a/lib/ui/editor.dart b/lib/src/custom_painter.dart
similarity index 97%
rename from lib/ui/editor.dart
rename to lib/src/custom_painter.dart
index 6d4abac..5d3255c 100644
--- a/lib/ui/editor.dart
+++ b/lib/src/custom_painter.dart
@@ -9,11 +9,12 @@ import 'line_painter.dart';
class NodeEditor extends StatefulWidget {
const NodeEditor(
- {super.key,
+ {Key? key,
required this.controller,
required this.background,
required this.focusNode,
- required this.infiniteCanvasSize});
+ required this.infiniteCanvasSize})
+ : super(key: key);
final NodeEditorController controller;
final NodeEditorBackgroundBase background;
@@ -50,7 +51,7 @@ class _NodeEditorState extends State<NodeEditor> {
// set the focus in the controller
widget.controller.focusNode = widget.focusNode;
- // debugPrint('Set stackPos');
+ debugPrint('Set stackPos');
afterBuild = true;
widget.controller.verticalScrollController = verticalScrollController;
widget.controller.horizontalScrollController = horizontalScrollController;
@@ -94,7 +95,7 @@ class _NodeEditorState extends State<NodeEditor> {
},
child: GestureDetector(
onTapDown: (TapDownDetails details) {
- // debugPrint("onTapDown");
+ debugPrint("onTapDown");
widget.controller.selectOnTap(details.localPosition);
},
child: AnimatedBuilder(
diff --git a/lib/ui/inherit.dart b/lib/src/inherit.dart
similarity index 89%
rename from lib/ui/inherit.dart
rename to lib/src/inherit.dart
index dd148e0..50faf91 100644
--- a/lib/ui/inherit.dart
+++ b/lib/src/inherit.dart
@@ -6,10 +6,10 @@ class ControllerInheritedWidget extends InheritedWidget {
final NodeEditorController controller;
const ControllerInheritedWidget({
- super.key,
+ Key? key,
required this.controller,
- required super.child,
- });
+ required Widget child,
+ }) : super(key: key, child: child);
static ControllerInheritedWidget of(BuildContext context) {
final ControllerInheritedWidget? result =
diff --git a/lib/ui/line_painter.dart b/lib/src/line_painter.dart
similarity index 98%
rename from lib/ui/line_painter.dart
rename to lib/src/line_painter.dart
index 50540bb..f4bd640 100644
--- a/lib/ui/line_painter.dart
+++ b/lib/src/line_painter.dart
@@ -1,8 +1,6 @@
import 'package:flutter/material.dart';
+import 'package:node_editor/node_editor.dart';
-import 'background.dart';
-import 'connections.dart';
-import 'controller.dart';
import 'nodes.dart';
class LinePainter extends CustomPainter {
diff --git a/lib/src/node_widget.dart b/lib/src/node_widget.dart
new file mode 100644
index 0000000..027d21e
--- /dev/null
+++ b/lib/src/node_widget.dart
@@ -0,0 +1,412 @@
+import 'package:flutter/material.dart';
+
+import 'controller.dart';
+import 'inherit.dart';
+import 'nodes.dart';
+import 'port.dart';
+
+abstract class NodeItemWidgetInterface {
+ NodeItem get nodeInfo;
+}
+
+class NodeWidgetAtt {
+ bool selected = false;
+}
+
+/// Base class to create NodeWidgets
+abstract class NodeWidgetBase {
+ NodeWidgetBase(
+ {required this.width, required this.name, required this.typeName});
+
+ final String name;
+ final String typeName;
+ final double width;
+
+ @protected
+ final NodeWidgetAtt att = NodeWidgetAtt();
+
+ Widget customBuild(BuildContext context);
+
+ /// Flag to specify if the node is selected
+ bool get isSelected => att.selected;
+
+ /// Mark node as selected
+ ///
+ /// The node must be marked as selected on the controller
+ /// so the controller is called, and the name of the node is given
+ /// as argument, so the controller mark the node as selected
+ void selectNode(BuildContext context) {
+ NodeEditorController controller =
+ ControllerInheritedWidget.of(context).controller;
+ controller.selectNodeAction(name);
+ }
+}
+
+class NodeEditorInheritedWidget extends InheritedWidget {
+ NodeEditorInheritedWidget({
+ Key? key,
+ required this.blueprintNode,
+ }) : super(
+ key: key,
+ child: NodeWidget(
+ blueprintNode: blueprintNode,
+ ));
+
+ final NodeWidgetBase blueprintNode;
+
+ static NodeEditorInheritedWidget of(BuildContext context) {
+ final NodeEditorInheritedWidget? result =
+ context.dependOnInheritedWidgetOfExactType<NodeEditorInheritedWidget>();
+ assert(result != null, 'No NodeEditorInheritedWidget found in context');
+ return result!;
+ }
+
+ @override
+ bool updateShouldNotify(NodeEditorInheritedWidget oldWidget) {
+ return blueprintNode != oldWidget.blueprintNode;
+ }
+}
+
+class TitleBarNodeWidget extends NodeWidgetBase {
+ TitleBarNodeWidget(
+ {required this.icon,
+ required this.title,
+ super.width = 150,
+ this.titleBarColor,
+ this.backgroundColor,
+ this.boxShadow,
+ this.radius,
+ this.border,
+ this.selectedBorder,
+ this.gradient,
+ this.backgroundBlendMode,
+ this.image,
+ this.titleBarBorder,
+ this.titleBarGradient,
+ this.titleBarBackgroundBlendMode,
+ this.titleBarImage,
+ this.iconTileSpacing,
+ this.titleBarPadding,
+ this.contentPadding,
+ required super.name,
+ required super.typeName,
+ required this.child});
+
+ final Widget child;
+ final Color? titleBarColor;
+ final Color? backgroundColor;
+ final double? radius;
+ final Widget icon;
+ final Widget title;
+ final List<BoxShadow>? boxShadow;
+ final BoxBorder? border;
+ final BoxBorder? selectedBorder;
+ final Gradient? gradient;