MCPcopy Create free account
hub / github.com/AlexandreRouma/SDRPlusPlus / TreeNodeBehavior

Method TreeNodeBehavior

core/src/imgui/imgui_widgets.cpp:5704–5889  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5702}
5703
5704bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* label, const char* label_end)
5705{
5706 ImGuiWindow* window = GetCurrentWindow();
5707 if (window->SkipItems)
5708 return false;
5709
5710 ImGuiContext& g = *GImGui;
5711 const ImGuiStyle& style = g.Style;
5712 const bool display_frame = (flags & ImGuiTreeNodeFlags_Framed) != 0;
5713 const ImVec2 padding = (display_frame || (flags & ImGuiTreeNodeFlags_FramePadding)) ? style.FramePadding : ImVec2(style.FramePadding.x, ImMin(window->DC.CurrLineTextBaseOffset, style.FramePadding.y));
5714
5715 if (!label_end)
5716 label_end = FindRenderedTextEnd(label);
5717 const ImVec2 label_size = CalcTextSize(label, label_end, false);
5718
5719 // We vertically grow up to current line height up the typical widget height.
5720 const float frame_height = ImMax(ImMin(window->DC.CurrLineSize.y, g.FontSize + style.FramePadding.y * 2), label_size.y + padding.y * 2);
5721 ImRect frame_bb;
5722 frame_bb.Min.x = (flags & ImGuiTreeNodeFlags_SpanFullWidth) ? window->WorkRect.Min.x : window->DC.CursorPos.x;
5723 frame_bb.Min.y = window->DC.CursorPos.y;
5724 frame_bb.Max.x = window->WorkRect.Max.x;
5725 frame_bb.Max.y = window->DC.CursorPos.y + frame_height;
5726 if (display_frame)
5727 {
5728 // Framed header expand a little outside the default padding, to the edge of InnerClipRect
5729 // (FIXME: May remove this at some point and make InnerClipRect align with WindowPadding.x instead of WindowPadding.x*0.5f)
5730 frame_bb.Min.x -= IM_FLOOR(window->WindowPadding.x * 0.5f - 1.0f);
5731 frame_bb.Max.x += IM_FLOOR(window->WindowPadding.x * 0.5f);
5732 }
5733
5734 const float text_offset_x = g.FontSize + (display_frame ? padding.x * 3 : padding.x * 2); // Collapser arrow width + Spacing
5735 const float text_offset_y = ImMax(padding.y, window->DC.CurrLineTextBaseOffset); // Latch before ItemSize changes it
5736 const float text_width = g.FontSize + (label_size.x > 0.0f ? label_size.x + padding.x * 2 : 0.0f); // Include collapser
5737 ImVec2 text_pos(window->DC.CursorPos.x + text_offset_x, window->DC.CursorPos.y + text_offset_y);
5738 ItemSize(ImVec2(text_width, frame_height), padding.y);
5739
5740 // For regular tree nodes, we arbitrary allow to click past 2 worth of ItemSpacing
5741 ImRect interact_bb = frame_bb;
5742 if (!display_frame && (flags & (ImGuiTreeNodeFlags_SpanAvailWidth | ImGuiTreeNodeFlags_SpanFullWidth)) == 0)
5743 interact_bb.Max.x = frame_bb.Min.x + text_width + style.ItemSpacing.x * 2.0f;
5744
5745 // Store a flag for the current depth to tell if we will allow closing this node when navigating one of its child.
5746 // For this purpose we essentially compare if g.NavIdIsAlive went from 0 to 1 between TreeNode() and TreePop().
5747 // This is currently only support 32 level deep and we are fine with (1 << Depth) overflowing into a zero.
5748 const bool is_leaf = (flags & ImGuiTreeNodeFlags_Leaf) != 0;
5749 bool is_open = TreeNodeBehaviorIsOpen(id, flags);
5750 if (is_open && !g.NavIdIsAlive && (flags & ImGuiTreeNodeFlags_NavLeftJumpsBackHere) && !(flags & ImGuiTreeNodeFlags_NoTreePushOnOpen))
5751 window->DC.TreeJumpToParentOnPopMask |= (1 << window->DC.TreeDepth);
5752
5753 bool item_add = ItemAdd(interact_bb, id);
5754 window->DC.LastItemStatusFlags |= ImGuiItemStatusFlags_HasDisplayRect;
5755 window->DC.LastItemDisplayRect = frame_bb;
5756
5757 if (!item_add)
5758 {
5759 if (is_open && !(flags & ImGuiTreeNodeFlags_NoTreePushOnOpen))
5760 TreePushOverrideID(id);
5761 IMGUI_TEST_ENGINE_ITEM_INFO(window->DC.LastItemId, label, window->DC.LastItemStatusFlags | (is_leaf ? 0 : ImGuiItemStatusFlags_Openable) | (is_open ? ImGuiItemStatusFlags_Opened : 0));

Callers

nothing calls this directly

Calls 7

GetCurrentWindowFunction · 0.85
ImVec2Function · 0.85
ImMinFunction · 0.85
ImMaxFunction · 0.85
RenderBulletFunction · 0.85
RenderArrowFunction · 0.85
SetIntMethod · 0.80

Tested by

no test coverage detected