Nelarius / imnodes

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

Customizable ID type #169

Open JulesFouchy opened 1 year ago

JulesFouchy commented 1 year ago

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: