1
0
mirror of https://github.com/ocornut/imgui.git synced 2025-02-26 22:59:19 +01:00

Viewports: default to first monitor is viewport is outside bounds. (#8393, #8385)

Before the assert was introduced in d66f4e589 the viewport would be eventually clamped with ClampWindowPos using g.FallbackMonitor, but code would run temporarly with DpiScale=0.
This commit is contained in:
Gabriel Rodriguez 2025-02-12 12:39:44 +01:00 committed by ocornut
parent 71d39a4634
commit 95c4111783
2 changed files with 8 additions and 2 deletions

View File

@ -83,6 +83,11 @@ Other changes:
- Backends: WebGPU: Fix for DAWN API rename WGPUProgrammableStageDescriptor -> WGPUComputeState. - Backends: WebGPU: Fix for DAWN API rename WGPUProgrammableStageDescriptor -> WGPUComputeState.
[@PhantomCloak] (#8369) [@PhantomCloak] (#8369)
Docking+Viewports Branch:
- Viewports: fixed an assert when a window load settings with a position outside
monitor bounds, when there are multiple monitors. (#8393, #8385) [@gaborodriguez]
----------------------------------------------------------------------- -----------------------------------------------------------------------
VERSION 1.91.8 (Released 2025-01-31) VERSION 1.91.8 (Released 2025-01-31)

View File

@ -16536,13 +16536,14 @@ static int ImGui::FindPlatformMonitorForRect(const ImRect& rect)
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
const int monitor_count = g.PlatformIO.Monitors.Size; const int monitor_count = g.PlatformIO.Monitors.Size;
IM_ASSERT(monitor_count > 0);
if (monitor_count <= 1) if (monitor_count <= 1)
return monitor_count - 1; return 0;
// 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. // 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.
// This is necessary for tooltips which always resize down to zero at first. // 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); const float surface_threshold = ImMax(rect.GetWidth() * rect.GetHeight() * 0.5f, 1.0f);
int best_monitor_n = -1; int best_monitor_n = 0; // Default to the first monitor as fallback
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++)