Expand description
High-level, safe bindings for imnodes, a node editor extension for imgui-rs.
Based on the C API bindings generated by cimnodes.
§Usage
- Create an
imnodes::Context
once at application startup. - Create an
imnodes::EditorContext
for each node editor you want to display. - In your UI loop, call
EditorContext::set_as_current_editor
before defining the editor UI. - Use the
imnodes::editor
function to define the node editor content.
// Before calling editor:
state.editor_context.set_as_current_editor();
let mut node_id_gen = state.editor_context.new_identifier_generator();
let outer_scope = imnodes::editor(&mut state.editor_context, |mut editor_scope| {
editor_scope.add_node(node_id_gen.next_node(), |mut node_scope| {
node_scope.add_titlebar(|| ui.text("My Node"));
node_scope.add_input(node_id_gen.next_input_pin(), imnodes::PinShape::Circle, || {
ui.text("Input Pin");
});
node_scope.add_output(node_id_gen.next_output_pin(), imnodes::PinShape::Triangle, || {
ui.text("Output Pin");
});
});
// Add more nodes and links...
});
// Handle events after the editor scope ends
if let Some(link) = outer_scope.links_created() {
// handle new link creation
}
if let Some(dropped_link_id) = outer_scope.get_destroyed_link() {
// handle link deletion
}
Identifiers
imnodes requires unique integer IDs for nodes, pins (attributes), and links.
The [IdentifierGenerator] struct provides a convenient way to generate these unique IDs within an editor context.
Structs§
- Attribute
Flag Token - A token representing a pushed attribute flag change.
- Attribute
Id - Identifier for a static attribute within a node (an attribute without a pin).
- Color
Token - A token representing a pushed color style change.
- Context
- Represents the global imnodes context.
- Editor
Context - An editor context corresponds to a set of nodes in a single workspace
- Editor
Scope - Represents the scope within the main node editor block (
imnodes::editor
). Use methods on this struct to add nodes, links, and the minimap. - Identifier
Generator - Provides unique identifiers for nodes, pins, attributes, and links within an editor context.
- ImNodesIO
- ImVec2
- Input
PinId - Identifier for an input pin (rendered on the left side of a node).
- Link
- Represents a link successfully created by the user in the current frame.
- LinkId
- Identifier for a link between two pins.
- NodeId
- Identifier for a Node.
- Node
Scope - Represents the scope within a node definition block (
add_node
). Use methods on this struct to add title bars, input/output pins, and static attributes. - Outer
Scope - Represents the scope outside the main node editor block.
Use methods on this struct after
editor()
has returned to query UI events. - Output
PinId - Identifier for an output pin (rendered on the right side of a node).
- PinId
- Generic identifier for either an input or output pin.
- Style
- Wrapper struct for
imnodes_sys::ImNodesStyle
to implementDefault
locally. This works around Rust’s orphan rule (E0117). - Style
VarToken - A token representing a pushed style variable change (float or ImVec2).
Enums§
- Attribute
Flags - Flags controlling the behavior of individual attributes (pins).
- Color
Style - Identifies a specific color setting within the node editor’s style.
- Coordinate
System - Specifies the coordinate system for getting or setting node positions.
- Mini
MapLocation - Specifies the corner location of the minimap within the editor canvas.
Used with
crate::EditorScope::add_mini_map
. - PinShape
- Controls the visual shape of attribute pins.
- Style
Flags - Flags controlling boolean style options for the editor.
- Style
Var - Identifies a specific style variable setting within the node editor’s style.
Traits§
- Hoverable
- Trait implemented by elements that can be hovered over by the mouse.
Functions§
- create_
imnodes_ style Deprecated - Creates an
ImNodesStyle
struct initialized with default values and the dark color theme. Deprecated: Use [imnodes::Style::default()
] instead. - editor
- Begins the node editor UI definition.
- get_
hovered_ node - Returns the ID of the node currently being hovered over, if any. This can be called outside the OuterScope if needed.