MCPcopy Create free account
hub / github.com/Aegel5/SimpleSwitcher / FindPlatformMonitorForRect

Method FindPlatformMonitorForRect

imgui_tiny_app/imgui/imgui.cpp:17557–17586  ·  view source on GitHub ↗

Search for the monitor with the largest intersection area with the given rectangle We generally try to avoid searching loops but the monitor count should be very small here FIXME-OPT: We could test the last monitor used for that viewport first, and early

Source from the content-addressed store, hash-verified

17555// We generally try to avoid searching loops but the monitor count should be very small here
17556// FIXME-OPT: We could test the last monitor used for that viewport first, and early
17557static int ImGui::FindPlatformMonitorForRect(const ImRect& rect)
17558{
17559 ImGuiContext& g = *GImGui;
17560
17561 const int monitor_count = g.PlatformIO.Monitors.Size;
17562 if (monitor_count <= 1)
17563 return monitor_count - 1;
17564
17565 // Use a minimum threshold of 1.0f so a zero-sized rect won't false positive, and will still find the correct monitor given its position.
17566 // This is necessary for tooltips which always resize down to zero at first.
17567 const float surface_threshold = ImMax(rect.GetWidth() * rect.GetHeight() * 0.5f, 1.0f);
17568 int best_monitor_n = 0; // Default to the first monitor as fallback
17569 float best_monitor_surface = 0.001f;
17570
17571 for (int monitor_n = 0; monitor_n < g.PlatformIO.Monitors.Size && best_monitor_surface < surface_threshold; monitor_n++)
17572 {
17573 const ImGuiPlatformMonitor& monitor = g.PlatformIO.Monitors[monitor_n];
17574 const ImRect monitor_rect = ImRect(monitor.MainPos, monitor.MainPos + monitor.MainSize);
17575 if (monitor_rect.Contains(rect))
17576 return monitor_n;
17577 ImRect overlapping_rect = rect;
17578 overlapping_rect.ClipWithFull(monitor_rect);
17579 float overlapping_surface = overlapping_rect.GetWidth() * overlapping_rect.GetHeight();
17580 if (overlapping_surface < best_monitor_surface)
17581 continue;
17582 best_monitor_surface = overlapping_surface;
17583 best_monitor_n = monitor_n;
17584 }
17585 return best_monitor_n;
17586}
17587
17588// Update monitor from viewport rectangle (we'll use this info to clamp windows and save windows lost in a removed monitor)
17589static void ImGui::UpdateViewportPlatformMonitor(ImGuiViewportP* viewport)

Callers

nothing calls this directly

Calls 3

ImMaxFunction · 0.85
ImRectFunction · 0.70
ContainsMethod · 0.45

Tested by

no test coverage detected