Nelarius / imnodes

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

Internal link refactor #155

Open Nelarius opened 2 years ago

Nelarius commented 2 years ago

This pr contributes three things:

@Auburn, if you are still around, wondering if you could give this branch a spin. You’ve been very good at spotting broken interaction code, and this branch rewrites everything 😓 I will leave this pr open for a while while I continue my own tests.

More details about each change below.

Move links from the object pool to a vector

This change boils down to

// in `ImNodesEditorContext`
- ImObjectPool<ImLinkData> Links;

// in `ImNodesContext`
+ ImVector<ImLink> Links;

When BeginNodeEditor is called, the vector is resized to zero. Links are appended to the vector in ImNodes::Link(). In EndNodeEditor, we render them. Links are now truly immediate-mode and really simple.

Subtle bugs occurring on id reuse, such as this https://github.com/Nelarius/imnodes/issues/91 no longer apply to links. The goal is to apply this change for nodes and pins as well.

Rebuild link, node, pin interaction

Remove the EnableLinkDetachWithDragClick attribute flag

Test checklist

Auburn commented 2 years ago

Hi, I gave this a quick test run, these are the things I noted:

Nelarius commented 2 years ago

Thanks for the feedback, really appreciate it! I will definitely look into adding EnableLinkDetachWithDragClick back, I had a (wrong) hunch that it wasn't used much.

IsLinkedCreated works slightly differently now

Yeah, that's a good point. ImNodes::Link() is really simple now and just stores the ids in the order received. The exact behaviour of the IsLinkStarted function could be specified.

juliusl commented 1 year ago

@Nelarius Hey there, If I'm reading this PR right, it looks like we'll be able to customize the bezier curve's path from pin-pin? For example, if we have an output pin that needs to travel to an input pin to the left of it, we can make the curve arc upwards instead of connect in a straight line?

Auburn commented 1 year ago

Hey @Nelarius is there any further progress on this update? Getting this and zooming functionality would be a huge upgrade for this library.

Without zooming support I'll probably have to switch to a different node library which would be a shame. I have locally merged latest onto the zooming PR and got that working. Also attempted to fix the mouse positioning bugs but not had any success.

Any input you have on this would be great! Thanks again