Viewport: Fixed a bug where tooltips on their first frame didn't find a monitor leading to the "recovery" code to revert it to the main viewport for a frame. (#1542)

This commit is contained in:
omar
2018-11-30 14:13:51 +01:00
parent 2fbbcaa339
commit 1c7be88a1a
2 changed files with 6 additions and 2 deletions

View File

@ -7699,9 +7699,13 @@ static int ImGui::FindPlatformMonitorForPos(const ImVec2& pos)
static int ImGui::FindPlatformMonitorForRect(const ImRect& rect)
{
ImGuiContext& g = *GImGui;
float surface_threshold = rect.GetWidth() * rect.GetHeight() * 0.5f;
// Use a minimum threshold of 1.0f so a zero-sized rect will still find its monitor given its position.
// This is necessary for tooltips which always resize down to zero at first.
const float surface_threshold = ImMax(rect.GetWidth() * rect.GetHeight() * 0.5f, 1.0f);
int best_monitor_n = -1;
float best_monitor_surface = 0.001f;
for (int monitor_n = 0; monitor_n < g.PlatformIO.Monitors.Size && best_monitor_surface < surface_threshold; monitor_n++)
{
const ImGuiPlatformMonitor& monitor = g.PlatformIO.Monitors[monitor_n];