Crate imnodes

Source
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

  1. Create an imnodes::Context once at application startup.
  2. Create an imnodes::EditorContext for each node editor you want to display.
  3. In your UI loop, call EditorContext::set_as_current_editor before defining the editor UI.
  4. 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§

AttributeFlagToken
A token representing a pushed attribute flag change.
AttributeId
Identifier for a static attribute within a node (an attribute without a pin).
ColorToken
A token representing a pushed color style change.
Context
Represents the global imnodes context.
EditorContext
An editor context corresponds to a set of nodes in a single workspace
EditorScope
Represents the scope within the main node editor block (imnodes::editor). Use methods on this struct to add nodes, links, and the minimap.
IdentifierGenerator
Provides unique identifiers for nodes, pins, attributes, and links within an editor context.
ImNodesIO
ImVec2
InputPinId
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.
NodeScope
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.
OuterScope
Represents the scope outside the main node editor block. Use methods on this struct after editor() has returned to query UI events.
OutputPinId
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 implement Default locally. This works around Rust’s orphan rule (E0117).
StyleVarToken
A token representing a pushed style variable change (float or ImVec2).

Enums§

AttributeFlags
Flags controlling the behavior of individual attributes (pins).
ColorStyle
Identifies a specific color setting within the node editor’s style.
CoordinateSystem
Specifies the coordinate system for getting or setting node positions.
MiniMapLocation
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.
StyleFlags
Flags controlling boolean style options for the editor.
StyleVar
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_styleDeprecated
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.