diff --git a/imgui.cpp b/imgui.cpp index 1ec4cd2..fec7c37 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -6043,19 +6043,20 @@ ImGuiWindow* window = GetCurrentWindow(); if (window->SkipItems) return false; - return TreeNodeBehavior(window->GetID(label), 0, label, NULL); } -float ImGui::GetTreeNodeToLabelSpacing(ImGuiTreeNodeFlags flags) +void ImGui::TreeAdvanceToLabelPos() { ImGuiContext& g = *GImGui; - float off_from_start; - if (flags & ImGuiTreeNodeFlags_Framed) - off_from_start = g.FontSize + (g.Style.FramePadding.x * 3.0f) - ((float)(int)(g.CurrentWindow->WindowPadding.x*0.5f) - 1); - else - off_from_start = g.FontSize + (g.Style.FramePadding.x * 2.0f); - return off_from_start; + g.CurrentWindow->DC.CursorPos.x += GetTreeNodeToLabelSpacing(); +} + +// Horizontal distance preceeding label when using TreeNode() or Bullet() +float ImGui::GetTreeNodeToLabelSpacing() +{ + ImGuiContext& g = *GImGui; + return g.FontSize + (g.Style.FramePadding.x * 2.0f); } void ImGui::SetNextTreeNodeOpen(bool is_open, ImGuiSetCond cond) diff --git a/imgui.cpp b/imgui.cpp index 1ec4cd2..fec7c37 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -6043,19 +6043,20 @@ ImGuiWindow* window = GetCurrentWindow(); if (window->SkipItems) return false; - return TreeNodeBehavior(window->GetID(label), 0, label, NULL); } -float ImGui::GetTreeNodeToLabelSpacing(ImGuiTreeNodeFlags flags) +void ImGui::TreeAdvanceToLabelPos() { ImGuiContext& g = *GImGui; - float off_from_start; - if (flags & ImGuiTreeNodeFlags_Framed) - off_from_start = g.FontSize + (g.Style.FramePadding.x * 3.0f) - ((float)(int)(g.CurrentWindow->WindowPadding.x*0.5f) - 1); - else - off_from_start = g.FontSize + (g.Style.FramePadding.x * 2.0f); - return off_from_start; + g.CurrentWindow->DC.CursorPos.x += GetTreeNodeToLabelSpacing(); +} + +// Horizontal distance preceeding label when using TreeNode() or Bullet() +float ImGui::GetTreeNodeToLabelSpacing() +{ + ImGuiContext& g = *GImGui; + return g.FontSize + (g.Style.FramePadding.x * 2.0f); } void ImGui::SetNextTreeNodeOpen(bool is_open, ImGuiSetCond cond) diff --git a/imgui.h b/imgui.h index 24da799..c455cb7 100644 --- a/imgui.h +++ b/imgui.h @@ -326,8 +326,9 @@ IMGUI_API void TreePush(const char* str_id = NULL); // ~ Indent()+PushId(). Already called by TreeNode() when returning true, but you can call Push/Pop yourself for layout purpose IMGUI_API void TreePush(const void* ptr_id = NULL); // " IMGUI_API void TreePop(); // ~ Unindent()+PopId() + IMGUI_API void TreeAdvanceToLabelPos(); // advance cursor x position by GetTreeNodeToLabelSpacing() + IMGUI_API float GetTreeNodeToLabelSpacing(); // horizontal distance preceeding label when using TreeNode*() or Bullet() == (g.FontSize + style.FramePadding.x*2) for a regular unframed TreeNode IMGUI_API void SetNextTreeNodeOpen(bool is_open, ImGuiSetCond cond = 0); // set next TreeNode/CollapsingHeader open state. - IMGUI_API float GetTreeNodeToLabelSpacing(ImGuiTreeNodeFlags flags = 0); // return horizontal distance between cursor and text label due to collapsing node. == (g.FontSize + style.FramePadding.x*2) for a regular unframed TreeNode IMGUI_API bool CollapsingHeader(const char* label, ImGuiTreeNodeFlags flags = 0); // if returning 'true' the header is open. user doesn't have to call TreePop(). IMGUI_API bool CollapsingHeader(const char* label, bool* p_open, ImGuiTreeNodeFlags flags = 0); // when 'p_open' isn't NULL, display an additional small close button on upper right of the header diff --git a/imgui.cpp b/imgui.cpp index 1ec4cd2..fec7c37 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -6043,19 +6043,20 @@ ImGuiWindow* window = GetCurrentWindow(); if (window->SkipItems) return false; - return TreeNodeBehavior(window->GetID(label), 0, label, NULL); } -float ImGui::GetTreeNodeToLabelSpacing(ImGuiTreeNodeFlags flags) +void ImGui::TreeAdvanceToLabelPos() { ImGuiContext& g = *GImGui; - float off_from_start; - if (flags & ImGuiTreeNodeFlags_Framed) - off_from_start = g.FontSize + (g.Style.FramePadding.x * 3.0f) - ((float)(int)(g.CurrentWindow->WindowPadding.x*0.5f) - 1); - else - off_from_start = g.FontSize + (g.Style.FramePadding.x * 2.0f); - return off_from_start; + g.CurrentWindow->DC.CursorPos.x += GetTreeNodeToLabelSpacing(); +} + +// Horizontal distance preceeding label when using TreeNode() or Bullet() +float ImGui::GetTreeNodeToLabelSpacing() +{ + ImGuiContext& g = *GImGui; + return g.FontSize + (g.Style.FramePadding.x * 2.0f); } void ImGui::SetNextTreeNodeOpen(bool is_open, ImGuiSetCond cond) diff --git a/imgui.h b/imgui.h index 24da799..c455cb7 100644 --- a/imgui.h +++ b/imgui.h @@ -326,8 +326,9 @@ IMGUI_API void TreePush(const char* str_id = NULL); // ~ Indent()+PushId(). Already called by TreeNode() when returning true, but you can call Push/Pop yourself for layout purpose IMGUI_API void TreePush(const void* ptr_id = NULL); // " IMGUI_API void TreePop(); // ~ Unindent()+PopId() + IMGUI_API void TreeAdvanceToLabelPos(); // advance cursor x position by GetTreeNodeToLabelSpacing() + IMGUI_API float GetTreeNodeToLabelSpacing(); // horizontal distance preceeding label when using TreeNode*() or Bullet() == (g.FontSize + style.FramePadding.x*2) for a regular unframed TreeNode IMGUI_API void SetNextTreeNodeOpen(bool is_open, ImGuiSetCond cond = 0); // set next TreeNode/CollapsingHeader open state. - IMGUI_API float GetTreeNodeToLabelSpacing(ImGuiTreeNodeFlags flags = 0); // return horizontal distance between cursor and text label due to collapsing node. == (g.FontSize + style.FramePadding.x*2) for a regular unframed TreeNode IMGUI_API bool CollapsingHeader(const char* label, ImGuiTreeNodeFlags flags = 0); // if returning 'true' the header is open. user doesn't have to call TreePop(). IMGUI_API bool CollapsingHeader(const char* label, bool* p_open, ImGuiTreeNodeFlags flags = 0); // when 'p_open' isn't NULL, display an additional small close button on upper right of the header diff --git a/imgui_demo.cpp b/imgui_demo.cpp index c78f696..3d92424 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -275,10 +275,8 @@ } else { - // Leaf: Here we use the ImGuiTreeNodeFlags_Leaf functionality + ImGuiTreeNodeFlags_NoTreePushOnOpen to avoid testing return value and doing a TreePop - // The only reason we have a TreeNode at all is to allow selection of the leaf. Otherwise we can use BulletText() or a simple Text() element offset by GetTreeNodeToLabelSpacing() - node_flags |= ImGuiTreeNodeFlags_Leaf|ImGuiTreeNodeFlags_NoTreePushOnOpen; - ImGui::TreeNodeEx((void*)(intptr_t)i, node_flags, "Selectable Leaf %d", i); + // Leaf: The only reason we have a TreeNode at all is to allow selection of the leaf. Otherwise we can use BulletText() or TreeAdvanceToLabelPos()+Text(). + ImGui::TreeNodeEx((void*)(intptr_t)i, node_flags | ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen, "Selectable Leaf %d", i); if (ImGui::IsItemClicked()) node_clicked = i; }