Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Button in the same line as a TreeWindow header #2396

Closed
Rush2k opened this issue Mar 3, 2019 · 2 comments
Closed

Button in the same line as a TreeWindow header #2396

Rush2k opened this issue Mar 3, 2019 · 2 comments
Labels
tree tree nodes

Comments

@Rush2k
Copy link

Rush2k commented Mar 3, 2019

Hi,

I'm trying to put a button in the same line as the header of the tree window (eg code below), and I am having issues getting the button to activate reliably. By that I mean; it either needs a lot of clicks to trigger, or it only opens when the tree window is open.

object_treenode

Here's a minimal example code of what I'm doing:
ImGui::AlignTextToFramePadding();
bool treeopen = ImGui::TreeNode("TreeTest");
ImGui::SameLine();
if (ImGui::Button("+")) ImGui::OpenPopup("ElementList");
if (ImGui::IsItemHovered()) ImGui::SetTooltip("new element");
if (ImGui::BeginPopup("ElementList")) {
ImGui::MenuItem("element 1");
ImGui::EndPopup();
}
if (treeopen)
ImGui::TreePop();

I tried this instead:
bool treeopen = ImGui::TreeNodeEx("TreeTest", ImGuiButtonFlags_AllowItemOverlap);

But it actually made opening the tree harder through the arrow.

What's the preferred setup to make this work?

@ocornut
Copy link
Owner

ocornut commented Mar 4, 2019

This works for me:

ImGui::AlignTextToFramePadding();
bool treeopen = ImGui::TreeNodeEx("TreeTest", ImGuiTreeNodeFlags_AllowItemOverlap);
ImGui::SameLine();
if (ImGui::Button("+")) ImGui::OpenPopup("ElementList");
if (ImGui::IsItemHovered()) ImGui::SetTooltip("new element");
if (ImGui::BeginPopup("ElementList")) 
{
    ImGui::MenuItem("element 1");
    ImGui::MenuItem("element 2");
    ImGui::EndPopup();
}
if (treeopen)
{
    ImGui::Text("Tree contents");
    ImGui::TreePop();
}

You said:
"I tried this instead:
bool treeopen = ImGui::TreeNodeEx("TreeTest", ImGuiButtonFlags_AllowItemOverlap);"

I think you meant ImGuiTreeNodeFlags_AllowItemOverlap and NOT ImGuiButtonFlags_AllowItemOverlap here.

You may otherwise have another issue in your real app code where maybe the identifier of the + buttons are conflicting with each others (if you don't use PushID/PopID).

@ocornut ocornut added the tree tree nodes label Mar 4, 2019
@Rush2k
Copy link
Author

Rush2k commented Mar 4, 2019

Thank you! It was a combination of ID issues and incorrect flags.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tree tree nodes
Projects
None yet
Development

No branches or pull requests

2 participants