You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there a way to get to the state of a tree node and force it to open?
I am implementing a simple file explorer in ImGui (think Unity Project Widget). When I double click on a folder in the file view I need to change the state of the directory tree. What is the recommended way to do this? ImGui::SetNextItemOpen() does not help here. I also would very much prefer to NOT maintain my own tree state as this seems redundant and error prone.
You are not specifying why ImGui::SetNextItemOpen does not help there.
You can use GetStateStorage()->GetInt(ImGuiID key, int default_val = 0) with the ID of the tree node or correspondingly the SetInt() function.
The only thing is that this storage will ignore the SetNextItemOpen() data and the ImGuiTreeNodeFlags_DefaultOpen flag (the later correspond to altering the default value of GetInt() above.
You can use ImGui::TreeNodeBehaviorIsOpen() from imgui_internal.h as a getter to handle those two cases if you need them. Also see how the function is implemented as a reference.
PS: Please fill in the request issue template when opening new issues. Thank you.
Activity
ocornut commentedon Jan 2, 2020
Hello,
You are not specifying why
ImGui::SetNextItemOpendoes not help there.You can use
GetStateStorage()->GetInt(ImGuiID key, int default_val = 0)with the ID of the tree node or correspondingly theSetInt()function.The only thing is that this storage will ignore the
SetNextItemOpen()data and theImGuiTreeNodeFlags_DefaultOpenflag (the later correspond to altering the default value ofGetInt()above.You can use
ImGui::TreeNodeBehaviorIsOpen()fromimgui_internal.has a getter to handle those two cases if you need them. Also see how the function is implemented as a reference.PS: Please fill in the request issue template when opening new issues. Thank you.
dgregorius commentedon Jan 2, 2020
Thanks, Omar. I thought about this more and I can indeed use
ImGui::SetNextItemOpen.Internals: Added TreeNodeIsOpen() to facilitate discoverability. (#7553…
Internals: rename recently added TreeNodeIsOpen() -> TreeNodeGetOpen(…
Ocornut master (24/07) (#4)
Commented out obsolete internals's SetItemUsingMouseWheel() (#2891), …
TreeNode: moved TreeNodeGetOpen() helper to public API. (#3823, #9251, …
TreeNode: moved TreeNodeGetOpen() helper to public API. (ocornut#3823, …
TreeNode: fixed duplicate TreeNodeGetOpen() declaration. (#3823, #9251,