Open dgm3333 opened 9 months ago
This library provides you a canvas to draw ImGui nodes, it doesn't teach you how to serialize/deserialize data. You should implement that on your own, because everyone's node/graph structure is different and thus impossible to come up with a generic solution.
If you're making examples then showing how the example can be integrated into a pre-existing imgui app would be good - turns out to be only a handful of lines of code but it took me hours to figure out what they were.
The following uses the blueprint example and layouts (which seems to be a drop-in replacement for ImGui My existing app was built on the imgui docking branch so although there appears to be absolutely no explanation of what each of the branches are for I picked this one (because it mentioned docking...) https://github.com/thedmd/imgui/tree/feature/docking-layout-external
Adding to an existing Imgui app
This should replace the main() function in the blueprint example (admittedly flow isn't yet working but I think that is a bigger issue as it doesn't trigger with the z key either)
Enabling the Left Pane and fixing Save/Restore
Using my current code the left pane will crash (because there are no icons loaded) Changing to simple buttons fixes this with no loss of function. NB: The editor state (ie zoom and scroll) is saved between sessions. However blueprint hardcodes the node positions and these are not saved
Also NB the buttons are saving/restoring a temporary state - not saving to a file
To allow the leftpane to show you will need to alter the save code (approx line 800) to remove the dependence on icons and return to plain buttons. you may also have to add an adjustment to position it correctly (for me the buttons were drawn off the pane)
Saving / Loading to/from file
The code automatically saves very basic information about nodes and state to a json file in the working directory called "Blueprint.json". However I've no idea how to trigger this manually nor how to add other details (eg user edits of contents of nodes) to this file. commenting out the hardcoded positioning (approx line 530) does mean the hardcoded nodes are restored to their previous locations, but nodes previously added by the user are lost.
This is thus another vote for implementing examples of the state and node/link save/load functions into the side panel. (or at an absolute minimum documenting what the code is doing - admittedly this is my biggest frustration throughout this entire library not just about save/load).
I spent ages digging around the backend code trying to figure this out. But it definitely doesn't seem to be easy to figure out and having traced my way around what I think it does it seems to be neither intuitive nor comprehensive.
Perhaps blueprint2 could also be merged with main as the following posts suggests this has a better strategy? This was the most useful post I've found on the topic (but 3 years old there appears to have been no progress since then) https://github.com/thedmd/imgui-node-editor/issues/58
Incidentally this is a very basic initial load routine for importing a mermaid flow chart