Browse Source

Fix window position assertion caused by negative window size (#2722)

pull/2728/head
Aevyrie 2 years ago
committed by GitHub
parent
commit
95247daa17
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      crates/egui-winit/src/window_settings.rs

18
crates/egui-winit/src/window_settings.rs

@ -128,15 +128,17 @@ impl WindowSettings {
active_monitor.position().x as f32,
active_monitor.position().y as f32,
);
let monitor_size = active_monitor.size();
*position = position.clamp(
monitor_position,
// To get the maximum position, we get the rightmost corner of the display, then subtract
// the size of the window to get the bottom right most value window.position can have.
monitor_position
+ egui::Vec2::new(monitor_size.width as f32, monitor_size.height as f32)
- inner_size_pixels,
let monitor_size = egui::Vec2::new(
active_monitor.size().width as f32,
active_monitor.size().height as f32,
);
// Window size cannot be negative or the subsequent `clamp` will panic.
let window_size = (monitor_size - inner_size_pixels).max(egui::Vec2::ZERO);
// To get the maximum position, we get the rightmost corner of the display, then
// subtract the size of the window to get the bottom right most value window.position
// can have.
*position = position.clamp(monitor_position, monitor_position + window_size);
}
}
}

Loading…
Cancel
Save