| 6801 | } |
| 6802 | |
| 6803 | bool ImGui::TreeNodeUpdateNextOpen(ImGuiID storage_id, ImGuiTreeNodeFlags flags) |
| 6804 | { |
| 6805 | // Leaf node always open a new tree/id scope. If you never use it, add ImGuiTreeNodeFlags_NoTreePushOnOpen. |
| 6806 | if (flags & ImGuiTreeNodeFlags_Leaf) |
| 6807 | return true; |
| 6808 | |
| 6809 | // We only write to the tree storage if the user clicks, or explicitly use the SetNextItemOpen function |
| 6810 | ImGuiContext& g = *GImGui; |
| 6811 | ImGuiWindow* window = g.CurrentWindow; |
| 6812 | ImGuiStorage* storage = window->DC.StateStorage; |
| 6813 | |
| 6814 | bool is_open; |
| 6815 | if (g.NextItemData.HasFlags & ImGuiNextItemDataFlags_HasOpen) |
| 6816 | { |
| 6817 | if (g.NextItemData.OpenCond & ImGuiCond_Always) |
| 6818 | { |
| 6819 | is_open = g.NextItemData.OpenVal; |
| 6820 | TreeNodeSetOpen(storage_id, is_open); |
| 6821 | } |
| 6822 | else |
| 6823 | { |
| 6824 | // We treat ImGuiCond_Once and ImGuiCond_FirstUseEver the same because tree node state are not saved persistently. |
| 6825 | const int stored_value = storage->GetInt(storage_id, -1); |
| 6826 | if (stored_value == -1) |
| 6827 | { |
| 6828 | is_open = g.NextItemData.OpenVal; |
| 6829 | TreeNodeSetOpen(storage_id, is_open); |
| 6830 | } |
| 6831 | else |
| 6832 | { |
| 6833 | is_open = stored_value != 0; |
| 6834 | } |
| 6835 | } |
| 6836 | } |
| 6837 | else |
| 6838 | { |
| 6839 | is_open = storage->GetInt(storage_id, (flags & ImGuiTreeNodeFlags_DefaultOpen) ? 1 : 0) != 0; |
| 6840 | } |
| 6841 | |
| 6842 | // When logging is enabled, we automatically expand tree nodes (but *NOT* collapsing headers.. seems like sensible behavior). |
| 6843 | // NB- If we are above max depth we still allow manually opened nodes to be logged. |
| 6844 | if (g.LogEnabled && !(flags & ImGuiTreeNodeFlags_NoAutoOpenOnLog) && (window->DC.TreeDepth - g.LogDepthRef) < g.LogDepthToExpand) |
| 6845 | is_open = true; |
| 6846 | |
| 6847 | return is_open; |
| 6848 | } |
| 6849 | |
| 6850 | // Store ImGuiTreeNodeStackData for just submitted node. |
| 6851 | // Currently only supports 32 level deep and we are fine with (1 << Depth) overflowing into a zero, easy to increase. |