Nelarius / imnodes

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

Option to render nodes over top of links. #56

Closed jonathan2222 closed 3 years ago

jonathan2222 commented 3 years ago

When rendering a complex node graph, the links will often be in the way of editing the nodes. If there was an option to render the links under everything else it would fix many problems I am having when changing node attributes.

I know this might be too hard to implement because of the immediate nature of imgui.

Nelarius commented 3 years ago

Hi @jonathan2222 ! It should be doable, just requires some trickery with the draw channels. I'll see what I can do once I make some progress on one of the previous issues 👍

If you're itching to try it out, I think the following change inside the EndNodeEditor function should work:

diff --git a/imnodes.cpp b/imnodes.cpp
index 286abc6..6535738 100644
--- a/imnodes.cpp
+++ b/imnodes.cpp
@@ -2107,7 +2107,7 @@ void EndNodeEditor()
     object_pool_update(editor.pins);

     draw_list_sort_channels_by_depth(editor.node_depth_order);
-    draw_list_merge_channels();
+    g.canvas_draw_list->ChannelsSetCurrent(0);

     for (int link_idx = 0; link_idx < editor.links.pool.size(); ++link_idx)
     {
@@ -2117,6 +2117,8 @@ void EndNodeEditor()
         }
     }

+    g.canvas_draw_list->ChannelsMerge();
+
     // After the links have been rendered, the link pool can be updated as well.
     object_pool_update(editor.links);

I'm going to have to do some more testing on my end though and clean up the code a bit!

jonathan2222 commented 3 years ago

Hi @Nelarius! Thank you for the fast reply!

That change inside the EndNodeEditor function worked really nice, the only problem is that I can still interact with the links when hovering over the nodes. I will use this for the time being and wait for the update. I really appreciate the work you have put into this, thank you! 👌

Nelarius commented 3 years ago

@jonathan2222 I pushed the change in 8ecdd39. Added some additional logic to inhibit link interaction when overlapped with a node. 🙂