| 6682 | } |
| 6683 | |
| 6684 | bool ImGui::TreeNodeUpdateNextOpen(ImGuiID storage_id, ImGuiTreeNodeFlags flags) |
| 6685 | { |
| 6686 | if (flags & ImGuiTreeNodeFlags_Leaf) |
| 6687 | return true; |
| 6688 | |
| 6689 | // We only write to the tree storage if the user clicks, or explicitly use the SetNextItemOpen function |
| 6690 | ImGuiContext& g = *GImGui; |
| 6691 | ImGuiWindow* window = g.CurrentWindow; |
| 6692 | ImGuiStorage* storage = window->DC.StateStorage; |
| 6693 | |
| 6694 | bool is_open; |
| 6695 | if (g.NextItemData.HasFlags & ImGuiNextItemDataFlags_HasOpen) |
| 6696 | { |
| 6697 | if (g.NextItemData.OpenCond & ImGuiCond_Always) |
| 6698 | { |
| 6699 | is_open = g.NextItemData.OpenVal; |
| 6700 | TreeNodeSetOpen(storage_id, is_open); |
| 6701 | } |
| 6702 | else |
| 6703 | { |
| 6704 | // We treat ImGuiCond_Once and ImGuiCond_FirstUseEver the same because tree node state are not saved persistently. |
| 6705 | const int stored_value = storage->GetInt(storage_id, -1); |
| 6706 | if (stored_value == -1) |
| 6707 | { |
| 6708 | is_open = g.NextItemData.OpenVal; |
| 6709 | TreeNodeSetOpen(storage_id, is_open); |
| 6710 | } |
| 6711 | else |
| 6712 | { |
| 6713 | is_open = stored_value != 0; |
| 6714 | } |
| 6715 | } |
| 6716 | } |
| 6717 | else |
| 6718 | { |
| 6719 | is_open = storage->GetInt(storage_id, (flags & ImGuiTreeNodeFlags_DefaultOpen) ? 1 : 0) != 0; |
| 6720 | } |
| 6721 | |
| 6722 | // When logging is enabled, we automatically expand tree nodes (but *NOT* collapsing headers.. seems like sensible behavior). |
| 6723 | // NB- If we are above max depth we still allow manually opened nodes to be logged. |
| 6724 | if (g.LogEnabled && !(flags & ImGuiTreeNodeFlags_NoAutoOpenOnLog) && (window->DC.TreeDepth - g.LogDepthRef) < g.LogDepthToExpand) |
| 6725 | is_open = true; |
| 6726 | |
| 6727 | return is_open; |
| 6728 | } |
| 6729 | |
| 6730 | // Store ImGuiTreeNodeStackData for just submitted node. |
| 6731 | // Currently only supports 32 level deep and we are fine with (1 << Depth) overflowing into a zero, easy to increase. |