I'm trying to make something like the hierarchy in Unity where I see all of the Objects, can click on them, right click and delete them or do stuff like this. I'm using ImGui as UI Library and my code looks like this:
for (Object obj : SceneView<>(*scene)) {
ImGui::PushID(obj.id);
std::string& name = obj.name->name;
ImGuiTreeNodeFlags flags = ((selectedObj == obj) ? ImGuiTreeNodeFlags_Selected : 0) | ImGuiTreeNodeFlags_OpenOnArrow;
bool opened = ImGui::TreeNodeEx((void*) (uint64_t) (uint32_t) obj, flags, name.c_str());
if (ImGui::IsItemClicked()) { selectedObj = obj; }
if (ImGui::BeginPopupContextItem(0)) {
if(ImGui::MenuItem("Delete")) { // }
ImGui::EndPopup();
}
ImGui::PopID();
}
It works, It shows all of the objects but when I right click on any of the objects, it shows the popup but for some reason the Delete option is the amount of objects in scene times there. and if I instead change the name of the option from 'Delete' to the name of the object, it shows names of all of the objects in the scene, I have a very similar code elsewhere on the project, and it is literally the exact same. I tried to remove the PushID and PopID, tried to change it so the id is the name of the object, that works but if there are objects with the same name it shows the option again how many times the object with the name is there. Any idea what might be causing this ? tried to look it up but found nothing.