imgui-node-editor
imgui-node-editor copied to clipboard
ed::PinId.Get() always returns 0
I've created a Pin
struct that contains an ed::PinId
. I'm storing Pin
s in an unordered_map<int, Pin>
, mapping int
to Pin
. (Originally, I tried to create a unordered_map<ed::PinId, Pin>
but it complained that the Hash function for ed::PinId
was deleted.)
When I call QueryNewLink()
a new link and get a PinI
d, I try to get its associated Pin
from the map by calling theMap[pinId.Get()]
however, Get()
always returns 0, no matter what the PinId
was set to.
Am I doing something wrong here?
You can define your own hash function for ed::PinId
:
namespace std
{
template<> struct hash<ed::PinId>
{
std::size_t operator()(const ed::PinId& s) const noexcept
{
return static_cast<std::size_t>(s.Get());
}
};
}
Please note that 0 is used to indicate invalid id.
QueryNewLink(PinId* startId, PinId* endId)
returns true when editor is in the process of creating new link. At first only one id will be valid, until you drag link to another pin. Then you will get two valid ids. When that happens you can call AcceptNewItem
to indicate connection make sense.
Did you saw this example? https://github.com/thedmd/imgui-node-editor/blob/2ca25cf3aaf719a435f15dda1758da481de2ef56/Examples/BasicInteraction/BasicInteraction.cpp#L131-L161