MCPcopy Create free account
hub / github.com/danoon2/Boxedwine / CalcWindowAutoFitSize

Function CalcWindowAutoFitSize

lib/imgui/imgui.cpp:4867–4900  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4865}
4866
4867static ImVec2 CalcWindowAutoFitSize(ImGuiWindow* window, const ImVec2& size_contents)
4868{
4869 ImGuiContext& g = *GImGui;
4870 ImGuiStyle& style = g.Style;
4871 ImVec2 size_decorations = ImVec2(0.0f, window->TitleBarHeight() + window->MenuBarHeight());
4872 ImVec2 size_pad = window->WindowPadding * 2.0f;
4873 ImVec2 size_desired = size_contents + size_pad + size_decorations;
4874 if (window->Flags & ImGuiWindowFlags_Tooltip)
4875 {
4876 // Tooltip always resize
4877 return size_desired;
4878 }
4879 else
4880 {
4881 // Maximum window size is determined by the viewport size or monitor size
4882 const bool is_popup = (window->Flags & ImGuiWindowFlags_Popup) != 0;
4883 const bool is_menu = (window->Flags & ImGuiWindowFlags_ChildMenu) != 0;
4884 ImVec2 size_min = style.WindowMinSize;
4885 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)
4886 size_min = ImMin(size_min, ImVec2(4.0f, 4.0f));
4887 ImVec2 size_auto_fit = ImClamp(size_desired, size_min, ImMax(size_min, g.IO.DisplaySize - style.DisplaySafeAreaPadding * 2.0f));
4888
4889 // When the window cannot fit all contents (either because of constraints, either because screen is too small),
4890 // we are growing the size on the other axis to compensate for expected scrollbar. FIXME: Might turn bigger than ViewportSize-WindowPadding.
4891 ImVec2 size_auto_fit_after_constraint = CalcWindowSizeAfterConstraint(window, size_auto_fit);
4892 bool will_have_scrollbar_x = (size_auto_fit_after_constraint.x - size_pad.x - size_decorations.x < size_contents.x && !(window->Flags & ImGuiWindowFlags_NoScrollbar) && (window->Flags & ImGuiWindowFlags_HorizontalScrollbar)) || (window->Flags & ImGuiWindowFlags_AlwaysHorizontalScrollbar);
4893 bool will_have_scrollbar_y = (size_auto_fit_after_constraint.y - size_pad.y - size_decorations.y < size_contents.y && !(window->Flags & ImGuiWindowFlags_NoScrollbar)) || (window->Flags & ImGuiWindowFlags_AlwaysVerticalScrollbar);
4894 if (will_have_scrollbar_x)
4895 size_auto_fit.y += style.ScrollbarSize;
4896 if (will_have_scrollbar_y)
4897 size_auto_fit.x += style.ScrollbarSize;
4898 return size_auto_fit;
4899 }
4900}
4901
4902ImVec2 ImGui::CalcWindowExpectedSize(ImGuiWindow* window)
4903{

Callers 2

BeginMethod · 0.85

Calls 5

ImVec2Class · 0.85
ImMinFunction · 0.85
ImClampFunction · 0.85
ImMaxFunction · 0.85

Tested by

no test coverage detected