MCPcopy Create free account
hub / github.com/KebsCS/KBotExt / CalcWindowAutoFitSize

Function CalcWindowAutoFitSize

KBotExt/imgui/imgui.cpp:5654–5690  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5652}
5653
5654static ImVec2 CalcWindowAutoFitSize(ImGuiWindow* window, const ImVec2& size_contents)
5655{
5656 ImGuiContext& g = *GImGui;
5657 ImGuiStyle& style = g.Style;
5658 const float decoration_w_without_scrollbars = window->DecoOuterSizeX1 + window->DecoOuterSizeX2 - window->ScrollbarSizes.x;
5659 const float decoration_h_without_scrollbars = window->DecoOuterSizeY1 + window->DecoOuterSizeY2 - window->ScrollbarSizes.y;
5660 ImVec2 size_pad = window->WindowPadding * 2.0f;
5661 ImVec2 size_desired = size_contents + size_pad + ImVec2(decoration_w_without_scrollbars, decoration_h_without_scrollbars);
5662 if (window->Flags & ImGuiWindowFlags_Tooltip)
5663 {
5664 // Tooltip always resize
5665 return size_desired;
5666 }
5667 else
5668 {
5669 // Maximum window size is determined by the viewport size or monitor size
5670 const bool is_popup = (window->Flags & ImGuiWindowFlags_Popup) != 0;
5671 const bool is_menu = (window->Flags & ImGuiWindowFlags_ChildMenu) != 0;
5672 ImVec2 size_min = style.WindowMinSize;
5673 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)
5674 size_min = ImMin(size_min, ImVec2(4.0f, 4.0f));
5675
5676 ImVec2 avail_size = ImGui::GetMainViewport()->WorkSize;
5677 ImVec2 size_auto_fit = ImClamp(size_desired, size_min, ImMax(size_min, avail_size - style.DisplaySafeAreaPadding * 2.0f));
5678
5679 // When the window cannot fit all contents (either because of constraints, either because screen is too small),
5680 // we are growing the size on the other axis to compensate for expected scrollbar. FIXME: Might turn bigger than ViewportSize-WindowPadding.
5681 ImVec2 size_auto_fit_after_constraint = CalcWindowSizeAfterConstraint(window, size_auto_fit);
5682 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);
5683 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);
5684 if (will_have_scrollbar_x)
5685 size_auto_fit.y += style.ScrollbarSize;
5686 if (will_have_scrollbar_y)
5687 size_auto_fit.x += style.ScrollbarSize;
5688 return size_auto_fit;
5689 }
5690}
5691
5692ImVec2 ImGui::CalcWindowNextAutoFitSize(ImGuiWindow* window)
5693{

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