MCPcopy Create free account
hub / github.com/Aegel5/SimpleSwitcher / TreeNodeBehavior

Method TreeNodeBehavior

imgui_tiny_app/imgui/imgui_widgets.cpp:6854–7135  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6852}
6853
6854bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* label, const char* label_end)
6855{
6856 ImGuiWindow* window = GetCurrentWindow();
6857 if (window->SkipItems)
6858 return false;
6859
6860 ImGuiContext& g = *GImGui;
6861 const ImGuiStyle& style = g.Style;
6862
6863 // When not framed, we vertically increase height up to typical framed widget height
6864 const bool display_frame = (flags & ImGuiTreeNodeFlags_Framed) != 0;
6865 const bool use_frame_padding = (display_frame || (flags & ImGuiTreeNodeFlags_FramePadding));
6866 const ImVec2 padding = use_frame_padding ? style.FramePadding : ImVec2(style.FramePadding.x, ImMin(window->DC.CurrLineTextBaseOffset, style.FramePadding.y));
6867
6868 if (!label_end)
6869 label_end = FindRenderedTextEnd(label);
6870 const ImVec2 label_size = CalcTextSize(label, label_end, false);
6871
6872 const float text_offset_x = g.FontSize + (display_frame ? padding.x * 3 : padding.x * 2); // Collapsing arrow width + Spacing
6873 const float text_offset_y = use_frame_padding ? ImMax(style.FramePadding.y, window->DC.CurrLineTextBaseOffset) : window->DC.CurrLineTextBaseOffset; // Latch before ItemSize changes it
6874 const float text_width = g.FontSize + label_size.x + padding.x * 2; // Include collapsing arrow
6875
6876 const float frame_height = label_size.y + padding.y * 2;
6877 const bool span_all_columns = (flags & ImGuiTreeNodeFlags_SpanAllColumns) != 0 && (g.CurrentTable != NULL);
6878 const bool span_all_columns_label = (flags & ImGuiTreeNodeFlags_LabelSpanAllColumns) != 0 && (g.CurrentTable != NULL);
6879 ImRect frame_bb;
6880 frame_bb.Min.x = span_all_columns ? window->ParentWorkRect.Min.x : (flags & ImGuiTreeNodeFlags_SpanFullWidth) ? window->WorkRect.Min.x : window->DC.CursorPos.x;
6881 frame_bb.Min.y = window->DC.CursorPos.y + (text_offset_y - padding.y);
6882 frame_bb.Max.x = span_all_columns ? window->ParentWorkRect.Max.x : (flags & ImGuiTreeNodeFlags_SpanLabelWidth) ? window->DC.CursorPos.x + text_width + padding.x : window->WorkRect.Max.x;
6883 frame_bb.Max.y = window->DC.CursorPos.y + (text_offset_y - padding.y) + frame_height;
6884 if (display_frame)
6885 {
6886 const float outer_extend = IM_TRUNC(window->WindowPadding.x * 0.5f); // Framed header expand a little outside of current limits
6887 frame_bb.Min.x -= outer_extend;
6888 frame_bb.Max.x += outer_extend;
6889 }
6890
6891 ImVec2 text_pos(window->DC.CursorPos.x + text_offset_x, window->DC.CursorPos.y + text_offset_y);
6892 ItemSize(ImVec2(text_width, frame_height), padding.y);
6893
6894 // For regular tree nodes, we arbitrary allow to click past 2 worth of ItemSpacing
6895 ImRect interact_bb = frame_bb;
6896 if ((flags & (ImGuiTreeNodeFlags_Framed | ImGuiTreeNodeFlags_SpanAvailWidth | ImGuiTreeNodeFlags_SpanFullWidth | ImGuiTreeNodeFlags_SpanLabelWidth | ImGuiTreeNodeFlags_SpanAllColumns)) == 0)
6897 interact_bb.Max.x = frame_bb.Min.x + text_width + (label_size.x > 0.0f ? style.ItemSpacing.x * 2.0f : 0.0f);
6898
6899 // Compute open and multi-select states before ItemAdd() as it clear NextItem data.
6900 ImGuiID storage_id = (g.NextItemData.HasFlags & ImGuiNextItemDataFlags_HasStorageID) ? g.NextItemData.StorageId : id;
6901 bool is_open = TreeNodeUpdateNextOpen(storage_id, flags);
6902
6903 bool is_visible;
6904 if (span_all_columns || span_all_columns_label)
6905 {
6906 // Modify ClipRect for the ItemAdd(), faster than doing a PushColumnsBackground/PushTableBackgroundChannel for every Selectable..
6907 const float backup_clip_rect_min_x = window->ClipRect.Min.x;
6908 const float backup_clip_rect_max_x = window->ClipRect.Max.x;
6909 window->ClipRect.Min.x = window->ParentWorkRect.Min.x;
6910 window->ClipRect.Max.x = window->ParentWorkRect.Max.x;
6911 is_visible = ItemAdd(interact_bb, id);

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected