MCPcopy Create free account
hub / github.com/DISTRHO/Cardinal / CalcWindowAutoFitSize

Function CalcWindowAutoFitSize

plugins/Cardinal/src/DearImGui/imgui.cpp:5416–5452  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5414}
5415
5416static ImVec2 CalcWindowAutoFitSize(ImGuiWindow* window, const ImVec2& size_contents)
5417{
5418 ImGuiContext& g = *GImGui;
5419 ImGuiStyle& style = g.Style;
5420 const float decoration_up_height = window->TitleBarHeight() + window->MenuBarHeight();
5421 ImVec2 size_pad = window->WindowPadding * 2.0f;
5422 ImVec2 size_desired = size_contents + size_pad + ImVec2(0.0f, decoration_up_height);
5423 if (window->Flags & ImGuiWindowFlags_Tooltip)
5424 {
5425 // Tooltip always resize
5426 return size_desired;
5427 }
5428 else
5429 {
5430 // Maximum window size is determined by the viewport size or monitor size
5431 const bool is_popup = (window->Flags & ImGuiWindowFlags_Popup) != 0;
5432 const bool is_menu = (window->Flags & ImGuiWindowFlags_ChildMenu) != 0;
5433 ImVec2 size_min = style.WindowMinSize;
5434 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)
5435 size_min = ImMin(size_min, ImVec2(4.0f, 4.0f));
5436
5437 // FIXME-VIEWPORT-WORKAREA: May want to use GetWorkSize() instead of Size depending on the type of windows?
5438 ImVec2 avail_size = ImGui::GetMainViewport()->Size;
5439 ImVec2 size_auto_fit = ImClamp(size_desired, size_min, ImMax(size_min, avail_size - style.DisplaySafeAreaPadding * 2.0f));
5440
5441 // When the window cannot fit all contents (either because of constraints, either because screen is too small),
5442 // we are growing the size on the other axis to compensate for expected scrollbar. FIXME: Might turn bigger than ViewportSize-WindowPadding.
5443 ImVec2 size_auto_fit_after_constraint = CalcWindowSizeAfterConstraint(window, size_auto_fit);
5444 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);
5445 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);
5446 if (will_have_scrollbar_x)
5447 size_auto_fit.y += style.ScrollbarSize;
5448 if (will_have_scrollbar_y)
5449 size_auto_fit.x += style.ScrollbarSize;
5450 return size_auto_fit;
5451 }
5452}
5453
5454ImVec2 ImGui::CalcWindowNextAutoFitSize(ImGuiWindow* window)
5455{

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