Nelarius / imnodes

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

Allow User Defined Callbacks and Custom Header like ImGui #115

Closed kfields closed 2 years ago

kfields commented 2 years ago

Hi! I'm wrapping ImNodes with pybind11 and it's going pretty well. Right now I'm trying to wrap MiniMap. I just need a way wrap callbacks with py::function

If you would allow user defined callbacks like ImGui does that would be great. Also, It would be nice to have a custom include header like ImGui does also, for instance in imnodes.h you would have to add:

#ifdef IMNODES_USER_CONFIG
#include IMNODES_USER_CONFIG
#endif

Wrap callbacks in #ifndef's (BTW, I noticed you have ImNodesMiniMapNodeHoveringCallback defined in both imnodes.h and imnodes_internal.h. Looks like an oversight)

#ifndef ImNodesMiniMapNodeHoveringCallback
typedef void (*ImNodesMiniMapNodeHoveringCallback)(int, void*);
#endif

And then in my 'imnodesconfig.h'

#define ImNodesMiniMapNodeHoveringCallback py::function

At least that's the plan. I was able to do this with ImGui::AddCallback to do custom drawing within python so it is doable. Nice job on the library! Thanks!

Nelarius commented 2 years ago

Hi @kfields !

Adding the ability to define ImNodesMiniMapNodeHoveringCallback in a user-provided header is something we can do. 👍 I'm aware of a few other binding projects, so this proposal would probably benefit multiple projects.

I would accept PRs for this if you would like to submit the functionality which works on your end.

(BTW, I noticed you have ImNodesMiniMapNodeHoveringCallback defined in both imnodes.h and imnodes_internal.h. Looks like an oversight)

Yep, it is! Thanks for pointing that out, I'll get it fixed.

kfields commented 2 years ago

That makes sense. Maybe I can identify other useful stuff to make user customizable. I'll try to get a PR together over the weekend. Thanks!

kfields commented 2 years ago

Thanks for the merge! Issue closed.