When using public API, currently 'id == storage_id' is always true, but we separate the values to facilitate advanced user code doing storage queries outside of UI loop.
| 6753 | |
| 6754 | // When using public API, currently 'id == storage_id' is always true, but we separate the values to facilitate advanced user code doing storage queries outside of UI loop. |
| 6755 | bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* label, const char* label_end) |
| 6756 | { |
| 6757 | ImGuiWindow* window = GetCurrentWindow(); |
| 6758 | if (window->SkipItems) |
| 6759 | return false; |
| 6760 | |
| 6761 | ImGuiContext& g = *GImGui; |
| 6762 | const ImGuiStyle& style = g.Style; |
| 6763 | const bool display_frame = (flags & ImGuiTreeNodeFlags_Framed) != 0; |
| 6764 | const ImVec2 padding = (display_frame || (flags & ImGuiTreeNodeFlags_FramePadding)) ? style.FramePadding : ImVec2(style.FramePadding.x, ImMin(window->DC.CurrLineTextBaseOffset, style.FramePadding.y)); |
| 6765 | |
| 6766 | if (!label_end) |
| 6767 | label_end = FindRenderedTextEnd(label); |
| 6768 | const ImVec2 label_size = CalcTextSize(label, label_end, false); |
| 6769 | |
| 6770 | const float text_offset_x = g.FontSize + (display_frame ? padding.x * 3 : padding.x * 2); // Collapsing arrow width + Spacing |
| 6771 | const float text_offset_y = ImMax(padding.y, window->DC.CurrLineTextBaseOffset); // Latch before ItemSize changes it |
| 6772 | const float text_width = g.FontSize + label_size.x + padding.x * 2; // Include collapsing arrow |
| 6773 | |
| 6774 | // We vertically grow up to current line height up the typical widget height. |
| 6775 | const float frame_height = ImMax(ImMin(window->DC.CurrLineSize.y, g.FontSize + style.FramePadding.y * 2), label_size.y + padding.y * 2); |
| 6776 | const bool span_all_columns = (flags & ImGuiTreeNodeFlags_SpanAllColumns) != 0 && (g.CurrentTable != NULL); |
| 6777 | const bool span_all_columns_label = (flags & ImGuiTreeNodeFlags_LabelSpanAllColumns) != 0 && (g.CurrentTable != NULL); |
| 6778 | ImRect frame_bb; |
| 6779 | frame_bb.Min.x = span_all_columns ? window->ParentWorkRect.Min.x : (flags & ImGuiTreeNodeFlags_SpanFullWidth) ? window->WorkRect.Min.x : window->DC.CursorPos.x; |
| 6780 | frame_bb.Min.y = window->DC.CursorPos.y; |
| 6781 | 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; |
| 6782 | frame_bb.Max.y = window->DC.CursorPos.y + frame_height; |
| 6783 | if (display_frame) |
| 6784 | { |
| 6785 | const float outer_extend = IM_TRUNC(window->WindowPadding.x * 0.5f); // Framed header expand a little outside of current limits |
| 6786 | frame_bb.Min.x -= outer_extend; |
| 6787 | frame_bb.Max.x += outer_extend; |
| 6788 | } |
| 6789 | |
| 6790 | ImVec2 text_pos(window->DC.CursorPos.x + text_offset_x, window->DC.CursorPos.y + text_offset_y); |
| 6791 | ItemSize(ImVec2(text_width, frame_height), padding.y); |
| 6792 | |
| 6793 | // For regular tree nodes, we arbitrary allow to click past 2 worth of ItemSpacing |
| 6794 | ImRect interact_bb = frame_bb; |
| 6795 | if ((flags & (ImGuiTreeNodeFlags_Framed | ImGuiTreeNodeFlags_SpanAvailWidth | ImGuiTreeNodeFlags_SpanFullWidth | ImGuiTreeNodeFlags_SpanLabelWidth | ImGuiTreeNodeFlags_SpanAllColumns)) == 0) |
| 6796 | interact_bb.Max.x = frame_bb.Min.x + text_width + (label_size.x > 0.0f ? style.ItemSpacing.x * 2.0f : 0.0f); |
| 6797 | |
| 6798 | // Compute open and multi-select states before ItemAdd() as it clear NextItem data. |
| 6799 | ImGuiID storage_id = (g.NextItemData.HasFlags & ImGuiNextItemDataFlags_HasStorageID) ? g.NextItemData.StorageId : id; |
| 6800 | bool is_open = TreeNodeUpdateNextOpen(storage_id, flags); |
| 6801 | |
| 6802 | bool is_visible; |
| 6803 | if (span_all_columns || span_all_columns_label) |
| 6804 | { |
| 6805 | // Modify ClipRect for the ItemAdd(), faster than doing a PushColumnsBackground/PushTableBackgroundChannel for every Selectable.. |
| 6806 | const float backup_clip_rect_min_x = window->ClipRect.Min.x; |
| 6807 | const float backup_clip_rect_max_x = window->ClipRect.Max.x; |
| 6808 | window->ClipRect.Min.x = window->ParentWorkRect.Min.x; |
| 6809 | window->ClipRect.Max.x = window->ParentWorkRect.Max.x; |
| 6810 | is_visible = ItemAdd(interact_bb, id); |
| 6811 | window->ClipRect.Min.x = backup_clip_rect_min_x; |
| 6812 | window->ClipRect.Max.x = backup_clip_rect_max_x; |
nothing calls this directly
no test coverage detected