Pop Ups On TreeNodes

Hello guys, good evening.
I’m kinda new to ImGui so this may be a easy question but i’m beating my head up to solve it and ain’t having any progress.
That said, i’d like firstly to contextualize my problem.
I’m writing a program that has a lot of scene objects that are drawn into a hierarchy as TreeNodes and what i’d like to is to to rightClick a node and open a popup with some basic options such as delete, newchildren, change mesh and etc.
Here’s how my code is now, without any treatment in that regard.

P2::drawHierarchyWindow(cg::Scene* node, cg::SceneNode* current, ImGuiTreeNodeFlags flag) {
if (node->root->filhos.size() > 0) {
auto open = ImGui::TreeNodeEx(node, _current == node ? flag | ImGuiTreeNodeFlags_Selected : flag, node->name());

	// Update current node.
	if (ImGui::IsItemClicked(0))
		_current = node;
            // Catch the right click
	if (ImGui::IsItemClicked(1)) {
            // Create a new popup
		if (ImGui::OpenPopupOnItemClick())
		{
			if (ImGui::Selectable("Test"))
			{
			}
			ImGui::EndPopup();
		}
	}
	
	setDragAndDropTarget(node->root);

	if (open) {
		for (auto &c : node->root->filhos) {
			drawHierarchyWindow(c, _current, flag);
		}
		ImGui::TreePop();			
	}
}
else {
	// If nodes hasn children
	flag |= ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen;
	ImGui::TreeNodeEx(node, _current == node ? flag | ImGuiTreeNodeFlags_Selected : flag, node->name());

	// Update current if node was clicked
	if (ImGui::IsItemClicked())
		_current = node;
}

}

Well, the code above isn’t working for me as i right click the node and it doesn’t create the pop up.
Doen any of you knows the reason or have any suggestions ?

Thanks in advance, guys and sorry for any lack of education.
I’m new to ImGui and to English as well :smiley:

  1. OpenPopupOnItemClick() mark the popup as open, you still need to use a BeginPopup/EndPopup block to fill the popup. BeginPopup will only return true when the popup marked with the given identifier is open.

Refer to the imgui_demo.cpp code and see how OpenPopup is used (OpenPopupOnItemClick works the same).

I have added some extra comments in it now:

  1. Using if (ImGui::IsItemClicked(1)) + OpenPopupOnItemClick() together is contradictory for one reason that is not obvious (OpenPopupOnItemClick actually test for mouse button release to behave like standard popups, so IsItemClicked+OpenPopupOnItemClick together will never pass… just use OpenPopupOnItemClick)