Skip to content

Commit

Permalink
Windows: shared code for CalcWindowMinSize().
Browse files Browse the repository at this point in the history
+ Don't apply WindowMinSize during auto-fit of child windows (not exercised yet).
  • Loading branch information
ocornut committed Oct 19, 2023
1 parent c95fbb4 commit e2035a5
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5646,6 +5646,24 @@ static ImGuiWindow* CreateNewWindow(const char* name, ImGuiWindowFlags flags)
return window;
}

static inline ImVec2 CalcWindowMinSize(ImGuiWindow* window)
{
// 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)
ImGuiContext& g = *GImGui;
ImVec2 size_min;
if (window->Flags & (ImGuiWindowFlags_Popup | ImGuiWindowFlags_ChildMenu | ImGuiWindowFlags_ChildWindow))
{
size_min = ImVec2(4.0f, 4.0f);
}
else
{
ImGuiWindow* window_for_height = window;
size_min = g.Style.WindowMinSize;
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
}
return size_min;
}

static ImVec2 CalcWindowSizeAfterConstraint(ImGuiWindow* window, const ImVec2& size_desired)
{
ImGuiContext& g = *GImGui;
Expand All @@ -5671,14 +5689,8 @@ static ImVec2 CalcWindowSizeAfterConstraint(ImGuiWindow* window, const ImVec2& s
}

// Minimum size
if (!(window->Flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_AlwaysAutoResize)))
{
ImGuiWindow* window_for_height = window;
new_size = ImMax(new_size, g.Style.WindowMinSize);
const float minimum_height = window_for_height->TitleBarHeight() + window_for_height->MenuBarHeight() + ImMax(0.0f, g.Style.WindowRounding - 1.0f);
new_size.y = ImMax(new_size.y, minimum_height); // Reduce artifacts with very small windows
}
return new_size;
ImVec2 size_min = CalcWindowMinSize(window);
return ImMax(new_size, size_min);
}

static void CalcWindowContentSizes(ImGuiWindow* window, ImVec2* content_size_current, ImVec2* content_size_ideal)
Expand Down Expand Up @@ -5717,12 +5729,7 @@ static ImVec2 CalcWindowAutoFitSize(ImGuiWindow* window, const ImVec2& size_cont
else
{
// Maximum window size is determined by the viewport size or monitor size
const bool is_popup = (window->Flags & ImGuiWindowFlags_Popup) != 0;
const bool is_menu = (window->Flags & ImGuiWindowFlags_ChildMenu) != 0;
ImVec2 size_min = style.WindowMinSize;
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)
size_min = ImMin(size_min, ImVec2(4.0f, 4.0f));

ImVec2 size_min = CalcWindowMinSize(window);
ImVec2 avail_size = ImGui::GetMainViewport()->WorkSize;
ImVec2 size_auto_fit = ImClamp(size_desired, size_min, ImMax(size_min, avail_size - style.DisplaySafeAreaPadding * 2.0f));

Expand Down

0 comments on commit e2035a5

Please sign in to comment.