add sample code

This commit is contained in:
Yuki Kuwashima 2022-09-17 11:39:13 +09:00 committed by GitHub
parent 640c8e9e3f
commit 3cfeb06f13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 53 additions and 1 deletions

View File

@ -1,3 +1,55 @@
# EasyNodeEditor
Very easy node editor.
```.swift
import SwiftUI
import EasyNodeEditor
struct ContentView: View {
var body: some View {
EasyNodeEditor(nodeTypes: [Output3Node.self, MultiplyNode.self, ShowNode.self])
}
}
class Output3Node: NodeModelBase {
@objc @Output var output: Int = 3
}
class MultiplyNodeSubModel: ObservableObject {
@Published var sliderValue: Double = 0.0
}
class MultiplyNode: NodeModelBase {
@objc @Input var input: Int = 0
@ObservedObject var subModel = MultiplyNodeSubModel()
@objc @Middle var count: Int = 0
@objc @Output var output: Int = 0
override func processOnChange() {
output = input * count
}
override func middleContent() -> AnyView {
return AnyView(
Group {
Slider(value: self.$subModel.sliderValue, in: 0...100, onEditingChanged: { changed in
self.count = Int(self.subModel.sliderValue)
})
}
.frame(minWidth: 200, maxWidth: 200)
.fixedSize()
)
}
}
class ShowNode: NodeModelBase {
@objc @Input var myinput: Int = 0
var showCount = 0
override func processOnChange() {
showCount = myinput
}
override func middleContent() -> AnyView {
return AnyView(
Group {
Text("number is now -> \(showCount)")
}
)
}
}
```