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

Method BeginComboPopup

KBotExt/imgui/imgui_widgets.cpp:1746–1808  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1744}
1745
1746bool ImGui::BeginComboPopup(ImGuiID popup_id, const ImRect& bb, ImGuiComboFlags flags)
1747{
1748 ImGuiContext& g = *GImGui;
1749 if (!IsPopupOpen(popup_id, ImGuiPopupFlags_None))
1750 {
1751 g.NextWindowData.ClearFlags();
1752 return false;
1753 }
1754
1755 // Set popup size
1756 float w = bb.GetWidth();
1757 if (g.NextWindowData.Flags & ImGuiNextWindowDataFlags_HasSizeConstraint)
1758 {
1759 g.NextWindowData.SizeConstraintRect.Min.x = ImMax(g.NextWindowData.SizeConstraintRect.Min.x, w);
1760 }
1761 else
1762 {
1763 if ((flags & ImGuiComboFlags_HeightMask_) == 0)
1764 flags |= ImGuiComboFlags_HeightRegular;
1765 IM_ASSERT(ImIsPowerOfTwo(flags & ImGuiComboFlags_HeightMask_)); // Only one
1766 int popup_max_height_in_items = -1;
1767 if (flags & ImGuiComboFlags_HeightRegular) popup_max_height_in_items = 8;
1768 else if (flags & ImGuiComboFlags_HeightSmall) popup_max_height_in_items = 4;
1769 else if (flags & ImGuiComboFlags_HeightLarge) popup_max_height_in_items = 20;
1770 ImVec2 constraint_min(0.0f, 0.0f), constraint_max(FLT_MAX, FLT_MAX);
1771 if ((g.NextWindowData.Flags & ImGuiNextWindowDataFlags_HasSize) == 0 || g.NextWindowData.SizeVal.x <= 0.0f) // Don't apply constraints if user specified a size
1772 constraint_min.x = w;
1773 if ((g.NextWindowData.Flags & ImGuiNextWindowDataFlags_HasSize) == 0 || g.NextWindowData.SizeVal.y <= 0.0f)
1774 constraint_max.y = CalcMaxPopupHeightFromItemCount(popup_max_height_in_items);
1775 SetNextWindowSizeConstraints(constraint_min, constraint_max);
1776 }
1777
1778 // This is essentially a specialized version of BeginPopupEx()
1779 char name[16];
1780 ImFormatString(name, IM_ARRAYSIZE(name), "##Combo_%02d", g.BeginPopupStack.Size); // Recycle windows based on depth
1781
1782 // Set position given a custom constraint (peak into expected window size so we can position it)
1783 // FIXME: This might be easier to express with an hypothetical SetNextWindowPosConstraints() function?
1784 // FIXME: This might be moved to Begin() or at least around the same spot where Tooltips and other Popups are calling FindBestWindowPosForPopupEx()?
1785 if (ImGuiWindow* popup_window = FindWindowByName(name))
1786 if (popup_window->WasActive)
1787 {
1788 // Always override 'AutoPosLastDirection' to not leave a chance for a past value to affect us.
1789 ImVec2 size_expected = CalcWindowNextAutoFitSize(popup_window);
1790 popup_window->AutoPosLastDirection = (flags & ImGuiComboFlags_PopupAlignLeft) ? ImGuiDir_Left : ImGuiDir_Down; // Left = "Below, Toward Left", Down = "Below, Toward Right (default)"
1791 ImRect r_outer = GetPopupAllowedExtentRect(popup_window);
1792 ImVec2 pos = FindBestWindowPosForPopupEx(bb.GetBL(), size_expected, &popup_window->AutoPosLastDirection, r_outer, bb, ImGuiPopupPositionPolicy_ComboBox);
1793 SetNextWindowPos(pos);
1794 }
1795
1796 // We don't use BeginPopupEx() solely because we have a custom name string, which we could make an argument to BeginPopupEx()
1797 ImGuiWindowFlags window_flags = ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_Popup | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoMove;
1798 PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(g.Style.FramePadding.x, g.Style.WindowPadding.y)); // Horizontally align ourselves with the framed text
1799 bool ret = Begin(name, NULL, window_flags);
1800 PopStyleVar();
1801 if (!ret)
1802 {
1803 EndPopup();

Callers

nothing calls this directly

Calls 6

ImMaxFunction · 0.85
ImIsPowerOfTwoFunction · 0.85
ImFormatStringFunction · 0.85
ImVec2Function · 0.85
ClearFlagsMethod · 0.45

Tested by

no test coverage detected