From f142887088c9e94f17aa5a5b263b30add5d6a10a Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 31 Jan 2023 11:23:24 +0100 Subject: [PATCH] Combo: Allow SetNextWindowSize() to alter combo popup size. (#6130) Amend a5e939214 --- docs/CHANGELOG.txt | 1 + imgui_widgets.cpp | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 1e2278b03..31f1fee65 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -52,6 +52,7 @@ All changes: - InputText: On OSX, inhibit usage of Alt key to toggle menu when active (used for work skip). - Menus: Fixed layout of MenuItem()/BeginMenu() when label contains a '\n'. (#6116) [@imkcy9] - PlotHistogram, PlotLines: Passing negative sizes honor alignment like other widgets. +- Combo: Allow SetNextWindowSize() to alter combo popup size. (#6130) - ImDrawList: Added missing early-out in AddPolyline() and AddConvexPolyFilled() when color alpha is zero. - Misc: Most text functions treat "%s" as a shortcut to no-formatting. (#3466) diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 4e80c9d0f..9fcf9718c 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -1695,7 +1695,12 @@ bool ImGui::BeginComboPopup(ImGuiID popup_id, const ImRect& bb, ImGuiComboFlags if (flags & ImGuiComboFlags_HeightRegular) popup_max_height_in_items = 8; else if (flags & ImGuiComboFlags_HeightSmall) popup_max_height_in_items = 4; else if (flags & ImGuiComboFlags_HeightLarge) popup_max_height_in_items = 20; - SetNextWindowSizeConstraints(ImVec2(w, 0.0f), ImVec2(FLT_MAX, CalcMaxPopupHeightFromItemCount(popup_max_height_in_items))); + ImVec2 constraint_min(0.0f, 0.0f), constraint_max(FLT_MAX, FLT_MAX); + if ((g.NextWindowData.Flags & ImGuiNextWindowDataFlags_HasSize) == 0 || g.NextWindowData.SizeVal.x <= 0.0f) // Don't apply constraints if user specified a size + constraint_min.x = w; + if ((g.NextWindowData.Flags & ImGuiNextWindowDataFlags_HasSize) == 0 || g.NextWindowData.SizeVal.y <= 0.0f) + constraint_max.y = CalcMaxPopupHeightFromItemCount(popup_max_height_in_items); + SetNextWindowSizeConstraints(constraint_min, constraint_max); } // This is essentially a specialized version of BeginPopupEx()