MCPcopy Create free account
hub / github.com/InteractiveComputerGraphics/SPlisHSPlasH / TreeNodeBehavior

Method TreeNodeBehavior

extern/imgui/imgui_widgets.cpp:5950–6135  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5948}
5949
5950bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* label, const char* label_end)
5951{
5952 ImGuiWindow* window = GetCurrentWindow();
5953 if (window->SkipItems)
5954 return false;
5955
5956 ImGuiContext& g = *GImGui;
5957 const ImGuiStyle& style = g.Style;
5958 const bool display_frame = (flags & ImGuiTreeNodeFlags_Framed) != 0;
5959 const ImVec2 padding = (display_frame || (flags & ImGuiTreeNodeFlags_FramePadding)) ? style.FramePadding : ImVec2(style.FramePadding.x, ImMin(window->DC.CurrLineTextBaseOffset, style.FramePadding.y));
5960
5961 if (!label_end)
5962 label_end = FindRenderedTextEnd(label);
5963 const ImVec2 label_size = CalcTextSize(label, label_end, false);
5964
5965 // We vertically grow up to current line height up the typical widget height.
5966 const float frame_height = ImMax(ImMin(window->DC.CurrLineSize.y, g.FontSize + style.FramePadding.y * 2), label_size.y + padding.y * 2);
5967 ImRect frame_bb;
5968 frame_bb.Min.x = (flags & ImGuiTreeNodeFlags_SpanFullWidth) ? window->WorkRect.Min.x : window->DC.CursorPos.x;
5969 frame_bb.Min.y = window->DC.CursorPos.y;
5970 frame_bb.Max.x = window->WorkRect.Max.x;
5971 frame_bb.Max.y = window->DC.CursorPos.y + frame_height;
5972 if (display_frame)
5973 {
5974 // Framed header expand a little outside the default padding, to the edge of InnerClipRect
5975 // (FIXME: May remove this at some point and make InnerClipRect align with WindowPadding.x instead of WindowPadding.x*0.5f)
5976 frame_bb.Min.x -= IM_FLOOR(window->WindowPadding.x * 0.5f - 1.0f);
5977 frame_bb.Max.x += IM_FLOOR(window->WindowPadding.x * 0.5f);
5978 }
5979
5980 const float text_offset_x = g.FontSize + (display_frame ? padding.x * 3 : padding.x * 2); // Collapser arrow width + Spacing
5981 const float text_offset_y = ImMax(padding.y, window->DC.CurrLineTextBaseOffset); // Latch before ItemSize changes it
5982 const float text_width = g.FontSize + (label_size.x > 0.0f ? label_size.x + padding.x * 2 : 0.0f); // Include collapser
5983 ImVec2 text_pos(window->DC.CursorPos.x + text_offset_x, window->DC.CursorPos.y + text_offset_y);
5984 ItemSize(ImVec2(text_width, frame_height), padding.y);
5985
5986 // For regular tree nodes, we arbitrary allow to click past 2 worth of ItemSpacing
5987 ImRect interact_bb = frame_bb;
5988 if (!display_frame && (flags & (ImGuiTreeNodeFlags_SpanAvailWidth | ImGuiTreeNodeFlags_SpanFullWidth)) == 0)
5989 interact_bb.Max.x = frame_bb.Min.x + text_width + style.ItemSpacing.x * 2.0f;
5990
5991 // Store a flag for the current depth to tell if we will allow closing this node when navigating one of its child.
5992 // For this purpose we essentially compare if g.NavIdIsAlive went from 0 to 1 between TreeNode() and TreePop().
5993 // This is currently only support 32 level deep and we are fine with (1 << Depth) overflowing into a zero.
5994 const bool is_leaf = (flags & ImGuiTreeNodeFlags_Leaf) != 0;
5995 bool is_open = TreeNodeUpdateNextOpen(id, flags);
5996 if (is_open && !g.NavIdIsAlive && (flags & ImGuiTreeNodeFlags_NavLeftJumpsBackHere) && !(flags & ImGuiTreeNodeFlags_NoTreePushOnOpen))
5997 window->DC.TreeJumpToParentOnPopMask |= (1 << window->DC.TreeDepth);
5998
5999 bool item_add = ItemAdd(interact_bb, id);
6000 g.LastItemData.StatusFlags |= ImGuiItemStatusFlags_HasDisplayRect;
6001 g.LastItemData.DisplayRect = frame_bb;
6002
6003 if (!item_add)
6004 {
6005 if (is_open && !(flags & ImGuiTreeNodeFlags_NoTreePushOnOpen))
6006 TreePushOverrideID(id);
6007 IMGUI_TEST_ENGINE_ITEM_INFO(g.LastItemData.ID, label, g.LastItemData.StatusFlags | (is_leaf ? 0 : ImGuiItemStatusFlags_Openable) | (is_open ? ImGuiItemStatusFlags_Opened : 0));

Callers

nothing calls this directly

Calls 6

GetCurrentWindowFunction · 0.85
ImVec2Function · 0.85
ImMinFunction · 0.85
ImMaxFunction · 0.85
ItemSizeFunction · 0.85
SetIntMethod · 0.80

Tested by

no test coverage detected