Skip to content

Commit 8a1be9c

Browse files
committedApr 1, 2018
Made all the nodes public
1 parent aa75bf9 commit 8a1be9c

18 files changed

+554
-278
lines changed
 

‎VPL.xcodeproj/project.pbxproj

+238
Large diffs are not rendered by default.

‎VPL.xcodeproj/xcuserdata/nathanflurry.xcuserdatad/xcschemes/xcschememanagement.plist

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
<key>orderHint</key>
1010
<integer>0</integer>
1111
</dict>
12+
<key>VPLEditor.xcscheme</key>
13+
<dict>
14+
<key>orderHint</key>
15+
<integer>1</integer>
16+
</dict>
1217
</dict>
1318
<key>SuppressBuildableAutocreation</key>
1419
<dict>

‎VPL/Data/Node.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ public protocol Node: class {
2626
}
2727

2828
extension Node {
29-
var inputTrigger: InputTrigger? { return nil }
30-
var inputValues: [InputValue] { return [] }
31-
var inputVariables: [InputVariable] { return [] }
32-
var output: NodeOutput { return .none }
29+
public var inputTrigger: InputTrigger? { return nil }
30+
public var inputValues: [InputValue] { return [] }
31+
public var inputVariables: [InputVariable] { return [] }
32+
public var output: NodeOutput { return .none }
3333
}
3434

