Skip to content

Commit 3a04190

Browse files
committed
TreeNode: extracted TreeNodeDrawLineToChildNode() for usage by custom widgets (#2920)
1 parent b811c42 commit 3a04190

File tree

5 files changed

+29
-16
lines changed

5 files changed

+29
-16
lines changed

docs/CHANGELOG.txt

+6-2
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,18 @@ Other changes:
5757
one in docking (they accidentally diverged). (#8554)
5858
- TreeNode: added flags to draw tree hierarchy outlines linking parent
5959
and tree nodes: (#2920)
60-
- ImGuiTreeNodeFlags_DrawLinesNone: No lines drawn.
60+
- ImGuiTreeNodeFlags_DrawLinesNone: No lines drawn (default value in style.TreeLinesFlags).
6161
- ImGuiTreeNodeFlags_DrawLinesFull: Horizontal lines to child nodes. Vertical line drawn down to TreePop() position: cover full contents.
6262
- ImGuiTreeNodeFlags_DrawLinesToNodes: Horizontal lines to child nodes. Vertical line drawn down to bottom-most child node.
6363
- Added style.TreeLinesFlags which stores the default setting,
6464
which may be overriden in individual TreeNode() calls.
6565
- Added style.TreeLinesSize (default to 1.0f).
6666
- Added ImGuiCol_TreeLines (in default style this is the same as ImGuiCol_Border).
67-
- The feature adds a little cost as extra data needs to be stored.
67+
- Caveats:
68+
- Tree nodes may be used in many creative ways (manually positioning openable
69+
nodes in unusual ways, using indent to create tree-looking structures, etc.)
70+
and the feature may not accurately represent them in every cases.
71+
- The feature adds a little cost as extra data needs to be stored.
6872
- Nav: fixed assertion when holding gamepad FaceLeft/West button to open
6973
CTRL+Tab windowing + pressing a keyboard key. (#8525)
7074
- Error Handling: added better error report and recovery for extraneous

imgui.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -22444,9 +22444,9 @@ void ImGui::DebugNodeWindowsListByBeginStackParent(ImGuiWindow** windows, int wi
2244422444
ImFormatString(buf, IM_ARRAYSIZE(buf), "[%04d] Window", window->BeginOrderWithinContext);
2244522445
//BulletText("[%04d] Window '%s'", window->BeginOrderWithinContext, window->Name);
2244622446
DebugNodeWindow(window, buf);
22447-
Indent();
22447+
TreePush(buf);
2244822448
DebugNodeWindowsListByBeginStackParent(windows + i + 1, windows_size - i - 1, window);
22449-
Unindent();
22449+
TreePop();
2245022450
}
2245122451
}
2245222452

imgui.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
// Library Version
3030
// (Integer encoded as XYYZZ for use in #if preprocessor conditionals, e.g. '#if IMGUI_VERSION_NUM >= 12345')
3131
#define IMGUI_VERSION "1.92.0 WIP"
32-
#define IMGUI_VERSION_NUM 19192
32+
#define IMGUI_VERSION_NUM 19193
3333
#define IMGUI_HAS_TABLE
3434
#define IMGUI_HAS_VIEWPORT // Viewport WIP branch
3535
#define IMGUI_HAS_DOCK // Docking WIP branch

imgui_internal.h

+1
Original file line numberDiff line numberDiff line change
@@ -3768,6 +3768,7 @@ namespace ImGui
37683768

37693769
// Widgets: Tree Nodes
37703770
IMGUI_API bool TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* label, const char* label_end = NULL);
3771+
IMGUI_API void TreeNodeDrawLineToChildNode(const ImVec2& target_pos);
37713772
IMGUI_API void TreePushOverrideID(ImGuiID id);
37723773
IMGUI_API bool TreeNodeGetOpen(ImGuiID storage_id);
37733774
IMGUI_API void TreeNodeSetOpen(ImGuiID storage_id, bool open);

imgui_widgets.cpp

+19-11
Original file line numberDiff line numberDiff line change
@@ -6829,17 +6829,8 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l
68296829
LogSetNextTextDecoration(">", NULL);
68306830
}
68316831

6832-
if (draw_tree_lines && (window->DC.TreeHasStackDataDepthMask & (1 << (window->DC.TreeDepth - 1))))
6833-
{
6834-
// Draw horizontal line from our parent node
6835-
ImGuiTreeNodeStackData* parent_data = &g.TreeNodeStack.Data[g.TreeNodeStack.Size - 1];
6836-
float x1 = parent_data->DrawLinesX1 + ImTrunc(g.FontSize * 0.5f + g.Style.FramePadding.x); // GetTreeNodeToLabelSpacing() * 0.5f
6837-
float x2 = text_pos.x - text_offset_x;
6838-
float y = text_pos.y + ImTrunc(g.FontSize * 0.5f);
6839-
parent_data->DrawLinesY2 = ImMax(parent_data->DrawLinesY2, y);
6840-
if (x1 < x2)
6841-
window->DrawList->AddLine(ImVec2(x1, y), ImVec2(x2, y), GetColorU32(ImGuiCol_TreeLines), g.Style.TreeLinesSize);
6842-
}
6832+
if (draw_tree_lines)
6833+
TreeNodeDrawLineToChildNode(ImVec2(text_pos.x - text_offset_x, text_pos.y + g.FontSize * 0.5f));
68436834

68446835
if (span_all_columns && !span_all_columns_label)
68456836
TablePopBackgroundChannel();
@@ -6863,6 +6854,23 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l
68636854
return is_open;
68646855
}
68656856

6857+
// Draw horizontal line from our parent node
6858+
// This is only called for visible child nodes so we are not too fussy anymore about performances
6859+
void ImGui::TreeNodeDrawLineToChildNode(const ImVec2& target_pos)
6860+
{
6861+
ImGuiContext& g = *GImGui;
6862+
ImGuiWindow* window = g.CurrentWindow;
6863+
if ((window->DC.TreeHasStackDataDepthMask & (1 << (window->DC.TreeDepth - 1))) == 0)
6864+
return;
6865+
6866+
ImGuiTreeNodeStackData* parent_data = &g.TreeNodeStack.Data[g.TreeNodeStack.Size - 1];
6867+
float x1 = parent_data->DrawLinesX1 + ImTrunc(g.FontSize * 0.5f + g.Style.FramePadding.x); // GetTreeNodeToLabelSpacing() * 0.5f
6868+
float y = ImTrunc(target_pos.y);
6869+
parent_data->DrawLinesY2 = ImMax(parent_data->DrawLinesY2, y);
6870+
if (x1 < target_pos.x)
6871+
window->DrawList->AddLine(ImVec2(x1, y), ImVec2(target_pos.x, y), GetColorU32(ImGuiCol_TreeLines), g.Style.TreeLinesSize);
6872+
}
6873+
68666874
void ImGui::TreePush(const char* str_id)
68676875
{
68686876
ImGuiWindow* window = GetCurrentWindow();

0 commit comments

Comments
 (0)