imgui-node-editor icon indicating copy to clipboard operation
imgui-node-editor copied to clipboard

Allow a context to defined in the ImGui config header.

Open bmqn opened this issue 1 year ago • 0 comments

I've found it useful to have control over the modifiers and/or type of the internal context s_Editor, which is defined in imgui_node_editor_api.cpp.

In my case, it's important to make the context thread_local for an application that has many instances of the the node editor all running in different threads of the same process, otherwise, the static context is shared and things get ugly.

I propose that the standard ImGui approach is adpoted, whereby defining your own GImGuiNodeEditor in your standard ImGui config header will enable you to override the context.

With this, to make the context thread_local we can define

namespace ax {
namespace NodeEditor {
namespace Detail {
struct EditorContext;
}}}
extern thread_local ax::NodeEditor::Detail::EditorContext *g_MyImGuiNodeEditor;
#define GImGuiNodeEditor g_MyImGuiNodeEditor

in our ImGui config header with the extern global referring to some instance of ax::NodeEditor::Detail::EditorContext somewhere in the program.

bmqn avatar Jun 16 '24 13:06 bmqn