mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-04 12:08:47 +02:00
Nav: TreeNode: Added ImGuiTreeNodeFlags_NavCloseFromChild flag, allow closing a TreeNode() from any of child. The explicit flag is not great, perhaps allowing some form of inheritance would help. (#787, #1079)
This commit is contained in:
22
imgui.cpp
22
imgui.cpp
@ -5924,6 +5924,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
|
||||
window->DC.TextWrapPosStack.resize(0);
|
||||
window->DC.ColumnsSet = NULL;
|
||||
window->DC.TreeDepth = 0;
|
||||
window->DC.TreeDepthMayCloseOnPop = 0x00;
|
||||
window->DC.StateStorage = &window->StateStorage;
|
||||
window->DC.GroupStack.resize(0);
|
||||
window->MenuColumns.Update(3, style.ItemSpacing.x, window_just_activated_by_user);
|
||||
@ -7883,6 +7884,13 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l
|
||||
// (Ideally we'd want to add a flag for the user to specify if we want the hit test to be done up to the right side of the content or not)
|
||||
const ImRect interact_bb = display_frame ? bb : ImRect(bb.Min.x, bb.Min.y, bb.Min.x + text_width + style.ItemSpacing.x*2, bb.Max.y);
|
||||
bool is_open = TreeNodeBehaviorIsOpen(id, flags);
|
||||
|
||||
// Store a flag for the current depth to tell if we will allow closing this node when navigating one of its child.
|
||||
// For this purpose we essentially compare if g.NavIdIsAlive went from 0 to 1 between TreeNode() and TreePop().
|
||||
// This is currently only support 32 level deep and we are fine with (1 << Depth) overflowing into a zero.
|
||||
if (is_open && !g.NavIdIsAlive && (flags & ImGuiTreeNodeFlags_NavCloseFromChild) && !(flags & ImGuiTreeNodeFlags_NoTreePushOnOpen))
|
||||
window->DC.TreeDepthMayCloseOnPop |= (1 << window->DC.TreeDepth);
|
||||
|
||||
if (!ItemAdd(interact_bb, id))
|
||||
{
|
||||
if (is_open && !(flags & ImGuiTreeNodeFlags_NoTreePushOnOpen))
|
||||
@ -12529,9 +12537,21 @@ void ImGui::TreePushRawID(ImGuiID id)
|
||||
|
||||
void ImGui::TreePop()
|
||||
{
|
||||
ImGuiWindow* window = GetCurrentWindow();
|
||||
ImGuiContext& g = *GImGui;
|
||||
ImGuiWindow* window = g.CurrentWindow;
|
||||
Unindent();
|
||||
|
||||
window->DC.TreeDepth--;
|
||||
if (g.NavMoveDir == ImGuiDir_Left && g.NavWindow == window && NavMoveRequestButNoResultYet())
|
||||
if (g.NavIdIsAlive && (window->DC.TreeDepthMayCloseOnPop & (1 << window->DC.TreeDepth)))
|
||||
{
|
||||
ImGuiID id = window->IDStack.back();
|
||||
window->DC.StateStorage->SetBool(id, false);
|
||||
SetNavID(id, g.NavLayer);
|
||||
NavMoveRequestCancel();
|
||||
}
|
||||
window->DC.TreeDepthMayCloseOnPop &= (1 << window->DC.TreeDepth) - 1;
|
||||
|
||||
PopID();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user