[][src]Crate gazpatcho

Simple node-based graph editor for Rust. Register nodes, let the user mingle with them, read the result.

Example

The following example initializes the application with a single node type. Eeach node will have one input and one output pin, and a "switch" widget that can be set on or off by the user.

First we need to define the config for our application. The config describes all the node templates available for the user.

use gazpatcho::config::*;

let config = Config {
    node_templates: vec![
        NodeTemplate {
            label: "Example node".to_owned(),
            class: "example_node".to_owned(),
            pins: vec![
                Pin {
                    label: "Input".to_owned(),
                    class: "in".to_owned(),
                    direction: Input,
                },
                Pin {
                    label: "Output".to_owned(),
                    class: "out".to_owned(),
                    direction: Output,
                },
            ],
            widgets: vec![Switch {
                label: "Switch".to_owned(),
                key: "switch".to_owned(),
            }],
        }
    ],
};

The we start the application, this will open a new window with the canvas. We are passing the previously defined config and also a callback function. This callback will be executed every time the user updates the graph represented in the UI.

gazpatcho::run("Application Name", config, |report| {
    // Act upon the current report
    dbg!(report);
});

The dbg! output of such a configuration would return something like:

This example is not tested
Report {
    nodes: [
        Node {
            id: "example_node:0",
            class: "example_node",
            data: {
                "switch": Bool(
                    false,
                ),
            },
        },
        Node {
            id: "example_node:1",
            class: "example_node",
            data: {
                "switch": Bool(
                    true,
                ),
            },
        },
    ],
    patches: [
        Patch {
            source: PinAddress {
                node_id: "example_node:0",
                pin_class: "out",
            },
            destination: PinAddress {
                node_id: "example_node:1",
                pin_class: "in",
            },
        },
    ],
}

To see the list of all available widgets and detailed documentation of the state, read the config documentation. To learn more about the reported state, read the report documentation.

If you prefer to go directly for a code examples, take a look at the examples folder.

Modules

config

Configuration defining available node types, pins and widgets that will be available in given application instance.

report

Definition of the current state of the graph modeled in the UI.

Functions

run

Launch the user interface.