ImGuiNET / ImGui.NET

An ImGui wrapper for .NET.
MIT License
1.8k stars 296 forks source link

Node Editor (Extensions?) #201

Open rootCBR opened 3 years ago

rootCBR commented 3 years ago

I'm currently using ImGui.NET, but for what I'm looking to build, I'd need something like this.

Realistically, as someone whose experience doesn't go much further than C#, what are my options to get something like Imnodes working in C# with ImGui.NET?

Can I hope for this extension to be wrapped by someone? Where would I start if I wanted to do it myself? Or in case I'd be better off building a node editor myself using Imgui, how would I go about that?

mellinoe commented 3 years ago

Unless you are intimately familiar with the low-level drawing functionality in ImGui, then your best bet is to try and port the ImNode implementation from C++ to C#. In general, the languages are similar enough that you can copy-paste parts of the code into C# and fix up the syntax little by little. I've ported several other ImGui extensions this way. It can be a little bit slow and painstaking, depending on how many "weird" C++ features the code uses.

One snag you will hit here is that ImNodes uses at least a couple of things from the imgui_internal header, which isn't wrapped by ImGui.NET. You'd have to replace those or inline the code from the header manually.

enquel commented 3 years ago

@rootCBR I'm afraid you need to write it on your own, as I did (cannot share it though). There are many useful snippets on how to approach that in ImGUI, and a very basic node editor example by the creator of that UI - basically you can start off by modifying it as you need.

rootCBR commented 3 years ago

The author of cimgui has now created https://github.com/cimgui/cimnodes. Is that of any help? I'd actually attempt to try and use it, but I'm afraid I'd need a step-by-step tutorial for that.

mellinoe commented 3 years ago

The generator in this repo could theoretically be pointed at that repo and generate bindings automatically. However, the native library itself would likely need to be compiled in a specific way to be used in a PInvoke from C#, and that part is uncharted territory. My guess is that the cimnodes DLL/so/dylib would need to be dynamically linked with cimgui.dll/so/dylib, and care would have to be taken that both DLLs are compatible.

enquel commented 3 years ago

@rootCBR I highly recommend the old snippet I mentioned - it will help you get started. I know nothing about cimnodes. Your best choice time-wise is to create the most simple node editor (no visual layer; no caching; no flow control and no state machines). Funny thing is that it is actually faster to implement a universal stateless node editor, where nested calls trace back from your "final value" to the source (nodes as classes sharing common base; functionality added inside overriden method called say "GetValue"). If you plan to have some heavy computations, you will eventually need flow control and caching.

rlalance commented 3 years ago

I personally think that the extensions found online shouldn't be the goal of ImGui.net. Just the fact we can find the basic support for ImGui in the .net ecosystem is amazing.

Any extra/extensions should be implemented by 3rd parties so the focus can be kept on the base implementation :)

My 2 cents :)