Browse Source

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)

omar 6 years ago
parent
commit
1c7be88a1a
2 changed files with 6 additions and 2 deletions
  1. 1 1
      docs/TODO.txt
  2. 5 1
      imgui.cpp

+ 1 - 1
docs/TODO.txt

@@ -287,7 +287,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i
  - viewport: with platform decoration enabled, platform may force constraint (e.g. minimum size)
  - viewport: with platform decoration enabled, platform may force constraint (e.g. minimum size)
  - viewport: use getfocus/setfocus api to synchronize imgui<>platform focus better (e.g imgui-side ctrl-tab can focus os window, OS initial setup and alt-tab can focus imgui window etc.)
  - viewport: use getfocus/setfocus api to synchronize imgui<>platform focus better (e.g imgui-side ctrl-tab can focus os window, OS initial setup and alt-tab can focus imgui window etc.)
  - viewport: store per-viewport/monitor DPI in .ini file so an application reload or main window changing DPI on reload can be properly patched for.
  - viewport: store per-viewport/monitor DPI in .ini file so an application reload or main window changing DPI on reload can be properly patched for.
- - viewport: implicit Debug window can hog a zombie viewport (harmless, noisy?)
+ - viewport: implicit Debug window can hog a zombie viewport (harmless, noisy?) > could at least clear out the reference on a per session basis?
  - viewport: need to clarify how to use GetMousePos() from a user point of view.
  - viewport: need to clarify how to use GetMousePos() from a user point of view.
  - platform: glfw: no support for ImGuiBackendFlags_HasMouseHoveredViewport. 
  - platform: glfw: no support for ImGuiBackendFlags_HasMouseHoveredViewport. 
  - platform: sdl: no support for ImGuiBackendFlags_HasMouseHoveredViewport. maybe we could use SDL_GetMouseFocus() / SDL_WINDOW_MOUSE_FOCUS if imgui could fallback on its heuristic when NoInputs is set
  - platform: sdl: no support for ImGuiBackendFlags_HasMouseHoveredViewport. maybe we could use SDL_GetMouseFocus() / SDL_WINDOW_MOUSE_FOCUS if imgui could fallback on its heuristic when NoInputs is set

+ 5 - 1
imgui.cpp

@@ -7699,9 +7699,13 @@ static int ImGui::FindPlatformMonitorForPos(const ImVec2& pos)
 static int ImGui::FindPlatformMonitorForRect(const ImRect& rect)
 static int ImGui::FindPlatformMonitorForRect(const ImRect& rect)
 {
 {
     ImGuiContext& g = *GImGui;
     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;
     int best_monitor_n = -1;
     float best_monitor_surface = 0.001f;
     float best_monitor_surface = 0.001f;
+
     for (int monitor_n = 0; monitor_n < g.PlatformIO.Monitors.Size && best_monitor_surface < surface_threshold; monitor_n++)
     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];
         const ImGuiPlatformMonitor& monitor = g.PlatformIO.Monitors[monitor_n];