| 5228 | } |
| 5229 | |
| 5230 | static ImVec2 CalcWindowAutoFitSize(ImGuiWindow* window, const ImVec2& size_contents) |
| 5231 | { |
| 5232 | ImGuiContext& g = *GImGui; |
| 5233 | ImGuiStyle& style = g.Style; |
| 5234 | const float decoration_up_height = window->TitleBarHeight() + window->MenuBarHeight(); |
| 5235 | ImVec2 size_pad = window->WindowPadding * 2.0f; |
| 5236 | ImVec2 size_desired = size_contents + size_pad + ImVec2(0.0f, decoration_up_height); |
| 5237 | if (window->Flags & ImGuiWindowFlags_Tooltip) |
| 5238 | { |
| 5239 | // Tooltip always resize |
| 5240 | return size_desired; |
| 5241 | } |
| 5242 | else |
| 5243 | { |
| 5244 | // Maximum window size is determined by the viewport size or monitor size |
| 5245 | const bool is_popup = (window->Flags & ImGuiWindowFlags_Popup) != 0; |
| 5246 | const bool is_menu = (window->Flags & ImGuiWindowFlags_ChildMenu) != 0; |
| 5247 | ImVec2 size_min = style.WindowMinSize; |
| 5248 | 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) |
| 5249 | size_min = ImMin(size_min, ImVec2(4.0f, 4.0f)); |
| 5250 | |
| 5251 | // FIXME-VIEWPORT-WORKAREA: May want to use GetWorkSize() instead of Size depending on the type of windows? |
| 5252 | ImVec2 avail_size = ImGui::GetMainViewport()->Size; |
| 5253 | ImVec2 size_auto_fit = ImClamp(size_desired, size_min, ImMax(size_min, avail_size - style.DisplaySafeAreaPadding * 2.0f)); |
| 5254 | |
| 5255 | // When the window cannot fit all contents (either because of constraints, either because screen is too small), |
| 5256 | // we are growing the size on the other axis to compensate for expected scrollbar. FIXME: Might turn bigger than ViewportSize-WindowPadding. |
| 5257 | ImVec2 size_auto_fit_after_constraint = CalcWindowSizeAfterConstraint(window, size_auto_fit); |
| 5258 | 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); |
| 5259 | 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); |
| 5260 | if (will_have_scrollbar_x) |
| 5261 | size_auto_fit.y += style.ScrollbarSize; |
| 5262 | if (will_have_scrollbar_y) |
| 5263 | size_auto_fit.x += style.ScrollbarSize; |
| 5264 | return size_auto_fit; |
| 5265 | } |
| 5266 | } |
| 5267 | |
| 5268 | ImVec2 ImGui::CalcWindowNextAutoFitSize(ImGuiWindow* window) |
| 5269 | { |
no test coverage detected