Hi 👋
In my application I have a use case where I use 128-bits UUIDs as IDs internally, and I would like to use these same IDs as Node and Link IDs when I use imnodes without having to truncate to int back and forth.
This is why I basically added using ID = int; to imnodes, and added the possibility to override that definition of ID inside "imnodes_config.h".
A user-defined "imnodes_config.h" would look like this:
// imnodes_config.h
#pragma once
#include <limits.h>
#include <string>
namespace IMNODES_NAMESPACE
{
using ID = int;
static constexpr ID INVALID_ID = INT_MIN;
inline void PushID(ID id) { ImGui::PushID(id); }
inline std::string IDToString(ID id) { return std::to_string(id); }
inline ID IDFromString(const std::string& str) { return std::stoi(str); }
} // namespace IMNODES_NAMESPACE
Changes
The two main (and maybe controversial) changes I hade to make are:
[ ] Having to copy-paste ImGuiStorage's implementation from Dear ImGui into imnodes just to change the type of the ID used to index into that storage. But this also has the benefit of removing the static_casts from int to ImGuiID that were all over imnodes' implementation.
[ ] Changing the implementation of NodeLineHandler() that is used during serialization of the editor state. We now use std::string manipulations instead of sscanf to read and write the ID to and from strings. That is because we don't know how complex the user ID might be, and we have to let them handle the conversions. Using std::string instead of char[] is the simplest.
Hi 👋 In my application I have a use case where I use 128-bits UUIDs as IDs internally, and I would like to use these same IDs as Node and Link IDs when I use imnodes without having to truncate to
int
back and forth.This is why I basically added
using ID = int;
to imnodes, and added the possibility to override that definition ofID
inside "imnodes_config.h".A user-defined "imnodes_config.h" would look like this:
Changes
The two main (and maybe controversial) changes I hade to make are:
ImGuiStorage
's implementation from Dear ImGui into imnodes just to change the type of the ID used to index into that storage. But this also has the benefit of removing thestatic_cast
s fromint
toImGuiID
that were all over imnodes' implementation.NodeLineHandler()
that is used during serialization of the editor state. We now usestd::string
manipulations instead ofsscanf
to read and write theID
to and from strings. That is because we don't know how complex the user ID might be, and we have to let them handle the conversions. Usingstd::string
instead ofchar[]
is the simplest.