Nelarius / imnodes

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

Allow the setting of user data #138

Open nfwGytautas opened 2 years ago

nfwGytautas commented 2 years ago

Hello, I have a suggestion for adding the ability to map internal ImNodes data with user defined objects. For example ImLinkData could have a void field called UserData, which one could set using `ImNodes::SetLinkUserData(iint id, void object)and then receive withvoid* ImNodes::GetLinkUserData(int id)`. This could be done for other data structures such as ImPinData, ImNodeData. This would allow the user to have his own object mapped to an imnodes id making working with the library easier.

The current workflow is rendering the entire graph, then checking for if (ImNodes::IsLinkDestroyed(&link_id)) then acquiring the object to it and performing actions with it. With this change one can just query the user pointer and then just cast it.