| 7043 | } |
| 7044 | |
| 7045 | static ImVec2 CalcWindowAutoFitSize(ImGuiWindow* window, const ImVec2& size_contents, int axis_mask) |
| 7046 | { |
| 7047 | ImGuiContext& g = *GImGui; |
| 7048 | ImGuiStyle& style = g.Style; |
| 7049 | const float decoration_w_without_scrollbars = window->DecoOuterSizeX1 + window->DecoOuterSizeX2 - window->ScrollbarSizes.x; |
| 7050 | const float decoration_h_without_scrollbars = window->DecoOuterSizeY1 + window->DecoOuterSizeY2 - window->ScrollbarSizes.y; |
| 7051 | ImVec2 size_pad = window->WindowPadding * 2.0f; |
| 7052 | ImVec2 size_desired; |
| 7053 | size_desired[ImGuiAxis_X] = (axis_mask & 1) ? size_contents.x + size_pad.x + decoration_w_without_scrollbars : window->Size.x; |
| 7054 | size_desired[ImGuiAxis_Y] = (axis_mask & 2) ? size_contents.y + size_pad.y + decoration_h_without_scrollbars : window->Size.y; |
| 7055 | |
| 7056 | // Determine maximum window size |
| 7057 | // Child windows are laid within their parent (unless they are also popups/menus) and thus have no restriction |
| 7058 | ImVec2 size_max = ImVec2(FLT_MAX, FLT_MAX); |
| 7059 | if ((window->Flags & ImGuiWindowFlags_ChildWindow) == 0 || (window->Flags & ImGuiWindowFlags_Popup) != 0) |
| 7060 | { |
| 7061 | if (!window->ViewportOwned) |
| 7062 | size_max = ImGui::GetMainViewport()->WorkSize - style.DisplaySafeAreaPadding * 2.0f; |
| 7063 | const int monitor_idx = window->ViewportAllowPlatformMonitorExtend; |
| 7064 | if (monitor_idx >= 0 && monitor_idx < g.PlatformIO.Monitors.Size) |
| 7065 | size_max = g.PlatformIO.Monitors[monitor_idx].WorkSize - style.DisplaySafeAreaPadding * 2.0f; |
| 7066 | } |
| 7067 | |
| 7068 | if (window->Flags & ImGuiWindowFlags_Tooltip) |
| 7069 | { |
| 7070 | // Tooltip always resize (up to maximum size) |
| 7071 | return ImMin(size_desired, size_max); |
| 7072 | } |
| 7073 | else |
| 7074 | { |
| 7075 | ImVec2 size_min = CalcWindowMinSize(window); |
| 7076 | ImVec2 size_auto_fit = ImClamp(size_desired, ImMin(size_min, size_max), size_max); |
| 7077 | |
| 7078 | // When the window cannot fit all contents (either because of constraints, either because screen is too small), |
| 7079 | // we are growing the size on the other axis to compensate for expected scrollbar. FIXME: Might turn bigger than ViewportSize-WindowPadding. |
| 7080 | ImVec2 size_auto_fit_after_constraint = CalcWindowSizeAfterConstraint(window, size_auto_fit); |
| 7081 | 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); |
| 7082 | 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); |
| 7083 | if (will_have_scrollbar_x) |
| 7084 | size_auto_fit.y += style.ScrollbarSize; |
| 7085 | if (will_have_scrollbar_y) |
| 7086 | size_auto_fit.x += style.ScrollbarSize; |
| 7087 | return size_auto_fit; |
| 7088 | } |
| 7089 | } |
| 7090 | |
| 7091 | ImVec2 ImGui::CalcWindowNextAutoFitSize(ImGuiWindow* window) |
| 7092 | { |
no test coverage detected