3535
extension Node {
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import VPLEditor
2+
import UIKit
3+
import PlaygroundSupport
4+
5+
let canvas = CanvasViewController()
6+
7+
// Create and insert the display node
8+
9+
10+
baseNode = DisplayNode(node: BaseNode())
11+
insert(node: baseNode, at: CGPoint(x: contentSize.width / 2, y: contentSize.height / 2))
12+
13+
PlaygroundPage.current.liveView = canvas
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<playground version='5.0' target-platform='ios'>
3+
<timeline fileName='timeline.xctimeline'/>
4+
</playground>

‎VPL/Rendering/CanvasViewController.swift

+13-13
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class CanvasViewController: UIViewController {
1919
var outputView: CodeOutputView!
2020

2121
/// Canvas that holds all of the nodes
22-
var nodeCanvas: DisplayNodeCanvas!
22+
public private(set) var canvas: DisplayNodeCanvas!
2323

2424
/// Canvas for all of the drawing for quick shortcuts
2525
var drawingCanvas: DrawingCanvas!
@@ -40,21 +40,21 @@ public class CanvasViewController: UIViewController {
4040
outputView.heightAnchor.constraint(equalToConstant: isInPlayground ? 260 : 180).activate()
4141

4242
// Add the node canvas
43-
nodeCanvas = DisplayNodeCanvas(frame: view.bounds)
44-
nodeCanvas.updateCallback = {
45-
let assembled = self.nodeCanvas.assemble()
43+
canvas = DisplayNodeCanvas(frame: view.bounds)
44+
canvas.updateCallback = {
45+
let assembled = self.canvas.assemble()
4646
self.outputView.render(code: assembled.trimmingCharacters(in: .whitespacesAndNewlines))
4747
}
48-
view.addSubview(nodeCanvas)
49-
nodeCanvas.translatesAutoresizingMaskIntoConstraints = false
50-
nodeCanvas.leftAnchor.constraint(equalTo: view.leftAnchor).activate()
51-
nodeCanvas.rightAnchor.constraint(equalTo: view.rightAnchor).activate()
52-
nodeCanvas.topAnchor.constraint(equalTo: view.topAnchor).activate()
53-
nodeCanvas.bottomAnchor.constraint(equalTo: outputView.topAnchor).activate()
48+
view.addSubview(canvas)
49+
canvas.translatesAutoresizingMaskIntoConstraints = false
50+
canvas.leftAnchor.constraint(equalTo: view.leftAnchor).activate()
51+
canvas.rightAnchor.constraint(equalTo: view.rightAnchor).activate()
52+
canvas.topAnchor.constraint(equalTo: view.topAnchor).activate()
53+
canvas.bottomAnchor.constraint(equalTo: outputView.topAnchor).activate()
5454

5555
// Add drawing canvas
56-
drawingCanvas = DrawingCanvas(frame: nodeCanvas.bounds)
57-
nodeCanvas.backgroundView = drawingCanvas
56+
drawingCanvas = DrawingCanvas(frame: canvas.bounds)
57+
canvas.backgroundView = drawingCanvas
5858
drawingCanvas.onInputStart = {
5959
// Cancel the timer
6060
self.commitDrawingTimer?.invalidate()
@@ -125,7 +125,7 @@ public class CanvasViewController: UIViewController {
125125

126126
// Create and insert the display node
127127
let displayNode = DisplayNode(node: node)
128-
nodeCanvas.insert(node: displayNode, at: position)
128+
canvas.insert(node: displayNode, at: position)
129129

130130
return displayNode
131131
}

‎VPL/Rendering/Node/DisplayNode.swift

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import UIKit
1010

11-
class DisplayNode: UIView, UIGestureRecognizerDelegate {
11+
public class DisplayNode: UIView, UIGestureRecognizerDelegate {
1212
/// The underlying node data.
1313
var node: DisplayableNode
1414

@@ -19,9 +19,9 @@ class DisplayNode: UIView, UIGestureRecognizerDelegate {
1919
var sockets: [DisplayNodeSocket] = []
2020

2121
/// The content view for this node.
22-
var contentView: DisplayableNodeContentView?
22+
public var contentView: DisplayableNodeContentView?
2323

24-
init(node: DisplayableNode) {
24+
public init(node: DisplayableNode) {
2525
// Save the node and canvas
2626
self.node = node
2727

@@ -129,7 +129,7 @@ class DisplayNode: UIView, UIGestureRecognizerDelegate {
129129
}
130130
}
131131

132-
required init(coder: NSCoder) {
132+
public required init(coder: NSCoder) {
133133
fatalError("init(coder:) has not been implemented")
134134
}
135135

@@ -209,7 +209,7 @@ class DisplayNode: UIView, UIGestureRecognizerDelegate {
209209
canvas?.remove(node: self)
210210
}
211211

212-
override func layoutSubviews() {
212+
public override func layoutSubviews() {
213213
// Size to fit content
214214
frame.size = systemLayoutSizeFitting(UILayoutFittingCompressedSize)
215215
}
@@ -247,7 +247,7 @@ class DisplayNode: UIView, UIGestureRecognizerDelegate {
247247
layer.add(groupAnim, forKey: "shadowAnim")
248248
}
249249

250-
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
250+
public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
251251
// If the content view absorbs touches, make sure the touch isn't inside
252252
if let contentView = contentView, contentView.absorbsTouches {
253253
return !contentView.point(inside: touch.location(in: contentView), with: nil)

‎VPL/Rendering/Node/DisplayNodeCanvas.swift

+10-10
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
import UIKit
1010

11-
class DisplayNodeCanvas: UIScrollView, UIScrollViewDelegate {
11+
public class DisplayNodeCanvas: UIScrollView, UIScrollViewDelegate {
1212
/// List of all nodes in the canvas.
13-
var nodes: [DisplayNode]
13+
public private(set) var nodes: [DisplayNode]
1414

1515
/// View that is drawn behind all other views.
1616
var backgroundView: UIView? {
@@ -33,7 +33,7 @@ class DisplayNodeCanvas: UIScrollView, UIScrollViewDelegate {
3333
var updateCallback: (() -> Void)?
3434

3535
/// The starting node that all other nodes build off of.
36-
var baseNode: DisplayNode!
36+
public private(set) var baseNode: DisplayNode!
3737

3838
override init(frame: CGRect) {
3939
// Create new node list
@@ -73,17 +73,17 @@ class DisplayNodeCanvas: UIScrollView, UIScrollViewDelegate {
7373
contentOffset = CGPoint(x: contentSize.width / 2 - 200, y: contentSize.height / 2 - 200)
7474
}
7575

76-
required init?(coder aDecoder: NSCoder) {
76+
public required init?(coder aDecoder: NSCoder) {
7777
fatalError("init(coder:) has not been implemented")
7878
}
7979

80-
override func layoutSubviews() {
80+
public override func layoutSubviews() {
8181
// Resize all views
8282
backgroundView?.frame.size = bounds.size
8383
overlayView.frame.size = bounds.size
8484
}
8585

86-
func scrollViewDidScroll(_ scrollView: UIScrollView) {
86+
public func scrollViewDidScroll(_ scrollView: UIScrollView) {
8787
// Move the background and overlay with the view
8888
backgroundView?.frame.origin = scrollView.contentOffset
8989
overlayView.frame.origin = scrollView.contentOffset
@@ -93,7 +93,7 @@ class DisplayNodeCanvas: UIScrollView, UIScrollViewDelegate {
9393
}
9494

9595
/// Assembles all of the code.
96-
func assemble() -> String {
96+
public func assemble() -> String {
9797
var output = ""
9898

9999
// Assemble each function
@@ -109,7 +109,7 @@ class DisplayNodeCanvas: UIScrollView, UIScrollViewDelegate {
109109
}
110110

111111
/// Adds a node to the canvas.
112-
func insert(node: DisplayNode, at position: CGPoint, absolutePosition: Bool = false) {
112+
public func insert(node: DisplayNode, at position: CGPoint, absolutePosition: Bool = false) {
113113
assert(!nodes.contains(node))
114114
assert(node.canvas == nil)
115115

@@ -139,7 +139,7 @@ class DisplayNodeCanvas: UIScrollView, UIScrollViewDelegate {
139139

140140
/// Called when any interaction occurs with the node and it needs to be
141141
/// updated.
142-
func updated(node: DisplayNode) {
142+
public func updated(node: DisplayNode) {
143143
// Bring node to front under overlay
144144
bringSubview(toFront: node)
145145
bringSubview(toFront: overlayView)
@@ -155,7 +155,7 @@ class DisplayNodeCanvas: UIScrollView, UIScrollViewDelegate {
155155
}
156156

157157
/// Removes a ndoe from the canvas.
158-
func remove(node: DisplayNode) {
158+
public func remove(node: DisplayNode) {
159159
assert(nodes.contains(node))
160160
assert(node.canvas == self)
161161

0 commit comments

Comments
 (0)
Please sign in to comment.