Nelarius / imnodes

A small, dependency-free node editor for dear imgui
MIT License
2.01k stars 244 forks source link

allow context creation independently from imgui #79

Closed benmkw closed 3 years ago

benmkw commented 3 years ago

In my rust wrapper, combined with the simple api of webgpu I have the following problem:

The simple API initialises the drawing backend (webgpu) and imgui for the user and calls a user provided function on each iteration to draw the UI. This function is called with a user defined struct which can contain data such as the imnodes/ implot context.

Implot allows creation of this context before the imgui context is created as can be seen here. This is necessary in this design of the API because the user has to create the struct and pass it to the API together with the function which draws the UI.

Imnodes calls GetIO during context creation which assumes the imgui context is already created and it is thus not possible to use with this api as the user has to pass the imnodes context into the api which then internally createds the imgui context https://github.com/Nelarius/imnodes/blob/595972941054e9fa453f5a6d5590a51c9e1c98a4/imnodes.cpp#L1966-L1967

I'm wondering if it would be possible to move these GetIO calls to a later stage without impacting performance or usability and thus making context creation for imnodes independent from imgui, like possible with implot.

Nelarius commented 3 years ago

Hi @benmkw ! Sorry for taking so long to get around to this 😬

A pr was recently merged which allowed the context to be passed in, much like is done in ImGui and ImPlot: https://github.com/Nelarius/imnodes/pull/89

However, I think this change alone doesn't solve your problem, because imnodes::CreateContext still calls ImGui::GetIO() during context creation. That function call could be moved out.

Nelarius commented 3 years ago

The GetIO() calls were removed from imnodes::CreateContext in 43e7e

benmkw commented 3 years ago

thanks for looking into this :)