Skip to content

Commit

Permalink
Factor out active monitor detection
Browse files Browse the repository at this point in the history
  • Loading branch information
avery-radmacher committed May 2, 2024
1 parent c9b24d5 commit 6937f39
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions crates/egui-winit/src/window_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@ impl WindowSettings {
}
}

fn clamp_pos_to_monitors<E>(
fn find_active_monitor<E>(
egui_zoom_factor: f32,
event_loop: &winit::event_loop::EventLoopWindowTarget<E>,
window_size_pts: egui::Vec2,
position_px: &mut egui::Pos2,
) {
position_px: &egui::Pos2,
) -> Option<winit::monitor::MonitorHandle> {
crate::profile_function!();

let monitors = event_loop.available_monitors();
Expand All @@ -142,7 +142,7 @@ fn clamp_pos_to_monitors<E>(
.primary_monitor()
.or_else(|| event_loop.available_monitors().next())
else {
return; // no monitors 🤷
return None; // no monitors 🤷
};

for monitor in monitors {
Expand All @@ -159,6 +159,23 @@ fn clamp_pos_to_monitors<E>(
}
}

Some(active_monitor)
}

fn clamp_pos_to_monitors<E>(
egui_zoom_factor: f32,
event_loop: &winit::event_loop::EventLoopWindowTarget<E>,
window_size_pts: egui::Vec2,
position_px: &mut egui::Pos2,
) {
crate::profile_function!();

let Some(active_monitor) =
find_active_monitor(egui_zoom_factor, event_loop, window_size_pts, position_px)
else {
return; // no monitors 🤷
};

let mut window_size_px =
window_size_pts * (egui_zoom_factor * active_monitor.scale_factor() as f32);
// Add size of title bar. This is 32 px by default in Win 10/11.
Expand Down

0 comments on commit 6937f39

Please sign in to comment.