Skip to main content

extension/
extension.rs

1use ferrum_flow::*;
2use gpui::{
3    AnyElement, AppContext as _, Application, Element as _, ParentElement as _, Styled,
4    WindowOptions, div, rgb, white,
5};
6
7fn main() {
8    Application::new().run(|cx| {
9        let mut graph = Graph::new();
10
11        graph
12            .create_node("number")
13            .position(100.0, 100.0)
14            .size(300.0, 150.0)
15            .output()
16            .build(&mut graph);
17
18        graph
19            .create_node("")
20            .position(300.0, 400.0)
21            .input()
22            .build(&mut graph);
23
24        cx.open_window(WindowOptions::default(), |_, cx| {
25            cx.new(|fc| {
26                let mut flow = FlowCanvas::new(graph, fc)
27                    .plugin(SelectionPlugin::new())
28                    .plugin(NodeInteractionPlugin::new())
29                    .plugin(ViewportPlugin::new())
30                    .plugin(Background::new())
31                    .plugin(NodePlugin::new().register_node("number", NumberNode {}));
32                flow.init_plugins();
33                flow
34            })
35        })
36        .unwrap();
37    });
38}
39
40pub struct NumberNode;
41
42impl NodeRenderer for NumberNode {
43    fn render(&self, node: &Node, ctx: &mut RenderContext) -> AnyElement {
44        let screen = ctx.viewport.world_to_screen(node.point());
45        let node_x = screen.x;
46        let node_y = screen.y;
47
48        div()
49            .absolute()
50            .left(node_x)
51            .top(node_y)
52            .w(node.size.width * ctx.viewport.zoom)
53            .h(node.size.height * ctx.viewport.zoom)
54            .bg(rgb(0x505078))
55            .child(div().child("Number Node").text_color(white()))
56            .into_any()
57    }
58}