MCPcopy Create free account
hub / github.com/clementgallet/libTAS / CalcWindowAutoFitSize

Function CalcWindowAutoFitSize

src/external/imgui/imgui.cpp:5732–5763  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5730}
5731
5732static ImVec2 CalcWindowAutoFitSize(ImGuiWindow* window, const ImVec2& size_contents)
5733{
5734 ImGuiContext& g = *GImGui;
5735 ImGuiStyle& style = g.Style;
5736 const float decoration_w_without_scrollbars = window->DecoOuterSizeX1 + window->DecoOuterSizeX2 - window->ScrollbarSizes.x;
5737 const float decoration_h_without_scrollbars = window->DecoOuterSizeY1 + window->DecoOuterSizeY2 - window->ScrollbarSizes.y;
5738 ImVec2 size_pad = window->WindowPadding * 2.0f;
5739 ImVec2 size_desired = size_contents + size_pad + ImVec2(decoration_w_without_scrollbars, decoration_h_without_scrollbars);
5740 if (window->Flags & ImGuiWindowFlags_Tooltip)
5741 {
5742 // Tooltip always resize
5743 return size_desired;
5744 }
5745 else
5746 {
5747 // Maximum window size is determined by the viewport size or monitor size
5748 ImVec2 size_min = CalcWindowMinSize(window);
5749 ImVec2 size_max = (window->Flags & ImGuiWindowFlags_ChildWindow) ? ImVec2(FLT_MAX, FLT_MAX) : ImGui::GetMainViewport()->WorkSize - style.DisplaySafeAreaPadding * 2.0f;
5750 ImVec2 size_auto_fit = ImClamp(size_desired, size_min, size_max);
5751
5752 // When the window cannot fit all contents (either because of constraints, either because screen is too small),
5753 // we are growing the size on the other axis to compensate for expected scrollbar. FIXME: Might turn bigger than ViewportSize-WindowPadding.
5754 ImVec2 size_auto_fit_after_constraint = CalcWindowSizeAfterConstraint(window, size_auto_fit);
5755 bool will_have_scrollbar_x = (size_auto_fit_after_constraint.x - size_pad.x - decoration_w_without_scrollbars < size_contents.x && !(window->Flags & ImGuiWindowFlags_NoScrollbar) && (window->Flags & ImGuiWindowFlags_HorizontalScrollbar)) || (window->Flags & ImGuiWindowFlags_AlwaysHorizontalScrollbar);
5756 bool will_have_scrollbar_y = (size_auto_fit_after_constraint.y - size_pad.y - decoration_h_without_scrollbars < size_contents.y && !(window->Flags & ImGuiWindowFlags_NoScrollbar)) || (window->Flags & ImGuiWindowFlags_AlwaysVerticalScrollbar);
5757 if (will_have_scrollbar_x)
5758 size_auto_fit.y += style.ScrollbarSize;
5759 if (will_have_scrollbar_y)
5760 size_auto_fit.x += style.ScrollbarSize;
5761 return size_auto_fit;
5762 }
5763}
5764
5765ImVec2 ImGui::CalcWindowNextAutoFitSize(ImGuiWindow* window)
5766{

Callers 2

BeginMethod · 0.85

Calls 4

ImVec2Function · 0.85
CalcWindowMinSizeFunction · 0.85
ImClampFunction · 0.85

Tested by

no test coverage detected