thedmd / imgui-node-editor

Node Editor built using Dear ImGui
MIT License
3.73k stars 551 forks source link

Some patches for a smoother integration of imgui-node-editor and imgui #310

Open pthom opened 1 month ago

pthom commented 1 month ago

Hello @thedmd,

Many thanks for your wonderful library!

During the development of Dear ImGui Bundle, I applied a series of patches to imgui-node-editor and imgui, to make their integration smoother. Since they require modifications on both imgui and imgui-node-editor, proposing a PR is not straightforward.

However, since they might be useful, I took the time to group them here in this issue, in the hope of being helpful.

Demo

Video demo:

https://github.com/user-attachments/assets/6f3f783b-88d4-43ee-b9ef-673b3c8c94aa

You can also test it live on this webasm demo

Handle node width in separators:

Thanks to this patch, ImGui::SeparatorText(), ImGui::Separator(), and ImGui::CollapsingHeader() can use the actual node width. It was proposed here

Handle Popups:

@lukaasm proposed a patch here, which solves many issues with popups in the node editor (by automatically suspending the canvas, and placing popups correctly).

Example implementation for this patch:

With this patch, ImGui::ColorEdit, ImGui::Begin/EndCombo will work correctly inside a node.

Warn users if using BeginChild / EndChild:

imgui-node-editor remains incompatible with ImGui::BeginChild() and ImGui::EndChild().

Below is the list of ImGui widgets which are concerned (because they use BeginChild/EndChild):

We can warn the developer whenever they use these functions inside a node:

Handle InputTextMultiline

By default InputTextMultiline uses a child window, which is not compatible with the node editor. An additional patch adapts its behavior, by showing a preview within a single line text input, followed by a "..." button which triggers a popup with the full text edition.

To apply this, two patches are required: