Skip to main content

dear_imnodes/context/editor/
build.rs

1use super::super::{AttrKind, AttributeToken, NodeEditor, NodeToken};
2use crate::sys;
3
4impl<'ui> NodeEditor<'ui> {
5    /// Begin a node
6    pub fn node(&self, id: i32) -> NodeToken<'_> {
7        self.bind();
8        unsafe { sys::imnodes_BeginNode(id) };
9        NodeToken {
10            scope: self.scope(),
11            _phantom: std::marker::PhantomData,
12        }
13    }
14
15    /// Begin an input attribute pin
16    pub fn input_attr(&self, id: i32, shape: crate::PinShape) -> AttributeToken<'_> {
17        self.bind();
18        unsafe { sys::imnodes_BeginInputAttribute(id, shape as sys::ImNodesPinShape) };
19        AttributeToken {
20            kind: AttrKind::Input,
21            scope: self.scope(),
22            _phantom: std::marker::PhantomData,
23        }
24    }
25
26    /// Begin an output attribute pin
27    pub fn output_attr(&self, id: i32, shape: crate::PinShape) -> AttributeToken<'_> {
28        self.bind();
29        unsafe { sys::imnodes_BeginOutputAttribute(id, shape as sys::ImNodesPinShape) };
30        AttributeToken {
31            kind: AttrKind::Output,
32            scope: self.scope(),
33            _phantom: std::marker::PhantomData,
34        }
35    }
36
37    /// Begin a static attribute region
38    pub fn static_attr(&self, id: i32) -> AttributeToken<'_> {
39        self.bind();
40        unsafe { sys::imnodes_BeginStaticAttribute(id) };
41        AttributeToken {
42            kind: AttrKind::Static,
43            scope: self.scope(),
44            _phantom: std::marker::PhantomData,
45        }
46    }
47
48    /// Draw a link between two attributes
49    pub fn link(&self, id: i32, start_attr: i32, end_attr: i32) {
50        self.bind();
51        unsafe { sys::imnodes_Link(id, start_attr, end_attr) }
52    }
53}