ImGui Node Editor: node graphs made of nodes, pins and links, on a canvas that zooms and pans.
The C++ API of ImGui Node Editor as it is bound to Python: the entries of the module imgui_bundle.imgui_node_editor, in the same order, with their C++ signatures and the headers’ comments. From the stubs: the functions excluded from the bindings, the typedefs and the macros are absent.
imgui_node_editor.h¶
Enums¶
PinKind (enum)¶
The kind of a pin, given to BeginPin(): an input or an output
| Member | Value | |
|---|---|---|
Input | 0 | |
Output | 1 |
FlowDirection (enum)¶
The direction of the flow animation along a link, given to Flow()
| Member | Value | |
|---|---|---|
Forward | 0 | |
Backward | 1 |
CanvasSizeMode (enum)¶
How the view adapts when the editor’s window is resized (Config::CanvasSizeMode)
| Member | Value | |
|---|---|---|
FitVerticalView | 0 | Previous view will be scaled to fit new view on Y axis |
FitHorizontalView | 1 | Previous view will be scaled to fit new view on X axis |
CenterOnly | 2 | Previous view will be centered on new view |
Config¶
SaveReasonFlags (enum)¶
Why the editor saves its settings: given to the callbacks Config::SaveSettings and SaveNodeSettings
| Member | Value | |
|---|---|---|
None = 0x00000000 | 0x00000000 | |
Navigation = 0x00000001 | 0x00000001 | |
Position = 0x00000002 | 0x00000002 | |
Size = 0x00000004 | 0x00000004 | |
Selection = 0x00000008 | 0x00000008 | |
AddNode = 0x00000010 | 0x00000010 | |
RemoveNode = 0x00000020 | 0x00000020 | |
User = 0x00000040 | 0x00000040 |
Config (struct)¶
The configuration of an editor, given to CreateEditor(): settings file, callbacks, mouse buttons, zoom
| Member | |
|---|---|
void* UserPointer; | Passed to the callbacks above |
CanvasSizeModeAlias CanvasSizeMode; | How the view adapts when the editor’s window is resized |
int DragButtonIndex; | Mouse button index drag action will react to (0-left, 1-right, 2-middle) |
int SelectButtonIndex; | Mouse button index select action will react to (0-left, 1-right, 2-middle) |
int NavigateButtonIndex; | Mouse button index navigate action will react to (0-left, 1-right, 2-middle) |
int ContextMenuButtonIndex; | Mouse button index context menu action will react to (0-left, 1-right, 2-middle) |
bool EnableSmoothZoom; | Smooth zoom with the wheel (False: steps through the zoom levels) |
float SmoothZoomPower; | With smooth zoom, the zoom factor of one wheel step |
bool ForceWindowContentWidthToNodeWidth; | |
| `` |
Config::Config¶
Config() : SettingsFile("NodeEditor.json")\
, BeginSaveSession(nullptr)\
, EndSaveSession(nullptr)\
, SaveSettings(nullptr)\
, LoadSettings(nullptr)\
, SaveNodeSettings(nullptr)\
, LoadNodeSettings(nullptr)\
, UserPointer(nullptr)\
, CustomZoomLevels()\
, CanvasSizeMode(CanvasSizeModeAlias::FitVerticalView)\
, DragButtonIndex(0)\
, SelectButtonIndex(0)\
, NavigateButtonIndex(1)\
, ContextMenuButtonIndex(1)\
, EnableSmoothZoom(true)\
\# ifdef __APPLE__\
, SmoothZoomPower(1.1f)\
\# else\
, SmoothZoomPower(1.3f)\
\# endifStyle¶
StyleColor (enum)¶
The colors of an editor: the indices of Style::Colors (see PushStyleColor())
| Member | Value | |
|---|---|---|
StyleColor_Bg | 0 | |
StyleColor_Grid | 1 | |
StyleColor_NodeBg | 2 | |
StyleColor_NodeBorder | 3 | |
StyleColor_HovNodeBorder | 4 | |
StyleColor_SelNodeBorder | 5 | |
StyleColor_NodeSelRect | 6 | |
StyleColor_NodeSelRectBorder | 7 | |
StyleColor_HovLinkBorder | 8 | |
StyleColor_SelLinkBorder | 9 | |
StyleColor_HighlightLinkBorder | 10 | |
StyleColor_LinkSelRect | 11 | |
StyleColor_LinkSelRectBorder | 12 | |
StyleColor_PinRect | 13 | |
StyleColor_PinRectBorder | 14 | |
StyleColor_Flow | 15 | |
StyleColor_FlowMarker | 16 | |
StyleColor_GroupBg | 17 | |
StyleColor_GroupBorder | 18 | |
StyleColor_Count | 19 |
StyleVar (enum)¶
The style variables that PushStyleVar() changes: the fields of Style
| Member | Value | |
|---|---|---|
StyleVar_NodePadding | 0 | |
StyleVar_NodeRounding | 1 | |
StyleVar_NodeBorderWidth | 2 | |
StyleVar_HoveredNodeBorderWidth | 3 | |
StyleVar_SelectedNodeBorderWidth | 4 | |
StyleVar_PinRounding | 5 | |
StyleVar_PinBorderWidth | 6 | |
StyleVar_LinkStrength | 7 | |
StyleVar_SourceDirection | 8 | |
StyleVar_TargetDirection | 9 | |
StyleVar_ScrollDuration | 10 | |
StyleVar_FlowMarkerDistance | 11 | |
StyleVar_FlowSpeed | 12 | |
StyleVar_FlowDuration | 13 | |
StyleVar_PivotAlignment | 14 | |
StyleVar_PivotSize | 15 | |
StyleVar_PivotScale | 16 | |
StyleVar_PinCorners | 17 | |
StyleVar_PinRadius | 18 | |
StyleVar_PinArrowSize | 19 | |
StyleVar_PinArrowWidth | 20 | |
StyleVar_GroupRounding | 21 | |
StyleVar_GroupBorderWidth | 22 | |
StyleVar_HighlightConnectedLinks | 23 | |
StyleVar_SnapLinkToPinDir | 24 | |
StyleVar_HoveredNodeBorderOffset | 25 | |
StyleVar_SelectedNodeBorderOffset | 26 | |
StyleVar_GridSize | 27 | |
StyleVar_Count | 28 |
Style (struct)¶
The style of an editor (GetStyle()): sizes, roundings, the links, the flow animation, the colors
| Member | |
|---|---|
ImVec4 NodePadding; | |
float NodeRounding; | |
float NodeBorderWidth; | |
float HoveredNodeBorderWidth; | |
float HoverNodeBorderOffset; | |
float SelectedNodeBorderWidth; | |
float SelectedNodeBorderOffset; | |
float PinRounding; | |
float PinBorderWidth; | |
float LinkStrength; | |
ImVec2 SourceDirection; | |
ImVec2 TargetDirection; | |
float ScrollDuration; | |
float FlowMarkerDistance; | |
float FlowSpeed; | |
float FlowDuration; | |
ImVec2 PivotAlignment; | |
ImVec2 PivotSize; | |
ImVec2 PivotScale; | |
float PinCorners; | |
float PinRadius; | |
float PinArrowSize; | |
float PinArrowWidth; | |
float GroupRounding; | |
float GroupBorderWidth; | |
float HighlightConnectedLinks; | |
float SnapLinkToPinDir; | when True link will start on the line defined by pin direction |
bool AngledLinks; | when True (default), a link that would pass through its source or target node is routed around them, with angles |
ImVec2 GridSize; | size of a background grid cell, in canvas units (x and y independent) |
Style::Style¶
Style();Functions¶
Editor context lifecycle¶
You may keep multiple editors and switch between them with SetCurrentEditor.
Pass a Config to CreateEditor to set e.g. SettingsFile (where node positions
are persisted) or to override the default mouse buttons.
ax::NodeEditor::SetCurrentEditor¶
IMGUI_NODE_EDITOR_API void SetCurrentEditor(EditorContext* ctx);Makes this editor the current one: all the other functions apply to the current editor.
ax::NodeEditor::GetCurrentEditor¶
IMGUI_NODE_EDITOR_API EditorContext* GetCurrentEditor();The current editor (None if none)
ax::NodeEditor::CreateEditor¶
IMGUI_NODE_EDITOR_API EditorContext* CreateEditor(const Config* config = nullptr);Creates an editor, with a copy of this config (or the default one). It does not become current (SetCurrentEditor).
ax::NodeEditor::DestroyEditor¶
IMGUI_NODE_EDITOR_API void DestroyEditor(EditorContext* ctx);Destroys an editor created by CreateEditor()
ax::NodeEditor::GetConfig¶
IMGUI_NODE_EDITOR_API const Config& GetConfig(EditorContext* ctx = nullptr);The config of this editor (None: the current one). It is read-only: give your Config to CreateEditor().
Style¶
Editor-specific style, separate from ImGui::GetStyle().
Push/PopStyleColor and Push/PopStyleVar work like the ImGui equivalents.
ax::NodeEditor::GetStyle¶
IMGUI_NODE_EDITOR_API Style& GetStyle();The style of the current editor: its fields can be changed
ax::NodeEditor::GetStyleColorName¶
IMGUI_NODE_EDITOR_API const char* GetStyleColorName(StyleColor colorIndex);The name of a style color
ax::NodeEditor::PushStyleColor¶
IMGUI_NODE_EDITOR_API void PushStyleColor(StyleColor colorIndex, const ImVec4& color);Pushes a style color until PopStyleColor(), e.g. PushStyleColor(StyleColor_NodeBg, color).
ax::NodeEditor::PopStyleColor¶
IMGUI_NODE_EDITOR_API void PopStyleColor(int count = 1);Pops the last count colors pushed by PushStyleColor()
ax::NodeEditor::PushStyleVar¶
IMGUI_NODE_EDITOR_API void PushStyleVar(StyleVar varIndex, float value);IMGUI_NODE_EDITOR_API void PushStyleVar(StyleVar varIndex, const ImVec2& value);IMGUI_NODE_EDITOR_API void PushStyleVar(StyleVar varIndex, const ImVec4& value);Pushes a style variable until PopStyleVar(). This one for a float variable, the next ones for an ImVec2 or an ImVec4.
ax::NodeEditor::PopStyleVar¶
IMGUI_NODE_EDITOR_API void PopStyleVar(int count = 1);Pops the last count variables pushed by PushStyleVar()
Frame¶
All node-editor calls (BeginNode, Link, BeginCreate, ...) must be made
between Begin() and End(), and Begin() must be called inside a real ImGui
window. id distinguishes editor instances inside the same window;
size matches ImGui::BeginChild semantics (0 = available).
ax::NodeEditor::Begin¶
IMGUI_NODE_EDITOR_API void Begin(const char* id, const ImVec2& size = ImVec2(0, 0));Starts drawing the current editor, in the current ImGui window: the other calls follow, until End().
ax::NodeEditor::End¶
IMGUI_NODE_EDITOR_API void End();Ends the editor started by Begin()
Nodes & pins¶
Inside Begin/End: declare each node with BeginNode(id) ... EndNode(), and (optionally) declare its pins with BeginPin(id, kind) ... EndPin() in between. Anything you draw between the Begin/End is rendered inside the node; pins are typically wrapped around a Text/Button so the user has something to grab onto.
ax::NodeEditor::BeginNode¶
IMGUI_NODE_EDITOR_API void BeginNode(NodeId id);Starts a node: its widgets follow, until EndNode()
ax::NodeEditor::BeginPin¶
IMGUI_NODE_EDITOR_API void BeginPin(PinId id, PinKind kind);Starts a pin: its widgets follow, until EndPin()
Pin geometry overrides (advanced)¶
By default the pin’s own item rectangle is used both as the hover area
and as the place where links attach (the “pivot”). Use these calls to
customize either independently, between BeginPin and EndPin.
PinRect(a, b) : override the pin’s hover/visual rectangle
(otherwise inferred from drawn content).
PinPivotRect(a, b) : override the rectangle used to compute where
a link attaches.
PinPivotSize(size) : set the pivot rect’s size; -1 on a component
means “use the pin’s size on that axis”.
PinPivotScale(scale) : multiplicative scale applied to PivotSize.
PinPivotAlignment(al) : where in the pin’s rect the pivot is anchored;
(0,0)=top-left, (1,1)=bottom-right, (0.5,0.5)=center.
You will rarely need these unless you draw custom-shaped pins (e.g. a
triangle whose tip should be the link attach point).
ax::NodeEditor::PinRect¶
IMGUI_NODE_EDITOR_API void PinRect(const ImVec2& a, const ImVec2& b);Sets the pin’s hover rectangle
ax::NodeEditor::PinPivotRect¶
IMGUI_NODE_EDITOR_API void PinPivotRect(const ImVec2& a, const ImVec2& b);Sets the rectangle where links attach
ax::NodeEditor::PinPivotSize¶
IMGUI_NODE_EDITOR_API void PinPivotSize(const ImVec2& size);Sets the pivot’s size (-1 on an axis: the pin’s)
ax::NodeEditor::PinPivotScale¶
IMGUI_NODE_EDITOR_API void PinPivotScale(const ImVec2& scale);Scales the pivot’s size
ax::NodeEditor::PinPivotAlignment¶
IMGUI_NODE_EDITOR_API void PinPivotAlignment(const ImVec2& alignment);Where links attach: (0.5, 0.5) is the center
ax::NodeEditor::EndPin¶
IMGUI_NODE_EDITOR_API void EndPin();Ends the pin started by BeginPin()
Group nodes¶
Calling Group(size) inside a BeginNode/EndNode block turns the node into a
“Group node”: a tinted, resizable rectangle (StyleColor_GroupBg / GroupBorder)
that can act as a labeled container for other nodes.
Behavior:
The user can resize the group by dragging its bottom-right corner.
Dragging the group drags every node whose bounds fall inside it (handled internally by the editor’s DragAction).
sizeis only the INITIAL size, applied on the very first frame the group exists. Subsequent user resizes are persisted by the editor and overridesize. To resize a group programmatically afterwards, use
SetGroupSize(node_id, size).Anything drawn between BeginNode and Group(size) lands in the group’s
“title strip” above the colored rectangle: title text, buttons, and even pins via BeginPin/EndPin (useful for “summary” pins on a collapsed group).
Minimal example (C++):
ed::BeginNode(groupId);
ImGui::TextUnformatted("My Group");
ed::Group(ImVec2(300, 200)); // initial size only
ed::EndNode();Minimal example (Python):
ed.begin_node(group_id)
imgui.text_unformatted(“My Group”)
ed.group(imgui.ImVec2(300, 200)) # initial size only
ed.end_node()
To find the nodes contained in a group, use the editor’s geometry getters
(no internal API needed): get the group’s GetNodePosition / GetNodeSize,
then for each candidate node test whether its center sits inside the
group’s rectangle.
ax::NodeEditor::Group¶
IMGUI_NODE_EDITOR_API void Group(const ImVec2& size);Makes the current node a group, of this initial size
ax::NodeEditor::EndNode¶
IMGUI_NODE_EDITOR_API void EndNode();Ends the node started by BeginNode()
Group hints¶
A “group hint” is overlay UI that the editor renders ONLY when zoomed out
far enough that the in-node title becomes hard to read. BeginGroupHint
returns False at normal zoom; it returns True and fades in below ~0.75x.
The intended use is to draw a large title above the group so users can
still identify it at low zoom.
GetGroupMin / GetGroupMax return the targeted group’s bounds in SCREEN
coordinates so you can position your overlay relative to it.
GetHintForegroundDrawList / GetHintBackgroundDrawList return draw lists
that sit above (foreground) and below (background) the editor’s normal
content, so your overlay isn’t clipped by the canvas.
Minimal example (C++):
if (ed::BeginGroupHint(groupId))
{
ImVec2 min = ed::GetGroupMin();
auto* fg = ed::GetHintForegroundDrawList(); fg->AddText(ImVec2(min.x, min.y - 24.0),\
ImGui::GetColorU32(ImGuiCol_Text), "My Group");
}
ed::EndGroupHint();Minimal example (Python):
if ed.begin_group_hint(group_id):
min_ = ed.get_group_min()
fg = ed.get_hint_foreground_draw_list()
fg.add_text(imgui.ImVec2(min_.x, min_.y - 24.0),
imgui.get_color_u32(imgui.Col_.text.value),
“My Group”)
ed.end_group_hint()
ax::NodeEditor::BeginGroupHint¶
IMGUI_NODE_EDITOR_API bool BeginGroupHint(NodeId nodeId);True when zoomed out: draw the group’s hint then
ax::NodeEditor::GetGroupMin¶
IMGUI_NODE_EDITOR_API ImVec2 GetGroupMin();The top left corner of the group, in screen coords (in a hint)
ax::NodeEditor::GetGroupMax¶
IMGUI_NODE_EDITOR_API ImVec2 GetGroupMax();The bottom right corner of the group, in screen coords (in a hint)
ax::NodeEditor::GetHintForegroundDrawList¶
IMGUI_NODE_EDITOR_API ImDrawList* GetHintForegroundDrawList();A draw list above the editor’s content (in a hint)
ax::NodeEditor::GetHintBackgroundDrawList¶
IMGUI_NODE_EDITOR_API ImDrawList* GetHintBackgroundDrawList();A draw list below the editor’s content (in a hint)
ax::NodeEditor::EndGroupHint¶
IMGUI_NODE_EDITOR_API void EndGroupHint();Ends the group hint (see the example above)
ax::NodeEditor::GetNodeBackgroundDrawList¶
IMGUI_NODE_EDITOR_API ImDrawList* GetNodeBackgroundDrawList(NodeId nodeId);Returns the draw list used for the node’s BACKGROUND layer (drawn under
the node’s content). Useful to add badges, highlights, etc. behind a node.
TODO: Add a way to manage node background channels
ax::NodeEditor::Link¶
IMGUI_NODE_EDITOR_API bool Link(LinkId id, PinId startPinId, PinId endPinId, const ImVec4& color = ImVec4(0, 0, 0, 0), float thickness = 1.0f);Declares an existing link between two pins. Call once per frame for every
link you want shown. Returns False when one of its pins was not drawn this frame.
color default is the sentinel ImVec4(0,0,0,0) (“auto”): when alpha is 0
the implementation substitutes the current ImGuiCol_Text, so links stay
readable on both light and dark themes. Pass any non-zero-alpha color to
override.
ax::NodeEditor::Flow¶
IMGUI_NODE_EDITOR_API void Flow(LinkId linkId, FlowDirection direction = FlowDirection::Forward);Trigger a one-shot animated “flow” pulse along a link. Calling this once is enough; the editor handles the time-bounded animation internally.
Item creation (drag-out new link / new node)¶
Interaction protocol fired while the user drags a link from a pin:
if (BeginCreate()) {
PinId a, b;
if (QueryNewLink(&a, &b)) { // user is hovering a candidate endpoint if (/* link a->b is invalid */) RejectNewItem(); // shows red feedback
else if (AcceptNewItem()) // returns True on mouse-release
/* commit the new link to your data model */;
}
if (QueryNewNode(&a)) { // user dragged a link into empty space
if (AcceptNewItem()) // -> typical UX: open a "Add node" popup
/* spawn a new node and connect pin `a` to one of its pins */;
}
EndCreate(); // only when BeginCreate() returned True
}The QueryNewLink/QueryNewNode/AcceptNewItem overloads taking a color and
thickness customize the in-progress link’s drawing while the user drags.
Once QueryNewLink() or QueryNewNode() returned True, and until EndCreate(), the editor is suspended (it draws the
dragged link in screen space): ImGui::GetMousePos() and the cursor are then in SCREEN coords, while everywhere else
between Begin() and End() they are in CANVAS coords. To place a new node at the mouse, use GetMousePosOnCanvas().
ax::NodeEditor::BeginCreate¶
IMGUI_NODE_EDITOR_API bool BeginCreate(const ImVec4& color = ImVec4(0, 0, 0, 0), float thickness = 1.0f);Starts the create action: True while the user drags a link from a pin. Then call EndCreate().
ax::NodeEditor::QueryNewLink¶
IMGUI_NODE_EDITOR_API bool QueryNewLink(PinId* startId, PinId* endId);IMGUI_NODE_EDITOR_API bool QueryNewLink(PinId* startId, PinId* endId, const ImVec4& color, float thickness = 1.0f);True while the dragged link is not over empty space: the pin it starts from, and the pin under the mouse (0 if none).
ax::NodeEditor::QueryNewNode¶
IMGUI_NODE_EDITOR_API bool QueryNewNode(PinId* pinId);IMGUI_NODE_EDITOR_API bool QueryNewNode(PinId* pinId, const ImVec4& color, float thickness = 1.0f);True while the dragged link is over empty space: its pin
ax::NodeEditor::AcceptNewItem¶
IMGUI_NODE_EDITOR_API bool AcceptNewItem();IMGUI_NODE_EDITOR_API bool AcceptNewItem(const ImVec4& color, float thickness = 1.0f);Accepts the queried link or node: True when the mouse is released
ax::NodeEditor::RejectNewItem¶
IMGUI_NODE_EDITOR_API void RejectNewItem();IMGUI_NODE_EDITOR_API void RejectNewItem(const ImVec4& color, float thickness = 1.0f);Refuses the queried link or node: the dragged link shows it
ax::NodeEditor::EndCreate¶
IMGUI_NODE_EDITOR_API void EndCreate();Ends the create action: only when BeginCreate() returned True
ax::NodeEditor::BeginDelete¶
IMGUI_NODE_EDITOR_API bool BeginDelete();Starts the delete action: True when items are to be deleted this frame
--- Item deletion (Delete key, “Delete” context-menu, etc.) -------------
Interaction protocol that yields the things the user wants to delete this
frame. You decide whether to honor each one:
if (BeginDelete()) {
LinkId l; while (QueryDeletedLink(&l)) if (AcceptDeletedItem()) /* remove link from your model */;
NodeId n; while (QueryDeletedNode(&n)) if (AcceptDeletedItem()) /* remove node and its links */;
}
EndDelete();deleteDependencies = True (the default for AcceptDeletedItem) tells the
editor to also enqueue links touching the accepted node, so a subsequent
QueryDeletedLink call yields them too.
ax::NodeEditor::QueryDeletedLink¶
IMGUI_NODE_EDITOR_API bool QueryDeletedLink(LinkId* linkId, PinId* startId = nullptr, PinId* endId = nullptr);True for each link to delete, one per call: its id, and its pins if you want them.
ax::NodeEditor::QueryDeletedNode¶
IMGUI_NODE_EDITOR_API bool QueryDeletedNode(NodeId* nodeId);True for each node to delete, one per call: its id
ax::NodeEditor::AcceptDeletedItem¶
IMGUI_NODE_EDITOR_API bool AcceptDeletedItem(bool deleteDependencies = true);Accepts the deletion of the queried item: then remove it from your data (see deleteDependencies above).
ax::NodeEditor::RejectDeletedItem¶
IMGUI_NODE_EDITOR_API void RejectDeletedItem();Refuses the deletion of the queried item: it stays
ax::NodeEditor::EndDelete¶
IMGUI_NODE_EDITOR_API void EndDelete();Ends the delete action (harmless when BeginDelete() returned False)
Node geometry¶
Positions and sizes are in EDITOR (canvas) space, not screen space. Use
CanvasToScreen / ScreenToCanvas to convert.
GetNodeSize returns (0,0) on the very first frame a node is drawn (the
editor has no measurement yet). It stabilizes immediately after.
ax::NodeEditor::SetNodePosition¶
IMGUI_NODE_EDITOR_API void SetNodePosition(NodeId nodeId, const ImVec2& editorPosition);Sets a node’s position, in canvas coords (e.g. once, when you create it): the editor keeps it afterwards.
ax::NodeEditor::SetGroupSize¶
IMGUI_NODE_EDITOR_API void SetGroupSize(NodeId nodeId, const ImVec2& size);Sets the size of a group node
ax::NodeEditor::GetNodePosition¶
IMGUI_NODE_EDITOR_API ImVec2 GetNodePosition(NodeId nodeId);In canvas coords; (FLT_MAX, FLT_MAX) if unknown
ax::NodeEditor::GetNodeSize¶
IMGUI_NODE_EDITOR_API ImVec2 GetNodeSize(NodeId nodeId);In canvas coords; (0, 0) before the node was drawn
ax::NodeEditor::CenterNodeOnScreen¶
IMGUI_NODE_EDITOR_API void CenterNodeOnScreen(NodeId nodeId);Moves the node (a group: with its nodes) to the center of the view, when it is next drawn.
ax::NodeEditor::SetNodeZPosition¶
IMGUI_NODE_EDITOR_API void SetNodeZPosition(NodeId nodeId, float z);Sets node z position, nodes with higher value are drawn over nodes with lower value
ax::NodeEditor::GetNodeZPosition¶
IMGUI_NODE_EDITOR_API float GetNodeZPosition(NodeId nodeId);Returns node z position, defaults is 0.0
ax::NodeEditor::RestoreNodeState¶
IMGUI_NODE_EDITOR_API void RestoreNodeState(NodeId nodeId);Re-load the node’s position/size from the editor’s persisted settings (the SettingsFile, if any). Useful right after creating a node whose previous layout you want to bring back without the user having to drag it.
Suspend / Resume¶
Temporarily disable the editor’s input/canvas state machine: positions are then in SCREEN coords. With a stock
Dear ImGui, you MUST suspend before calling ImGui popup APIs like ImGui::OpenPopup or ImGui::BeginPopup that should
appear ABOVE the canvas (otherwise the popup’s coordinates and event capture will be wrong). With a Dear ImGui that
has the patches of docs/fork_imgui_bundle.md (chapter 3), popups work without it. Resume() restores editor input
handling. See the ShowNodeContextMenu example below.
ax::NodeEditor::Suspend¶
IMGUI_NODE_EDITOR_API void Suspend();Suspends the canvas: positions are in screen coords until Resume()
ax::NodeEditor::Resume¶
IMGUI_NODE_EDITOR_API void Resume();Resumes the canvas suspended by Suspend()
ax::NodeEditor::IsSuspended¶
IMGUI_NODE_EDITOR_API bool IsSuspended();True between Suspend() and Resume()
ax::NodeEditor::IsActive¶
IMGUI_NODE_EDITOR_API bool IsActive();True when the editor’s window has the focus: the editor’s keyboard shortcuts work only then.
Selection¶
HasSelectionChanged returns True for one frame after the selection set
changed (use it to react to selection changes once, not every frame).
SelectNode/SelectLink with append=False replaces the current selection.
ax::NodeEditor::HasSelectionChanged¶
IMGUI_NODE_EDITOR_API bool HasSelectionChanged();True during the frame after the selection changed
ax::NodeEditor::GetSelectedObjectCount¶
IMGUI_NODE_EDITOR_API int GetSelectedObjectCount();The number of selected nodes and links
ax::NodeEditor::IsNodeSelected¶
IMGUI_NODE_EDITOR_API bool IsNodeSelected(NodeId nodeId);True if the node is selected
ax::NodeEditor::IsLinkSelected¶
IMGUI_NODE_EDITOR_API bool IsLinkSelected(LinkId linkId);True if the link is selected
ax::NodeEditor::ClearSelection¶
IMGUI_NODE_EDITOR_API void ClearSelection();Deselects all the nodes and links
ax::NodeEditor::SelectNode¶
IMGUI_NODE_EDITOR_API void SelectNode(NodeId nodeId, bool append = false);Selects a node (append: keep the others)
ax::NodeEditor::SelectLink¶
IMGUI_NODE_EDITOR_API void SelectLink(LinkId linkId, bool append = false);Selects a link (append: keep the others)
ax::NodeEditor::DeselectNode¶
IMGUI_NODE_EDITOR_API void DeselectNode(NodeId nodeId);Removes a node from the selection
ax::NodeEditor::DeselectLink¶
IMGUI_NODE_EDITOR_API void DeselectLink(LinkId linkId);Removes a link from the selection
ax::NodeEditor::DeleteNode¶
IMGUI_NODE_EDITOR_API bool DeleteNode(NodeId nodeId);Queues a node for deletion (see BeginDelete())
Programmatically queue a node/link for deletion. The next BeginDelete() loop will yield it via QueryDeletedNode/QueryDeletedLink.
ax::NodeEditor::DeleteLink¶
IMGUI_NODE_EDITOR_API bool DeleteLink(LinkId linkId);Queues a link for deletion (see BeginDelete())
ax::NodeEditor::HasAnyLinks¶
IMGUI_NODE_EDITOR_API bool HasAnyLinks(NodeId nodeId);IMGUI_NODE_EDITOR_API bool HasAnyLinks(PinId pinId);Returns True if node has any link connected
ax::NodeEditor::BreakLinks¶
IMGUI_NODE_EDITOR_API int BreakLinks(NodeId nodeId);IMGUI_NODE_EDITOR_API int BreakLinks(PinId pinId);Break all links connected to this node
Navigation¶
Programmatic equivalents of pressing F (with no modifier and with Shift).
duration is the animation length in seconds; -1 means “use the editor
default”. NavigateToSelection requires a non-empty selection.
ax::NodeEditor::NavigateToContent¶
IMGUI_NODE_EDITOR_API void NavigateToContent(float duration = -1);Moves the view to show all the nodes, as F does. Call it after End(). New nodes are measured over two frames: to fit them, call it at their third frame.
ax::NodeEditor::NavigateToSelection¶
IMGUI_NODE_EDITOR_API void NavigateToSelection(bool zoomIn = false, float duration = -1);Moves the view to the selected nodes, as Shift+F does (zoomIn: zoom in too, to fit them).
ax::NodeEditor::ShowNodeContextMenu¶
IMGUI_NODE_EDITOR_API bool ShowNodeContextMenu(NodeId* nodeId);True when the user opens a node’s menu: its id
Shows context menu for node, link or background
Typical usage (this should happen inside ed::Begin/ed::End block):
ed::Begin();
... (Show nodes)
ed::Suspend();
if (ed::ShowNodeContextMenu(&contextNodeId))
ImGui::OpenPopup("Node Context Menu");
ed::Resume();
...
ed::Suspend(); if (ImGui::BeginPopup("Node Context Menu")) {
ImGui::Text("Node Context Menu, node ID: %d", contextNodeId);
ImGui::EndPopup();
}
ed::Resume();
...
ed::End();(With the Dear ImGui patches of docs/fork_imgui_bundle.md, the Suspend() / Resume() pairs are not needed.)
ax::NodeEditor::ShowPinContextMenu¶
IMGUI_NODE_EDITOR_API bool ShowPinContextMenu(PinId* pinId);True when the user opens a pin’s menu: its id
ax::NodeEditor::ShowLinkContextMenu¶
IMGUI_NODE_EDITOR_API bool ShowLinkContextMenu(LinkId* linkId);True when the user opens a link’s menu: its id
ax::NodeEditor::ShowBackgroundContextMenu¶
IMGUI_NODE_EDITOR_API bool ShowBackgroundContextMenu();True when the user opens the background’s menu
Keyboard shortcuts¶
Master switch: when disabled the editor never reacts to F / Ctrl+X /
Ctrl+C / Ctrl+V / Ctrl+D / Space etc. Useful when an ImGui text input
has focus and you want shortcuts ignored.
ax::NodeEditor::EnableShortcuts¶
IMGUI_NODE_EDITOR_API void EnableShortcuts(bool enable);Enables or disables the editor’s keyboard shortcuts
ax::NodeEditor::AreShortcutsEnabled¶
IMGUI_NODE_EDITOR_API bool AreShortcutsEnabled();True if the keyboard shortcuts are enabled
Shortcut handling protocol¶
Lets you ASK the editor which keyboard shortcut fired this frame and respond to it. Pattern (inside Begin/End):
if (BeginShortcut()) {
if (AcceptCopy()) /* user pressed Ctrl+C: copy selection */;
if (AcceptPaste()) /* user pressed Ctrl+V: paste at mouse */;
if (AcceptCut()) /* user pressed Ctrl+X */;
if (AcceptDuplicate()) /* user pressed Ctrl+D */;
if (AcceptCreateNode()) /* user pressed Space */;
}
EndShortcut();GetActionContextNodes / GetActionContextLinks return the objects the shortcut applies to (typically the current selection at the moment the shortcut fired). They are valid only between Begin/EndShortcut.
ax::NodeEditor::BeginShortcut¶
IMGUI_NODE_EDITOR_API bool BeginShortcut();Starts the shortcut action: True when a shortcut fired this frame
ax::NodeEditor::AcceptCut¶
IMGUI_NODE_EDITOR_API bool AcceptCut();True if the shortcut is Cut (Ctrl+X)
ax::NodeEditor::AcceptCopy¶
IMGUI_NODE_EDITOR_API bool AcceptCopy();True if the shortcut is Copy (Ctrl+C)
ax::NodeEditor::AcceptPaste¶
IMGUI_NODE_EDITOR_API bool AcceptPaste();True if the shortcut is Paste (Ctrl+V)
ax::NodeEditor::AcceptDuplicate¶
IMGUI_NODE_EDITOR_API bool AcceptDuplicate();True if the shortcut is Duplicate (Ctrl+D)
ax::NodeEditor::AcceptCreateNode¶
IMGUI_NODE_EDITOR_API bool AcceptCreateNode();True if the shortcut is Create a node (Space)
ax::NodeEditor::GetActionContextSize¶
IMGUI_NODE_EDITOR_API int GetActionContextSize();The number of nodes and links the shortcut applies to
ax::NodeEditor::EndShortcut¶
IMGUI_NODE_EDITOR_API void EndShortcut();Ends the shortcut action (harmless when BeginShortcut() returned False)
ax::NodeEditor::GetCurrentZoom¶
IMGUI_NODE_EDITOR_API float GetCurrentZoom();Returns the INVERSE of the zoom: the size of a pixel in canvas units.
1.0 at 100%, 2.0 when the content is drawn at half size (zoomed out), 0.5 when it is drawn twice as big (zoomed in).
To convert positions, use ScreenToCanvas() / CanvasToScreen().
Input queries (call between Begin and End)¶
These return the object under the mouse this frame (NodeId/PinId/LinkId,
0 if none) and which buttons were clicked or double-clicked on the empty
background. The “BackgroundClick” pair returns -1 when no click happened.
ax::NodeEditor::GetHoveredNode¶
IMGUI_NODE_EDITOR_API NodeId GetHoveredNode();The node under the mouse (0 if none)
ax::NodeEditor::GetHoveredPin¶
IMGUI_NODE_EDITOR_API PinId GetHoveredPin();The pin under the mouse (0 if none)
ax::NodeEditor::GetHoveredLink¶
IMGUI_NODE_EDITOR_API LinkId GetHoveredLink();The link under the mouse (0 if none)
ax::NodeEditor::GetDoubleClickedNode¶
IMGUI_NODE_EDITOR_API NodeId GetDoubleClickedNode();The node double-clicked this frame (0 if none)
ax::NodeEditor::GetDoubleClickedPin¶
IMGUI_NODE_EDITOR_API PinId GetDoubleClickedPin();The pin double-clicked this frame (0 if none)
ax::NodeEditor::GetDoubleClickedLink¶
IMGUI_NODE_EDITOR_API LinkId GetDoubleClickedLink();The link double-clicked this frame (0 if none)
ax::NodeEditor::IsBackgroundClicked¶
IMGUI_NODE_EDITOR_API bool IsBackgroundClicked();True if the background was clicked this frame
ax::NodeEditor::IsBackgroundDoubleClicked¶
IMGUI_NODE_EDITOR_API bool IsBackgroundDoubleClicked();True if the background was double-clicked this frame
ax::NodeEditor::GetBackgroundClickButtonIndex¶
IMGUI_NODE_EDITOR_API ImGuiMouseButton GetBackgroundClickButtonIndex();-1 if none
ax::NodeEditor::GetBackgroundDoubleClickButtonIndex¶
IMGUI_NODE_EDITOR_API ImGuiMouseButton GetBackgroundDoubleClickButtonIndex();-1 if none
ax::NodeEditor::GetLinkPins¶
IMGUI_NODE_EDITOR_API bool GetLinkPins(LinkId linkId, PinId* startPinId, PinId* endPinId);pass None if particular pin do not interest you
ax::NodeEditor::PinHadAnyLinks¶
IMGUI_NODE_EDITOR_API bool PinHadAnyLinks(PinId pinId);True if the pin was ever connected to a link in its lifetime, even if it is currently disconnected.
Coordinate conversion¶
SCREEN coords are pixels in the OS window. CANVAS coords are the editor’s virtual space (what GetNodePosition / SetNodePosition use). The two differ by the current pan + zoom transform.
ax::NodeEditor::GetScreenSize¶
IMGUI_NODE_EDITOR_API ImVec2 GetScreenSize();The size of the editor on screen, in pixels
ax::NodeEditor::ScreenToCanvas¶
IMGUI_NODE_EDITOR_API ImVec2 ScreenToCanvas(const ImVec2& pos);Converts a position from screen to canvas coords
ax::NodeEditor::CanvasToScreen¶
IMGUI_NODE_EDITOR_API ImVec2 CanvasToScreen(const ImVec2& pos);Converts a position from canvas to screen coords
ax::NodeEditor::GetMousePosOnCanvas¶
IMGUI_NODE_EDITOR_API ImVec2 GetMousePosOnCanvas();The mouse position in CANVAS coords, anywhere between Begin() and End(). ImGui::GetMousePos() gives the same, except where the editor is suspended (after Suspend(), and in the create action once QueryNewLink() or QueryNewNode() returned True): it then gives SCREEN coords.
ax::NodeEditor::GetNodeCount¶
IMGUI_NODE_EDITOR_API int GetNodeCount();Returns number of submitted nodes since Begin() call
node_editor_default_context.h¶
ax::NodeEditor::DefaultNodeEditorContext_Immapp¶
IMGUI_NODE_EDITOR_API NodeEditorContext* DefaultNodeEditorContext_Immapp();The editor created by ImmApp::Run() with withNodeEditor or withNodeEditorConfig (an error if there is none)
ax::NodeEditor::SuspendNodeEditorCanvas_Immapp¶
IMGUI_NODE_EDITOR_API void SuspendNodeEditorCanvas_Immapp();Same as ax::NodeEditor::Suspend()
ax::NodeEditor::ResumeNodeEditorCanvas_Immapp¶
IMGUI_NODE_EDITOR_API void ResumeNodeEditorCanvas_Immapp();Same as ax::NodeEditor::Resume()
ax::NodeEditor::DisableUserInputThisFrame¶
IMGUI_NODE_EDITOR_API void DisableUserInputThisFrame();Ignores the user’s input in the current editor this frame: e.g. the wheel over an image zooms it, not the canvas
ax::NodeEditor::UpdateNodeEditorColorsFromImguiColors¶
IMGUI_NODE_EDITOR_API void UpdateNodeEditorColorsFromImguiColors();Sets the colors of the current editor from Dear ImGui’s colors (ImmApp does it at each frame, unless disabled with updateNodeEditorColorsFromImguiColors = False)