TreeNode: Don't latch GetColorU32(ImGuiCol_TreeLines). (#2920)
Some checks are pending
build / Windows (push) Waiting to run
build / Linux (push) Waiting to run
build / MacOS (push) Waiting to run
build / iOS (push) Waiting to run
build / Emscripten (push) Waiting to run
build / Android (push) Waiting to run

Trade off doesn't seem worth it for large trees. User who really needs to alter colors can do it by adjusting Push/Pop locations.
This commit is contained in:
ocornut 2025-04-08 19:56:14 +02:00
parent e5b218e6d1
commit 39f34e1e58
3 changed files with 7 additions and 16 deletions

View file

@ -64,8 +64,6 @@ Other changes:
which may be overriden in individual TreeNode() calls.
- Added style.TreeLinesSize (default to 1.0f).
- Added ImGuiCol_TreeLines (in default style this is the same as ImGuiCol_Border).
The color for a given hierarchy level is latched in TreeNode(),
allowing advanced tree drawing code to potentially alter it.
- The feature adds a little cost as extra data needs to be stored.
- Nav: fixed assertion when holding gamepad FaceLeft/West button to open
CTRL+Tab windowing + pressing a keyboard key. (#8525)

View file

@ -1294,7 +1294,6 @@ struct ImGuiTreeNodeStackData
ImGuiTreeNodeFlags TreeFlags;
ImGuiItemFlags ItemFlags; // Used for nav landing
ImRect NavRect; // Used for nav landing
ImU32 DrawLinesCol;
float DrawLinesX1;
float DrawLinesY2;
};

View file

@ -6560,16 +6560,10 @@ static void TreeNodeStoreStackData(ImGuiTreeNodeFlags flags, float x1)
tree_node_data->TreeFlags = flags;
tree_node_data->ItemFlags = g.LastItemData.ItemFlags;
tree_node_data->NavRect = g.LastItemData.NavRect;
if (flags & (ImGuiTreeNodeFlags_DrawLinesFull | ImGuiTreeNodeFlags_DrawLinesToNodes))
{
tree_node_data->DrawLinesCol = ImGui::GetColorU32(ImGuiCol_TreeLines);
tree_node_data->DrawLinesX1 = x1;
tree_node_data->DrawLinesY2 = -FLT_MAX;
}
else
{
tree_node_data->DrawLinesCol = 0;
}
// Initially I tried to latch value for GetColorU32(ImGuiCol_TreeLines) but it's not a good trade-off for very large trees.
tree_node_data->DrawLinesX1 = (flags & (ImGuiTreeNodeFlags_DrawLinesFull | ImGuiTreeNodeFlags_DrawLinesToNodes)) ? x1 : +FLT_MAX;
tree_node_data->DrawLinesY2 = -FLT_MAX;
window->DC.TreeHasStackDataDepthMask |= (1 << window->DC.TreeDepth);
}
@ -6837,7 +6831,7 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l
float y = text_pos.y + ImTrunc(g.FontSize * 0.5f);
parent_data->DrawLinesY2 = ImMax(parent_data->DrawLinesY2, y);
if (x1 < x2)
window->DrawList->AddLine(ImVec2(x1, y), ImVec2(x2, y), parent_data->DrawLinesCol, g.Style.TreeLinesSize);
window->DrawList->AddLine(ImVec2(x1, y), ImVec2(x2, y), GetColorU32(ImGuiCol_TreeLines), g.Style.TreeLinesSize);
}
if (span_all_columns && !span_all_columns_label)
@ -6906,7 +6900,7 @@ void ImGui::TreePop()
if (g.NavIdIsAlive && g.NavMoveDir == ImGuiDir_Left && g.NavWindow == window && NavMoveRequestButNoResultYet())
NavMoveRequestResolveWithPastTreeNode(&g.NavMoveResultLocal, data);
}
if (data->DrawLinesCol != 0 && window->DC.CursorPos.y >= window->ClipRect.Min.y)
if (data->DrawLinesX1 != +FLT_MAX && window->DC.CursorPos.y >= window->ClipRect.Min.y)
{
// Draw vertical line of the hierarchy
float y1 = ImMax(data->NavRect.Max.y, window->ClipRect.Min.y);
@ -6915,7 +6909,7 @@ void ImGui::TreePop()
if (y1 < y2)
{
float x = data->DrawLinesX1 + ImTrunc(g.FontSize * 0.5f + g.Style.FramePadding.x); // GetTreeNodeToLabelSpacing() * 0.5f
window->DrawList->AddLine(ImVec2(x, y1), ImVec2(x, y2), data->DrawLinesCol, g.Style.TreeLinesSize);
window->DrawList->AddLine(ImVec2(x, y1), ImVec2(x, y2), GetColorU32(ImGuiCol_TreeLines), g.Style.TreeLinesSize);
}
}
g.TreeNodeStack.pop_back();