Skip to content

Commit ee0d96a

Browse files
committed
TreeNode: extract code out of TreePop() into TreeNodeDrawLineToTreePop(). (#2920)
1 parent 8c977bf commit ee0d96a

File tree

2 files changed

+34
-27
lines changed

2 files changed

+34
-27
lines changed

imgui_internal.h

+1
Original file line numberDiff line numberDiff line change
@@ -3471,6 +3471,7 @@ namespace ImGui
34713471
// Widgets: Tree Nodes
34723472
IMGUI_API bool TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* label, const char* label_end = NULL);
34733473
IMGUI_API void TreeNodeDrawLineToChildNode(const ImVec2& target_pos);
3474+
IMGUI_API void TreeNodeDrawLineToTreePop(const ImGuiTreeNodeStackData* data);
34743475
IMGUI_API void TreePushOverrideID(ImGuiID id);
34753476
IMGUI_API bool TreeNodeGetOpen(ImGuiID storage_id);
34763477
IMGUI_API void TreeNodeSetOpen(ImGuiID storage_id, bool open);

imgui_widgets.cpp

+33-27
Original file line numberDiff line numberDiff line change
@@ -6868,6 +6868,33 @@ void ImGui::TreeNodeDrawLineToChildNode(const ImVec2& target_pos)
68686868
window->DrawList->AddLine(ImVec2(x1, y), ImVec2(x2, y), GetColorU32(ImGuiCol_TreeLines), g.Style.TreeLinesSize);
68696869
}
68706870

6871+
// Draw vertical line of the hierarchy
6872+
void ImGui::TreeNodeDrawLineToTreePop(const ImGuiTreeNodeStackData* data)
6873+
{
6874+
ImGuiContext& g = *GImGui;
6875+
ImGuiWindow* window = g.CurrentWindow;
6876+
float y1 = ImMax(data->NavRect.Max.y, window->ClipRect.Min.y);
6877+
float y2 = data->DrawLinesToNodesY2;
6878+
if (data->TreeFlags & ImGuiTreeNodeFlags_DrawLinesFull)
6879+
{
6880+
float y2_full = window->DC.CursorPos.y;
6881+
if (g.CurrentTable)
6882+
y2_full = ImMax(g.CurrentTable->RowPosY2, y2_full);
6883+
y2_full = ImTrunc(y2_full - g.Style.ItemSpacing.y - g.FontSize * 0.5f);
6884+
if (y2 + g.Style.ItemSpacing.y < y2_full) // FIXME: threshold to use ToNodes Y2 instead of Full Y2 when close by ItemSpacing.y
6885+
y2 = y2_full;
6886+
}
6887+
y2 = ImMin(y2, window->ClipRect.Max.y);
6888+
if (y2 <= y1)
6889+
return;
6890+
float x = ImTrunc(data->DrawLinesX1);
6891+
if (data->DrawLinesTableColumn != -1)
6892+
TablePushColumnChannel(data->DrawLinesTableColumn);
6893+
window->DrawList->AddLine(ImVec2(x, y1), ImVec2(x, y2), GetColorU32(ImGuiCol_TreeLines), g.Style.TreeLinesSize);
6894+
if (data->DrawLinesTableColumn != -1)
6895+
TablePopColumnChannel();
6896+
}
6897+
68716898
void ImGui::TreePush(const char* str_id)
68726899
{
68736900
ImGuiWindow* window = GetCurrentWindow();
@@ -6906,37 +6933,16 @@ void ImGui::TreePop()
69066933
{
69076934
const ImGuiTreeNodeStackData* data = &g.TreeNodeStack.Data[g.TreeNodeStack.Size - 1];
69086935
IM_ASSERT(data->ID == window->IDStack.back());
6936+
6937+
// Handle Left arrow to move to parent tree node (when ImGuiTreeNodeFlags_NavLeftJumpsBackHere is enabled)
69096938
if (data->TreeFlags & ImGuiTreeNodeFlags_NavLeftJumpsBackHere)
6910-
{
6911-
// Handle Left arrow to move to parent tree node (when ImGuiTreeNodeFlags_NavLeftJumpsBackHere is enabled)
69126939
if (g.NavIdIsAlive && g.NavMoveDir == ImGuiDir_Left && g.NavWindow == window && NavMoveRequestButNoResultYet())
69136940
NavMoveRequestResolveWithPastTreeNode(&g.NavMoveResultLocal, data);
6914-
}
6941+
6942+
// Draw hierarchy lines
69156943
if (data->DrawLinesX1 != +FLT_MAX && window->DC.CursorPos.y >= window->ClipRect.Min.y)
6916-
{
6917-
// Draw vertical line of the hierarchy
6918-
float y1 = ImMax(data->NavRect.Max.y, window->ClipRect.Min.y);
6919-
float y2 = data->DrawLinesToNodesY2;
6920-
if (data->TreeFlags & ImGuiTreeNodeFlags_DrawLinesFull)
6921-
{
6922-
float y2_full = window->DC.CursorPos.y;
6923-
if (g.CurrentTable)
6924-
y2_full = ImMax(g.CurrentTable->RowPosY2, y2_full);
6925-
y2_full = ImTrunc(y2_full - g.Style.ItemSpacing.y - g.FontSize * 0.5f);
6926-
if (y2 + g.Style.ItemSpacing.y < y2_full) // FIXME: threshold to use ToNodes Y2 instead of Full Y2 when close by ItemSpacing.y
6927-
y2 = y2_full;
6928-
}
6929-
y2 = ImMin(y2, window->ClipRect.Max.y);
6930-
if (y1 < y2)
6931-
{
6932-
float x = ImTrunc(data->DrawLinesX1);
6933-
if (data->DrawLinesTableColumn != -1)
6934-
TablePushColumnChannel(data->DrawLinesTableColumn);
6935-
window->DrawList->AddLine(ImVec2(x, y1), ImVec2(x, y2), GetColorU32(ImGuiCol_TreeLines), g.Style.TreeLinesSize);
6936-
if (data->DrawLinesTableColumn != -1)
6937-
TablePopColumnChannel();
6938-
}
6939-
}
6944+
TreeNodeDrawLineToTreePop(data);
6945+
69406946
g.TreeNodeStack.pop_back();
69416947
window->DC.TreeHasStackDataDepthMask &= ~tree_depth_mask;
69426948
}

0 commit comments

Comments
 (0)