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

How to use TreeNodeBehaviorIsOpen? #4814

Closed
Stanlyhalo opened this issue Dec 18, 2021 · 2 comments
Closed

How to use TreeNodeBehaviorIsOpen? #4814

Stanlyhalo opened this issue Dec 18, 2021 · 2 comments
Labels
tree tree nodes

Comments

@Stanlyhalo
Copy link

Version: 1.83
Branch: docking

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_glfw.cpp + imgui_impl_vulkan.cpp
Compiler: vs2022
Operating System: win10

My Issue/Question:

I'm trying to create a custom container, a sort of box, similar to the collapsing header, however, I wanted to try to utilize ImGui::TreeNodeBehaviorIsOpen to store the bool value for checking whether it's opened or not. However, it always returns false except for when I click, than returns back to being false.

ImGuiID __id = window->GetID(std::string("###MY_COLLAPSING_CONTAINER_" + s).c_str());
bool is_open = ImGui::TreeNodeBehaviorIsOpen(__id, 0);

// *** other code

if (ImGui::Button(std::string("###MY_COLLAPSING_CONTAINER_BTN_" + s).c_str())) (is_open == false) ? is_open = true : is_open = false;

If you're wondering, the s variable being used, is just an id from a class I have, it doesn't change.

@Stanlyhalo
Copy link
Author

I'm still trying to figure out how the CollapsingHeader method utilizes it, but when I attempt to do the same, it just doesn't work, it only works for the frame that I click it, than it goes back to being false.

@ocornut ocornut added the tree tree nodes label Dec 20, 2021
@ocornut
Copy link
Owner

ocornut commented Dec 20, 2021

only works for the frame that I click it, than it goes back to being false.

Well you are not writing any modified value back, how would you expect it to work.

TreeNode does:

if (toggled)
{
    is_open = !is_open;
    window->DC.StateStorage->SetInt(id, is_open);
}

@ocornut ocornut closed this as completed Jan 4, 2022
ocornut added a commit that referenced this issue Oct 15, 2024
…TreeNodeBehaviorIsOpen() (#4814, #5423, #282, #2958, #924)

+ Removed obsolete header checks for IMGUI_DISABLE_METRICS_WINDOW.
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