Skip to content

Commit e2035a5

Browse files
committed
Windows: shared code for CalcWindowMinSize().
+ Don't apply WindowMinSize during auto-fit of child windows (not exercised yet).
1 parent c95fbb4 commit e2035a5

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

imgui.cpp

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5646,6 +5646,24 @@ static ImGuiWindow* CreateNewWindow(const char* name, ImGuiWindowFlags flags)
56465646
return window;
56475647
}
56485648

5649+
static inline ImVec2 CalcWindowMinSize(ImGuiWindow* window)
5650+
{
5651+
// Popups, menus and childs bypass style.WindowMinSize by default, but we give then a non-zero minimum size to facilitate understanding problematic cases (e.g. empty popups)
5652+
ImGuiContext& g = *GImGui;
5653+
ImVec2 size_min;
5654+
if (window->Flags & (ImGuiWindowFlags_Popup | ImGuiWindowFlags_ChildMenu | ImGuiWindowFlags_ChildWindow))
5655+
{
5656+
size_min = ImVec2(4.0f, 4.0f);
5657+
}
5658+
else
5659+
{
5660+
ImGuiWindow* window_for_height = window;
5661+
size_min = g.Style.WindowMinSize;
5662+
size_min.y = ImMax(size_min.y, window_for_height->TitleBarHeight() + window_for_height->MenuBarHeight() + ImMax(0.0f, g.Style.WindowRounding - 1.0f)); // Reduce artifacts with very small windows
5663+
}
5664+
return size_min;
5665+
}
5666+
56495667
static ImVec2 CalcWindowSizeAfterConstraint(ImGuiWindow* window, const ImVec2& size_desired)
56505668
{
56515669
ImGuiContext& g = *GImGui;
@@ -5671,14 +5689,8 @@ static ImVec2 CalcWindowSizeAfterConstraint(ImGuiWindow* window, const ImVec2& s
56715689
}
56725690

56735691
// Minimum size
5674-
if (!(window->Flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_AlwaysAutoResize)))
5675-
{
5676-
ImGuiWindow* window_for_height = window;
5677-
new_size = ImMax(new_size, g.Style.WindowMinSize);
5678-
const float minimum_height = window_for_height->TitleBarHeight() + window_for_height->MenuBarHeight() + ImMax(0.0f, g.Style.WindowRounding - 1.0f);
5679-
new_size.y = ImMax(new_size.y, minimum_height); // Reduce artifacts with very small windows
5680-
}
5681-
return new_size;
5692+
ImVec2 size_min = CalcWindowMinSize(window);
5693+
return ImMax(new_size, size_min);
56825694
}
56835695

56845696
static void CalcWindowContentSizes(ImGuiWindow* window, ImVec2* content_size_current, ImVec2* content_size_ideal)
@@ -5717,12 +5729,7 @@ static ImVec2 CalcWindowAutoFitSize(ImGuiWindow* window, const ImVec2& size_cont
57175729
else
57185730
{
57195731
// Maximum window size is determined by the viewport size or monitor size
5720-
const bool is_popup = (window->Flags & ImGuiWindowFlags_Popup) != 0;
5721-
const bool is_menu = (window->Flags & ImGuiWindowFlags_ChildMenu) != 0;
5722-
ImVec2 size_min = style.WindowMinSize;
5723-
if (is_popup || is_menu) // Popups and menus bypass style.WindowMinSize by default, but we give then a non-zero minimum size to facilitate understanding problematic cases (e.g. empty popups)
5724-
size_min = ImMin(size_min, ImVec2(4.0f, 4.0f));
5725-
5732+
ImVec2 size_min = CalcWindowMinSize(window);
57265733
ImVec2 avail_size = ImGui::GetMainViewport()->WorkSize;
57275734
ImVec2 size_auto_fit = ImClamp(size_desired, size_min, ImMax(size_min, avail_size - style.DisplaySafeAreaPadding * 2.0f));
57285735

0 commit comments

Comments
 (0)