AudioKit / Flow

Generic node graph editor
https://www.audiokit.io/Flow/
MIT License
302 stars 17 forks source link

Example / clarity on how to add nodes #35

Closed dirkx closed 1 year ago

dirkx commented 1 year ago

Description

My compliments for flow; very neat & easy to keep the data model in sync with the UI & lovely editing for the wires.

But am wondering if an example is needed that shows how to add a node (or delete) at runtime.

I had expected something like below to be possible - but am clearly missing something obvious.

import SwiftUI
import Combine
import Flow

@main
struct FlowDemoApp: App {
    var fcv = FlowContentView.init()
    var body: some Scene {
        WindowGroup {
            // FlowContentView()
            fcv;
        }
        .commands {
            CommandMenu("Nodes") {
                Button(action: {
                    // fcv.addNode();
                    let newNode = Node(name: "PID", titleBarColor: Color.red,
                                  inputs: ["in1", "in2"], outputs: ["out"]);
                    fcv.patch.nodes.append(newNode)
                }, label: {
                    Text("Add Node")
                });
            }
        }
    }
}

Proposed Solution

Adding something to the example that adds a node would be most lovely

Describe Alternatives You've Considered

Tried various other options (obviously recreating and redrawing works)

Additional Context

No response

wtholliday commented 1 year ago

@dirkx I added a button in the demo. I suspect there's a problem with your code because it seems to store a view as a var.

dirkx commented 1 year ago

Perfect & clear ! Thanks.