Browse Source

Combo: Allow SetNextWindowSize() to alter combo popup size. (#6130)

Amend a5e939214
ocornut 2 years ago
parent
commit
f142887088
2 changed files with 7 additions and 1 deletions
  1. 1 0
      docs/CHANGELOG.txt
  2. 6 1
      imgui_widgets.cpp

+ 1 - 0
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)

+ 6 - 1
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()