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

Dynamically closing CollaspingHeader #924

Closed
djones4487169 opened this issue Nov 30, 2016 · 10 comments
Closed

Dynamically closing CollaspingHeader #924

djones4487169 opened this issue Nov 30, 2016 · 10 comments
Labels
tree tree nodes

Comments

@djones4487169
Copy link

I have the following code snippet:

ImGui::Begin("Control Centre II", &ImGui_WindowOpened, ImVec2(0, 0), 0.5f, ImGuiWindowFlags_AlwaysUseWindowPadding | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings);
ImGui::SetWindowPos(ImVec2(1602, 2));
ImGui::SetWindowSize(ImVec2(right_menu_width, Display::GetScreenHeight() - 2));
if (ImGui::CollapsingHeader("Image Library", 0, true, true))
{
// Do stuff
}
ImGui::Checkbox("Show Grayscale", &show_grayscale_image);

How can I dynamically force the “Image Library” CollaspingHeader to close/open when I check the “Show Grayscale” checkbox?

@ocornut
Copy link
Owner

ocornut commented Nov 30, 2016

You can use SetNextTreeNodeOpen() for that, order that is an ordered primitive so you need to call it before CollapsingHeader() and therefore it is easier just to move your checkbox above it.

@djones4487169
Copy link
Author

Soory ocornut can you give me a quick code snippet example I have to have the checkbox after the CollaspingHeader on the GUI?

@ocornut
Copy link
Owner

ocornut commented Nov 30, 2016

Move the Checkbox() before CollapsingHeader()

if (CheckBox(...))
   SetNextTreeNodeOpen(...)

if (CollapsingHeader(...))
{
}

@djones4487169
Copy link
Author

Is it not possible to have the Checkbox() shown after the CollaspingHeader() and somehow get the same result as above? Can we access an id or something for that particular widget and change its state?

@ocornut
Copy link
Owner

ocornut commented Nov 30, 2016 via email

@ocornut
Copy link
Owner

ocornut commented Nov 30, 2016 via email

@djones4487169
Copy link
Author

Can you give me a code example of how to access the StateStorage if that would work please?

@pdoane
Copy link

pdoane commented Dec 1, 2016

Manipulating the state storage works and it can sometimes be a cleaner solution. With the checkbox after the header, it will happen on the next frame though. If that's acceptable, you can get the same behavior with SetNextTreeNodeOpen:

static bool changedValue;
if (changedValue)
{
   SetNextTreeNodeOpen(...);
   changedValue = false;
}

if (CollapsingHeader(...))
{
}

if (CheckBox(...))
   changedValue = true;

My preferred approach would be to allow the app to maintain the open state and pass in a bool* to ImGui. This would simplify dynamic manipulation and the existing entrypoints can continue to use the StateStorage mechanism.

@djones4487169
Copy link
Author

Yes, got it working. Thanks

@ocornut
Copy link
Owner

ocornut commented Dec 13, 2016

@pdoane

My preferred approach would be to allow the app to maintain the open state and pass in a bool* to ImGui. This would simplify dynamic manipulation and the existing entrypoints can continue to use the StateStorage mechanism.

I sort of agree this would be good.

  • The node stills needs a unique ID for its regular button behavior.

  • The Internal TreeNodeBehavior TreeNodeBehaviorIsOpen would probably need some rework and an extra optional bool* as those functions are designed to lazily add to the storage only when needed. Reworking those isn't so much of a problem. We also need to honor SetNextTreeNodeOpened() functions for completeness (which would set the bool).

  • However adding more public API however is a bigger problem.? We could be adding:

IMGUI_API bool TreeNodeEx(const char* str_id, bool* p_open, ImGuiTreeNodeFlags flags, const char* fmt, ...) IM_PRINTFARGS(3);
IMGUI_API bool TreeNodeEx(const void* ptr_id, bool* p_open, ImGuiTreeNodeFlags flags, const char* fmt, ...) IM_PRINTFARGS(3);
IMGUI_API bool TreeNodeExV(const char* str_id, bool* p_open, ImGuiTreeNodeFlags flags, const char* fmt, va_list args);
IMGUI_API bool TreeNodeExV(const void* ptr_id, bool* p_open, ImGuiTreeNodeFlags flags, const char* fmt, va_list args);

@ocornut ocornut added the tree tree nodes label Jun 15, 2018
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

3 participants