Skip to content

Set open state of tree node #2958

Closed
Closed

Description

@dgregorius

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.

Activity

  1. ocornut commented on Jan 2, 2020

    @ocornut
    Owner

    Hello,

    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.

  2. dgregorius commented on Jan 2, 2020

    @dgregorius
    Author

    Thanks, Omar. I thought about this more and I can indeed use ImGui::SetNextItemOpen.

  3. added a commit that references this issue on Jul 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    treetree nodes

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ 换网址