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

CollapsingHeader - close header #579

Closed
KozmoK opened this issue Apr 7, 2016 · 2 comments
Closed

CollapsingHeader - close header #579

KozmoK opened this issue Apr 7, 2016 · 2 comments

Comments

@KozmoK
Copy link

KozmoK commented Apr 7, 2016

Is it possible to close a Collapsing header section?

You have the ability for windows to collapse in this function:

IMGUI_API void SetWindowCollapsed(const char* name, bool collapsed, ImGuiSetCond cond = 0);

It would be nice to see a

IMGUI_API void          SetCollapsedHeader(const char* name, bool collapsed, ImGuiSetCond cond = 0);

The issue:

I would like to control the which headers are open, as to not get the menu scrolling far down.
In my situation they only need to be in one section at at time.

@ocornut
Copy link
Owner

ocornut commented Apr 7, 2016

Hello,

CollapsingHeader are actually using part of the TreeNode code under the hood so this is working:

if (ImGui::Button("Open"))
    ImGui::SetNextTreeNodeOpened(true);
if (ImGui::Button("Close"))
    ImGui::SetNextTreeNodeOpened(false);
if (ImGui::CollapsingHeader("Help"))
{

It should probably be clarified.

You can also directly access the storage map, e.g.

if (ImGui::Button("Open2"))
    ImGui::GetStateStorage()->SetInt(ImGui::GetID("Help"), 1);
if (ImGui::Button("Close2"))
    ImGui::GetStateStorage()->SetInt(ImGui::GetID("Help"), 0);

if (ImGui::CollapsingHeader("Help"))
{

You might also use the SetStateStorage GetStateStorage facility to provide your own storage which you can clear independently.

If you need custom behavior, you can copy and strip CollapsingHeader out of most of the code you don't need.. at the end of the day it is merely a glorified button accessing a boolean value from storage, but it may make more sense to provide the state yourself. Lots of the code in there you don't need if you write a customized version (handling tree nodes/header modes, calling TreeNodeBehaviorIsOpened to query from storage and honor calls to SetNextTreeNode functions, handling of Log).

ocornut added a commit that referenced this issue May 1, 2016
…eters version. Refactored code into TreeNodeBehavior. (#600)

New flag and declaration makes uses of SetNextTreeNode() functions on
collapsing header more obvious as well (#579).
@ocornut
Copy link
Owner

ocornut commented May 1, 2016

Just committed a bunch of TreeNode/CollapsingHeader related change, and the ImGuiTreeNodeFlags type along with the location and code of CollapsingHeader should make it much more obvious now that CollapsingHeader is just a helper calling TreeNode, and therefore that SetNextTreeNode* functions are functional. Closing this!

@ocornut ocornut closed this as completed May 1, 2016
ocornut added a commit that referenced this issue May 2, 2016
…tNextTreeNodeOpened() to SetNextTreeNodeOpen(). (#625, #579)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants