Skip to content

Commit 268e5fe

Browse files
committed
Editor: Add IMGUI_NODE_EDITOR_API to support building editor as a shared library (#189)
1 parent 7d0f315 commit 268e5fe

File tree

2 files changed

+150
-142
lines changed

2 files changed

+150
-142
lines changed

docs/CHANGELOG.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ v0.9.2 (WIP):
22

33
NEW: Editor: Add offset of hover/select to style (thanks @MultiPain)
44

5+
NEW: Editor: Add IMGUI_NODE_EDITOR_API to support building editor as a shared library (#189)
6+
57
CHANGE: Editor: Support ImGui r18836 after SetItemUsingMouseWheel removal (#218), thanks @ocornut
68

79
CHANGE: Editor: Define IMGUI_DEFINE_MATH_OPERATORS before <imgui.h> (#209), thanks @ocornut

imgui_node_editor.h

Lines changed: 148 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
# define IMGUI_NODE_EDITOR_VERSION_NUM 000902
2626

2727

28+
//------------------------------------------------------------------------------
29+
#ifndef IMGUI_NODE_EDITOR_API
30+
#define IMGUI_NODE_EDITOR_API
31+
#endif
32+
33+
2834
//------------------------------------------------------------------------------
2935
namespace ax {
3036
namespace NodeEditor {
@@ -272,150 +278,150 @@ struct EditorContext;
272278

273279

274280
//------------------------------------------------------------------------------
275-
void SetCurrentEditor(EditorContext* ctx);
276-
EditorContext* GetCurrentEditor();
277-
EditorContext* CreateEditor(const Config* config = nullptr);
278-
void DestroyEditor(EditorContext* ctx);
279-
const Config& GetConfig(EditorContext* ctx = nullptr);
280-
281-
Style& GetStyle();
282-
const char* GetStyleColorName(StyleColor colorIndex);
283-
284-
void PushStyleColor(StyleColor colorIndex, const ImVec4& color);
285-
void PopStyleColor(int count = 1);
286-
287-
void PushStyleVar(StyleVar varIndex, float value);
288-
void PushStyleVar(StyleVar varIndex, const ImVec2& value);
289-
void PushStyleVar(StyleVar varIndex, const ImVec4& value);
290-
void PopStyleVar(int count = 1);
291-
292-
void Begin(const char* id, const ImVec2& size = ImVec2(0, 0));
293-
void End();
294-
295-
void BeginNode(NodeId id);
296-
void BeginPin(PinId id, PinKind kind);
297-
void PinRect(const ImVec2& a, const ImVec2& b);
298-
void PinPivotRect(const ImVec2& a, const ImVec2& b);
299-
void PinPivotSize(const ImVec2& size);
300-
void PinPivotScale(const ImVec2& scale);
301-
void PinPivotAlignment(const ImVec2& alignment);
302-
void EndPin();
303-
void Group(const ImVec2& size);
304-
void EndNode();
305-
306-
bool BeginGroupHint(NodeId nodeId);
307-
ImVec2 GetGroupMin();
308-
ImVec2 GetGroupMax();
309-
ImDrawList* GetHintForegroundDrawList();
310-
ImDrawList* GetHintBackgroundDrawList();
311-
void EndGroupHint();
281+
IMGUI_NODE_EDITOR_API void SetCurrentEditor(EditorContext* ctx);
282+
IMGUI_NODE_EDITOR_API EditorContext* GetCurrentEditor();
283+
IMGUI_NODE_EDITOR_API EditorContext* CreateEditor(const Config* config = nullptr);
284+
IMGUI_NODE_EDITOR_API void DestroyEditor(EditorContext* ctx);
285+
IMGUI_NODE_EDITOR_API const Config& GetConfig(EditorContext* ctx = nullptr);
286+
287+
IMGUI_NODE_EDITOR_API Style& GetStyle();
288+
IMGUI_NODE_EDITOR_API const char* GetStyleColorName(StyleColor colorIndex);
289+
290+
IMGUI_NODE_EDITOR_API void PushStyleColor(StyleColor colorIndex, const ImVec4& color);
291+
IMGUI_NODE_EDITOR_API void PopStyleColor(int count = 1);
292+
293+
IMGUI_NODE_EDITOR_API void PushStyleVar(StyleVar varIndex, float value);
294+
IMGUI_NODE_EDITOR_API void PushStyleVar(StyleVar varIndex, const ImVec2& value);
295+
IMGUI_NODE_EDITOR_API void PushStyleVar(StyleVar varIndex, const ImVec4& value);
296+
IMGUI_NODE_EDITOR_API void PopStyleVar(int count = 1);
297+
298+
IMGUI_NODE_EDITOR_API void Begin(const char* id, const ImVec2& size = ImVec2(0, 0));
299+
IMGUI_NODE_EDITOR_API void End();
300+
301+
IMGUI_NODE_EDITOR_API void BeginNode(NodeId id);
302+
IMGUI_NODE_EDITOR_API void BeginPin(PinId id, PinKind kind);
303+
IMGUI_NODE_EDITOR_API void PinRect(const ImVec2& a, const ImVec2& b);
304+
IMGUI_NODE_EDITOR_API void PinPivotRect(const ImVec2& a, const ImVec2& b);
305+
IMGUI_NODE_EDITOR_API void PinPivotSize(const ImVec2& size);
306+
IMGUI_NODE_EDITOR_API void PinPivotScale(const ImVec2& scale);
307+
IMGUI_NODE_EDITOR_API void PinPivotAlignment(const ImVec2& alignment);
308+
IMGUI_NODE_EDITOR_API void EndPin();
309+
IMGUI_NODE_EDITOR_API void Group(const ImVec2& size);
310+
IMGUI_NODE_EDITOR_API void EndNode();
311+
312+
IMGUI_NODE_EDITOR_API bool BeginGroupHint(NodeId nodeId);
313+
IMGUI_NODE_EDITOR_API ImVec2 GetGroupMin();
314+
IMGUI_NODE_EDITOR_API ImVec2 GetGroupMax();
315+
IMGUI_NODE_EDITOR_API ImDrawList* GetHintForegroundDrawList();
316+
IMGUI_NODE_EDITOR_API ImDrawList* GetHintBackgroundDrawList();
317+
IMGUI_NODE_EDITOR_API void EndGroupHint();
312318

313319
// TODO: Add a way to manage node background channels
314-
ImDrawList* GetNodeBackgroundDrawList(NodeId nodeId);
315-
316-
bool Link(LinkId id, PinId startPinId, PinId endPinId, const ImVec4& color = ImVec4(1, 1, 1, 1), float thickness = 1.0f);
317-
318-
void Flow(LinkId linkId, FlowDirection direction = FlowDirection::Forward);
319-
320-
bool BeginCreate(const ImVec4& color = ImVec4(1, 1, 1, 1), float thickness = 1.0f);
321-
bool QueryNewLink(PinId* startId, PinId* endId);
322-
bool QueryNewLink(PinId* startId, PinId* endId, const ImVec4& color, float thickness = 1.0f);
323-
bool QueryNewNode(PinId* pinId);
324-
bool QueryNewNode(PinId* pinId, const ImVec4& color, float thickness = 1.0f);
325-
bool AcceptNewItem();
326-
bool AcceptNewItem(const ImVec4& color, float thickness = 1.0f);
327-
void RejectNewItem();
328-
void RejectNewItem(const ImVec4& color, float thickness = 1.0f);
329-
void EndCreate();
330-
331-
bool BeginDelete();
332-
bool QueryDeletedLink(LinkId* linkId, PinId* startId = nullptr, PinId* endId = nullptr);
333-
bool QueryDeletedNode(NodeId* nodeId);
334-
bool AcceptDeletedItem(bool deleteDependencies = true);
335-
void RejectDeletedItem();
336-
void EndDelete();
337-
338-
void SetNodePosition(NodeId nodeId, const ImVec2& editorPosition);
339-
void SetGroupSize(NodeId nodeId, const ImVec2& size);
340-
ImVec2 GetNodePosition(NodeId nodeId);
341-
ImVec2 GetNodeSize(NodeId nodeId);
342-
void CenterNodeOnScreen(NodeId nodeId);
343-
void SetNodeZPosition(NodeId nodeId, float z); // Sets node z position, nodes with higher value are drawn over nodes with lower value
344-
float GetNodeZPosition(NodeId nodeId); // Returns node z position, defaults is 0.0f
345-
346-
void RestoreNodeState(NodeId nodeId);
347-
348-
void Suspend();
349-
void Resume();
350-
bool IsSuspended();
351-
352-
bool IsActive();
353-
354-
bool HasSelectionChanged();
355-
int GetSelectedObjectCount();
356-
int GetSelectedNodes(NodeId* nodes, int size);
357-
int GetSelectedLinks(LinkId* links, int size);
358-
bool IsNodeSelected(NodeId nodeId);
359-
bool IsLinkSelected(LinkId linkId);
360-
void ClearSelection();
361-
void SelectNode(NodeId nodeId, bool append = false);
362-
void SelectLink(LinkId linkId, bool append = false);
363-
void DeselectNode(NodeId nodeId);
364-
void DeselectLink(LinkId linkId);
365-
366-
bool DeleteNode(NodeId nodeId);
367-
bool DeleteLink(LinkId linkId);
368-
369-
bool HasAnyLinks(NodeId nodeId); // Returns true if node has any link connected
370-
bool HasAnyLinks(PinId pinId); // Return true if pin has any link connected
371-
int BreakLinks(NodeId nodeId); // Break all links connected to this node
372-
int BreakLinks(PinId pinId); // Break all links connected to this pin
373-
374-
void NavigateToContent(float duration = -1);
375-
void NavigateToSelection(bool zoomIn = false, float duration = -1);
376-
377-
bool ShowNodeContextMenu(NodeId* nodeId);
378-
bool ShowPinContextMenu(PinId* pinId);
379-
bool ShowLinkContextMenu(LinkId* linkId);
380-
bool ShowBackgroundContextMenu();
381-
382-
void EnableShortcuts(bool enable);
383-
bool AreShortcutsEnabled();
384-
385-
bool BeginShortcut();
386-
bool AcceptCut();
387-
bool AcceptCopy();
388-
bool AcceptPaste();
389-
bool AcceptDuplicate();
390-
bool AcceptCreateNode();
391-
int GetActionContextSize();
392-
int GetActionContextNodes(NodeId* nodes, int size);
393-
int GetActionContextLinks(LinkId* links, int size);
394-
void EndShortcut();
395-
396-
float GetCurrentZoom();
397-
398-
NodeId GetHoveredNode();
399-
PinId GetHoveredPin();
400-
LinkId GetHoveredLink();
401-
NodeId GetDoubleClickedNode();
402-
PinId GetDoubleClickedPin();
403-
LinkId GetDoubleClickedLink();
404-
bool IsBackgroundClicked();
405-
bool IsBackgroundDoubleClicked();
406-
ImGuiMouseButton GetBackgroundClickButtonIndex(); // -1 if none
407-
ImGuiMouseButton GetBackgroundDoubleClickButtonIndex(); // -1 if none
408-
409-
bool GetLinkPins(LinkId linkId, PinId* startPinId, PinId* endPinId); // pass nullptr if particular pin do not interest you
410-
411-
bool PinHadAnyLinks(PinId pinId);
412-
413-
ImVec2 GetScreenSize();
414-
ImVec2 ScreenToCanvas(const ImVec2& pos);
415-
ImVec2 CanvasToScreen(const ImVec2& pos);
416-
417-
int GetNodeCount(); // Returns number of submitted nodes since Begin() call
418-
int GetOrderedNodeIds(NodeId* nodes, int size); // Fills an array with node id's in order they're drawn; up to 'size` elements are set. Returns actual size of filled id's.
320+
IMGUI_NODE_EDITOR_API ImDrawList* GetNodeBackgroundDrawList(NodeId nodeId);
321+
322+
IMGUI_NODE_EDITOR_API bool Link(LinkId id, PinId startPinId, PinId endPinId, const ImVec4& color = ImVec4(1, 1, 1, 1), float thickness = 1.0f);
323+
324+
IMGUI_NODE_EDITOR_API void Flow(LinkId linkId, FlowDirection direction = FlowDirection::Forward);
325+
326+
IMGUI_NODE_EDITOR_API bool BeginCreate(const ImVec4& color = ImVec4(1, 1, 1, 1), float thickness = 1.0f);
327+
IMGUI_NODE_EDITOR_API bool QueryNewLink(PinId* startId, PinId* endId);
328+
IMGUI_NODE_EDITOR_API bool QueryNewLink(PinId* startId, PinId* endId, const ImVec4& color, float thickness = 1.0f);
329+
IMGUI_NODE_EDITOR_API bool QueryNewNode(PinId* pinId);
330+
IMGUI_NODE_EDITOR_API bool QueryNewNode(PinId* pinId, const ImVec4& color, float thickness = 1.0f);
331+
IMGUI_NODE_EDITOR_API bool AcceptNewItem();
332+
IMGUI_NODE_EDITOR_API bool AcceptNewItem(const ImVec4& color, float thickness = 1.0f);
333+
IMGUI_NODE_EDITOR_API void RejectNewItem();
334+
IMGUI_NODE_EDITOR_API void RejectNewItem(const ImVec4& color, float thickness = 1.0f);
335+
IMGUI_NODE_EDITOR_API void EndCreate();
336+
337+
IMGUI_NODE_EDITOR_API bool BeginDelete();
338+
IMGUI_NODE_EDITOR_API bool QueryDeletedLink(LinkId* linkId, PinId* startId = nullptr, PinId* endId = nullptr);
339+
IMGUI_NODE_EDITOR_API bool QueryDeletedNode(NodeId* nodeId);
340+
IMGUI_NODE_EDITOR_API bool AcceptDeletedItem(bool deleteDependencies = true);
341+
IMGUI_NODE_EDITOR_API void RejectDeletedItem();
342+
IMGUI_NODE_EDITOR_API void EndDelete();
343+
344+
IMGUI_NODE_EDITOR_API void SetNodePosition(NodeId nodeId, const ImVec2& editorPosition);
345+
IMGUI_NODE_EDITOR_API void SetGroupSize(NodeId nodeId, const ImVec2& size);
346+
IMGUI_NODE_EDITOR_API ImVec2 GetNodePosition(NodeId nodeId);
347+
IMGUI_NODE_EDITOR_API ImVec2 GetNodeSize(NodeId nodeId);
348+
IMGUI_NODE_EDITOR_API void CenterNodeOnScreen(NodeId nodeId);
349+
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
350+
IMGUI_NODE_EDITOR_API float GetNodeZPosition(NodeId nodeId); // Returns node z position, defaults is 0.0f
351+
352+
IMGUI_NODE_EDITOR_API void RestoreNodeState(NodeId nodeId);
353+
354+
IMGUI_NODE_EDITOR_API void Suspend();
355+
IMGUI_NODE_EDITOR_API void Resume();
356+
IMGUI_NODE_EDITOR_API bool IsSuspended();
357+
358+
IMGUI_NODE_EDITOR_API bool IsActive();
359+
360+
IMGUI_NODE_EDITOR_API bool HasSelectionChanged();
361+
IMGUI_NODE_EDITOR_API int GetSelectedObjectCount();
362+
IMGUI_NODE_EDITOR_API int GetSelectedNodes(NodeId* nodes, int size);
363+
IMGUI_NODE_EDITOR_API int GetSelectedLinks(LinkId* links, int size);
364+
IMGUI_NODE_EDITOR_API bool IsNodeSelected(NodeId nodeId);
365+
IMGUI_NODE_EDITOR_API bool IsLinkSelected(LinkId linkId);
366+
IMGUI_NODE_EDITOR_API void ClearSelection();
367+
IMGUI_NODE_EDITOR_API void SelectNode(NodeId nodeId, bool append = false);
368+
IMGUI_NODE_EDITOR_API void SelectLink(LinkId linkId, bool append = false);
369+
IMGUI_NODE_EDITOR_API void DeselectNode(NodeId nodeId);
370+
IMGUI_NODE_EDITOR_API void DeselectLink(LinkId linkId);
371+
372+
IMGUI_NODE_EDITOR_API bool DeleteNode(NodeId nodeId);
373+
IMGUI_NODE_EDITOR_API bool DeleteLink(LinkId linkId);
374+
375+
IMGUI_NODE_EDITOR_API bool HasAnyLinks(NodeId nodeId); // Returns true if node has any link connected
376+
IMGUI_NODE_EDITOR_API bool HasAnyLinks(PinId pinId); // Return true if pin has any link connected
377+
IMGUI_NODE_EDITOR_API int BreakLinks(NodeId nodeId); // Break all links connected to this node
378+
IMGUI_NODE_EDITOR_API int BreakLinks(PinId pinId); // Break all links connected to this pin
379+
380+
IMGUI_NODE_EDITOR_API void NavigateToContent(float duration = -1);
381+
IMGUI_NODE_EDITOR_API void NavigateToSelection(bool zoomIn = false, float duration = -1);
382+
383+
IMGUI_NODE_EDITOR_API bool ShowNodeContextMenu(NodeId* nodeId);
384+
IMGUI_NODE_EDITOR_API bool ShowPinContextMenu(PinId* pinId);
385+
IMGUI_NODE_EDITOR_API bool ShowLinkContextMenu(LinkId* linkId);
386+
IMGUI_NODE_EDITOR_API bool ShowBackgroundContextMenu();
387+
388+
IMGUI_NODE_EDITOR_API void EnableShortcuts(bool enable);
389+
IMGUI_NODE_EDITOR_API bool AreShortcutsEnabled();
390+
391+
IMGUI_NODE_EDITOR_API bool BeginShortcut();
392+
IMGUI_NODE_EDITOR_API bool AcceptCut();
393+
IMGUI_NODE_EDITOR_API bool AcceptCopy();
394+
IMGUI_NODE_EDITOR_API bool AcceptPaste();
395+
IMGUI_NODE_EDITOR_API bool AcceptDuplicate();
396+
IMGUI_NODE_EDITOR_API bool AcceptCreateNode();
397+
IMGUI_NODE_EDITOR_API int GetActionContextSize();
398+
IMGUI_NODE_EDITOR_API int GetActionContextNodes(NodeId* nodes, int size);
399+
IMGUI_NODE_EDITOR_API int GetActionContextLinks(LinkId* links, int size);
400+
IMGUI_NODE_EDITOR_API void EndShortcut();
401+
402+
IMGUI_NODE_EDITOR_API float GetCurrentZoom();
403+
404+
IMGUI_NODE_EDITOR_API NodeId GetHoveredNode();
405+
IMGUI_NODE_EDITOR_API PinId GetHoveredPin();
406+
IMGUI_NODE_EDITOR_API LinkId GetHoveredLink();
407+
IMGUI_NODE_EDITOR_API NodeId GetDoubleClickedNode();
408+
IMGUI_NODE_EDITOR_API PinId GetDoubleClickedPin();
409+
IMGUI_NODE_EDITOR_API LinkId GetDoubleClickedLink();
410+
IMGUI_NODE_EDITOR_API bool IsBackgroundClicked();
411+
IMGUI_NODE_EDITOR_API bool IsBackgroundDoubleClicked();
412+
IMGUI_NODE_EDITOR_API ImGuiMouseButton GetBackgroundClickButtonIndex(); // -1 if none
413+
IMGUI_NODE_EDITOR_API ImGuiMouseButton GetBackgroundDoubleClickButtonIndex(); // -1 if none
414+
415+
IMGUI_NODE_EDITOR_API bool GetLinkPins(LinkId linkId, PinId* startPinId, PinId* endPinId); // pass nullptr if particular pin do not interest you
416+
417+
IMGUI_NODE_EDITOR_API bool PinHadAnyLinks(PinId pinId);
418+
419+
IMGUI_NODE_EDITOR_API ImVec2 GetScreenSize();
420+
IMGUI_NODE_EDITOR_API ImVec2 ScreenToCanvas(const ImVec2& pos);
421+
IMGUI_NODE_EDITOR_API ImVec2 CanvasToScreen(const ImVec2& pos);
422+
423+
IMGUI_NODE_EDITOR_API int GetNodeCount(); // Returns number of submitted nodes since Begin() call
424+
IMGUI_NODE_EDITOR_API int GetOrderedNodeIds(NodeId* nodes, int size); // Fills an array with node id's in order they're drawn; up to 'size` elements are set. Returns actual size of filled id's.
419425

420426

421427

0 commit comments

Comments
 (0)