MCPcopy Create free account
hub / github.com/RenderKit/embree / CalcWindowAutoFitSize

Function CalcWindowAutoFitSize

tutorials/common/imgui/imgui.cpp:5769–5804  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5767}
5768
5769static ImVec2 CalcWindowAutoFitSize(ImGuiWindow* window, const ImVec2& size_contents)
5770{
5771 ImGuiContext& g = *GImGui;
5772 ImGuiStyle& style = g.Style;
5773 const float decoration_up_height = window->TitleBarHeight() + window->MenuBarHeight();
5774 ImVec2 size_pad = window->WindowPadding * 2.0f;
5775 ImVec2 size_desired = size_contents + size_pad + ImVec2(0.0f, decoration_up_height);
5776 if (window->Flags & ImGuiWindowFlags_Tooltip)
5777 {
5778 // Tooltip always resize
5779 return size_desired;
5780 }
5781 else
5782 {
5783 // Maximum window size is determined by the viewport size or monitor size
5784 const bool is_popup = (window->Flags & ImGuiWindowFlags_Popup) != 0;
5785 const bool is_menu = (window->Flags & ImGuiWindowFlags_ChildMenu) != 0;
5786 ImVec2 size_min = style.WindowMinSize;
5787 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)
5788 size_min = ImMin(size_min, ImVec2(4.0f, 4.0f));
5789
5790 ImVec2 avail_size = ImGui::GetMainViewport()->WorkSize;
5791 ImVec2 size_auto_fit = ImClamp(size_desired, size_min, ImMax(size_min, avail_size - style.DisplaySafeAreaPadding * 2.0f));
5792
5793 // When the window cannot fit all contents (either because of constraints, either because screen is too small),
5794 // we are growing the size on the other axis to compensate for expected scrollbar. FIXME: Might turn bigger than ViewportSize-WindowPadding.
5795 ImVec2 size_auto_fit_after_constraint = CalcWindowSizeAfterConstraint(window, size_auto_fit);
5796 bool will_have_scrollbar_x = (size_auto_fit_after_constraint.x - size_pad.x - 0.0f < size_contents.x && !(window->Flags & ImGuiWindowFlags_NoScrollbar) && (window->Flags & ImGuiWindowFlags_HorizontalScrollbar)) || (window->Flags & ImGuiWindowFlags_AlwaysHorizontalScrollbar);
5797 bool will_have_scrollbar_y = (size_auto_fit_after_constraint.y - size_pad.y - decoration_up_height < size_contents.y && !(window->Flags & ImGuiWindowFlags_NoScrollbar)) || (window->Flags & ImGuiWindowFlags_AlwaysVerticalScrollbar);
5798 if (will_have_scrollbar_x)
5799 size_auto_fit.y += style.ScrollbarSize;
5800 if (will_have_scrollbar_y)
5801 size_auto_fit.x += style.ScrollbarSize;
5802 return size_auto_fit;
5803 }
5804}
5805
5806ImVec2 ImGui::CalcWindowNextAutoFitSize(ImGuiWindow* window)
5807{

Callers 2

BeginMethod · 0.85

Calls 5

ImVec2Function · 0.85
ImMinFunction · 0.85
ImClampFunction · 0.85
ImMaxFunction · 0.85

Tested by

no test coverage detected