MCPcopy Create free account
hub / github.com/KebsCS/KBotExt / BeginCombo

Method BeginCombo

KBotExt/imgui/imgui_widgets.cpp:1671–1744  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1669}
1670
1671bool ImGui::BeginCombo(const char* label, const char* preview_value, ImGuiComboFlags flags)
1672{
1673 ImGuiContext& g = *GImGui;
1674 ImGuiWindow* window = GetCurrentWindow();
1675
1676 ImGuiNextWindowDataFlags backup_next_window_data_flags = g.NextWindowData.Flags;
1677 g.NextWindowData.ClearFlags(); // We behave like Begin() and need to consume those values
1678 if (window->SkipItems)
1679 return false;
1680
1681 const ImGuiStyle& style = g.Style;
1682 const ImGuiID id = window->GetID(label);
1683 IM_ASSERT((flags & (ImGuiComboFlags_NoArrowButton | ImGuiComboFlags_NoPreview)) != (ImGuiComboFlags_NoArrowButton | ImGuiComboFlags_NoPreview)); // Can't use both flags together
1684
1685 const float arrow_size = (flags & ImGuiComboFlags_NoArrowButton) ? 0.0f : GetFrameHeight();
1686 const ImVec2 label_size = CalcTextSize(label, NULL, true);
1687 const float w = (flags & ImGuiComboFlags_NoPreview) ? arrow_size : CalcItemWidth();
1688 const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y + style.FramePadding.y * 2.0f));
1689 const ImRect total_bb(bb.Min, bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f));
1690 ItemSize(total_bb, style.FramePadding.y);
1691 if (!ItemAdd(total_bb, id, &bb))
1692 return false;
1693
1694 // Open on click
1695 bool hovered, held;
1696 bool pressed = ButtonBehavior(bb, id, &hovered, &held);
1697 const ImGuiID popup_id = ImHashStr("##ComboPopup", 0, id);
1698 bool popup_open = IsPopupOpen(popup_id, ImGuiPopupFlags_None);
1699 if (pressed && !popup_open)
1700 {
1701 OpenPopupEx(popup_id, ImGuiPopupFlags_None);
1702 popup_open = true;
1703 }
1704
1705 // Render shape
1706 const ImU32 frame_col = GetColorU32(hovered ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg);
1707 const float value_x2 = ImMax(bb.Min.x, bb.Max.x - arrow_size);
1708 RenderNavHighlight(bb, id);
1709 if (!(flags & ImGuiComboFlags_NoPreview))
1710 window->DrawList->AddRectFilled(bb.Min, ImVec2(value_x2, bb.Max.y), frame_col, style.FrameRounding, (flags & ImGuiComboFlags_NoArrowButton) ? ImDrawFlags_RoundCornersAll : ImDrawFlags_RoundCornersLeft);
1711 if (!(flags & ImGuiComboFlags_NoArrowButton))
1712 {
1713 ImU32 bg_col = GetColorU32((popup_open || hovered) ? ImGuiCol_ButtonHovered : ImGuiCol_Button);
1714 ImU32 text_col = GetColorU32(ImGuiCol_Text);
1715 window->DrawList->AddRectFilled(ImVec2(value_x2, bb.Min.y), bb.Max, bg_col, style.FrameRounding, (w <= arrow_size) ? ImDrawFlags_RoundCornersAll : ImDrawFlags_RoundCornersRight);
1716 if (value_x2 + arrow_size - style.FramePadding.x <= bb.Max.x)
1717 RenderArrow(window->DrawList, ImVec2(value_x2 + style.FramePadding.y, bb.Min.y + style.FramePadding.y), text_col, ImGuiDir_Down, 1.0f);
1718 }
1719 RenderFrameBorder(bb.Min, bb.Max, style.FrameRounding);
1720
1721 // Custom preview
1722 if (flags & ImGuiComboFlags_CustomPreview)
1723 {
1724 g.ComboPreviewData.PreviewRect = ImRect(bb.Min.x, bb.Min.y, value_x2, bb.Max.y);
1725 IM_ASSERT(preview_value == NULL || preview_value[0] == 0);
1726 preview_value = NULL;
1727 }
1728

Callers

nothing calls this directly

Calls 9

GetCurrentWindowFunction · 0.85
ImVec2Function · 0.85
ItemSizeFunction · 0.85
ImHashStrFunction · 0.85
ImMaxFunction · 0.85
GetIDMethod · 0.80
AddRectFilledMethod · 0.80
ImRectFunction · 0.70
ClearFlagsMethod · 0.45

Tested by

no test coverage detected